Search in sources :

Example 1 with StoreHeartbeatRequest

use of com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest in project sofa-jraft by sofastack.

the class StoreStatsPersistenceHandler method readMessage.

@Override
public void readMessage(final HandlerContext ctx, final StorePingEvent event) throws Exception {
    final MetadataStore metadataStore = event.getMetadataStore();
    final StoreHeartbeatRequest request = event.getMessage();
    // sync
    metadataStore.updateStoreStats(request.getClusterId(), request.getStats()).get();
}
Also used : MetadataStore(com.alipay.sofa.jraft.rhea.MetadataStore) StoreHeartbeatRequest(com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest)

Example 2 with StoreHeartbeatRequest

use of com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest in project sofa-jraft by sofastack.

the class StoreStatsValidator method readMessage.

@Override
public void readMessage(final HandlerContext ctx, final StorePingEvent event) throws Exception {
    final MetadataStore metadataStore = event.getMetadataStore();
    final StoreHeartbeatRequest request = event.getMessage();
    final StoreStats storeStats = request.getStats();
    if (storeStats == null) {
        LOG.error("Empty [StoreStats] by event: {}.", event);
        throw Errors.INVALID_STORE_STATS.exception();
    }
    final StoreStats currentStoreStats = metadataStore.getStoreStats(request.getClusterId(), storeStats.getStoreId());
    if (currentStoreStats == null) {
        // new data
        return;
    }
    final TimeInterval interval = storeStats.getInterval();
    if (interval == null) {
        LOG.error("Empty [TimeInterval] by event: {}.", event);
        throw Errors.INVALID_STORE_STATS.exception();
    }
    final TimeInterval currentInterval = currentStoreStats.getInterval();
    if (interval.getEndTimestamp() < currentInterval.getEndTimestamp()) {
        LOG.error("The [TimeInterval] is out of date: {}.", event);
        throw Errors.STORE_HEARTBEAT_OUT_OF_DATE.exception();
    }
}
Also used : MetadataStore(com.alipay.sofa.jraft.rhea.MetadataStore) StoreHeartbeatRequest(com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest) StoreStats(com.alipay.sofa.jraft.rhea.metadata.StoreStats) TimeInterval(com.alipay.sofa.jraft.rhea.metadata.TimeInterval)

Example 3 with StoreHeartbeatRequest

use of com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest in project sofa-jraft by sofastack.

the class HeartbeatSender 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(com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest) Status(com.alipay.sofa.jraft.Status) StoreStats(com.alipay.sofa.jraft.rhea.metadata.StoreStats) TimeInterval(com.alipay.sofa.jraft.rhea.metadata.TimeInterval) Endpoint(com.alipay.sofa.jraft.util.Endpoint)

Aggregations

StoreHeartbeatRequest (com.alipay.sofa.jraft.rhea.cmd.pd.StoreHeartbeatRequest)3 MetadataStore (com.alipay.sofa.jraft.rhea.MetadataStore)2 StoreStats (com.alipay.sofa.jraft.rhea.metadata.StoreStats)2 TimeInterval (com.alipay.sofa.jraft.rhea.metadata.TimeInterval)2 Status (com.alipay.sofa.jraft.Status)1 Endpoint (com.alipay.sofa.jraft.util.Endpoint)1