Skip to content

fix calculation of expected tables and create tables from upcoming schema considering grace period #1976

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 3 commits into from
Jan 22, 2020

Conversation

sandeepsukhani
Copy link
Contributor

@sandeepsukhani sandeepsukhani commented Jan 13, 2020

What this PR does:
This PR includes following to fixes:

  1. Fix calculation of expected tables:
    While calculating periodic tables for a given duration, the end time of the duration was used to find what the last table number would be. To avoid creating an extra table, there was a check whether end duration was ending exactly at end of the day which was causing the whole table to be omitted. Instead of checking against a days duration, this PR uses periodic table duration to check whether we have an extra table.

  2. Create tables from upcoming schema considering grace period:
    We skip creating tables for configs whose start time is after now() which means tables would not be created until we already are past the start time of config. This can cause writes to fail since tables won't be created already for writing data to it.
    This PR checks whether the config start time is before now() + gracePeriod when creating tables.

Which issue(s) this PR fixes:
Fixes: #1920
In #1920, the start time of config was not set to the day when tables would rotate. When the time was just short by grace period before hitting next config, this block started calculating tables for duration from start-of-active-schema to start-of-next-schema. Since the end was not a multiple of table duration but was a multiple of a days duration, issue 1 above was causing table manager to unexpectedly drop the active table.

Checklist

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

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.

LGTM

@@ -239,7 +239,8 @@ func (m *TableManager) calculateExpectedTables() []TableDesc {
result := []TableDesc{}

for i, config := range m.schemaCfg.Configs {
if config.From.Time.Time().After(mtime.Now()) {
// Consider configs which we are about to hit and requires tables to be created due to grace period
if config.From.Time.Time().After(mtime.Now().Add(m.cfg.CreationGracePeriod)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to myself: this looks a safe change to me. We're going to create the new table a bit ahead of time, which is what we want.

Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

Seems legit. One thought about a comment.

@@ -424,8 +424,8 @@ func (cfg *PeriodicTableConfig) periodicTables(from, through model.Time, pCfg Pr
nowWeek = now / periodSecs
result = []TableDesc{}
)
// If through ends on 00:00 of the day, don't include the upcoming day
if through.Unix()%secondsInDay == 0 {
// Make sure we don't have an extra table
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is now less explanatory. Could say something like “If interval ends exactly on a period boundary, don’t include the upcoming period”.

…hema considering grace period

Signed-off-by: Sandeep Sukhani <[email protected]>
Signed-off-by: Sandeep Sukhani <[email protected]>
Signed-off-by: Sandeep Sukhani <[email protected]>
@pracucci pracucci merged commit ab3e836 into cortexproject:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table-manager graceperiod bug with new schema
3 participants