Skip to content

[multistage] Avoid Broker Request Id Collision#10789

Merged
walterddr merged 6 commits intoapache:masterfrom
ankitsultana:multistage-rng
May 23, 2023
Merged

[multistage] Avoid Broker Request Id Collision#10789
walterddr merged 6 commits intoapache:masterfrom
ankitsultana:multistage-rng

Conversation

@ankitsultana
Copy link
Contributor

cc: @walterddr

request id collisions across brokers can cause weird query failures (we are seeing this in our production).

Later we should switch to string based request-id. For now going with RNG to avoid having to deal with broker response changes and b/w incompatibility issues.

@codecov-commenter
Copy link

codecov-commenter commented May 20, 2023

Codecov Report

Merging #10789 (53bf9f4) into master (3851f33) will decrease coverage by 5.16%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master   #10789      +/-   ##
============================================
- Coverage     68.51%   63.36%   -5.16%     
+ Complexity     6479     5256    -1223     
============================================
  Files          2159     2143      -16     
  Lines        116044   115614     -430     
  Branches      17569    17514      -55     
============================================
- Hits          79510    73261    -6249     
- Misses        30899    36989    +6090     
+ Partials       5635     5364     -271     
Flag Coverage Δ
integration1 24.14% <100.00%> (+0.15%) ⬆️
integration2 23.80% <62.50%> (?)
unittests1 67.91% <ø> (+0.04%) ⬆️
unittests2 ?

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

Impacted Files Coverage Δ
...requesthandler/MultiStageBrokerRequestHandler.java 64.28% <100.00%> (-3.39%) ⬇️

... and 434 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Nullable RequesterIdentity requesterIdentity, RequestContext requestContext)
throws Exception {
long requestId = _requestIdGenerator.incrementAndGet();
long requestId = _multistageRequestIdGenerator.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on this. CC @Jackie-Jiang to take a look and see if there's any alternative opinion on solving this issue.


public class MultiStageBrokerRequestHandler extends BaseBrokerRequestHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(MultiStageBrokerRequestHandler.class);
private final Random _random = new Random();
Copy link
Contributor

Choose a reason for hiding this comment

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

had some offline discussion, can we do something like

requestID = ((Long)((hash(brokerId) << 32)) + _requestIdGenerator.incrementAndGet()

encode brokerID and requestID with high/low bits?

this way we can still masked out the lower bit to get the exact ordering of the requests when we look at the requestID. this will be better in terms of debuggability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added base-2 masking. We can also do base-10 masking to make debugging even easier. Something like:

brokerHash * 10^9 + (requestId.incrementAndGet() % 10^9)

lmk your preference

@ankitsultana ankitsultana changed the title [multistage] Use RNG for Request Id Generation [multistage] Avoid Broker Request Id Collision May 23, 2023
Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

lgtm. also chatted offline, another alternative is to use mask ^ 10^9 + requestID
which will be simplier to decipher on logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants