Package org.apache.blur.server

Examples of org.apache.blur.server.IndexSearcherClosable


      throw e;
    } catch (Exception e) {
      LOG.error("Unknown error while trying to get the correct index reader for selector [{0}].", e, selector);
      throw new BException(e.getMessage(), e);
    }
    IndexSearcherClosable searcher = null;
    TimerContext timerContext = _fetchTimer.time();
    boolean usedCache = true;
    try {
      ShardServerContext shardServerContext = ShardServerContext.getShardServerContext();
      if (shardServerContext != null) {
        searcher = shardServerContext.getIndexSearcherClosable(table, shard);
      }
      if (searcher == null) {
        searcher = index.getIndexReader();
        usedCache = false;
      }

      TableContext tableContext = getTableContext(table);
      FieldManager fieldManager = tableContext.getFieldManager();

      Query highlightQuery = getHighlightQuery(selector, table, fieldManager);

      fetchRow(searcher.getIndexReader(), table, shard, selector, fetchResult, highlightQuery, fieldManager,
          _maxHeapPerRowFetch);

      if (fetchResult.rowResult != null) {
        if (fetchResult.rowResult.row != null && fetchResult.rowResult.row.records != null) {
          _readRecordsMeter.mark(fetchResult.rowResult.row.records.size());
        }
        _readRowMeter.mark();
      } else if (fetchResult.recordResult != null) {
        _readRecordsMeter.mark();
      }
    } catch (Exception e) {
      LOG.error("Unknown error while trying to fetch row.", e);
      throw new BException(e.getMessage(), e);
    } finally {
      timerContext.stop();
      if (!usedCache && searcher != null) {
        // if the cached search was not used, close the searcher.
        // this will allow for closing of index
        try {
          searcher.close();
        } catch (IOException e) {
          LOG.error("Unknown error trying to call close on searcher [{0}]", e, searcher);
        }
      }
    }
View Full Code Here


    Map<String, BlurIndex> indexes = _indexServer.getIndexes(table);
    BlurIndex blurIndex = indexes.get(shardName);
    if (blurIndex == null) {
      throw new BException("Shard [" + shardName + "] is not being servered by this shardserver.");
    }
    IndexSearcherClosable searcher = blurIndex.getIndexReader();
    try {
      BooleanQuery query = new BooleanQuery();
      if (selector.recordOnly) {
        query.add(new TermQuery(new Term(RECORD_ID, recordId)), Occur.MUST);
        query.add(new TermQuery(new Term(ROW_ID, rowId)), Occur.MUST);
      } else {
        query.add(new TermQuery(new Term(ROW_ID, rowId)), Occur.MUST);
        query.add(new TermQuery(BlurUtil.PRIME_DOC_TERM), Occur.MUST);
      }
      TopDocs topDocs = searcher.search(query, 1);
      if (topDocs.totalHits > 1) {
        if (selector.recordOnly) {
          LOG.warn("Rowid [" + rowId + "], recordId [" + recordId
              + "] has more than one prime doc that is not deleted.");
        } else {
          LOG.warn("Rowid [" + rowId + "] has more than one prime doc that is not deleted.");
        }
      }
      if (topDocs.totalHits == 1) {
        selector.setLocationId(shardName + "/" + topDocs.scoreDocs[0].doc);
      } else {
        selector.setLocationId(NOT_FOUND);
      }
    } finally {
      // this will allow for closing of index
      searcher.close();
    }
  }
