@Test public void testQueryRecordOnly() throws Exception { BlurQuery blurQuery = new BlurQuery(); blurQuery.query = new Query(); blurQuery.query.query = "test-family.testcol1:value1"; blurQuery.selector = new Selector(); blurQuery.selector.setRecordOnly(true); BlurResultIterable iterable = indexManager.query(TABLE, blurQuery, null); assertEquals(iterable.getTotalResults(), 2); int matchRecord1 = 0; int matchRecord4 = 0; BlurIterator<BlurResult, BlurException> iterator = iterable.iterator(); while (iterator.hasNext()) { BlurResult result = iterator.next(); assertNull(result.fetchResult.rowResult); assertNotNull(result.fetchResult.recordResult); Record r = result.fetchResult.recordResult.record; if (r.getRecordId().equals("record-1")) { matchRecord1 += 1; } else if (r.getRecordId().equals("record-4")) { matchRecord4 += 1; } else { fail("Unexpected record ID [" + r.getRecordId() + "]"); } } assertEquals("Unexpected number of record-1 results", 1, matchRecord1); assertEquals("Unexpected number of record-4 results", 1, matchRecord4); }
public BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts) throws Exception { boolean runSlow = DEBUG_RUN_SLOW.get(); final AtomicBoolean running = new AtomicBoolean(true); User user = UserContext.getUser(); final QueryStatus status = _statusManager.newQueryStatus(table, blurQuery, _threadCount, running, UserConverter.toThriftUser(user)); _queriesExternalMeter.mark(); try { Map<String, BlurIndex> blurIndexes; try { blurIndexes = _indexServer.getIndexes(table); } catch (IOException e) { LOG.error("Unknown error while trying to fetch index readers.", e); throw new BException(e.getMessage(), e); } String rowId = blurQuery.getRowId(); if (rowId != null) { Map<String, BlurIndex> map = new HashMap<String, BlurIndex>(); String shard = MutationHelper.getShardName(table, rowId, getNumberOfShards(table), _blurPartitioner); BlurIndex index = getBlurIndex(table, shard); map.put(shard, index); blurIndexes = map; } Tracer trace = Trace.trace("query setup", Trace.param("table", table)); ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); ParallelCall<Entry<String, BlurIndex>, BlurResultIterable> call; TableContext context = getTableContext(table); FieldManager fieldManager = context.getFieldManager(); org.apache.blur.thrift.generated.Query simpleQuery = blurQuery.query; ReadInterceptor interceptor = context.getReadInterceptor(); Filter readFilter = interceptor.getFilter(); if (rowId != null) { if (simpleQuery.recordFilter == null) { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId; } else { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId + " +(" + simpleQuery.recordFilter + ")"; } } Filter recordFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.recordFilter, false, fieldManager, _filterCache, context); Filter rowFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.rowFilter, true, fieldManager, _filterCache, context); Filter docFilter; if (recordFilterForSearch == null && readFilter != null) { docFilter = readFilter; } else if (recordFilterForSearch != null && readFilter == null) { docFilter = recordFilterForSearch; } else if (recordFilterForSearch != null && readFilter != null) { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.add(recordFilterForSearch, Occur.MUST); booleanFilter.add(readFilter, Occur.MUST); docFilter = booleanFilter; } else { docFilter = null; } Query userQuery = QueryParserUtil.parseQuery(simpleQuery.query, simpleQuery.rowQuery, fieldManager, rowFilterForSearch, docFilter, getScoreType(simpleQuery.scoreType), context); Query facetedQuery; FacetExecutor executor = null; if (blurQuery.facets != null) { long[] facetMinimums = getFacetMinimums(blurQuery.facets); executor = new FacetExecutor(blurQuery.facets.size(), facetMinimums, facetedCounts, running); facetedQuery = new FacetQuery(userQuery, getFacetQueries(blurQuery, fieldManager, context, rowFilterForSearch, recordFilterForSearch), executor); } else { facetedQuery = userQuery; } Sort sort = getSort(blurQuery, fieldManager); call = new SimpleQueryParallelCall(running, table, status, facetedQuery, blurQuery.selector, _queriesInternalMeter, shardServerContext, runSlow, _fetchCount, _maxHeapPerRowFetch, context.getSimilarity(), context, sort, _deepPagingCache, _memoryAllocationWatcher); trace.done(); MergerBlurResultIterable merger = new MergerBlurResultIterable(blurQuery); BlurResultIterable merge = ForkJoin.execute(_executor, blurIndexes.entrySet(), call, new Cancel() { @Override public void cancel() { running.set(false); } }).merge(merger); if (executor != null) { executor.processFacets(_facetExecutor); } return fetchDataIfNeeded(merge, table, blurQuery.getSelector()); } catch (StopExecutionCollectorException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } catch (ExitingReaderException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } finally { _statusManager.removeStatus(status); } }
IndexManager { public BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts) throws Exception { boolean runSlow = DEBUG_RUN_SLOW.get(); final AtomicBoolean running = new AtomicBoolean(true); User user = UserContext.getUser(); final QueryStatus status = _statusManager.newQueryStatus(table, blurQuery, _threadCount, running, UserConverter.toThriftUser(user)); _queriesExternalMeter.mark(); try { Map<String, BlurIndex> blurIndexes; try { blurIndexes = _indexServer.getIndexes(table); } catch (IOException e) { LOG.error("Unknown error while trying to fetch index readers.", e); throw new BException(e.getMessage(), e); } String rowId = blurQuery.getRowId(); if (rowId != null) { Map<String, BlurIndex> map = new HashMap<String, BlurIndex>(); String shard = MutationHelper.getShardName(table, rowId, getNumberOfShards(table), _blurPartitioner); BlurIndex index = getBlurIndex(table, shard); map.put(shard, index); blurIndexes = map; } Tracer trace = Trace.trace("query setup", Trace.param("table", table)); ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); ParallelCall<Entry<String, BlurIndex>, BlurResultIterable> call; TableContext context = getTableContext(table); FieldManager fieldManager = context.getFieldManager(); org.apache.blur.thrift.generated.Query simpleQuery = blurQuery.query; ReadInterceptor interceptor = context.getReadInterceptor(); Filter readFilter = interceptor.getFilter(); if (rowId != null) { if (simpleQuery.recordFilter == null) { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId; } else { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId + " +(" + simpleQuery.recordFilter + ")"; } } Filter recordFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.recordFilter, false, fieldManager, _filterCache, context); Filter rowFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.rowFilter, true, fieldManager, _filterCache, context); Filter docFilter; if (recordFilterForSearch == null && readFilter != null) { docFilter = readFilter; } else if (recordFilterForSearch != null && readFilter == null) { docFilter = recordFilterForSearch; } else if (recordFilterForSearch != null && readFilter != null) { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.add(recordFilterForSearch, Occur.MUST); booleanFilter.add(readFilter, Occur.MUST); docFilter = booleanFilter; } else { docFilter = null; } Query userQuery = QueryParserUtil.parseQuery(simpleQuery.query, simpleQuery.rowQuery, fieldManager, rowFilterForSearch, docFilter, getScoreType(simpleQuery.scoreType), context); Query facetedQuery; FacetExecutor executor = null; if (blurQuery.facets != null) { long[] facetMinimums = getFacetMinimums(blurQuery.facets); executor = new FacetExecutor(blurQuery.facets.size(), facetMinimums, facetedCounts, running); facetedQuery = new FacetQuery(userQuery, getFacetQueries(blurQuery, fieldManager, context, rowFilterForSearch, recordFilterForSearch), executor); } else { facetedQuery = userQuery; } Sort sort = getSort(blurQuery, fieldManager); call = new SimpleQueryParallelCall(running, table, status, facetedQuery, blurQuery.selector, _queriesInternalMeter, shardServerContext, runSlow, _fetchCount, _maxHeapPerRowFetch, context.getSimilarity(), context, sort, _deepPagingCache, _memoryAllocationWatcher); trace.done(); MergerBlurResultIterable merger = new MergerBlurResultIterable(blurQuery); BlurResultIterable merge = ForkJoin.execute(_executor, blurIndexes.entrySet(), call, new Cancel() { @Override public void cancel() { running.set(false); } }).merge(merger); if (executor != null) { executor.processFacets(_facetExecutor); } return fetchDataIfNeeded(merge, table, blurQuery.getSelector()); } catch (StopExecutionCollectorException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } catch (ExitingReaderException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } finally { _statusManager.removeStatus(status); } } }
IndexManager { public BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts) throws Exception { boolean runSlow = DEBUG_RUN_SLOW.get(); final AtomicBoolean running = new AtomicBoolean(true); User user = UserContext.getUser(); final QueryStatus status = _statusManager.newQueryStatus(table, blurQuery, _threadCount, running, UserConverter.toThriftUser(user)); _queriesExternalMeter.mark(); try { Map<String, BlurIndex> blurIndexes; try { blurIndexes = _indexServer.getIndexes(table); } catch (IOException e) { LOG.error("Unknown error while trying to fetch index readers.", e); throw new BException(e.getMessage(), e); } String rowId = blurQuery.getRowId(); if (rowId != null) { Map<String, BlurIndex> map = new HashMap<String, BlurIndex>(); String shard = MutationHelper.getShardName(table, rowId, getNumberOfShards(table), _blurPartitioner); BlurIndex index = getBlurIndex(table, shard); map.put(shard, index); blurIndexes = map; } Tracer trace = Trace.trace("query setup", Trace.param("table", table)); ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); ParallelCall<Entry<String, BlurIndex>, BlurResultIterable> call; TableContext context = getTableContext(table); FieldManager fieldManager = context.getFieldManager(); org.apache.blur.thrift.generated.Query simpleQuery = blurQuery.query; ReadInterceptor interceptor = context.getReadInterceptor(); Filter readFilter = interceptor.getFilter(); if (rowId != null) { if (simpleQuery.recordFilter == null) { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId; } else { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId + " +(" + simpleQuery.recordFilter + ")"; } } Filter recordFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.recordFilter, false, fieldManager, _filterCache, context); Filter rowFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.rowFilter, true, fieldManager, _filterCache, context); Filter docFilter; if (recordFilterForSearch == null && readFilter != null) { docFilter = readFilter; } else if (recordFilterForSearch != null && readFilter == null) { docFilter = recordFilterForSearch; } else if (recordFilterForSearch != null && readFilter != null) { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.add(recordFilterForSearch, Occur.MUST); booleanFilter.add(readFilter, Occur.MUST); docFilter = booleanFilter; } else { docFilter = null; } Query userQuery = QueryParserUtil.parseQuery(simpleQuery.query, simpleQuery.rowQuery, fieldManager, rowFilterForSearch, docFilter, getScoreType(simpleQuery.scoreType), context); Query facetedQuery; FacetExecutor executor = null; if (blurQuery.facets != null) { long[] facetMinimums = getFacetMinimums(blurQuery.facets); executor = new FacetExecutor(blurQuery.facets.size(), facetMinimums, facetedCounts, running); facetedQuery = new FacetQuery(userQuery, getFacetQueries(blurQuery, fieldManager, context, rowFilterForSearch, recordFilterForSearch), executor); } else { facetedQuery = userQuery; } Sort sort = getSort(blurQuery, fieldManager); call = new SimpleQueryParallelCall(running, table, status, facetedQuery, blurQuery.selector, _queriesInternalMeter, shardServerContext, runSlow, _fetchCount, _maxHeapPerRowFetch, context.getSimilarity(), context, sort, _deepPagingCache, _memoryAllocationWatcher); trace.done(); MergerBlurResultIterable merger = new MergerBlurResultIterable(blurQuery); BlurResultIterable merge = ForkJoin.execute(_executor, blurIndexes.entrySet(), call, new Cancel() { @Override public void cancel() { running.set(false); } }).merge(merger); if (executor != null) { executor.processFacets(_facetExecutor); } return fetchDataIfNeeded(merge, table, blurQuery.getSelector()); } catch (StopExecutionCollectorException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } catch (ExitingReaderException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } finally { _statusManager.removeStatus(status); } } IndexManager(IndexServer indexServer, ClusterStatus clusterStatus, BlurFilterCache filterCache,
      int maxHeapPerRowFetch, int fetchCount, int threadCount, int mutateThreadCount, int facetThreadCount,
      DeepPagingCache deepPagingCache, MemoryAllocationWatcher memoryAllocationWatcher, QueryStatusManager statusManager); }
