dsmiley commented on code in PR #3851:
URL: https://github.com/apache/solr/pull/3851#discussion_r2528012411
##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java:
##########
@@ -1135,52 +1253,123 @@ public boolean isDirectUpdatesToLeadersOnly() {
return directUpdatesToLeadersOnly;
}
- protected static Object[] objectList(int n) {
- Object[] l = new Object[n];
- for (int i = 0; i < n; i++) {
- l[i] = new Object();
- }
- return l;
+ /** Visible for tests so they can assert the configured refresh parallelism.
*/
+ protected int getStateRefreshParallelism() {
+ return stateRefreshParallelism;
}
protected DocCollection getDocCollection(String collection, Integer
expectedVersion)
throws SolrException {
- if (expectedVersion == null) expectedVersion = -1;
- if (collection == null) return null;
- ExpiringCachedDocCollection cacheEntry =
collectionStateCache.get(collection);
- DocCollection col = cacheEntry == null ? null : cacheEntry.cached;
- if (col != null) {
- if (expectedVersion <= col.getZNodeVersion() &&
!cacheEntry.shouldRetry()) return col;
+ if (expectedVersion == null) {
+ expectedVersion = -1;
+ }
+ if (collection == null) {
+ return null;
}
- Object[] locks = this.locks;
- int lockId =
- Math.abs(Hash.murmurhash3_x86_32(collection, 0, collection.length(),
0) % locks.length);
- final Object lock = locks[lockId];
- synchronized (lock) {
- /*we have waited for some time just check once again*/
- cacheEntry = collectionStateCache.get(collection);
- col = cacheEntry == null ? null : cacheEntry.cached;
- if (col != null) {
- if (expectedVersion <= col.getZNodeVersion() &&
!cacheEntry.shouldRetry()) return col;
- }
- ClusterState.CollectionRef ref = getCollectionRef(collection);
- if (ref == null) {
- // no such collection exists
- return null;
- }
- // We are going to fetch a new version
- // we MUST try to get a new version
- DocCollection fetchedCol = ref.get(); // this is a call to ZK
- if (fetchedCol == null) return null; // this collection no more exists
- if (col != null && fetchedCol.getZNodeVersion() ==
col.getZNodeVersion()) {
- cacheEntry.setRetriedAt(); // we retried and found that it is the same
version
- cacheEntry.maybeStale = false;
- } else {
- collectionStateCache.put(collection, new
ExpiringCachedDocCollection(fetchedCol));
+ ExpiringCachedDocCollection cacheEntry =
collectionStateCache.peek(collection);
+ if (cacheEntry != null &&
cacheEntry.isExpired(collectionStateCache.timeToLiveMs)) {
+ collectionStateCache.remove(collection, cacheEntry);
+ cacheEntry = null;
+ }
+
+ DocCollection cached = cacheEntry == null ? null : cacheEntry.cached;
+
+ if (cacheEntry != null && cacheEntry.shouldRetry()) {
+ triggerCollectionRefresh(collection);
+ }
+
+ if (cached != null && expectedVersion <= cached.getZNodeVersion()) {
+ return cached;
+ }
+
+ CompletableFuture<DocCollection> refreshFuture =
triggerCollectionRefresh(collection);
+ return waitForCollectionRefresh(collection, refreshFuture);
+ }
+
+ private CompletableFuture<DocCollection> triggerCollectionRefresh(String
collection) {
+ if (closed) {
+ ExpiringCachedDocCollection cacheEntry =
collectionStateCache.peek(collection);
+ DocCollection cached = cacheEntry == null ? null : cacheEntry.cached;
+ return CompletableFuture.completedFuture(cached);
+ }
+ return collectionRefreshes.computeIfAbsent(
+ collection,
+ key -> {
+ ExecutorService executor = threadPool;
+ CompletableFuture<DocCollection> future;
+ if (executor == null || ExecutorUtil.isShutdown(executor)) {
+ future = new CompletableFuture<>();
+ try {
+ future.complete(loadDocCollection(key));
+ } catch (Throwable t) {
+ future.completeExceptionally(t);
+ }
+ } else {
+ future =
+ CompletableFuture.supplyAsync(
+ () -> {
+ stateRefreshSemaphore.acquireUninterruptibly();
Review Comment:
perhaps we should acquire before supplyAsync, thus some potential
back-pressure for triggerCollectionRefresh's callers? not sure honestly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]