Search in sources :

Example 1 with StoreStats

use of io.dingodb.store.row.metadata.StoreStats in project dingo by dingodb.

the class StoreHeartbeatSender method sendStoreHeartbeat.

private void sendStoreHeartbeat(final long nextDelay, final boolean forceRefreshLeader, final long lastTime) {
    final long now = System.currentTimeMillis();
    final StoreHeartbeatRequest request = new StoreHeartbeatRequest();
    request.setClusterId(this.storeEngine.getClusterId());
    final TimeInterval timeInterval = new TimeInterval(lastTime, now);
    final StoreStats stats = this.statsCollector.collectStoreStats(timeInterval);
    request.setStats(stats);
    final HeartbeatClosure<Object> closure = new HeartbeatClosure<Object>() {

        @Override
        public void run(final Status status) {
            final boolean forceRefresh = !status.isOk() && ErrorsHelper.isInvalidPeer(getError());
            final StoreHeartbeatTask nexTask = new StoreHeartbeatTask(nextDelay, now, forceRefresh);
            heartbeatTimer.newTimeout(nexTask, nexTask.getNextDelay(), TimeUnit.SECONDS);
        }
    };
    final Endpoint endpoint = this.pdClient.getPdLeader(forceRefreshLeader, this.heartbeatRpcTimeoutMillis);
    callAsyncWithRpc(endpoint, request, closure);
}
Also used : StoreHeartbeatRequest(io.dingodb.store.row.cmd.pd.StoreHeartbeatRequest) Status(io.dingodb.raft.Status) StoreStats(io.dingodb.store.row.metadata.StoreStats) TimeInterval(io.dingodb.store.row.metadata.TimeInterval) Endpoint(io.dingodb.raft.util.Endpoint)

Example 2 with StoreStats

use of io.dingodb.store.row.metadata.StoreStats in project dingo by dingodb.

the class StoreHeartbeatSender method sendStoreHeartbeat.

private void sendStoreHeartbeat(final long nextDelay, final boolean forceRefreshLeader, final long lastTime) {
    final long now = System.currentTimeMillis();
    final StoreHeartbeatRequest request = new StoreHeartbeatRequest();
    request.setClusterId(this.storeEngine.getClusterId());
    final TimeInterval timeInterval = new TimeInterval(lastTime, now);
    final StoreStats stats = this.statsCollector.collectStoreStats(timeInterval);
    stats.setLocation(CURRENT_LOCATION);
    request.setStats(stats);
    final HeartbeatClosure<Object> closure = new HeartbeatClosure<Object>() {

        @Override
        public void run(final Status status) {
            final boolean forceRefresh = !status.isOk() && ErrorsHelper.isInvalidPeer(getError());
            final StoreHeartbeatTask nexTask = new StoreHeartbeatTask(nextDelay, now, forceRefresh);
            heartbeatTimer.newTimeout(nexTask, nexTask.getNextDelay(), TimeUnit.SECONDS);
        }
    };
    final Endpoint endpoint = this.pdClient.getPdLeader(forceRefreshLeader, this.heartbeatRpcTimeoutMillis);
    callAsyncWithRpc(endpoint, request, closure);
}
Also used : StoreHeartbeatRequest(io.dingodb.store.row.cmd.pd.StoreHeartbeatRequest) Status(io.dingodb.raft.Status) StoreStats(io.dingodb.store.row.metadata.StoreStats) TimeInterval(io.dingodb.store.row.metadata.TimeInterval) Endpoint(io.dingodb.raft.util.Endpoint)

Example 3 with StoreStats

use of io.dingodb.store.row.metadata.StoreStats in project dingo by dingodb.

the class StatsCollector method collectStoreStats.

