Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

analyze: analyze table after restore #605

Merged
merged 23 commits into from
Nov 26, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix ci failed
  • Loading branch information
3pointer committed Nov 25, 2020
commit 90f2340bccc09ce339b359f57f40e2a9dc24b7fe
27 changes: 17 additions & 10 deletions pkg/restore/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,52 +68,59 @@ func newDrySender() *drySender {
}
}

type recordCurrentTableManager map[int64]bool
type recordCurrentTableManager struct {
sync.Mutex
m map[int64]bool
}

func (manager recordCurrentTableManager) Close(ctx context.Context) {
if len(manager) > 0 {
if len(manager.m) > 0 {
log.Panic("When closing, there are still some tables doesn't be sent",
zap.Any("tables", manager))
zap.Any("tables", manager.m))
}
}

func newMockManager() recordCurrentTableManager {
return make(recordCurrentTableManager)
return make(map[int64]bool)
}

func (manager recordCurrentTableManager) Enter(_ context.Context, tables []restore.CreatedTable) error {
for _, t := range tables {
log.Info("entering", zap.Int64("table ID", t.Table.ID))
manager[t.Table.ID] = true
manager.Lock()
manager.m[t.Table.ID] = true
manager.Unlock()
}
return nil
}

func (manager recordCurrentTableManager) Leave(_ context.Context, tables []restore.CreatedTable) error {
for _, t := range tables {
if !manager[t.Table.ID] {
manager.Lock()
if !manager.m[t.Table.ID] {
return errors.Errorf("Table %d is removed before added", t.Table.ID)
}
log.Info("leaving", zap.Int64("table ID", t.Table.ID))
delete(manager, t.Table.ID)
delete(manager.m, t.Table.ID)
manager.Unlock()
}
return nil
}

func (manager recordCurrentTableManager) Has(tables ...restore.TableWithRange) bool {
ids := make([]int64, 0, len(tables))
currentIDs := make([]int64, 0, len(manager))
currentIDs := make([]int64, 0, len(manager.m))
for _, t := range tables {
ids = append(ids, t.Table.ID)
}
for id, contains := range manager {
for id, contains := range manager.m {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read option should be protected by lock

if contains {
currentIDs = append(currentIDs, id)
}
}
log.Info("testing", zap.Int64s("should has ID", ids), zap.Int64s("has ID", currentIDs))
for _, i := range ids {
if !manager[i] {
if !manager.m[i] {
return false
}
}
Expand Down