You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2015/04/23 00:33:47 UTC

accumulo git commit: ACCUMULO-3745 Always obtain locks in same order in SourceSwitching iter

Repository: accumulo
Updated Branches:
  refs/heads/1.5 fca7cb409 -> 95e234c7e


ACCUMULO-3745 Always obtain locks in same order in SourceSwitching iter

[~ecn] and I sat together and fixed this.  We are not sure how to test.  We
both visually analyzed all locking to ensure it was done in the same order.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/95e234c7
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/95e234c7
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/95e234c7

Branch: refs/heads/1.5
Commit: 95e234c7e468d61211d6f1d65ee1955d2bf53a9b
Parents: fca7cb4
Author: Keith Turner <kt...@apache.org>
Authored: Wed Apr 22 15:05:06 2015 -0400
Committer: Keith Turner <kt...@apache.org>
Committed: Wed Apr 22 15:05:06 2015 -0400

----------------------------------------------------------------------
 .../system/SourceSwitchingIterator.java         | 29 +++++++++++++-------
 1 file changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/95e234c7/core/src/main/java/org/apache/accumulo/core/iterators/system/SourceSwitchingIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/system/SourceSwitchingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/system/SourceSwitchingIterator.java
index 6c40176..7684352 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/system/SourceSwitchingIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/system/SourceSwitchingIterator.java
@@ -69,11 +69,11 @@ public class SourceSwitchingIterator implements SortedKeyValueIterator<Key,Value
     this.source = source;
     this.onlySwitchAfterRow = onlySwitchAfterRow;
     this.copies = copies;
-    copies.add(this);
   }
 
   public SourceSwitchingIterator(DataSource source, boolean onlySwitchAfterRow) {
     this(source, onlySwitchAfterRow, Collections.synchronizedList(new ArrayList<SourceSwitchingIterator>()));
+    copies.add(this);
   }
 
   public SourceSwitchingIterator(DataSource source) {
@@ -81,8 +81,14 @@ public class SourceSwitchingIterator implements SortedKeyValueIterator<Key,Value
   }
 
   @Override
-  public synchronized SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) {
-    return new SourceSwitchingIterator(source.getDeepCopyDataSource(env), onlySwitchAfterRow, copies);
+  public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) {
+    synchronized (copies) {
+      synchronized(this){
+        SourceSwitchingIterator ssi = new SourceSwitchingIterator(source.getDeepCopyDataSource(env), onlySwitchAfterRow, copies);
+        copies.add(ssi);
+        return ssi;
+      }
+    }
   }
 
   @Override
@@ -186,14 +192,17 @@ public class SourceSwitchingIterator implements SortedKeyValueIterator<Key,Value
   }
 
   @Override
-  public synchronized void setInterruptFlag(AtomicBoolean flag) {
-    if (copies.size() != 1)
-      throw new IllegalStateException("setInterruptFlag() called after deep copies made " + copies.size());
+  public void setInterruptFlag(AtomicBoolean flag) {
+    synchronized (copies) {
+      synchronized (this) {
+        if (copies.size() != 1)
+          throw new IllegalStateException("setInterruptFlag() called after deep copies made " + copies.size());
 
-    if (iter != null)
-      ((InterruptibleIterator) iter).setInterruptFlag(flag);
+        if (iter != null)
+          ((InterruptibleIterator) iter).setInterruptFlag(flag);
 
-    source.setInterruptFlag(flag);
+        source.setInterruptFlag(flag);
+      }
+    }
   }
-
 }