Search in sources :

Example 26 with Transaction

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

the class GarbageCollectorTestInMemory method testTextIndexLikeWithDeletions.

private void testTextIndexLikeWithDeletions(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));
                    }
                    randomInt = (randomInt * randomInt) & 0x3fffffff;
                    for (int j = 0; j < count / 2; randomInt += ++j) {
                        final int intKey = randomInt & 0x3fff;
                        final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
                        store.delete(txn, key);
                        try (Cursor cursor = storeDups.openCursor(txn)) {
                            if (cursor.getSearchBoth(key, IntegerBinding.intToEntry(randomInt % 32))) {
                                cursor.deleteCurrent();
                            }
                        }
                    }
                }
            });
            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) Cursor(jetbrains.exodus.env.Cursor) File(java.io.File)

Example 27 with Transaction

use of jetbrains.exodus.env.Transaction 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 28 with Transaction

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

the class PersistentSequentialDictionary method rename.

public void rename(@NotNull final PersistentStoreTransaction txn, @NotNull final String oldName, @NotNull final String newName) {
    if (oldName.equals(newName)) {
        return;
    }
    final int id = getId(txn, oldName);
    if (id < 0) {
        throw new IllegalArgumentException("Old entity type doesn't exist: " + oldName);
    }
    final int newId = getId(txn, newName);
    final ByteIterable idEntry = IntegerBinding.intToCompressedEntry(id);
    synchronized (lock) {
        operationsLog.add(new DictionaryOperation() {

            @Override
            void persist(final Transaction txn) {
                table.delete(txn, StringBinding.stringToEntry(oldName), idEntry);
                table.put(txn, StringBinding.stringToEntry(newName), idEntry);
            }
        });
        cache.remove(oldName);
        cache.put(newName, id);
        reverseCache.remove(id);
        if (newId >= 0) {
            reverseCache.remove(newId);
        }
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) ByteIterable(jetbrains.exodus.ByteIterable)

Example 29 with Transaction

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

the class ExodusDirectory method listAll.

@Override
public String[] listAll() throws IOException {
    final Transaction txn = env.getAndCheckCurrentTransaction();
    final ArrayList<String> allFiles = new ArrayList<>((int) vfs.getNumberOfFiles(txn));
    for (final File file : vfs.getFiles(txn)) {
        allFiles.add(file.getPath());
    }
    return allFiles.toArray(new String[allFiles.size()]);
}
Also used : Transaction(jetbrains.exodus.env.Transaction) ArrayList(java.util.ArrayList)

Example 30 with Transaction

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

the class VfsFileTests method testFileCreation.

@Test
public void testFileCreation() {
    final Transaction txn = env.beginTransaction();
    final File file0 = vfs.createFile(txn, "file0");
    txn.commit();
    Assert.assertEquals(0L, file0.getDescriptor());
}
Also used : Transaction(jetbrains.exodus.env.Transaction) Test(org.junit.Test)

Aggregations

Transaction (jetbrains.exodus.env.Transaction)43 Test (org.junit.Test)33 OutputStream (java.io.OutputStream)22 InputStream (java.io.InputStream)18 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)4 Store (jetbrains.exodus.env.Store)4 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)4 File (java.io.File)3 ByteIterable (jetbrains.exodus.ByteIterable)3 Cursor (jetbrains.exodus.env.Cursor)3 TestFor (jetbrains.exodus.TestFor)2 NotNull (org.jetbrains.annotations.NotNull)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 BlobsTable (jetbrains.exodus.entitystore.tables.BlobsTable)1 Environment (jetbrains.exodus.env.Environment)1