Search in sources :

Example 1 with ScanBatch

use of org.apache.accumulo.tserver.tablet.ScanBatch in project accumulo by apache.

the class NextBatchTask method run.

@Override
public void run() {
    final ScanSession scanSession = (ScanSession) 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;
        }
        long t1 = System.currentTimeMillis();
        ScanBatch batch = scanSession.scanner.read();
        long t2 = System.currentTimeMillis();
        scanSession.nbTimes.addStat(t2 - t1);
        // 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 (OutOfMemoryError ome) {
        Halt.halt("Ran out of memory scanning " + scanSession.extent + " for " + scanSession.client, 1);
        addResult(ome);
    } catch (Throwable e) {
        log.warn("exception while scanning tablet " + (scanSession == null ? "(unknown)" : scanSession.extent), e);
        addResult(e);
    } finally {
        runState.set(ScanRunState.FINISHED);
        Thread.currentThread().setName(oldThreadName);
    }
}
Also used : TooManyFilesException(org.apache.accumulo.tserver.TooManyFilesException) 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.iterators.IterationInterruptedException) Tablet(org.apache.accumulo.tserver.tablet.Tablet) ScanSession(org.apache.accumulo.tserver.session.ScanSession)

Example 2 with ScanBatch

use of org.apache.accumulo.tserver.tablet.ScanBatch in project accumulo by apache.

the class SessionManager method getActiveScans.

public List<ActiveScan> getActiveScans() {
    final List<ActiveScan> activeScans = new ArrayList<>();
    final long ct = System.currentTimeMillis();
    final Set<Entry<Long, Session>> copiedIdleSessions = new HashSet<>();
    synchronized (idleSessions) {
        /**
         * Add sessions so that get the list returned in the active scans call
         */
        for (Session session : idleSessions) {
            copiedIdleSessions.add(Maps.immutableEntry(expiredSessionMarker, session));
        }
    }
    for (Entry<Long, Session> entry : Iterables.concat(sessions.entrySet(), copiedIdleSessions)) {
        Session session = entry.getValue();
        if (session instanceof ScanSession) {
            ScanSession ss = (ScanSession) session;
            ScanState state = ScanState.RUNNING;
            ScanTask<ScanBatch> nbt = ss.nextBatchTask;
            if (nbt == null) {
                state = ScanState.IDLE;
            } else {
                switch(nbt.getScanRunState()) {
                    case QUEUED:
                        state = ScanState.QUEUED;
                        break;
                    case FINISHED:
                        state = ScanState.IDLE;
                        break;
                    case RUNNING:
                    default:
                        /* do nothing */
                        break;
                }
            }
            ActiveScan activeScan = new ActiveScan(ss.client, ss.getUser(), ss.extent.getTableId().canonicalID(), ct - ss.startTime, ct - ss.lastAccessTime, ScanType.SINGLE, state, ss.extent.toThrift(), Translator.translate(ss.columnSet, Translators.CT), ss.ssiList, ss.ssio, ss.auths.getAuthorizationsBB(), ss.context);
            // scanId added by ACCUMULO-2641 is an optional thrift argument and not available in ActiveScan constructor
            activeScan.setScanId(entry.getKey());
            activeScans.add(activeScan);
        } else if (session instanceof MultiScanSession) {
            MultiScanSession mss = (MultiScanSession) session;
            ScanState state = ScanState.RUNNING;
            ScanTask<MultiScanResult> nbt = mss.lookupTask;
            if (nbt == null) {
                state = ScanState.IDLE;
            } else {
                switch(nbt.getScanRunState()) {
                    case QUEUED:
                        state = ScanState.QUEUED;
                        break;
                    case FINISHED:
                        state = ScanState.IDLE;
                        break;
                    case RUNNING:
                    default:
                        /* do nothing */
                        break;
                }
            }
            activeScans.add(new ActiveScan(mss.client, mss.getUser(), mss.threadPoolExtent.getTableId().canonicalID(), ct - mss.startTime, ct - mss.lastAccessTime, ScanType.BATCH, state, mss.threadPoolExtent.toThrift(), Translator.translate(mss.columnSet, Translators.CT), mss.ssiList, mss.ssio, mss.auths.getAuthorizationsBB(), mss.context));
        }
    }
    return activeScans;
}
Also used : ScanTask(org.apache.accumulo.tserver.scan.ScanTask) ActiveScan(org.apache.accumulo.core.tabletserver.thrift.ActiveScan) ArrayList(java.util.ArrayList) ScanState(org.apache.accumulo.core.tabletserver.thrift.ScanState) Entry(java.util.Map.Entry) ScanBatch(org.apache.accumulo.tserver.tablet.ScanBatch) HashSet(java.util.HashSet)

Aggregations

ScanBatch (org.apache.accumulo.tserver.tablet.ScanBatch)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)1 IterationInterruptedException (org.apache.accumulo.core.iterators.IterationInterruptedException)1 ActiveScan (org.apache.accumulo.core.tabletserver.thrift.ActiveScan)1 ScanState (org.apache.accumulo.core.tabletserver.thrift.ScanState)1 TooManyFilesException (org.apache.accumulo.tserver.TooManyFilesException)1 ScanTask (org.apache.accumulo.tserver.scan.ScanTask)1 ScanSession (org.apache.accumulo.tserver.session.ScanSession)1 Tablet (org.apache.accumulo.tserver.tablet.Tablet)1 TabletClosedException (org.apache.accumulo.tserver.tablet.TabletClosedException)1