Skip to content

Commit 5609ef2

Browse files
fixed apache#469
because of remove the collection item action inside of collection for each action.
1 parent 2503604 commit 5609ef2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

apm-collector/apm-collector-cluster/src/main/java/org/skywalking/apm/collector/cluster/zookeeper/ClusterZKDataMonitor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.skywalking.apm.collector.cluster.zookeeper;
22

3+
import java.util.HashSet;
34
import java.util.Iterator;
45
import java.util.LinkedHashMap;
56
import java.util.List;
67
import java.util.Map;
78
import java.util.Set;
8-
import java.util.HashSet;
99
import org.apache.zookeeper.CreateMode;
1010
import org.apache.zookeeper.WatchedEvent;
1111
import org.apache.zookeeper.Watcher;
@@ -42,14 +42,14 @@ public ClusterZKDataMonitor() {
4242
registrations = new LinkedHashMap<>();
4343
}
4444

45-
@Override public void process(WatchedEvent event) {
45+
@Override public synchronized void process(WatchedEvent event) {
4646
logger.info("changed path {}, event type: {}", event.getPath(), event.getType().name());
4747
if (listeners.containsKey(event.getPath())) {
4848
List<String> paths;
4949
try {
5050
paths = client.getChildren(event.getPath(), true);
5151
ClusterDataListener listener = listeners.get(event.getPath());
52-
Set<String> remoteNodes = new HashSet<String>();
52+
Set<String> remoteNodes = new HashSet<>();
5353
Set<String> notifiedNodes = listener.getAddresses();
5454
if (CollectionUtils.isNotEmpty(paths)) {
5555
for (String serverPath : paths) {
@@ -65,9 +65,12 @@ public ClusterZKDataMonitor() {
6565
}
6666
}
6767
}
68-
for (String address : notifiedNodes) {
68+
69+
String[] notifiedNodeArray = notifiedNodes.toArray(new String[notifiedNodes.size()]);
70+
for (int i = notifiedNodeArray.length - 1; i >= 0; i--) {
71+
String address = notifiedNodeArray[i];
6972
if (remoteNodes.isEmpty() || !remoteNodes.contains(address)) {
70-
logger.info("path children has been changed, path and data: {}", event.getPath() + "/" + address);
73+
logger.info("path children has been remove, path and data: {}", event.getPath() + "/" + address);
7174
listener.removeAddress(address);
7275
listener.serverQuitNotify(address);
7376
}

0 commit comments

Comments
 (0)