Search in sources :

Example 1 with ShutDownCloser

use of org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser in project jackrabbit-oak by apache.

the class FileStore method bind.

FileStore bind(TarRevisions revisions) throws IOException {
    try (ShutDownCloser ignored = shutDown.keepAlive()) {
        this.revisions = revisions;
        this.revisions.bind(this, tracker, initialNode());
        return this;
    }
}
Also used : ShutDownCloser(org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser)

Example 2 with ShutDownCloser

use of org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser in project jackrabbit-oak by apache.

the class FileStore method close.

@Override
public void close() {
    try (ShutDownCloser ignored = shutDown.shutDown()) {
        // avoid deadlocks by closing (and joining) the background
        // thread before acquiring the synchronization lock
        fileStoreScheduler.close();
        try {
            doFlush();
        } catch (IOException e) {
            log.warn("Unable to flush the store", e);
        }
        Closer closer = Closer.create();
        closer.register(repositoryLock::unlock);
        closer.register(tarFiles);
        closer.register(revisions);
        closeAndLogOnFail(closer);
    }
    // Try removing pending files in case the scheduler didn't have a chance to run yet
    // for any memory-mappings that are no longer used
    System.gc();
    fileReaper.reap();
    log.info("TarMK closed: {}", directory);
}
Also used : ShutDownCloser(org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser) Closer(com.google.common.io.Closer) ShutDownCloser(org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser) IOException(java.io.IOException)

Example 3 with ShutDownCloser

use of org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser in project jackrabbit-oak by apache.

the class FileStore method writeSegment.

@Override
public void writeSegment(SegmentId id, byte[] buffer, int offset, int length) throws IOException {
    try (ShutDownCloser ignored = shutDown.keepAlive()) {
        Segment segment = null;
        // If the segment is a data segment, create a new instance of Segment to
        // access some internal information stored in the segment and to store
        // in an in-memory cache for later use.
        GCGeneration generation = GCGeneration.NULL;
        Set<UUID> references = null;
        Set<String> binaryReferences = null;
        if (id.isDataSegmentId()) {
            ByteBuffer data;
            if (offset > 4096) {
                data = ByteBuffer.allocate(length);
                data.put(buffer, offset, length);
                data.rewind();
            } else {
                data = ByteBuffer.wrap(buffer, offset, length);
            }
            segment = new Segment(tracker, segmentReader, id, data);
            generation = segment.getGcGeneration();
            references = readReferences(segment);
            binaryReferences = readBinaryReferences(segment);
        }
        tarFiles.writeSegment(id.asUUID(), buffer, offset, length, generation, references, binaryReferences);
        // Keep this data segment in memory as it's likely to be accessed soon.
        if (segment != null) {
            segmentCache.putSegment(segment);
        }
    }
}
Also used : ShutDownCloser(org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer) Segment(org.apache.jackrabbit.oak.segment.Segment) GCGeneration(org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)

Aggregations

ShutDownCloser (org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser)3 Closer (com.google.common.io.Closer)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 UUID (java.util.UUID)1 Segment (org.apache.jackrabbit.oak.segment.Segment)1 GCGeneration (org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)1