Questions
It was found that in high concurrency and weak network environments, the "remove" method of SubsMapHelper may be called earlier than the "put" method, leading to the failure of the "remove" method. A retry should be added to the remove method
Version
4.4.1
solution to the problem
public void remove(String address, RegistrationInfo registrationInfo, Promise<Void> promise) {
try {
if (registrationInfo.localOnly()) {
localSubs.computeIfPresent(address, (add, curr) -> removeFromSet(registrationInfo, curr));
fireRegistrationUpdateEvent(address);
promise.complete();
} else {
//-> @wjw_add The deletion instruction came too early and the node does not exist yet. Try again a few times at this time!
int retryCount=0;
org.apache.zookeeper.data.Stat stat = curator.checkExists().forPath(fullPath.apply(address, registrationInfo));
while(stat==null && retryCount<3) {
log.warn(MessageFormat.format("要删除的Zookeeper节点不存在:{0}, 重试第:{1}次!", fullPath.apply(address, registrationInfo), retryCount));
java.util.concurrent.TimeUnit.SECONDS.sleep(1);
retryCount++;
stat = curator.checkExists().forPath(fullPath.apply(address, registrationInfo));
}
if(stat==null) {
log.warn(MessageFormat.format("重试几次后,要删除的Zookeeper节点还不存在:{0}", fullPath.apply(address, registrationInfo)));
}
//<- @wjw_add
curator.delete().guaranteed().inBackground((c, e) -> {
if (e.getType() == CuratorEventType.DELETE) {
vertx.runOnContext(aVoid -> {
ownSubs.computeIfPresent(address, (add, curr) -> removeFromSet(registrationInfo, curr));
promise.complete();
});
}
}).forPath(fullPath.apply(address, registrationInfo));
}
} catch (Exception e) {
log.error(String.format("remove subs address %s failed.", address), e);
promise.fail(e);
}
}
Questions
It was found that in high concurrency and weak network environments, the "remove" method of SubsMapHelper may be called earlier than the "put" method, leading to the failure of the "remove" method. A retry should be added to the remove method
Version
4.4.1
solution to the problem