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));
}
}
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()));
}
}
Aggregations