-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: do not leak file handles from Compactor.write #25725
Conversation
There are a number of code paths in Compactor.write which on error can lead to leaked file handles to temporary files. This, in turn, prevents the removal of the temporary files until InfluxDB is rebooted, releasing the file handles. closes #25724
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Just one note about errors.Is
and errors.Join
expectation settings. I'm sure its fine though. I didn't notice any holes as I went through.
tsdb/engine/tsm1/compact.go
Outdated
@@ -1064,11 +1064,11 @@ func (c *Compactor) writeNewFiles(generation, sequence int, src []string, iter K | |||
|
|||
// We've hit the max file limit and there is more to write. Create a new file | |||
// and continue. | |||
if err == errMaxFileExceeded || err == ErrMaxBlocksExceeded { | |||
if errors.Is(err, errMaxFileExceeded) || errors.Is(err, ErrMaxBlocksExceeded) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it matters but since you are joining errors and then checking with errors.Is
if there are multiple errors joined and errMaxFileExceed
or ErrMaxBlocksExceeded
is in the errors this will pass the test.
See the following example where I check for a single error. The function that returns two errors combined still passes the test.
https://goplay.tools/snippet/b_YVLCYn5-j
I'm sure thats what you were expecting but just something I noticed with errors.Is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the original code discards file closing errors on errMaxFileExceededor
or ErrMaxBlocksExceeded
, behavior that using errors.Is
essentially replicates because of the feature you mention above, on reflection I think we should report and abort compaction on file closing errors, which will require an additional commit to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There are a number of code paths in Compactor.write which on error can lead to leaked file handles to temporary files. This, in turn, prevents the removal of the temporary files until InfluxDB is rebooted, releasing the file handles.
closes #25724