IndexManager { public BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts) throws Exception { boolean runSlow = DEBUG_RUN_SLOW.get(); final AtomicBoolean running = new AtomicBoolean(true); User user = UserContext.getUser(); final QueryStatus status = _statusManager.newQueryStatus(table, blurQuery, _threadCount, running, UserConverter.toThriftUser(user)); _queriesExternalMeter.mark(); try { Map<String, BlurIndex> blurIndexes; try { blurIndexes = _indexServer.getIndexes(table); } catch (IOException e) { LOG.error("Unknown error while trying to fetch index readers.", e); throw new BException(e.getMessage(), e); } String rowId = blurQuery.getRowId(); if (rowId != null) { Map<String, BlurIndex> map = new HashMap<String, BlurIndex>(); String shard = MutationHelper.getShardName(table, rowId, getNumberOfShards(table), _blurPartitioner); BlurIndex index = getBlurIndex(table, shard); map.put(shard, index); blurIndexes = map; } Tracer trace = Trace.trace("query setup", Trace.param("table", table)); ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); ParallelCall<Entry<String, BlurIndex>, BlurResultIterable> call; TableContext context = getTableContext(table); FieldManager fieldManager = context.getFieldManager(); org.apache.blur.thrift.generated.Query simpleQuery = blurQuery.query; ReadInterceptor interceptor = context.getReadInterceptor(); Filter readFilter = interceptor.getFilter(); if (rowId != null) { if (simpleQuery.recordFilter == null) { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId; } else { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId + " +(" + simpleQuery.recordFilter + ")"; } } Filter recordFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.recordFilter, false, fieldManager, _filterCache, context); Filter rowFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.rowFilter, true, fieldManager, _filterCache, context); Filter docFilter; if (recordFilterForSearch == null && readFilter != null) { docFilter = readFilter; } else if (recordFilterForSearch != null && readFilter == null) { docFilter = recordFilterForSearch; } else if (recordFilterForSearch != null && readFilter != null) { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.add(recordFilterForSearch, Occur.MUST); booleanFilter.add(readFilter, Occur.MUST); docFilter = booleanFilter; } else { docFilter = null; } Query userQuery = QueryParserUtil.parseQuery(simpleQuery.query, simpleQuery.rowQuery, fieldManager, rowFilterForSearch, docFilter, getScoreType(simpleQuery.scoreType), context); Query facetedQuery; FacetExecutor executor = null; if (blurQuery.facets != null) { long[] facetMinimums = getFacetMinimums(blurQuery.facets); executor = new FacetExecutor(blurQuery.facets.size(), facetMinimums, facetedCounts, running); facetedQuery = new FacetQuery(userQuery, getFacetQueries(blurQuery, fieldManager, context, rowFilterForSearch, recordFilterForSearch), executor); } else { facetedQuery = userQuery; } Sort sort = getSort(blurQuery, fieldManager); call = new SimpleQueryParallelCall(running, table, status, facetedQuery, blurQuery.selector, _queriesInternalMeter, shardServerContext, runSlow, _fetchCount, _maxHeapPerRowFetch, context.getSimilarity(), context, sort, _deepPagingCache, _memoryAllocationWatcher); trace.done(); MergerBlurResultIterable merger = new MergerBlurResultIterable(blurQuery); BlurResultIterable merge = ForkJoin.execute(_executor, blurIndexes.entrySet(), call, new Cancel() { @Override public void cancel() { running.set(false); } }).merge(merger); if (executor != null) { executor.processFacets(_facetExecutor); } return fetchDataIfNeeded(merge, table, blurQuery.getSelector()); } catch (StopExecutionCollectorException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } catch (ExitingReaderException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } finally { _statusManager.removeStatus(status); } } IndexManager(IndexServer indexServer, ClusterStatus clusterStatus, BlurFilterCache filterCache,
      int maxHeapPerRowFetch, int fetchCount, int threadCount, int mutateThreadCount, int facetThreadCount,
      DeepPagingCache deepPagingCache, MemoryAllocationWatcher memoryAllocationWatcher, QueryStatusManager statusManager); synchronized void close(); List<FetchResult> fetchRowBatch(final String table, List<Selector> selectors); void fetchRow(String table, Selector selector, FetchResult fetchResult); static void populateSelector(IndexSearcherCloseable searcher, String shardName, String table, Selector selector); static void validSelector(Selector selector); BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts); String parseQuery(String table, org.apache.blur.thrift.generated.Query simpleQuery); void cancelQuery(String table, String uuid); List<BlurQueryStatus> currentQueries(String table); BlurQueryStatus queryStatus(String table, String uuid); List<String> queryStatusIdList(String table); static void fetchRow(IndexReader reader, String table, String shard, Selector selector,
      FetchResult fetchResult, Query highlightQuery, int maxHeap, TableContext tableContext, Filter filter); static void fetchRow(IndexReader reader, String table, String shard, Selector selector,
      FetchResult fetchResult, Query highlightQuery, FieldManager fieldManager, int maxHeap, TableContext tableContext,
      Filter filter); static ResetableDocumentStoredFieldVisitor getFieldSelector(final Selector selector); IndexServer getIndexServer(); long recordFrequency(final String table, final String columnFamily, final String columnName, final String value); List<String> terms(final String table, final String columnFamily, final String columnName,
      final String startWith, final short size); static long recordFrequency(IndexReader reader, String columnFamily, String columnName, String value); static List<String> terms(IndexReader reader, FieldTypeDefinition typeDef, String columnFamily,
      String columnName, String startWith, short size); void mutate(final RowMutation mutation); void mutate(final List<RowMutation> mutations); void enqueue(List<RowMutation> mutations); static boolean resetExitableReader(IndexReader indexReader, AtomicBoolean running); void optimize(String table, int numberOfSegmentsPerShard); void enqueue(RowMutation mutation); void bulkMutateAdd(String table, String bulkId, RowMutation mutation); void bulkMutateFinish(Set<String> potentialTables, String bulkId, boolean apply, boolean blockUntilComplete); void bulkMutateAddMultiple(String table, String bulkId, List<RowMutation> rowMutations); }
