diff --git a/solr/core/src/java/org/apache/solr/update/DefaultIndexWriterProvider.java b/solr/core/src/java/org/apache/solr/update/DefaultIndexWriterProvider.java index 2fd00c73f29..1dc1a777cfe 100644 --- a/solr/core/src/java/org/apache/solr/update/DefaultIndexWriterProvider.java +++ b/solr/core/src/java/org/apache/solr/update/DefaultIndexWriterProvider.java @@ -25,26 +25,25 @@ import org.apache.solr.core.SolrCore; public final class DefaultIndexWriterProvider implements IndexWriterProvider { private int refCnt = 1; private IndexWriter indexWriter = null; - private SolrCore core; - public DefaultIndexWriterProvider(SolrCore core) { - this.core = core; + public DefaultIndexWriterProvider() { + } @Override - public synchronized IndexWriter getIndexWriter() throws IOException { + public synchronized IndexWriter getIndexWriter(SolrCore core) throws IOException { if (indexWriter == null) { - indexWriter = createMainIndexWriter("DirectUpdateHandler2", false); + indexWriter = createMainIndexWriter(core, "DirectUpdateHandler2", false); } return indexWriter; } @Override - public synchronized void newIndexWriter() throws IOException { + public synchronized void newIndexWriter(SolrCore core) throws IOException { if (indexWriter != null) { indexWriter.close(); } - indexWriter = createMainIndexWriter("DirectUpdateHandler2", + indexWriter = createMainIndexWriter(core, "DirectUpdateHandler2", false); } @@ -65,21 +64,16 @@ public final class DefaultIndexWriterProvider implements IndexWriterProvider { } @Override - public synchronized void rollbackIndexWriter() throws IOException { + public synchronized void rollbackIndexWriter(SolrCore core) throws IOException { indexWriter.rollback(); - newIndexWriter(); + newIndexWriter(core); } - protected SolrIndexWriter createMainIndexWriter(String name, + protected SolrIndexWriter createMainIndexWriter(SolrCore core, String name, boolean removeAllExisting) throws IOException { return new SolrIndexWriter(name, core.getNewIndexDir(), core.getDirectoryFactory(), removeAllExisting, core.getSchema(), core.getSolrConfig().mainIndexConfig, core.getDeletionPolicy(), core.getCodecProvider()); } - - @Override - public synchronized void updateCore(SolrCore core) { - this.core = core; - } } diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java index dd953c45d57..24f87afe348 100644 --- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java +++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java @@ -20,31 +20,29 @@ package org.apache.solr.update; +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicLong; + import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.store.Directory; - -import java.util.concurrent.Future; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicLong; -import java.io.IOException; -import java.net.URL; - -import org.apache.solr.search.QParser; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; -import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrConfig.UpdateHandlerInfo; +import org.apache.solr.core.SolrCore; +import org.apache.solr.search.QParser; import org.apache.solr.search.SolrIndexSearcher; /** @@ -79,7 +77,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { public DirectUpdateHandler2(SolrCore core) throws IOException { super(core); - indexWriterProvider = new DefaultIndexWriterProvider(core); + indexWriterProvider = new DefaultIndexWriterProvider(); UpdateHandlerInfo updateHandlerInfo = core.getSolrConfig() .getUpdateHandlerInfo(); @@ -96,11 +94,10 @@ public class DirectUpdateHandler2 extends UpdateHandler { super(core); if (updateHandler instanceof DirectUpdateHandler2) { this.indexWriterProvider = ((DirectUpdateHandler2)updateHandler).indexWriterProvider; - this.indexWriterProvider.updateCore(core); } else { // the impl has changed, so we cannot use the old state - decref it updateHandler.decref(); - indexWriterProvider = new DefaultIndexWriterProvider(core); + indexWriterProvider = new DefaultIndexWriterProvider(); } UpdateHandlerInfo updateHandlerInfo = core.getSolrConfig() @@ -117,18 +114,18 @@ public class DirectUpdateHandler2 extends UpdateHandler { private void deleteAll() throws IOException { SolrCore.log.info(core.getLogId()+"REMOVING ALL DOCUMENTS FROM INDEX"); - indexWriterProvider.getIndexWriter().deleteAll(); + indexWriterProvider.getIndexWriter(core).deleteAll(); } protected void rollbackWriter() throws IOException { numDocsPending.set(0); - indexWriterProvider.rollbackIndexWriter(); + indexWriterProvider.rollbackIndexWriter(core); } @Override public int addDoc(AddUpdateCommand cmd) throws IOException { - IndexWriter writer = indexWriterProvider.getIndexWriter(); + IndexWriter writer = indexWriterProvider.getIndexWriter(core); addCommands.incrementAndGet(); addCommandsCumulative.incrementAndGet(); int rc=-1; @@ -193,7 +190,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { deleteByIdCommands.incrementAndGet(); deleteByIdCommandsCumulative.incrementAndGet(); - indexWriterProvider.getIndexWriter().deleteDocuments(new Term(idField.getName(), cmd.getIndexedId())); + indexWriterProvider.getIndexWriter(core).deleteDocuments(new Term(idField.getName(), cmd.getIndexedId())); if (commitTracker.timeUpperBound > 0) { commitTracker.scheduleCommitWithin(commitTracker.timeUpperBound); @@ -222,7 +219,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { if (delAll) { deleteAll(); } else { - indexWriterProvider.getIndexWriter().deleteDocuments(q); + indexWriterProvider.getIndexWriter(core).deleteDocuments(q); } madeIt = true; @@ -250,7 +247,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { IndexReader[] readers = cmd.readers; if (readers != null && readers.length > 0) { - indexWriterProvider.getIndexWriter().addIndexes(readers); + indexWriterProvider.getIndexWriter(core).addIndexes(readers); rc = 1; } else { rc = 0; @@ -269,7 +266,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { @Override public void commit(CommitUpdateCommand cmd) throws IOException { - IndexWriter writer = indexWriterProvider.getIndexWriter(); + IndexWriter writer = indexWriterProvider.getIndexWriter(core); if (cmd.optimize) { optimizeCommands.incrementAndGet(); } else { @@ -352,7 +349,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { IndexReader currentReader = previousSearcher.getIndexReader(); IndexReader newReader; - newReader = currentReader.reopen(indexWriterProvider.getIndexWriter(), true); + newReader = currentReader.reopen(indexWriterProvider.getIndexWriter(core), true); if (newReader == currentReader) { @@ -364,7 +361,7 @@ public class DirectUpdateHandler2 extends UpdateHandler { @Override public void newIndexWriter() throws IOException { - indexWriterProvider.newIndexWriter(); + indexWriterProvider.newIndexWriter(core); } /** diff --git a/solr/core/src/java/org/apache/solr/update/IndexWriterProvider.java b/solr/core/src/java/org/apache/solr/update/IndexWriterProvider.java index 00929851dba..0600092afaa 100644 --- a/solr/core/src/java/org/apache/solr/update/IndexWriterProvider.java +++ b/solr/core/src/java/org/apache/solr/update/IndexWriterProvider.java @@ -24,16 +24,14 @@ import org.apache.solr.core.SolrCore; public interface IndexWriterProvider { - public void newIndexWriter() throws IOException; + public void newIndexWriter(SolrCore core) throws IOException; - public IndexWriter getIndexWriter() throws IOException; + public IndexWriter getIndexWriter(SolrCore core) throws IOException; public void decref() throws IOException; public void incref(); - public void rollbackIndexWriter() throws IOException; - - public void updateCore(SolrCore core); + public void rollbackIndexWriter(SolrCore core) throws IOException; } diff --git a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java index ace6c027408..a3381199356 100644 --- a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java +++ b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java @@ -120,7 +120,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { // test merge factor picked up SolrCore core = h.getCore(); - IndexWriter writer = ((DirectUpdateHandler2)core.getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)core.getUpdateHandler()).getIndexWriterProvider().getIndexWriter(core); assertEquals("Mergefactor was not picked up", ((LogMergePolicy)writer.getConfig().getMergePolicy()).getMergeFactor(), 8); lrf.args.put(CommonParams.VERSION,"2.2"); diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java index 9029ef56069..f689615748b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java @@ -47,7 +47,7 @@ public class BasicZkTest extends AbstractZkTestCase { // test merge factor picked up SolrCore core = h.getCore(); - IndexWriter writer = ((DirectUpdateHandler2)core.getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)core.getUpdateHandler()).getIndexWriterProvider().getIndexWriter(core); assertEquals("Mergefactor was not picked up", ((LogMergePolicy)writer.getConfig().getMergePolicy()).getMergeFactor(), 8); diff --git a/solr/core/src/test/org/apache/solr/core/TestConfig.java b/solr/core/src/test/org/apache/solr/core/TestConfig.java index ea9f8ae1095..af0c502fb35 100644 --- a/solr/core/src/test/org/apache/solr/core/TestConfig.java +++ b/solr/core/src/test/org/apache/solr/core/TestConfig.java @@ -116,7 +116,7 @@ public class TestConfig extends SolrTestCaseJ4 { @Test public void testTermIndexInterval() throws Exception { - IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(h.getCore()); int interval = writer.getConfig().getTermIndexInterval(); assertEquals(256, interval); } diff --git a/solr/core/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java b/solr/core/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java index e123921b02f..5e4dbafd9f8 100644 --- a/solr/core/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java +++ b/solr/core/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java @@ -33,7 +33,7 @@ public class TestLegacyMergeSchedulerPolicyConfig extends SolrTestCaseJ4 { @Test public void testLegacy() throws Exception { - IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(h.getCore()); assertTrue(writer.getConfig().getMergePolicy().getClass().getName().equals(LogDocMergePolicy.class.getName())); assertTrue(writer.getConfig().getMergeScheduler().getClass().getName().equals(SerialMergeScheduler.class.getName())); } diff --git a/solr/core/src/test/org/apache/solr/core/TestPropInject.java b/solr/core/src/test/org/apache/solr/core/TestPropInject.java index 2f9c2d5ea3d..1195ca40e06 100644 --- a/solr/core/src/test/org/apache/solr/core/TestPropInject.java +++ b/solr/core/src/test/org/apache/solr/core/TestPropInject.java @@ -37,13 +37,13 @@ public class TestPropInject extends AbstractSolrTestCase { } public void testMergePolicy() throws Exception { - IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(h.getCore()); LogByteSizeMergePolicy mp = (LogByteSizeMergePolicy)writer.getConfig().getMergePolicy(); assertEquals(64.0, mp.getMaxMergeMB(), 0); } public void testProps() throws Exception { - IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(h.getCore()); ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler)writer.getConfig().getMergeScheduler(); assertEquals(2, cms.getMaxThreadCount()); } diff --git a/solr/core/src/test/org/apache/solr/core/TestPropInjectDefaults.java b/solr/core/src/test/org/apache/solr/core/TestPropInjectDefaults.java index 7b87e52fe66..9fe4354ae42 100644 --- a/solr/core/src/test/org/apache/solr/core/TestPropInjectDefaults.java +++ b/solr/core/src/test/org/apache/solr/core/TestPropInjectDefaults.java @@ -33,14 +33,14 @@ public class TestPropInjectDefaults extends SolrTestCaseJ4 { @Test public void testMergePolicyDefaults() throws Exception { - IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(h.getCore()); LogByteSizeMergePolicy mp = (LogByteSizeMergePolicy)writer.getConfig().getMergePolicy(); assertEquals(32.0, mp.getMaxMergeMB(), 0); } @Test public void testPropsDefaults() throws Exception { - IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(); + IndexWriter writer = ((DirectUpdateHandler2)h.getCore().getUpdateHandler()).getIndexWriterProvider().getIndexWriter(h.getCore()); ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler)writer.getConfig().getMergeScheduler(); assertEquals(4, cms.getMaxThreadCount()); }