incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/2] git commit: Working on BLUR-33.
Date Thu, 18 Oct 2012 02:04:28 GMT
Working on BLUR-33.


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

Branch: refs/heads/lucene-4.0.0
Commit: dda0c7ade98efacb8a5607069da8a4d1d0096dba
Parents: 8b48537
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Wed Oct 17 21:41:37 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Oct 17 21:41:37 2012 -0400

----------------------------------------------------------------------
 .../manager/indexserver/AbstractIndexServer.java   |  121 ++++-----------
 1 files changed, 28 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/dda0c7ad/src/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
b/src/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
index 03344af..b9e0e6b 100644
--- a/src/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
+++ b/src/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
@@ -18,119 +18,54 @@ package org.apache.blur.manager.indexserver;
  */
 import java.io.IOException;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.blur.manager.IndexServer;
 import org.apache.blur.manager.writer.BlurIndex;
 import org.apache.blur.utils.BlurConstants;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.TermDocs;
-
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
 
 public abstract class AbstractIndexServer implements IndexServer {
 
-  private Map<String, IndexCounts> _recordsTableCounts = new ConcurrentHashMap<String,
IndexCounts>();
-  private Map<String, IndexCounts> _rowTableCounts = new ConcurrentHashMap<String,
IndexCounts>();
-
-  private static class IndexCounts {
-    Map<String, IndexCount> counts = new ConcurrentHashMap<String, IndexCount>();
-  }
-
-  private static class IndexCount {
-    long version;
-    long count = -1;
-  }
-
   public long getRecordCount(String table) throws IOException {
-    IndexCounts indexCounts;
-    synchronized (_recordsTableCounts) {
-      indexCounts = _recordsTableCounts.get(table);
-      if (indexCounts == null) {
-        indexCounts = new IndexCounts();
-        _recordsTableCounts.put(table, indexCounts);
-      }
-    }
-    synchronized (indexCounts) {
-      long recordCount = 0;
-      Map<String, BlurIndex> indexes = getIndexes(table);
-      for (Map.Entry<String, BlurIndex> index : indexes.entrySet()) {
-        IndexReader indexReader = null;
-        try {
-          String shard = index.getKey();
-          IndexCount indexCount = indexCounts.counts.get(shard);
-          if (indexCount == null) {
-            indexCount = new IndexCount();
-            indexCounts.counts.put(shard, indexCount);
-          }
-          indexReader = index.getValue().getIndexReader();
-          if (!isValid(indexCount, indexReader)) {
-            indexCount.count = indexReader.numDocs();
-            indexCount.version = indexReader.getVersion();
-          }
-          recordCount += indexCount.count;
-        } finally {
-          if (indexReader != null) {
-            indexReader.decRef();
-          }
+    long recordCount = 0;
+    Map<String, BlurIndex> indexes = getIndexes(table);
+    for (Map.Entry<String, BlurIndex> index : indexes.entrySet()) {
+      IndexReader indexReader = null;
+      try {
+        indexReader = index.getValue().getIndexReader();
+        recordCount += indexReader.numDocs();
+      } finally {
+        if (indexReader != null) {
+          indexReader.decRef();
         }
       }
-      return recordCount;
     }
-  }
-
-  private boolean isValid(IndexCount indexCount, IndexReader indexReader) {
-    if (indexCount.version == indexReader.getVersion() && indexCount.count != -1l)
{
-      return true;
-    }
-    return false;
+    return recordCount;
   }
 
   public long getRowCount(String table) throws IOException {
-    IndexCounts indexCounts;
-    synchronized (_rowTableCounts) {
-      indexCounts = _rowTableCounts.get(table);
-      if (indexCounts == null) {
-        indexCounts = new IndexCounts();
-        _rowTableCounts.put(table, indexCounts);
-      }
-    }
-    synchronized (indexCounts) {
-      long rowCount = 0;
-      Map<String, BlurIndex> indexes = getIndexes(table);
-      for (Map.Entry<String, BlurIndex> index : indexes.entrySet()) {
-        IndexReader indexReader = null;
-        try {
-          String shard = index.getKey();
-          IndexCount indexCount = indexCounts.counts.get(shard);
-          if (indexCount == null) {
-            indexCount = new IndexCount();
-            indexCounts.counts.put(shard, indexCount);
-          }
-          indexReader = index.getValue().getIndexReader();
-          if (!isValid(indexCount, indexReader)) {
-            indexCount.count = getRowCount(indexReader);
-            indexCount.version = indexReader.getVersion();
-          }
-          rowCount += indexCount.count;
-        } finally {
-          if (indexReader != null) {
-            indexReader.decRef();
-          }
+    long rowCount = 0;
+    Map<String, BlurIndex> indexes = getIndexes(table);
+    for (Map.Entry<String, BlurIndex> index : indexes.entrySet()) {
+      IndexReader indexReader = null;
+      try {
+        indexReader = index.getValue().getIndexReader();
+        rowCount += getRowCount(indexReader);
+      } finally {
+        if (indexReader != null) {
+          indexReader.decRef();
         }
       }
-      return rowCount;
     }
+    return rowCount;
   }
 
   private long getRowCount(IndexReader indexReader) throws IOException {
-    long rowCount = 0;
-    TermDocs termDocs = indexReader.termDocs(BlurConstants.PRIME_DOC_TERM);
-    while (termDocs.next()) {
-      if (!indexReader.isDeleted(termDocs.doc())) {
-        rowCount++;
-      }
-    }
-    termDocs.close();
-    return rowCount;
+    IndexSearcher searcher = new IndexSearcher(indexReader);
+    TopDocs topDocs = searcher.search(new TermQuery(BlurConstants.PRIME_DOC_TERM), 1);
+    return topDocs.totalHits;
   }
 }


Mime
View raw message