Move remove listener logic to ServiceManager

This commit is contained in:
KomachiSion 2020-10-12 14:17:31 +08:00
parent ea515428ce
commit b8b111320a
2 changed files with 9 additions and 8 deletions

View File

@ -231,10 +231,6 @@ public class PersistentServiceProcessor extends LogProcessor4CP implements Persi
final ValueChangeEvent event = ValueChangeEvent.builder().key(key).value(value)
.action(Op.Delete.equals(op) ? DataOperation.DELETE : DataOperation.CHANGE).build();
NotifyCenter.publishEvent(event);
// remove listeners of key to avoid mem leak
if (Op.Delete.equals(op)) {
notifier.deregisterAllListener(key);
}
}
}

View File

@ -26,6 +26,7 @@ import com.alibaba.nacos.naming.consistency.ConsistencyService;
import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.consistency.RecordListener;
import com.alibaba.nacos.naming.consistency.persistent.impl.PersistentServiceProcessor;
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet;
import com.alibaba.nacos.naming.misc.GlobalExecutor;
@ -229,10 +230,14 @@ public class ServiceManager implements RecordListener<Service> {
if (service != null) {
service.destroy();
consistencyService.remove(KeyBuilder.buildInstanceListKey(namespace, name, true));
consistencyService.remove(KeyBuilder.buildInstanceListKey(namespace, name, false));
String ephemeralInstanceListKey = KeyBuilder.buildInstanceListKey(namespace, name, true);
String persistInstanceListKey = KeyBuilder.buildInstanceListKey(namespace, name, false);
consistencyService.remove(ephemeralInstanceListKey);
consistencyService.remove(persistInstanceListKey);
// remove listeners of key to avoid mem leak
consistencyService.unListen(ephemeralInstanceListKey, service);
consistencyService.unListen(persistInstanceListKey, service);
consistencyService.unListen(KeyBuilder.buildServiceMetaKey(namespace, name), service);
Loggers.SRV_LOG.info("[DEAD-SERVICE] {}", service.toJson());
}