Skip to content

Commit

Permalink
*: fix show placement for v2 (#51577)
Browse files Browse the repository at this point in the history
ref #50959
  • Loading branch information
ywqzzy authored Mar 7, 2024
1 parent d9a3b73 commit c128a2d
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions pkg/executor/show_placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (e *ShowExec) fetchShowPlacementForDB(ctx context.Context) (err error) {
}

if placement != nil {
state, err := fetchDBScheduleState(ctx, nil, dbInfo)
state, err := e.fetchDBScheduleState(ctx, nil, dbInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func (e *ShowExec) fetchAllDBPlacements(ctx context.Context, scheduleState map[i
}

if placement != nil {
state, err := fetchDBScheduleState(ctx, scheduleState, dbInfo)
state, err := e.fetchDBScheduleState(ctx, scheduleState, dbInfo)
if err != nil {
return err
}
Expand All @@ -343,6 +343,22 @@ func (e *ShowExec) fetchAllDBPlacements(ctx context.Context, scheduleState map[i
return nil
}

func (e *ShowExec) fetchDBScheduleState(ctx context.Context, scheduleState map[int64]infosync.PlacementScheduleState, db *model.DBInfo) (infosync.PlacementScheduleState, error) {
state := infosync.PlacementScheduleStateScheduled
for _, table := range e.is.SchemaTables(db.Name) {
tbl := table.Meta()
schedule, err := fetchTableScheduleState(ctx, scheduleState, tbl)
if err != nil {
return state, err
}
state = accumulateState(state, schedule)
if state != infosync.PlacementScheduleStateScheduled {
break
}
}
return state, nil
}

type tableRowSet struct {
name string
rows [][]any
Expand Down Expand Up @@ -501,21 +517,6 @@ func fetchTableScheduleState(ctx context.Context, scheduleState map[int64]infosy
return schedule, nil
}

func fetchDBScheduleState(ctx context.Context, scheduleState map[int64]infosync.PlacementScheduleState, db *model.DBInfo) (infosync.PlacementScheduleState, error) {
state := infosync.PlacementScheduleStateScheduled
for _, table := range db.Tables {
schedule, err := fetchTableScheduleState(ctx, scheduleState, table)
if err != nil {
return state, err
}
state = accumulateState(state, schedule)
if state != infosync.PlacementScheduleStateScheduled {
break
}
}
return state, nil
}

func accumulateState(curr, news infosync.PlacementScheduleState) infosync.PlacementScheduleState {
a, b := int(curr), int(news)
if a > b {
Expand Down

0 comments on commit c128a2d

Please sign in to comment.