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);
}
}
}