Skip to content

Commit

Permalink
sync now correctly tracks first Migrate() IDs/hashes
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Moore <[email protected]>
  • Loading branch information
jimmyaxod committed Nov 4, 2024
1 parent dac97b6 commit e9f0d72
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/storage/migrator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Syncer struct {
}

type BlockStatus struct {
Set bool
UpdatingID uint64
CurrentID uint64
CurrentHash [sha256.Size]byte
Expand All @@ -57,6 +58,7 @@ func NewSyncer(ctx context.Context, sinfo *SyncConfig) *Syncer {
status := make([]BlockStatus, numBlocks)
for b := 0; b < int(numBlocks); b++ {
status[b] = BlockStatus{
Set: false,
UpdatingID: 0,
CurrentID: 0,
CurrentHash: [sha256.Size]byte{},
Expand All @@ -79,7 +81,7 @@ func (s *Syncer) GetSafeBlockMap() map[uint][sha256.Size]byte {
blocks := make(map[uint][sha256.Size]byte, 0)

for b, status := range s.blockStatus {
if status.CurrentID > 0 && status.CurrentID == status.UpdatingID {
if status.Set && status.CurrentID == status.UpdatingID {
blocks[uint(b)] = status.CurrentHash
}
}
Expand Down Expand Up @@ -154,7 +156,10 @@ func (s *Syncer) Sync(syncAllFirst bool, continuous bool) (*MigrationProgress, e
hash := sha256.Sum256(data)

s.blockStatusLock.Lock()
if id > s.blockStatus[b.Block].CurrentID {
if !s.blockStatus[b.Block].Set {
s.blockStatus[b.Block].Set = true
s.blockStatus[b.Block].CurrentHash = hash
} else if id > s.blockStatus[b.Block].CurrentID {
s.blockStatus[b.Block].CurrentID = id
s.blockStatus[b.Block].CurrentHash = hash
}
Expand Down

0 comments on commit e9f0d72

Please sign in to comment.