Author: chetanm
Date: Mon Jul 10 08:47:33 2017
New Revision: 1801425
URL: http://svn.apache.org/viewvc?rev=1801425&view=rev
Log:
OAK-6271 - Support for importing index files
Add support for importing the indexes via oak-run "index" command.
The index can be imported by "--index-import --index-import-dir=<dir>
--read-write" options to cli
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupport.java
(with props)
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexImportIT.java
- copied, changed from r1801424,
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java?rev=1801425&r1=1801424&r2=1801425&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexCommand.java
Mon Jul 10 08:47:33 2017
@@ -110,6 +110,7 @@ public class IndexCommand implements Com
performConsistencyCheck(indexOpts, indexHelper);
dumpIndexContents(indexOpts, indexHelper);
reindexIndex(indexOpts, indexHelper);
+ importIndex(indexOpts, indexHelper);
}
private void configurePreExtractionSupport(IndexOptions indexOpts,
IndexHelper indexHelper) throws IOException {
@@ -136,6 +137,13 @@ public class IndexCommand implements Com
}
}
+ private void importIndex(IndexOptions indexOpts, IndexHelper indexHelper)
throws IOException, CommitFailedException {
+ if (indexOpts.isImportIndex()) {
+ File importDir = indexOpts.getIndexImportDir();
+ new IndexImporterSupport(indexHelper).importIndex(importDir);
+ }
+ }
+
private void dumpIndexContents(IndexOptions indexOpts, IndexHelper
indexHelper) throws IOException {
if (indexOpts.dumpIndex()) {
new IndexDumper(indexHelper, indexOpts.getOutDir()).dump();
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupport.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupport.java?rev=1801425&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupport.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupport.java
Mon Jul 10 08:47:33 2017
@@ -0,0 +1,74 @@
+/*
+ * 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.index;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.importer.AsyncIndexerLock;
+import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock;
+import org.apache.jackrabbit.oak.plugins.index.importer.IndexImporter;
+import
org.apache.jackrabbit.oak.plugins.index.lucene.directory.LuceneIndexImporter;
+import org.apache.jackrabbit.oak.spi.state.Clusterable;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+import static java.util.Collections.singletonList;
+
+class IndexImporterSupport {
+ private final IndexHelper indexHelper;
+ private final NodeStore nodeStore;
+
+ public IndexImporterSupport(IndexHelper indexHelper) {
+ this.indexHelper = indexHelper;
+ this.nodeStore = indexHelper.getNodeStore();
+ }
+
+ public void importIndex(File importDir) throws IOException,
CommitFailedException {
+ IndexImporter importer = new IndexImporter(nodeStore, importDir,
createIndexEditorProvider(), createLock());
+ addImportProviders(importer);
+ importer.importIndex();
+ }
+
+ private void addImportProviders(IndexImporter importer) {
+ importer.addImporterProvider(new
LuceneIndexImporter(indexHelper.getGCBlobStore()));
+ }
+
+ private AsyncIndexerLock createLock() {
+ if (nodeStore instanceof Clusterable) {
+ return new ClusterNodeStoreLock(nodeStore);
+ }
+ //For oak-run usage with non Clusterable NodeStore indicates that
NodeStore is not
+ //active. So we can use a noop lock implementation as there is no
concurrent run
+ return AsyncIndexerLock.NOOP_LOCK;
+ }
+
+ private IndexEditorProvider createIndexEditorProvider() throws IOException
{
+ IndexEditorProvider lucene = createLuceneEditorProvider();
+ //Later we can add support for property index and other indexes here
+ return CompositeIndexEditorProvider.compose(singletonList(lucene));
+ }
+
+ private IndexEditorProvider createLuceneEditorProvider() throws
IOException {
+ return indexHelper.getLuceneIndexHelper().createEditorProvider();
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java?rev=1801425&r1=1801424&r2=1801425&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
Mon Jul 10 08:47:33 2017
@@ -43,11 +43,13 @@ public class IndexOptions implements Opt
private final OptionSpec<File> workDirOpt;
private final OptionSpec<File> outputDirOpt;
+ private final OptionSpec<File> indexImportDir;
private final OptionSpec<File> preExtractedTextOpt;
private final OptionSpec<Void> stats;
private final OptionSpec<Void> definitions;
private final OptionSpec<Void> dumpIndex;
private final OptionSpec<Void> reindex;
+ private final OptionSpec<Void> importIndex;
private final OptionSpec<Integer> consistencyCheck;
private OptionSet options;
private final Set<OptionSpec> actionOpts;
@@ -83,8 +85,15 @@ public class IndexOptions implements Opt
dumpIndex = parser.accepts("index-dump", "Dumps index content");
reindex = parser.accepts("reindex", "Reindex the indexes specified by
--index-paths").availableIf("index-paths");
+ importIndex = parser.accepts("index-import", "Imports index");
+
+ indexImportDir = parser.accepts("index-import-dir", "Directory
containing index files. This " +
+ "is required when --index-import operation is selected")
+ .requiredIf(importIndex)
+ .withRequiredArg().ofType(File.class);
+
//Set of options which define action
- actionOpts = ImmutableSet.of(stats, definitions, consistencyCheck,
dumpIndex, reindex);
+ actionOpts = ImmutableSet.of(stats, definitions, consistencyCheck,
dumpIndex, reindex, importIndex);
operationNames = collectionOperationNames(actionOpts);
}
@@ -130,6 +139,10 @@ public class IndexOptions implements Opt
return preExtractedTextOpt.value(options);
}
+ public File getIndexImportDir() {
+ return indexImportDir.value(options);
+ }
+
public boolean dumpStats(){
return options.has(stats) || !anyActionSelected();
}
@@ -154,6 +167,10 @@ public class IndexOptions implements Opt
return options.has(reindex);
}
+ public boolean isImportIndex() {
+ return options.has(importIndex);
+ }
+
public String getCheckpoint(){
return checkpoint.value(options);
}
Modified:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java?rev=1801425&r1=1801424&r2=1801425&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
Mon Jul 10 08:47:33 2017
@@ -53,25 +53,25 @@ public class AbstractIndexCommandTest {
}
indexIndexDefinitions();
createLuceneIndex(asyncIndex);
- addTestContent();
+ addTestContent(fixture, "/testNode/a", 100);
}
- private void indexIndexDefinitions() throws IOException,
RepositoryException {
- //By default Oak index definitions are not indexed
- //so add them to declaringNodeTypes
+ protected void addTestContent(RepositoryFixture fixture, String basePath,
int count) throws IOException, RepositoryException {
Session session = fixture.getAdminSession();
- Node nodeType = session.getNode("/oak:index/nodetype");
- nodeType.setProperty(IndexConstants.DECLARING_NODE_TYPES, new String[]
{"oak:QueryIndexDefinition"}, PropertyType.NAME);
+ for (int i = 0; i < count; i++) {
+ getOrCreateByPath(basePath+i,
+ "oak:Unstructured", session).setProperty("foo", "bar");
+ }
session.save();
session.logout();
}
- private void addTestContent() throws IOException, RepositoryException {
+ private void indexIndexDefinitions() throws IOException,
RepositoryException {
+ //By default Oak index definitions are not indexed
+ //so add them to declaringNodeTypes
Session session = fixture.getAdminSession();
- for (int i = 0; i < 100; i++) {
- getOrCreateByPath("/testNode/a"+i,
- "oak:Unstructured", session).setProperty("foo", "bar");
- }
+ Node nodeType = session.getNode("/oak:index/nodetype");
+ nodeType.setProperty(IndexConstants.DECLARING_NODE_TYPES, new String[]
{"oak:QueryIndexDefinition"}, PropertyType.NAME);
session.save();
session.logout();
}
Modified:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java?rev=1801425&r1=1801424&r2=1801425&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
Mon Jul 10 08:47:33 2017
@@ -180,44 +180,6 @@ public class IndexCommandIT extends Abst
assertEquals(2, reindexCount.getValue(Type.LONG).longValue());
}
- @Test
- public void reindexOutOfBand() throws Exception{
- createTestData(true);
- fixture.getAsyncIndexUpdate("async").run();
- String checkpoint =
fixture.getNodeStore().checkpoint(TimeUnit.HOURS.toMillis(24));
-
- //Close the repository so as all changes are flushed
- fixture.close();
-
- IndexCommand command = new IndexCommand();
-
- File outDir = temporaryFolder.newFolder();
- File storeDir = fixture.getDir();
- String[] args = {
- "--index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
- "--index-out-dir=" + outDir.getAbsolutePath(),
- "--index-paths=/oak:index/fooIndex",
- "--checkpoint="+checkpoint,
- "--reindex",
- "--", // -- indicates that options have ended and rest needs
to be treated as non option
- storeDir.getAbsolutePath()
- };
-
- command.execute(args);
-
- RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
- NodeStore store2 = fixture2.getNodeStore();
- PropertyState reindexCount = getNode(store2.getRoot(),
"/oak:index/fooIndex").getProperty(IndexConstants.REINDEX_COUNT);
- assertEquals(1, reindexCount.getValue(Type.LONG).longValue());
-
- File indexes = new File(outDir, OutOfBandIndexer.LOCAL_INDEX_ROOT_DIR);
- assertTrue(indexes.exists());
-
- IndexRootDirectory idxRoot = new IndexRootDirectory(indexes);
- List<LocalIndexDir> idxDirs = idxRoot.getAllLocalIndexes();
-
- assertEquals(1, idxDirs.size());
- }
}
\ No newline at end of file
Copied:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexImportIT.java
(from r1801424,
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java)
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexImportIT.java?p2=jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexImportIT.java&p1=jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java&r1=1801424&r2=1801425&rev=1801425&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexCommandIT.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/IndexImportIT.java
Mon Jul 10 08:47:33 2017
@@ -20,141 +20,45 @@
package org.apache.jackrabbit.oak.index;
import java.io.File;
+import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
-import com.google.common.io.Files;
+import com.google.common.collect.Iterators;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock;
import
org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory;
import org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.junit.Test;
-import static java.nio.charset.Charset.defaultCharset;
import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-public class IndexCommandIT extends AbstractIndexCommandTest {
+public class IndexImportIT extends AbstractIndexCommandTest {
@Test
- public void dumpStatsAndInfo() throws Exception{
- createTestData(false);
- //Close the repository so as all changes are flushed
- fixture.close();
-
- IndexCommand command = new IndexCommand();
-
- File outDir = temporaryFolder.newFolder();
- String[] args = {
- "-index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
- "-index-out-dir=" + outDir.getAbsolutePath(),
- "-index-info",
- "-index-definitions",
- fixture.getDir().getAbsolutePath()
- };
-
- command.execute(args);
-
- File info = new File(outDir, IndexCommand.INDEX_INFO_TXT);
- File defns = new File(outDir, IndexCommand.INDEX_DEFINITIONS_JSON);
-
- assertTrue(info.exists());
- assertTrue(defns.exists());
-
- assertThat(Files.toString(info, defaultCharset()),
containsString("/oak:index/uuid"));
- assertThat(Files.toString(info, defaultCharset()),
containsString("/oak:index/fooIndex"));
- }
-
- @Test
- public void selectedIndexPaths() throws Exception{
- createTestData(false);
- //Close the repository so as all changes are flushed
- fixture.close();
-
- IndexCommand command = new IndexCommand();
-
- File outDir = temporaryFolder.newFolder();
- String[] args = {
- "-index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
- "-index-out-dir=" + outDir.getAbsolutePath(),
- "-index-paths=/oak:index/fooIndex",
- "-index-info",
- "-index-definitions",
- fixture.getDir().getAbsolutePath()
- };
-
- command.execute(args);
-
- File info = new File(outDir, IndexCommand.INDEX_INFO_TXT);
-
- assertTrue(info.exists());
-
- assertThat(Files.toString(info, defaultCharset()),
not(containsString("/oak:index/uuid")));
- assertThat(Files.toString(info, defaultCharset()),
containsString("/oak:index/fooIndex"));
- }
-
- @Test
- public void consistencyCheck() throws Exception{
- createTestData(false);
- //Close the repository so as all changes are flushed
- fixture.close();
-
- IndexCommand command = new IndexCommand();
-
- File outDir = temporaryFolder.newFolder();
- String[] args = {
- "--index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
- "--index-out-dir=" + outDir.getAbsolutePath(),
- "--index-consistency-check",
- "--", // -- indicates that options have ended and rest needs
to be treated as non option
- fixture.getDir().getAbsolutePath()
- };
-
- command.execute(args);
-
- File report = new File(outDir,
IndexCommand.INDEX_CONSISTENCY_CHECK_TXT);
-
- assertFalse(new File(outDir, IndexCommand.INDEX_INFO_TXT).exists());
- assertFalse(new File(outDir,
IndexCommand.INDEX_DEFINITIONS_JSON).exists());
- assertTrue(report.exists());
-
- assertThat(Files.toString(report, defaultCharset()),
containsString("/oak:index/fooIndex"));
- }
-
- @Test
- public void dumpIndex() throws Exception{
- createTestData(false);
- //Close the repository so as all changes are flushed
- fixture.close();
-
- IndexCommand command = new IndexCommand();
-
- File outDir = temporaryFolder.newFolder();
- String[] args = {
- "--index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
- "--index-out-dir=" + outDir.getAbsolutePath(),
- "--index-dump",
- "--", // -- indicates that options have ended and rest needs
to be treated as non option
- fixture.getDir().getAbsolutePath()
- };
-
- command.execute(args);
- File dumpDir = new File(outDir, IndexDumper.INDEX_DUMPS_DIR);
- assertTrue(dumpDir.exists());
- }
-
- @Test
- public void reindex() throws Exception{
+ public void reindexOutOfBand() throws Exception{
createTestData(true);
fixture.getAsyncIndexUpdate("async").run();
+
+ String checkpoint =
fixture.getNodeStore().checkpoint(TimeUnit.HOURS.toMillis(24));
+
//Close the repository so as all changes are flushed
fixture.close();
@@ -166,7 +70,7 @@ public class IndexCommandIT extends Abst
"--index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
"--index-out-dir=" + outDir.getAbsolutePath(),
"--index-paths=/oak:index/fooIndex",
- "--read-write=true",
+ "--checkpoint="+checkpoint,
"--reindex",
"--", // -- indicates that options have ended and rest needs
to be treated as non option
storeDir.getAbsolutePath()
@@ -177,14 +81,23 @@ public class IndexCommandIT extends Abst
RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
NodeStore store2 = fixture2.getNodeStore();
PropertyState reindexCount = getNode(store2.getRoot(),
"/oak:index/fooIndex").getProperty(IndexConstants.REINDEX_COUNT);
- assertEquals(2, reindexCount.getValue(Type.LONG).longValue());
+ assertEquals(1, reindexCount.getValue(Type.LONG).longValue());
+
+ File indexes = new File(outDir, OutOfBandIndexer.LOCAL_INDEX_ROOT_DIR);
+ assertTrue(indexes.exists());
+
+ IndexRootDirectory idxRoot = new IndexRootDirectory(indexes);
+ List<LocalIndexDir> idxDirs = idxRoot.getAllLocalIndexes();
+
+ assertEquals(1, idxDirs.size());
}
@Test
- public void reindexOutOfBand() throws Exception{
+ public void reindexAndThenImport() throws Exception {
createTestData(true);
fixture.getAsyncIndexUpdate("async").run();
+ int fooCount = getFooCount(fixture);
String checkpoint =
fixture.getNodeStore().checkpoint(TimeUnit.HOURS.toMillis(24));
//Close the repository so as all changes are flushed
@@ -206,18 +119,72 @@ public class IndexCommandIT extends Abst
command.execute(args);
+ //----------------------------------------
+ //Phase 2 - Add some more indexable content. This would let us
validate that post
+ //import
+
RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
- NodeStore store2 = fixture2.getNodeStore();
- PropertyState reindexCount = getNode(store2.getRoot(),
"/oak:index/fooIndex").getProperty(IndexConstants.REINDEX_COUNT);
- assertEquals(1, reindexCount.getValue(Type.LONG).longValue());
+ addTestContent(fixture2, "/testNode/b", 100);
+ fixture2.getAsyncIndexUpdate("async").run();
- File indexes = new File(outDir, OutOfBandIndexer.LOCAL_INDEX_ROOT_DIR);
- assertTrue(indexes.exists());
+ int foo2Count = getFooCount(fixture2);
+ assertEquals(fooCount + 100, foo2Count);
+ assertNotNull(fixture2.getNodeStore().retrieve(checkpoint));
+ fixture2.close();
+
+ //~-----------------------------------------
+ //Phase 3 - Import the indexes
+
+ IndexCommand command3 = new IndexCommand();
+ File outDir3 = temporaryFolder.newFolder();
+ File indexDir = new File(outDir,
OutOfBandIndexer.LOCAL_INDEX_ROOT_DIR);
+ String[] args3 = {
+ "--index-temp-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
+ "--index-out-dir=" +
temporaryFolder.newFolder().getAbsolutePath(),
+ "--index-import-dir=" + indexDir.getAbsolutePath(),
+ "--index-import",
+ "--read-write",
+ "--", // -- indicates that options have ended and rest needs
to be treated as non option
+ storeDir.getAbsolutePath()
+ };
- IndexRootDirectory idxRoot = new IndexRootDirectory(indexes);
- List<LocalIndexDir> idxDirs = idxRoot.getAllLocalIndexes();
+ command3.execute(args3);
- assertEquals(1, idxDirs.size());
+ //~-----------------------------------------
+ //Phase 4 - Validate the import
+
+ RepositoryFixture fixture4 = new RepositoryFixture(storeDir);
+ int foo4Count = getFooCount(fixture4);
+
+ //new count should be same as previous
+ assertEquals(foo2Count, foo4Count);
+
+ //Checkpoint must be released
+ assertNull(fixture4.getNodeStore().retrieve(checkpoint));
+
+ //Lock should also be released
+ ClusterNodeStoreLock clusterLock = new
ClusterNodeStoreLock(fixture4.getNodeStore());
+ assertFalse(clusterLock.isLocked("async"));
+ fixture4.close();
+ }
+
+ private int getFooCount(RepositoryFixture fixture) throws IOException,
RepositoryException {
+ Session session = fixture.getAdminSession();
+ QueryManager qm = session.getWorkspace().getQueryManager();
+ assertFooIndexBeingUsed(qm);
+
+ Query q = qm.createQuery("select * from [nt:base] where [foo] is not
null", Query.JCR_SQL2);
+ QueryResult result = q.execute();
+ int size = Iterators.size(result.getNodes());
+ session.logout();
+ return size;
+ }
+
+ private static void assertFooIndexBeingUsed(QueryManager qm) throws
RepositoryException {
+ Query explain = qm.createQuery("explain select * from [nt:base] where
[foo] is not null", Query.JCR_SQL2);
+ QueryResult explainResult = explain.execute();
+ Row explainRow = explainResult.getRows().nextRow();
+ assertThat(explainRow.getValue("plan").getString(),
containsString("/oak:index/fooIndex"));
}
-}
\ No newline at end of file
+}
Modified:
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java?rev=1801425&r1=1801424&r2=1801425&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/index/RepositoryFixture.java
Mon Jul 10 08:47:33 2017
@@ -42,7 +42,6 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
-import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils;
import static
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.getService;
@@ -54,7 +53,12 @@ public class RepositoryFixture implement
private Whiteboard whiteboard;
public RepositoryFixture(File dir) {
+ this(dir, null);
+ }
+
+ public RepositoryFixture(File dir, NodeStore nodeStore) {
this.dir = dir;
+ this.nodeStore = nodeStore;
}
public Repository getRepository() throws IOException {