Skip to content
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

Table lifecycle: skip time hint for unspecified states #7151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions go/vt/vttablet/tabletserver/gc/tablegc.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ func (collector *TableGC) submitTransitionRequest(ctx context.Context, fromState
}()
}

// shouldTransitionTable checks if the given table is a GC table and if it's time to transition it to next state
func (collector *TableGC) shouldTransitionTable(tableName string) (shouldTransition bool, state schema.TableGCState, err error) {
isGCTable, state, t, err := schema.AnalyzeGCTableName(tableName)
if err != nil {
return false, state, err
}
if !isGCTable {
// irrelevant table
return false, state, nil
}
if _, ok := collector.lifecycleStates[state]; ok {
// this state is in our expected lifecycle. Let's check table's time hint:
timeNow := time.Now().UTC()
if timeNow.Before(t) {
// not yet time to operate on this table
return false, state, nil
}
// If the state is not in our expected lifecycle, we ignore the time hint and just move it to the next phase
}
return true, state, nil
}

// checkTables looks for potential GC tables in the MySQL server+schema.
// It lists _vt_% tables, then filters through those which are due-date.
// It then applies the necessary operation per table.
Expand All @@ -350,20 +372,17 @@ func (collector *TableGC) checkTables(ctx context.Context) error {
for _, row := range res.Rows {
tableName := row[0].ToString()

isGCTable, state, t, err := schema.AnalyzeGCTableName(tableName)
shouldTransition, state, err := collector.shouldTransitionTable(tableName)

if err != nil {
log.Errorf("TableGC: error while checking tables: %+v", err)
continue
}
timeNow := time.Now().UTC()
if !isGCTable {
if !shouldTransition {
// irrelevant table
continue
}
if timeNow.Before(t) {
// net yet time to operate on this table
continue
}

log.Infof("TableGC: will operate on table %s", tableName)

if state == schema.HoldTableGCState {
Expand Down
61 changes: 61 additions & 0 deletions go/vt/vttablet/tabletserver/gc/tablegc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,64 @@ func TestNextState(t *testing.T) {
assert.Nil(t, postDrop)
}
}

func TestShouldTransitionTable(t *testing.T) {
tt := []struct {
table string
state schema.TableGCState
shouldTransition bool
isError bool
}{
{
table: "_vt_PURGE_6ace8bcef73211ea87e9f875a4d24e90_20200915120410",
state: schema.PurgeTableGCState,
shouldTransition: true,
},
{
table: "_vt_PURGE_6ace8bcef73211ea87e9f875a4d24e90_29990915120410",
state: schema.PurgeTableGCState,
shouldTransition: false,
},
{
table: "_vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_29990915120410",
state: schema.DropTableGCState,
shouldTransition: false,
},
{
table: "_vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20090915120410",
state: schema.DropTableGCState,
shouldTransition: true,
},
{
table: "_vt_EVAC_6ace8bcef73211ea87e9f875a4d24e90_29990915120410",
state: schema.EvacTableGCState,
shouldTransition: false,
},
{
table: "_vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_29990915120410",
state: schema.HoldTableGCState,
shouldTransition: true,
},
{
table: "_vt_SOMETHING_6ace8bcef73211ea87e9f875a4d24e90_29990915120410",
state: "",
shouldTransition: false,
},
}
lifecycleStates, err := schema.ParseGCLifecycle("purge,evac,drop")
assert.NoError(t, err)
collector := &TableGC{
lifecycleStates: lifecycleStates,
}
for _, ts := range tt {
shouldTransition, state, err := collector.shouldTransitionTable(ts.table)
if ts.isError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, ts.shouldTransition, shouldTransition)
assert.Equal(t, ts.state, state)

}
}
}