Search in sources :

Example 1 with LongIterator

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

the class Log method getFirstLoggableOfType.

/**
 * Returns the first loggable in the log of specified type.
 *
 * @param type type of loggable.
 * @return loggable or null if it doesn't exists.
 */
@Nullable
public Loggable getFirstLoggableOfType(final int type) {
    final LogTip logTip = getTip();
    final LongIterator files = logTip.logFileSet.getFilesFrom(0);
    final long approvedHighAddress = logTip.approvedHighAddress;
    while (files.hasNext()) {
        final long fileAddress = files.nextLong();
        final Iterator<RandomAccessLoggable> it = getLoggableIterator(fileAddress);
        while (it.hasNext()) {
            final Loggable loggable = it.next();
            if (loggable == null || loggable.getAddress() >= fileAddress + fileLengthBound) {
                break;
            }
            if (loggable.getType() == type) {
                return loggable;
            }
            if (loggable.getAddress() + loggable.length() == approvedHighAddress) {
                break;
            }
        }
    }
    return null;
}
Also used : LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with LongIterator

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

the class UpdatableEntityIdSortedSetCachedInstanceIterable method getOrCreateIdCollection.

@NotNull
private OrderedEntityIdCollection getOrCreateIdCollection() {
    OrderedEntityIdCollection collection = this.idCollection;
    if (collection == null) {
        PersistentLongSet.ImmutableSet currentSet = localIds.beginRead();
        final long[] result = new long[currentSet.size()];
        final LongIterator it = currentSet.longIterator();
        int i = 0;
        while (it.hasNext()) {
            result[i++] = it.next();
        }
        collection = EntityIdArrayCachedInstanceIterableFactory.makeIdCollection(entityTypeId, result);
        this.idCollection = collection;
    }
    return collection;
}
Also used : LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator) PersistentLongSet(jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LongIterator

use of jetbrains.exodus.core.dataStructures.hash.LongIterator 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(new ObjectProcedureThrows<Map.Entry<Long, InputStream>, Exception>() {

            @Override
            public boolean execute(final Map.Entry<Long, InputStream> object) throws Exception {
                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(new ObjectProcedureThrows<Map.Entry<Long, File>, Exception>() {

            @Override
            public boolean execute(final Map.Entry<Long, File> object) throws Exception {
                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(new Runnable() {

            @Override
            public void run() {
                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) AtomicLong(java.util.concurrent.atomic.AtomicLong) Environment(jetbrains.exodus.env.Environment) Job(jetbrains.exodus.core.execution.Job) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator)

Example 4 with LongIterator

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

the class JMHPersistentLongSetIterationBenchmark method iterateBitTree.

@Benchmark
@Warmup(iterations = 6, time = 1)
@Measurement(iterations = 8, time = 1)
@Fork(5)
public long iterateBitTree() {
    LongIterator iterator = bitTreeSet.beginRead().longIterator();
    long result = 0;
    while (iterator.hasNext()) {
        result += iterator.nextLong();
    }
    return result;
}
Also used : LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator)

Example 5 with LongIterator

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

the class JMHPersistentLongSetIterationBenchmark method iterate23Tree.

@Benchmark
@Warmup(iterations = 6, time = 1)
@Measurement(iterations = 8, time = 1)
@Fork(5)
public long iterate23Tree() {
    LongIterator iterator = treeSet.beginRead().longIterator();
    long result = 0;
    while (iterator.hasNext()) {
        result += iterator.nextLong();
    }
    return result;
}
Also used : LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator)

Aggregations

LongIterator (jetbrains.exodus.core.dataStructures.hash.LongIterator)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 LongArrayList (jetbrains.exodus.core.dataStructures.LongArrayList)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 PersistentLongSet (jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet)1 Job (jetbrains.exodus.core.execution.Job)1 StreamCipherProvider (jetbrains.exodus.crypto.StreamCipherProvider)1 Environment (jetbrains.exodus.env.Environment)1 Block (jetbrains.exodus.io.Block)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1