Search in sources :

Example 6 with Store

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

the class VFSBlobVault method loadAllBlobs.

@NotNull
private static LongSet loadAllBlobs(@NotNull final PersistentEntityStoreImpl store, @NotNull final PersistentStoreTransaction txn) {
    final LongSet result = new PackedLongHashSet();
    final Transaction envTxn = txn.getEnvironmentTransaction();
    try (Cursor entityTypesCursor = store.getEntityTypesTable().getSecondIndexCursor(envTxn)) {
        while (entityTypesCursor.getNext()) {
            final int entityTypeId = IntegerBinding.compressedEntryToInt(entityTypesCursor.getKey());
            final BlobsTable blobs = store.getBlobsTable(txn, entityTypeId);
            final Store primary = blobs.getPrimaryIndex();
            try (Cursor blobsCursor = primary.openCursor(envTxn)) {
                while (blobsCursor.getNext()) {
                    final long blobId = LongBinding.compressedEntryToLong(blobsCursor.getValue());
                    result.add(blobId);
                }
            }
        }
        return result;
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) BlobsTable(jetbrains.exodus.entitystore.tables.BlobsTable) Store(jetbrains.exodus.env.Store) Cursor(jetbrains.exodus.env.Cursor) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with Store

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

the class UniqueKeyIndicesEngine method insertUniqueKey.

public void insertUniqueKey(@NotNull final PersistentStoreTransaction txn, @NotNull final Index index, @NotNull final List<Comparable> propValues, @NotNull final Entity entity) {
    final PropertyTypes propertyTypes = persistentStore.getPropertyTypes();
    final int propCount = index.getFields().size();
    if (propCount != propValues.size()) {
        throw new IllegalArgumentException("Number of fields differs from the number of property values");
    }
    final Store indexTable = getUniqueKeyIndex(txn, index);
    if (!indexTable.add(txn.getEnvironmentTransaction(), propertyTypes.dataArrayToEntry(propValues.toArray(new Comparable[propCount])), LongBinding.longToCompressedEntry(entity.getId().getLocalId()))) {
        throw new InsertConstraintException("Failed to insert unique key (already exists). Index: " + index);
    }
}
Also used : PropertyTypes(jetbrains.exodus.entitystore.tables.PropertyTypes) Store(jetbrains.exodus.env.Store)

Example 8 with Store

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

the class GarbageCollectorLowCacheTest method collectExpiredPageWithKeyAddressPointingToDeletedFile.

@Test
public void collectExpiredPageWithKeyAddressPointingToDeletedFile() throws IOException, InterruptedException {
    /**
     * o. low cache, small file size
     * 1. create tree IP->BP(N1),BP(N2)
     * 2. save a lot of updates to last key of BP(N2),
     *    so ther're a lot of files with expired version of BP(N2) and
     *    links to min key of BP(N2), that was saved in a very first file
     * 3. clean first file, with min key of BP(N2)
     * 4. clean second file with expired version of BP(N2) and link to min key in removed file
     */
    printDiskUsage();
    set1KbFileWithoutGC();
    env.getEnvironmentConfig().setTreeMaxPageSize(16);
    env.getEnvironmentConfig().setMemoryUsage(0);
    reopenEnvironment();
    Store store = openStoreAutoCommit("duplicates", getConfig());
    putAutoCommit(store, IntegerBinding.intToEntry(1), StringBinding.stringToEntry("value1"));
    putAutoCommit(store, IntegerBinding.intToEntry(2), StringBinding.stringToEntry("value2"));
    putAutoCommit(store, IntegerBinding.intToEntry(3), StringBinding.stringToEntry("value3"));
    putAutoCommit(store, IntegerBinding.intToEntry(4), StringBinding.stringToEntry("value4"));
    putAutoCommit(store, IntegerBinding.intToEntry(5), StringBinding.stringToEntry("value5"));
    putAutoCommit(store, IntegerBinding.intToEntry(6), StringBinding.stringToEntry("value6"));
    for (int i = 0; i < 1000; ++i) {
        putAutoCommit(store, IntegerBinding.intToEntry(6), StringBinding.stringToEntry("value6"));
    }
    final Log log = getLog();
    final GarbageCollector gc = getEnvironment().getGC();
    final long highFileAddress = log.getHighFileAddress();
    long fileAddress = log.getLowAddress();
    while (fileAddress != highFileAddress) {
        gc.doCleanFile(fileAddress);
        fileAddress = log.getNextFileAddress(fileAddress);
        gc.testDeletePendingFiles();
    }
    printDiskUsage();
}
Also used : Log(jetbrains.exodus.log.Log) Store(jetbrains.exodus.env.Store) Test(org.junit.Test)

Example 9 with Store

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

the class GarbageCollectorTestInMemory method testTextIndexLikeWithDeletionsAndConcurrentReading.

@Test
public void testTextIndexLikeWithDeletionsAndConcurrentReading() throws InterruptedException, BrokenBarrierException {
    final long started = System.currentTimeMillis();
    prepare();
    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();
    final Throwable[] throwable = { null };
    final JobProcessor[] processors = new JobProcessor[10];
    for (int i = 0; i < processors.length; ++i) {
        processors[i] = ThreadJobProcessorPool.getOrCreateJobProcessor("test processor" + i);
        processors[i].start();
    }
    final CyclicBarrier barrier = new CyclicBarrier(processors.length + 1);
    processors[0].queue(new Job() {

        @Override
        protected void execute() throws Throwable {
            barrier.await();
            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; 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) {
                throwable[0] = t;
            }
        }
    });
    for (int i = 1; i < processors.length; ++i) {
        processors[i].queue(new Job() {

            @Override
            protected void execute() throws Throwable {
                try {
                    barrier.await();
                    while (System.currentTimeMillis() - started < TEST_DURATION) {
                        int randomInt = rnd.nextInt() & 0x3fffffff;
                        for (int j = 0; j < 100; randomInt += ++j) {
                            final int intKey = randomInt & 0x3fff;
                            final ArrayByteIterable key = IntegerBinding.intToCompressedEntry(intKey);
                            getAutoCommit(store, key);
                            getAutoCommit(storeDups, key);
                            Thread.sleep(0);
                        }
                        Thread.sleep(50);
                    }
                } catch (Throwable t) {
                    throwable[0] = t;
                }
            }
        });
    }
    barrier.await();
    for (final JobProcessor processor : processors) {
        processor.finish();
    }
    final Throwable t = throwable[0];
    if (t != null) {
        memory.dump(new File(System.getProperty("user.home"), "dump"));
        logger.error("User code exception: ", t);
        Assert.assertTrue(false);
    }
}
Also used : JobProcessor(jetbrains.exodus.core.execution.JobProcessor) Store(jetbrains.exodus.env.Store) Cursor(jetbrains.exodus.env.Cursor) NotNull(org.jetbrains.annotations.NotNull) CyclicBarrier(java.util.concurrent.CyclicBarrier) TransactionalExecutable(jetbrains.exodus.env.TransactionalExecutable) Transaction(jetbrains.exodus.env.Transaction) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Job(jetbrains.exodus.core.execution.Job) File(java.io.File) Test(org.junit.Test)

Example 10 with Store

use of jetbrains.exodus.env.Store 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)

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