Search in sources :

Example 1 with ScanResult

use of org.apache.accumulo.core.dataImpl.thrift.ScanResult in project accumulo by apache.

the class ThriftClientHandler method continueScan.

private ScanResult continueScan(TInfo tinfo, long scanID, SingleScanSession scanSession) throws NoSuchScanIDException, NotServingTabletException, org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException, TSampleNotPresentException {
    if (scanSession.nextBatchTask == null) {
        scanSession.nextBatchTask = new NextBatchTask(server, scanID, scanSession.interruptFlag);
        server.resourceManager.executeReadAhead(scanSession.extent, getScanDispatcher(scanSession.extent), scanSession, scanSession.nextBatchTask);
    }
    ScanBatch bresult;
    try {
        bresult = scanSession.nextBatchTask.get(MAX_TIME_TO_WAIT_FOR_SCAN_RESULT_MILLIS, TimeUnit.MILLISECONDS);
        scanSession.nextBatchTask = null;
    } catch (ExecutionException e) {
        server.sessionManager.removeSession(scanID);
        if (e.getCause() instanceof NotServingTabletException) {
            throw (NotServingTabletException) e.getCause();
        } else if (e.getCause() instanceof TooManyFilesException) {
            throw new org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException(scanSession.extent.toThrift());
        } else if (e.getCause() instanceof SampleNotPresentException) {
            throw new TSampleNotPresentException(scanSession.extent.toThrift());
        } else if (e.getCause() instanceof IOException) {
            sleepUninterruptibly(MAX_TIME_TO_WAIT_FOR_SCAN_RESULT_MILLIS, TimeUnit.MILLISECONDS);
            List<KVEntry> empty = Collections.emptyList();
            bresult = new ScanBatch(empty, true);
            scanSession.nextBatchTask = null;
        } else {
            throw new RuntimeException(e);
        }
    } catch (CancellationException ce) {
        server.sessionManager.removeSession(scanID);
        Tablet tablet = server.getOnlineTablet(scanSession.extent);
        if (tablet == null || tablet.isClosed()) {
            throw new NotServingTabletException(scanSession.extent.toThrift());
        } else {
            throw new NoSuchScanIDException();
        }
    } catch (TimeoutException e) {
        List<TKeyValue> param = Collections.emptyList();
        long timeout = server.getConfiguration().getTimeInMillis(Property.TSERV_CLIENT_TIMEOUT);
        server.sessionManager.removeIfNotAccessed(scanID, timeout);
        return new ScanResult(param, true);
    } catch (Exception t) {
        server.sessionManager.removeSession(scanID);
        log.warn("Failed to get next batch", t);
        throw new RuntimeException(t);
    }
    ScanResult scanResult = new ScanResult(Key.compress(bresult.getResults()), bresult.isMore());
    scanSession.entriesReturned += scanResult.results.size();
    scanSession.batchCount++;
    if (scanResult.more && scanSession.batchCount > scanSession.readaheadThreshold) {
        // start reading next batch while current batch is transmitted
        // to client
        scanSession.nextBatchTask = new NextBatchTask(server, scanID, scanSession.interruptFlag);
        server.resourceManager.executeReadAhead(scanSession.extent, getScanDispatcher(scanSession.extent), scanSession, scanSession.nextBatchTask);
    }
    if (!scanResult.more) {
        closeScan(tinfo, scanID);
    }
    return scanResult;
}
Also used : ScanResult(org.apache.accumulo.core.dataImpl.thrift.ScanResult) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) IOException(java.io.IOException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) CancellationException(java.util.concurrent.CancellationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TimeoutException(java.util.concurrent.TimeoutException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) CancellationException(java.util.concurrent.CancellationException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ScanBatch(org.apache.accumulo.tserver.tablet.ScanBatch) Tablet(org.apache.accumulo.tserver.tablet.Tablet) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NextBatchTask(org.apache.accumulo.tserver.scan.NextBatchTask) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ScanResult

use of org.apache.accumulo.core.dataImpl.thrift.ScanResult 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 ScanResult

use of org.apache.accumulo.core.dataImpl.thrift.ScanResult in project accumulo by apache.

the class ThriftScanner method scan.

private static List<KeyValue> scan(TabletLocation loc, ScanState scanState, ClientContext context) throws AccumuloSecurityException, NotServingTabletException, TException, NoSuchScanIDException, TooManyFilesException, TSampleNotPresentException {
    if (scanState.finished)
        return null;
    OpTimer timer = null;
    final TInfo tinfo = TraceUtil.traceInfo();
    final HostAndPort parsedLocation = HostAndPort.fromString(loc.tablet_location);
    TabletClientService.Client client = ThriftUtil.getTServerClient(parsedLocation, context);
    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) {
            Thread.currentThread().setName("Starting scan tserver=" + loc.tablet_location + " tableId=" + loc.tablet_extent.tableId());
            if (log.isTraceEnabled()) {
                String msg = "Starting scan tserver=" + loc.tablet_location + " tablet=" + loc.tablet_extent + " range=" + scanState.range + " ssil=" + scanState.serverSideIteratorList + " ssio=" + scanState.serverSideIteratorOptions + " context=" + scanState.classLoaderContext;
                log.trace("tid={} {}", Thread.currentThread().getId(), msg);
                timer = new OpTimer().start();
            }
            TabletType ttype = TabletType.type(loc.tablet_extent);
            boolean waitForWrites = !serversWaitedForWrites.get(ttype).contains(loc.tablet_location);
            InitialScan is = client.startScan(tinfo, scanState.context.rpcCreds(), loc.tablet_extent.toThrift(), scanState.range.toThrift(), scanState.columns.stream().map(Column::toThrift).collect(Collectors.toList()), scanState.size, scanState.serverSideIteratorList, scanState.serverSideIteratorOptions, scanState.authorizations.getAuthorizationsBB(), waitForWrites, scanState.isolated, scanState.readaheadThreshold, SamplerConfigurationImpl.toThrift(scanState.samplerConfig), scanState.batchTimeOut, scanState.classLoaderContext, scanState.executionHints);
            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);
            if (log.isTraceEnabled()) {
                log.trace("tid={} {}", Thread.currentThread().getId(), msg);
                timer = new OpTimer().start();
            }
            sr = client.continueScan(tinfo, scanState.scanID);
            if (!sr.more) {
                client.closeScan(tinfo, scanState.scanID);
                scanState.scanID = null;
            }
        }
        if (sr.more) {
            if (timer != null) {
                timer.stop();
                log.trace("tid={} Finished scan in {} #results={} scanid={}", Thread.currentThread().getId(), String.format("%.3f secs", timer.scale(SECONDS)), sr.results.size(), scanState.scanID);
            }
        } else {
            // "+scanState.range);
            if (loc.tablet_extent.endRow() == null) {
                scanState.finished = true;
                if (timer != null) {
                    timer.stop();
                    log.trace("tid={} Completely finished scan in {} #results={}", Thread.currentThread().getId(), String.format("%.3f secs", timer.scale(SECONDS)), sr.results.size());
                }
            } else if (scanState.range.getEndKey() == null || !scanState.range.afterEndKey(new Key(loc.tablet_extent.endRow()).followingKey(PartialKey.ROW))) {
                scanState.startRow = loc.tablet_extent.endRow();
                scanState.skipStartRow = true;
                if (timer != null) {
                    timer.stop();
                    log.trace("tid={} Finished scanning tablet in {} #results={}", Thread.currentThread().getId(), String.format("%.3f secs", timer.scale(SECONDS)), sr.results.size());
                }
            } else {
                scanState.finished = true;
                if (timer != null) {
                    timer.stop();
                    log.trace("tid={} Completely finished in {} #results={}", Thread.currentThread().getId(), String.format("%.3f secs", timer.scale(SECONDS)), sr.results.size());
                }
            }
        }
        Key.decompress(sr.results);
        if (!sr.results.isEmpty() && !scanState.finished)
            scanState.range = new Range(new Key(sr.results.get(sr.results.size() - 1).key), false, scanState.range.getEndKey(), scanState.range.isEndKeyInclusive());
        List<KeyValue> results = new ArrayList<>(sr.results.size());
        for (TKeyValue tkv : sr.results) results.add(new KeyValue(new Key(tkv.key), tkv.value));
        return results;
    } catch (ThriftSecurityException e) {
        throw new AccumuloSecurityException(e.user, e.code, e);
    } finally {
        ThriftUtil.returnClient(client, context);
        Thread.currentThread().setName(old);
    }
}
Also used : TInfo(org.apache.accumulo.core.trace.thrift.TInfo) ScanResult(org.apache.accumulo.core.dataImpl.thrift.ScanResult) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) KeyValue(org.apache.accumulo.core.data.KeyValue) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) InitialScan(org.apache.accumulo.core.dataImpl.thrift.InitialScan) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Column(org.apache.accumulo.core.data.Column) OpTimer(org.apache.accumulo.core.util.OpTimer) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)3 ScanResult (org.apache.accumulo.core.dataImpl.thrift.ScanResult)3 ArrayList (java.util.ArrayList)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 Column (org.apache.accumulo.core.data.Column)2 Range (org.apache.accumulo.core.data.Range)2 InitialScan (org.apache.accumulo.core.dataImpl.thrift.InitialScan)2 MultiScanResult (org.apache.accumulo.core.dataImpl.thrift.MultiScanResult)2 NoSuchScanIDException (org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException)2 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)2 Tablet (org.apache.accumulo.tserver.tablet.Tablet)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors.toList (java.util.stream.Collectors.toList)1 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)1