Apache Lucene open-source search software
when MDW fails to close because of a still-held lock, show the stack trace where the lock was obtained
Michael McCandless6bc788b1a0f6
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.javaindex 371a0fd5f95..048179eb5e2 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java@@ -79,7 +79,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {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 extends BaseDirectoryWrapper {// print the first one as its very verbose otherwiseException 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;diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.javaindex 23759680d1b..5791043617e 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockLockFactoryWrapper.java@@ -70,7 +70,8 @@ public class MockLockFactoryWrapper extends LockFactory {@Overridepublic 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;