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;
}
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);
}
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;
}
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;
}
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!");
}
}
}
Aggregations