Skip to content

Commit

Permalink
test new formats
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Nov 27, 2023
1 parent 068433a commit 3f0d8b0
Showing 1 changed file with 173 additions and 13 deletions.
186 changes: 173 additions & 13 deletions go/vt/vttablet/tabletserver/gc/tablegc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -48,6 +51,7 @@ func TestNextTableToPurge(t *testing.T) {
ok: true,
},
{
name: "mid",
tables: []string{
"_vt_PURGE_2ace8bcef73211ea87e9f875a4d24e90_20200915120411",
"_vt_PURGE_3ace8bcef73211ea87e9f875a4d24e90_20200915120412",
Expand All @@ -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)
}
})
}
}

Expand Down Expand Up @@ -171,13 +225,27 @@ 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",
state: schema.PurgeTableGCState,
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",
Expand All @@ -186,34 +254,70 @@ 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",
state: schema.DropTableGCState,
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",
state: schema.DropTableGCState,
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",
state: schema.EvacTableGCState,
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",
state: schema.HoldTableGCState,
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",
Expand All @@ -222,13 +326,28 @@ 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",
state: "",
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) {
Expand Down Expand Up @@ -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{
{
Expand All @@ -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)
Expand Down

0 comments on commit 3f0d8b0

Please sign in to comment.