dsmiley commented on code in PR #2021: URL: https://github.com/apache/solr/pull/2021#discussion_r1365561237
########## solr/core/src/java/org/apache/solr/update/VersionInfo.java: ########## @@ -284,11 +297,20 @@ public Long getMaxVersionFromIndex(IndexSearcher searcher) throws IOException { } public void seedBucketsWithHighestVersion(long highestVersion) { - for (int i = 0; i < buckets.length; i++) { - // should not happen, but in case other threads are calling updateHighest on the version - // bucket - synchronized (buckets[i]) { - if (buckets[i].highest < highestVersion) buckets[i].highest = highestVersion; + if (buckets == null) { + synchronized (bucketsSync) { + if (buckets == null) { + // Update the highest version seed to use if/when buckets are created. + highestVersionSeed = Math.max(highestVersion, highestVersionSeed); + return; + } + } + } + for (VersionBucket bucket : buckets) { Review Comment: I think this would be clearer with an "else". ########## solr/core/src/java/org/apache/solr/update/VersionBucket.java: ########## @@ -31,14 +31,41 @@ * ignores the <code>lockTimeoutMs</code>. */ public class VersionBucket { - public long highest; + private long highest; + + /** + * @param highest the initial value of this bucket highest version. + */ + public VersionBucket(long highest) { + setHighestIfGreater(highest); + } + + /** + * Updates the highest version if the current bucket value is not zero and if the provided value + * is greater than the current bucket value. The caller must synchronize on this bucket when + * calling this method. + */ public void updateHighest(long val) { if (highest != 0) { - highest = Math.max(highest, Math.abs(val)); + setHighestIfGreater(Math.abs(val)); + } + } + + /** + * Sets the highest version if the provided value is greater than the current bucket value. The + * caller must synchronize on this bucket when calling this method. + */ + public void setHighestIfGreater(long val) { + if (val > highest) { + this.highest = val; } } + public long getHighest() { Review Comment: If writers must synchronize, it's probably true that readers should synchronize? Or make this method synchronized? ########## solr/core/src/java/org/apache/solr/update/VersionInfo.java: ########## @@ -284,11 +297,20 @@ public Long getMaxVersionFromIndex(IndexSearcher searcher) throws IOException { } public void seedBucketsWithHighestVersion(long highestVersion) { - for (int i = 0; i < buckets.length; i++) { - // should not happen, but in case other threads are calling updateHighest on the version - // bucket - synchronized (buckets[i]) { - if (buckets[i].highest < highestVersion) buckets[i].highest = highestVersion; + if (buckets == null) { + synchronized (bucketsSync) { + if (buckets == null) { + // Update the highest version seed to use if/when buckets are created. + highestVersionSeed = Math.max(highestVersion, highestVersionSeed); + return; + } + } + } + for (VersionBucket bucket : buckets) { + // Should not happen, but synchronize in case other threads are calling + // updateHighest on the version bucket. + synchronized (bucket) { + bucket.setHighestIfGreater(highestVersion); Review Comment: should the synchronization move to be on setHighestIfGreater ? -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org