Skip to content

Commit c94877c

Browse files
committed
don't create indexes for old lucene versions
1 parent 9a65bed commit c94877c

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
import org.apache.lucene.analysis.Analyzer;
4141
import org.apache.lucene.index.IndexWriter;
4242
import org.apache.lucene.index.IndexWriterConfig;
43+
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
4344
import org.apache.lucene.misc.store.DirectIODirectory;
4445
import org.apache.lucene.search.SearcherFactory;
4546
import org.apache.lucene.search.SearcherManager;
4647
import org.apache.lucene.store.Directory;
4748
import org.apache.lucene.store.FSDirectory;
49+
import org.apache.lucene.util.Version;
4850
import org.slf4j.Logger;
4951
import org.slf4j.LoggerFactory;
5052

@@ -219,6 +221,12 @@ public void create(final String name, IndexDefinition indexDefinition) throws IO
219221
assertSame(indexDefinition, loadIndexDefinition(name));
220222
return;
221223
}
224+
if (indexDefinition.getLuceneVersion() != Version.LATEST.major) {
225+
var msg = String.format(
226+
"cannot create index of version %d, only %d supported",
227+
indexDefinition.getLuceneVersion(), Version.LATEST.major);
228+
throw new WebApplicationException(msg, Status.FORBIDDEN);
229+
}
222230

223231
final Lock lock = this.createLock.writeLock(name);
224232
lock.lock();
@@ -383,6 +391,9 @@ private Index load(final String name) throws IOException {
383391
final Directory dir = new DirectIODirectory(
384392
FSDirectory.open(path.resolve(Integer.toString(indexDefinition.getLuceneVersion()))));
385393
final IndexWriterConfig config = new IndexWriterConfig(analyzer);
394+
if (indexDefinition.getLuceneVersion() != Version.LATEST.major) {
395+
config.setOpenMode(OpenMode.APPEND);
396+
}
386397
config.setUseCompoundFile(false);
387398
final IndexWriter writer = new IndexWriter(dir, config);
388399
final long updateSeq = getSeq(writer, "update_seq");

nouveau/src/test/java/org/apache/couchdb/nouveau/core/IndexManagerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.couchdb.nouveau.api.IndexDefinition;
2525
import org.apache.couchdb.nouveau.api.SearchRequest;
2626
import org.apache.couchdb.nouveau.lucene.ParallelSearcherFactory;
27+
import org.apache.lucene.util.Version;
2728
import org.junit.jupiter.api.AfterAll;
2829
import org.junit.jupiter.api.BeforeAll;
2930
import org.junit.jupiter.api.Test;
@@ -56,7 +57,7 @@ public static void cleanup() throws Exception {
5657

5758
@Test
5859
public void managerReturnsUsableIndex() throws Exception {
59-
final IndexDefinition indexDefinition = new IndexDefinition();
60+
final IndexDefinition indexDefinition = new IndexDefinition(Version.LATEST.major, "standard", null);
6061
indexDefinition.setDefaultAnalyzer("standard");
6162
manager.create("foo", indexDefinition);
6263
var searchRequest = new SearchRequest();
@@ -67,7 +68,7 @@ public void managerReturnsUsableIndex() throws Exception {
6768

6869
@Test
6970
public void managerReopensAClosedIndex() throws Exception {
70-
final IndexDefinition indexDefinition = new IndexDefinition();
71+
final IndexDefinition indexDefinition = new IndexDefinition(Version.LATEST.major, "standard", null);
7172
indexDefinition.setDefaultAnalyzer("standard");
7273

7374
manager.create("bar", indexDefinition);

nouveau/src/test/java/org/apache/couchdb/nouveau/lucene/LuceneIndexTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@
4242
import org.apache.lucene.search.SearcherManager;
4343
import org.apache.lucene.store.Directory;
4444
import org.apache.lucene.store.FSDirectory;
45+
import org.apache.lucene.util.Version;
4546
import org.junit.jupiter.api.Test;
4647
import org.junit.jupiter.api.io.TempDir;
4748

4849
public class LuceneIndexTest {
4950

5051
protected final Index setup(final Path path) throws IOException {
51-
final IndexDefinition indexDefinition = new IndexDefinition();
52+
final IndexDefinition indexDefinition = new IndexDefinition(Version.LATEST.major, "standard", null);
5253
indexDefinition.setDefaultAnalyzer("standard");
5354
final Analyzer analyzer = LuceneAnalyzerFactory.fromDefinition(indexDefinition);
5455
final Directory dir = new DirectIODirectory(FSDirectory.open(path));

src/nouveau/src/nouveau_api.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ search_path(#index{} = Index) ->
234234

235235
jaxrs_error(400, Body) ->
236236
{bad_request, message(Body)};
237+
jaxrs_error(403, Body) ->
238+
{forbidden, message(Body)};
237239
jaxrs_error(404, Body) ->
238240
{not_found, message(Body)};
239241
jaxrs_error(405, Body) ->

0 commit comments

Comments
 (0)