Move datum key check to KeyBuilder

This commit is contained in:
KomachiSion 2020-09-25 15:17:12 +08:00
parent 481a1f972f
commit 402ad12c85
3 changed files with 9 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;