View Full Code Here

    }
    return ForkJoin.execute(_executor, blurIndexes.entrySet(), new ParallelCall<Entry<String, BlurIndex>, Long>() {
      @Override
      public Long call(Entry<String, BlurIndex> input) throws Exception {
        BlurIndex index = input.getValue();
        IndexSearcherClosable searcher = index.getIndexReader();
        try {
          return recordFrequency(searcher.getIndexReader(), columnFamily, columnName, value);
        } finally {
          // this will allow for closing of index
          searcher.close();
        }
      }
    }).merge(new Merger<Long>() {
      @Override
      public Long merge(BlurExecutorCompletionService<Long> service) throws BlurException {
View Full Code Here

    return ForkJoin.execute(_executor, blurIndexes.entrySet(),
        new ParallelCall<Entry<String, BlurIndex>, List<String>>() {
          @Override
          public List<String> call(Entry<String, BlurIndex> input) throws Exception {
            BlurIndex index = input.getValue();
            IndexSearcherClosable searcher = index.getIndexReader();
            try {
              return terms(searcher.getIndexReader(), columnFamily, columnName, startWith, size);
            } finally {
              // this will allow for closing of index
              searcher.close();
            }
          }
        }).merge(new Merger<List<String>>() {
      @Override
      public List<String> merge(BlurExecutorCompletionService<List<String>> service) throws BlurException {
View Full Code Here

  private void warmUp(final BlurIndex index, final TableDescriptor table, final String shard) throws IOException {
    _warmupExecutor.submit(new Runnable() {
      @Override
      public void run() {
        try {
          final IndexSearcherClosable searcher = index.getIndexReader();
          IndexReader reader = searcher.getIndexReader();
          _warmup.warmBlurIndex(table, shard, reader, index.isClosed(), new ReleaseReader() {
            @Override
            public void release() throws IOException {
              // this will allow for closing of index
              searcher.close();
            }
          }, _pauseWarmup);
        } catch (Exception e) {
          LOG.error("Unknown error while trying to warmup index [" + index + "]", e);
        }
View Full Code Here

  public abstract void removeSnapshot(String name) throws IOException;
 
  public abstract List<String> getSnapshots() throws IOException;

  public long getRecordCount() throws IOException {
    IndexSearcherClosable searcher = getIndexReader();
    try {
      return searcher.getIndexReader().numDocs();
    } finally {
      if (searcher != null) {
        searcher.close();
      }
    }
  }
View Full Code Here

      }
    }
  }

  public long getRowCount() throws IOException {
    IndexSearcherClosable searcher = getIndexReader();
    try {
      return getRowCount(searcher);
    } finally {
      if (searcher != null) {
        searcher.close();
      }
    }
  }
View Full Code Here

  public long getIndexMemoryUsage() throws IOException {
    long now = System.currentTimeMillis();
    if (_lastMemoryCheck + ONE_MINUTE > now) {
      return _memoryUsage;
    }
    IndexSearcherClosable searcher = getIndexReader();
    try {
      IndexReaderContext topReaderContext = searcher.getTopReaderContext();
      return _memoryUsage = RamUsageEstimator.sizeOf(topReaderContext, new ClassNameFilter() {
        @Override
        public boolean include(String className) {
          if (className.startsWith("org.apache.blur.index.ExitableReader")) {
            return true;
          } else if (className.startsWith("org.apache.blur.")) {
            // System.out.println("className [" + className + "]");
            return false;
          }
          return true;
        }
      });
    } finally {
      searcher.close();
      _lastMemoryCheck = System.currentTimeMillis();
    }
  }
View Full Code Here

      _lastMemoryCheck = System.currentTimeMillis();
    }
  }

  public long getSegmentCount() throws IOException {
    IndexSearcherClosable indexSearcherClosable = getIndexReader();
    try {
      IndexReader indexReader = indexSearcherClosable.getIndexReader();
      IndexReaderContext context = indexReader.getContext();
      return context.leaves().size();
    } finally {
      indexSearcherClosable.close();
    }
  }
View Full Code Here

  @Override
  public IndexSearcherClosable getIndexReader() throws IOException {
    final DirectoryReader reader = _indexReaderRef.get();
    reader.incRef();
    return new IndexSearcherClosable(reader, null) {

      @Override
      public Directory getDirectory() {
        return _directory;
      }
View Full Code Here

TOP

Related Classes of org.apache.blur.server.IndexSearcherClosable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.