|
18 | 18 |
|
19 | 19 | import com.google.api.core.InternalApi; |
20 | 20 | import com.google.common.annotations.VisibleForTesting; |
| 21 | +import com.google.common.collect.Lists; |
21 | 22 | import com.google.common.hash.Hashing; |
22 | 23 | import com.google.protobuf.ByteString; |
23 | 24 | import com.google.spanner.v1.CacheUpdate; |
|
27 | 28 | import com.google.spanner.v1.RoutingHint; |
28 | 29 | import com.google.spanner.v1.Tablet; |
29 | 30 | import java.time.Duration; |
30 | | -import java.util.AbstractList; |
31 | 31 | import java.util.ArrayList; |
32 | 32 | import java.util.Arrays; |
33 | 33 | import java.util.Collections; |
@@ -740,7 +740,7 @@ RouteLookupResult lookupRoutingHint( |
740 | 740 | directedReadOptions.getReplicasCase() |
741 | 741 | != DirectedReadOptions.ReplicasCase.REPLICAS_NOT_SET; |
742 | 742 | Map<String, ChannelEndpoint> resolvedEndpoints = new HashMap<>(); |
743 | | - SelectionStats selectionStats = new SelectionStats(); |
| 743 | + SelectionState selectionStats = new SelectionState(); |
744 | 744 |
|
745 | 745 | TabletSnapshot selected = |
746 | 746 | selectTablet( |
@@ -812,7 +812,7 @@ private TabletSnapshot selectTablet( |
812 | 812 | Set<Long> skippedTabletUids, |
813 | 813 | List<SkippedTabletDetail> skippedTabletDetails, |
814 | 814 | Map<String, ChannelEndpoint> resolvedEndpoints, |
815 | | - SelectionStats selectionStats) { |
| 815 | + SelectionState selectionStats) { |
816 | 816 | if (!preferLeader || hintBuilder.getOperationUid() > 0L) { |
817 | 817 | TabletSnapshot preferredLeader = |
818 | 818 | preferLeader ? localLeaderForScoreBias(snapshot, hasDirectedReadOptions) : null; |
@@ -893,7 +893,7 @@ private TabletSnapshot selectScoreAwareTablet( |
893 | 893 | Set<Long> skippedTabletUids, |
894 | 894 | List<SkippedTabletDetail> skippedTabletDetails, |
895 | 895 | Map<String, ChannelEndpoint> resolvedEndpoints, |
896 | | - SelectionStats selectionStats, |
| 896 | + SelectionState selectionStats, |
897 | 897 | @javax.annotation.Nullable TabletSnapshot preferredLeader) { |
898 | 898 | long operationUid = hintBuilder.getOperationUid(); |
899 | 899 | List<EligibleReplica> eligibleReplicas = |
@@ -924,7 +924,7 @@ private List<EligibleReplica> collectEligibleReplicas( |
924 | 924 | Set<Long> skippedTabletUids, |
925 | 925 | List<SkippedTabletDetail> skippedTabletDetails, |
926 | 926 | Map<String, ChannelEndpoint> resolvedEndpoints, |
927 | | - SelectionStats selectionStats, |
| 927 | + SelectionState selectionStats, |
928 | 928 | long operationUid, |
929 | 929 | boolean preferLeader, |
930 | 930 | @javax.annotation.Nullable TabletSnapshot preferredLeader) { |
@@ -991,17 +991,7 @@ private EligibleReplica lowestCostReplica(List<EligibleReplica> eligibleReplicas |
991 | 991 | } |
992 | 992 |
|
993 | 993 | private List<ChannelEndpoint> endpointView(List<EligibleReplica> eligibleReplicas) { |
994 | | - return new AbstractList<ChannelEndpoint>() { |
995 | | - @Override |
996 | | - public ChannelEndpoint get(int index) { |
997 | | - return eligibleReplicas.get(index).endpoint; |
998 | | - } |
999 | | - |
1000 | | - @Override |
1001 | | - public int size() { |
1002 | | - return eligibleReplicas.size(); |
1003 | | - } |
1004 | | - }; |
| 994 | + return Lists.transform(eligibleReplicas, candidate -> candidate.endpoint); |
1005 | 995 | } |
1006 | 996 |
|
1007 | 997 | private double selectionCostForEndpoint( |
@@ -1109,7 +1099,7 @@ private boolean shouldSkip( |
1109 | 1099 | Set<Long> skippedTabletUids, |
1110 | 1100 | List<SkippedTabletDetail> skippedTabletDetails, |
1111 | 1101 | Map<String, ChannelEndpoint> resolvedEndpoints, |
1112 | | - SelectionStats selectionStats) { |
| 1102 | + SelectionState selectionStats) { |
1113 | 1103 | String targetEndpointLabel = endpointLabel(snapshot, tablet); |
1114 | 1104 | if (tablet.skip) { |
1115 | 1105 | selectionStats.sawNonExcludedReplica = true; |
@@ -1179,7 +1169,7 @@ private boolean shouldSkip( |
1179 | 1169 | return true; |
1180 | 1170 | } |
1181 | 1171 |
|
1182 | | - private final class SelectionStats { |
| 1172 | + private final class SelectionState { |
1183 | 1173 | private boolean sawMatchingReplica; |
1184 | 1174 | private boolean sawExcludedReplica; |
1185 | 1175 | private boolean sawNonExcludedReplica; |
|
0 commit comments