From 82c6dafc010e373266af9d49534f74ccb0d4b8a1 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Sun, 26 Jun 2011 14:17:27 +0000 Subject: [PATCH] NRTCachingDir doesn't need the MergeScheduler anymore git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/LUCENE2793@1139797 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/store/NRTCachingDirectory.java | 30 +------------------ .../apache/lucene/index/TestNRTManager.java | 4 +-- .../lucene/store/TestNRTCachingDirectory.java | 2 -- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java index 89de60561d7..feee0121598 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/NRTCachingDirectory.java @@ -40,11 +40,7 @@ import org.apache.lucene.util.IOUtils; /** * Wraps a {@link RAMDirectory} * around any provided delegate directory, to - * be used during NRT search. Make sure you pull the merge - * scheduler using {@link #getMergeScheduler} and pass that to your - * {@link IndexWriter}; this class uses that to keep track of which - * merges are being done by which threads, to decide when to - * cache each written file. + * be used during NRT search. * *

This class is likely only useful in a near-real-time * context, where indexing rate is lowish but reopen @@ -56,20 +52,12 @@ import org.apache.lucene.util.IOUtils; *

This is safe to use: when your app calls {IndexWriter#commit}, * all cached files will be flushed from the cached and sync'd.

* - *

NOTE: this class is somewhat sneaky in its - * approach for spying on merges to determine the size of a - * merge: it records which threads are running which merges - * by watching ConcurrentMergeScheduler's doMerge method. - * While this works correctly, likely future versions of - * this class will take a more general approach. - * *

Here's a simple example usage: * *

  *   Directory fsDir = FSDirectory.open(new File("/path/to/index"));
  *   NRTCachingDirectory cachedFSDir = new NRTCachingDirectory(fsDir, 5.0, 60.0);
  *   IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_32, analyzer);
- *   conf.setMergeScheduler(cachedFSDir.getMergeScheduler());
  *   IndexWriter writer = new IndexWriter(cachedFSDir, conf);
  * 
* @@ -246,22 +234,6 @@ public class NRTCachingDirectory extends Directory { delegate.close(); } - private final ConcurrentHashMap merges = new ConcurrentHashMap(); - - public MergeScheduler getMergeScheduler() { - return new ConcurrentMergeScheduler() { - @Override - protected void doMerge(MergePolicy.OneMerge merge) throws IOException { - try { - merges.put(Thread.currentThread(), merge); - super.doMerge(merge); - } finally { - merges.remove(Thread.currentThread()); - } - } - }; - } - /** Subclass can override this to customize logic; return * true if this file should be written to the RAMDirectory. */ protected boolean doCacheWrite(String name, IOContext context) { diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestNRTManager.java b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestNRTManager.java index 6b1af4c02d0..26d6c0f8717 100644 --- a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestNRTManager.java +++ b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestNRTManager.java @@ -159,9 +159,7 @@ public class TestNRTManager extends LuceneTestCase { System.out.println("TEST: wrap NRTCachingDir"); } - NRTCachingDirectory nrtDir = new NRTCachingDirectory(dir, 5.0, 60.0); - conf.setMergeScheduler(nrtDir.getMergeScheduler()); - dir = nrtDir; + dir = new NRTCachingDirectory(dir, 5.0, 60.0); } final IndexWriter writer = new IndexWriter(dir, conf); diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java b/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java index 364d327e03c..48a7162b91f 100644 --- a/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java +++ b/lucene/contrib/misc/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java @@ -45,7 +45,6 @@ public class TestNRTCachingDirectory extends LuceneTestCase { Directory dir = newDirectory(); NRTCachingDirectory cachedDir = new NRTCachingDirectory(dir, 2.0, 25.0); IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)); - conf.setMergeScheduler(cachedDir.getMergeScheduler()); RandomIndexWriter w = new RandomIndexWriter(random, cachedDir, conf); w.w.setInfoStream(VERBOSE ? System.out : null); final LineFileDocs docs = new LineFileDocs(random); @@ -109,7 +108,6 @@ public class TestNRTCachingDirectory extends LuceneTestCase { Directory fsDir = FSDirectory.open(new File("/path/to/index")); NRTCachingDirectory cachedFSDir = new NRTCachingDirectory(fsDir, 2.0, 25.0); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_32, analyzer); - conf.setMergeScheduler(cachedFSDir.getMergeScheduler()); IndexWriter writer = new IndexWriter(cachedFSDir, conf); }