Search in sources :

Example 11 with ExodusException

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;
    }
}
Also used : EnvironmentImpl(jetbrains.exodus.env.EnvironmentImpl) ExodusException(jetbrains.exodus.ExodusException)

Example 12 with ExodusException

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();
    }
}
Also used : EnvironmentImpl(jetbrains.exodus.env.EnvironmentImpl) ExodusException(jetbrains.exodus.ExodusException)

Example 13 with ExodusException

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);
}
Also used : FileDataReader(jetbrains.exodus.io.FileDataReader) FileDataWriter(jetbrains.exodus.io.FileDataWriter) File(java.io.File) ExodusException(jetbrains.exodus.ExodusException) Test(org.junit.Test)

Example 14 with ExodusException

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();
}
Also used : ExodusException(jetbrains.exodus.ExodusException)

Example 15 with ExodusException

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);
}
Also used : CompoundByteIterable(jetbrains.exodus.CompoundByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ExodusException(jetbrains.exodus.ExodusException)

Aggregations

ExodusException (jetbrains.exodus.ExodusException)21 File (java.io.File)6 IOException (java.io.IOException)6 RandomAccessFile (java.io.RandomAccessFile)3 CriticalSection (jetbrains.exodus.core.execution.locks.CriticalSection)3 ByteIterable (jetbrains.exodus.ByteIterable)2 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)2 Job (jetbrains.exodus.core.execution.Job)2 EnvironmentImpl (jetbrains.exodus.env.EnvironmentImpl)2 FileDataReader (jetbrains.exodus.io.FileDataReader)2 FileDataWriter (jetbrains.exodus.io.FileDataWriter)2 SharedRandomAccessFile (jetbrains.exodus.util.SharedRandomAccessFile)2 UncheckedIOException (java.io.UncheckedIOException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 FileChannel (java.nio.channels.FileChannel)1 Map (java.util.Map)1 Condition (java.util.concurrent.locks.Condition)1 Pair (jetbrains.exodus.core.dataStructures.Pair)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 LongSet (jetbrains.exodus.core.dataStructures.hash.LongSet)1