Search in sources :

Example 1 with ActiveScan

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

use of org.apache.accumulo.core.tabletserver.thrift.ActiveScan in project accumulo by apache.

the class Monitor method fetchScans.

public static void fetchScans() throws Exception {
    if (instance == null)
        return;
    Connector c = context.getConnector();
    for (String server : c.instanceOperations().getTabletServers()) {
        final HostAndPort parsedServer = HostAndPort.fromString(server);
        Client tserver = ThriftUtil.getTServerClient(parsedServer, context);
        try {
            List<ActiveScan> scans = tserver.getActiveScans(null, context.rpcCreds());
            synchronized (allScans) {
                allScans.put(parsedServer, new ScanStats(scans));
            }
        } catch (Exception ex) {
            log.debug("Failed to get active scans from {}", server, ex);
        } finally {
            ThriftUtil.returnClient(tserver);
        }
    }
    // Age off old scan information
    Iterator<Entry<HostAndPort, ScanStats>> entryIter = allScans.entrySet().iterator();
    long now = System.currentTimeMillis();
    while (entryIter.hasNext()) {
        Entry<HostAndPort, ScanStats> entry = entryIter.next();
        if (now - entry.getValue().fetched > 5 * 60 * 1000) {
            entryIter.remove();
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Entry(java.util.Map.Entry) ActiveScan(org.apache.accumulo.core.tabletserver.thrift.ActiveScan) MasterClient(org.apache.accumulo.core.client.impl.MasterClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException)

Aggregations

Entry (java.util.Map.Entry)2 ActiveScan (org.apache.accumulo.core.tabletserver.thrift.ActiveScan)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Connector (org.apache.accumulo.core.client.Connector)1 MasterClient (org.apache.accumulo.core.client.impl.MasterClient)1 ScanState (org.apache.accumulo.core.tabletserver.thrift.ScanState)1 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)1 HostAndPort (org.apache.accumulo.core.util.HostAndPort)1 ScanTask (org.apache.accumulo.tserver.scan.ScanTask)1 ScanBatch (org.apache.accumulo.tserver.tablet.ScanBatch)1 KeeperException (org.apache.zookeeper.KeeperException)1