Author: frm Date: Wed Dec 5 17:00:25 2018 New Revision: 1848226 URL: http://svn.apache.org/viewvc?rev=1848226&view=rev Log: OAK-7942 - Fix covariant return type changes in ByteBuffer
Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/Buffer.java (with props) Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java jackrabbit/oak/trunk/oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV1.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntryV2.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/memory/MemoryStore.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/split/UnclosedSegmentArchiveReader.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/CharsetEncodingUtils.java jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/util/ReaderAtEnd.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CacheWeightEstimator.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CompactorTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/NodeRecordTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitorTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderTest.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV1Test.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexLoaderV2Test.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV1Test.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexV2Test.java jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/StandbyTestUtils.java jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/PersistingDiff.java Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveReader.java Wed Dec 5 17:00:25 2018 @@ -23,7 +23,6 @@ import static org.apache.jackrabbit.oak. import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -40,6 +39,7 @@ import com.microsoft.azure.storage.blob. import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; public class AzureSegmentArchiveReader implements SegmentArchiveReader { static final boolean OFF_HEAP = getBoolean("access.off.heap"); @@ -70,17 +70,17 @@ public class AzureSegmentArchiveReader i } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { AzureSegmentArchiveEntry indexEntry = index.get(new UUID(msb, lsb)); if (indexEntry == null) { return null; } - ByteBuffer buffer; + Buffer buffer; if (OFF_HEAP) { - buffer = ByteBuffer.allocateDirect(indexEntry.getLength()); + buffer = Buffer.allocateDirect(indexEntry.getLength()); } else { - buffer = ByteBuffer.allocate(indexEntry.getLength()); + buffer = Buffer.allocate(indexEntry.getLength()); } ioMonitor.beforeSegmentRead(pathAsFile(), msb, lsb, indexEntry.getLength()); Stopwatch stopwatch = Stopwatch.createStarted(); @@ -101,8 +101,8 @@ public class AzureSegmentArchiveReader i } @Override - public ByteBuffer getGraph() throws IOException { - ByteBuffer graph = readBlob(getName() + ".gph"); + public Buffer getGraph() throws IOException { + Buffer graph = readBlob(getName() + ".gph"); hasGraph = graph != null; return graph; } @@ -118,7 +118,7 @@ public class AzureSegmentArchiveReader i } @Override - public ByteBuffer getBinaryReferences() throws IOException { + public Buffer getBinaryReferences() throws IOException { return readBlob(getName() + ".brf"); } @@ -154,14 +154,14 @@ public class AzureSegmentArchiveReader i } } - private ByteBuffer readBlob(String name) throws IOException { + private Buffer readBlob(String name) throws IOException { try { CloudBlockBlob blob = getBlob(name); if (!blob.exists()) { return null; } long length = blob.getProperties().getLength(); - ByteBuffer buffer = ByteBuffer.allocate((int) length); + Buffer buffer = Buffer.allocate((int) length); AzureUtilities.readBufferFully(blob, buffer); return buffer; } catch (StorageException e) { Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentArchiveWriter.java Wed Dec 5 17:00:25 2018 @@ -23,7 +23,6 @@ import static org.apache.jackrabbit.oak. import java.io.File; import java.io.IOException; import java.net.URISyntaxException; -import java.nio.ByteBuffer; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -40,6 +39,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; public class AzureSegmentArchiveWriter implements SegmentArchiveWriter { @@ -99,22 +99,22 @@ public class AzureSegmentArchiveWriter i } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { UUID uuid = new UUID(msb, lsb); Optional<SegmentWriteAction> segment = queue.map(q -> q.read(uuid)); if (segment.isPresent()) { - return segment.get().toByteBuffer(); + return segment.get().toBuffer(); } AzureSegmentArchiveEntry indexEntry = index.get(new UUID(msb, lsb)); if (indexEntry == null) { return null; } - ByteBuffer buffer; + Buffer buffer; if (OFF_HEAP) { - buffer = ByteBuffer.allocateDirect(indexEntry.getLength()); + buffer = Buffer.allocateDirect(indexEntry.getLength()); } else { - buffer = ByteBuffer.allocate(indexEntry.getLength()); + buffer = Buffer.allocate(indexEntry.getLength()); } readBufferFully(getBlob(getSegmentFileName(indexEntry)), buffer); return buffer; Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzureUtilities.java Wed Dec 5 17:00:25 2018 @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; -import java.nio.ByteBuffer; import java.nio.file.Paths; import java.security.InvalidKeyException; import java.util.EnumSet; @@ -36,6 +35,7 @@ import com.microsoft.azure.storage.blob. import com.microsoft.azure.storage.blob.CloudBlob; import com.microsoft.azure.storage.blob.CloudBlobContainer; import com.microsoft.azure.storage.blob.CloudBlobDirectory; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,7 +75,7 @@ public final class AzureUtilities { } } - public static void readBufferFully(CloudBlob blob, ByteBuffer buffer) throws IOException { + public static void readBufferFully(CloudBlob blob, Buffer buffer) throws IOException { try { blob.download(new ByteBufferOutputStream(buffer)); buffer.flip(); @@ -105,7 +105,7 @@ public final class AzureUtilities { public static CloudBlobDirectory cloudBlobDirectoryFrom(String connection, String containerName, String dir) throws InvalidKeyException, URISyntaxException, StorageException { - CloudStorageAccount cloud = CloudStorageAccount.parse(connection.toString()); + CloudStorageAccount cloud = CloudStorageAccount.parse(connection); CloudBlobContainer container = cloud.createCloudBlobClient().getContainerReference(containerName); container.createIfNotExists(); @@ -115,19 +115,19 @@ public final class AzureUtilities { private static class ByteBufferOutputStream extends OutputStream { @NotNull - private final ByteBuffer buffer; + private final Buffer buffer; - public ByteBufferOutputStream(@NotNull ByteBuffer buffer) { + public ByteBufferOutputStream(@NotNull Buffer buffer) { this.buffer = buffer; } @Override - public void write(int b) throws IOException { + public void write(int b) { buffer.put((byte)b); } @Override - public void write(@NotNull byte[] bytes, int offset, int length) throws IOException { + public void write(@NotNull byte[] bytes, int offset, int length) { buffer.put(bytes, offset, length); } } Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/queue/SegmentWriteAction.java Wed Dec 5 17:00:25 2018 @@ -17,9 +17,9 @@ package org.apache.jackrabbit.oak.segment.azure.queue; import org.apache.jackrabbit.oak.segment.azure.AzureSegmentArchiveEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.UUID; public class SegmentWriteAction { @@ -47,8 +47,8 @@ public class SegmentWriteAction { return new UUID(indexEntry.getMsb(), indexEntry.getLsb()); } - public ByteBuffer toByteBuffer() { - return ByteBuffer.wrap(buffer, offset, length); + public Buffer toBuffer() { + return Buffer.wrap(buffer, offset, length); } void passTo(SegmentWriteQueue.SegmentConsumer consumer) throws IOException { Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentCopy.java Wed Dec 5 17:00:25 2018 @@ -45,10 +45,10 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; import org.apache.jackrabbit.oak.segment.tool.Check; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import java.io.IOException; import java.io.PrintWriter; -import java.nio.ByteBuffer; import java.text.MessageFormat; import java.util.ArrayDeque; import java.util.Collections; @@ -317,12 +317,12 @@ public class SegmentCopy { writeSegment(segmentEntry, archiveReader, archiveWriter); } - ByteBuffer binRefBuffer = archiveReader.getBinaryReferences(); + Buffer binRefBuffer = archiveReader.getBinaryReferences(); byte[] binRefData = fetchByteArray(binRefBuffer); archiveWriter.writeBinaryReferences(binRefData); - ByteBuffer graphBuffer = archiveReader.getGraph(); + Buffer graphBuffer = archiveReader.getGraph(); byte[] graphData = fetchByteArray(graphBuffer); archiveWriter.writeGraph(graphData); @@ -344,7 +344,7 @@ public class SegmentCopy { int fullGeneration = segmentEntry.getFullGeneration(); boolean isCompacted = segmentEntry.isCompacted(); - ByteBuffer byteBuffer = archiveReader.readSegment(msb, lsb); + Buffer byteBuffer = archiveReader.readSegment(msb, lsb); byte[] data = fetchByteArray(byteBuffer); archiveWriter.writeSegment(msb, lsb, data, offset, size, generation, fullGeneration, isCompacted); Modified: jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/ToolUtils.java Wed Dec 5 17:00:25 2018 @@ -24,12 +24,19 @@ import static org.apache.jackrabbit.oak. import static org.apache.jackrabbit.oak.segment.azure.util.AzureConfigurationParserUtils.parseAzureConfigurationFromUri; import static org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.defaultGCOptions; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URISyntaxException; +import java.text.MessageFormat; +import java.util.Map; +import java.util.concurrent.TimeUnit; + import com.google.common.base.Stopwatch; import com.microsoft.azure.storage.StorageCredentials; import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.blob.CloudBlobDirectory; - import org.apache.jackrabbit.oak.segment.azure.AzurePersistence; import org.apache.jackrabbit.oak.segment.azure.AzureUtilities; import org.apache.jackrabbit.oak.segment.file.FileStore; @@ -40,15 +47,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.net.URISyntaxException; -import java.nio.ByteBuffer; -import java.text.MessageFormat; -import java.util.Map; -import java.util.concurrent.TimeUnit; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; /** * Utility class for common stuff pertaining to tooling. @@ -164,7 +163,7 @@ public class ToolUtils { pw.println(MessageFormat.format(format, arg)); } - public static byte[] fetchByteArray(ByteBuffer buffer) throws IOException { + public static byte[] fetchByteArray(Buffer buffer) throws IOException { byte[] data = new byte[buffer.remaining()]; buffer.get(data); return data; Modified: jackrabbit/oak/trunk/oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java (original) +++ jackrabbit/oak/trunk/oak-segment-azure/src/test/java/oak/apache/jackrabbit/oak/segment/azure/tool/SegmentCopyTestBase.java Wed Dec 5 17:00:25 2018 @@ -23,6 +23,12 @@ import static org.apache.jackrabbit.oak. import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.List; + import org.apache.jackrabbit.oak.segment.SegmentCache; import org.apache.jackrabbit.oak.segment.SegmentNodeStore; import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders; @@ -42,6 +48,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; @@ -50,13 +57,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; - public abstract class SegmentCopyTestBase { private static final String AZURE_DIRECTORY = "repository"; private static final String AZURE_CONTAINER = "oak-test"; @@ -164,20 +164,20 @@ public abstract class SegmentCopyTestBas assertEquals(srcSegment.getFullGeneration(), destSegment.getFullGeneration()); assertEquals(srcSegment.getGeneration(), destSegment.getFullGeneration()); - ByteBuffer srcDataBuffer = srcArchiveReader.readSegment(srcSegment.getMsb(), srcSegment.getLsb()); - ByteBuffer destDataBuffer = destArchiveReader.readSegment(destSegment.getMsb(), destSegment.getLsb()); + Buffer srcDataBuffer = srcArchiveReader.readSegment(srcSegment.getMsb(), srcSegment.getLsb()); + Buffer destDataBuffer = destArchiveReader.readSegment(destSegment.getMsb(), destSegment.getLsb()); assertEquals(srcDataBuffer, destDataBuffer); } - ByteBuffer srcBinRefBuffer = srcArchiveReader.getBinaryReferences(); - ByteBuffer destBinRefBuffer = destArchiveReader.getBinaryReferences(); + Buffer srcBinRefBuffer = srcArchiveReader.getBinaryReferences(); + Buffer destBinRefBuffer = destArchiveReader.getBinaryReferences(); assertEquals(srcBinRefBuffer, destBinRefBuffer); assertEquals(srcArchiveReader.hasGraph(), destArchiveReader.hasGraph()); - ByteBuffer srcGraphBuffer = srcArchiveReader.getGraph(); - ByteBuffer destGraphBuffer = destArchiveReader.getGraph(); + Buffer srcGraphBuffer = srcArchiveReader.getGraph(); + Buffer destGraphBuffer = destArchiveReader.getGraph(); assertEquals(srcGraphBuffer, destGraphBuffer); } } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/CheckpointCompactor.java Wed Dec 5 17:00:25 2018 @@ -27,7 +27,6 @@ import static org.apache.jackrabbit.oak. import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; @@ -36,6 +35,7 @@ import java.util.Map.Entry; import org.apache.jackrabbit.oak.segment.file.GCNodeWriteMonitor; import org.apache.jackrabbit.oak.segment.file.cancel.Canceller; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.gc.GCMonitor; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; @@ -70,7 +70,7 @@ public class CheckpointCompactor { private interface NodeWriter { @NotNull - SegmentNodeState writeNode(@NotNull NodeState node, @Nullable ByteBuffer stableId) throws IOException; + SegmentNodeState writeNode(@NotNull NodeState node, @Nullable Buffer stableId) throws IOException; } /** @@ -141,7 +141,7 @@ public class CheckpointCompactor { } @Nullable - private static ByteBuffer getStableIdBytes(@NotNull NodeState node) { + private static Buffer getStableIdBytes(@NotNull NodeState node) { return node instanceof SegmentNodeState ? ((SegmentNodeState) node).getStableIdBytes() : null; Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Compactor.java Wed Dec 5 17:00:25 2018 @@ -28,7 +28,6 @@ import static org.apache.jackrabbit.oak. import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.List; import org.apache.jackrabbit.oak.api.Blob; @@ -37,6 +36,7 @@ import org.apache.jackrabbit.oak.api.Typ import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; import org.apache.jackrabbit.oak.segment.file.GCNodeWriteMonitor; import org.apache.jackrabbit.oak.segment.file.cancel.Canceller; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateDiff; @@ -124,7 +124,7 @@ public class Compactor { } @Nullable - private static ByteBuffer getStableIdBytes(NodeState state) { + private static Buffer getStableIdBytes(NodeState state) { if (state instanceof SegmentNodeState) { return ((SegmentNodeState) state).getStableIdBytes(); } else { Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java Wed Dec 5 17:00:25 2018 @@ -52,7 +52,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; -import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -68,6 +67,7 @@ import org.apache.jackrabbit.oak.plugins import org.apache.jackrabbit.oak.segment.RecordWriters.RecordWriter; import org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation; import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff; @@ -185,7 +185,7 @@ public class DefaultSegmentWriter implem @Override @NotNull - public RecordId writeNode(@NotNull final NodeState state, @Nullable final ByteBuffer stableIdBytes) throws IOException { + public RecordId writeNode(@NotNull final NodeState state, @Nullable final Buffer stableIdBytes) throws IOException { return new SegmentWriteOperation(writeOperationHandler.getGCGeneration()) .writeNode(state, stableIdBytes); } @@ -740,7 +740,7 @@ public class DefaultSegmentWriter implem return tid; } - private RecordId writeNode(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) + private RecordId writeNode(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException { RecordId compactedId = deduplicateNode(state); @@ -767,7 +767,7 @@ public class DefaultSegmentWriter implem return (byte) (Byte.MIN_VALUE + 64 - numberOfLeadingZeros(childCount)); } - private RecordId writeNodeUncached(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) + private RecordId writeNodeUncached(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException { ModifiedNodeState after = null; @@ -873,7 +873,7 @@ public class DefaultSegmentWriter implem RecordId stableId; if (stableIdBytes != null) { - ByteBuffer buffer = stableIdBytes.duplicate(); + Buffer buffer = stableIdBytes.duplicate(); byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes); stableId = writeBlock(bytes, 0, bytes.length); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordId.java Wed Dec 5 17:00:25 2018 @@ -22,11 +22,11 @@ import static com.google.common.base.Pre import static java.lang.Integer.parseInt; import static org.apache.jackrabbit.oak.segment.CacheWeights.OBJECT_HEADER_SIZE; -import java.nio.ByteBuffer; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; /** @@ -103,12 +103,12 @@ public final class RecordId implements C * @return this record id as byte array */ @NotNull - ByteBuffer getBytes() { + Buffer getBytes() { byte[] buffer = new byte[SERIALIZED_RECORD_ID_BYTES]; BinaryUtils.writeLong(buffer, 0, segmentId.getMostSignificantBits()); BinaryUtils.writeLong(buffer, 8, segmentId.getLeastSignificantBits()); BinaryUtils.writeInt(buffer, 16, offset); - return ByteBuffer.wrap(buffer); + return Buffer.wrap(buffer); } //--------------------------------------------------------< Comparable >-- Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java Wed Dec 5 17:00:25 2018 @@ -36,7 +36,6 @@ import static org.apache.jackrabbit.oak. import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; -import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Iterator; import java.util.UUID; @@ -54,6 +53,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.data.SegmentData; import org.apache.jackrabbit.oak.segment.data.StringData; import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -179,9 +179,9 @@ public class Segment { this.reader = checkNotNull(reader); this.info = checkNotNull(info); if (id.isDataSegmentId()) { - this.data = newSegmentData(ByteBuffer.wrap(buffer)); + this.data = newSegmentData(Buffer.wrap(buffer)); } else { - this.data = newRawSegmentData(ByteBuffer.wrap(buffer)); + this.data = newRawSegmentData(Buffer.wrap(buffer)); } this.version = SegmentVersion.fromByte(buffer[3]); this.recordNumbers = recordNumbers; @@ -192,7 +192,7 @@ public class Segment { public Segment(@NotNull SegmentIdProvider idProvider, @NotNull SegmentReader reader, @NotNull final SegmentId id, - @NotNull final ByteBuffer data) { + @NotNull final Buffer data) { this.reader = checkNotNull(reader); this.id = checkNotNull(id); if (id.isDataSegmentId()) { @@ -417,7 +417,7 @@ public class Segment { readBytes(recordNumber, position, length).get(buffer, offset, length); } - ByteBuffer readBytes(int recordNumber, int position, int length) { + Buffer readBytes(int recordNumber, int position, int length) { return data.readBytes(recordNumbers.getOffset(recordNumber) + position, length); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBlob.java Wed Dec 5 17:00:25 2018 @@ -21,9 +21,9 @@ package org.apache.jackrabbit.oak.segmen import static com.google.common.base.Charsets.UTF_8; import static com.google.common.collect.Sets.newHashSet; import static java.util.Collections.emptySet; -import static org.apache.jackrabbit.oak.segment.SegmentStream.BLOCK_SIZE; import static org.apache.jackrabbit.oak.segment.Segment.MEDIUM_LIMIT; import static org.apache.jackrabbit.oak.segment.Segment.SMALL_LIMIT; +import static org.apache.jackrabbit.oak.segment.SegmentStream.BLOCK_SIZE; import java.io.InputStream; import java.util.List; @@ -198,7 +198,7 @@ public class SegmentBlob extends Record private static String readShortBlobId(Segment segment, int recordNumber, byte head) { int length = (head & 0x0f) << 8 | (segment.readByte(recordNumber, 1) & 0xff); - return UTF_8.decode(segment.readBytes(recordNumber, 2, length)).toString(); + return segment.readBytes(recordNumber, 2, length).decode(UTF_8).toString(); } private static String readLongBlobId(Segment segment, int recordNumber) { Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferMonitor.java Wed Dec 5 17:00:25 2018 @@ -23,16 +23,16 @@ import static org.apache.jackrabbit.oak. import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.nio.ByteBuffer; import java.util.Set; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.jetbrains.annotations.NotNull; /** * This class exposes {@link CounterStats} for allocations and de-allocations - * of {@link ByteBuffer} instances: + * of {@link Buffer} instances: * <ul> * <li>{@link #DIRECT_BUFFER_COUNT}: number of allocated direct byte * buffers.</li> @@ -44,7 +44,7 @@ import org.jetbrains.annotations.NotNull * heap byte buffers.</li> * </ul> * <p> - * Users of this class call {@link #trackAllocation(ByteBuffer)} to update above statistics. + * Users of this class call {@link #trackAllocation(Buffer)} to update above statistics. */ public class SegmentBufferMonitor { @@ -72,7 +72,7 @@ public class SegmentBufferMonitor { private final Set<BufferReference> buffers = newConcurrentHashSet(); @NotNull - private final ReferenceQueue<ByteBuffer> referenceQueue = new ReferenceQueue<>(); + private final ReferenceQueue<Buffer> referenceQueue = new ReferenceQueue<>(); @NotNull private final CounterStats directBufferCount; @@ -98,12 +98,12 @@ public class SegmentBufferMonitor { heapBufferCapacity = statisticsProvider.getCounterStats(HEAP_BUFFER_CAPACITY, METRICS_ONLY); } - private static class BufferReference extends WeakReference<ByteBuffer> { + private static class BufferReference extends WeakReference<Buffer> { private final int capacity; private final boolean isDirect; - public BufferReference(@NotNull ByteBuffer buffer, - @NotNull ReferenceQueue<ByteBuffer> queue) { + public BufferReference(@NotNull Buffer buffer, + @NotNull ReferenceQueue<Buffer> queue) { super(buffer, queue); this.capacity = buffer.capacity(); this.isDirect = buffer.isDirect(); @@ -114,7 +114,7 @@ public class SegmentBufferMonitor { * Track the allocation of a {@code buffer} and update the exposed statistics. * @param buffer */ - public void trackAllocation(@NotNull ByteBuffer buffer) { + public void trackAllocation(@NotNull Buffer buffer) { BufferReference reference = new BufferReference(buffer, referenceQueue); buffers.add(reference); allocated(reference); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java Wed Dec 5 17:00:25 2018 @@ -36,7 +36,6 @@ import static org.apache.jackrabbit.oak. import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE; import static org.apache.jackrabbit.oak.spi.state.AbstractNodeState.checkValidName; -import java.nio.ByteBuffer; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -47,6 +46,7 @@ import org.apache.jackrabbit.oak.api.Pro import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState; import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.spi.state.AbstractNodeState; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; @@ -134,8 +134,8 @@ public class SegmentNodeState extends Re } @NotNull - static String getStableId(@NotNull ByteBuffer stableId) { - ByteBuffer buffer = stableId.duplicate(); + static String getStableId(@NotNull Buffer stableId) { + Buffer buffer = stableId.duplicate(); long msb = buffer.getLong(); long lsb = buffer.getLong(); int offset = buffer.getInt(); @@ -161,7 +161,7 @@ public class SegmentNodeState extends Re * * @return the stable ID of this node. */ - public ByteBuffer getStableIdBytes() { + public Buffer getStableIdBytes() { // The first record id of this node points to the stable id. RecordId id = getSegment().readRecordId(getRecordNumber()); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentStream.java Wed Dec 5 17:00:25 2018 @@ -25,12 +25,11 @@ import static com.google.common.base.Pre import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; import java.util.List; import com.google.common.base.Charsets; import com.google.common.io.ByteStreams; - +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,7 +55,7 @@ public class SegmentStream extends Input private final RecordId recordId; - private final ByteBuffer inline; + private final Buffer inline; private final ListRecord blocks; @@ -74,7 +73,7 @@ public class SegmentStream extends Input this.length = length; } - SegmentStream(RecordId recordId, ByteBuffer inline, int length) { + SegmentStream(RecordId recordId, Buffer inline, int length) { this.recordId = checkNotNull(recordId); this.inline = inline.duplicate(); this.blocks = null; @@ -95,7 +94,7 @@ public class SegmentStream extends Input public String getString() { if (inline != null) { - return Charsets.UTF_8.decode(inline).toString(); + return inline.decode(Charsets.UTF_8).toString(); } else if (length > Integer.MAX_VALUE) { throw new IllegalStateException("Too long value: " + length); } else { Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java Wed Dec 5 17:00:25 2018 @@ -19,9 +19,9 @@ package org.apache.jackrabbit.oak.segmen import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; import org.apache.jackrabbit.oak.api.Blob; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,14 +65,14 @@ public interface SegmentWriter { * @throws IOException */ @NotNull - RecordId writeNode(@NotNull NodeState state, @Nullable ByteBuffer stableIdBytes) throws IOException; + RecordId writeNode(@NotNull NodeState state, @Nullable Buffer stableIdBytes) throws IOException; /** * Write a node state. * <p> * Equivalent to {@code writeNode(state, null)} * - * @see #writeNode(NodeState, ByteBuffer) + * @see #writeNode(NodeState, Buffer) */ @NotNull default RecordId writeNode(@NotNull NodeState state) throws IOException { Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentData.java Wed Dec 5 17:00:25 2018 @@ -19,7 +19,8 @@ package org.apache.jackrabbit.oak.segmen import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; + +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; /** * Access the data of a segment. @@ -62,11 +63,11 @@ import java.nio.ByteBuffer; */ public interface SegmentData { - static SegmentData newSegmentData(ByteBuffer buffer) { + static SegmentData newSegmentData(Buffer buffer) { return SegmentDataLoader.newSegmentData(buffer); } - static SegmentData newRawSegmentData(ByteBuffer buffer) { + static SegmentData newRawSegmentData(Buffer buffer) { return SegmentDataLoader.newRawSegmentData(buffer); } @@ -108,7 +109,7 @@ public interface SegmentData { long readLong(int recordReferenceOffset); - ByteBuffer readBytes(int recordReferenceOffset, int size); + Buffer readBytes(int recordReferenceOffset, int size); int size(); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataLoader.java Wed Dec 5 17:00:25 2018 @@ -17,7 +17,7 @@ package org.apache.jackrabbit.oak.segment.data; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataLoader { @@ -27,7 +27,7 @@ class SegmentDataLoader { private static final byte SEGMENT_DATA_V13 = 13; - static SegmentData newSegmentData(ByteBuffer buffer) { + static SegmentData newSegmentData(Buffer buffer) { switch (buffer.get(VERSION_OFFSET)) { case SEGMENT_DATA_V12: return new SegmentDataV12(buffer); @@ -38,7 +38,7 @@ class SegmentDataLoader { } } - static SegmentData newRawSegmentData(ByteBuffer buffer) { + static SegmentData newRawSegmentData(Buffer buffer) { return new SegmentDataRaw(buffer); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataRaw.java Wed Dec 5 17:00:25 2018 @@ -19,13 +19,14 @@ package org.apache.jackrabbit.oak.segmen import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; + +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataRaw implements SegmentData { - private final ByteBuffer buffer; + private final Buffer buffer; - SegmentDataRaw(ByteBuffer buffer) { + SegmentDataRaw(Buffer buffer) { this.buffer = buffer; } @@ -34,7 +35,7 @@ class SegmentDataRaw implements SegmentD } @Override - public ByteBuffer readBytes(int recordReferenceOffset, int size) { + public Buffer readBytes(int recordReferenceOffset, int size) { return SegmentDataUtils.readBytes(buffer, index(recordReferenceOffset), size); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataUtils.java Wed Dec 5 17:00:25 2018 @@ -19,11 +19,11 @@ package org.apache.jackrabbit.oak.segmen import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.WritableByteChannel; import org.apache.commons.io.HexDump; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataUtils { @@ -33,33 +33,33 @@ class SegmentDataUtils { private static final int MAX_SEGMENT_SIZE = 1 << 18; - static void hexDump(ByteBuffer buffer, OutputStream stream) throws IOException { + static void hexDump(Buffer buffer, OutputStream stream) throws IOException { byte[] data = new byte[buffer.remaining()]; buffer.duplicate().get(data); HexDump.dump(data, 0, stream, 0); } - static void binDump(ByteBuffer buffer, OutputStream stream) throws IOException { - ByteBuffer data = buffer.duplicate(); + static void binDump(Buffer buffer, OutputStream stream) throws IOException { + Buffer data = buffer.duplicate(); try (WritableByteChannel channel = Channels.newChannel(stream)) { while (data.hasRemaining()) { - channel.write(data); + data.write(channel); } } } - static int estimateMemoryUsage(ByteBuffer buffer) { + static int estimateMemoryUsage(Buffer buffer) { return buffer.isDirect() ? 0 : buffer.remaining(); } - static ByteBuffer readBytes(ByteBuffer buffer, int index, int size) { - ByteBuffer duplicate = buffer.duplicate(); + static Buffer readBytes(Buffer buffer, int index, int size) { + Buffer duplicate = buffer.duplicate(); duplicate.position(index); duplicate.limit(index + size); return duplicate.slice(); } - static int index(ByteBuffer buffer, int recordReferenceOffset) { + static int index(Buffer buffer, int recordReferenceOffset) { return buffer.limit() - (MAX_SEGMENT_SIZE - recordReferenceOffset); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV12.java Wed Dec 5 17:00:25 2018 @@ -19,9 +19,9 @@ package org.apache.jackrabbit.oak.segmen import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; import com.google.common.base.Charsets; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataV12 implements SegmentData { @@ -65,9 +65,9 @@ class SegmentDataV12 implements SegmentD private static final int MAX_MEDIUM_LENGTH_VALUE = (1 << 14) + MAX_SMALL_LENGTH_VALUE; - final ByteBuffer buffer; + final Buffer buffer; - SegmentDataV12(ByteBuffer buffer) { + SegmentDataV12(Buffer buffer) { this.buffer = buffer; } @@ -192,10 +192,10 @@ class SegmentDataV12 implements SegmentD } private StringData internalReadString(int index, int length) { - ByteBuffer duplicate = buffer.duplicate(); + Buffer duplicate = buffer.duplicate(); duplicate.position(index); duplicate.limit(index + length); - String string = Charsets.UTF_8.decode(duplicate).toString(); + String string = duplicate.decode(Charsets.UTF_8).toString(); return new StringData(string, length); } @@ -231,7 +231,7 @@ class SegmentDataV12 implements SegmentD } @Override - public ByteBuffer readBytes(int recordReferenceOffset, int size) { + public Buffer readBytes(int recordReferenceOffset, int size) { return SegmentDataUtils.readBytes(buffer, index(recordReferenceOffset), size); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/data/SegmentDataV13.java Wed Dec 5 17:00:25 2018 @@ -17,13 +17,13 @@ package org.apache.jackrabbit.oak.segment.data; -import java.nio.ByteBuffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; class SegmentDataV13 extends SegmentDataV12 { private static final int FULL_GENERATION_OFFSET = 4; - SegmentDataV13(ByteBuffer buffer) { + SegmentDataV13(Buffer buffer) { super(buffer); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractFileStore.java Wed Dec 5 17:00:25 2018 @@ -24,7 +24,6 @@ import static org.apache.jackrabbit.oak. import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -54,6 +53,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.file.tar.TarRecovery; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.apache.jackrabbit.oak.stats.StatsOptions; import org.jetbrains.annotations.NotNull; @@ -215,7 +215,7 @@ public abstract class AbstractFileStore private void writeSegment(UUID id, byte[] data, EntryRecovery w) throws IOException { long msb = id.getMostSignificantBits(); long lsb = id.getLeastSignificantBits(); - ByteBuffer buffer = ByteBuffer.wrap(data); + Buffer buffer = Buffer.wrap(data); GCGeneration generation = SegmentId.isDataSegmentId(lsb) ? Segment.getGcGeneration(newSegmentData(buffer), id) : GCGeneration.NULL; @@ -279,7 +279,7 @@ public abstract class AbstractFileStore } Segment readSegmentUncached(TarFiles tarFiles, SegmentId id) { - ByteBuffer buffer = tarFiles.readSegment(id.getMostSignificantBits(), id.getLeastSignificantBits()); + Buffer buffer = tarFiles.readSegment(id.getMostSignificantBits(), id.getLeastSignificantBits()); if (buffer == null) { throw new SegmentNotFoundException(id); } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java Wed Dec 5 17:00:25 2018 @@ -29,7 +29,6 @@ import static org.apache.jackrabbit.oak. import static org.apache.jackrabbit.oak.stats.StatsOptions.METRICS_ONLY; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -53,6 +52,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.file.tar.TarFiles; import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.StatisticsProvider; @@ -517,14 +517,14 @@ public class FileStore extends AbstractF Set<String> binaryReferences = null; if (id.isDataSegmentId()) { - ByteBuffer data; + Buffer data; if (offset > 4096) { - data = ByteBuffer.allocate(length); + data = Buffer.allocate(length); data.put(buffer, offset, length); data.rewind(); } else { - data = ByteBuffer.wrap(buffer, offset, length); + data = Buffer.wrap(buffer, offset, length); } segment = new Segment(tracker, segmentReader, id, data); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileAccess.java Wed Dec 5 17:00:25 2018 @@ -20,15 +20,14 @@ package org.apache.jackrabbit.oak.segmen import static com.google.common.base.Preconditions.checkState; import static java.nio.channels.FileChannel.MapMode.READ_ONLY; -import static org.apache.jackrabbit.oak.commons.IOUtils.readFully; import java.io.EOFException; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; + /** * A wrapper around either memory mapped files or random access files, to allow * reading from a file. @@ -39,7 +38,7 @@ abstract class FileAccess { abstract int length() throws IOException; - abstract ByteBuffer read(int position, int length) throws IOException; + abstract Buffer read(int position, int length) throws IOException; abstract void close() throws IOException; @@ -52,11 +51,11 @@ abstract class FileAccess { private final RandomAccessFile file; - private MappedByteBuffer buffer; + private Buffer buffer; Mapped(RandomAccessFile file) throws IOException { this.file = file; - this.buffer = file.getChannel().map(READ_ONLY, 0, file.length()); + this.buffer = Buffer.map(file.getChannel(), READ_ONLY, 0, file.length()); } @Override @@ -70,8 +69,8 @@ abstract class FileAccess { } @Override - public ByteBuffer read(int position, int length) { - ByteBuffer entry = buffer.asReadOnlyBuffer(); + public Buffer read(int position, int length) { + Buffer entry = buffer.asReadOnlyBuffer(); entry.position(entry.position() + position); entry.limit(entry.position() + length); return entry.slice(); @@ -111,12 +110,9 @@ abstract class FileAccess { } @Override - public synchronized ByteBuffer read(int position, int length) - throws IOException { - ByteBuffer entry; - entry = ByteBuffer.allocate(length); - - if (readFully(channel, position, entry) < length) { + public synchronized Buffer read(int position, int length) throws IOException { + Buffer entry = Buffer.allocate(length); + if (entry.readFully(channel, position) < length) { throw new EOFException(); } entry.flip(); @@ -141,12 +137,9 @@ abstract class FileAccess { } @Override - public synchronized ByteBuffer read(int position, int length) - throws IOException { - ByteBuffer entry; - entry = ByteBuffer.allocateDirect(length); - - if (readFully(channel, position, entry) < length) { + public synchronized Buffer read(int position, int length) throws IOException { + Buffer entry = Buffer.allocateDirect(length); + if (entry.readFully(channel, position) < length) { throw new EOFException(); } entry.flip(); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/GraphLoader.java Wed Dec 5 17:00:25 2018 @@ -18,20 +18,20 @@ */ package org.apache.jackrabbit.oak.segment.file.tar; -import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static com.google.common.collect.Lists.newArrayListWithCapacity; +import static com.google.common.collect.Maps.newHashMapWithExpectedSize; +import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.zip.CRC32; -import static com.google.common.collect.Lists.newArrayListWithCapacity; -import static com.google.common.collect.Maps.newHashMapWithExpectedSize; -import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; +import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class GraphLoader { @@ -48,8 +48,8 @@ public final class GraphLoader { * @return the graph or {@code null} if one was not found * @throws IOException if the tar file could not be read */ - public static ByteBuffer loadGraph(ReaderAtEnd readerAtEnd) throws IOException { - ByteBuffer meta = readerAtEnd.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); + public static Buffer loadGraph(ReaderAtEnd readerAtEnd) throws IOException { + Buffer meta = readerAtEnd.readAtEnd(FOOTER_SIZE, FOOTER_SIZE); int crc32 = meta.getInt(); int count = meta.getInt(); @@ -71,7 +71,7 @@ public final class GraphLoader { return null; } - ByteBuffer graph = readerAtEnd.readAtEnd(bytes, bytes); + Buffer graph = readerAtEnd.readAtEnd(bytes, bytes); byte[] b = new byte[bytes - FOOTER_SIZE]; @@ -90,7 +90,7 @@ public final class GraphLoader { return graph; } - public static Map<UUID, List<UUID>> parseGraph(ByteBuffer buffer) { + public static Map<UUID, List<UUID>> parseGraph(Buffer buffer) { int nEntries = buffer.getInt(buffer.limit() - 12); Map<UUID, List<UUID>> graph = newHashMapWithExpectedSize(nEntries); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarManager.java Wed Dec 5 17:00:25 2018 @@ -19,23 +19,12 @@ package org.apache.jackrabbit.oak.segment.file.tar; import static com.google.common.base.Charsets.UTF_8; -import static java.nio.ByteBuffer.wrap; import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; - -import org.apache.commons.io.filefilter.SuffixFileFilter; -import org.apache.jackrabbit.oak.segment.file.tar.index.Index; -import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; -import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static org.apache.jackrabbit.oak.segment.spi.persistence.Buffer.wrap; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; import java.nio.file.Files; import java.util.Arrays; import java.util.LinkedHashMap; @@ -45,6 +34,17 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.CRC32; +import org.apache.commons.io.filefilter.SuffixFileFilter; +import org.apache.jackrabbit.oak.segment.file.tar.index.Index; +import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; +import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class SegmentTarManager implements SegmentArchiveManager { /** @@ -219,7 +219,7 @@ public class SegmentTarManager implement } // The header checksum passes, so read the entry name and size - ByteBuffer buffer = wrap(header); + Buffer buffer = wrap(header); String name = readString(buffer, 100); buffer.position(124); int size = readNumber(buffer, 12); @@ -247,7 +247,7 @@ public class SegmentTarManager implement if (checksum != null) { CRC32 crc = new CRC32(); - crc.update(data); + crc.update(data, 0, data.length); if (crc.getValue() != Long.parseLong(checksum, 16)) { log.warn("Checksum mismatch in entry {} of tar file {}, skipping...", name, file); @@ -270,7 +270,7 @@ public class SegmentTarManager implement } } - private static String readString(ByteBuffer buffer, int fieldSize) { + private static String readString(Buffer buffer, int fieldSize) { byte[] b = new byte[fieldSize]; buffer.get(b); int n = 0; @@ -280,7 +280,7 @@ public class SegmentTarManager implement return new String(b, 0, n, UTF_8); } - private static int readNumber(ByteBuffer buffer, int fieldSize) { + private static int readNumber(Buffer buffer, int fieldSize) { byte[] b = new byte[fieldSize]; buffer.get(b); int number = 0; Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarReader.java Wed Dec 5 17:00:25 2018 @@ -18,32 +18,32 @@ */ package org.apache.jackrabbit.oak.segment.file.tar; +import static org.apache.jackrabbit.oak.segment.file.tar.SegmentTarWriter.getPaddingSize; +import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; +import static org.apache.jackrabbit.oak.segment.file.tar.index.IndexLoader.newIndexLoader; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; + import com.google.common.base.Stopwatch; -import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader; import org.apache.jackrabbit.oak.segment.file.tar.binaries.InvalidBinaryReferencesIndexException; import org.apache.jackrabbit.oak.segment.file.tar.index.Index; import org.apache.jackrabbit.oak.segment.file.tar.index.IndexEntry; import org.apache.jackrabbit.oak.segment.file.tar.index.IndexLoader; import org.apache.jackrabbit.oak.segment.file.tar.index.InvalidIndexException; +import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.apache.jackrabbit.oak.segment.file.tar.SegmentTarWriter.getPaddingSize; -import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; -import static org.apache.jackrabbit.oak.segment.file.tar.index.IndexLoader.newIndexLoader; - public class SegmentTarReader implements SegmentArchiveReader { private static final Logger log = LoggerFactory.getLogger(SegmentTarReader.class); @@ -71,7 +71,7 @@ public class SegmentTarReader implements } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { int i = index.findEntry(msb, lsb); if (i == -1) { return null; @@ -79,7 +79,7 @@ public class SegmentTarReader implements IndexEntry indexEntry = index.entry(i); ioMonitor.beforeSegmentRead(file, msb, lsb, indexEntry.getLength()); Stopwatch stopwatch = Stopwatch.createStarted(); - ByteBuffer buffer = access.read(indexEntry.getPosition(), indexEntry.getLength()); + Buffer buffer = access.read(indexEntry.getPosition(), indexEntry.getLength()); long elapsed = stopwatch.elapsed(TimeUnit.NANOSECONDS); ioMonitor.afterSegmentRead(file, msb, lsb, indexEntry.getLength(), elapsed); return buffer; @@ -115,7 +115,7 @@ public class SegmentTarReader implements return null; } ReaderAtEnd r = (whence, size) -> { - ByteBuffer buffer = ByteBuffer.allocate(size); + Buffer buffer = Buffer.allocate(size); file.seek(length - 2 * BLOCK_SIZE - whence); file.readFully(buffer.array()); return buffer; @@ -129,9 +129,9 @@ public class SegmentTarReader implements } @Override - public ByteBuffer getGraph() throws IOException { + public Buffer getGraph() throws IOException { int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize(); - ByteBuffer graph = GraphLoader.loadGraph((whence, amount) -> access.read(end - whence, amount)); + Buffer graph = GraphLoader.loadGraph((whence, amount) -> access.read(end - whence, amount)); hasGraph = graph != null; return graph; } @@ -147,7 +147,7 @@ public class SegmentTarReader implements } @Override - public ByteBuffer getBinaryReferences() throws IOException { + public Buffer getBinaryReferences() throws IOException { try { int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize() - getGraphEntrySize(); return BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, amount) -> access.read(end - whence, amount)); @@ -181,7 +181,7 @@ public class SegmentTarReader implements } private int getGraphEntrySize() { - ByteBuffer buffer; + Buffer buffer; try { buffer = getGraph(); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java Wed Dec 5 17:00:25 2018 @@ -20,14 +20,12 @@ package org.apache.jackrabbit.oak.segmen import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.oak.commons.IOUtils.readFully; import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Collections; import java.util.LinkedHashMap; @@ -43,6 +41,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor; import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -133,14 +132,14 @@ public class SegmentTarWriter implements } @Override - public ByteBuffer readSegment(long msb, long lsb) throws IOException { + public Buffer readSegment(long msb, long lsb) throws IOException { IndexEntry indexEntry = index.get(new UUID(msb, lsb)); if (indexEntry == null) { return null; } checkState(channel != null); // implied by entry != null - ByteBuffer data = ByteBuffer.allocate(indexEntry.getLength()); - if (readFully(channel, indexEntry.getPosition(), data) < indexEntry.getLength()) { + Buffer data = Buffer.allocate(indexEntry.getLength()); + if (data.readFully(channel, indexEntry.getPosition()) < indexEntry.getLength()) { throw new EOFException(); } data.rewind(); Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java Wed Dec 5 17:00:25 2018 @@ -28,7 +28,6 @@ import static java.util.Collections.empt import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -55,6 +54,7 @@ import org.apache.jackrabbit.oak.segment import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.apache.jackrabbit.oak.stats.CounterStats; import org.apache.jackrabbit.oak.stats.NoopStats; import org.jetbrains.annotations.NotNull; @@ -547,14 +547,14 @@ public class TarFiles implements Closeab return false; } - public ByteBuffer readSegment(long msb, long lsb) { + public Buffer readSegment(long msb, long lsb) { try { Node head; lock.readLock().lock(); try { if (writer != null) { - ByteBuffer b = writer.readEntry(msb, lsb); + Buffer b = writer.readEntry(msb, lsb); if (b != null) { return b; } @@ -565,7 +565,7 @@ public class TarFiles implements Closeab } for (TarReader reader : iterable(head)) { - ByteBuffer b = reader.readEntry(msb, lsb); + Buffer b = reader.readEntry(msb, lsb); if (b != null) { return b; } Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java?rev=1848226&r1=1848225&r2=1848226&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java (original) +++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java Wed Dec 5 17:00:25 2018 @@ -29,7 +29,6 @@ import static org.apache.jackrabbit.oak. import java.io.Closeable; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -42,13 +41,14 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import com.google.common.base.Predicate; -import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; -import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndex; +import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader; import org.apache.jackrabbit.oak.segment.file.tar.binaries.InvalidBinaryReferencesIndexException; import org.apache.jackrabbit.oak.segment.file.tar.index.IndexEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry; +import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager; import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader; +import org.apache.jackrabbit.oak.segment.spi.persistence.Buffer; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -305,7 +305,7 @@ public class TarReader implements Closea * @param lsb the least significant bits of the segment id * @return the byte buffer, or null if not in this file. */ - ByteBuffer readEntry(long msb, long lsb) throws IOException { + Buffer readEntry(long msb, long lsb) throws IOException { return archive.readSegment(msb, lsb); } @@ -586,7 +586,7 @@ public class TarReader implements Closea * @return The parsed graph, or {@code null} if one was not found. */ Map<UUID, List<UUID>> getGraph() throws IOException { - ByteBuffer buffer = archive.getGraph(); + Buffer buffer = archive.getGraph(); if (buffer == null) { return null; } else {