use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class VirtualFileSystem method openFile.
/**
* Returns existing {@linkplain File} with specified path or creates the new one if {@code create} is {@code true},
* otherwise returns {@code null}. If {@code create} is {@code true} it never returns {@code null}.
*
* @param txn {@linkplain Transaction} instance
* @param path file path
* @param create {@code true} if new file creation is allowed
* @return existing or newly created {@linkplain File} if if {@code create} is {@code true}, or {@code null}
* @see File
*/
@Nullable
public File openFile(@NotNull final Transaction txn, @NotNull final String path, boolean create) {
final ArrayByteIterable key = StringBinding.stringToEntry(path);
final ByteIterable value = pathnames.get(txn, key);
if (value != null) {
return new File(path, value);
}
if (create) {
return createFile(txn, path);
}
return null;
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class PropertiesTable method put.
/**
* Setter for property value. Doesn't affect entity version and doesn't
* invalidate any of the cached entity iterables.
*
* @param localId entity local id.
* @param value property value.
* @param oldValue property old value
* @param propertyId property id
*/
public void put(@NotNull final PersistentStoreTransaction txn, final long localId, @NotNull final ByteIterable value, @Nullable final ByteIterable oldValue, final int propertyId, @NotNull final ComparableValueType type) {
final Store valueIdx = getOrCreateValueIndex(txn, propertyId);
final ByteIterable key = PropertyKey.propertyKeyToEntry(new PropertyKey(localId, propertyId));
final Transaction envTxn = txn.getEnvironmentTransaction();
primaryStore.put(envTxn, key, value);
final ByteIterable secondaryValue = LongBinding.longToCompressedEntry(localId);
boolean success;
if (oldValue == null) {
success = allPropsIndex.put(envTxn, IntegerBinding.intToCompressedEntry(propertyId), secondaryValue);
} else {
success = deleteFromStore(envTxn, valueIdx, secondaryValue, createSecondaryKeys(store.getPropertyTypes(), oldValue, type));
}
if (success) {
for (final ByteIterable secondaryKey : createSecondaryKeys(store.getPropertyTypes(), value, type)) {
valueIdx.put(envTxn, secondaryKey, secondaryValue);
}
}
checkStatus(success, "Failed to put");
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class BTreeDuplicatesExpiredAddressesTest method testBulkDeleteByKey.
@Test
public void testBulkDeleteByKey() throws IOException {
tm = new BTreeEmpty(log, createTestSplittingPolicy(), true, 1).getMutableCopy();
ByteIterable[] keys = new ByteIterable[1000];
for (int i = 0; i < 1000; i++) {
INode node = kv(i, "value");
getTreeMutable().put(node);
getTreeMutable().put(kv(i, "value2"));
getTreeMutable().put(kv(i, "value3"));
getTreeMutable().put(kv(i, "value4"));
getTreeMutable().put(kv(i, "value5"));
getTreeMutable().put(kv(i, "value6"));
getTreeMutable().put(kv(i, "value7"));
getTreeMutable().put(kv(i, "value8"));
keys[i] = node.getKey();
}
// Expired: none
checkExpiredAddress(tm, 0);
long address = saveTree();
t = new BTree(log, address, true, 1);
tm = getTree().getMutableCopy();
long addresses = countNodes(getTreeMutable());
for (int i = 0; i < 1000; i++) {
tm.delete(keys[i]);
}
checkExpiredAddress(tm, addresses);
saveTree();
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class BTreeReclaimTest method testDupLeaf.
@Test
public void testDupLeaf() {
int p;
int u;
long rootAddress = initDup(p = 10, u = 100);
tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy();
final ByteIterable key = key(0);
final ILeafNode savedLeaf = getTree().getRoot().get(key);
Assert.assertNotNull(savedLeaf);
final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeaf.getAddress());
Assert.assertTrue(tm.reclaim(iter.next(), iter));
final AddressIterator addressIterator = getTreeAddresses(getTree());
while (addressIterator.hasNext()) {
final long address = addressIterator.next();
isAffected(log.read(address), key, (BTreeTraverser) addressIterator.getTraverser());
final Loggable loggable = log.read(address);
if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, key, BTreeTraverser.getTraverserNoDup(addressIterator))) {
assertAffected(getTreeMutable(), getTree(), loggable, key);
}
}
rootAddress = saveTree();
checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy(), p, u).run();
}
use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.
the class BTreeReclaimTest method testPageDup.
@Test
public void testPageDup() {
int p;
int u;
long rootAddress = initDup(p = 10, u = 100);
tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy();
final ByteIterable key = key(0);
final ByteIterable value = value("v0#10");
final LeafNodeDup dupLeaf = (LeafNodeDup) getTree().getRoot().get(key);
Assert.assertNotNull(dupLeaf);
final BTreeBase dt = dupLeaf.tree;
final ILeafNode savedLeaf = dt.getRoot().get(value);
Assert.assertNotNull(savedLeaf);
final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeaf.getAddress());
RandomAccessLoggable loggable = iter.next();
while (loggable.getType() != BTreeBase.DUP_INTERNAL) {
loggable = iter.next();
}
final BasePage page = dt.loadPage(loggable.getAddress());
Assert.assertTrue(tm.reclaim(loggable, iter));
final AddressIterator addressIterator = getTreeAddresses(getTree());
final LeafNodeDupMutable dupLeafMutable = (LeafNodeDupMutable) getTreeMutable().getRoot().get(key);
Assert.assertNotNull(dupLeafMutable);
final BTreeMutable dtm = dupLeafMutable.tree;
while (addressIterator.hasNext()) {
final long address = addressIterator.next();
loggable = log.read(address);
if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, value, BTreeTraverser.getTraverserNoDup(addressIterator))) {
assertAffected(dtm, dt, loggable, page, (BTreeTraverser) addressIterator.getTraverser());
}
}
checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy(), p, u).run();
}
Aggregations