Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
OAK-4607 - Add support for multiple directory in IndexCopier
Introduced new parameter dirName in both read and write variant

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1754236 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
chetanmeh committed Jul 27, 2016
1 parent 7789db1 commit f4b659f
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 81 deletions.
Expand Up @@ -132,13 +132,13 @@ public IndexCopier(Executor executor, File indexRootDir, boolean prefetchEnabled
}

public Directory wrapForRead(String indexPath, IndexDefinition definition,
Directory remote) throws IOException {
Directory local = createLocalDirForIndexReader(indexPath, definition);
Directory remote, String dirName) throws IOException {
Directory local = createLocalDirForIndexReader(indexPath, definition, dirName);
return new CopyOnReadDirectory(remote, local, prefetchEnabled, indexPath, getSharedWorkingSet(indexPath));
}

public Directory wrapForWrite(IndexDefinition definition, Directory remote, boolean reindexMode) throws IOException {
Directory local = createLocalDirForIndexWriter(definition);
public Directory wrapForWrite(IndexDefinition definition, Directory remote, boolean reindexMode, String dirName) throws IOException {
Directory local = createLocalDirForIndexWriter(definition, dirName);
return new CopyOnWriteDirectory(remote, local, reindexMode,
getIndexPathForLogging(definition), getSharedWorkingSet(definition.getIndexPathFromConfig()));
}
Expand All @@ -156,9 +156,9 @@ IndexRootDirectory getIndexRootDirectory() {
return indexRootDirectory;
}

protected Directory createLocalDirForIndexWriter(IndexDefinition definition) throws IOException {
protected Directory createLocalDirForIndexWriter(IndexDefinition definition, String dirName) throws IOException {
String indexPath = definition.getIndexPathFromConfig();
File indexWriterDir = getIndexDir(definition, indexPath);
File indexWriterDir = getIndexDir(definition, indexPath, dirName);

//By design indexing in Oak is single threaded so Lucene locking
//can be disabled
Expand All @@ -168,8 +168,8 @@ protected Directory createLocalDirForIndexWriter(IndexDefinition definition) thr
return dir;
}

protected Directory createLocalDirForIndexReader(String indexPath, IndexDefinition definition) throws IOException {
File indexDir = getIndexDir(definition, indexPath);
protected Directory createLocalDirForIndexReader(String indexPath, IndexDefinition definition, String dirName) throws IOException {
File indexDir = getIndexDir(definition, indexPath, dirName);
Directory result = FSDirectory.open(indexDir);

String newPath = indexDir.getAbsolutePath();
Expand All @@ -181,8 +181,8 @@ protected Directory createLocalDirForIndexReader(String indexPath, IndexDefiniti
return result;
}

public File getIndexDir(IndexDefinition definition, String indexPath) throws IOException {
return indexRootDirectory.getIndexDir(definition, indexPath);
public File getIndexDir(IndexDefinition definition, String indexPath, String dirName) throws IOException {
return indexRootDirectory.getIndexDir(definition, indexPath, dirName);
}

Map<String, LocalIndexFile> getFailedToDeleteFiles() {
Expand Down
Expand Up @@ -50,7 +50,7 @@ static IndexNode open(String indexPath, NodeState root, NodeState defnNodeState,
if (data.exists()) {
directory = new OakDirectory(new ReadOnlyBuilder(defnNodeState), definition, true);
if (cloner != null) {
directory = cloner.wrapForRead(indexPath, definition, directory);
directory = cloner.wrapForRead(indexPath, definition, directory, LuceneIndexConstants.INDEX_DATA_CHILD_NAME);
}
} else if (PERSISTENCE_FILE.equalsIgnoreCase(defnNodeState.getString(PERSISTENCE_NAME))) {
String path = defnNodeState.getString(PERSISTENCE_PATH);
Expand Down
Expand Up @@ -52,8 +52,6 @@ public interface LuceneIndexConstants {

String PERSISTENCE_PATH = "path";

String INDEX_DATA_CHILD_NAME_FS = "data";

/**
* Experimental flag to control storage behavior: 'null' or 'true' means the content is stored
*/
Expand Down
Expand Up @@ -192,7 +192,7 @@ IndexWriter getWriter() throws IOException {
directory = newIndexDirectory(definition, definitionBuilder);
IndexWriterConfig config;
if (indexCopier != null){
directory = indexCopier.wrapForWrite(definition, directory, reindex);
directory = indexCopier.wrapForWrite(definition, directory, reindex, LuceneIndexConstants.INDEX_DATA_CHILD_NAME);
config = getIndexWriterConfig(definition, false);
} else {
config = getIndexWriterConfig(definition, true);
Expand Down
Expand Up @@ -83,7 +83,7 @@ public long getSize(){
return FileUtils.sizeOfDirectory(indexRootDir);
}

public File getIndexDir(IndexDefinition definition, String indexPath) throws IOException {
public File getIndexDir(IndexDefinition definition, String indexPath, String dirName) throws IOException {
String uid = definition.getUniqueId();

if (uid == null) {
Expand All @@ -110,8 +110,7 @@ public File getIndexDir(IndexDefinition definition, String indexPath) throws IOE
}

//Create index folder under that
//TODO Add support for multiple folders depending on type of content
File indexFolder = new File(baseFolder, "default");
File indexFolder = new File(baseFolder, getFSSafeName(dirName));
if (!indexFolder.exists()) {
checkState(indexFolder.mkdir(), "Not able to create folder [%s]", indexFolder);
}
Expand Down Expand Up @@ -195,7 +194,7 @@ static String getIndexFolderBaseName(String indexPath) {
continue;
}
//Strip of any char outside of a-zA-Z0-9-
result.add(e.replaceAll("\\W", ""));
result.add(getFSSafeName(e));
}

Collections.reverse(result);
Expand Down Expand Up @@ -295,6 +294,10 @@ private File getOldFormatDir(String indexPath) {
return new File(indexRootDir, subDir);
}

private static String getFSSafeName(String e) {
return e.replaceAll("\\W", "");
}

private static long getTime() {
try {
return Clock.SIMPLE.getTimeIncreasing();
Expand Down

0 comments on commit f4b659f

Please sign in to comment.