Skip to content

Don't update lastUpdateTime if TSDB isn't updated. #3727

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

Merged
merged 4 commits into from
Jan 25, 2021
Merged

Don't update lastUpdateTime if TSDB isn't updated. #3727

merged 4 commits into from
Jan 25, 2021

Conversation

pstibrany
Copy link
Contributor

What this PR does: This PR modified ingester to not update "lastUpdate" time if push request didn't contain any sample that was appended to TSDB.

Without doing this change, continuous push of bad samples will keep TSDB in memory with unflushed data. If "good" sample arrives much later, all old data will be finally put to block.

With this change, ingester will eventually flush and close such TSDB, and remove local data. After closing, next push of valid or invalid sample will reopen TSDB again (and then later close, if no valid samples arrive), but at least old samples will not be kept in the memory for a long time.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Contributor

@ranton256 ranton256 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. The changes LGTM.

db.setLastUpdate(time.Now())
// If only invalid samples are pushed, don't change "last update", as TSDB was not modified.
if succeededSamplesCount > 0 {
db.setLastUpdate(time.Now())
Copy link
Contributor

Choose a reason for hiding this comment

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

We can avoid time.Now() using startCommit.

Suggested change
db.setLastUpdate(time.Now())
db.setLastUpdate(startCommit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need to avoid time.Now() here. Furthermore there are cases where commit takes quite a while. We only have bucket up to 10 seconds, but metrics show that we hit it regularly on some ingesters (!), although in practice that should still be good enough.

lastUpdate := db.lastUpdate.Load()

// Wait until 1 second passes.
test.Poll(t, 1*time.Second, time.Now().Unix()+1, func() interface{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not time.Sleep(time.Second)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test.Poll allows us to wait shorter.

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Could you also add a CHANGELOG entry, please?

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany pstibrany merged commit 91a1261 into cortexproject:master Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants