Session: Fixes scoped session token on partition splits and multiple write endpoints enabled #2937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mirror of Azure/azure-sdk-for-java#25555
Scenario
When a write operation is done through the SDK instance on Session consistency, the SDK stores locally the session token in a cache and also returns the token to the user. When a read operation for the same partition is done, and the user does not pass a session token in the input, we extract the session token from the cache from the write operation and pass it along.
Since the token that travels to the Gateway and is returned is scoped to a partition, the issue arises when a partition split occurs:
Ideally on step 7, the SDK should be sending the cached token for partition 2, which is C.
Fix
To fix this scenario, we are detecting which was the resulting partition for the operation and compare that with the initial partition SDK thought it was targeting. If the partitions do not match, it triggers a refresh of the partition map. That way when Step 7 happens, the SDK is aware of partitions 2 and 3 and it would identify the operation is for partition 2 and use token C.
Additional fix
For accounts that have multiple write endpoints enabled, the cached session token was not being sent on write operations. This PR also fixes that scenario so writes contain the cached token.
Type of change