Fix dropping database under write load #4580
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a number of issues that occur when dropping a database under write load.
Initially, the changes were to prevent panics that occurred with trying to create a new WAL segment in a DB dir that had been removed. When those were fixed, a full DB deadlock occurred due to WAL locks not being released when errors were returned. When those were fixed, shards were getting re-created on writes because we deleted the DB state before updating the meta-store which cause the
PointsWriter
to fall into the case where it should create a shard that does not exist locally. This also uncovered that shard references were not fully removed from thetsdb.Store
when a database was dropped which cause spurious errors in the logs due to the long-running periodic maintenance task goroutines. Finally, the WAL was not closed when a shard was closed which also led to spurious errors in the logs.Fixes #4538