Skip to content

Commit

Permalink
*: fix schema store log (pingcap#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu authored Jan 24, 2025
1 parent 7a53695 commit aa798a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
36 changes: 8 additions & 28 deletions logservice/schemastore/multi_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
)

type tableInfoItem struct {
version uint64
info *common.TableInfo
Version uint64
Info *common.TableInfo
}

type versionedTableInfoStore struct {
Expand Down Expand Up @@ -64,7 +64,7 @@ func (v *versionedTableInfoStore) addInitialTableInfo(info *common.TableInfo, ve
v.mu.Lock()
defer v.mu.Unlock()
// assertEmpty(v.infos)
v.infos = append(v.infos, &tableInfoItem{version: version, info: info})
v.infos = append(v.infos, &tableInfoItem{Version: version, Info: info})
}

func (v *versionedTableInfoStore) getTableID() int64 {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (v *versionedTableInfoStore) getTableInfo(ts uint64) (*common.TableInfo, er
}

target := sort.Search(len(v.infos), func(i int) bool {
return v.infos[i].version > ts
return v.infos[i].Version > ts
})
if target == 0 {
log.Error("no version found",
Expand All @@ -127,7 +127,7 @@ func (v *versionedTableInfoStore) getTableInfo(ts uint64) (*common.TableInfo, er
zap.Any("deleteVersion", v.deleteVersion))
return nil, errors.New("no version found")
}
return v.infos[target-1].info, nil
return v.infos[target-1].Info, nil
}

// only keep one item with the largest version <= gcTS, return whether the store should be totally removed
Expand All @@ -146,7 +146,7 @@ func (v *versionedTableInfoStore) gc(gcTs uint64) bool {
}

target := sort.Search(len(v.infos), func(i int) bool {
return v.infos[i].version > gcTs
return v.infos[i].Version > gcTs
})
if target == 0 {
return false
Expand All @@ -159,26 +159,6 @@ func (v *versionedTableInfoStore) gc(gcTs uint64) bool {
return false
}

func assertEmpty(infos []*tableInfoItem, event *PersistedDDLEvent) {
if len(infos) != 0 {
log.Panic("shouldn't happen",
zap.Any("infosLen", len(infos)),
zap.Any("lastVersion", infos[len(infos)-1].version),
zap.String("query", event.Query),
zap.Int64("tableID", event.CurrentTableID),
zap.Uint64("finishedTs", event.FinishedTs),
zap.Int64("schemaVersion", event.SchemaVersion))
}
}

func assertNonEmpty(infos []*tableInfoItem, event *PersistedDDLEvent) {
if len(infos) == 0 {
log.Panic("shouldn't happen",
zap.Any("infos", infos),
zap.String("query", event.Query))
}
}

func assertNonDeleted(v *versionedTableInfoStore) {
if v.deleteVersion != uint64(math.MaxUint64) {
log.Panic("shouldn't happen", zap.Uint64("deleteVersion", v.deleteVersion))
Expand Down Expand Up @@ -213,7 +193,7 @@ func (v *versionedTableInfoStore) applyDDL(event *PersistedDDLEvent) {

// lock must be hold by the caller
func (v *versionedTableInfoStore) doApplyDDL(event *PersistedDDLEvent) {
if len(v.infos) != 0 && event.FinishedTs <= v.infos[len(v.infos)-1].version {
if len(v.infos) != 0 && event.FinishedTs <= v.infos[len(v.infos)-1].Version {
log.Warn("already applied ddl, ignore it.",
zap.Int64("tableID", v.tableID),
zap.String("query", event.Query),
Expand All @@ -228,7 +208,7 @@ func (v *versionedTableInfoStore) doApplyDDL(event *PersistedDDLEvent) {
}
tableInfo, deleted := handler.extractTableInfoFunc(event, v.tableID)
if tableInfo != nil {
v.infos = append(v.infos, &tableInfoItem{version: event.FinishedTs, info: tableInfo})
v.infos = append(v.infos, &tableInfoItem{Version: event.FinishedTs, Info: tableInfo})
if ddlType == model.ActionRecoverTable {
v.deleteVersion = math.MaxUint64
}
Expand Down
6 changes: 3 additions & 3 deletions logservice/schemastore/multi_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func TestGCMultiVersionTableInfo(t *testing.T) {
store := newEmptyVersionedTableInfoStore(tableID)
store.setTableInfoInitialized()

store.infos = append(store.infos, &tableInfoItem{version: 100, info: &common.TableInfo{}})
store.infos = append(store.infos, &tableInfoItem{version: 200, info: &common.TableInfo{}})
store.infos = append(store.infos, &tableInfoItem{version: 300, info: &common.TableInfo{}})
store.infos = append(store.infos, &tableInfoItem{Version: 100, Info: &common.TableInfo{}})
store.infos = append(store.infos, &tableInfoItem{Version: 200, Info: &common.TableInfo{}})
store.infos = append(store.infos, &tableInfoItem{Version: 300, Info: &common.TableInfo{}})
store.deleteVersion = 1000

require.False(t, store.gc(200))
Expand Down

0 comments on commit aa798a0

Please sign in to comment.