Skip to content

Commit ab3e836

Browse files
sandeepsukhanipracucci
authored andcommitted
fix calculation of expected tables and create tables from upcoming schema considering grace period (#1976)
* fix calculation of expected tables and create tables from upcoming schema considering grace period Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com> * updated changelog Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com> * updated comment to make it clearer Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
1 parent a0da2c8 commit ab3e836

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ instructions below to upgrade your Postgres.
5555
* [BUGFIX] TSDB: Fixed `cortex_ingester_queried_samples` and `cortex_ingester_queried_series` metrics when using block storage. #1981
5656
* [BUGFIX] TSDB: Fixed `cortex_ingester_memory_series` and `cortex_ingester_memory_users` metrics when using with the experimental TSDB blocks storage. #1982
5757
* [BUGFIX] TSDB: Fixed `cortex_ingester_memory_series_created_total` and `cortex_ingester_memory_series_removed_total` metrics when using TSDB blocks storage. #1990
58+
* [BUGFIX] Table Manager: Fixed calculation of expected tables and creation of tables from next active schema considering grace period. #1976
5859

5960
### Upgrading Postgres (if you're using configs service)
6061

pkg/chunk/schema_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ func (cfg *PeriodicTableConfig) periodicTables(from, through model.Time, pCfg Pr
424424
nowWeek = now / periodSecs
425425
result = []TableDesc{}
426426
)
427-
// If through ends on 00:00 of the day, don't include the upcoming day
428-
if through.Unix()%secondsInDay == 0 {
427+
// If interval ends exactly on a period boundary, dont include the upcoming period
428+
if through.Unix()%periodSecs == 0 {
429429
lastTable--
430430
}
431431
// Don't make tables further back than the configured retention

pkg/chunk/table_manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ func (m *TableManager) calculateExpectedTables() []TableDesc {
239239
result := []TableDesc{}
240240

241241
for i, config := range m.schemaCfg.Configs {
242-
if config.From.Time.Time().After(mtime.Now()) {
242+
// Consider configs which we are about to hit and requires tables to be created due to grace period
243+
if config.From.Time.Time().After(mtime.Now().Add(m.cfg.CreationGracePeriod)) {
243244
continue
244245
}
245246
if config.IndexTables.Period == 0 { // non-periodic table

pkg/chunk/table_manager_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@ func TestTableManager(t *testing.T) {
285285
},
286286
)
287287

288+
// Move ahead where we are short by just grace period before hitting next section
289+
tmTest(t, client, tableManager,
290+
"Move ahead where we are short by just grace period before hitting next section",
291+
weeklyTable2Start.Add(-gracePeriod+time.Second),
292+
[]TableDesc{
293+
{Name: baseTableName, ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite},
294+
{Name: tablePrefix + week1Suffix, ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite, WriteScale: inactiveScalingConfig},
295+
{Name: tablePrefix + week2Suffix, ProvisionedRead: read, ProvisionedWrite: write, WriteScale: activeScalingConfig},
296+
{Name: table2Prefix + "5", ProvisionedRead: read, ProvisionedWrite: write, WriteScale: activeScalingConfig},
297+
{Name: chunkTablePrefix + week1Suffix, ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite},
298+
{Name: chunkTablePrefix + week2Suffix, ProvisionedRead: read, ProvisionedWrite: write},
299+
{Name: chunkTable2Prefix + "5", ProvisionedRead: read, ProvisionedWrite: write},
300+
},
301+
)
302+
288303
// Move to the next section of the config
289304
tmTest(t, client, tableManager,
290305
"Move forward to next section of schema config",
@@ -648,6 +663,20 @@ func TestTableManagerRetentionOnly(t *testing.T) {
648663
},
649664
)
650665

666+
// Check after three weeks and a day short by grace period, we have three tables (two previous periods and the new one), table 0 was deleted
667+
tmTest(t, client, tableManager,
668+
"Move forward by three table periods and a day short by grace period",
669+
baseTableStart.Add(tablePeriod*3+24*time.Hour-gracePeriod),
670+
[]TableDesc{
671+
{Name: tablePrefix + "1", ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite, WriteScale: inactiveScalingConfig},
672+
{Name: tablePrefix + "2", ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite, WriteScale: inactiveScalingConfig},
673+
{Name: tablePrefix + "3", ProvisionedRead: read, ProvisionedWrite: write},
674+
{Name: chunkTablePrefix + "1", ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite},
675+
{Name: chunkTablePrefix + "2", ProvisionedRead: inactiveRead, ProvisionedWrite: inactiveWrite},
676+
{Name: chunkTablePrefix + "3", ProvisionedRead: read, ProvisionedWrite: write},
677+
},
678+
)
679+
651680
// Verify that without RetentionDeletesEnabled no tables are removed
652681
tableManager.cfg.RetentionDeletesEnabled = false
653682
// Retention > 0 will prevent older tables from being created so we need to create the old tables manually for the test

0 commit comments

Comments
 (0)