修复client register事件跟clientManager addClient异步并行问题 (#11634)

This commit is contained in:
CZJCC 2024-01-10 19:06:37 +08:00 committed by GitHub
parent f3fb60ebf3
commit c98b8c4111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,6 +60,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -461,15 +462,19 @@ public class PersistentClientOperationServiceImpl extends RequestProcessor4CP im
List<String> groupNames = data.getGroupNames();
List<String> serviceNames = data.getServiceNames();
List<InstancePublishInfo> instances = data.getInstancePublishInfos();
List<ClientOperationEvent.ClientRegisterServiceEvent> waitPublishEvents = new ArrayList<>();
for (int i = 0; i < namespaces.size(); i++) {
Service service = Service.newService(namespaces.get(i), groupNames.get(i), serviceNames.get(i), false);
Service singleton = ServiceManager.getInstance().getSingleton(service);
client.putServiceInstance(singleton, instances.get(i));
Loggers.RAFT.info("[SNAPSHOT-DATA-ADD] service={}, instance={}", service, instances.get(i));
NotifyCenter.publishEvent(
waitPublishEvents.add(
new ClientOperationEvent.ClientRegisterServiceEvent(singleton, client.getClientId()));
}
clientManager.addSyncClient(client);
for (ClientOperationEvent.ClientRegisterServiceEvent waitPublishEvent : waitPublishEvents) {
NotifyCenter.publishEvent(waitPublishEvent);
}
}
@Override