From 402ad12c8505427d48126af03cc082b5b2ced67b Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Fri, 25 Sep 2020 15:17:12 +0800 Subject: [PATCH] Move datum key check to KeyBuilder --- .../com/alibaba/nacos/naming/consistency/KeyBuilder.java | 9 +++++++-- .../persistent/impl/PersistentServiceProcessor.java | 2 +- .../naming/consistency/persistent/raft/RaftStore.java | 7 +------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/KeyBuilder.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/KeyBuilder.java index 092896612..41ce7cb12 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/KeyBuilder.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/KeyBuilder.java @@ -19,6 +19,8 @@ package com.alibaba.nacos.naming.consistency; import com.alibaba.nacos.naming.misc.UtilsAndCommons; import org.apache.commons.lang3.StringUtils; +import static com.alibaba.nacos.naming.misc.UtilsAndCommons.RAFT_CACHE_FILE_PREFIX; + /** * Key operations for data. * @@ -81,8 +83,7 @@ public class KeyBuilder { } public static boolean matchSwitchKey(String key) { - return key.endsWith(UtilsAndCommons.SWITCH_DOMAIN_NAME) || key - .endsWith(UtilsAndCommons.SWITCH_DOMAIN_NAME + UtilsAndCommons.RAFT_CACHE_FILE_SUFFIX); + return key.endsWith(UtilsAndCommons.SWITCH_DOMAIN_NAME); } public static boolean matchServiceName(String key, String namespaceId, String serviceName) { @@ -141,4 +142,8 @@ public class KeyBuilder { public static String getServiceName(String key) { return key.split(NAMESPACE_KEY_CONNECTOR)[1]; } + + public static boolean isDatumCacheFile(String key) { + return key.startsWith(RAFT_CACHE_FILE_PREFIX); + } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/impl/PersistentServiceProcessor.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/impl/PersistentServiceProcessor.java index 659c1cda3..0e8f90d2b 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/impl/PersistentServiceProcessor.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/impl/PersistentServiceProcessor.java @@ -331,7 +331,7 @@ public class PersistentServiceProcessor extends LogProcessor4CP implements Persi } private void notifierDatumIfAbsent(String key, RecordListener listener) throws NacosException { - if (key.equals(KeyBuilder.SERVICE_META_KEY_PREFIX)) { + if (KeyBuilder.SERVICE_META_KEY_PREFIX.equals(key)) { notifierAllServiceMeta(listener); } else { Datum datum = get(key); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java index 6df31d3f6..5a56c60ee 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java @@ -49,7 +49,6 @@ import java.util.Map; import java.util.Properties; import static com.alibaba.nacos.naming.misc.UtilsAndCommons.DATA_BASE_DIR; -import static com.alibaba.nacos.naming.misc.UtilsAndCommons.RAFT_CACHE_FILE_PREFIX; /** * Raft store. @@ -146,12 +145,8 @@ public class RaftStore implements Closeable { return null; } - private boolean isDatumCacheFile(String fileName) { - return fileName.startsWith(RAFT_CACHE_FILE_PREFIX); - } - private synchronized Datum readDatum(File file, String namespaceId) throws IOException { - if (!isDatumCacheFile(file.getName())) { + if (!KeyBuilder.isDatumCacheFile(file.getName())) { return null; } ByteBuffer buffer;