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

Method createTask

ethstorage/p2p/protocol/syncclient.go:326–400  ·  view source on GitHub ↗
(sid uint64, lastKvIndex uint64)

Source from the content-addressed store, hash-verified

324}
325
326func (s *SyncClient) createTask(sid uint64, lastKvIndex uint64) *task {
327 task := task{
328 Contract: s.storageManager.ContractAddress(),
329 ShardId: sid,
330 nextIdx: 0,
331 statelessPeers: make(map[peer.ID]struct{}),
332 state: &SyncState{
333 PeerCount: 0,
334 BlobsToSync: 0,
335 BlobsSynced: 0,
336 SyncProgress: 0,
337 SyncedSeconds: 0,
338 EmptyFilled: 0,
339 EmptyToFill: 0,
340 FillEmptySeconds: 0,
341 FillEmptyProgress: 0,
342 },
343 }
344
345 healTask := healTask{
346 task: &task,
347 Indexes: make(map[uint64]int64),
348 }
349
350 first, limit := s.storageManager.KvEntries()*sid, s.storageManager.KvEntries()*(sid+1)
351 firstEmpty, limitForEmpty := uint64(0), uint64(0)
352 if first >= lastKvIndex {
353 firstEmpty, limitForEmpty = first, limit
354 limit = first
355 } else if limit >= lastKvIndex {
356 firstEmpty, limitForEmpty = lastKvIndex, limit
357 limit = lastKvIndex
358 }
359
360 subTasks := make([]*subTask, 0)
361 // split subTask for a shard to 16 subtasks and if one batch is too small
362 // set to minSubTaskSize
363 maxTaskSize := max((limit-first+s.syncerParams.SyncConcurrency-1)/s.syncerParams.SyncConcurrency, minSubTaskSize)
364
365 for first < limit {
366 last := min(first+maxTaskSize, limit)
367 subTask := subTask{
368 task: &task,
369 next: first,
370 First: first,
371 Last: last,
372 done: false,
373 }
374
375 subTasks = append(subTasks, &subTask)
376 first = last
377 }
378
379 subEmptyTasks := make([]*subEmptyTask, 0)
380 if limitForEmpty > 0 {
381 task.state.EmptyToFill = limitForEmpty - firstEmpty
382 maxEmptyTaskSize := max((limitForEmpty-firstEmpty+uint64(maxFillEmptyTaskTreads)-1)/uint64(maxFillEmptyTaskTreads), minSubTaskSize)
383

Callers 1

loadSyncStatusMethod · 0.95

Calls 2

ContractAddressMethod · 0.65
KvEntriesMethod · 0.65

Tested by

no test coverage detected