This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch lucene-10
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/lucene-10 by this push:
new f0d9136bc open latest version of index
f0d9136bc is described below
commit f0d9136bcf0d64e978c1b21cd91647ff2d9da245
Author: Robert Newson <[email protected]>
AuthorDate: Wed Aug 6 16:15:45 2025 +0100
open latest version of index
---
.../apache/couchdb/nouveau/core/IndexManager.java | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git
a/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
b/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
index 623963d81..489f871e8 100644
--- a/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
+++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
@@ -20,6 +20,7 @@ import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response.Status;
import java.io.File;
import java.io.IOException;
+import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@@ -45,6 +46,7 @@ import org.apache.lucene.search.SearcherFactory;
import org.apache.lucene.search.SearcherManager;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.util.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -380,7 +382,9 @@ public final class IndexManager implements Managed {
final Path path = indexPath(name);
final IndexDefinition indexDefinition = loadIndexDefinition(name);
final Analyzer analyzer =
LuceneAnalyzerFactory.fromDefinition(indexDefinition);
- final Directory dir = new
DirectIODirectory(FSDirectory.open(path.resolve("10")));
+ final int version = getIndexVersion(path);
+ final Path indexPath = path.resolve(Integer.toString(version));
+ final Directory dir = new
DirectIODirectory(FSDirectory.open(indexPath));
final IndexWriterConfig config = new IndexWriterConfig(analyzer);
config.setUseCompoundFile(false);
final IndexWriter writer = new IndexWriter(dir, config);
@@ -390,6 +394,22 @@ public final class IndexManager implements Managed {
return new LuceneIndex(analyzer, writer, updateSeq, purgeSeq,
searcherManager);
}
+ /**
+ * Find highest version index on disk, or latest version if none.
+ */
+ private int getIndexVersion(final Path path) throws IOException {
+ if (!path.toFile().exists()) {
+ return Version.LATEST.major;
+ }
+ int version = 0;
+ try (final DirectoryStream<Path> stream =
Files.newDirectoryStream(path, "[0-9]*")) {
+ for (final Path file : stream) {
+ version = Math.max(version,
Integer.parseInt(file.getFileName().toString()));
+ }
+ }
+ return version == 0 ? Version.LATEST.major : version;
+ }
+
private long getSeq(final IndexWriter writer, final String key) throws
IOException {
final Iterable<Map.Entry<String, String>> commitData =
writer.getLiveCommitData();
if (commitData == null) {