Skip to content

Fix broker request id generator to avoid generating same id#16661

Merged
Jackie-Jiang merged 1 commit intoapache:masterfrom
Jackie-Jiang:fix_request_id_generator
Aug 22, 2025
Merged

Fix broker request id generator to avoid generating same id#16661
Jackie-Jiang merged 1 commit intoapache:masterfrom
Jackie-Jiang:fix_request_id_generator

Conversation

@Jackie-Jiang
Copy link
Contributor

@Jackie-Jiang Jackie-Jiang commented Aug 21, 2025

Summary

This PR fixes the broker request ID generator to prevent the generation of duplicate request IDs across different brokers, broker restarts, and different query engines.

Problem

The previous implementation used the broker ID hash code as a mask for generating request IDs. This approach had several issues:

  • Brokers with similar IDs could generate the same hash code, leading to duplicate request IDs
  • Broker restarts would regenerate the same sequence of request IDs
  • Hash collisions could occur between different broker instances
  • Different query engines (single-stage vs multi-stage) could potentially generate the same request IDs

Solution

  • Replaced deterministic hash-based approach with random-based approach
  • Centralized request ID generator creation in BaseBrokerStarter
  • Updated all broker request handlers to use shared generator instance
  • Ensures different query engines use the same ID generation mechanism
  • Improved documentation to reflect the new random-based approach

Changes

Core Changes

  • BrokerRequestIdGenerator: Changed from hash-based to random-based ID generation
  • BaseBrokerStarter: Creates a single shared BrokerRequestIdGenerator instance
  • All Request Handlers: Updated constructors to accept the shared generator

Files Modified

  • BaseBrokerStarter.java - Creates and injects shared request ID generator
  • BaseBrokerRequestHandler.java - Updated constructor to accept generator
  • BaseSingleStageBrokerRequestHandler.java - Updated constructor signature
  • BrokerRequestIdGenerator.java - Changed from hash-based to random-based generation
  • GrpcBrokerRequestHandler.java - Updated constructor
  • MultiStageBrokerRequestHandler.java - Updated constructor
  • SingleConnectionBrokerRequestHandler.java - Updated constructor
  • TimeSeriesRequestHandler.java - Updated constructor
  • Test files updated to use new constructor signatures

Technical Details

ID Generation Strategy

  • Base: Random integer multiplied by 1,000,000,000
  • Counter: Auto-incrementing counter for uniqueness
  • Result: Unique 19-digit request ID with high probability of uniqueness

Benefits

  1. Eliminates hash collisions between brokers
  2. Handles broker restarts gracefully
  3. Maintains performance with atomic counter
  4. Preserves uniqueness across distributed system
  5. Ensures consistent ID generation across different query engines (single-stage, multi-stage, time-series)

Query Engine Consistency

By centralizing the request ID generator in BaseBrokerStarter and injecting it into all request handlers:

  • SingleConnectionBrokerRequestHandler (single-stage engine)
  • GrpcBrokerRequestHandler (single-stage engine with gRPC)
  • MultiStageBrokerRequestHandler (multi-stage engine)
  • TimeSeriesRequestHandler (time-series engine)

All query engines now use the same ID generation mechanism, preventing conflicts between different execution paths.

Testing

  • Code compiles successfully
  • All existing tests updated and passing
  • Manual testing with multiple broker instances
  • Verified no duplicate IDs generated across restarts
  • Tested with different query engines to ensure ID uniqueness

This change improves the reliability of request tracking across all query execution engines in Pinot.

This comment was marked as outdated.

@Jackie-Jiang Jackie-Jiang force-pushed the fix_request_id_generator branch from b6dca07 to 6e9f986 Compare August 21, 2025 22:08
@Jackie-Jiang Jackie-Jiang requested a review from Copilot August 21, 2025 22:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the broker request ID generator to prevent duplicate request IDs across different brokers, broker restarts, and query engines by replacing the deterministic hash-based approach with a random-based approach.

