HTHou commented on code in PR #18349:
URL: https://github.com/apache/iotdb/pull/18349#discussion_r3689728164
##########
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java:
##########
@@ -276,8 +277,9 @@ public long takeSnapshot() throws IOException {
private void deleteIncompleteSnapshot(File snapshotDir) throws IOException {
// this takeSnapshot failed, clean up files and directories
// statemachine is supposed to clear snapshotDir on failure
- boolean isEmpty = snapshotDir.delete();
- if (!isEmpty) {
+ try {
+ Files.deleteIfExists(snapshotDir.toPath());
+ } catch (DirectoryNotEmptyException e) {
Review Comment:
Could we preserve the old recursive-cleanup fallback for any deletion
failure, rather than only DirectoryNotEmptyException? That exception is an
optional specific exception in the Files.deleteIfExists contract, so a
compliant custom provider may report a non-empty directory as a plain
IOException. In that case this code skips FileUtils.deleteFully(snapshotDir)
and leaves the incomplete snapshot behind. Please fall back on any failed
single-directory delete, preserving the original exception if recursive cleanup
also fails. JDK contract:
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#deleteIfExists(java.nio.file.Path)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]