sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.53k stars 1.12k forks source link

When deploying a PD single node, there is a probability that onLeaderStart cannot be called. #1060

Closed ye-xiaowei closed 6 months ago

ye-xiaowei commented 6 months ago

Describe the bug

Because the store was initialized first, followed by the call to addLeaderStateListerer. Perhaps onLeaderStart has already been called. Can I adjust the code order in PlacementDriverServer # init?

this.rheaKVStore = new DefaultRheaKVStore();
this.placementDriverService = new DefaultPlacementDriverService(this.rheaKVStore);
this.rheaKVStore.addLeaderStateListener(-1, ((DefaultPlacementDriverService) this.placementDriverService));
if (!this.rheaKVStore.init(rheaOpts)) {
    LOG.error("Fail to init [RheaKVStore].");
    return false;
}
killme2008 commented 6 months ago

Looks good, can you create a PR to fix it?

ye-xiaowei commented 6 months ago

Looks good, can you create a PR to fix it?

Sure