Search in sources :

Example 11 with Store

use of jetbrains.exodus.env.Store in project xodus by JetBrains.

the class GarbageCollectorTestInMemory method testTextIndexLike.

private void testTextIndexLike(boolean useExpirationChecker) {
    final long started = System.currentTimeMillis();
    prepare(useExpirationChecker);
    final Transaction txn = env.beginTransaction();
    final Store store = env.openStore("store", getStoreConfig(false), txn);
    final Store storeDups = env.openStore("storeDups", getStoreConfig(true), txn);
    txn.commit();
    try {
        while (System.currentTimeMillis() - started < TEST_DURATION) {
            env.executeInTransaction(new TransactionalExecutable() {

                @Override
                public void execute(@NotNull final Transaction txn) {
                    int randomInt = rnd.nextInt() & 0x3fffffff;
                    final int count = 4 + (randomInt) & 0x1f;
                    for (int j = 0; j < count; randomInt += ++j) {
                        final int intKey = randomInt & 0x3fff;
                        final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
                        final int valueLength = 50 + (randomInt % 100);
                        store.put(txn, key, new ArrayByteIterable(new byte[valueLength]));
                        storeDups.put(txn, key, IntegerBinding.intToEntry(randomInt % 32));
                    }
                }
            });
            Thread.sleep(0);
        }
    } catch (Throwable t) {
        memory.dump(new File(System.getProperty("user.home"), "dump"));
        logger.error("User code exception: ", t);
        Assert.assertTrue(false);
    }
}
Also used : TransactionalExecutable(jetbrains.exodus.env.TransactionalExecutable) Transaction(jetbrains.exodus.env.Transaction) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Store(jetbrains.exodus.env.Store) File(java.io.File)

Example 12 with Store

use of jetbrains.exodus.env.Store in project pwm by pwm-project.

the class XodusLocalDB method putAll.

@Override
public void putAll(final LocalDB.DB db, final Map<String, String> keyValueMap) throws LocalDBException {
    checkStatus(true);
    environment.executeInTransaction(transaction -> {
        final Store store = getStore(db);
        for (final Map.Entry<String, String> entry : keyValueMap.entrySet()) {
            final ByteIterable k = bindMachine.keyToEntry(entry.getKey());
            final ByteIterable v = bindMachine.valueToEntry(entry.getValue());
            store.put(transaction, k, v);
        }
    });
    outputLogExecutor.conditionallyExecuteTask();
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) Store(jetbrains.exodus.env.Store) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 13 with Store

use of jetbrains.exodus.env.Store in project pwm by pwm-project.

the class XodusLocalDB method get.

@Override
public String get(final LocalDB.DB db, final String key) throws LocalDBException {
    checkStatus(false);
    return environment.computeInReadonlyTransaction(transaction -> {
        final Store store = getStore(db);
        final ByteIterable returnValue = store.get(transaction, bindMachine.keyToEntry(key));
        if (returnValue != null) {
            return bindMachine.entryToValue(returnValue);
        }
        return null;
    });
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) Store(jetbrains.exodus.env.Store)

Example 14 with Store

use of jetbrains.exodus.env.Store in project pwm by pwm-project.

the class XodusLocalDB method truncate.

@Override
public void truncate(final LocalDB.DB db) throws LocalDBException {
    checkStatus(true);
    LOGGER.trace("begin truncate of " + db.toString() + ", size=" + this.size(db));
    final Date startDate = new Date();
    environment.executeInTransaction(transaction -> {
        environment.truncateStore(db.toString(), transaction);
        final Store newStoreReference = environment.openStore(db.toString(), StoreConfig.USE_EXISTING, transaction);
        cachedStoreObjects.put(db, newStoreReference);
    });
    LOGGER.trace("completed truncate of " + db.toString() + " (" + TimeDuration.fromCurrent(startDate).asCompactString() + ")" + ", size=" + this.size(db));
}
Also used : Store(jetbrains.exodus.env.Store) Date(java.util.Date)

Aggregations

Store (jetbrains.exodus.env.Store)14 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)7 ByteIterable (jetbrains.exodus.ByteIterable)4 Transaction (jetbrains.exodus.env.Transaction)4 File (java.io.File)3 Cursor (jetbrains.exodus.env.Cursor)3 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)3 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExodusException (jetbrains.exodus.ExodusException)1 OutOfDiskSpaceException (jetbrains.exodus.OutOfDiskSpaceException)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1