Skip to content

fix: ignore empty index error deleting last measurement (#25037)#27086

Merged
davidby-influx merged 2 commits intomain-2.xfrom
DSB/delete_last_measure
Jan 17, 2026
Merged

fix: ignore empty index error deleting last measurement (#25037)#27086
davidby-influx merged 2 commits intomain-2.xfrom
DSB/delete_last_measure

Conversation

@davidby-influx
Copy link
Copy Markdown
Contributor

An empty index is appropriate when deleting the last measurement. Also clean up error handling, avoid
duplicate calls to Close.

closes #9929

(cherry picked from commit b09e4b7)

Fixes #27037

An empty index is appropriate when deleting the last
measurement.  Also clean up error handling, avoid
duplicate calls to Close.

closes #9929

(cherry picked from commit b09e4b7)

Fixes #27037
return fmt.Errorf("failed to write index to TSM file: %w", err)
// Write index & close.
// It is okay to have no index values if no block was written
if err := w.WriteIndex(); err != nil && !(hasData || errors.Is(err, tsm1.ErrNoValues)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this will discard errors as long as hasData = true. For instance, if hasData = true and w.WriteIndex returns an out of space error (syscall.ENOSPC):

err != nil && !(hasData || errors.Is(err, tsm1.ErrNoValues))
syscall.ENOSPC != nil && !(true || errors.Is(syscall.ENOSPC, tsm1.ErrNoValues))
true && !(true || false)
true && !true
true && false
false

So the conditional will evaluate to false and we will ignore the syscall.ENOSPC returned by w.WriteIndex.

Am I missing something, or did I get my logic incorrect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me channel the ghost of George Boole tomorrow....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing a negation of hasData like this?

err != nil && !(!hasData || errors.Is(err, tsm1.ErrNoValues))

Copy link
Copy Markdown
Member

@gwossum gwossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a question about some logic. I approved the original PR this is based on, but now I have some doubt about the correctness.

@davidby-influx
Copy link
Copy Markdown
Contributor Author

Claude thoughts:

Current logic:
err != nil && !(blockWritten || errors.Is(err, tsm1.ErrNoValues))
Equivalent to: err != nil && !blockWritten && !errors.Is(err, tsm1.ErrNoValues)

Returns error when: error AND no blocks written AND not ErrNoValues

Problem: If blockWritten is true and WriteIndex() fails with a real error, that error is suppressed.

Your proposed logic:
err != nil && !(!blockWritten || errors.Is(err, tsm1.ErrNoValues))
Equivalent to: err != nil && blockWritten && !errors.Is(err, tsm1.ErrNoValues)

Returns error when: error AND blocks were written AND not ErrNoValues

Problem: If blockWritten is false and WriteIndex() fails with an unexpected error (not ErrNoValues), that error is suppressed.

What the comment suggests the intent is:
"It is okay to have no index values if no block was written"

The only acceptable error condition is ErrNoValues when !blockWritten. The correct logic would be:

err != nil && !(errors.Is(err, tsm1.ErrNoValues) && !blockWritten)

This suppresses only the specific case of ErrNoValues when no blocks were written, and reports all other errors regardless of blockWritten state.

davidby-influx added a commit that referenced this pull request Jan 15, 2026
@davidby-influx davidby-influx merged commit e4c88be into main-2.x Jan 17, 2026
25 checks passed
@davidby-influx davidby-influx deleted the DSB/delete_last_measure branch January 17, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

influx_inspect deletetsm: Can't delete last measurement [port to main-2.x]

3 participants