From c9b64e0173782f64a50b35a1da9d8b9f411ebb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BB=B6?= <1060026287@qq.com> Date: Mon, 10 Aug 2020 09:09:13 +0800 Subject: [PATCH] fix-#3550. write cache file and delete the old version cache file (#3551) --- .../consistency/persistent/raft/RaftStore.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 0b78b70a1f4..8d9042703a6 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 @@ -231,12 +231,12 @@ private synchronized Datum readDatum(File file, String namespaceId) throws IOExc } } - private String cacheFileName(String namespaceId, Datum datum) { + private String cacheFileName(String namespaceId, String datumKey) { String fileName; if (StringUtils.isNotBlank(namespaceId)) { - fileName = CACHE_DIR + File.separator + namespaceId + File.separator + encodeDatumKey(datum.key); + fileName = CACHE_DIR + File.separator + namespaceId + File.separator + encodeDatumKey(datumKey); } else { - fileName = CACHE_DIR + File.separator + encodeDatumKey(datum.key); + fileName = CACHE_DIR + File.separator + encodeDatumKey(datumKey); } return fileName; } @@ -259,7 +259,7 @@ public synchronized void write(final Datum datum) throws Exception { String namespaceId = KeyBuilder.getNamespace(datum.key); - File cacheFile = cacheFile(cacheFileName(namespaceId, datum)); + File cacheFile = cacheFile(cacheFileName(namespaceId, datum.key)); if (!cacheFile.exists() && !cacheFile.getParentFile().mkdirs() && !cacheFile.createNewFile()) { MetricsMonitor.getDiskException().increment(); @@ -288,10 +288,10 @@ public synchronized void write(final Datum datum) throws Exception { // remove old format file: if (StringUtils.isNoneBlank(namespaceId)) { if (datum.key.contains(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER)) { - String oldFormatKey = datum.key + String oldDatumKey = datum.key .replace(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER, StringUtils.EMPTY); - cacheFile = cacheFile(cacheFileName(namespaceId, datum)); + cacheFile = cacheFile(cacheFileName(namespaceId, oldDatumKey)); if (cacheFile.exists() && !cacheFile.delete()) { Loggers.RAFT.error("[RAFT-DELETE] failed to delete old format datum: {}, value: {}", datum.key, datum.value); @@ -322,7 +322,7 @@ public void delete(Datum datum) { if (StringUtils.isNotBlank(namespaceId)) { - File cacheFile = new File(cacheFileName(namespaceId, datum)); + File cacheFile = new File(cacheFileName(namespaceId, datum.key)); if (cacheFile.exists() && !cacheFile.delete()) { Loggers.RAFT.error("[RAFT-DELETE] failed to delete datum: {}, value: {}", datum.key, datum.value); throw new IllegalStateException("failed to delete datum: " + datum.key);