@@ -870,34 +870,50 @@ public void checkLocalConfig(CacheData cacheData) {
870870 // Check if a failover file exists for the specified dataId, group, and tenant.
871871 File file = LocalConfigInfoProcessor .getFailoverFile (envName , dataId , group , tenant );
872872
873- // not using local config info, but a failover file exists
874- boolean failOverFileCreated = !cacheData .isUseLocalConfigInfo () && file .exists ();
875-
876- // using local config info, but there is a change in local configuration
877- boolean failOverFileChanged = cacheData .isUseLocalConfigInfo () && file .exists () && cacheData .getLocalConfigInfoVersion () != file .lastModified ();
878-
879- // using local config info, but the failover file is deleted
880- boolean failOverFileDeleted = cacheData .isUseLocalConfigInfo () && !file .exists ();
881-
882- if (failOverFileCreated || failOverFileChanged ) {
883- // load and use the file content
884- String content = LocalConfigInfoProcessor .getFailover (envName , dataId , group , tenant );
885- final String md5 = MD5Utils .md5Hex (content , Constants .ENCODE );
886- cacheData .setUseLocalConfigInfo (true );
887- cacheData .setLocalConfigInfoVersion (file .lastModified ());
888- cacheData .setContent (content );
889- LOGGER .warn (
890- "[{}] [failover-change] failover file {}. dataId={}, group={}, tenant={}, md5={}, content={}" ,
891- failOverFileCreated ? "created" : "changed" , envName , dataId , group , tenant , md5 , ContentUtils .truncateContent (content ));
873+ if (isFailOverFileCreated (cacheData , file )) {
874+ loadAndUse (cacheData , file , true );
875+ return ;
892876 }
893877
894- if (failOverFileDeleted ) {
878+ if (isFailOverFileDeleted ( cacheData , file ) ) {
895879 // switch back to server config.
896880 cacheData .setUseLocalConfigInfo (false );
897881 LOGGER .warn ("[{}] [failover-change] failover file deleted. dataId={}, group={}, tenant={}" , envName ,
898882 dataId , group , tenant );
883+ return ;
884+ }
885+
886+ if (isFailOverFileChanged (cacheData , file )) {
887+ loadAndUse (cacheData , file , false );
899888 }
900889 }
890+
891+ private void loadAndUse (CacheData cacheData , File file , boolean failOverFileCreated ) {
892+ String content = LocalConfigInfoProcessor .getFailover (cacheData .envName , cacheData .dataId , cacheData .group , tenant );
893+ final String md5 = MD5Utils .md5Hex (content , Constants .ENCODE );
894+ cacheData .setUseLocalConfigInfo (true );
895+ cacheData .setLocalConfigInfoVersion (file .lastModified ());
896+ cacheData .setContent (content );
897+ LOGGER .warn (
898+ "[{}] [failover-change] failover file {}. dataId={}, group={}, tenant={}, md5={}, content={}" ,
899+ failOverFileCreated ? "created" : "changed" ,
900+ cacheData .envName , cacheData .dataId , cacheData .group , tenant , md5 , ContentUtils .truncateContent (content ));
901+ }
902+
903+ private boolean isFailOverFileCreated (CacheData cacheData , File file ) {
904+ // not using local config info, but a failover file exists
905+ return !cacheData .isUseLocalConfigInfo () && file .exists ();
906+ }
907+
908+ private boolean isFailOverFileChanged (CacheData cacheData , File file ) {
909+ // using local config info, but there is a change in local configuration
910+ return cacheData .isUseLocalConfigInfo () && file .exists () && cacheData .getLocalConfigInfoVersion () != file .lastModified ();
911+ }
912+
913+ private boolean isFailOverFileDeleted (CacheData cacheData , File file ) {
914+ // using local config info, but the failover file is deleted
915+ return cacheData .isUseLocalConfigInfo () && !file .exists ();
916+ }
901917
902918 private ExecutorService ensureSyncExecutor (String taskId ) {
903919 if (!multiTaskExecutor .containsKey (taskId )) {
0 commit comments