Search in sources :

Example 1 with SingleScanSession

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);
    }
}
Also used : SingleScanSession(org.apache.accumulo.tserver.session.SingleScanSession)

Example 2 with SingleScanSession

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);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Authorizations(org.apache.accumulo.core.security.Authorizations) ScanResult(org.apache.accumulo.core.dataImpl.thrift.ScanResult) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) Range(org.apache.accumulo.core.data.Range) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) InitialScan(org.apache.accumulo.core.dataImpl.thrift.InitialScan) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Column(org.apache.accumulo.core.data.Column) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) ScanParameters(org.apache.accumulo.tserver.scan.ScanParameters) Tablet(org.apache.accumulo.tserver.tablet.Tablet) NamespaceId(org.apache.accumulo.core.data.NamespaceId) SingleScanSession(org.apache.accumulo.tserver.session.SingleScanSession) HashSet(java.util.HashSet)

Example 3 with SingleScanSession

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);
    }
}
Also used : TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) IOException(java.io.IOException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ScanBatch(org.apache.accumulo.tserver.tablet.ScanBatch) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) Tablet(org.apache.accumulo.tserver.tablet.Tablet) SingleScanSession(org.apache.accumulo.tserver.session.SingleScanSession)

Aggregations

SingleScanSession (org.apache.accumulo.tserver.session.SingleScanSession)3 Tablet (org.apache.accumulo.tserver.tablet.Tablet)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)1 Column (org.apache.accumulo.core.data.Column)1 NamespaceId (org.apache.accumulo.core.data.NamespaceId)1 Range (org.apache.accumulo.core.data.Range)1 TableId (org.apache.accumulo.core.data.TableId)1 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)1 InitialScan (org.apache.accumulo.core.dataImpl.thrift.InitialScan)1 MultiScanResult (org.apache.accumulo.core.dataImpl.thrift.MultiScanResult)1 ScanResult (org.apache.accumulo.core.dataImpl.thrift.ScanResult)1 TColumn (org.apache.accumulo.core.dataImpl.thrift.TColumn)1 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)1 TRange (org.apache.accumulo.core.dataImpl.thrift.TRange)1 TRowRange (org.apache.accumulo.core.dataImpl.thrift.TRowRange)1 IterationInterruptedException (org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException)1