use of jetbrains.exodus.core.dataStructures.hash.PackedLongHashSet 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.PackedLongHashSet 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.PackedLongHashSet 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);
}
}
Aggregations