diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java index d10c8e77d3a..464029c6c6a 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigCacheService.java @@ -105,7 +105,12 @@ public static boolean dump(String dataId, String group, String tenant, String co try { final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); - + if (lastModifiedTs < ConfigCacheService.getLastModifiedTs(groupKey)) { + DUMP_LOG.warn("[dump-ignore] the content is old. groupKey={}, md5={}, lastModifiedOld={}, " + + "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), + lastModifiedTs); + return true; + } if (md5.equals(ConfigCacheService.getContentMd5(groupKey)) && DiskUtil.targetFile(dataId, group, tenant).exists()) { DUMP_LOG.warn("[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, " + "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), @@ -158,6 +163,12 @@ public static boolean dumpBeta(String dataId, String group, String tenant, Strin try { final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); + if (lastModifiedTs < ConfigCacheService.getLastModifiedTs4Beta(groupKey)) { + DUMP_LOG.warn("[dump-beta-ignore] the content is old. groupKey={}, md5={}, lastModifiedOld={}, " + + "lastModifiedNew={}", groupKey, md5, + ConfigCacheService.getLastModifiedTs4Beta(groupKey), lastModifiedTs); + return true; + } if (md5.equals(ConfigCacheService.getContentBetaMd5(groupKey)) && DiskUtil.targetBetaFile(dataId, group, tenant).exists()) { DUMP_LOG.warn("[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, " + "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), @@ -203,6 +214,12 @@ public static boolean dumpTag(String dataId, String group, String tenant, String try { final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); + if (lastModifiedTs < ConfigCacheService.getTagLastModifiedTs(groupKey, tag)) { + DUMP_LOG.warn("[dump-tag-ignore] the tag is old. groupKey={}, md5={}, lastTagModifiedOld={}, " + + "lastModifiedNew={}", groupKey, md5, + ConfigCacheService.getTagLastModifiedTs(groupKey, tag), lastModifiedTs); + return true; + } if (md5.equals(ConfigCacheService.getContentTagMd5(groupKey, tag)) && DiskUtil.targetTagFile(dataId, group, tenant, tag).exists()) { DUMP_LOG.warn("[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, " + "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), @@ -246,6 +263,12 @@ public static boolean dumpChange(String dataId, String group, String tenant, Str try { final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); + if (lastModifiedTs < ConfigCacheService.getLastModifiedTs(groupKey)) { + DUMP_LOG.warn("[dump-ignore] the content is old. groupKey={}, md5={}, lastModifiedOld={}, " + + "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), + lastModifiedTs); + return true; + } if (!PropertyUtil.isDirectRead()) { String localMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant); if (md5.equals(localMd5)) { @@ -614,6 +637,19 @@ public static long getLastModifiedTs(String groupKey) { return (null != item) ? item.lastModifiedTs : 0L; } + public static long getLastModifiedTs4Beta(String groupKey) { + CacheItem item = CACHE.get(groupKey); + return (null != item) ? item.lastModifiedTs4Beta : 0L; + } + + public static long getTagLastModifiedTs(String groupKey, String tag) { + CacheItem item = CACHE.get(groupKey); + if (item == null || item.getTagLastModifiedTs() == null) { + return 0L; + } + return item.getTagLastModifiedTs().getOrDefault(tag, 0L); + } + public static boolean isUptodate(String groupKey, String md5) { String serverMd5 = ConfigCacheService.getContentMd5(groupKey); return StringUtils.equals(md5, serverMd5);