Skip to content

Commit

Permalink
Backport to v11 vitessio#8634 reset table size stats when a table is …
Browse files Browse the repository at this point in the history
…dropped

schema engine: reset table size stats when a table is dropped

Signed-off-by: deepthi <[email protected]>
Signed-off-by: Vilius Okockis <[email protected]>
  • Loading branch information
deepthi authored and DeathBorn committed Apr 13, 2023
1 parent 8a1032b commit 862e317
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ func (se *Engine) reload(ctx context.Context) error {
if !curTables[tableName] {
dropped = append(dropped, tableName)
delete(se.tables, tableName)
// We can't actually delete the label from the stats, but we can set it to 0.
// Many monitoring tools will drop zero-valued metrics.
se.tableFileSizeGauge.Reset(tableName)
se.tableAllocatedSizeGauge.Reset(tableName)
}
}

Expand Down
2 changes: 2 additions & 0 deletions go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func TestOpenAndReload(t *testing.T) {
}
delete(want, "msg")
assert.Equal(t, want, se.GetSchema())
assert.Equal(t, int64(0), se.tableAllocatedSizeGauge.Counts()["msg"])
assert.Equal(t, int64(0), se.tableFileSizeGauge.Counts()["msg"])

//ReloadAt tests
pos1, err := mysql.DecodePosition("MariaDB/0-41983-20")
Expand Down

0 comments on commit 862e317

Please sign in to comment.