use of org.apache.accumulo.tserver.session.SingleScanSession in project accumulo by apache.
the class ThriftClientHandler method closeScan.
@Override
public void closeScan(TInfo tinfo, long scanID) {
final SingleScanSession ss = (SingleScanSession) server.sessionManager.removeSession(scanID);
if (ss != null) {
long t2 = System.currentTimeMillis();
if (log.isTraceEnabled()) {
log.trace(String.format("ScanSess tid %s %s %,d entries in %.2f secs, nbTimes = [%s] ", TServerUtils.clientAddress.get(), ss.extent.tableId(), ss.entriesReturned, (t2 - ss.startTime) / 1000.0, ss.runStats.toString()));
}
server.scanMetrics.addScan(t2 - ss.startTime);
server.scanMetrics.addResult(ss.entriesReturned);
}
}
use of org.apache.accumulo.tserver.session.SingleScanSession in project accumulo by apache.
the class ThriftClientHandler method startScan.
@Override
public InitialScan startScan(TInfo tinfo, TCredentials credentials, TKeyExtent textent, TRange range, List<TColumn> columns, int batchSize, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations, boolean waitForWrites, boolean isolated, long readaheadThreshold, TSamplerConfiguration tSamplerConfig, long batchTimeOut, String contextArg, Map<String, String> executionHints) throws NotServingTabletException, ThriftSecurityException, org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException, TSampleNotPresentException {
TableId tableId = TableId.of(new String(textent.getTable(), UTF_8));
NamespaceId namespaceId;
try {
namespaceId = server.getContext().getNamespaceId(tableId);
} catch (TableNotFoundException e1) {
throw new NotServingTabletException(textent);
}
if (!security.canScan(credentials, tableId, namespaceId, range, columns, ssiList, ssio, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
if (!security.authenticatedUserHasAuthorizations(credentials, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
}
final KeyExtent extent = KeyExtent.fromThrift(textent);
// metadata
if (waitForWrites) {
writeTracker.waitForWrites(TabletType.type(extent));
}
Tablet tablet = server.getOnlineTablet(extent);
if (tablet == null) {
throw new NotServingTabletException(textent);
}
HashSet<Column> columnSet = new HashSet<>();
for (TColumn tcolumn : columns) {
columnSet.add(new Column(tcolumn));
}
ScanParameters scanParams = new ScanParameters(batchSize, new Authorizations(authorizations), columnSet, ssiList, ssio, isolated, SamplerConfigurationImpl.fromThrift(tSamplerConfig), batchTimeOut, contextArg);
final SingleScanSession scanSession = new SingleScanSession(credentials, extent, scanParams, readaheadThreshold, executionHints);
scanSession.scanner = tablet.createScanner(new Range(range), scanParams, scanSession.interruptFlag);
long sid = server.sessionManager.createSession(scanSession, true);
ScanResult scanResult;
try {
scanResult = continueScan(tinfo, sid, scanSession);
} catch (NoSuchScanIDException e) {
log.error("The impossible happened", e);
throw new RuntimeException();
} finally {
server.sessionManager.unreserveSession(sid);
}
return new InitialScan(sid, scanResult);
}
use of org.apache.accumulo.tserver.session.SingleScanSession in project accumulo by apache.
the class NextBatchTask method run.
@Override
public void run() {
final SingleScanSession scanSession = (SingleScanSession) server.getSession(scanID);
String oldThreadName = Thread.currentThread().getName();
try {
if (isCancelled() || scanSession == null)
return;
runState.set(ScanRunState.RUNNING);
Thread.currentThread().setName("User: " + scanSession.getUser() + " Start: " + scanSession.startTime + " Client: " + scanSession.client + " Tablet: " + scanSession.extent);
Tablet tablet = server.getOnlineTablet(scanSession.extent);
if (tablet == null) {
addResult(new org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException(scanSession.extent.toThrift()));
return;
}
ScanBatch batch = scanSession.scanner.read();
// there should only be one thing on the queue at a time, so
// it should be ok to call add()
// instead of put()... if add() fails because queue is at
// capacity it means there is code
// problem somewhere
addResult(batch);
} catch (TabletClosedException e) {
addResult(new org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException(scanSession.extent.toThrift()));
} catch (IterationInterruptedException iie) {
if (!isCancelled()) {
log.warn("Iteration interrupted, when scan not cancelled", iie);
addResult(iie);
}
} catch (TooManyFilesException | SampleNotPresentException e) {
addResult(e);
} catch (IOException | RuntimeException e) {
log.warn("exception while scanning tablet {} for {}", scanSession.extent, scanSession.client, e);
addResult(e);
} finally {
runState.set(ScanRunState.FINISHED);
Thread.currentThread().setName(oldThreadName);
}
}
Aggregations