You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/06/13 04:29:23 UTC

[GitHub] [accumulo] ctubbsii commented on a change in pull request #1201: fix #1123 replace observing config with continual derivation

ctubbsii commented on a change in pull request #1201: fix #1123 replace observing config with continual derivation
URL: https://github.com/apache/accumulo/pull/1201#discussion_r293191163
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
 ##########
 @@ -435,6 +438,60 @@ Integer getDeprecatedScanThreads(String name) {
     return null;
   }
 
+  private static class RefCount<T> {
+    T obj;
+    long count;
+
+    RefCount(long c, T r) {
+      this.count = c;
+      this.obj = r;
+    }
+  }
+
+  private class Deriver<T> implements Supplier<T> {
+
+    private AtomicReference<RefCount<T>> refref;
+    private Function<AccumuloConfiguration,T> factory;
+
+    Deriver(Function<AccumuloConfiguration,T> factory) {
+      this.factory = factory;
+      refref = new AtomicReference<>();
+    }
+
+    @Override
+    public T get() {
+      RefCount<T> rc = refref.get();
+
+      long uc = getUpdateCount();
+
+      if (rc == null || rc.count != uc) {
+        T newObj = factory.apply(AccumuloConfiguration.this);
+
+        RefCount<T> nrc = new RefCount<>(uc, newObj);
+        refref.compareAndSet(rc, nrc);
 
 Review comment:
   If this returns false, it means the configuration changed while we were executing, and we're now going to return a stale derived object. Perhaps we should re-apply the function in a `boolean success; do { ... success = refref.compareAndSet(rc, nrc); } while (!success);` loop?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services