[ML] Better cleanup of normalizer quantiles state#2894
[ML] Better cleanup of normalizer quantiles state#2894edsavage wants to merge 8 commits intoelastic:mainfrom
Conversation
Ensure that quantiles state documents are always removed after an error has been encountered. This is intended to stop the disk being cluttered with many such documents after repeated failures.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
valeriy42
left a comment
There was a problem hiding this comment.
Thank you for addressing this issue. I have a couple of quick comments.
A more general comment: we have the same situation in bin/autodetect/Main.cc. Maybe you can generalize the RAII guard and use it in both cases.
bin/normalize/Main.cc
Outdated
| } | ||
| LOG_WARN(<< "Deleting quantiles state file '" << m_QuantilesStateFile << "'"); | ||
| // Ignore the return value from remove, the file may have already been deleted. | ||
| std::remove(m_QuantilesStateFile.c_str()); |
There was a problem hiding this comment.
You need to check the return value of std::remove and log if the files could not be deleted for some reason (permissions, locked file, etc.).
There was a problem hiding this comment.
Also, it would be consistent with the happy path behavior to delete the quantile files only when --deleteStateFiles is set.
bin/normalize/Main.cc
Outdated
| // No need for a warning here so we reset the cleanup function and delete the file explicitly if requested. | ||
| removeQuantilesStateOnFailure.reset(); | ||
| if (deleteStateFiles) { | ||
| std::remove(quantilesStateFile.c_str()); |
There was a problem hiding this comment.
Here again, it would be good to check the return value of std::remove and log success or failure with errno.
Ensure that quantiles state documents are always removed after an error has been encountered. This is intended to stop the disk being cluttered with many such documents after repeated failures.