Search in sources :

Example 86 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class JMHStringBindingTest method stringBinding2string.

@Benchmark
@Warmup(iterations = 2, time = 1)
@Measurement(iterations = 3, time = 1)
@Fork(4)
public String[] stringBinding2string() {
    String[] result = new String[STRINGS_COUNT];
    int i = 0;
    for (ByteIterable array : byteIterables) {
        result[i++] = StringBinding.entryToString(array);
    }
    return result;
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable)

Example 87 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class JMHEnvTokyoCabinetReadBenchmark method randomRead.

@Benchmark
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = WARMUP_ITERATIONS)
@Measurement(iterations = MEASUREMENT_ITERATIONS)
@Fork(FORKS)
public void randomRead(final Blackhole bh) {
    env.executeInReadonlyTransaction(txn -> {
        try (Cursor c = store.openCursor(txn)) {
            for (final ByteIterable key : randomKeys) {
                c.getSearchKey(key);
                consumeBytes(bh, c.getValue());
            }
        }
    });
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) Cursor(jetbrains.exodus.env.Cursor) TokyoCabinetBenchmark(jetbrains.exodus.benchmark.TokyoCabinetBenchmark)

Example 88 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class CursorImpl method deleteCurrent.

@Override
public boolean deleteCurrent() {
    final ReadWriteTransaction txn = EnvironmentImpl.throwIfReadonly(this.txn, "Can't delete a key/value pair of cursor in read-only transaction");
    if (treeCursor == null) {
        treeCursor = txn.getMutableTree(store).openCursor();
    } else {
        if (!treeCursor.isMutable()) {
            final ByteIterable key = treeCursor.getKey();
            final ByteIterable value = treeCursor.getValue();
            final ITreeCursor newCursor = txn.getMutableTree(store).openCursor();
            if (newCursor.getSearchBoth(key, value)) {
                // navigated to same pair, ready to delete
                treeCursor = newCursor;
            } else {
                throw new ConcurrentModificationException(CANT_DELETE_MODIFIED_MSG);
            }
        }
    }
    return treeCursor.deleteCurrent();
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ByteIterable(jetbrains.exodus.ByteIterable) ITreeCursor(jetbrains.exodus.tree.ITreeCursor)

Example 89 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class StoreImpl method get.

@Override
@Nullable
public ByteIterable get(@NotNull final Transaction txn, @NotNull final ByteIterable key) {
    final TransactionBase tx = (TransactionBase) txn;
    final ITree tree = tx.getTree(this);
    if (!tx.isDisableStoreGetCache()) {
        final StoreGetCache storeGetCache = environment.getStoreGetCache();
        if (storeGetCache != null) {
            final long treeRootAddress = tree.getRootAddress();
            final boolean useStoreGetCache = treeRootAddress != Loggable.NULL_ADDRESS && tree.getSize() >= storeGetCache.getMinTreeSize();
            // if neither tree is empty nor mutable
            if (useStoreGetCache) {
                ByteIterable result = storeGetCache.tryKey(treeRootAddress, key);
                if (result != null) {
                    return result == NULL_CACHED_VALUE ? null : result;
                }
                result = tree.get(key);
                final ArrayByteIterable cachedValue;
                if (result == null) {
                    cachedValue = NULL_CACHED_VALUE;
                } else if (result instanceof ArrayByteIterable) {
                    cachedValue = (ArrayByteIterable) result;
                } else {
                    cachedValue = new ArrayByteIterable(result);
                }
                if (cachedValue.getLength() <= storeGetCache.getMaxValueSize()) {
                    storeGetCache.cacheObject(treeRootAddress, key, cachedValue);
                }
                return result;
            }
        }
    }
    return tree.get(key);
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ITree(jetbrains.exodus.tree.ITree) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class BTreeMutable method save.

@Override
public long save() {
    // dfs, save leafs, then bottoms, then internals, then root
    final byte type = root.isBottom() ? BOTTOM_ROOT : INTERNAL_ROOT;
    final Log log = getLog();
    final ByteIterable savedData = root.getData();
    final ByteIterable[] iterables = { CompressedUnsignedLongByteIterable.getIterable(size), savedData };
    return log.write(type, structureId, new CompoundByteIterable(iterables));
}
Also used : CompoundByteIterable(jetbrains.exodus.CompoundByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) CompoundByteIterable(jetbrains.exodus.CompoundByteIterable)

Aggregations

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