Key changes:

  • Centralized ID generation: Creates a single BrokerRequestIdGenerator instance in BaseBrokerStarter and injects it into all request handlers
  • Random-based generation: Replaces hash-code masking with random number generation to eliminate collisions
  • Unified approach: Ensures all query engines (single-stage, multi-stage, time-series) use the same ID generation mechanism

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
BaseBrokerStarter.java Creates shared BrokerRequestIdGenerator instance and injects it into all request handlers
BrokerRequestIdGenerator.java Changes from hash-based to random-based ID generation using ThreadLocalRandom
BaseBrokerRequestHandler.java Updates constructor to accept injected requestIdGenerator instead of creating one
BaseSingleStageBrokerRequestHandler.java Updates constructor signature to pass through requestIdGenerator parameter
SingleConnectionBrokerRequestHandler.java Updates constructor to accept and pass through requestIdGenerator parameter
GrpcBrokerRequestHandler.java Updates constructor to accept and pass through requestIdGenerator parameter
MultiStageBrokerRequestHandler.java Updates constructor to accept and pass through requestIdGenerator parameter
TimeSeriesRequestHandler.java Updates constructor to accept and pass through requestIdGenerator parameter
LiteralOnlyBrokerRequestTest.java Updates test instantiations to provide BrokerRequestIdGenerator instance
BaseSingleStageBrokerRequestHandlerTest.java Updates test instantiation to provide BrokerRequestIdGenerator instance

@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.31%. Comparing base (76f2b7f) to head (6e9f986).

Files with missing lines Patch % Lines
...e/pinot/broker/broker/helix/BaseBrokerStarter.java 33.33% 2 Missing ⚠️
...roker/requesthandler/GrpcBrokerRequestHandler.java 0.00% 1 Missing ⚠️
...requesthandler/MultiStageBrokerRequestHandler.java 50.00% 0 Missing and 1 partial ⚠️
...roker/requesthandler/TimeSeriesRequestHandler.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #16661      +/-   ##
============================================
- Coverage     63.32%   63.31%   -0.01%     
+ Complexity     1380     1379       -1     
============================================
  Files          3035     3035              
  Lines        176714   176715       +1     
  Branches      27121    27121              
============================================
- Hits         111896   111884      -12     
- Misses        56232    56245      +13     
  Partials       8586     8586              
