when MDW fails to close because of a still-held lock, show the stack trace where the lock was obtained

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1590587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-04-28 10:28:43 +00:00
parent b2a01a6504
commit 6bc788b1a0
2 changed files with 11 additions and 4 deletions

View File

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

View File

@ -70,7 +70,8 @@ public class MockLockFactoryWrapper extends LockFactory {
@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;