From 3f0d8b0c1350ac802e84b51a88d14b0edd3de7b0 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:00:47 +0200 Subject: [PATCH] test new formats Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- .../vttablet/tabletserver/gc/tablegc_test.go | 186 ++++++++++++++++-- 1 file changed, 173 insertions(+), 13 deletions(-) diff --git a/go/vt/vttablet/tabletserver/gc/tablegc_test.go b/go/vt/vttablet/tabletserver/gc/tablegc_test.go index 446f6e6ff85..47012b26d87 100644 --- a/go/vt/vttablet/tabletserver/gc/tablegc_test.go +++ b/go/vt/vttablet/tabletserver/gc/tablegc_test.go @@ -29,15 +29,18 @@ import ( func TestNextTableToPurge(t *testing.T) { tt := []struct { + name string tables []string next string ok bool }{ { + name: "empty", tables: []string{}, ok: false, }, { + name: "first", tables: []string{ "_vt_PURGE_6ace8bcef73211ea87e9f875a4d24e90_20200915120410", "_vt_PURGE_2ace8bcef73211ea87e9f875a4d24e90_20200915120411", @@ -48,6 +51,7 @@ func TestNextTableToPurge(t *testing.T) { ok: true, }, { + name: "mid", tables: []string{ "_vt_PURGE_2ace8bcef73211ea87e9f875a4d24e90_20200915120411", "_vt_PURGE_3ace8bcef73211ea87e9f875a4d24e90_20200915120412", @@ -57,19 +61,69 @@ func TestNextTableToPurge(t *testing.T) { next: "_vt_PURGE_6ace8bcef73211ea87e9f875a4d24e90_20200915120410", ok: true, }, + { + name: "none", + tables: []string{ + "_vt_HOLD_2ace8bcef73211ea87e9f875a4d24e90_20200915120411", + "_vt_EVAC_3ace8bcef73211ea87e9f875a4d24e90_20200915120412", + "_vt_EVAC_6ace8bcef73211ea87e9f875a4d24e90_20200915120410", + "_vt_DROP_4ace8bcef73211ea87e9f875a4d24e90_20200915120413", + }, + next: "", + ok: false, + }, + { + name: "first, new format", + tables: []string{ + "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_", + "_vt_prg_2ace8bcef73211ea87e9f875a4d24e90_20200915120411_", + "_vt_prg_3ace8bcef73211ea87e9f875a4d24e90_20200915120412_", + "_vt_prg_4ace8bcef73211ea87e9f875a4d24e90_20200915120413_", + }, + next: "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_", + ok: true, + }, + { + name: "mid, new format", + tables: []string{ + "_vt_prg_2ace8bcef73211ea87e9f875a4d24e90_20200915120411_", + "_vt_prg_3ace8bcef73211ea87e9f875a4d24e90_20200915120412_", + "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_", + "_vt_prg_4ace8bcef73211ea87e9f875a4d24e90_20200915120413_", + }, + next: "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_", + ok: true, + }, + { + name: "none, new format", + tables: []string{ + "_vt_hld_2ace8bcef73211ea87e9f875a4d24e90_20200915120411_", + "_vt_evc_3ace8bcef73211ea87e9f875a4d24e90_20200915120412_", + "_vt_evc_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_", + "_vt_drp_4ace8bcef73211ea87e9f875a4d24e90_20200915120413_", + "_vt_prg_4ace8bcef73211ea87e9f875a4d24e90_20200915999999_", + }, + next: "", + ok: false, + }, } for _, ts := range tt { - collector := &TableGC{ - purgingTables: make(map[string]bool), - } - for _, table := range ts.tables { - collector.purgingTables[table] = true - } - next, ok := collector.nextTableToPurge() - assert.Equal(t, ts.ok, ok) - if ok { - assert.Equal(t, ts.next, next) - } + t.Run(ts.name, func(t *testing.T) { + collector := &TableGC{ + purgingTables: make(map[string]bool), + } + var err error + collector.lifecycleStates, err = schema.ParseGCLifecycle("hold,purge,evac,drop") + assert.NoError(t, err) + for _, table := range ts.tables { + collector.addPurgingTable(table) + } + next, ok := collector.nextTableToPurge() + assert.Equal(t, ts.ok, ok) + if ok { + assert.Equal(t, ts.next, next) + } + }) } } @@ -171,6 +225,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "6ace8bcef73211ea87e9f875a4d24e90", shouldTransition: true, }, + { + name: "purge, old timestamp, new format", + table: "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_20200915120410_", + state: schema.PurgeTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + shouldTransition: true, + }, { name: "no purge, future timestamp", table: "_vt_PURGE_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -178,6 +239,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "6ace8bcef73211ea87e9f875a4d24e90", shouldTransition: false, }, + { + name: "no purge, future timestamp, new format", + table: "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_29990915120410_", + state: schema.PurgeTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + shouldTransition: false, + }, { name: "no purge, PURGE not handled state", table: "_vt_PURGE_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -186,6 +254,14 @@ func TestShouldTransitionTable(t *testing.T) { handledStates: "hold,evac", // no PURGE shouldTransition: true, }, + { + name: "no purge, PURGE not handled state, new format", + table: "_vt_prg_6ace8bcef73211ea87e9f875a4d24e90_29990915120410_", + state: schema.PurgeTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + handledStates: "hold,evac", // no PURGE + shouldTransition: true, + }, { name: "no drop, future timestamp", table: "_vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -193,6 +269,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "6ace8bcef73211ea87e9f875a4d24e90", shouldTransition: false, }, + { + name: "no drop, future timestamp, new format", + table: "_vt_drp_6ace8bcef73211ea87e9f875a4d24e90_29990915120410_", + state: schema.DropTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + shouldTransition: false, + }, { name: "drop, old timestamp", table: "_vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20090915120410", @@ -200,6 +283,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "6ace8bcef73211ea87e9f875a4d24e90", shouldTransition: true, }, + { + name: "drop, old timestamp, new format", + table: "_vt_drp_6ace8bcef73211ea87e9f875a4d24e90_20090915120410_", + state: schema.DropTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + shouldTransition: true, + }, { name: "no evac, future timestamp", table: "_vt_EVAC_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -207,6 +297,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "6ace8bcef73211ea87e9f875a4d24e90", shouldTransition: false, }, + { + name: "no evac, future timestamp, new format", + table: "_vt_evc_6ace8bcef73211ea87e9f875a4d24e90_29990915120410_", + state: schema.EvacTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + shouldTransition: false, + }, { name: "no hold, HOLD not handled state", table: "_vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -214,6 +311,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "6ace8bcef73211ea87e9f875a4d24e90", shouldTransition: true, }, + { + name: "no hold, HOLD not handled state, new format", + table: "_vt_hld_6ace8bcef73211ea87e9f875a4d24e90_29990915120410_", + state: schema.HoldTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + shouldTransition: true, + }, { name: "hold, future timestamp", table: "_vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -222,6 +326,14 @@ func TestShouldTransitionTable(t *testing.T) { handledStates: "hold,purge,evac,drop", shouldTransition: false, }, + { + name: "hold, future timestamp, new format", + table: "_vt_hld_6ace8bcef73211ea87e9f875a4d24e90_29990915120410_", + state: schema.HoldTableGCState, + uuid: "6ace8bcef73211ea87e9f875a4d24e90", + handledStates: "hold,purge,evac,drop", + shouldTransition: false, + }, { name: "not a GC table", table: "_vt_SOMETHING_6ace8bcef73211ea87e9f875a4d24e90_29990915120410", @@ -229,6 +341,13 @@ func TestShouldTransitionTable(t *testing.T) { uuid: "", shouldTransition: false, }, + { + name: "invalid new format", + table: "_vt_hld_6ace8bcef73211ea87e9f875a4d24e90_29990915999999_", + state: "", + uuid: "", + shouldTransition: false, + }, } for _, ts := range tt { t.Run(ts.name, func(t *testing.T) { @@ -268,35 +387,70 @@ func TestCheckTables(t *testing.T) { tableName: "_vt_something_that_isnt_a_gc_table", isBaseTable: true, }, + { + tableName: "_vt_hld_6ace8bcef73211ea87e9f875a4d24e90_29990915999999_", + isBaseTable: true, + }, { tableName: "_vt_HOLD_11111111111111111111111111111111_20990920093324", // 2099 is in the far future isBaseTable: true, }, + { + tableName: "_vt_hld_11111111111111111111111111111111_20990920093324_", // 2099 is in the far future + isBaseTable: true, + }, { tableName: "_vt_HOLD_22222222222222222222222222222222_20200920093324", isBaseTable: true, }, + { + tableName: "_vt_hld_22222222222222222222222222222222_20200920093324_", + isBaseTable: true, + }, { tableName: "_vt_DROP_33333333333333333333333333333333_20200919083451", isBaseTable: true, }, + { + tableName: "_vt_drp_33333333333333333333333333333333_20200919083451_", + isBaseTable: true, + }, { tableName: "_vt_DROP_44444444444444444444444444444444_20200919083451", isBaseTable: false, }, + { + tableName: "_vt_drp_44444444444444444444444444444444_20200919083451_", + isBaseTable: false, + }, } - // one gcTable above is irrelevant, does not have a GC table name + expectResponses := len(gcTables) + // one gcTable above is irrelevant: it does not have a GC table name + expectResponses = expectResponses - 1 // one will not transition: its date is 2099 - expectResponses := len(gcTables) - 2 + expectResponses = expectResponses - 1 + // one gcTable above is irrelevant: it has an invalid new format timestamp + expectResponses = expectResponses - 1 + // one will not transition: its date is 2099 in new format + expectResponses = expectResponses - 1 + expectDropTables := []*gcTable{ { tableName: "_vt_DROP_33333333333333333333333333333333_20200919083451", isBaseTable: true, }, + { + tableName: "_vt_drp_33333333333333333333333333333333_20200919083451_", + isBaseTable: true, + }, { tableName: "_vt_DROP_44444444444444444444444444444444_20200919083451", isBaseTable: false, }, + { + tableName: "_vt_drp_44444444444444444444444444444444_20200919083451_", + isBaseTable: false, + }, } expectTransitionRequests := []*transitionRequest{ { @@ -305,6 +459,12 @@ func TestCheckTables(t *testing.T) { toGCState: schema.PurgeTableGCState, uuid: "22222222222222222222222222222222", }, + { + fromTableName: "_vt_hld_22222222222222222222222222222222_20200920093324_", + isBaseTable: true, + toGCState: schema.PurgeTableGCState, + uuid: "22222222222222222222222222222222", + }, } ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)