提交 b25aed0e authored 作者: Andrei Tokar's avatar Andrei Tokar

fix deadlock between compact from background and database closure in foreground

Preserve original exception in CreateTable and AlterTableAddConstraint.
上级 a71a0e3d
...@@ -77,8 +77,12 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -77,8 +77,12 @@ public class AlterTableAddConstraint extends SchemaCommand {
try { try {
return tryUpdate(); return tryUpdate();
} catch (DbException e) { } catch (DbException e) {
for (Index index : createdIndexes) { try {
session.getDatabase().removeSchemaObject(session, index); for (Index index : createdIndexes) {
session.getDatabase().removeSchemaObject(session, index);
}
} catch (Throwable ex) {
e.addSuppressed(ex);
} }
throw e; throw e;
} finally { } finally {
......
...@@ -159,10 +159,14 @@ public class CreateTable extends CommandWithColumns { ...@@ -159,10 +159,14 @@ public class CreateTable extends CommandWithColumns {
} }
} }
} catch (DbException e) { } catch (DbException e) {
db.checkPowerOff(); try {
db.removeSchemaObject(session, table); db.checkPowerOff();
if (!transactional) { db.removeSchemaObject(session, table);
session.commit(true); if (!transactional) {
session.commit(true);
}
} catch (Throwable ex) {
e.addSuppressed(ex);
} }
throw e; throw e;
} }
......
...@@ -293,7 +293,7 @@ public class MVStore { ...@@ -293,7 +293,7 @@ public class MVStore {
/** /**
* Simple lock to ensure that no more than one compaction runs at any given time * Simple lock to ensure that no more than one compaction runs at any given time
*/ */
private final Object compactSync = new Object(); private boolean compactInProgress;
private volatile IllegalStateException panicException; private volatile IllegalStateException panicException;
...@@ -1920,23 +1920,22 @@ public class MVStore { ...@@ -1920,23 +1920,22 @@ public class MVStore {
if (!reuseSpace) { if (!reuseSpace) {
return false; return false;
} }
synchronized (compactSync) { checkOpen();
checkOpen(); // We can't wait fo lock here, because if called from the background thread,
ArrayList<Chunk> old; // it might go into deadlock with concurrent database closure
// We can't wait fo lock here, because if called from the background thread, // and attempt to stop this thread.
// it might go into deadlock with concurrent database closure if (storeLock.tryLock() && !compactInProgress) {
// and attempt to stop this thread. try {
if (storeLock.tryLock()) { compactInProgress = true;
try { ArrayList<Chunk> old = findOldChunks(targetFillRate, write);
old = findOldChunks(targetFillRate, write); if (old == null || old.isEmpty()) {
if (old == null || old.isEmpty()) { return false;
return false;
}
compactRewrite(old);
return true;
} finally {
storeLock.unlock();
} }
compactRewrite(old);
return true;
} finally {
compactInProgress = false;
storeLock.unlock();
} }
} }
return false; return false;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论