优化代码提交
This commit is contained in:
parent
fc27c0f571
commit
f03a3918e8
@ -3086,37 +3086,94 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================ 2. 过滤并处理符合条件的记录 ================
|
// ================ 2. 过滤并处理符合条件的记录 ================
|
||||||
List<TsFiles> filteredRecords = tsFilesPage.getRecords().stream()
|
|
||||||
|
// ================ 2. 优化后的MD5比较处理 ================
|
||||||
|
List<TsFiles> filteredRecords = tsFilesPage.getRecords().parallelStream()
|
||||||
.filter(tsFile -> {
|
.filter(tsFile -> {
|
||||||
try {
|
if ("FOLDER".equals(tsFile.getIsFile())) {
|
||||||
if("FOLDER".equals(tsFile.getIsFile())){
|
return false; // 跳过文件夹
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
String localMD5 = null;
|
||||||
|
String minioMD5 = null;
|
||||||
|
boolean hasError = false;
|
||||||
|
|
||||||
|
// 计算本地文件MD5(带资源自动管理)
|
||||||
|
String localFilePath = filePathConfig.getValue() + tsFile.getWorkPath();
|
||||||
|
File localFile = new File(localFilePath, tsFile.getFileName());
|
||||||
|
|
||||||
|
if (localFile.exists()) {
|
||||||
|
try (InputStream is = new FileInputStream(localFile)) {
|
||||||
|
localMD5 = calculateMD5Data(is);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("本地文件MD5计算失败: {} | 路径: {}",
|
||||||
|
tsFile.getFileName(), localFilePath, e);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("本地文件不存在: {} | 路径: {}", tsFile.getFileName(), localFilePath);
|
||||||
|
hasError = true;
|
||||||
}
|
}
|
||||||
// 计算本地文件MD5
|
|
||||||
File localFile = new File(filePathConfig.getValue() + tsFile.getWorkPath(), tsFile.getFileName());
|
|
||||||
String localMD5 = calculateMD5Data(new FileInputStream(localFile));
|
|
||||||
|
|
||||||
// 计算MinIO文件MD5
|
// 计算MinIO文件MD5
|
||||||
|
try {
|
||||||
|
minioMD5 = getMinioMD5Data(
|
||||||
|
bucketConfig.getValue(),
|
||||||
|
tsFile.getBackupPath(),
|
||||||
|
tsFile.getFileName(),
|
||||||
|
storageSource
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("MinIO文件MD5获取失败: {} | Bucket: {}/{}",
|
||||||
|
tsFile.getFileName(),
|
||||||
|
bucketConfig.getValue(),
|
||||||
|
tsFile.getBackupPath(),
|
||||||
|
e);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
|
||||||
String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName(),storageSource);
|
// 始终设置MD5字段(成功为实际值,失败为null)
|
||||||
|
|
||||||
// 路径处理
|
|
||||||
//tsFile.setWorkPath(processingPath(tsFile.getWorkPath(), tsFile.getNodeId()));
|
|
||||||
// tsFile.setBackupPath(processingPath(tsFile.getBackupPath(), tsFile.getNodeId()));
|
|
||||||
|
|
||||||
// 设置MD5字段(即使不满足条件也保留字段)
|
|
||||||
tsFile.setLocatMd5(localMD5);
|
tsFile.setLocatMd5(localMD5);
|
||||||
tsFile.setMinioMd5(minioMD5);
|
tsFile.setMinioMd5(minioMD5);
|
||||||
|
|
||||||
// 返回是否满足过滤条件
|
// 仅当两者都成功计算且不相等时保留
|
||||||
return StringUtils.isNoneEmpty(localMD5, minioMD5) && !localMD5.equals(minioMD5);
|
return !hasError &&
|
||||||
} catch (Exception e) {
|
StringUtils.isNoneEmpty(localMD5, minioMD5) &&
|
||||||
LOGGER.error("MD5计算失败: {}", tsFile.getFileName(), e);
|
!localMD5.equals(minioMD5);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// List<TsFiles> filteredRecords = tsFilesPage.getRecords().stream()
|
||||||
|
// .filter(tsFile -> {
|
||||||
|
// try {
|
||||||
|
// if("FOLDER".equals(tsFile.getIsFile())){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// // 计算本地文件MD5
|
||||||
|
// File localFile = new File(filePathConfig.getValue() + tsFile.getWorkPath(), tsFile.getFileName());
|
||||||
|
// String localMD5 = calculateMD5Data(new FileInputStream(localFile));
|
||||||
|
//
|
||||||
|
// // 计算MinIO文件MD5
|
||||||
|
//
|
||||||
|
// String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName(),storageSource);
|
||||||
|
//
|
||||||
|
// // 路径处理
|
||||||
|
// //tsFile.setWorkPath(processingPath(tsFile.getWorkPath(), tsFile.getNodeId()));
|
||||||
|
// // tsFile.setBackupPath(processingPath(tsFile.getBackupPath(), tsFile.getNodeId()));
|
||||||
|
//
|
||||||
|
// // 设置MD5字段(即使不满足条件也保留字段)
|
||||||
|
// tsFile.setLocatMd5(localMD5);
|
||||||
|
// tsFile.setMinioMd5(minioMD5);
|
||||||
|
//
|
||||||
|
// // 返回是否满足过滤条件
|
||||||
|
// return StringUtils.isNoneEmpty(localMD5, minioMD5) && !localMD5.equals(minioMD5);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// LOGGER.error("MD5计算失败: {}", tsFile.getFileName(), e);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
|
||||||
|
|
||||||
// ================ 3. 构建新的分页结果 ================
|
// ================ 3. 构建新的分页结果 ================
|
||||||
Page<TsFiles> resultPage = new Page<>();
|
Page<TsFiles> resultPage = new Page<>();
|
||||||
@ -3824,13 +3881,13 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
});
|
});
|
||||||
|
|
||||||
totalProcessed += batchList.size();
|
totalProcessed += batchList.size();
|
||||||
LOGGER.debug("已处理: {}/{}", totalProcessed, batchList.size());
|
// LOGGER.debug("已处理: {}/{}", totalProcessed, batchList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 批量更新路径
|
// 4. 批量更新路径
|
||||||
long updateStart = System.currentTimeMillis();
|
long updateStart = System.currentTimeMillis();
|
||||||
updateBackupPaths(taskId, nodeId);
|
updateBackupPaths(taskId, nodeId);
|
||||||
LOGGER.info("批量更新耗时: {}ms", System.currentTimeMillis() - updateStart);
|
// LOGGER.info("批量更新耗时: {}ms", System.currentTimeMillis() - updateStart);
|
||||||
|
|
||||||
// 5. 性能监控
|
// 5. 性能监控
|
||||||
long totalTime = System.currentTimeMillis() - startTime;
|
long totalTime = System.currentTimeMillis() - startTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user