Search in sources :

Example 41 with ByteIterable

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;
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with ByteIterable

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");
}
Also used : PersistentStoreTransaction(jetbrains.exodus.entitystore.PersistentStoreTransaction) ByteIterable(jetbrains.exodus.ByteIterable)

Example 43 with ByteIterable

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();
}
Also used : INode(jetbrains.exodus.tree.INode) ByteIterable(jetbrains.exodus.ByteIterable) Test(org.junit.Test)

Example 44 with ByteIterable

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();
}
Also used : RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Loggable(jetbrains.exodus.log.Loggable) ByteIterable(jetbrains.exodus.ByteIterable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 45 with ByteIterable

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();
}
Also used : RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) ByteIterable(jetbrains.exodus.ByteIterable) Test(org.junit.Test)

Aggregations

ByteIterable (jetbrains.exodus.ByteIterable)86 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)45 Test (org.junit.Test)26 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)15 Nullable (org.jetbrains.annotations.Nullable)11 ITreeCursor (jetbrains.exodus.tree.ITreeCursor)8 Cursor (jetbrains.exodus.env.Cursor)7 RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)7 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)6 Store (jetbrains.exodus.env.Store)4 TreeSet (java.util.TreeSet)3 Transaction (jetbrains.exodus.env.Transaction)3 Exchange (com.persistit.Exchange)2 ExodusException (jetbrains.exodus.ExodusException)2 TokyoCabinetBenchmark (jetbrains.exodus.benchmark.TokyoCabinetBenchmark)2 Pair (jetbrains.exodus.core.dataStructures.Pair)2 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)2 PersistentLongSet (jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet)2 PersistentStoreTransaction (jetbrains.exodus.entitystore.PersistentStoreTransaction)2 Loggable (jetbrains.exodus.log.Loggable)2