Flag Coverage Δ
custom-integration1 100.00% <ø> (ø)
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-11 63.27% <61.53%> (+<0.01%) ⬆️
java-21 63.28% <61.53%> (-0.02%) ⬇️
temurin 63.31% <61.53%> (-0.01%) ⬇️
unittests 63.30% <61.53%> (-0.01%) ⬇️
unittests1 56.46% <ø> (ø)
unittests2 33.11% <61.53%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jackie-Jiang Jackie-Jiang merged commit 283b5f7 into apache:master Aug 22, 2025
34 of 36 checks passed
@Jackie-Jiang Jackie-Jiang deleted the fix_request_id_generator branch August 22, 2025 18:06
mqliang pushed a commit to mqliang/pinot that referenced this pull request Feb 10, 2026
* [Query Resource Isolation] Workload Configs (apache#15109)

* Workload Configs

* workload config

* Add API

* config

* Change config structure

* Propagation strategy

* Fix style check

* Cost spliting on update

* Table addition propagation

* perf

* Tests

* test

* test 2

* Review comments 1

* review comments 3

* review comments 3

* name change

* review comments 4

* Fix TableDoesNotExistError for hybrid tables in MSE queries in controller API (apache#16102)

* Make ThreadResourceUsageProvider a Helper/Utility Class. (apache#16051)

* ThreadResourceUsageProvider is a helper class. ThreadResourceContext tracks resource usage.

Fix updateConcurrently

* Rename to ThreadResourceSnapshot

* Clean up

* Add javadoc

* Done use auto closeable

* Checkstyle

* Fix compilation error

* Add back removed functions in SPI

* Remove private constructor because japicmp complains.

* Add setThreadResourceUsageProvider because of backward-incompatible checks

* Add setThreadResourceUsageProvider because of backward-incompatible checks

* Fix test

* Fix ThreadResourceSnapshot usage and tests

* Store cpu sample in nanoseconds.

* Reduce logs and improve logging when queries are terminated due to OOM. (apache#16172)

* Dynamic PerQueryCPUMemAccountant Config on Servers  (apache#16219)

* Checkpoint

* Register change handler

* Fix bugs. Manually tested

* Checkstyle

* Tests

* Add pre-check that values are default

* Undo typo fix

* Update QueryRunner to make use of window function overflow handling server configurations (apache#16108)

* Add multistage thread limiting configs at the broker and server level (apache#16080)

* Adding changes for supporting RLS (apache#16043)

* Use stats cache on error instead of the chained mechanism (apache#15992)

* Improve broker error messaging when broker is the one reporting the failure (apache#16076)

* Introduce MSE active and passive timeouts (apache#16075)

* Throttle SSE & MSE Tasks if Server heap usage is above a threshold (apache#16271)

* Fix QueryScheduler constructor using class name. (apache#16280)

* Fix QueryScheduler constructor using class name.

* Fix test

* [Query Resource Isolation] WorkloadBudgetManager and Host enforcement (apache#15798)

* QRI - WorkloadBudgetManager implementation

* Address review comments

* Remove singleton & signature fix

* Fix compatibility checker

* Review comments

* Move WorkloadBudgetManager to core.

---------

Co-authored-by: praveenc7 <praveenkchaganlal@gmail.com>

* Eliminate duplicate cancel attempts in PerQueryCPUMemAccountant (apache#16299)

* Add basic 1 query tests

* Add more tests

* Add ability to remember cancel queries.

* Clean up if conditions in killMostExpensiveQuery

* Fix test failures.

* Address review comments.

* Use QueryCancelCallback to cancel queries from ThreadResourceUsageAccountant (apache#16142)

* Remove all calls to System.gc() in PerQueryCPUMemAccountantFactory (apache#16374)

* Initialize thread accountant just before serving queries (apache#16326)

* Allow Reset of ThreadResourceUsageAccountant in Tracing.java (apache#16360)

* Queries now self terminate if in panic mode. (apache#16380)

* Queries now self terminate if in panic mode.

* Add config test

* Hard kill on critical level.

* Fix configs

* Separate anchor thread interruption.

* Checkstyle

* Review comments

* remove code for critical level

---------

Co-authored-by: Rajat Venkatesh <vrajat@users.noreply.github.com>

* [Query Resource Isolation] Additonal Sampling for Broker and Server (apache#16164)

* fix

* sampling

* Broker sampling

* revert integ-test

* Fix test failures

* review comments

* remove MSE

* broker auth

* remove per pruner & planner sample

* Use Broker's accountant to sample in the request handler. (apache#16439)

* [Query Resource Isolation] Workload Scheduler (apache#16018)

* QRI - WorkloadBudgetManager implementation

* Address review comments

* scheduler

* unit test

* review comments: metrics, secondary, resource-manager

* remove broker admission

* Remove default budget

---------

Co-authored-by: Vivek Iyer Vaidyanathan Iyer <vvaidyanathan@linkedin.com>

* Cleanup deprecated methods in ThreadResourceUsageAccountant (apache#16479)

* Remove unnecessary methods and config for ThreadResourceUsageAccountant (apache#16490)

* Add tests for OOM Termination of MSE queries. (apache#16514)

* Fix a flaky assert when testing OOM Cancellation of MSE Queries (apache#16533)

* Disable Flaky Tests (apache#16554)

This is a follow-up to apache#16533
The fix for a flaky test did not work. This PR disables these tests temporarily.

* Use correlation ID instead of request id in PerQueryCpuMemAccountant (apache#16040)

* [Query Resource Isolation]Interface for Workload Stats Collection (apache#16340)

* Interface for Stats Collection

* Additional comments

* inherit

* additional class comments

* [Query Resource Isolation] Fix Refresh message (apache#16636)

* Fix Refresh message

* delete queryworkload message handler

* info -> debug logs

* reduce logging (apache#16698)

* style check

* [Query Workload Isolation] Cost-split support  (apache#16672)

* splits

* Cost split

* test

* propagation entity change & java doc

* Propagation scheme review comments

* empty commit to trigger build

* Reduce log for PerQueryCPUMemResourceUsageAccountant (apache#16642)

* [refactor] Switching to RoutingManager for broker request handlers (apache#16442)

Co-authored-by: Shaurya Chaturvedi <shauryachats@uber.com>

* Fix broker request id generator to avoid generating same id (apache#16661)

* Introduce QueryExecutionContext to manage query life cycle (apache#16728)

* Introduce QueryExecutionContext to manage query life cycle 2 (apache#16728)

---------

Co-authored-by: Rajat Venkatesh <1638298+vrajat@users.noreply.github.com>
Co-authored-by: Yash Mayya <yash.mayya@gmail.com>
Co-authored-by: Satwik Pachigolla <40644097+satwik-pachigolla@users.noreply.github.com>
Co-authored-by: 9aman <35227405+9aman@users.noreply.github.com>
Co-authored-by: Gonzalo Ortiz Jaureguizar <gortiz@users.noreply.github.com>
Co-authored-by: Vivek Iyer Vaidyanathan <vvivekiyer@gmail.com>
Co-authored-by: Xiaotian (Jackie) Jiang <17555551+Jackie-Jiang@users.noreply.github.com>
Co-authored-by: Rajat Venkatesh <vrajat@users.noreply.github.com>
Co-authored-by: Vivek Iyer Vaidyanathan Iyer <vvaidyanathan@linkedin.com>
Co-authored-by: Shaurya Chaturvedi <shauryachats@gmail.com>
Co-authored-by: Shaurya Chaturvedi <shauryachats@uber.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants