incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: Extracting some methods for easier use when dealing with AtomicReader instances.
Date Mon, 24 Jun 2013 14:50:07 GMT
Updated Branches:
  refs/heads/master ca443f372 -> d54a7fc81


Extracting some methods for easier use when dealing with AtomicReader instances.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/c3825496
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/c3825496
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/c3825496

Branch: refs/heads/master
Commit: c38254966b0fdf1aff013f31b81f0b220d1999b0
Parents: ca443f3
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Jun 24 10:48:56 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Jun 24 10:48:56 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/lucene/warmup/IndexWarmup.java  | 89 ++++++++++++--------
 1 file changed, 54 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c3825496/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java b/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
index c616c8e..6e9d0ae 100644
--- a/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
+++ b/blur-store/src/main/java/org/apache/blur/lucene/warmup/IndexWarmup.java
@@ -161,6 +161,9 @@ public class IndexWarmup {
   }
 
   private Directory getDirectory(IndexReader reader, String segmentName, String context)
{
+    if (reader instanceof AtomicReader) {
+      return getDirectory((AtomicReader) reader, segmentName, context);
+    }
     for (IndexReaderContext ctext : reader.getContext().leaves()) {
       if (_isClosed.get()) {
         LOG.info("Context [{0}] index closed", context);
@@ -178,6 +181,16 @@ public class IndexWarmup {
     return null;
   }
 
+  private Directory getDirectory(AtomicReader atomicReader, String segmentName, String context)
{
+    if (atomicReader instanceof SegmentReader) {
+      SegmentReader segmentReader = (SegmentReader) atomicReader;
+      if (segmentReader.getSegmentName().equals(segmentName)) {
+        return segmentReader.directory();
+      }
+    }
+    return null;
+  }
+
   private int findNextSetTrace(List<IndexTracerResult> traces, int startingIndex, FILE_TYPE
type) {
     int size = traces.size();
     for (int i = startingIndex; i < size; i++) {
@@ -202,50 +215,56 @@ public class IndexWarmup {
 
   public Map<String, List<IndexTracerResult>> sampleIndex(IndexReader reader,
String context) throws IOException {
     Map<String, List<IndexTracerResult>> results = new HashMap<String, List<IndexTracerResult>>();
-    LOOP: for (IndexReaderContext ctext : reader.getContext().leaves()) {
+    for (IndexReaderContext ctext : reader.getContext().leaves()) {
       if (_isClosed.get()) {
         LOG.info("Context [{0}] index closed", context);
         return null;
       }
       AtomicReaderContext atomicReaderContext = (AtomicReaderContext) ctext;
       AtomicReader atomicReader = atomicReaderContext.reader();
-      if (atomicReader instanceof SegmentReader) {
-        SegmentReader segmentReader = (SegmentReader) atomicReader;
-        Directory directory = segmentReader.directory();
-        if (!(directory instanceof TraceableDirectory)) {
-          LOG.info("Context [{1}] cannot warmup directory [{0}] needs to be a TraceableDirectory.",
directory, context);
-          continue LOOP;
-        }
-        IndexTracer tracer = new IndexTracer((TraceableDirectory) directory, _maxSampleSize);
-        String fileName = segmentReader.getSegmentName() + SAMPLE_EXT;
-        List<IndexTracerResult> segmentTraces = new ArrayList<IndexTracerResult>();
-        if (directory.fileExists(fileName)) {
-          IndexInput input = directory.openInput(fileName, IOContext.READONCE);
-          segmentTraces = read(input);
-          input.close();
-        } else {
-          Fields fields = atomicReader.fields();
-          for (String field : fields) {
-            LOG.info("Context [{1}] sampling field [{0}].", field, context);
-            Terms terms = fields.terms(field);
-            boolean hasOffsets = terms.hasOffsets();
-            boolean hasPayloads = terms.hasPayloads();
-            boolean hasPositions = terms.hasPositions();
+      results.putAll(sampleIndex(atomicReader, context));
+    }
+    return results;
+  }
 
-            tracer.initTrace(segmentReader, field, hasPositions, hasPayloads, hasOffsets);
-            IndexTracerResult result = tracer.runTrace(terms);
-            segmentTraces.add(result);
-          }
-          if (_isClosed.get()) {
-            LOG.info("Context [{0}] index closed", context);
-            return null;
-          }
-          IndexOutput output = directory.createOutput(fileName, IOContext.DEFAULT);
-          write(segmentTraces, output);
-          output.close();
+  public Map<String, List<IndexTracerResult>> sampleIndex(AtomicReader atomicReader,
String context) throws IOException {
+    Map<String, List<IndexTracerResult>> results = new HashMap<String, List<IndexTracerResult>>();
+    if (atomicReader instanceof SegmentReader) {
+      SegmentReader segmentReader = (SegmentReader) atomicReader;
+      Directory directory = segmentReader.directory();
+      if (!(directory instanceof TraceableDirectory)) {
+        LOG.info("Context [{1}] cannot warmup directory [{0}] needs to be a TraceableDirectory.",
directory, context);
+        return results;
+      }
+      IndexTracer tracer = new IndexTracer((TraceableDirectory) directory, _maxSampleSize);
+      String fileName = segmentReader.getSegmentName() + SAMPLE_EXT;
+      List<IndexTracerResult> segmentTraces = new ArrayList<IndexTracerResult>();
+      if (directory.fileExists(fileName)) {
+        IndexInput input = directory.openInput(fileName, IOContext.READONCE);
+        segmentTraces = read(input);
+        input.close();
+      } else {
+        Fields fields = atomicReader.fields();
+        for (String field : fields) {
+          LOG.info("Context [{1}] sampling field [{0}].", field, context);
+          Terms terms = fields.terms(field);
+          boolean hasOffsets = terms.hasOffsets();
+          boolean hasPayloads = terms.hasPayloads();
+          boolean hasPositions = terms.hasPositions();
+
+          tracer.initTrace(segmentReader, field, hasPositions, hasPayloads, hasOffsets);
+          IndexTracerResult result = tracer.runTrace(terms);
+          segmentTraces.add(result);
+        }
+        if (_isClosed.get()) {
+          LOG.info("Context [{0}] index closed", context);
+          return null;
         }
-        results.put(segmentReader.getSegmentName(), segmentTraces);
+        IndexOutput output = directory.createOutput(fileName, IOContext.DEFAULT);
+        write(segmentTraces, output);
+        output.close();
       }
+      results.put(segmentReader.getSegmentName(), segmentTraces);
     }
     return results;
   }


Mime
View raw message