Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-2385: Move NoDeletionPolicy from benchmark to core

Shai Erera5792f0d711fd
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 6d0330fcc6a..bcecf3099e6 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -343,6 +343,10 @@ New features
and iterated as byte[] (wrapped in a BytesRef) by IndexReader for
searching.
+* LUCENE-2385: Moved NoDeletionPolicy from benchmark to core. NoDeletionPolicy
+ can be used to prevent commits from ever getting deleted from the index.
+ (Shai Erera)
+
Optimizations
* LUCENE-2075: Terms dict cache is now shared across threads instead
diff --git a/lucene/contrib/benchmark/conf/deletepercent.alg b/lucene/contrib/benchmark/conf/deletepercent.alg
index 01a4988e858..59d16726710 100644
--- a/lucene/contrib/benchmark/conf/deletepercent.alg
+++ b/lucene/contrib/benchmark/conf/deletepercent.alg
@@ -35,7 +35,7 @@ content.source=org.apache.lucene.benchmark.byTask.feeds.ReutersContentSource
#query.maker=org.apache.lucene.benchmark.byTask.feeds.SimpleQueryMaker
query.maker=org.apache.lucene.benchmark.byTask.feeds.ReutersQueryMaker
-deletion.policy=org.apache.lucene.benchmark.utils.NoDeletionPolicy
+deletion.policy=org.apache.lucene.index.NoDeletionPolicy
# task at this depth or less would print when they start
task.max.depth.log=2
diff --git a/lucene/contrib/benchmark/sortBench.py b/lucene/contrib/benchmark/sortBench.py
index 420969da398..bfef0339930 100644
--- a/lucene/contrib/benchmark/sortBench.py
+++ b/lucene/contrib/benchmark/sortBench.py
@@ -83,7 +83,7 @@ BASE_INDEX_ALG = '''
analyzer=org.apache.lucene.analysis.standard.StandardAnalyzer
$OTHER$
-deletion.policy = org.apache.lucene.benchmark.utils.NoDeletionPolicy
+deletion.policy = org.apache.lucene.index.NoDeletionPolicy
doc.tokenized = false
doc.body.tokenized = true
doc.stored = true
diff --git a/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java b/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java
index c3b699429ec..2aa125efbc1 100644
--- a/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java
+++ b/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTask.java
@@ -25,6 +25,7 @@ import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.MergeScheduler;
import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.lucene.index.MergePolicy;
+import org.apache.lucene.index.NoDeletionPolicy;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.NoMergeScheduler;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
@@ -135,23 +136,15 @@ public class CreateIndexTask extends PerfTask {
public static IndexDeletionPolicy getIndexDeletionPolicy(Config config) {
String deletionPolicyName = config.get("deletion.policy", "org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy");
- IndexDeletionPolicy indexDeletionPolicy = null;
- RuntimeException err = null;
- try {
- indexDeletionPolicy = Class.forName(deletionPolicyName).asSubclass(IndexDeletionPolicy.class).newInstance();
- } catch (IllegalAccessException iae) {
- err = new RuntimeException("unable to instantiate class '" + deletionPolicyName + "' as IndexDeletionPolicy");
- err.initCause(iae);
- } catch (InstantiationException ie) {
- err = new RuntimeException("unable to instantiate class '" + deletionPolicyName + "' as IndexDeletionPolicy");
- err.initCause(ie);
- } catch (ClassNotFoundException cnfe) {
- err = new RuntimeException("unable to load class '" + deletionPolicyName + "' as IndexDeletionPolicy");
- err.initCause(cnfe);
+ if (deletionPolicyName.equals(NoDeletionPolicy.class.getName())) {
+ return NoDeletionPolicy.INSTANCE;
+ } else {
+ try {
+ return Class.forName(deletionPolicyName).asSubclass(IndexDeletionPolicy.class).newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException("unable to instantiate class '" + deletionPolicyName + "' as IndexDeletionPolicy", e);
+ }
}
- if (err != null)
- throw err;
- return indexDeletionPolicy;
}
@Override
diff --git a/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTaskTest.java b/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTaskTest.java
index 60982366b90..14c3d2c9395 100644
--- a/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTaskTest.java
+++ b/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CreateIndexTaskTest.java
@@ -25,6 +25,7 @@ import java.util.Properties;
import org.apache.lucene.benchmark.BenchmarkTestCase;
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.benchmark.byTask.utils.Config;
+import org.apache.lucene.index.NoDeletionPolicy;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.NoMergeScheduler;
@@ -94,5 +95,12 @@ public class CreateIndexTaskTest extends BenchmarkTestCase {
new CreateIndexTask(runData).doLogic();
new CloseIndexTask(runData).doLogic();
}
+
+ public void testNoDeletionPolicy() throws Exception {
+ PerfRunData runData = createPerfRunData(null);
+ runData.getConfig().set("deletion.policy", NoDeletionPolicy.class.getName());
+ new CreateIndexTask(runData).doLogic();
+ new CloseIndexTask(runData).doLogic();
+ }
}
diff --git a/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/utils/NoDeletionPolicy.java b/lucene/src/java/org/apache/lucene/index/NoDeletionPolicy.java
similarity index 65%
rename from lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/utils/NoDeletionPolicy.java
rename to lucene/src/java/org/apache/lucene/index/NoDeletionPolicy.java
index ecacdbb1fb9..87b3b2e7fbc 100644
--- a/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/utils/NoDeletionPolicy.java
+++ b/lucene/src/java/org/apache/lucene/index/NoDeletionPolicy.java
@@ -1,4 +1,4 @@
-package org.apache.lucene.benchmark.utils;
+package org.apache.lucene.index;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,18 +20,22 @@ package org.apache.lucene.benchmark.utils;
import java.io.IOException;
import java.util.List;
-import org.apache.lucene.index.IndexCommit;
-import org.apache.lucene.index.IndexDeletionPolicy;
-
-public class NoDeletionPolicy implements IndexDeletionPolicy {
+/**
+ * An {@link IndexDeletionPolicy} which keeps all index commits around, never
+ * deleting them. This class is a singleton and can be accessed by referencing
+ * {@link #INSTANCE}.
+ */
+public final class NoDeletionPolicy implements IndexDeletionPolicy {
- public void onCommit(List<? extends IndexCommit> commits) throws IOException {
- // TODO Auto-generated method stub
-
+ /** The single instance of this class. */
+ public static final IndexDeletionPolicy INSTANCE = new NoDeletionPolicy();
+
+ private NoDeletionPolicy() {
+ // keep private to avoid instantiation
}
+
+ public void onCommit(List<? extends IndexCommit> commits) throws IOException {}
- public void onInit(List<? extends IndexCommit> commits) throws IOException {
- // TODO Auto-generated method stub
-
- }
+ public void onInit(List<? extends IndexCommit> commits) throws IOException {}
+
}
diff --git a/lucene/src/test/org/apache/lucene/index/TestNoMergeScheduler.java b/lucene/src/test/org/apache/lucene/index/TestNoMergeScheduler.java
index 040a7b04090..75be77178a5 100644
--- a/lucene/src/test/org/apache/lucene/index/TestNoMergeScheduler.java
+++ b/lucene/src/test/org/apache/lucene/index/TestNoMergeScheduler.java
@@ -46,9 +46,9 @@ public class TestNoMergeScheduler extends LuceneTestCaseJ4 {
@Test
public void testMethodsOverridden() throws Exception {
- // Ensures that all methods of MergePolicy are overridden. That's important
- // to ensure that NoMergePolicy overrides everything, so that no unexpected
- // behavior/error occurs
+ // Ensures that all methods of MergeScheduler are overridden. That's
+ // important to ensure that NoMergeScheduler overrides everything, so that
+ // no unexpected behavior/error occurs
for (Method m : NoMergeScheduler.class.getMethods()) {
// getDeclaredMethods() returns just those methods that are declared on
// NoMergeScheduler. getMethods() returns those that are visible in that