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