Support for out of band indexing with read only access to NodeStore
Clean the work directory at start for now. Later when resumable indexing is
to be supported this would need to be reworked.
@@ -25,6 +25,7 @@ import java.nio.file.Path;
import com.google.common.io.Closer;
import joptsimple.OptionParser;
+import org.apache.commons.io.FileUtils;
import org.apache.felix.inventory.Format;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.run.cli.NodeStoreFixture;
@@ -35,10 +36,13 @@ import org.apache.jackrabbit.oak.run.commons.Command;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
public class IndexCommand implements Command {
+ private static final Logger log = LoggerFactory.getLogger(IndexCommand.class);
public static final String NAME = "index";
public static final String INDEX_DEFINITIONS_JSON = "index-definitions.json";
public static final String INDEX_INFO_TXT = "index-info.txt";
@@ -67,7 +71,7 @@ public class IndexCommand implements Command {
NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts);
try (Closer closer = Closer.create()) {
closer.register(fixture);
-
+ cleanWorkDir(indexOpts.getWorkDir());
execute(fixture.getStore(), fixture.getBlobStore(), fixture.getStatisticsProvider(), indexOpts, closer);
tellReportPaths();
}
@@ -152,6 +156,16 @@ public class IndexCommand implements Command {
}
}
+ private static void cleanWorkDir(File workDir) throws IOException {
+ //TODO Do not clean if restarting
+ String[] dirListing = workDir.list();
+ if (dirListing != null && dirListing.length != 0) {
+ log.info("Cleaning existing work directory {}", workDir.getAbsolutePath());
+ FileUtils.cleanDirectory(workDir);
+ }
+ }
+
+
static Path getPath(File file) {
return file.toPath().normalize().toAbsolutePath();
}
