Search in sources :

Example 1 with ITree

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

the class TransactionBase method getTree.

@NotNull
public ITree getTree(@NotNull final StoreImpl store) {
    checkIsFinished();
    final int structureId = store.getStructureId();
    ITree result = immutableTrees.get(structureId);
    if (result == null) {
        result = store.openImmutableTree(getMetaTree());
        synchronized (immutableTrees) {
            immutableTrees.put(structureId, result);
        }
    }
    return result;
}
Also used : ITree(jetbrains.exodus.tree.ITree) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ITree

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

the class ReadWriteTransaction method storeRemoved.

void storeRemoved(@NotNull final StoreImpl store) {
    checkIsFinished();
    super.storeRemoved(store);
    final int structureId = store.getStructureId();
    final ITree tree = store.openImmutableTree(getMetaTree());
    removedStores.put(structureId, new Pair<>(store.getName(), tree));
    mutableTrees.remove(structureId);
}
Also used : ITree(jetbrains.exodus.tree.ITree)

Example 3 with ITree

use of jetbrains.exodus.tree.ITree 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 4 with ITree

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

the class StoreImpl method openImmutableTree.

ITree openImmutableTree(@NotNull final MetaTree metaTree) {
    final int structureId = getStructureId();
    final long upToDateRootAddress = metaTree.getRootAddress(structureId);
    final boolean hasDuplicates = metaInfo.hasDuplicates();
    final boolean treeIsEmpty = upToDateRootAddress == Loggable.NULL_ADDRESS;
    final Log log = environment.getLog();
    final ITree result;
    if (!metaInfo.isKeyPrefixing()) {
        final BTreeBalancePolicy balancePolicy = environment.getBTreeBalancePolicy();
        result = treeIsEmpty ? new BTreeEmpty(log, balancePolicy, hasDuplicates, structureId) : new BTree(log, balancePolicy, upToDateRootAddress, hasDuplicates, structureId);
    } else {
        if (treeIsEmpty) {
            result = new PatriciaTreeEmpty(log, structureId, hasDuplicates);
        } else {
            result = hasDuplicates ? new PatriciaTreeWithDuplicates(log, upToDateRootAddress, structureId) : new PatriciaTree(log, upToDateRootAddress, structureId);
        }
    }
    return result;
}
Also used : PatriciaTree(jetbrains.exodus.tree.patricia.PatriciaTree) BTreeBalancePolicy(jetbrains.exodus.tree.btree.BTreeBalancePolicy) Log(jetbrains.exodus.log.Log) BTree(jetbrains.exodus.tree.btree.BTree) BTreeEmpty(jetbrains.exodus.tree.btree.BTreeEmpty) ITree(jetbrains.exodus.tree.ITree) PatriciaTreeEmpty(jetbrains.exodus.tree.patricia.PatriciaTreeEmpty) PatriciaTreeWithDuplicates(jetbrains.exodus.tree.patricia.PatriciaTreeWithDuplicates)

Example 5 with ITree

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

the class BTreeStructureIdTest method assertStructureIdNotEqual.

public static void assertStructureIdNotEqual(long firstAddress, long secondAddress) {
    ITree firstImTree = new BTree(log, firstAddress, false, 3);
    ITree secondImTree = new BTree(log, secondAddress, false, 3);
    LongIterator it = firstImTree.addressIterator();
    LongHashSet firstSet = new LongHashSet();
    LongHashSet secondSet = new LongHashSet();
    while (it.hasNext()) firstSet.add(log.read(it.next()).getStructureId());
    it = secondImTree.addressIterator();
    while (it.hasNext()) secondSet.add(log.read(it.next()).getStructureId());
    for (long firstStructureId : firstSet) {
        for (long seconfStrutureId : secondSet) {
            if (firstStructureId == seconfStrutureId)
                throw new AssertionError("Structure ids are equal!");
        }
    }
}
Also used : LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) ITree(jetbrains.exodus.tree.ITree) LongIterator(jetbrains.exodus.tree.LongIterator)

Aggregations

ITree (jetbrains.exodus.tree.ITree)7 LongIterator (jetbrains.exodus.tree.LongIterator)2 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)1 ByteIterable (jetbrains.exodus.ByteIterable)1 Pair (jetbrains.exodus.core.dataStructures.Pair)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 LongHashSet (jetbrains.exodus.core.dataStructures.hash.LongHashSet)1 ExpiredLoggableInfo (jetbrains.exodus.log.ExpiredLoggableInfo)1 Log (jetbrains.exodus.log.Log)1 ITreeMutable (jetbrains.exodus.tree.ITreeMutable)1 TreeMetaInfo (jetbrains.exodus.tree.TreeMetaInfo)1 BTree (jetbrains.exodus.tree.btree.BTree)1 BTreeBalancePolicy (jetbrains.exodus.tree.btree.BTreeBalancePolicy)1 BTreeEmpty (jetbrains.exodus.tree.btree.BTreeEmpty)1 PatriciaTree (jetbrains.exodus.tree.patricia.PatriciaTree)1 PatriciaTreeEmpty (jetbrains.exodus.tree.patricia.PatriciaTreeEmpty)1 PatriciaTreeWithDuplicates (jetbrains.exodus.tree.patricia.PatriciaTreeWithDuplicates)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1