use of jetbrains.exodus.ExodusException in project meghanada-server by mopemope.
the class ProjectDatabase method close.
private synchronized void close() {
if (nonNull(this.entityStore)) {
try {
EnvironmentImpl environment = (EnvironmentImpl) this.entityStore.getEnvironment();
environment.flushAndSync();
this.entityStore.close();
} catch (ExodusException e) {
// wait transaction
try {
Thread.sleep(1000 * 3);
} catch (InterruptedException e1) {
log.catching(e1);
}
this.entityStore.close();
}
this.entityStore = null;
}
if (nonNull(this.environment)) {
this.environment.close();
this.environment = null;
}
}
use of jetbrains.exodus.ExodusException in project meghanada-server by mopemope.
the class ProjectDatabase method reset.
public static void reset() {
if (projectDatabase != null) {
if (nonNull(projectDatabase.entityStore)) {
try {
EnvironmentImpl environment = (EnvironmentImpl) projectDatabase.entityStore.getEnvironment();
environment.flushAndSync();
projectDatabase.entityStore.close();
} catch (ExodusException e) {
// wait transaction
try {
Thread.sleep(1000 * 3);
} catch (InterruptedException e1) {
log.catching(e1);
}
projectDatabase.entityStore.close();
}
projectDatabase.entityStore = null;
}
if (nonNull(projectDatabase.environment)) {
projectDatabase.environment.close();
projectDatabase.environment = null;
}
projectDatabase.open();
}
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class EnvironmentLockTest method testAlreadyLockedEnvironment.
@Test
public void testAlreadyLockedEnvironment() throws IOException {
boolean exOnCreate = false;
Environment first = null;
try {
final File dir = getEnvDirectory();
first = Environments.newInstance(LogConfig.create(new FileDataReader(dir, 16), new FileDataWriter(dir)), EnvironmentConfig.DEFAULT);
} catch (ExodusException ex) {
// Environment already created on startup!
exOnCreate = true;
}
if (first != null)
first.close();
Assert.assertTrue(exOnCreate);
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class LeafNodeDup method doReclaim.
@Override
public void doReclaim(@NotNull final BTreeReclaimTraverser context, final int leafIndex) {
final long keyAddress = context.currentNode.getKeyAddress(leafIndex);
final BTreeDupMutable tree;
final BaseLeafNodeMutable mutable;
final BTreeMutable mainTree = context.mainTree;
if (keyAddress < 0) {
mutable = ((BasePageMutable) context.currentNode).keys[leafIndex];
if (mutable.isDup()) {
tree = ((LeafNodeDupMutable) mutable).tree;
} else {
// current node is duplicate no more
return;
}
} else if (keyAddress == getAddress()) {
final BasePageMutable node = context.currentNode.getMutableCopy(mainTree);
final LeafNodeDupMutable converted = LeafNodeDupMutable.convert(this, mainTree);
mainTree.addExpiredLoggable(keyAddress);
tree = converted.tree;
mutable = converted;
node.set(leafIndex, mutable, null);
context.wasReclaim = true;
context.setPage(node);
} else {
final RandomAccessLoggable upToDate = mainTree.getLoggable(keyAddress);
switch(upToDate.getType()) {
case BTreeBase.LEAF_DUP_BOTTOM_ROOT:
case BTreeBase.LEAF_DUP_INTERNAL_ROOT:
// indicates that loggable was not updated
mutable = null;
tree = new LeafNodeDup(mainTree, upToDate).getTreeCopyMutable();
tree.mainTree = mainTree;
break;
case BTreeBase.LEAF:
// current node is duplicate no more
return;
default:
throw new ExodusException("Unexpected loggable type " + upToDate.getType());
}
}
// TODO: implement mutable lower bound to avoid allocations (yapavel knows how)
final BTreeReclaimTraverser dupStack = new BTreeReclaimTraverser(tree);
for (final RandomAccessLoggable loggable : context.dupLeafsLo) {
switch(loggable.getType()) {
case BTreeBase.DUP_LEAF:
new LeafNode(loggable).reclaim(dupStack);
break;
case BTreeBase.DUP_BOTTOM:
tree.reclaimBottom(loggable, dupStack);
break;
case BTreeBase.DUP_INTERNAL:
tree.reclaimInternal(loggable, dupStack);
break;
default:
throw new ExodusException("Unexpected loggable type " + loggable.getType());
}
}
// TODO: less copy-paste
for (final RandomAccessLoggable loggable : context.dupLeafsHi) {
switch(loggable.getType()) {
case BTreeBase.DUP_LEAF:
new LeafNode(loggable).reclaim(dupStack);
break;
case BTreeBase.DUP_BOTTOM:
tree.reclaimBottom(loggable, dupStack);
break;
case BTreeBase.DUP_INTERNAL:
tree.reclaimInternal(loggable, dupStack);
break;
default:
throw new ExodusException("Unexpected loggable type " + loggable.getType());
}
}
while (dupStack.canMoveUp()) {
// wire up mutated stuff
dupStack.popAndMutate();
}
if (dupStack.wasReclaim && mutable == null) {
// was reclaim in sub-tree
mainTree.addExpiredLoggable(keyAddress);
final BasePageMutable node = context.currentNode.getMutableCopy(mainTree);
node.set(leafIndex, new LeafNodeDupMutable(tree), null);
context.wasReclaim = true;
context.setPage(node);
}
// TODO: remove? dupStack.clear();
}
use of jetbrains.exodus.ExodusException in project xodus by JetBrains.
the class BTreeMutable method putRight.
@Override
public void putRight(@NotNull INode ln) {
final ByteIterable value = ln.getValue();
if (value == null) {
throw new ExodusException("Value can't be null");
}
putRight(ln.getKey(), value);
}
Aggregations