> getGraph() throws IOException {
- ByteBuffer graph = loadGraph();
- if (graph == null) {
- return null;
- } else {
- return GraphLoader.parseGraph(graph);
- }
+ public ByteBuffer getGraph() throws IOException {
+ int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize();
+ ByteBuffer graph = GraphLoader.loadGraph((whence, amount) -> access.read(end - whence, amount));
+ hasGraph = graph != null;
+ return graph;
}
@Override
public boolean hasGraph() {
if (hasGraph == null) {
try {
- loadGraph();
+ getGraph();
} catch (IOException ignore) { }
}
return hasGraph;
}
- private ByteBuffer loadGraph() throws IOException {
- int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize();
- ByteBuffer graph = GraphLoader.loadGraph((whence, amount) -> access.read(end - whence, amount));
- hasGraph = graph != null;
- return graph;
- }
-
@Override
- public BinaryReferencesIndex getBinaryReferences() throws IOException, InvalidBinaryReferencesIndexException {
- int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize() - getGraphEntrySize();
- return BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, size) -> access.read(end - whence, size));
+ public ByteBuffer getBinaryReferences() throws IOException {
+ try {
+ int end = access.length() - 2 * BLOCK_SIZE - getIndexEntrySize() - getGraphEntrySize();
+ return BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, amount) -> access.read(end - whence, amount));
+ } catch (InvalidBinaryReferencesIndexException e) {
+ throw new IOException(e);
+ }
}
@Override
@@ -179,7 +184,7 @@ public class SegmentTarReader implements SegmentArchiveManager.SegmentArchiveRea
ByteBuffer buffer;
try {
- buffer = loadGraph();
+ buffer = getGraph();
} catch (IOException e) {
log.warn("Exception while loading pre-compiled tar graph", e);
return 0;
@@ -191,6 +196,4 @@ public class SegmentTarReader implements SegmentArchiveManager.SegmentArchiveRea
return getEntrySize(buffer.getInt(buffer.limit() - 8));
}
-
-
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java
index 0a1846ab09..f4d0d5d920 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/SegmentTarWriter.java
@@ -19,7 +19,12 @@
package org.apache.jackrabbit.oak.segment.file.tar;
import com.google.common.base.Stopwatch;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
+import org.apache.jackrabbit.oak.segment.file.tar.index.IndexWriter;
+import org.apache.jackrabbit.oak.segment.file.tar.index.IndexEntry;
+import org.apache.jackrabbit.oak.segment.file.tar.index.SimpleIndexEntry;
+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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,9 +33,10 @@ 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;
import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.zip.CRC32;
@@ -38,7 +44,7 @@ import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkState;
import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE;
-public class SegmentTarWriter implements SegmentArchiveManager.SegmentArchiveWriter {
+public class SegmentTarWriter implements SegmentArchiveWriter {
private static final Logger log = LoggerFactory.getLogger(SegmentTarWriter.class);
@@ -57,7 +63,18 @@ public class SegmentTarWriter implements SegmentArchiveManager.SegmentArchiveWri
private final IOMonitor ioMonitor;
/**
- * File handle. Initialized lazily in {@link #writeSegment(long, long, byte[], int, int, GCGeneration)}
+ * Map of the entries that have already been written. Used by the
+ * {@link #containsSegment(long, long)} and {@link #readSegment(long, long)}
+ * methods to retrieve data from this file while it's still being written,
+ * and finally by the {@link #close()} method to generate the tar index.
+ * The map is ordered in the order that entries have been written.
+ *
+ * The MutableIndex implementation is thread-safe.
+ */
+ private final Map index = Collections.synchronizedMap(new LinkedHashMap<>());
+
+ /**
+ * File handle. Initialized lazily in {@link #writeSegment(long, long, byte[], int, int, int, int, boolean)}
* to avoid creating an extra empty file when just reading from the repository.
* Should only be accessed from synchronized code.
*/
@@ -74,7 +91,7 @@ public class SegmentTarWriter implements SegmentArchiveManager.SegmentArchiveWri
}
@Override
- public TarEntry writeSegment(long msb, long lsb, byte[] data, int offset, int size, GCGeneration generation) throws IOException {
+ public void writeSegment(long msb, long lsb, byte[] data, int offset, int size, int generation, int fullGeneration, boolean compacted) throws IOException {
UUID uuid = new UUID(msb, lsb);
CRC32 checksum = new CRC32();
checksum.update(data, offset, size);
@@ -110,26 +127,25 @@ public class SegmentTarWriter implements SegmentArchiveManager.SegmentArchiveWri
length = currentLength;
- return new TarEntry(msb, lsb, (int) dataOffset, size, generation);
+ index.put(new UUID(msb, lsb), new SimpleIndexEntry(msb, lsb, (int) dataOffset, size, generation, fullGeneration, compacted));
}
@Override
- public ByteBuffer readSegment(TarEntry tarEntry) throws IOException {
+ public ByteBuffer 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(tarEntry.size());
- channel.read(data, tarEntry.offset());
+ ByteBuffer data = ByteBuffer.allocate(indexEntry.getLength());
+ channel.read(data, indexEntry.getPosition());
data.rewind();
return data;
}
@Override
- public void writeIndex(byte[] data) throws IOException {
- byte[] header = newEntryHeader(file.getName() + ".idx", data.length);
- access.write(header);
- access.write(data);
- monitor.written(header.length + data.length);
-
- length = access.getFilePointer();
+ public boolean containsSegment(long msb, long lsb) {
+ return index.containsKey(new UUID(msb, lsb));
}
@Override
@@ -165,8 +181,35 @@ public class SegmentTarWriter implements SegmentArchiveManager.SegmentArchiveWri
return length;
}
+ private void writeIndex() throws IOException {
+ IndexWriter writer = IndexWriter.newIndexWriter(BLOCK_SIZE);
+
+ for (IndexEntry entry : index.values()) {
+ writer.addEntry(
+ entry.getMsb(),
+ entry.getLsb(),
+ entry.getPosition(),
+ entry.getLength(),
+ entry.getGeneration(),
+ entry.getFullGeneration(),
+ entry.isCompacted()
+ );
+ }
+
+ byte[] data = writer.write();
+
+ byte[] header = newEntryHeader(file.getName() + ".idx", data.length);
+ access.write(header);
+ access.write(data);
+ monitor.written(header.length + data.length);
+
+ length = access.getFilePointer();
+ }
+
@Override
public void close() throws IOException {
+ writeIndex();
+
access.write(ZERO_BYTES);
access.write(ZERO_BYTES);
access.close();
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarEntry.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarEntry.java
deleted file mode 100644
index efcb158f97..0000000000
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarEntry.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.jackrabbit.oak.segment.file.tar;
-
-import java.util.Comparator;
-
-/**
- * A file entry location in a tar file. This is used for the index with a tar
- * file.
- */
-public class TarEntry {
-
- /** Size in bytes a tar entry takes up in the tar file */
- static final int SIZE = 33;
-
- static final Comparator OFFSET_ORDER = new Comparator() {
- @Override
- public int compare(TarEntry a, TarEntry b) {
- if (a.offset > b.offset) {
- return 1;
- } else if (a.offset < b.offset) {
- return -1;
- } else {
- return 0;
- }
- }
- };
-
- private final long msb;
-
- private final long lsb;
-
- private final int offset;
-
- private final int size;
-
- private final GCGeneration generation;
-
- public TarEntry(long msb, long lsb, int offset, int size, GCGeneration generation) {
- this.msb = msb;
- this.lsb = lsb;
- this.offset = offset;
- this.size = size;
- this.generation = generation;
- }
-
- public long msb() {
- return msb;
- }
-
- public long lsb() {
- return lsb;
- }
-
- public int offset() {
- return offset;
- }
-
- public int size() {
- return size;
- }
-
- GCGeneration generation() {
- return generation;
- }
-
-}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java
index 1f80536125..1c770a353a 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarFiles.java
@@ -51,8 +51,11 @@ import javax.annotation.Nonnull;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter;
+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.file.FileReaper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java
index 1397462c0a..3ece84ac09 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java
@@ -19,9 +19,14 @@
package org.apache.jackrabbit.oak.segment.file.tar;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
-import org.apache.jackrabbit.oak.segment.file.GCJournal;
+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.GCJournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.ManifestFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.RepositoryLock;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
import org.apache.jackrabbit.oak.segment.file.LocalGCJournalFile;
import org.apache.jackrabbit.oak.segment.file.LocalManifestFile;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java
index 3bdc551368..b385bfdba1 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java
@@ -30,7 +30,6 @@ import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@@ -40,15 +39,18 @@ import java.util.Set;
import java.util.SortedMap;
import java.util.UUID;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import com.google.common.base.Predicate;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
+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.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.spi.persistence.SegmentArchiveReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -232,7 +234,7 @@ public class TarReader implements Closeable {
private static TarReader openFirstFileWithValidIndex(List archives, SegmentArchiveManager archiveManager) {
for (String name : archives) {
try {
- SegmentArchiveManager.SegmentArchiveReader reader = archiveManager.open(name);
+ SegmentArchiveReader reader = archiveManager.open(name);
if (reader != null) {
for (String other : archives) {
if (other != name) {
@@ -252,16 +254,19 @@ public class TarReader implements Closeable {
private final SegmentArchiveManager archiveManager;
- private final SegmentArchiveManager.SegmentArchiveReader archive;
+ private final SegmentArchiveReader archive;
- private final Index index;
+ private final Set segmentUUIDs;
private volatile boolean hasGraph;
- private TarReader(SegmentArchiveManager archiveManager, SegmentArchiveManager.SegmentArchiveReader archive) {
+ private TarReader(SegmentArchiveManager archiveManager, SegmentArchiveReader archive) {
this.archiveManager = archiveManager;
this.archive = archive;
- this.index = archive.getIndex();
+ this.segmentUUIDs = archive.listSegments()
+ .stream()
+ .map(e -> new UUID(e.getMsb(), e.getLsb()))
+ .collect(Collectors.toSet());
}
long size() {
@@ -275,7 +280,7 @@ public class TarReader implements Closeable {
* @return An instance of {@link Set}.
*/
Set getUUIDs() {
- return index.getUUIDs();
+ return segmentUUIDs;
}
/**
@@ -287,7 +292,7 @@ public class TarReader implements Closeable {
* otherwise.
*/
boolean containsEntry(long msb, long lsb) {
- return findEntry(msb, lsb) != -1;
+ return archive.containsSegment(msb, lsb);
}
/**
@@ -305,42 +310,15 @@ public class TarReader implements Closeable {
return archive.readSegment(msb, lsb);
}
- /**
- * Find the position of the given entry in this TAR file.
- *
- * @param msb The most significant bits of the entry identifier.
- * @param lsb The least significant bits of the entry identifier.
- * @return The position of the entry in the TAR file, or {@code -1} if the
- * entry is not found.
- */
- private int findEntry(long msb, long lsb) {
- return index.findEntry(msb, lsb);
- }
-
/**
* Read the entries in this TAR file.
*
- * @return An array of {@link TarEntry}.
+ * @return An array of {@link IndexEntry}.
*/
@Nonnull
- TarEntry[] getEntries() {
- TarEntry[] entries = new TarEntry[index.count()];
- for (int i = 0; i < entries.length; i++) {
- IndexEntry e = index.entry(i);
- entries[i] = new TarEntry(
- e.getMsb(),
- e.getLsb(),
- e.getPosition(),
- e.getLength(),
- newGCGeneration(
- e.getGeneration(),
- e.getFullGeneration(),
- e.isCompacted()
- )
- );
- }
- Arrays.sort(entries, TarEntry.OFFSET_ORDER);
- return entries;
+ SegmentArchiveEntry[] getEntries() {
+ List entryList = archive.listSegments();
+ return entryList.toArray(new SegmentArchiveEntry[entryList.size()]);
}
/**
@@ -428,16 +406,17 @@ public class TarReader implements Closeable {
*/
void mark(Set references, Set reclaimable, CleanupContext context) throws IOException {
Map> graph = getGraph();
- TarEntry[] entries = getEntries();
+ SegmentArchiveEntry[] entries = getEntries();
for (int i = entries.length - 1; i >= 0; i--) {
// A bulk segments is *always* written before any data segment referencing it.
// Backward iteration ensures we see all references to bulk segments before
// we see the bulk segment itself. Therefore we can remove a bulk reference
// from the bulkRefs set once we encounter it, which save us some memory and
// CPU on subsequent look-ups.
- TarEntry entry = entries[i];
- UUID id = new UUID(entry.msb(), entry.lsb());
- if (context.shouldReclaim(id, entry.generation(), references.remove(id))) {
+ SegmentArchiveEntry entry = entries[i];
+ UUID id = new UUID(entry.getMsb(), entry.getLsb());
+ GCGeneration generation = GCGeneration.newGCGeneration(entry);
+ if (context.shouldReclaim(id, generation, references.remove(id))) {
reclaimable.add(id);
} else {
for (UUID refId : getReferences(id, graph)) {
@@ -493,16 +472,16 @@ public class TarReader implements Closeable {
int beforeSize = 0;
int afterCount = 0;
- TarEntry[] entries = getEntries();
+ SegmentArchiveEntry[] entries = getEntries();
for (int i = 0; i < entries.length; i++) {
- TarEntry entry = entries[i];
- beforeSize += archive.getEntrySize(entry.size());
- UUID id = new UUID(entry.msb(), entry.lsb());
+ SegmentArchiveEntry entry = entries[i];
+ beforeSize += archive.getEntrySize(entry.getLength());
+ UUID id = new UUID(entry.getMsb(), entry.getLsb());
if (reclaim.contains(id)) {
cleaned.add(id);
entries[i] = null;
} else {
- afterSize += archive.getEntrySize(entry.size());
+ afterSize += archive.getEntrySize(entry.getLength());
afterCount += 1;
}
}
@@ -535,12 +514,12 @@ public class TarReader implements Closeable {
log.debug("Writing new generation {}", newFile);
TarWriter writer = new TarWriter(archiveManager, newFile);
- for (TarEntry entry : entries) {
+ for (SegmentArchiveEntry entry : entries) {
if (entry != null) {
- long msb = entry.msb();
- long lsb = entry.lsb();
- int size = entry.size();
- GCGeneration gen = entry.generation();
+ long msb = entry.getMsb();
+ long lsb = entry.getLsb();
+ int size = entry.getLength();
+ GCGeneration gen = GCGeneration.newGCGeneration(entry);
byte[] data = new byte[size];
archive.readSegment(msb, lsb).get(data);
writer.writeEntry(msb, lsb, data, 0, size, gen);
@@ -608,7 +587,12 @@ public class TarReader implements Closeable {
* @return The parsed graph, or {@code null} if one was not found.
*/
Map> getGraph() throws IOException {
- return archive.getGraph();
+ ByteBuffer buffer = archive.getGraph();
+ if (buffer == null) {
+ return null;
+ } else {
+ return GraphLoader.parseGraph(buffer);
+ }
}
private boolean hasGraph() {
@@ -629,7 +613,7 @@ public class TarReader implements Closeable {
BinaryReferencesIndex getBinaryReferences() {
BinaryReferencesIndex index = null;
try {
- index = archive.getBinaryReferences();
+ index = BinaryReferencesIndexLoader.parseBinaryReferencesIndex(archive.getBinaryReferences());
} catch (InvalidBinaryReferencesIndexException | IOException e) {
log.warn("Exception while loading binary reference", e);
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
index 8840b59137..406c72b87e 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
@@ -23,10 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Maps.newHashMap;
-import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Sets.newHashSet;
import static java.lang.String.format;
-import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE;
import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.FILE_NAME_FORMAT;
import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter.newBinaryReferencesIndexWriter;
@@ -40,9 +38,9 @@ import java.util.Set;
import java.util.UUID;
import java.util.zip.CRC32;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager;
import org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter;
-import org.apache.jackrabbit.oak.segment.file.tar.index.IndexWriter;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,17 +61,6 @@ class TarWriter implements Closeable {
*/
private boolean closed = false;
- /**
- * Map of the entries that have already been written. Used by the
- * {@link #containsEntry(long, long)} and {@link #readEntry(long, long)}
- * methods to retrieve data from this file while it's still being written,
- * and finally by the {@link #close()} method to generate the tar index.
- * The map is ordered in the order that entries have been written.
- *
- * Should only be accessed from synchronized code.
- */
- private final Map index = newLinkedHashMap();
-
/**
* List of binary references contained in this TAR file.
*/
@@ -86,7 +73,7 @@ class TarWriter implements Closeable {
private final SegmentArchiveManager archiveManager;
- private final SegmentArchiveManager.SegmentArchiveWriter archive;
+ private final SegmentArchiveWriter archive;
/** This object is used as an additional
* synchronization point by {@link #flush()} and {@link #close()} to
@@ -112,7 +99,7 @@ class TarWriter implements Closeable {
synchronized boolean containsEntry(long msb, long lsb) {
checkState(!closed);
- return index.containsKey(new UUID(msb, lsb));
+ return archive.containsSegment(msb, lsb);
}
/**
@@ -124,16 +111,10 @@ class TarWriter implements Closeable {
* @return the byte buffer, or null if not in this file
*/
ByteBuffer readEntry(long msb, long lsb) throws IOException {
- TarEntry entry;
synchronized (this) {
checkState(!closed);
- entry = index.get(new UUID(msb, lsb));
- }
- if (entry != null) {
- return archive.readSegment(entry);
- } else {
- return null;
}
+ return archive.readSegment(msb, lsb);
}
long writeEntry(long msb, long lsb, byte[] data, int offset, int size, GCGeneration generation) throws IOException {
@@ -143,11 +124,10 @@ class TarWriter implements Closeable {
synchronized (this) {
checkState(!closed);
- TarEntry entry = archive.writeSegment(msb, lsb, data, offset, size, generation);
+ archive.writeSegment(msb, lsb, data, offset, size, generation.getGeneration(), generation.getFullGeneration(), generation.isCompacted());
long currentLength = archive.getLength();
checkState(currentLength <= Integer.MAX_VALUE);
- index.put(new UUID(msb, lsb), entry);
return currentLength;
}
@@ -219,7 +199,6 @@ class TarWriter implements Closeable {
synchronized (closeMonitor) {
writeBinaryReferences();
writeGraph();
- writeIndex();
archive.close();
}
@@ -311,25 +290,6 @@ class TarWriter implements Closeable {
archive.writeGraph(buffer.array());
}
- private void writeIndex() throws IOException {
- IndexWriter writer = IndexWriter.newIndexWriter(BLOCK_SIZE);
-
- for (TarEntry entry : index.values()) {
- writer.addEntry(
- entry.msb(),
- entry.lsb(),
- entry.offset(),
- entry.size(),
- entry.generation().getGeneration(),
- entry.generation().getFullGeneration(),
- entry.generation().isCompacted()
- );
- }
-
- byte[] index = writer.write();
- archive.writeIndex(index);
- }
-
synchronized long fileLength() {
return archive.getLength();
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java
index 7ab8cdc8fe..09f8dce499 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoader.java
@@ -18,6 +18,7 @@
package org.apache.jackrabbit.oak.segment.file.tar.binaries;
import java.io.IOException;
+import java.nio.ByteBuffer;
import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd;
@@ -40,7 +41,7 @@ public class BinaryReferencesIndexLoader {
* @throws InvalidBinaryReferencesIndexException if the index is invalid or
* malformed.
*/
- public static BinaryReferencesIndex loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
+ public static ByteBuffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
switch (readMagic(reader)) {
case BinaryReferencesIndexLoaderV1.MAGIC:
return BinaryReferencesIndexLoaderV1.loadBinaryReferencesIndex(reader);
@@ -51,8 +52,25 @@ public class BinaryReferencesIndexLoader {
}
}
+ public static BinaryReferencesIndex parseBinaryReferencesIndex(ByteBuffer buffer) throws InvalidBinaryReferencesIndexException {
+ switch (readMagic(buffer)) {
+ case BinaryReferencesIndexLoaderV1.MAGIC:
+ return BinaryReferencesIndexLoaderV1.parseBinaryReferencesIndex(buffer);
+ case BinaryReferencesIndexLoaderV2.MAGIC:
+ return BinaryReferencesIndexLoaderV2.parseBinaryReferencesIndex(buffer);
+ default:
+ throw new InvalidBinaryReferencesIndexException("Unrecognized magic number");
+ }
+ }
+
private static int readMagic(ReaderAtEnd reader) throws IOException {
return reader.readAtEnd(Integer.BYTES, Integer.BYTES).getInt();
}
+ private static int readMagic(ByteBuffer buffer) {
+ buffer.position(buffer.limit() - Integer.BYTES);
+ int magic = buffer.getInt();
+ buffer.rewind();
+ return magic;
+ }
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java
index a760fcebbc..5d0c40e51c 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1.java
@@ -35,7 +35,7 @@ class BinaryReferencesIndexLoaderV1 {
static final int FOOTER_SIZE = 16;
- static BinaryReferencesIndex loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
+ static ByteBuffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
ByteBuffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE);
int crc32 = meta.getInt();
@@ -53,18 +53,41 @@ class BinaryReferencesIndexLoaderV1 {
throw new InvalidBinaryReferencesIndexException("Invalid size");
}
- ByteBuffer buffer = reader.readAtEnd(size, size - FOOTER_SIZE);
+ return reader.readAtEnd(size, size);
+ }
+
+ public static BinaryReferencesIndex parseBinaryReferencesIndex(ByteBuffer buffer) throws InvalidBinaryReferencesIndexException {
+ ByteBuffer data = buffer.slice();
+ data.limit(data.limit() - FOOTER_SIZE);
+
+ buffer.position(buffer.limit() - FOOTER_SIZE);
+ ByteBuffer meta = buffer.slice();
+
+ int crc32 = meta.getInt();
+ int count = meta.getInt();
+ int size = meta.getInt();
+ int magic = meta.getInt();
+
+ if (magic != MAGIC) {
+ throw new InvalidBinaryReferencesIndexException("Invalid magic number");
+ }
+ if (count < 0) {
+ throw new InvalidBinaryReferencesIndexException("Invalid count");
+ }
+ if (size < count * 22 + 16) {
+ throw new InvalidBinaryReferencesIndexException("Invalid size");
+ }
CRC32 checksum = new CRC32();
- buffer.mark();
- checksum.update(buffer);
- buffer.reset();
+ data.mark();
+ checksum.update(data);
+ data.reset();
if ((int) (checksum.getValue()) != crc32) {
throw new InvalidBinaryReferencesIndexException("Invalid checksum");
}
- return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, buffer));
+ return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, data));
}
private static Map>> parseBinaryReferencesIndex(int count, ByteBuffer buffer) {
@@ -123,5 +146,4 @@ class BinaryReferencesIndexLoaderV1 {
buffer.get(data);
return new String(data, Charsets.UTF_8);
}
-
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java
index 91856158ac..3ecaf006d1 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2.java
@@ -35,7 +35,7 @@ class BinaryReferencesIndexLoaderV2 {
static final int FOOTER_SIZE = 16;
- static BinaryReferencesIndex loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
+ static ByteBuffer loadBinaryReferencesIndex(ReaderAtEnd reader) throws IOException, InvalidBinaryReferencesIndexException {
ByteBuffer meta = reader.readAtEnd(FOOTER_SIZE, FOOTER_SIZE);
int crc32 = meta.getInt();
@@ -53,20 +53,41 @@ class BinaryReferencesIndexLoaderV2 {
throw new InvalidBinaryReferencesIndexException("Invalid size");
}
- ByteBuffer buffer = reader.readAtEnd(size, size - FOOTER_SIZE);
+ return reader.readAtEnd(size, size);
+ }
+
+ public static BinaryReferencesIndex parseBinaryReferencesIndex(ByteBuffer buffer) throws InvalidBinaryReferencesIndexException {
+ ByteBuffer data = buffer.slice();
+ data.limit(data.limit() - FOOTER_SIZE);
+
+ buffer.position(buffer.limit() - FOOTER_SIZE);
+ ByteBuffer meta = buffer.slice();
+
+ int crc32 = meta.getInt();
+ int count = meta.getInt();
+ int size = meta.getInt();
+ int magic = meta.getInt();
+
+ if (magic != MAGIC) {
+ throw new InvalidBinaryReferencesIndexException("Invalid magic number");
+ }
+ if (count < 0) {
+ throw new InvalidBinaryReferencesIndexException("Invalid count");
+ }
+ if (size < count * 22 + 16) {
+ throw new InvalidBinaryReferencesIndexException("Invalid size");
+ }
CRC32 checksum = new CRC32();
- byte[] data = new byte[size - FOOTER_SIZE];
- buffer.mark();
- buffer.get(data);
- buffer.reset();
+ data.mark();
checksum.update(data);
+ data.reset();
if ((int) (checksum.getValue()) != crc32) {
throw new InvalidBinaryReferencesIndexException("Invalid checksum");
}
- return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, buffer));
+ return new BinaryReferencesIndex(parseBinaryReferencesIndex(count, data));
}
private static Map>> parseBinaryReferencesIndex(int count, ByteBuffer buffer) {
@@ -127,5 +148,4 @@ class BinaryReferencesIndexLoaderV2 {
buffer.get(data);
return new String(data, Charsets.UTF_8);
}
-
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntry.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntry.java
index d1bd813c8e..aa9aa528bd 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntry.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/IndexEntry.java
@@ -17,10 +17,14 @@
package org.apache.jackrabbit.oak.segment.file.tar.index;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry;
+
+import java.util.Comparator;
+
/**
* An entry in the index of entries of a TAR file.
*/
-public interface IndexEntry {
+public interface IndexEntry extends SegmentArchiveEntry {
/**
* Return the most significant bits of the identifier of this entry.
@@ -71,4 +75,16 @@ public interface IndexEntry {
*/
boolean isCompacted();
+ Comparator POSITION_ORDER = new Comparator() {
+ @Override
+ public int compare(IndexEntry a, IndexEntry b) {
+ if (a.getPosition() > b.getPosition()) {
+ return 1;
+ } else if (a.getPosition() < b.getPosition()) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+ };
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/SimpleIndexEntry.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/SimpleIndexEntry.java
new file mode 100644
index 0000000000..54551b8f43
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/index/SimpleIndexEntry.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.segment.file.tar.index;
+
+public class SimpleIndexEntry implements IndexEntry {
+
+ private final long msb;
+
+ private final long lsb;
+
+ private final int position;
+
+ private final int length;
+
+ private final int generation;
+
+ private final int fullGeneration;
+
+ private final boolean compacted;
+
+ public SimpleIndexEntry(long msb, long lsb, int position, int length, int generation, int fullGeneration, boolean compacted) {
+ this.msb = msb;
+ this.lsb = lsb;
+ this.position = position;
+ this.length = length;
+ this.generation = generation;
+ this.fullGeneration = fullGeneration;
+ this.compacted = compacted;
+ }
+
+ @Override
+ public long getMsb() {
+ return msb;
+ }
+
+ @Override
+ public long getLsb() {
+ return lsb;
+ }
+
+ @Override
+ public int getPosition() {
+ return position;
+ }
+
+ @Override
+ public int getLength() {
+ return length;
+ }
+
+ @Override
+ public int getGeneration() {
+ return generation;
+ }
+
+ @Override
+ public int getFullGeneration() {
+ return fullGeneration;
+ }
+
+ @Override
+ public boolean isCompacted() {
+ return compacted;
+ }
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java
index ec559aa5da..f129d737f0 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/ConsistencyChecker.java
@@ -59,7 +59,7 @@ import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.segment.file.JournalEntry;
import org.apache.jackrabbit.oak.segment.file.JournalReader;
import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
-import org.apache.jackrabbit.oak.segment.file.tar.IOMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeState;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java
index ea85dea207..dfec7e1462 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tooling/RevisionHistory.java
@@ -36,7 +36,7 @@ import com.google.common.collect.Iterators;
import org.apache.jackrabbit.oak.json.BlobSerializer;
import org.apache.jackrabbit.oak.json.JsonSerializer;
import org.apache.jackrabbit.oak.segment.SegmentNodeState;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.segment.file.JournalEntry;
import org.apache.jackrabbit.oak.segment.file.JournalReader;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileStoreMonitor.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/FileStoreMonitor.java
similarity index 96%
rename from oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileStoreMonitor.java
rename to oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/FileStoreMonitor.java
index 7a390fe016..b72498c160 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileStoreMonitor.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/FileStoreMonitor.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.jackrabbit.oak.segment.file.tar;
+package org.apache.jackrabbit.oak.segment.spi.monitor;
/**
* FileStoreMonitor are notified for any writes or deletes
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileStoreMonitorAdapter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/FileStoreMonitorAdapter.java
similarity index 95%
rename from oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileStoreMonitorAdapter.java
rename to oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/FileStoreMonitorAdapter.java
index 962f9b85d2..55cdafa87d 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/FileStoreMonitorAdapter.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/FileStoreMonitorAdapter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.jackrabbit.oak.segment.file.tar;
+package org.apache.jackrabbit.oak.segment.spi.monitor;
public class FileStoreMonitorAdapter implements FileStoreMonitor {
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/IOMonitor.java
similarity index 98%
rename from oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
rename to oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/IOMonitor.java
index d05268a6b6..e9fa6ac052 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitor.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/IOMonitor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.jackrabbit.oak.segment.file.tar;
+package org.apache.jackrabbit.oak.segment.spi.monitor;
import java.io.File;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitorAdapter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/IOMonitorAdapter.java
similarity index 96%
rename from oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitorAdapter.java
rename to oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/IOMonitorAdapter.java
index a2fa10ead7..1e9fa05390 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/IOMonitorAdapter.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/monitor/IOMonitorAdapter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.jackrabbit.oak.segment.file.tar;
+package org.apache.jackrabbit.oak.segment.spi.monitor;
import java.io.File;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/GCJournalFile.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/GCJournalFile.java
new file mode 100644
index 0000000000..064e551b2c
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/GCJournalFile.java
@@ -0,0 +1,12 @@
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import java.io.IOException;
+import java.util.List;
+
+public interface GCJournalFile {
+
+ void writeLine(String line) throws IOException;
+
+ List readLines() throws IOException;
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFile.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFile.java
new file mode 100644
index 0000000000..260a3401b8
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFile.java
@@ -0,0 +1,14 @@
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import java.io.IOException;
+
+public interface JournalFile {
+
+ JournalFileReader openJournalReader() throws IOException;
+
+ JournalFileWriter openJournalWriter() throws IOException;
+
+ String getName();
+
+ boolean exists();
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFileReader.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFileReader.java
new file mode 100644
index 0000000000..0d1eae5ef7
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFileReader.java
@@ -0,0 +1,10 @@
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+public interface JournalFileReader extends Closeable {
+
+ String readLine() throws IOException;
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFileWriter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFileWriter.java
new file mode 100644
index 0000000000..54ab48ad05
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/JournalFileWriter.java
@@ -0,0 +1,12 @@
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+public interface JournalFileWriter extends Closeable {
+
+ void truncate() throws IOException;
+
+ void writeLine(String line) throws IOException;
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/ManifestFile.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/ManifestFile.java
new file mode 100644
index 0000000000..45c7c0a6d2
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/ManifestFile.java
@@ -0,0 +1,14 @@
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import java.io.IOException;
+import java.util.Properties;
+
+public interface ManifestFile {
+
+ boolean exists();
+
+ Properties load() throws IOException;
+
+ void save(Properties properties) throws IOException;
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/RepositoryLock.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/RepositoryLock.java
new file mode 100644
index 0000000000..bbe8c3a004
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/RepositoryLock.java
@@ -0,0 +1,9 @@
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import java.io.IOException;
+
+public interface RepositoryLock {
+
+ void unlock() throws IOException;
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveEntry.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveEntry.java
new file mode 100644
index 0000000000..44cd459e29
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveEntry.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+public interface SegmentArchiveEntry {
+
+ /**
+ * Return the most significant bits of the identifier of this entry.
+ *
+ * @return the most significant bits of the identifier of this entry.
+ */
+ long getMsb();
+
+ /**
+ * Return the least significant bits of the identifier of this entry.
+ *
+ * @return the least significant bits of the identifier of this entry.
+ */
+ long getLsb();
+
+ /**
+ * Return the length of this entry in the archive.
+ *
+ * @return the length of this entry in the archive.
+ */
+ int getLength();
+
+ /**
+ * Return the generation of this entry.
+ *
+ * @return the generation of this entry.
+ */
+ int getGeneration();
+
+ /**
+ * Return the full generation of this entry.
+ *
+ * @return the full generation of this entry.
+ */
+ int getFullGeneration();
+
+ /**
+ * Return {@code true} if this entry was generated by a compaction operation.
+ *
+ * @return {@code true} if this entry was generated by a compaction operation.
+ */
+ boolean isCompacted();
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveManager.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveManager.java
new file mode 100644
index 0000000000..8e6f713f1a
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveManager.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * SegmentArchiveManager provides a low-level access to the segment files (eg.
+ * stored in the .tar). It allows to perform a few FS-like operations (delete,
+ * rename, copy, etc.) and also opens the segment archives either for reading
+ * or reading and writing.
+ */
+public interface SegmentArchiveManager {
+
+ /**
+ * List names of the available archives.
+ *
+ * @return archive list
+ */
+ @Nonnull
+ List listArchives() throws IOException;
+
+ /**
+ * Opens a given archive for reading.
+ *
+ * @param archiveName
+ * @return the archive reader or null if the archive doesn't exist
+ */
+ @Nullable
+ SegmentArchiveReader open(@Nonnull String archiveName) throws IOException;
+
+ /**
+ * Creates a new archive.
+ *
+ * @param archiveName
+ * @return the archive writer
+ */
+ @Nonnull
+ SegmentArchiveWriter create(@Nonnull String archiveName) throws IOException;
+
+ /**
+ * Deletes the archive if exists.
+ *
+ * @param archiveName
+ * @return true if the archive was removed, false otherwise
+ */
+ boolean delete(@Nonnull String archiveName);
+
+ /**
+ * Renames the archive.
+ *
+ * @param from the existing archive
+ * @param to new name
+ * @return true if the archive was renamed, false otherwise
+ */
+ boolean renameTo(@Nonnull String from, @Nonnull String to);
+
+ /**
+ * Copies the archive with all the segments.
+ *
+ * @param from the existing archive
+ * @param to new name
+ */
+ void copyFile(@Nonnull String from, @Nonnull String to) throws IOException;
+
+ /**
+ * Check if archive exists.
+ *
+ * @param archiveName archive to check
+ * @return true if archive exists, false otherwise
+ */
+ boolean exists(@Nonnull String archiveName);
+
+ /**
+ * Finds all the segments included in the archive.
+ *
+ * @param archiveName archive to recover
+ * @param entries results will be put there, in the order of presence in the
+ * archive
+ */
+ void recoverEntries(@Nonnull String archiveName, @Nonnull LinkedHashMap entries) throws IOException;
+
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java
new file mode 100644
index 0000000000..aaf11ca967
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+public interface SegmentArchiveReader {
+
+ /**
+ * Read the segment.
+ *
+ * @param msb
+ * @param lsb
+ * @return byte buffer containing the segment data or null if segment doesn't exist
+ */
+ @Nullable
+ ByteBuffer readSegment(long msb, long lsb) throws IOException;
+
+ /**
+ * Check if the segment exists.
+ *
+ * @param msb
+ * @param lsb
+ * @return true if the segment exists
+ */
+ boolean containsSegment(long msb, long lsb);
+
+ /**
+ * List all the segments, in the order as they have been written to the archive.
+ *
+ * @return segment list, ordered by their position in the archive
+ */
+ List listSegments();
+
+ /**
+ * Loads and returns the graph.
+ *
+ * @return the segment graph or null if the persisted graph doesn't exist.
+ */
+ @Nullable
+ ByteBuffer getGraph() throws IOException;
+
+ /**
+ * Check if the persisted graph exists.
+ *
+ * @return true if the graph exists, false otherwise
+ */
+ boolean hasGraph();
+
+ /**
+ * Loads and returns the binary references.
+ *
+ * @return binary references
+ */
+ @Nonnull
+ ByteBuffer getBinaryReferences() throws IOException;
+
+ /**
+ * Get the current length of the archive.
+ *
+ * @return length of the archive, in bytes
+ */
+ long length();
+
+ /**
+ * Get the name of the archive.
+ *
+ * @return archive name
+ */
+ @Nonnull
+ String getName();
+
+ /**
+ * Close the archive.
+ */
+ void close() throws IOException;
+
+ /**
+ * Returns the size of the entry
+ * @param size
+ * @return
+ */
+ int getEntrySize(int size);
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java
new file mode 100644
index 0000000000..0e39f81207
--- /dev/null
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveWriter.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.segment.spi.persistence;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * Allows to write in the new archive.
+ */
+public interface SegmentArchiveWriter {
+
+ /**
+ * Write the new segment to the archive.
+ *
+ * @param msb
+ * @param lsb
+ * @param data
+ * @param offset
+ * @param size
+ * @param generation
+ * @param fullGeneration
+ * @param isCompacted
+ * @return the entry representing the new segment. Can be later used for the {@link #readSegment(long, long)} method.
+ */
+ @Nonnull
+ void writeSegment(long msb, long lsb, @Nonnull byte[] data, int offset, int size, int generation, int fullGeneration, boolean isCompacted) throws IOException;
+
+ /**
+ * Read the segment.
+ *
+ * @param msb
+ * @param lsb
+ * @return byte buffer containing the segment data or null if segment doesn't exist
+ */
+ @Nullable
+ ByteBuffer readSegment(long msb, long lsb) throws IOException;
+
+ /**
+ * Check if the segment exists.
+ *
+ * @param msb
+ * @param lsb
+ * @return true if the segment exists
+ */
+ boolean containsSegment(long msb, long lsb);
+
+ /**
+ * Write the graph data.
+ *
+ * @param data
+ */
+ void writeGraph(@Nonnull byte[] data) throws IOException;
+
+ /**
+ * Write the binary references data.
+ *
+ * @param data
+ */
+ void writeBinaryReferences(@Nonnull byte[] data) throws IOException;
+
+ /**
+ * Get the current length of the archive.
+ *
+ * @return length of the archive, in bytes
+ */
+ long getLength();
+
+ /**
+ * Close the archive.
+ */
+ void close() throws IOException;
+
+ /**
+ * Check if the archive has been created (eg. something has been written).
+ *
+ * @return true if the archive has been created, false otherwise
+ */
+ boolean isCreated();
+
+ /**
+ * Flush all the data to the storage.
+ */
+ void flush() throws IOException;
+
+ /**
+ * Get the name of the archive.
+ *
+ * @return archive name
+ */
+ @Nonnull
+ String getName();
+}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStorePersistence.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentNodeStorePersistence.java
similarity index 52%
rename from oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStorePersistence.java
rename to oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentNodeStorePersistence.java
index fd30a1ac96..ea4dc4b363 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStorePersistence.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentNodeStorePersistence.java
@@ -16,15 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.jackrabbit.oak.segment;
+package org.apache.jackrabbit.oak.segment.spi.persistence;
-import org.apache.jackrabbit.oak.segment.file.tar.FileStoreMonitor;
-import org.apache.jackrabbit.oak.segment.file.tar.IOMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitor;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor;
-import java.io.Closeable;
import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
public interface SegmentNodeStorePersistence {
@@ -40,52 +37,4 @@ public interface SegmentNodeStorePersistence {
RepositoryLock lockRepository() throws IOException;
- interface JournalFile {
-
- JournalFileReader openJournalReader() throws IOException;
-
- JournalFileWriter openJournalWriter() throws IOException;
-
- String getName();
-
- boolean exists();
- }
-
- interface JournalFileReader extends Closeable {
-
- String readLine() throws IOException;
-
- }
-
- interface JournalFileWriter extends Closeable {
-
- void truncate() throws IOException;
-
- void writeLine(String line) throws IOException;
-
- }
-
- interface GCJournalFile {
-
- void writeLine(String line) throws IOException;
-
- List readLines() throws IOException;
-
- }
-
- interface ManifestFile {
-
- boolean exists();
-
- Properties load() throws IOException;
-
- void save(Properties properties) throws IOException;
-
- }
-
- interface RepositoryLock {
-
- void unlock() throws IOException;
-
- }
}
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java
index 2a4cd5ca96..4425fde0d1 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Compact.java
@@ -39,8 +39,8 @@ import javax.annotation.Nullable;
import com.google.common.base.Stopwatch;
import org.apache.jackrabbit.oak.segment.SegmentCache;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFileWriter;
+import org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.JournalFileWriter;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java
index 8b6db6ab43..98bbbfe571 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/History.java
@@ -23,7 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.io.File;
import java.util.Iterator;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile;
import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
import org.apache.jackrabbit.oak.segment.file.tooling.RevisionHistory;
import org.apache.jackrabbit.oak.segment.file.tooling.RevisionHistory.HistoryElement;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java
index ffa0a99ae6..403c40f6f7 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Utils.java
@@ -30,7 +30,7 @@ import javax.annotation.Nonnull;
import com.google.common.base.Function;
import com.google.common.collect.Iterators;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.JournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.JournalFile;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.segment.file.JournalEntry;
import org.apache.jackrabbit.oak.segment.file.JournalReader;
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java
index 9cb88ccbe9..b58b124721 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/GcJournalTest.java
@@ -33,7 +33,8 @@ import java.util.List;
import org.apache.jackrabbit.oak.commons.IOUtils;
import org.apache.jackrabbit.oak.segment.RecordId;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
+import org.apache.jackrabbit.oak.segment.spi.persistence.GCJournalFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
import org.apache.jackrabbit.oak.segment.file.GCJournal.GCJournalEntry;
import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
import org.junit.Rule;
@@ -85,7 +86,7 @@ public class GcJournalTest {
Collection all = gc.readAll();
assertEquals(all.size(), 3);
- SegmentNodeStorePersistence.GCJournalFile gcFile = getPersistence().getGCJournalFile();
+ GCJournalFile gcFile = getPersistence().getGCJournalFile();
List allLines = gcFile.readLines();
assertEquals(allLines.size(), 3);
}
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java
index 8225a56f4e..f1fcfd94d6 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/ManifestCheckerTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
import java.io.File;
import java.nio.file.Files;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence.ManifestFile;
+import org.apache.jackrabbit.oak.segment.spi.persistence.ManifestFile;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
index c014bb424e..7314592c86 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/SizeDeltaGCEstimationTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
import org.junit.Before;
import org.junit.Rule;
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java
index c9b79027c8..93cafa74a0 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/TarRevisionsTest.java
@@ -45,7 +45,7 @@ import com.google.common.util.concurrent.ListeningExecutorService;
import org.apache.jackrabbit.oak.segment.RecordId;
import org.apache.jackrabbit.oak.segment.SegmentNodeBuilder;
import org.apache.jackrabbit.oak.segment.SegmentNodeState;
-import org.apache.jackrabbit.oak.segment.SegmentNodeStorePersistence;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
import org.apache.jackrabbit.oak.segment.SegmentReader;
import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
import org.junit.After;
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java
index 79ff22c6f6..55295d40af 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFileTest.java
@@ -36,7 +36,10 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -93,8 +96,8 @@ public class TarFileTest {
}
try (TarReader reader = TarReader.open("data00000a.tar", archiveManager)) {
- TarEntry[] entries = reader.getEntries();
- assertEquals(newGCGeneration(1, 2, false), entries[0].generation());
+ SegmentArchiveEntry[] entries = reader.getEntries();
+ assertEquals(newGCGeneration(1, 2, false), newGCGeneration(entries[0]));
}
}
@@ -111,8 +114,8 @@ public class TarFileTest {
}
try (TarReader reader = TarReader.open("data00000a.tar", archiveManager)) {
- TarEntry[] entries = reader.getEntries();
- assertEquals(newGCGeneration(1, 2, true), entries[0].generation());
+ SegmentArchiveEntry[] entries = reader.getEntries();
+ assertEquals(newGCGeneration(1, 2, true), newGCGeneration(entries[0]));
}
}
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java
index 0c201c4fc6..2c9e8a5367 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarFilesTest.java
@@ -42,6 +42,8 @@ import java.util.Set;
import java.util.UUID;
import org.apache.jackrabbit.oak.segment.file.tar.TarFiles.CleanupResult;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java
index 54ddd1135e..964b40ced2 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriterTest.java
@@ -29,7 +29,9 @@ import java.io.File;
import java.io.IOException;
import java.util.UUID;
-import org.apache.jackrabbit.oak.segment.SegmentArchiveManager;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java
index 2298d0a161..c29355934b 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderTest.java
@@ -50,12 +50,13 @@ public class BinaryReferencesIndexLoaderTest {
}
private static BinaryReferencesIndex loadIndex(ByteBuffer buffer) throws Exception {
- return BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, length) -> {
+ ByteBuffer data = BinaryReferencesIndexLoader.loadBinaryReferencesIndex((whence, length) -> {
ByteBuffer slice = buffer.duplicate();
slice.position(slice.limit() - whence);
slice.limit(slice.position() + length);
return slice.slice();
});
+ return BinaryReferencesIndexLoader.parseBinaryReferencesIndex(data);
}
@Test(expected = InvalidBinaryReferencesIndexException.class)
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java
index b21cdfa0d8..a1c4d09799 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV1Test.java
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV1.FOOTER_SIZE;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV1.MAGIC;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV1.loadBinaryReferencesIndex;
+import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV1.parseBinaryReferencesIndex;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -40,12 +41,13 @@ public class BinaryReferencesIndexLoaderV1Test {
}
private static BinaryReferencesIndex loadIndex(ByteBuffer buffer) throws Exception {
- return loadBinaryReferencesIndex((whence, length) -> {
+ ByteBuffer data = loadBinaryReferencesIndex((whence, length) -> {
ByteBuffer slice = buffer.duplicate();
slice.position(slice.limit() - whence);
slice.limit(slice.position() + length);
return slice.slice();
});
+ return parseBinaryReferencesIndex(data);
}
private static void assertInvalidBinaryReferencesIndexException(ByteBuffer buffer, String message) throws Exception {
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java
index 5ef08be53e..99d03ba880 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexLoaderV2Test.java
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV2.FOOTER_SIZE;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV2.MAGIC;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV2.loadBinaryReferencesIndex;
+import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoaderV2.parseBinaryReferencesIndex;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -40,12 +41,13 @@ public class BinaryReferencesIndexLoaderV2Test {
}
private static BinaryReferencesIndex loadIndex(ByteBuffer buffer) throws Exception {
- return loadBinaryReferencesIndex((whence, length) -> {
+ ByteBuffer data = loadBinaryReferencesIndex((whence, length) -> {
ByteBuffer slice = buffer.duplicate();
slice.position(slice.limit() - whence);
slice.limit(slice.position() + length);
return slice.slice();
});
+ return parseBinaryReferencesIndex(data);
}
private static void assertInvalidBinaryReferencesIndexException(ByteBuffer buffer, String message) throws Exception {
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java
index 51ed002cb5..c653236370 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/tar/binaries/BinaryReferencesIndexWriterTest.java
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.segment.file.tar.binaries;
import static java.util.Arrays.asList;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader.loadBinaryReferencesIndex;
+import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexLoader.parseBinaryReferencesIndex;
import static org.apache.jackrabbit.oak.segment.file.tar.binaries.BinaryReferencesIndexWriter.newBinaryReferencesIndexWriter;
import static org.junit.Assert.assertEquals;
@@ -52,7 +53,8 @@ public class BinaryReferencesIndexWriterTest {
byte[] data = writer.write();
- BinaryReferencesIndex index = loadBinaryReferencesIndex((whence, length) -> ByteBuffer.wrap(data, data.length - whence, length));
+ ByteBuffer buffer = loadBinaryReferencesIndex((whence, length) -> ByteBuffer.wrap(data, data.length - whence, length));
+ BinaryReferencesIndex index = parseBinaryReferencesIndex(buffer);
Generation g1 = new Generation(1, 2, false);
Generation g2 = new Generation(3, 4, true);
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
index 2cb8aed4ee..e6476ea61d 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java
@@ -40,7 +40,7 @@ import org.apache.jackrabbit.oak.segment.SegmentVersion;
import org.apache.jackrabbit.oak.segment.data.SegmentData;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.segment.file.LocalManifestFile;
-import org.apache.jackrabbit.oak.segment.file.tar.IOMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
import org.apache.jackrabbit.oak.segment.file.tar.TarFiles;
import org.apache.jackrabbit.oak.segment.tool.Compact;
import org.junit.Before;