Skip to content

Commit

Permalink
OAK-4295 - Add a manifest file in the root folder of the segment store
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1756374 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
francescomari committed Aug 15, 2016
1 parent 49a3808 commit 2b6c2f5
Show file tree
Hide file tree
Showing 65 changed files with 294 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static List<Integer> createSequence(int from, int to, int count) {
}

@Parameterized.Parameters
public static Collection<Object[]> fixtures() throws IOException {
public static Collection<Object[]> fixtures() throws Exception {
File file = new File(new File("target"), "tar." + System.nanoTime());
SegmentStore segmentStore = FileStore.builder(file).withMaxFileSize(256).withMemoryMapping(true).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -134,7 +133,7 @@ public void tearDown() {
}

@Parameterized.Parameters
public static Collection<Object[]> fixtures() throws IOException {
public static Collection<Object[]> fixtures() throws Exception {
File file = getTestDir("tar");
SegmentStore segmentStore = FileStore.builder(file)
.withBlobStore(createBlobStore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public RefreshOnGCTest(Fixture fixtures) {
this.fixture = fixtures;
}

private NodeStore createSegmentStore(File directory, GCMonitor gcMonitor) throws IOException {
private NodeStore createSegmentStore(File directory, GCMonitor gcMonitor) throws Exception {
CompactionStrategy strategy = new CompactionStrategy(
false, false, CLEAN_NONE, 0, CompactionStrategy.MEMORY_THRESHOLD_DEFAULT) {
@Override
Expand Down Expand Up @@ -130,7 +130,7 @@ public Void call() throws Exception {
}

@Before
public void setup() throws IOException {
public void setup() throws Exception {
File directory = createTempFile(getClass().getSimpleName(), "test", new File("target"));
directory.delete();
directory.mkdir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.state.NodeState;

/**
* A helper class to manage checkpoints on TarMK and DocumentMK.
*/
public abstract class Checkpoints {

public static Checkpoints onSegment(File path, Closer closer) throws IOException {
public static Checkpoints onSegment(File path, Closer closer) throws IOException, InvalidFileStoreVersionException {
return SegmentCheckpoints.create(path, closer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import com.google.common.io.Closer;
import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;

final class SegmentCheckpoints extends Checkpoints {

static Checkpoints create(File path, Closer closer) throws IOException {
static Checkpoints create(File path, Closer closer) throws IOException, InvalidFileStoreVersionException {
return new SegmentCheckpoints(closer.register(FileStore.builder(path).build()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStateHelper;
import org.apache.jackrabbit.oak.plugins.segment.SegmentPropertyState;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.state.NodeState;

class SegmentExplorerBackend implements ExplorerBackend {
Expand All @@ -55,7 +56,12 @@ class SegmentExplorerBackend implements ExplorerBackend {

@Override
public void open() throws IOException {
store = FileStore.builder(path).buildReadOnly();
try {
store = FileStore.builder(path).buildReadOnly();
} catch (InvalidFileStoreVersionException e) {
throw new IllegalStateException(e);
}

index = store.getTarReaderIndex();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore.ReadOnlyStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.plugins.segment.file.JournalReader;
import org.apache.jackrabbit.oak.plugins.segment.file.tooling.BasicReadOnlyBlobStore;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
Expand Down Expand Up @@ -173,7 +174,7 @@ public static boolean isValidFileStore(File store) {
return false;
}

public static File checkFileStoreVersionOrFail(String path, boolean force) throws IOException {
public static File checkFileStoreVersionOrFail(String path, boolean force) throws IOException, InvalidFileStoreVersionException {
File directory = new File(path);
if (!directory.exists()) {
return directory;
Expand All @@ -199,35 +200,37 @@ public static File checkFileStoreVersionOrFail(String path, boolean force) throw
return directory;
}

public static FileStore openFileStore(String directory) throws IOException {
public static FileStore openFileStore(String directory) throws IOException, InvalidFileStoreVersionException {
return openFileStore(directory, false);
}

public static FileStore openFileStore(String directory, boolean force)
throws IOException {
throws IOException, InvalidFileStoreVersionException {
return FileStore.builder(checkFileStoreVersionOrFail(directory, force))
.withCacheSize(TAR_SEGMENT_CACHE_SIZE)
.withMemoryMapping(TAR_STORAGE_MEMORY_MAPPED).build();
}

public static FileStore openFileStore(String directory, boolean force,
BlobStore blobStore) throws IOException {
BlobStore blobStore
) throws IOException, InvalidFileStoreVersionException {
return FileStore.builder(checkFileStoreVersionOrFail(directory, force))
.withCacheSize(TAR_SEGMENT_CACHE_SIZE)
.withMemoryMapping(TAR_STORAGE_MEMORY_MAPPED)
.withBlobStore(blobStore).build();
}

public static ReadOnlyStore openReadOnlyFileStore(File directory)
throws IOException {
throws IOException, InvalidFileStoreVersionException {
return FileStore.builder(isValidFileStoreOrFail(directory))
.withCacheSize(TAR_SEGMENT_CACHE_SIZE)
.withMemoryMapping(TAR_STORAGE_MEMORY_MAPPED)
.buildReadOnly();
}

public static ReadOnlyStore openReadOnlyFileStore(File directory,
BlobStore blobStore) throws IOException {
BlobStore blobStore
) throws IOException, InvalidFileStoreVersionException {
return FileStore.builder(isValidFileStoreOrFail(directory))
.withCacheSize(TAR_SEGMENT_CACHE_SIZE)
.withMemoryMapping(TAR_STORAGE_MEMORY_MAPPED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void main(String[] args) throws Exception {

private static SortedMap<String, String> extractRoots(File dir,
SortedMap<String, UUID> candidates, final SegmentVersion version)
throws IOException {
throws IOException, InvalidFileStoreVersionException {

ReadOnlyStore store = FileStore.builder(dir).withSegmentVersion(version).buildReadOnly();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.io.Closer;
import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeStore;

Expand All @@ -32,15 +33,15 @@ private SegmentUtils() {
// Prevent instantiation
}

static NodeStore bootstrap(String path, BlobStore store, Closer closer) throws IOException {
static NodeStore bootstrap(String path, BlobStore store, Closer closer) throws IOException, InvalidFileStoreVersionException {
return SegmentNodeStore.builder(fileStore(path, store, closer)).build();
}

private static FileStore fileStore(String path, BlobStore store, Closer closer) throws IOException {
private static FileStore fileStore(String path, BlobStore store, Closer closer) throws IOException, InvalidFileStoreVersionException {
return closer.register(fileStore(path, store));
}

private static FileStore fileStore(String path, BlobStore store) throws IOException {
private static FileStore fileStore(String path, BlobStore store) throws IOException, InvalidFileStoreVersionException {
return FileStore.builder(new File(path)).withBlobStore(store).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.slf4j.Logger;
Expand Down Expand Up @@ -286,7 +287,7 @@ private static Properties loadProperties(File s3Config) throws IOException {
return props;
}

private static NodeStore bootStrapNodeStore(String src, boolean segmentTar, BlobStore blobStore, Closer closer) throws IOException {
private static NodeStore bootStrapNodeStore(String src, boolean segmentTar, BlobStore blobStore, Closer closer) throws IOException, InvalidFileStoreVersionException {
if (src.startsWith(MongoURI.MONGODB_PREFIX)) {
MongoClientURI uri = new MongoClientURI(src);
if (uri.getDatabase() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.apache.jackrabbit.oak.plugins.segment.compaction.CompactionStrategy;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore.ReadOnlyStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.plugins.segment.file.JournalReader;
import org.apache.jackrabbit.oak.plugins.segment.file.tooling.RevisionHistory;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
Expand All @@ -98,7 +99,7 @@ private SegmentUtils() {
// Prevent instantiation
}

static NodeStore bootstrapNodeStore(String path, Closer closer) throws IOException {
static NodeStore bootstrapNodeStore(String path, Closer closer) throws IOException, InvalidFileStoreVersionException {
return SegmentNodeStore.builder(bootstrapFileStore(path, closer)).build();
}

Expand All @@ -121,11 +122,11 @@ static void backup(File source, File target) throws IOException {
}
}

static void restore(File source, File target) throws IOException {
static void restore(File source, File target) throws IOException, InvalidFileStoreVersionException {
FileStoreRestore.restore(source, target);
}

static void debug(String... args) throws IOException {
static void debug(String... args) throws IOException, InvalidFileStoreVersionException {
File file = new File(args[0]);
System.out.println("Debug " + file);
FileStore store = openReadOnlyFileStore(file);
Expand Down Expand Up @@ -154,18 +155,18 @@ static void graph(File path, boolean gcGraph, Date epoch, String regex, OutputSt
}
}

static void history(File directory, File journal, String path, int depth) throws IOException {
static void history(File directory, File journal, String path, int depth) throws IOException, InvalidFileStoreVersionException {
Iterable<RevisionHistory.HistoryElement> history = new RevisionHistory(directory).getHistory(journal, path);
for (RevisionHistory.HistoryElement historyElement : history) {
System.out.println(historyElement.toString(depth));
}
}

static void check(File dir, String journalFileName, boolean fullTraversal, long debugLevel, long binLen) throws IOException {
static void check(File dir, String journalFileName, boolean fullTraversal, long debugLevel, long binLen) throws IOException, InvalidFileStoreVersionException {
checkConsistency(dir, journalFileName, fullTraversal, debugLevel, binLen);
}

static void compact(File directory, boolean force) throws IOException {
static void compact(File directory, boolean force) throws IOException, InvalidFileStoreVersionException {
FileStore store = openFileStore(directory.getAbsolutePath(), force);
try {
boolean persistCM = Boolean.getBoolean("tar.PersistCompactionMap");
Expand Down Expand Up @@ -225,19 +226,19 @@ public boolean compacted(Callable<Boolean> setHead)
}
}

static void diff(File store, File out, boolean listOnly, String interval, boolean incremental, String path, boolean ignoreSNFEs) throws IOException {
static void diff(File store, File out, boolean listOnly, String interval, boolean incremental, String path, boolean ignoreSNFEs) throws IOException, InvalidFileStoreVersionException {
if (listOnly) {
listRevs(store, out);
} else {
diff(store, interval, incremental, out, path, ignoreSNFEs);
}
}

private static FileStore bootstrapFileStore(String path, Closer closer) throws IOException {
private static FileStore bootstrapFileStore(String path, Closer closer) throws IOException, InvalidFileStoreVersionException {
return closer.register(bootstrapFileStore(path));
}

private static FileStore bootstrapFileStore(String path) throws IOException {
private static FileStore bootstrapFileStore(String path) throws IOException, InvalidFileStoreVersionException {
return FileStore.builder(new File(path)).build();
}

Expand All @@ -259,7 +260,7 @@ private static void listRevs(File store, File out) throws IOException {
}
}

private static void diff(File dir, String interval, boolean incremental, File out, String filter, boolean ignoreSNFEs) throws IOException {
private static void diff(File dir, String interval, boolean incremental, File out, String filter, boolean ignoreSNFEs) throws IOException, InvalidFileStoreVersionException {
System.out.println("Store " + dir);
System.out.println("Writing diff to " + out);
String[] tokens = interval.trim().split("\\.\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
import org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeStore;

class Utils {

public static NodeStore bootstrapNodeStore(String[] args, Closer closer, String h) throws IOException {
public static NodeStore bootstrapNodeStore(String[] args, Closer closer, String h) throws IOException, InvalidFileStoreVersionException {
//TODO add support for other NodeStore flags
OptionParser parser = new OptionParser();
OptionSpec<Integer> clusterId = parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.segment.file.tooling.BasicReadOnlyBlobStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -53,7 +54,7 @@ public class FileStoreBackup {
public static void backup(@Nonnull SegmentReader reader,
@Nonnull Revisions revisions,
@Nonnull File destination)
throws IOException {
throws IOException, InvalidFileStoreVersionException {
Stopwatch watch = Stopwatch.createStarted();
SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions()
.setOffline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.jackrabbit.oak.segment.WriterCacheManager;
import org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions;
import org.apache.jackrabbit.oak.segment.file.FileStore;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -47,7 +48,7 @@ public class FileStoreRestore {
private static final String JOURNAL_FILE_NAME = "journal.log";

public static void restore(File source, File destination)
throws IOException {
throws IOException, InvalidFileStoreVersionException {
if (!validFileStore(source)) {
throw new IOException("Folder " + source
+ " is not a valid FileStore directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.apache.jackrabbit.oak.segment.file.FileStoreGCMonitor;
import org.apache.jackrabbit.oak.segment.file.FileStoreStatsMBean;
import org.apache.jackrabbit.oak.segment.file.GCMonitorMBean;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
import org.apache.jackrabbit.oak.spi.commit.Observable;
Expand Down Expand Up @@ -387,7 +388,12 @@ private boolean registerSegmentStore() throws IOException {
builder.withBlobStore(blobStore);
}

store = builder.build();
try {
store = builder.build();
} catch (InvalidFileStoreVersionException e) {
log.error("The segment store data is not compatible with the current version. Please use oak-segment or a different version of oak-segment-tar.");
return false;
}

// Expose an MBean to provide information about the gc options

Expand Down
Loading

0 comments on commit 2b6c2f5

Please sign in to comment.