MCPcopy Create free account
hub / github.com/ethstorage/es-node / cleanTasks

Method cleanTasks

ethstorage/p2p/protocol/syncclient.go:457–497  ·  view source on GitHub ↗

cleanTasks removes kv range retrieval tasks that have already been completed.

()

Source from the content-addressed store, hash-verified

455
456// cleanTasks removes kv range retrieval tasks that have already been completed.
457func (s *SyncClient) cleanTasks() {
458 // Sync wasn't finished previously, check for any subTask that can be finalized
459 s.lock.Lock()
460 defer s.lock.Unlock()
461 allDone := true
462 for _, t := range s.tasks {
463 for i := 0; i < len(t.SubTasks); i++ {
464 exist, first := t.healTask.hasIndexInRange(t.SubTasks[i].First, t.SubTasks[i].next)
465 // if existed, min will be the smallest index in range [subTask.First, subTask.next)
466 // if no exist, min will be next, so subTask.First can directly set to subTask.next
467 t.SubTasks[i].First = first
468 if t.SubTasks[i].done && !exist {
469 t.SubTasks = append(t.SubTasks[:i], t.SubTasks[i+1:]...)
470 if t.nextIdx > i {
471 t.nextIdx--
472 }
473 i--
474 }
475 }
476 for i := 0; i < len(t.SubEmptyTasks); i++ {
477 if t.SubEmptyTasks[i].done {
478 t.SubEmptyTasks = append(t.SubEmptyTasks[:i], t.SubEmptyTasks[i+1:]...)
479 i--
480 }
481 }
482 if len(t.SubTasks) > 0 || len(t.SubEmptyTasks) > 0 {
483 allDone = false
484 } else if !t.done {
485 t.done = true
486 if s.mux != nil {
487 s.mux.Send(EthStorageSyncDone{DoneType: SingleShardDone, ShardId: t.ShardId})
488 }
489 }
490 }
491
492 // If everything was just finalized, generate the account trie and origin heal
493 if allDone {
494 s.setSyncDone()
495 s.lg.Info("Storage sync done", "subTaskCount", len(s.tasks))
496 }
497}
498
499func (s *SyncClient) Start() error {
500 // Retrieve the previous sync status from LevelDB and abort if already synced

Callers 3

CloseMethod · 0.95
mainLoopMethod · 0.95

Calls 2

setSyncDoneMethod · 0.95
hasIndexInRangeMethod · 0.80

Tested by 1