Skip to content

Commit 101c085

Browse files
committed
address comments
1 parent 61e2f16 commit 101c085

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/ChannelFinder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ private void drainPendingUpdate() {
165165
}
166166
}
167167

168+
/**
169+
* Test-only hook used by {@link KeyAwareChannel#awaitPendingCacheUpdates()} to wait until the
170+
* async cache update worker has finished applying the latest pending update.
171+
*/
168172
@VisibleForTesting
169173
void awaitPendingUpdates() throws InterruptedException {
170174
// Spin until no pending update remains.

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/EndpointLifecycleManager.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ static final class EndpointState {
111111
* stable database-id key instead of a strong ChannelFinder reference. KeyAwareChannel unregisters
112112
* stale entries when a finder is cleared.
113113
*
114-
* <p>All reads and writes to this map, and stale-endpoint eviction based on it, are synchronized
115-
* on {@link #activeAddressLock}.
114+
* <p>All reads and writes to this map, and all updates to {@link
115+
* #transientFailureEvictedAddresses}, are synchronized on {@link #activeAddressLock}.
116116
*/
117117
private final Map<String, Set<String>> activeAddressesPerFinder = new ConcurrentHashMap<>();
118118

@@ -195,6 +195,24 @@ private boolean ensureEndpointExists(String address) {
195195
return created[0];
196196
}
197197

198+
private void retainTransientFailureEvictionMarkers(Set<String> activeAddresses) {
199+
synchronized (activeAddressLock) {
200+
transientFailureEvictedAddresses.retainAll(activeAddresses);
201+
}
202+
}
203+
204+
private void markTransientFailureEvicted(String address) {
205+
synchronized (activeAddressLock) {
206+
transientFailureEvictedAddresses.add(address);
207+
}
208+
}
209+
210+
private void clearTransientFailureEvictionMarker(String address) {
211+
synchronized (activeAddressLock) {
212+
transientFailureEvictedAddresses.remove(address);
213+
}
214+
}
215+
198216
/**
199217
* Records that real (non-probe) traffic was routed to an endpoint. This refreshes the idle
200218
* eviction timer for this endpoint.
@@ -243,7 +261,7 @@ void updateActiveAddresses(String finderKey, Set<String> activeAddresses) {
243261
for (Set<String> addresses : activeAddressesPerFinder.values()) {
244262
allActive.addAll(addresses);
245263
}
246-
transientFailureEvictedAddresses.retainAll(allActive);
264+
retainTransientFailureEvictionMarkers(allActive);
247265

248266
// Evict managed endpoints not referenced by any finder.
249267
List<String> stale = new ArrayList<>();
@@ -285,7 +303,7 @@ void unregisterFinder(String finderKey) {
285303
for (Set<String> addresses : activeAddressesPerFinder.values()) {
286304
allActive.addAll(addresses);
287305
}
288-
transientFailureEvictedAddresses.retainAll(allActive);
306+
retainTransientFailureEvictionMarkers(allActive);
289307

290308
List<String> stale = new ArrayList<>();
291309
for (String address : endpoints.keySet()) {
@@ -422,7 +440,7 @@ private void probe(String address) {
422440
case READY:
423441
state.lastReadyAt = clock.instant();
424442
state.consecutiveTransientFailures = 0;
425-
transientFailureEvictedAddresses.remove(address);
443+
clearTransientFailureEvictionMarker(address);
426444
break;
427445

428446
case IDLE:
@@ -509,9 +527,9 @@ private void evictEndpoint(String address, EvictionReason reason) {
509527
stopProbing(address);
510528
endpoints.remove(address);
511529
if (reason == EvictionReason.TRANSIENT_FAILURE) {
512-
transientFailureEvictedAddresses.add(address);
530+
markTransientFailureEvicted(address);
513531
} else {
514-
transientFailureEvictedAddresses.remove(address);
532+
clearTransientFailureEvictionMarker(address);
515533
}
516534
endpointCache.evict(address);
517535
}

0 commit comments

Comments
 (0)