public StoreStats collectStoreStats(final TimeInterval timeInterval) {
    final StoreStats stats = new StoreStats();
    stats.setStoreId(this.storeEngine.getStoreId());
    // Capacity for the store
    stats.setCapacity(this.storeEngine.getTotalSpace());
    // Available size for the store
    stats.setAvailable(this.storeEngine.getUsableSpace());
    // Total region count in this store
    stats.setRegionCount(this.storeEngine.getRegionCount());
    // Leader region count in this store
    stats.setLeaderRegionCount(this.storeEngine.getLeaderRegionCount());
    // Current sending snapshot count
    // TODO
    // Current receiving snapshot count
    // TODO
    // How many region is applying snapshot
    // TODO
    // When the store is started (unix timestamp in milliseconds)
    stats.setStartTime(this.storeEngine.getStartTime());
    // If the store is busy
    stats.setBusy(this.storeEngine.isBusy());
    // Actually used space by db
    stats.setUsedSize(this.storeEngine.getStoreUsedSpace());
    // Bytes written for the store during this period
    stats.setBytesWritten(getStoreBytesWritten(true));
    // Bytes read for the store during this period
    stats.setBytesRead(getStoreBytesRead(true));
    // Keys written for the store during this period
    stats.setKeysWritten(getStoreKeysWritten(true));
    // Keys read for the store during this period
    stats.setKeysRead(getStoreKeysRead(true));
    // Actually reported time interval
    stats.setInterval(timeInterval);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Collect [StoreStats]: {}.", stats);
    }
    return stats;
}
Also used : StoreStats(io.dingodb.store.row.metadata.StoreStats)

Example 4 with StoreStats

use of io.dingodb.store.row.metadata.StoreStats in project dingo by dingodb.

the class RegionHeartbeatHandler method tryToFindLaziestWorker.

private Pair<String, Integer> tryToFindLaziestWorker(final List<Pair<String, Integer>> lazyWorkers) {
    final List<Pair<Pair<String, Integer>, StoreStats>> storeStatsList = Lists.newArrayList();
    for (final Pair<String, Integer> worker : lazyWorkers) {
        final StoreStats stats = rowStoreMetaAdaptor.storeStats(GeneralId.fromStr(worker.getKey()));
        if (stats != null) {
            // TODO check timeInterval
            storeStatsList.add(Pair.of(worker, stats));
        }
    }
    if (storeStatsList.isEmpty()) {
        return null;
    }
    if (storeStatsList.size() == 1) {
        return storeStatsList.get(0).getKey();
    }
    final Pair<Pair<String, Integer>, StoreStats> min = Collections.min(storeStatsList, (o1, o2) -> {
        final StoreStats s1 = o1.getValue();
        final StoreStats s2 = o2.getValue();
        int val = Boolean.compare(s1.isBusy(), s2.isBusy());
        if (val != 0) {
            return val;
        }
        val = Integer.compare(s1.getRegionCount(), s2.getRegionCount());
        if (val != 0) {
            return val;
        }
        val = Long.compare(s1.getBytesWritten(), s2.getBytesWritten());
        if (val != 0) {
            return val;
        }
        val = Long.compare(s1.getBytesRead(), s2.getBytesRead());
        if (val != 0) {
            return val;
        }
        val = Long.compare(s1.getKeysWritten(), s2.getKeysWritten());
        if (val != 0) {
            return val;
        }
        val = Long.compare(s1.getKeysRead(), s2.getKeysRead());
        if (val != 0) {
            return val;
        }
        return Long.compare(-s1.getAvailable(), -s2.getAvailable());
    });
    return min.getKey();
}
Also used : StoreStats(io.dingodb.store.row.metadata.StoreStats) Endpoint(io.dingodb.raft.util.Endpoint) Pair(io.dingodb.store.row.util.Pair)

Aggregations

StoreStats (io.dingodb.store.row.metadata.StoreStats)4 Endpoint (io.dingodb.raft.util.Endpoint)3 Status (io.dingodb.raft.Status)2 StoreHeartbeatRequest (io.dingodb.store.row.cmd.pd.StoreHeartbeatRequest)2 TimeInterval (io.dingodb.store.row.metadata.TimeInterval)2 Pair (io.dingodb.store.row.util.Pair)1