IndexManager { public BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts) throws Exception { boolean runSlow = DEBUG_RUN_SLOW.get(); final AtomicBoolean running = new AtomicBoolean(true); User user = UserContext.getUser(); final QueryStatus status = _statusManager.newQueryStatus(table, blurQuery, _threadCount, running, UserConverter.toThriftUser(user)); _queriesExternalMeter.mark(); try { Map<String, BlurIndex> blurIndexes; try { blurIndexes = _indexServer.getIndexes(table); } catch (IOException e) { LOG.error("Unknown error while trying to fetch index readers.", e); throw new BException(e.getMessage(), e); } String rowId = blurQuery.getRowId(); if (rowId != null) { Map<String, BlurIndex> map = new HashMap<String, BlurIndex>(); String shard = MutationHelper.getShardName(table, rowId, getNumberOfShards(table), _blurPartitioner); BlurIndex index = getBlurIndex(table, shard); map.put(shard, index); blurIndexes = map; } Tracer trace = Trace.trace("query setup", Trace.param("table", table)); ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); ParallelCall<Entry<String, BlurIndex>, BlurResultIterable> call; TableContext context = getTableContext(table); FieldManager fieldManager = context.getFieldManager(); org.apache.blur.thrift.generated.Query simpleQuery = blurQuery.query; ReadInterceptor interceptor = context.getReadInterceptor(); Filter readFilter = interceptor.getFilter(); if (rowId != null) { if (simpleQuery.recordFilter == null) { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId; } else { simpleQuery.recordFilter = "+" + BlurConstants.ROW_ID + ":" + rowId + " +(" + simpleQuery.recordFilter + ")"; } } Filter recordFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.recordFilter, false, fieldManager, _filterCache, context); Filter rowFilterForSearch = QueryParserUtil.parseFilter(table, simpleQuery.rowFilter, true, fieldManager, _filterCache, context); Filter docFilter; if (recordFilterForSearch == null && readFilter != null) { docFilter = readFilter; } else if (recordFilterForSearch != null && readFilter == null) { docFilter = recordFilterForSearch; } else if (recordFilterForSearch != null && readFilter != null) { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.add(recordFilterForSearch, Occur.MUST); booleanFilter.add(readFilter, Occur.MUST); docFilter = booleanFilter; } else { docFilter = null; } Query userQuery = QueryParserUtil.parseQuery(simpleQuery.query, simpleQuery.rowQuery, fieldManager, rowFilterForSearch, docFilter, getScoreType(simpleQuery.scoreType), context); Query facetedQuery; FacetExecutor executor = null; if (blurQuery.facets != null) { long[] facetMinimums = getFacetMinimums(blurQuery.facets); executor = new FacetExecutor(blurQuery.facets.size(), facetMinimums, facetedCounts, running); facetedQuery = new FacetQuery(userQuery, getFacetQueries(blurQuery, fieldManager, context, rowFilterForSearch, recordFilterForSearch), executor); } else { facetedQuery = userQuery; } Sort sort = getSort(blurQuery, fieldManager); call = new SimpleQueryParallelCall(running, table, status, facetedQuery, blurQuery.selector, _queriesInternalMeter, shardServerContext, runSlow, _fetchCount, _maxHeapPerRowFetch, context.getSimilarity(), context, sort, _deepPagingCache, _memoryAllocationWatcher); trace.done(); MergerBlurResultIterable merger = new MergerBlurResultIterable(blurQuery); BlurResultIterable merge = ForkJoin.execute(_executor, blurIndexes.entrySet(), call, new Cancel() { @Override public void cancel() { running.set(false); } }).merge(merger); if (executor != null) { executor.processFacets(_facetExecutor); } return fetchDataIfNeeded(merge, table, blurQuery.getSelector()); } catch (StopExecutionCollectorException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } catch (ExitingReaderException e) { BlurQueryStatus queryStatus = status.getQueryStatus(); QueryState state = queryStatus.getState(); if (state == QueryState.BACK_PRESSURE_INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.BACK_PRESSURE); } else if (state == QueryState.INTERRUPTED) { throw new BlurException("Cannot execute query right now.", null, ErrorType.QUERY_CANCEL); } throw e; } finally { _statusManager.removeStatus(status); } } IndexManager(IndexServer indexServer, ClusterStatus clusterStatus, BlurFilterCache filterCache,
      int maxHeapPerRowFetch, int fetchCount, int threadCount, int mutateThreadCount, int facetThreadCount,
      DeepPagingCache deepPagingCache, MemoryAllocationWatcher memoryAllocationWatcher, QueryStatusManager statusManager); synchronized void close(); List<FetchResult> fetchRowBatch(final String table, List<Selector> selectors); void fetchRow(String table, Selector selector, FetchResult fetchResult); static void populateSelector(IndexSearcherCloseable searcher, String shardName, String table, Selector selector); static void validSelector(Selector selector); BlurResultIterable query(final String table, final BlurQuery blurQuery, AtomicLongArray facetedCounts); String parseQuery(String table, org.apache.blur.thrift.generated.Query simpleQuery); void cancelQuery(String table, String uuid); List<BlurQueryStatus> currentQueries(String table); BlurQueryStatus queryStatus(String table, String uuid); List<String> queryStatusIdList(String table); static void fetchRow(IndexReader reader, String table, String shard, Selector selector,
      FetchResult fetchResult, Query highlightQuery, int maxHeap, TableContext tableContext, Filter filter); static void fetchRow(IndexReader reader, String table, String shard, Selector selector,
      FetchResult fetchResult, Query highlightQuery, FieldManager fieldManager, int maxHeap, TableContext tableContext,
      Filter filter); static ResetableDocumentStoredFieldVisitor getFieldSelector(final Selector selector); IndexServer getIndexServer(); long recordFrequency(final String table, final String columnFamily, final String columnName, final String value); List<String> terms(final String table, final String columnFamily, final String columnName,
      final String startWith, final short size); static long recordFrequency(IndexReader reader, String columnFamily, String columnName, String value); static List<String> terms(IndexReader reader, FieldTypeDefinition typeDef, String columnFamily,
      String columnName, String startWith, short size); void mutate(final RowMutation mutation); void mutate(final List<RowMutation> mutations); void enqueue(List<RowMutation> mutations); static boolean resetExitableReader(IndexReader indexReader, AtomicBoolean running); void optimize(String table, int numberOfSegmentsPerShard); void enqueue(RowMutation mutation); void bulkMutateAdd(String table, String bulkId, RowMutation mutation); void bulkMutateFinish(Set<String> potentialTables, String bulkId, boolean apply, boolean blockUntilComplete); void bulkMutateAddMultiple(String table, String bulkId, List<RowMutation> rowMutations); static final String NOT_FOUND; static AtomicBoolean DEBUG_RUN_SLOW; }