| 244 | } |
| 245 | |
| 246 | func (s *SyncClient) loadSyncStatus() { |
| 247 | var progress SyncProgress |
| 248 | |
| 249 | if status, _ := s.db.Get(SyncTasksKey); status != nil { |
| 250 | if err := json.Unmarshal(status, &progress); err != nil { |
| 251 | s.lg.Error("Failed to decode storage sync status", "err", err) |
| 252 | } else { |
| 253 | for _, t := range progress.Tasks { |
| 254 | s.lg.Debug("Load sync subTask", "contract", t.Contract.Hex(), |
| 255 | "shard", t.ShardId, "count", len(t.SubTasks)) |
| 256 | t.healTask = &healTask{ |
| 257 | Indexes: make(map[uint64]int64), |
| 258 | task: t, |
| 259 | } |
| 260 | t.statelessPeers = make(map[peer.ID]struct{}) |
| 261 | for _, sTask := range t.SubTasks { |
| 262 | sTask.task = t |
| 263 | sTask.next = sTask.First |
| 264 | } |
| 265 | for _, sEmptyTask := range t.SubEmptyTasks { |
| 266 | sEmptyTask.task = t |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | var states map[uint64]*SyncState |
| 273 | if status, _ := s.db.Get(SyncStatusKey); status != nil { |
| 274 | if err := json.Unmarshal(status, &states); err != nil { |
| 275 | s.lg.Error("Failed to decode storage sync status", "err", err) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // create tasks |
| 280 | lastKvIndex := s.storageManager.KvEntryCount() |
| 281 | for _, sid := range s.storageManager.Shards() { |
| 282 | exist := false |
| 283 | for _, t := range progress.Tasks { |
| 284 | if t.Contract == s.storageManager.ContractAddress() && t.ShardId == sid { |
| 285 | if states != nil { |
| 286 | if state, ok := states[t.ShardId]; ok { |
| 287 | state.PeerCount = 0 |
| 288 | t.state = state |
| 289 | } |
| 290 | } |
| 291 | if t.state == nil { |
| 292 | |
| 293 | // TODO if t.state is nil, that mean the status is marshal by old state, |
| 294 | // set process value to SyncState to make it compatible. |
| 295 | // it can be removed after public test done. |
| 296 | t.state = &SyncState{ |
| 297 | PeerCount: 0, |
| 298 | BlobsToSync: 0, |
| 299 | BlobsSynced: progress.BlobsSynced, |
| 300 | SyncProgress: 0, |
| 301 | SyncedSeconds: progress.TotalSecondsUsed, |
| 302 | EmptyFilled: progress.EmptyBlobsFilled, |
| 303 | EmptyToFill: 0, |