Search in sources :

Example 1 with ObjectProcedureThrows

use of jetbrains.exodus.core.dataStructures.hash.ObjectProcedureThrows 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()));
    }
}
Also used : LongArrayList(jetbrains.exodus.core.dataStructures.LongArrayList) java.util(java.util) Logger(org.slf4j.Logger) Transaction(jetbrains.exodus.env.Transaction) LoggerFactory(org.slf4j.LoggerFactory) NonNls(org.jetbrains.annotations.NonNls) Environment(jetbrains.exodus.env.Environment) DeferredIO(jetbrains.exodus.util.DeferredIO) LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator) Nullable(org.jetbrains.annotations.Nullable) AtomicLong(java.util.concurrent.atomic.AtomicLong) VirtualFileDescriptor(jetbrains.exodus.backup.VirtualFileDescriptor) ObjectProcedureThrows(jetbrains.exodus.core.dataStructures.hash.ObjectProcedureThrows) Job(jetbrains.exodus.core.execution.Job) IOUtil(jetbrains.exodus.util.IOUtil) java.io(java.io) BackupStrategy(jetbrains.exodus.backup.BackupStrategy) LongSet(jetbrains.exodus.core.dataStructures.hash.LongSet) NotNull(org.jetbrains.annotations.NotNull) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) LongArrayList(jetbrains.exodus.core.dataStructures.LongArrayList) Environment(jetbrains.exodus.env.Environment) Job(jetbrains.exodus.core.execution.Job) LongIterator(jetbrains.exodus.core.dataStructures.hash.LongIterator)

Aggregations

java.io (java.io)1 java.util (java.util)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BackupStrategy (jetbrains.exodus.backup.BackupStrategy)1 VirtualFileDescriptor (jetbrains.exodus.backup.VirtualFileDescriptor)1 LongArrayList (jetbrains.exodus.core.dataStructures.LongArrayList)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 LongIterator (jetbrains.exodus.core.dataStructures.hash.LongIterator)1 LongSet (jetbrains.exodus.core.dataStructures.hash.LongSet)1 ObjectProcedureThrows (jetbrains.exodus.core.dataStructures.hash.ObjectProcedureThrows)1 Job (jetbrains.exodus.core.execution.Job)1 Environment (jetbrains.exodus.env.Environment)1 Transaction (jetbrains.exodus.env.Transaction)1 DeferredIO (jetbrains.exodus.util.DeferredIO)1 IOUtil (jetbrains.exodus.util.IOUtil)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1