Search in sources :

Example 36 with ByteIterable

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

the class PersistentSequentialDictionary method getOrAllocateId.

public int getOrAllocateId(@NotNull final TxnProvider txnProvider, @NotNull final String name) {
    Integer result = cache.get(name);
    if (result != null && result >= 0) {
        return result;
    }
    synchronized (lock) {
        result = cache.get(name);
        if (result != null && result >= 0) {
            return result;
        }
        final ByteIterable nameEntry = StringBinding.stringToEntry(name);
        final PersistentStoreTransaction txn = txnProvider.getTransaction();
        final ByteIterable idEntry = table.get(txn.getEnvironmentTransaction(), nameEntry);
        final int id = idEntry == null ? (int) sequence.increment() : IntegerBinding.compressedEntryToInt(idEntry);
        putIdUnsafe(name, id);
        if (idEntry == null) {
            operationsLog.add(new DictionaryOperation() {

                @Override
                public void persist(final Transaction txn) {
                    table.put(txn, nameEntry, IntegerBinding.intToCompressedEntry(id));
                }
            });
            created(txn, id);
        }
        return id;
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) ByteIterable(jetbrains.exodus.ByteIterable)

Example 37 with ByteIterable

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

the class JMHPersistItTokyoCabinetBenchmarkBase method writeSuccessiveKeys.

void writeSuccessiveKeys(@NotNull final Exchange store) throws PersistitException {
    for (final ByteIterable key : successiveKeys) {
        exchange.clear();
        for (int i = 0; i < key.getLength(); i++) {
            exchange.append(key.getBytesUnsafe()[i]);
        }
        exchange.getValue().put(key.getBytesUnsafe());
        exchange.store();
    }
    persistit.flush();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable)

Example 38 with ByteIterable

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

the class JMHPersistItTokyoCabinetWriteBenchmark method randomWrite.

@Benchmark
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = WARMUP_ITERATIONS)
@Measurement(iterations = MEASUREMENT_ITERATIONS)
@Fork(FORKS)
public void randomWrite() throws PersistitException {
    final Exchange exchange = createTestStore();
    for (final ByteIterable key : randomKeys) {
        exchange.clear();
        for (int i = 0; i < key.getLength(); i++) {
            exchange.append(key.getBytesUnsafe()[i]);
        }
        exchange.getValue().put(key.getBytesUnsafe());
        exchange.store();
    }
    persistit.flush();
}
Also used : Exchange(com.persistit.Exchange) ByteIterable(jetbrains.exodus.ByteIterable) TokyoCabinetBenchmark(jetbrains.exodus.benchmark.TokyoCabinetBenchmark)

Example 39 with ByteIterable

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

the class PropertyValueIterable method countImpl.

@Override
protected long countImpl(@NotNull final PersistentStoreTransaction txn) {
    final ByteIterable key = getStore().getPropertyTypes().dataToPropertyValue(value).dataToEntry();
    final Cursor valueIdx = openCursor(txn);
    return valueIdx == null ? 0 : new SingleKeyCursorCounter(valueIdx, key).getCount();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) Cursor(jetbrains.exodus.env.Cursor)

Example 40 with ByteIterable

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

the class VfsSettings method get.

ByteIterable get(@Nullable final Transaction txn, @NotNull final String settingName) {
    final ArrayByteIterable key = StringBinding.stringToEntry(settingName);
    if (txn != null) {
        return settingStore.get(txn, key);
    }
    final ByteIterable[] result = new ByteIterable[1];
    env.executeInTransaction(new TransactionalExecutable() {

        @Override
        public void execute(@NotNull final Transaction txn) {
            result[0] = settingStore.get(txn, key);
        }
    });
    return result[0];
}
Also used : TransactionalExecutable(jetbrains.exodus.env.TransactionalExecutable) Transaction(jetbrains.exodus.env.Transaction) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable)

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