Search in sources :

Example 1 with ITreeMutable

use of jetbrains.exodus.tree.ITreeMutable in project xodus by JetBrains.

the class ReadWriteTransaction method doCommit.

Iterable<ExpiredLoggableInfo>[] doCommit(@NotNull final MetaTree.Proto[] out) {
    final Set<Map.Entry<Integer, ITreeMutable>> entries = mutableTrees.entrySet();
    final Set<Map.Entry<Long, Pair<String, ITree>>> removedEntries = removedStores.entrySet();
    final int size = entries.size() + removedEntries.size();
    // noinspection unchecked
    final Iterable<ExpiredLoggableInfo>[] expiredLoggables = new Iterable[size + 1];
    int i = 0;
    final ITreeMutable metaTreeMutable = getMetaTree().tree.getMutableCopy();
    for (final Map.Entry<Long, Pair<String, ITree>> entry : removedEntries) {
        final Pair<String, ITree> value = entry.getValue();
        MetaTree.removeStore(metaTreeMutable, value.getFirst(), entry.getKey());
        expiredLoggables[i++] = TreeMetaInfo.getTreeLoggables(value.getSecond());
    }
    removedStores.clear();
    for (final Map.Entry<String, TreeMetaInfo> entry : createdStores.entrySet()) {
        MetaTree.addStore(metaTreeMutable, entry.getKey(), entry.getValue());
    }
    createdStores.clear();
    final Collection<ExpiredLoggableInfo> last;
    for (final Map.Entry<Integer, ITreeMutable> entry : entries) {
        final ITreeMutable treeMutable = entry.getValue();
        expiredLoggables[i++] = treeMutable.getExpiredLoggables();
        MetaTree.saveTree(metaTreeMutable, treeMutable);
    }
    clearImmutableTrees();
    mutableTrees.clear();
    expiredLoggables[i] = last = metaTreeMutable.getExpiredLoggables();
    out[0] = MetaTree.saveMetaTree(metaTreeMutable, getEnvironment(), last);
    return expiredLoggables;
}
Also used : TreeMetaInfo(jetbrains.exodus.tree.TreeMetaInfo) ITree(jetbrains.exodus.tree.ITree) ITreeMutable(jetbrains.exodus.tree.ITreeMutable) ExpiredLoggableInfo(jetbrains.exodus.log.ExpiredLoggableInfo) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) Pair(jetbrains.exodus.core.dataStructures.Pair)

Example 2 with ITreeMutable

use of jetbrains.exodus.tree.ITreeMutable in project xodus by JetBrains.

the class ReadWriteTransaction method getMutableTree.

@NotNull
ITreeMutable getMutableTree(@NotNull final StoreImpl store) {
    checkIsFinished();
    if (getEnvironment().getEnvironmentConfig().getEnvTxnSingleThreadWrites()) {
        final Thread creatingThread = getCreatingThread();
        if (!creatingThread.equals(Thread.currentThread())) {
            throw new ExodusException("Can't create mutable tree in a thread different from the one which transaction was created in");
        }
    }
    final int structureId = store.getStructureId();
    ITreeMutable result = mutableTrees.get(structureId);
    if (result == null) {
        result = getTree(store).getMutableCopy();
        mutableTrees.put(structureId, result);
    }
    return result;
}
Also used : ITreeMutable(jetbrains.exodus.tree.ITreeMutable) ExodusException(jetbrains.exodus.ExodusException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ITreeMutable

use of jetbrains.exodus.tree.ITreeMutable in project xodus by JetBrains.

the class StoreImpl method putRight.

@Override
public void putRight(@NotNull final Transaction txn, @NotNull final ByteIterable key, @NotNull final ByteIterable value) {
    final ITreeMutable mutableTree = EnvironmentImpl.throwIfReadonly(txn, "Can't put in read-only transaction").getMutableTree(this);
    mutableTree.putRight(key, value);
    TreeCursorMutable.notifyCursors(mutableTree);
}
Also used : ITreeMutable(jetbrains.exodus.tree.ITreeMutable)

Example 4 with ITreeMutable

use of jetbrains.exodus.tree.ITreeMutable in project xodus by JetBrains.

the class ReadWriteTransaction method getTree.

@NotNull
@Override
public ITree getTree(@NotNull final StoreImpl store) {
    checkIsFinished();
    final ITreeMutable result = mutableTrees.get(store.getStructureId());
    if (result == null) {
        return super.getTree(store);
    }
    return result;
}
Also used : ITreeMutable(jetbrains.exodus.tree.ITreeMutable) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ITreeMutable

use of jetbrains.exodus.tree.ITreeMutable in project xodus by JetBrains.

the class ReadWriteTransaction method doCommit.

ExpiredLoggableCollection doCommit(@NotNull final MetaTreeImpl.Proto[] out) {
    final Set<Map.Entry<Integer, ITreeMutable>> entries = mutableTrees.entrySet();
    final Set<Map.Entry<Long, Pair<String, ITree>>> removedEntries = removedStores.entrySet();
    ExpiredLoggableCollection expiredLoggables = ExpiredLoggableCollection.getEMPTY();
    final ITreeMutable metaTreeMutable = getMetaTree().tree.getMutableCopy();
    for (final Map.Entry<Long, Pair<String, ITree>> entry : removedEntries) {
        final Pair<String, ITree> value = entry.getValue();
        MetaTreeImpl.removeStore(metaTreeMutable, value.getFirst(), entry.getKey());
        expiredLoggables = expiredLoggables.mergeWith(TreeMetaInfo.getTreeLoggables(value.getSecond()).trimToSize());
    }
    removedStores.clear();
    for (final Map.Entry<String, TreeMetaInfo> entry : createdStores.entrySet()) {
        MetaTreeImpl.addStore(metaTreeMutable, entry.getKey(), entry.getValue());
    }
    createdStores.clear();
    for (final Map.Entry<Integer, ITreeMutable> entry : entries) {
        final ITreeMutable treeMutable = entry.getValue();
        expiredLoggables = expiredLoggables.mergeWith(treeMutable.getExpiredLoggables().trimToSize());
        MetaTreeImpl.saveTree(metaTreeMutable, treeMutable);
    }
    clearImmutableTrees();
    mutableTrees.clear();
    expiredLoggables = expiredLoggables.mergeWith(metaTreeMutable.getExpiredLoggables().trimToSize());
    out[0] = MetaTreeImpl.saveMetaTree(metaTreeMutable, getEnvironment(), expiredLoggables);
    return expiredLoggables;
}
Also used : ExpiredLoggableCollection(jetbrains.exodus.tree.ExpiredLoggableCollection) TreeMetaInfo(jetbrains.exodus.tree.TreeMetaInfo) ITree(jetbrains.exodus.tree.ITree) ITreeMutable(jetbrains.exodus.tree.ITreeMutable) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) Pair(jetbrains.exodus.core.dataStructures.Pair)

Aggregations

ITreeMutable (jetbrains.exodus.tree.ITreeMutable)5 Pair (jetbrains.exodus.core.dataStructures.Pair)2 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)2 ITree (jetbrains.exodus.tree.ITree)2 TreeMetaInfo (jetbrains.exodus.tree.TreeMetaInfo)2 NotNull (org.jetbrains.annotations.NotNull)2 ExodusException (jetbrains.exodus.ExodusException)1 ExpiredLoggableInfo (jetbrains.exodus.log.ExpiredLoggableInfo)1 ExpiredLoggableCollection (jetbrains.exodus.tree.ExpiredLoggableCollection)1