Search in sources :

Example 1 with LongHashMap

use of jetbrains.exodus.core.dataStructures.hash.LongHashMap in project xodus by JetBrains.

the class TreeCursorDuplicatesTest method test_xd_347_like.

@Test
public void test_xd_347_like() {
    tm = createMutableTree(true, 1);
    final int count = 20000;
    long value = 0;
    final LongHashMap<LongHashSet> values = new LongHashMap<>();
    final Random rnd = new Random();
    for (int i = 0; i < count; ++i, ++value) {
        if (i > count / 2) {
            final Pair<Long, LongHashSet>[] pair = new Pair[1];
            values.forEachEntry((ObjectProcedure<Map.Entry<Long, LongHashSet>>) object -> {
                pair[0] = new Pair<>(object.getKey(), object.getValue());
                return false;
            });
            final Pair<Long, LongHashSet> p = pair[0];
            final LongHashSet oldSet = p.getSecond();
            final long oldValue = oldSet.iterator().nextLong();
            final Long oldKey = p.getFirst();
            try (ITreeCursor cursor = tm.openCursor()) {
                if (!cursor.getSearchBoth(key(oldKey), value(oldValue))) {
                    Assert.assertTrue(cursor.getSearchBoth(key(oldKey), value(oldValue)));
                }
                cursor.deleteCurrent();
            }
            Assert.assertTrue(oldSet.remove(oldValue));
            if (oldSet.isEmpty()) {
                Assert.assertEquals(oldSet, values.remove(oldKey));
            }
        }
        final long key = System.currentTimeMillis() + rnd.nextInt(count / 10);
        LongHashSet keyValues = values.get(key);
        if (keyValues == null) {
            keyValues = new LongHashSet();
            values.put(key, keyValues);
        }
        Assert.assertTrue(keyValues.add(value));
        tm.put(key(key), value(value));
    }
}
Also used : java.util(java.util) Pair(jetbrains.exodus.core.dataStructures.Pair) Random(jetbrains.exodus.util.Random) LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) Test(org.junit.Test) Cursor(jetbrains.exodus.env.Cursor) Assert(org.junit.Assert) ObjectProcedure(jetbrains.exodus.core.dataStructures.hash.ObjectProcedure) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) Before(org.junit.Before) LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) Random(jetbrains.exodus.util.Random) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) Pair(jetbrains.exodus.core.dataStructures.Pair) Test(org.junit.Test)

Example 2 with LongHashMap

use of jetbrains.exodus.core.dataStructures.hash.LongHashMap in project xodus by JetBrains.

the class FileSystemBlobVaultOld method flushBlobs.

@Override
public void flushBlobs(@Nullable final LongHashMap<InputStream> blobStreams, @Nullable final LongHashMap<File> blobFiles, @Nullable final LongSet deferredBlobsToDelete, @NotNull final Transaction txn) throws Exception {
    if (blobStreams != null) {
        blobStreams.forEachEntry((ObjectProcedureThrows<Map.Entry<Long, InputStream>, Exception>) object -> {
            final InputStream stream = object.getValue();
            stream.reset();
            setContent(object.getKey(), stream);
            return true;
        });
    }
    // if there were blob files then move them
    if (blobFiles != null) {
        blobFiles.forEachEntry((ObjectProcedureThrows<Map.Entry<Long, File>, Exception>) object -> {
            setContent(object.getKey(), object.getValue());
            return true;
        });
    }
    // if there are deferred blobs to delete then defer their deletion
    if (deferredBlobsToDelete != null) {
        final LongArrayList copy = new LongArrayList(deferredBlobsToDelete.size());
        final LongIterator it = deferredBlobsToDelete.iterator();
        while (it.hasNext()) {
            copy.add(it.nextLong());
        }
        final Environment environment = txn.getEnvironment();
        environment.executeTransactionSafeTask(() -> DeferredIO.getJobProcessor().queueIn(new Job() {

            @Override
            protected void execute() {
                final long[] blobHandles = copy.getInstantArray();
                for (int i = 0; i < copy.size(); ++i) {
                    delete(blobHandles[i]);
                }
            }

            @Override
            public String getName() {
                return "Delete obsolete blob files";
            }

            @Override
            public String getGroup() {
                return environment.getLocation();
            }
        }, environment.getEnvironmentConfig().getGcFilesDeletionDelay()));
    }
}
Also used : LongArrayList(jetbrains.exodus.core.dataStructures.LongArrayList) java.util(java.util) Logger(org.slf4j.Logger) Transaction(jetbrains.exodus.env.Transaction) LoggerFactory(org.slf4j.LoggerFactory) NonNls(org.jetbrains.annotations.NonNls) Environment(jetbrains.exodus.env.Environment) DeferredIO(jetbrains.exodus.util.DeferredIO) LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator) Nullable(org.jetbrains.annotations.Nullable) AtomicLong(java.util.concurrent.atomic.AtomicLong) VirtualFileDescriptor(jetbrains.exodus.backup.VirtualFileDescriptor) ObjectProcedureThrows(jetbrains.exodus.core.dataStructures.hash.ObjectProcedureThrows) Job(jetbrains.exodus.core.execution.Job) IOUtil(jetbrains.exodus.util.IOUtil) java.io(java.io) BackupStrategy(jetbrains.exodus.backup.BackupStrategy) LongSet(jetbrains.exodus.core.dataStructures.hash.LongSet) NotNull(org.jetbrains.annotations.NotNull) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) LongArrayList(jetbrains.exodus.core.dataStructures.LongArrayList) Environment(jetbrains.exodus.env.Environment) Job(jetbrains.exodus.core.execution.Job) LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator)

Aggregations

java.util (java.util)2 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)2 java.io (java.io)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BackupStrategy (jetbrains.exodus.backup.BackupStrategy)1 VirtualFileDescriptor (jetbrains.exodus.backup.VirtualFileDescriptor)1 LongArrayList (jetbrains.exodus.core.dataStructures.LongArrayList)1 Pair (jetbrains.exodus.core.dataStructures.Pair)1 LongHashSet (jetbrains.exodus.core.dataStructures.hash.LongHashSet)1 LongIterator (jetbrains.exodus.core.dataStructures.hash.LongIterator)1 LongSet (jetbrains.exodus.core.dataStructures.hash.LongSet)1 ObjectProcedure (jetbrains.exodus.core.dataStructures.hash.ObjectProcedure)1 ObjectProcedureThrows (jetbrains.exodus.core.dataStructures.hash.ObjectProcedureThrows)1 Job (jetbrains.exodus.core.execution.Job)1 Cursor (jetbrains.exodus.env.Cursor)1 Environment (jetbrains.exodus.env.Environment)1 Transaction (jetbrains.exodus.env.Transaction)1 DeferredIO (jetbrains.exodus.util.DeferredIO)1 IOUtil (jetbrains.exodus.util.IOUtil)1 Random (jetbrains.exodus.util.Random)1