You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/04/28 12:28:44 UTC

svn commit: r1590587 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store: MockDirectoryWrapper.java MockLockFactoryWrapper.java

Author: mikemccand
Date: Mon Apr 28 10:28:43 2014
New Revision: 1590587

URL: http://svn.apache.org/r1590587
Log:
when MDW fails to close because of a still-held lock, show the stack trace where the lock was obtained

Modified:
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1590587&r1=1590586&r2=1590587&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java Mon Apr 28 10:28:43 2014
@@ -79,7 +79,7 @@ public class MockDirectoryWrapper extend
   private Set<String> unSyncedFiles;
   private Set<String> createdFiles;
   private Set<String> openFilesForWrite = new HashSet<>();
-  Set<String> openLocks = Collections.synchronizedSet(new HashSet<String>());
+  Map<String,Exception> openLocks = Collections.synchronizedMap(new HashMap<String,Exception>());
   volatile boolean crashed;
   private ThrottledIndexOutput throttledOutput;
   private Throttling throttling = Throttling.SOMETIMES;
@@ -655,14 +655,20 @@ public class MockDirectoryWrapper extend
       // print the first one as its very verbose otherwise
       Exception cause = null;
       Iterator<Exception> stacktraces = openFileHandles.values().iterator();
-      if (stacktraces.hasNext())
+      if (stacktraces.hasNext()) {
         cause = stacktraces.next();
+      }
       // RuntimeException instead of IOException because
       // super() does not throw IOException currently:
       throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open files: " + openFiles, cause);
     }
     if (openLocks.size() > 0) {
-      throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks);
+      Exception cause = null;
+      Iterator<Exception> stacktraces = openLocks.values().iterator();
+      if (stacktraces.hasNext()) {
+        cause = stacktraces.next();
+      }
+      throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks, cause);
     }
 
     isOpen = false;

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java?rev=1590587&r1=1590586&r2=1590587&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java Mon Apr 28 10:28:43 2014
@@ -70,7 +70,8 @@ public class MockLockFactoryWrapper exte
     @Override
     public boolean obtain() throws IOException {
       if (delegateLock.obtain()) {
-        dir.openLocks.add(name);
+        assert (delegate instanceof NoLockFactory) || dir.openLocks.containsKey(name) == false;
+        dir.openLocks.put(name, new RuntimeException("lock \"" + name + "\" was not released"));
         return true;
       } else {
         return false;