diff --git a/solr/core/src/java/org/apache/solr/storage/TeeDirectory.java b/solr/core/src/java/org/apache/solr/storage/TeeDirectory.java index 5d076719cfc..cd6cf7b0c0a 100644 --- a/solr/core/src/java/org/apache/solr/storage/TeeDirectory.java +++ b/solr/core/src/java/org/apache/solr/storage/TeeDirectory.java @@ -69,7 +69,7 @@ public TeeDirectory(Path path, LockFactory lockFactory) throws IOException { String pathS = path.toString(); String scope = pathS.endsWith("/index") - ? TeeDirectoryFactory.getCoreName(pathS) + ? TeeDirectoryFactory.getScopeName(pathS) : pathS.substring(pathS.lastIndexOf('/')); String accessPath = accessDir + scope + "-" + Long.toUnsignedString(System.nanoTime(), 16); this.closeLocal = diff --git a/solr/core/src/java/org/apache/solr/storage/TeeDirectoryFactory.java b/solr/core/src/java/org/apache/solr/storage/TeeDirectoryFactory.java index f7837162890..6551e535484 100644 --- a/solr/core/src/java/org/apache/solr/storage/TeeDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/storage/TeeDirectoryFactory.java @@ -239,11 +239,22 @@ public void init(NamedList args) { useAsyncIO = params.getBool("useAsyncIO", useDirectIO); } - static String getCoreName(String path) { - assert path.endsWith("/index"); - int end = path.lastIndexOf('/', path.length() - "/index".length() - 1); + static String getScopeName(String path) { + int lastPathDelimIdx = path.lastIndexOf('/'); + if (lastPathDelimIdx == -1) { + throw new IllegalArgumentException("unexpected path: " + path); + } + String dirName = path.substring(path.lastIndexOf('/')); + int end = path.lastIndexOf('/', lastPathDelimIdx - 1); int start = path.lastIndexOf('/', end - 1); - return path.substring(start, end); + if ("/index".equals(dirName)) { + return path.substring(start, end); + } else if (dirName.startsWith("/index.")) { + // append the suffix identifier; this is a snapshot or temp index dir + return path.substring(start, end).concat(dirName.substring("/index".length())); + } else { + throw new IllegalArgumentException("unexpected path: " + path); + } } @Override @@ -253,7 +264,7 @@ public Directory create(String path, LockFactory lockFactory, DirContext dirCont Path compressedPath = Path.of(path); IOFunction> accessFunction = unused -> { - String accessPath = accessDir.concat(getCoreName(path)); + String accessPath = accessDir.concat(getScopeName(path)); Directory dir = new AccessDirectory(Path.of(accessPath), lockFactory, compressedPath, nodeLevelState); return new AbstractMap.SimpleImmutableEntry<>(accessPath, dir);