Package org.apache.blur.trace

Examples of org.apache.blur.trace.Tracer


    // TODO: should we make this
    // threaded...? the Collector could be sync'd?
    // always use single thread:
    for (AtomicReaderContext ctx : leaves) { // search each subreader
      Tracer trace = Trace.trace("search - internal", Trace.param("AtomicReader", ctx.reader()));
      try {
        try {
          collector.setNextReader(ctx);
        } catch (CollectionTerminatedException e) {
          // there is no doc of interest in this reader context
          // continue with the following leaf
          continue;
        }
        Scorer scorer = weight.scorer(ctx, !collector.acceptsDocsOutOfOrder(), true, ctx.reader().getLiveDocs());
        if (scorer != null) {
          try {
            scorer.score(collector);
          } catch (CollectionTerminatedException e) {
            // collection was terminated prematurely
            // continue with the following leaf
          }
        }
      } finally {
        trace.done();
      }
    }
  }
View Full Code Here


    return _counts.get(i);
  }

  public void processFacets(ExecutorService executor) throws IOException {
    if (!_processed) {
      Tracer trace = Trace.trace("processing facets");
      try {
        processInternal(executor);
      } finally {
        trace.done();
      }
      _processed = true;
    }
  }
View Full Code Here

      _locks = locks;
    }

    void process(AtomicLongArray counts, long[] minimumsBeforeReturning, AtomicBoolean running) throws IOException {
      if (minimumsBeforeReturning == null) {
        Tracer trace = Trace.trace("processing facet - segment", Trace.param("reader", _readerStr),
            Trace.param("maxDoc", _maxDoc), Trace.param("minimums", "NONE"), Trace.param("scorers", _scorers.length));
        try {
          for (int i = 0; i < _scorers.length && running.get(); i++) {
            SimpleCollector col = new SimpleCollector(_bitSet);
            runFacet(counts, col, i);
          }
        } finally {
          trace.done();
        }
      } else {
        BlockingQueue<Integer> ids = new ArrayBlockingQueue<Integer>(_scorers.length + 1);
        try {
          populate(ids);
View Full Code Here

    }

    private void runFacet(AtomicLongArray counts, SimpleCollector col, int i) throws IOException {
      Scorer scorer = _scorers[i];
      if (scorer != null) {
        Tracer traceInner = Trace.trace("processing facet - segment - scorer", Trace.param("scorer", scorer),
            Trace.param("scorer.cost", scorer.cost()));
        try {
          // new ExitScorer(scorer).score(col);
          scorer.score(col);
        } catch (Finished e) {
          // Do nothing, exiting early.
        } finally {
          traceInner.done();
        }
        int hits = col._hits;
        LOG.debug("Facet [{0}] result [{1}]", i, hits);
        counts.addAndGet(i, hits);
      }
View Full Code Here

    public BlurResultIterable call(Entry<String, BlurIndex> entry) throws Exception {
      String shard = entry.getKey();
      _status.attachThread(shard);
      BlurIndex index = entry.getValue();
      IndexSearcherClosable searcher = index.getIndexSearcher();
      Tracer trace2 = null;
      try {
        IndexReader indexReader = searcher.getIndexReader();
        if (indexReader instanceof ExitableReader) {
          ExitableReader er = (ExitableReader) indexReader;
          er.setRunning(_running);
        } else {
          throw new IOException("IndexReader is not ExitableReader");
        }
        if (_shardServerContext != null) {
          _shardServerContext.setIndexSearcherClosable(_table, shard, searcher);
        }
        searcher.setSimilarity(_similarity);
        Tracer trace1 = Trace.trace("query rewrite", Trace.param("table", _table));
        Query rewrite;
        try {
          rewrite = searcher.rewrite((Query) _query.clone());
        } catch (ExitingReaderException e) {
          LOG.info("Query [{0}] has been cancelled during the rewrite phase.", _query);
          throw e;
        } finally {
          trace1.done();
        }

        // BlurResultIterableSearcher will close searcher, if shard server
        // context is null.
        trace2 = Trace.trace("query initial search");
View Full Code Here

  @Override
  public BlurIterator<BlurResult, BlurException> iterator() throws BlurException {
    MultipleHitsIterator iterator = new MultipleHitsIterator(results);
    long start = 0;
    Tracer trace = Trace.trace("blurResultsIterable - iterator - skipping", Trace.param("skipTo", skipTo));
    while (iterator.hasNext() && start < skipTo) {
      iterator.next();
      start++;
    }
    trace.done();
    return iterator;
  }
View Full Code Here

    _fileSystem = _storagePath.getFileSystem(_configuration);
  }

  @Override
  protected List<String> getFieldNamesToLoad() throws IOException {
    Tracer trace = Trace.trace("filesystem - getFieldNamesToLoad", Trace.param("storagePath", _storagePath));
    try {
      if (!_fileSystem.exists(_storagePath)) {
        return EMPTY_LIST;
      }
      FileStatus[] listStatus = _fileSystem.listStatus(_storagePath, new PathFilter() {
        @Override
        public boolean accept(Path path) {
          if (path.getName().endsWith(TYPE_FILE_EXT)) {
            return true;
          }
          return false;
        }
      });
      if (listStatus == null) {
        return EMPTY_LIST;
      }
      List<String> fieldNames = new ArrayList<String>();
      for (FileStatus fileStatus : listStatus) {
        if (!fileStatus.isDir()) {
          String fileName = fileStatus.getPath().getName();
         
          fieldNames.add(fileName.substring(0, fileName.lastIndexOf(TYPE_FILE_EXT)));
        }
      }
      return fieldNames;
    } finally {
      trace.done();
    }
  }
View Full Code Here

    }
  }

  @Override
  protected boolean tryToStore(FieldTypeDefinition fieldTypeDefinition, String fieldName) throws IOException {
    Tracer trace = Trace.trace("filesystem - tryToStore fieldName", Trace.param("fieldName", fieldName),
        Trace.param("storagePath", _storagePath));
    try {
      // Might want to make this a ZK lock
      _lock.lock();
      try {
        String fieldType = fieldTypeDefinition.getFieldType();
        boolean fieldLessIndexed = fieldTypeDefinition.isFieldLessIndexed();
        boolean sortEnable = fieldTypeDefinition.isSortEnable();
        LOG.info(
            "Attempting to store new field [{0}] with fieldLessIndexing [{1}] with type [{2}] and properties [{3}]",
            fieldName, fieldLessIndexed, fieldType, fieldTypeDefinition.getProperties());
        Properties properties = new Properties();
        setProperty(properties, FAMILY, fieldTypeDefinition.getFamily());
        setProperty(properties, FAMILY, fieldTypeDefinition.getFamily());
        setProperty(properties, COLUMN_NAME, fieldTypeDefinition.getColumnName());
        setProperty(properties, SUB_COLUMN_NAME, fieldTypeDefinition.getSubColumnName());
        setProperty(properties, FIELD_LESS_INDEXING, Boolean.toString(fieldLessIndexed));
        setProperty(properties, SORTENABLED, Boolean.toString(sortEnable));

        setProperty(properties, FIELD_TYPE, fieldType);
        Map<String, String> props = fieldTypeDefinition.getProperties();
        if (props != null) {
          for (Entry<String, String> e : props.entrySet()) {
            properties.setProperty(e.getKey(), e.getValue());
          }
        }
        Path path = getFieldPath(fieldName);
        if (_fileSystem.exists(path)) {
          LOG.info("Field [{0}] already exists.", fieldName);
          return false;
        }
        Path tmpPath = new Path(path.getParent(), UUID.randomUUID().toString() + ".tmp");
        FSDataOutputStream outputStream = _fileSystem.create(tmpPath, false);
        properties.store(outputStream, getComments());
        outputStream.close();
        if (_fileSystem.rename(tmpPath, path)) {
          // @TODO make this configurable
          _fileSystem.setReplication(path, (short) 10);
          return true;
        } else {
          _fileSystem.delete(tmpPath, false);
          LOG.info("Field [{0}] already exists.", fieldName, fieldLessIndexed, fieldType, props);
          return false;
        }
      } finally {
        _lock.unlock();
      }
    } finally {
      trace.done();
    }
  }
View Full Code Here

  public List<String> getSnapshots() throws IOException {
    return new ArrayList<String>(_snapshotIndexDeletionPolicy.getSnapshots());
  }

  private void commit() throws IOException {
    Tracer trace1 = Trace.trace("prepareCommit");
    waitUntilNotNull(_writer);
    BlurIndexWriter writer = _writer.get();
    writer.prepareCommit();
    trace1.done();

    Tracer trace2 = Trace.trace("commit");
    writer.commit();
    trace2.done();

    Tracer trace3 = Trace.trace("index refresh");
    DirectoryReader currentReader = _indexReader.get();
    DirectoryReader newReader = DirectoryReader.openIfChanged(currentReader);
    if (newReader == null) {
      LOG.debug("Reader should be new after commit for table [{0}] shard [{1}].", _tableContext.getTable(),
          _shardContext.getShard());
    } else {
      DirectoryReader reader = wrap(newReader);
      _indexRefreshWriteLock.lock();
      try {
        _indexReader.set(reader);
      } finally {
        _indexRefreshWriteLock.unlock();
      }
      _indexCloser.close(currentReader);
    }
    trace3.done();
  }
View Full Code Here

    TableContext tableContext = getTableContext(table);
    ReadInterceptor interceptor = tableContext.getReadInterceptor();
    Filter filter = interceptor.getFilter();
    BlurIndex index = null;
    String shard = null;
    Tracer trace = Trace.trace("manager fetch", Trace.param("table", table));
    IndexSearcherClosable searcher = null;
    try {
      if (selector.getLocationId() == null) {
        // Not looking up by location id so we should resetSearchers.
        ShardServerContext.resetSearchers();
        shard = MutationHelper.getShardName(table, selector.rowId, getNumberOfShards(table), _blurPartitioner);
        index = getBlurIndex(table, shard);
        searcher = index.getIndexSearcher();
        populateSelector(searcher, shard, table, selector);
      }
      String locationId = selector.getLocationId();
      if (locationId.equals(NOT_FOUND)) {
        fetchResult.setDeleted(false);
        fetchResult.setExists(false);
        return;
      }
      if (shard == null) {
        shard = getShard(locationId);
      }
      if (index == null) {
        index = getBlurIndex(table, shard);
      }
    } catch (BlurException e) {
      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);
    }
    TimerContext timerContext = _fetchTimer.time();
    boolean usedCache = true;
    try {
      ShardServerContext shardServerContext = ShardServerContext.getShardServerContext();
      if (shardServerContext != null) {
        searcher = shardServerContext.getIndexSearcherClosable(table, shard);
      }
      if (searcher == null) {
        // Was not pulled from cache, get a fresh one from the index.
        searcher = index.getIndexSearcher();
        usedCache = false;
      }
      FieldManager fieldManager = tableContext.getFieldManager();

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

      fetchRow(searcher.getIndexReader(), table, shard, selector, fetchResult, highlightQuery, fieldManager,
          _maxHeapPerRowFetch, tableContext, filter);
    } catch (Exception e) {
      LOG.error("Unknown error while trying to fetch row.", e);
      throw new BException(e.getMessage(), e);
    } finally {
      trace.done();
      timerContext.stop();
      if (!usedCache && searcher != null) {
        // if the cached search was not used, close the searcher.
        // this will allow for closing of index
        try {
View Full Code Here

TOP

Related Classes of org.apache.blur.trace.Tracer

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.