Skip to content
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

TBS: drop and recreate badger db after exceeding storage limit for TTL time #15106

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

carsonip
Copy link
Member

@carsonip carsonip commented Jan 2, 2025

Motivation/summary

Alternative to #15081

Workaround for cases where apm-server is stuck at storage limit exceeded state indefinitely because badger DB compaction conditions are not satisfied. This PR implements a goroutine that detects this state, and if the state persists for at least TTL time, as the entries in badger DB would have been expired, just drop and recreate the DB to get out of this state.

Checklist

For functional changes, consider:

  • Is it observable through the addition of either logging or metrics?
  • Is its use being published in telemetry to enable product improvement?
  • Have system tests been added to avoid regression?

How to test these changes

Related issues

Fixes #14923

Copy link
Contributor

mergify bot commented Jan 2, 2025

This pull request does not have a backport label. Could you fix it @carsonip? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-7.17 is the label to automatically backport to the 7.17 branch.
  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • backport-8.x is the label to automatically backport to the 8.x branch.

Copy link
Contributor

mergify bot commented Jan 2, 2025

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Jan 2, 2025
@carsonip carsonip added backport-8.16 Automated backport with mergify backport-8.17 Automated backport with mergify labels Jan 2, 2025
@carsonip carsonip changed the title TBS: drop badger db if storage limit is reached for at least TTL TBS: drop and recreate badger db if storage limit exceeded for at least TTL time Jan 2, 2025
Copy link
Member Author

@carsonip carsonip left a comment

Choose a reason for hiding this comment

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

When the code is mostly ready, I plan to split this PR into 2 - a refactoring PR with no behavior changes and a bugfix PR with actual "drop and recreate" logic.

@carsonip carsonip requested a review from 1pkg January 2, 2025 23:48
}

func (s *ManagedReadWriter) WriteTraceEvent(traceID, id string, event *modelpb.APMEvent, opts WriterOpts) error {
s.sm.mu.RLock()
Copy link
Member Author

@carsonip carsonip Jan 2, 2025

Choose a reason for hiding this comment

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

TODO: not sure if it should RLock and wait for the swap, or just fail right away with TryRLock to avoid blocking ingestion.

1pkg
1pkg previously approved these changes Jan 3, 2025
Copy link
Member

@1pkg 1pkg left a comment

Choose a reason for hiding this comment

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

Overall the changes look good to me, thank you @carsonip!

@carsonip
Copy link
Member Author

carsonip commented Jan 3, 2025

Will rebase this PR after refactoring PR #15112 is merged done

@carsonip carsonip force-pushed the tbs-recover-from-storage-limit-exceeded-rm-db branch from 8e65516 to 9605745 Compare January 3, 2025 19:54
@carsonip carsonip changed the title TBS: drop and recreate badger db if storage limit exceeded for at least TTL time TBS: drop and recreate badger db after exceeding storage limit for TTL time Jan 3, 2025
@carsonip carsonip force-pushed the tbs-recover-from-storage-limit-exceeded-rm-db branch from 9605745 to 1e4d5b3 Compare January 3, 2025 19:56
now := time.Now()
if firstExceeded.IsZero() {
firstExceeded = now
s.logger.Warnf("badger db size has exceeded storage limit; db will be dropped and recreated if problem persists for `sampling.tail.ttl` (%s)", ttl.String())
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: maybe report badger db size in this log line as well

1pkg
1pkg previously approved these changes Jan 4, 2025
return len(filenames) == 0
}, 10*time.Second, 500*time.Millisecond, filenames)

b, err := os.ReadFile(subscriberPositionFile)
Copy link
Member

Choose a reason for hiding this comment

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

Should we also check that backup directory is gone?
And that new writes are accepted by badger after DB was recreated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify backport-8.16 Automated backport with mergify backport-8.17 Automated backport with mergify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TBS: Investigate cases where apm-server keeps exceeding storage limit and lsm size >> vlog size
2 participants