private static List<KeyValue> scan(TabletLocation loc, ScanState scanState, AccumuloConfiguration conf) throws AccumuloSecurityException,
NotServingTabletException, TException, NoSuchScanIDException, TooManyFilesException {
if (scanState.finished)
return null;
OpTimer opTimer = new OpTimer(log, Level.TRACE);
TInfo tinfo = Tracer.traceInfo();
TabletClientService.Client client = ThriftUtil.getTServerClient(loc.tablet_location, conf);
String old = Thread.currentThread().getName();
try {
ScanResult sr;
if (scanState.prevLoc != null && !scanState.prevLoc.equals(loc))
scanState.scanID = null;
scanState.prevLoc = loc;
if (scanState.scanID == null) {
String msg = "Starting scan tserver=" + loc.tablet_location + " tablet=" + loc.tablet_extent + " range=" + scanState.range + " ssil="
+ scanState.serverSideIteratorList + " ssio=" + scanState.serverSideIteratorOptions;
Thread.currentThread().setName(msg);
opTimer.start(msg);
TabletType ttype = TabletType.type(loc.tablet_extent);
boolean waitForWrites = !serversWaitedForWrites.get(ttype).contains(loc.tablet_location);
InitialScan is = client.startScan(tinfo, scanState.credentials, loc.tablet_extent.toThrift(), scanState.range.toThrift(),
Translator.translate(scanState.columns, Translator.CT), scanState.size, scanState.serverSideIteratorList, scanState.serverSideIteratorOptions,
scanState.authorizations.getAuthorizationsBB(), waitForWrites, scanState.isolated);
if (waitForWrites)
serversWaitedForWrites.get(ttype).add(loc.tablet_location);
sr = is.result;
if (sr.more)
scanState.scanID = is.scanID;
else
client.closeScan(tinfo, is.scanID);
} else {
// log.debug("Calling continue scan : "+scanState.range+" loc = "+loc);
String msg = "Continuing scan tserver=" + loc.tablet_location + " scanid=" + scanState.scanID;
Thread.currentThread().setName(msg);
opTimer.start(msg);
sr = client.continueScan(tinfo, scanState.scanID);
if (!sr.more) {
client.closeScan(tinfo, scanState.scanID);
scanState.scanID = null;
}
}
if (!sr.more) {
// log.debug("No more : tab end row = "+loc.tablet_extent.getEndRow()+" range = "+scanState.range);
if (loc.tablet_extent.getEndRow() == null) {
scanState.finished = true;
opTimer.stop("Completely finished scan in %DURATION% #results=" + sr.results.size());
} else if (scanState.range.getEndKey() == null || !scanState.range.afterEndKey(new Key(loc.tablet_extent.getEndRow()).followingKey(PartialKey.ROW))) {
scanState.startRow = loc.tablet_extent.getEndRow();
scanState.skipStartRow = true;
opTimer.stop("Finished scanning tablet in %DURATION% #results=" + sr.results.size());
} else {
scanState.finished = true;
opTimer.stop("Completely finished scan in %DURATION% #results=" + sr.results.size());
}
} else {
opTimer.stop("Finished scan in %DURATION% #results=" + sr.results.size() + " scanid=" + scanState.scanID);
}
Key.decompress(sr.results);
if (sr.results.size() > 0 && !scanState.finished)