Search in sources :

Example 1 with ScanTask

use of org.apache.accumulo.tserver.scan.ScanTask 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)

Example 2 with ScanTask

use of org.apache.accumulo.tserver.scan.ScanTask in project accumulo by apache.

the class SessionManager method getActiveScansPerTable.

public Map<Table.ID, MapCounter<ScanRunState>> getActiveScansPerTable() {
    Map<Table.ID, MapCounter<ScanRunState>> counts = new HashMap<>();
    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();
        @SuppressWarnings("rawtypes") ScanTask nbt = null;
        Table.ID tableID = null;
        if (session instanceof ScanSession) {
            ScanSession ss = (ScanSession) session;
            nbt = ss.nextBatchTask;
            tableID = ss.extent.getTableId();
        } else if (session instanceof MultiScanSession) {
            MultiScanSession mss = (MultiScanSession) session;
            nbt = mss.lookupTask;
            tableID = mss.threadPoolExtent.getTableId();
        }
        if (nbt == null)
            continue;
        ScanRunState srs = nbt.getScanRunState();
        if (srs == ScanRunState.FINISHED)
            continue;
        MapCounter<ScanRunState> stateCounts = counts.get(tableID);
        if (stateCounts == null) {
            stateCounts = new MapCounter<>();
            counts.put(tableID, stateCounts);
        }
        stateCounts.increment(srs, 1);
    }
    return counts;
}
Also used : Table(org.apache.accumulo.core.client.impl.Table) ScanTask(org.apache.accumulo.tserver.scan.ScanTask) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Entry(java.util.Map.Entry) MapCounter(org.apache.accumulo.core.util.MapCounter) ScanRunState(org.apache.accumulo.tserver.scan.ScanRunState) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 ScanTask (org.apache.accumulo.tserver.scan.ScanTask)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Table (org.apache.accumulo.core.client.impl.Table)1 ActiveScan (org.apache.accumulo.core.tabletserver.thrift.ActiveScan)1 ScanState (org.apache.accumulo.core.tabletserver.thrift.ScanState)1 MapCounter (org.apache.accumulo.core.util.MapCounter)1 ScanRunState (org.apache.accumulo.tserver.scan.ScanRunState)1 ScanBatch (org.apache.accumulo.tserver.tablet.ScanBatch)1