Search in sources :

Example 1 with PackedLongHashSet

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;
}
Also used : LongSet(jetbrains.exodus.core.dataStructures.hash.LongSet) PackedLongHashSet(jetbrains.exodus.core.dataStructures.hash.PackedLongHashSet) OOMGuard(jetbrains.exodus.runtime.OOMGuard) Job(jetbrains.exodus.core.execution.Job) ExodusException(jetbrains.exodus.ExodusException)

Example 2 with PackedLongHashSet

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;
}
Also used : LongSet(jetbrains.exodus.core.dataStructures.hash.LongSet) PackedLongHashSet(jetbrains.exodus.core.dataStructures.hash.PackedLongHashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PackedLongHashSet

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);
    }
}
Also used : LongSet(jetbrains.exodus.core.dataStructures.hash.LongSet) PackedLongHashSet(jetbrains.exodus.core.dataStructures.hash.PackedLongHashSet)

Aggregations

LongSet (jetbrains.exodus.core.dataStructures.hash.LongSet)3 PackedLongHashSet (jetbrains.exodus.core.dataStructures.hash.PackedLongHashSet)3 ExodusException (jetbrains.exodus.ExodusException)1 Job (jetbrains.exodus.core.execution.Job)1 OOMGuard (jetbrains.exodus.runtime.OOMGuard)1 NotNull (org.jetbrains.annotations.NotNull)1