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

Method saveSyncStatus

ethstorage/p2p/protocol/syncclient.go:403–437  ·  view source on GitHub ↗

saveSyncStatus marshals the remaining sync tasks into leveldb.

()

Source from the content-addressed store, hash-verified

401
402// saveSyncStatus marshals the remaining sync tasks into leveldb.
403func (s *SyncClient) saveSyncStatus() {
404 s.lock.Lock()
405 defer s.lock.Unlock()
406 // Store the actual progress markers
407 progress := &SyncProgress{
408 Tasks: s.tasks,
409 // TODO remote it before next test net
410 BlobsSynced: 0,
411 SyncedBytes: 0,
412 EmptyBlobsToFill: 0,
413 EmptyBlobsFilled: 0,
414 TotalSecondsUsed: 0,
415 }
416 status, err := json.Marshal(progress)
417 if err != nil {
418 panic(err) // This can only fail during implementation
419 }
420 if err := s.db.Put(SyncTasksKey, status); err != nil {
421 s.lg.Error("Failed to store sync tasks", "err", err)
422 }
423 s.lg.Debug("Save sync state to DB")
424
425 // save sync states to DB for status reporting
426 states := make(map[uint64]*SyncState)
427 for _, t := range s.tasks {
428 states[t.ShardId] = t.state
429 }
430 status, err = json.Marshal(states)
431 if err != nil {
432 panic(err) // This can only fail during implementation
433 }
434 if err := s.db.Put(SyncStatusKey, status); err != nil {
435 s.lg.Error("Failed to store sync states", "err", err)
436 }
437}
438
439// saveStatusLoop marshals the remaining sync tasks into leveldb.
440func (s *SyncClient) saveStatusLoop() {

Callers 4

saveStatusLoopMethod · 0.95
CloseMethod · 0.95
mainLoopMethod · 0.95

Calls 1

ErrorMethod · 0.45

Tested by 1