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();
}
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();
}
}
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);
}
Aggregations