bruno-roustant commented on code in PR #2021:
URL: https://github.com/apache/solr/pull/2021#discussion_r1366628537


##########
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:
   I'll use a volatile. This fixes a potential multi-thread memory visibility 
bug in the existing code.
   Actually it's another hint that makes me wonder whether this version 
optimization has any perf improvement impact. I'll run the CloudIndexing 
benchmark to try to see something when I disable it.



-- 
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

Reply via email to