@Test public void recover() throws IOException, MetadataException { Map<String, Map<Long, Set<File>>> allFileList = new HashMap<>(); for (int i = 0; i < 3; i++) { IoTDB.metaManager.setStorageGroup(new PartialPath(getSgName(i))); } Random r = new Random(0); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { allFileList.computeIfAbsent(getSgName(i), k -> new HashMap<>()).computeIfAbsent(0L, k -> new HashSet<>()); String rand = r.nextInt(10000) + TSFILE_SUFFIX; String fileName = FilePathUtils.regularizePath(dataDir) + IoTDBConstant.SEQUENCE_FLODER_NAME + File.separator + getSgName(i) + File.separator + "0" + File.separator + rand; File file = new File(fileName); allFileList.get(getSgName(i)).get(0L).add(file); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } if (!file.exists() && !file.createNewFile()) { LOGGER.error("Can not create new file {}", file.getPath()); } if (!new File(file.getAbsolutePath() + TsFileResource.RESOURCE_SUFFIX).exists() && !new File(file.getAbsolutePath() + TsFileResource.RESOURCE_SUFFIX).createNewFile()) { LOGGER.error("Can not create new file {}", file.getPath()); } } } manager.getValidFiles(dataDir); assertTrue(SyncUtils.isEmpty(manager.getLastLocalFilesMap())); senderLogger.startSyncTsFiles(); for (Map<Long, Set<File>> map : allFileList.values()) { for (Set<File> newTsFiles : map.values()) { for (File file : newTsFiles) { senderLogger.finishSyncTsfile(file); } } } senderLogger.close(); senderLogAnalyzer.recover(); manager.getValidFiles(dataDir); assertFalse(SyncUtils.isEmpty(manager.getLastLocalFilesMap())); Map<String, Map<Long, Set<File>>> lastFilesMap = manager.getLastLocalFilesMap(); assertFileMap(allFileList, lastFilesMap); assertFalse(new File(config.getSenderFolderPath(), SyncConstant.SYNC_LOG_NAME).exists()); senderLogger = new SyncSenderLogger( new File(config.getSenderFolderPath(), SyncConstant.SYNC_LOG_NAME)); manager.getValidFiles(dataDir); assertFalse(SyncUtils.isEmpty(manager.getLastLocalFilesMap())); senderLogger.startSyncDeletedFilesName(); for (Map<Long, Set<File>> map : allFileList.values()) { for (Set<File> newTsFiles : map.values()) { for (File file : newTsFiles) { senderLogger.finishSyncDeletedFileName(file); } } } senderLogger.close(); senderLogAnalyzer.recover(); manager.getValidFiles(dataDir); assertTrue(SyncUtils.isEmpty(manager.getLastLocalFilesMap())); assertTrue(SyncUtils.isEmpty(manager.getDeletedFilesMap())); Map<String, Map<Long, Set<File>>> toBeSyncedFilesMap = manager.getToBeSyncedFilesMap(); assertFileMap(allFileList, toBeSyncedFilesMap); }
@Override public void recover() throws IOException { if (currentLocalFile.exists() && !lastLocalFile.exists()) { FileUtils.moveFile(currentLocalFile, lastLocalFile); } else { Set<String> lastLocalFiles = new HashSet<>(); Set<String> deletedFiles = new HashSet<>(); Set<String> newFiles = new HashSet<>(); loadLastLocalFiles(lastLocalFiles); loadLogger(deletedFiles, newFiles); lastLocalFiles.removeAll(deletedFiles); lastLocalFiles.addAll(newFiles); updateLastLocalFile(lastLocalFiles); } FileUtils.deleteDirectory(new File(senderPath, SyncConstant.DATA_SNAPSHOT_NAME)); syncLogFile.delete(); }
SyncSenderLogAnalyzer implements ISyncSenderLogAnalyzer { @Override public void recover() throws IOException { if (currentLocalFile.exists() && !lastLocalFile.exists()) { FileUtils.moveFile(currentLocalFile, lastLocalFile); } else { Set<String> lastLocalFiles = new HashSet<>(); Set<String> deletedFiles = new HashSet<>(); Set<String> newFiles = new HashSet<>(); loadLastLocalFiles(lastLocalFiles); loadLogger(deletedFiles, newFiles); lastLocalFiles.removeAll(deletedFiles); lastLocalFiles.addAll(newFiles); updateLastLocalFile(lastLocalFiles); } FileUtils.deleteDirectory(new File(senderPath, SyncConstant.DATA_SNAPSHOT_NAME)); syncLogFile.delete(); } }
SyncSenderLogAnalyzer implements ISyncSenderLogAnalyzer { @Override public void recover() throws IOException { if (currentLocalFile.exists() && !lastLocalFile.exists()) { FileUtils.moveFile(currentLocalFile, lastLocalFile); } else { Set<String> lastLocalFiles = new HashSet<>(); Set<String> deletedFiles = new HashSet<>(); Set<String> newFiles = new HashSet<>(); loadLastLocalFiles(lastLocalFiles); loadLogger(deletedFiles, newFiles); lastLocalFiles.removeAll(deletedFiles); lastLocalFiles.addAll(newFiles); updateLastLocalFile(lastLocalFiles); } FileUtils.deleteDirectory(new File(senderPath, SyncConstant.DATA_SNAPSHOT_NAME)); syncLogFile.delete(); } SyncSenderLogAnalyzer(String senderPath); }
SyncSenderLogAnalyzer implements ISyncSenderLogAnalyzer { @Override public void recover() throws IOException { if (currentLocalFile.exists() && !lastLocalFile.exists()) { FileUtils.moveFile(currentLocalFile, lastLocalFile); } else { Set<String> lastLocalFiles = new HashSet<>(); Set<String> deletedFiles = new HashSet<>(); Set<String> newFiles = new HashSet<>(); loadLastLocalFiles(lastLocalFiles); loadLogger(deletedFiles, newFiles); lastLocalFiles.removeAll(deletedFiles); lastLocalFiles.addAll(newFiles); updateLastLocalFile(lastLocalFiles); } FileUtils.deleteDirectory(new File(senderPath, SyncConstant.DATA_SNAPSHOT_NAME)); syncLogFile.delete(); } SyncSenderLogAnalyzer(String senderPath); @Override void recover(); @Override void loadLastLocalFiles(Set<String> lastLocalFiles); @Override void loadLogger(Set<String> deletedFiles, Set<String> newFiles); @Override void updateLastLocalFile(Set<String> currentLocalFiles); }
SyncSenderLogAnalyzer implements ISyncSenderLogAnalyzer { @Override public void recover() throws IOException { if (currentLocalFile.exists() && !lastLocalFile.exists()) { FileUtils.moveFile(currentLocalFile, lastLocalFile); } else { Set<String> lastLocalFiles = new HashSet<>(); Set<String> deletedFiles = new HashSet<>(); Set<String> newFiles = new HashSet<>(); loadLastLocalFiles(lastLocalFiles); loadLogger(deletedFiles, newFiles); lastLocalFiles.removeAll(deletedFiles); lastLocalFiles.addAll(newFiles); updateLastLocalFile(lastLocalFiles); } FileUtils.deleteDirectory(new File(senderPath, SyncConstant.DATA_SNAPSHOT_NAME)); syncLogFile.delete(); } SyncSenderLogAnalyzer(String senderPath); @Override void recover(); @Override void loadLastLocalFiles(Set<String> lastLocalFiles); @Override void loadLogger(Set<String> deletedFiles, Set<String> newFiles); @Override void updateLastLocalFile(Set<String> currentLocalFiles);  }