Skip to content

Commit

Permalink
improve the code quality for consistency (#5783)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xiao-shuang committed May 20, 2021
1 parent 08db47c commit 022fb6a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class KeyBuilder {

public static final String BRIEF_INSTANCE_LIST_KEY_PREFIX = "iplist.";

public static final String RESOURCE_KEY_SNAPSHOT = "snapshot";

public static final String RESOURCE_KEY_CHECKSUM = "checksum";

private static String buildEphemeralInstanceListKey(String namespaceId, String serviceName) {
return INSTANCE_LIST_KEY_PREFIX + EPHEMERAL_KEY_PREFIX + namespaceId + NAMESPACE_KEY_CONNECTOR + serviceName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public DistroData getDistroData(DistroKey distroKey) {
public DistroData getDatumSnapshot() {
Map<String, Datum> result = dataStore.getDataMap();
byte[] dataContent = ApplicationUtils.getBean(Serializer.class).serialize(result);
DistroKey distroKey = new DistroKey("snapshot", KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
DistroKey distroKey = new DistroKey(KeyBuilder.RESOURCE_KEY_SNAPSHOT, KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
return new DistroData(distroKey, dataContent);
}

Expand All @@ -98,7 +98,7 @@ public List<DistroData> getVerifyData() {
if (keyChecksums.isEmpty()) {
return Collections.emptyList();
}
DistroKey distroKey = new DistroKey("checksum", KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
DistroKey distroKey = new DistroKey(KeyBuilder.RESOURCE_KEY_CHECKSUM, KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
DistroData data = new DistroData(distroKey, ApplicationUtils.getBean(Serializer.class).serialize(keyChecksums));
data.setType(DataOperation.VERIFY);
return Collections.singletonList(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public DistroData getData(DistroKey key, String targetServer) {
public DistroData getDatumSnapshot(String targetServer) {
try {
byte[] allDatum = NamingProxy.getAllData(targetServer);
return new DistroData(new DistroKey("snapshot", KeyBuilder.INSTANCE_LIST_KEY_PREFIX), allDatum);
return new DistroData(new DistroKey(KeyBuilder.RESOURCE_KEY_SNAPSHOT, KeyBuilder.INSTANCE_LIST_KEY_PREFIX), allDatum);
} catch (Exception e) {
throw new DistroException(String.format("Get snapshot from %s failed.", targetServer), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class NamingKvStorage extends MemoryKvStorage {

private static final String LOAD_SNAPSHOT = NamingKvStorage.class.getSimpleName() + ".snapshotLoad";

private static final String LABEL = "naming-persistent";

private final String baseDir;

private final KvStorage baseDirStorage;
Expand All @@ -55,7 +57,7 @@ public class NamingKvStorage extends MemoryKvStorage {

public NamingKvStorage(final String baseDir) throws Exception {
this.baseDir = baseDir;
this.baseDirStorage = StorageFactory.createKvStorage(KvStorage.KvType.File, "naming-persistent", baseDir);
this.baseDirStorage = StorageFactory.createKvStorage(KvStorage.KvType.File, LABEL, baseDir);
this.namespaceKvStorage = new ConcurrentHashMap<>(16);
}

Expand Down Expand Up @@ -215,7 +217,7 @@ private KvStorage createActualStorageIfAbsent(String namespace) throws Exception
Function<String, KvStorage> kvStorageBuilder = key -> {
try {
String namespacePath = Paths.get(baseDir, key).toString();
return StorageFactory.createKvStorage(KvType.File, "naming-persistent", namespacePath);
return StorageFactory.createKvStorage(KvType.File, LABEL, namespacePath);
} catch (Exception e) {
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e);
}
Expand Down

0 comments on commit 022fb6a

Please sign in to comment.