Map<String, BlurIndex> blurIndexes = _indexServer.getIndexes(table);
if (blurIndexes == null) {
LOG.error("Table [{0}] not found", table);
// @TODO probably should make a enum for not found on this server so the
// controller knows to try another server.
throw new BException("Table [" + table + "] not found");
}
index = blurIndexes.get(shard);
if (index == null) {
LOG.error("Shard [{0}] not found in table [{1}]", shard, table);
// @TODO probably should make a enum for not found on this server so the
// controller knows to try another server.
throw new BException("Shard [" + shard + "] not found in table [" + table + "]");
}
} 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);
}
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