Skip to content
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
9 changes: 5 additions & 4 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"strings"
"sync"
"sync/atomic"
"time"

"golang.org/x/exp/maps"
Expand Down Expand Up @@ -71,7 +72,7 @@ type Engine struct {
mu sync.Mutex
isOpen bool
tables map[string]*Table
lastChange int64
lastChange atomic.Int64
// the position at which the schema was last loaded. it is only used in conjunction with ReloadAt
reloadAtPos replication.Position
notifierMu sync.Mutex
Expand Down Expand Up @@ -319,7 +320,7 @@ func (se *Engine) closeLocked() {
se.conns.Close()

se.tables = make(map[string]*Table)
se.lastChange = 0
se.lastChange.Store(0)
se.notifiers = make(map[string]notifier)
se.isOpen = false

Expand Down Expand Up @@ -553,7 +554,7 @@ func (se *Engine) reload(ctx context.Context, includeStats bool) error {
tbl, isInTablesMap := se.tables[tableName]
_, isInChangedViewMap := changedViews[tableName]
_, isInMismatchTableMap := mismatchTables[tableName]
if isInTablesMap && createTime == tbl.CreateTime && createTime < se.lastChange && !isInChangedViewMap && !isInMismatchTableMap {
if isInTablesMap && createTime == tbl.CreateTime && createTime < se.lastChange.Load() && !isInChangedViewMap && !isInMismatchTableMap {
if includeStats {
tbl.FileSize = fileSize
tbl.AllocatedSize = allocatedSize
Expand Down Expand Up @@ -616,7 +617,7 @@ func (se *Engine) reload(ctx context.Context, includeStats bool) error {
for k, t := range changedTables {
se.tables[k] = t
}
se.lastChange = curTime
se.lastChange.Store(curTime)
if len(created) > 0 || len(altered) > 0 || len(dropped) > 0 {
log.Infof("schema engine created %v, altered %v, dropped %v", extractNamesFromTablesList(created), extractNamesFromTablesList(altered), extractNamesFromTablesList(dropped))
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ func TestEngineReload(t *testing.T) {
require.NoError(t, err)

se.SkipMetaCheck = false
se.lastChange = 987654321
se.lastChange.Store(987654321)

// Initial tables in the schema engine
se.tables = map[string]*Table{
Expand Down
Loading