Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -936,22 +936,6 @@ private TabletSnapshot selectTablet(
List<SkippedTabletDetail> skippedTabletDetails,
Map<String, ChannelEndpoint> resolvedEndpoints,
SelectionState selectionStats) {
if (!preferLeader || hintBuilder.getOperationUid() > 0L) {
TabletSnapshot preferredLeader =
preferLeader ? localLeaderForScoreBias(snapshot, hasDirectedReadOptions) : null;
return selectScoreAwareTablet(
snapshot,
preferLeader,
directedReadOptions,
hintBuilder,
excludedEndpoints,
skippedTabletUids,
skippedTabletDetails,
resolvedEndpoints,
selectionStats,
preferredLeader);
}

boolean checkedLeader = false;
if (preferLeader
&& !hasDirectedReadOptions
Expand All @@ -971,6 +955,22 @@ private TabletSnapshot selectTablet(
return snapshot.leader();
}
}

if (!preferLeader || hintBuilder.getOperationUid() > 0L) {
TabletSnapshot preferredLeader =
preferLeader ? localLeaderForScoreBias(snapshot, hasDirectedReadOptions) : null;
return selectScoreAwareTablet(
snapshot,
preferLeader,
directedReadOptions,
hintBuilder,
excludedEndpoints,
skippedTabletUids,
skippedTabletDetails,
resolvedEndpoints,
selectionStats,
preferredLeader);
}
for (int index = 0; index < snapshot.tablets.size(); index++) {
if (checkedLeader && index == snapshot.leaderIndex) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public void preferLeaderFalseUsesLowestLatencyReplicaWhenScoresAvailable() {
}

@Test
public void preferLeaderTrueUsesLatencyScoresWhenOperationUidAvailable() {
public void preferLeaderTrueWithOperationUidSelectsLeaderEvenWhenFollowerHasLowerLatency() {
FakeEndpointCache endpointCache = new FakeEndpointCache();
KeyRangeCache cache = new KeyRangeCache(endpointCache);
cache.useDeterministicRandom();
Expand All @@ -794,6 +794,38 @@ public void preferLeaderTrueUsesLatencyScoresWhenOperationUidAvailable() {
endpointCache.get("server2");
endpointCache.get("server3");

EndpointLatencyRegistry.recordLatency(
null, TEST_OPERATION_UID, true, "server1", Duration.ofNanos(300_000L));
EndpointLatencyRegistry.recordLatency(
null, TEST_OPERATION_UID, true, "server2", Duration.ofNanos(100_000L));
EndpointLatencyRegistry.recordLatency(
null, TEST_OPERATION_UID, true, "server3", Duration.ofNanos(200_000L));

RoutingHint.Builder hint =
RoutingHint.newBuilder().setKey(bytes("a")).setOperationUid(TEST_OPERATION_UID);
ChannelEndpoint server =
cache.fillRoutingHint(
true,
KeyRangeCache.RangeMode.COVERING_SPLIT,
DirectedReadOptions.getDefaultInstance(),
hint);

assertNotNull(server);
assertEquals("server1", server.getAddress());
}

@Test
public void preferLeaderTrueWithOperationUidFallsBackToScoreAwareWhenLeaderUnhealthy() {
FakeEndpointCache endpointCache = new FakeEndpointCache();
KeyRangeCache cache = new KeyRangeCache(endpointCache);
cache.useDeterministicRandom();
cache.addRanges(threeReplicaUpdate());

endpointCache.get("server1");
endpointCache.get("server2");
endpointCache.get("server3");
endpointCache.setState("server1", EndpointHealthState.TRANSIENT_FAILURE);

EndpointLatencyRegistry.recordLatency(
null, TEST_OPERATION_UID, true, "server1", Duration.ofNanos(300_000L));
EndpointLatencyRegistry.recordLatency(
Expand Down
Loading