use of jetbrains.exodus.core.dataStructures.hash.LongSet in project xodus by JetBrains.
the class GarbageCollector method doCleanFiles.
private boolean doCleanFiles(@NotNull final Iterator<Long> fragmentedFiles) {
// if there are no more files then even don't start a txn
if (!fragmentedFiles.hasNext()) {
return true;
}
final LongSet cleanedFiles = new PackedLongHashSet();
final ReadWriteTransaction txn;
try {
final TransactionBase tx = useRegularTxn ? env.beginTransaction() : env.beginGCTransaction();
// tx can be read-only, so we should manually finish it (see XD-667)
if (tx.isReadonly()) {
tx.abort();
return false;
}
txn = (ReadWriteTransaction) tx;
} catch (TransactionAcquireTimeoutException ignore) {
return false;
}
final boolean isTxnExclusive = txn.isExclusive();
try {
final OOMGuard guard = new OOMGuard();
final long started = System.currentTimeMillis();
while (fragmentedFiles.hasNext()) {
final long fileAddress = fragmentedFiles.next();
cleanSingleFile(fileAddress, txn);
cleanedFiles.add(fileAddress);
if (!isTxnExclusive) {
// do not process more than one file in a non-exclusive txn
break;
}
if (started + ec.getGcTransactionTimeout() < System.currentTimeMillis()) {
// break by timeout
break;
}
if (guard.isItCloseToOOM()) {
// break because of the risk of OutOfMemoryError
break;
}
}
if (!txn.forceFlush()) {
// paranoiac check
if (isTxnExclusive) {
throw new ExodusException("Can't be: exclusive txn should be successfully flushed");
}
return false;
}
} catch (Throwable e) {
throw ExodusException.toExodusException(e);
} finally {
txn.abort();
}
if (!cleanedFiles.isEmpty()) {
for (final Long file : cleanedFiles) {
pendingFilesToDelete.add(file);
utilizationProfile.removeFile(file);
}
utilizationProfile.estimateTotalBytes();
env.executeTransactionSafeTask(new Runnable() {
@Override
public void run() {
final int filesDeletionDelay = ec.getGcFilesDeletionDelay();
if (filesDeletionDelay == 0) {
for (final Long file : cleanedFiles) {
deletionQueue.offer(file);
}
} else {
DeferredIO.getJobProcessor().queueIn(new Job() {
@Override
protected void execute() {
for (final Long file : cleanedFiles) {
deletionQueue.offer(file);
}
}
}, filesDeletionDelay);
}
}
});
}
return true;
}
use of jetbrains.exodus.core.dataStructures.hash.LongSet in project xodus by JetBrains.
the class ImmutableSingleTypeEntityIdBitSet method getTypeSetSnapshot.
@NotNull
@Override
public LongSet getTypeSetSnapshot(int typeId) {
if (typeId == singleTypeId) {
final LongSet result = new PackedLongHashSet();
int next = data.nextSetBit(0);
while (next != -1) {
result.add(next + min);
// if (next == Integer.MAX_VALUE) { break; }
next = data.nextSetBit(next + 1);
}
return result;
}
return LongSet.EMPTY;
}
use of jetbrains.exodus.core.dataStructures.hash.LongSet in project xodus by JetBrains.
the class SingleTypeEntityIdSet method add.
public EntityIdSet add(final int typeId, final long localId) {
if (typeId == singleTypeId) {
singleTypeLocalIds.add(localId);
return this;
} else {
final LongSet moreLocalIds = new PackedLongHashSet();
moreLocalIds.add(localId);
return new MultiTypeEntityIdSet(typeId, moreLocalIds, singleTypeId, singleTypeLocalIds, holdsNull);
}
}
use of jetbrains.exodus.core.dataStructures.hash.LongSet in project xodus by JetBrains.
the class StoreTest method concurrentPutLikeJetPass.
private void concurrentPutLikeJetPass(@NotNull final StoreConfig config) {
env.getEnvironmentConfig().setGcEnabled(false);
final Store store = openStoreAutoCommit("store", config);
final JobProcessor processor = new MultiThreadDelegatingJobProcessor("ConcurrentPutProcessor", 8) {
};
processor.setExceptionHandler(new JobProcessorExceptionHandler() {
@Override
public void handle(JobProcessor processor, Job job, Throwable t) {
t.printStackTrace(System.out);
}
});
processor.start();
final int count = 50000;
final LongSet keys = new LongHashSet();
for (int i = 0; i < count; ++i) {
processor.queue(new Job() {
@Override
protected void execute() {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final long key = randomLong();
store.put(txn, LongBinding.longToCompressedEntry(key), getValue());
if (txn.flush()) {
final boolean added;
synchronized (keys) {
added = keys.add(key);
}
if (!added) {
System.out.println("Happy birthday paradox!");
}
}
}
});
}
});
}
processor.waitForJobs(10);
processor.finish();
assertEquals(count, keys.size());
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final long[] longs = keys.toLongArray();
for (long key : longs) {
assertEquals(getValue(), store.get(txn, LongBinding.longToCompressedEntry(key)));
}
Arrays.sort(longs);
try (Cursor cursor = store.openCursor(txn)) {
int i = 0;
while (cursor.getNext()) {
assertEquals(longs[i++], LongBinding.compressedEntryToLong(cursor.getKey()));
}
assertEquals(count, i);
}
}
});
}
Aggregations