MCPcopy Create free account
hub / github.com/pydio/cells / RootStats

Method RootStats

common/sync/task/sync.go:284–344  ·  view source on GitHub ↗
(ctx context.Context, useSnapshots bool)

Source from the content-addressed store, hash-verified

282}
283
284func (s *Sync) RootStats(ctx context.Context, useSnapshots bool) (map[string]*model.EndpointRootStat, error) {
285
286 endpoints := map[string]model.Endpoint{
287 s.Source.GetEndpointInfo().URI: s.Source,
288 s.Target.GetEndpointInfo().URI: s.Target,
289 }
290 if useSnapshots && s.Direction == model.DirectionBi && s.snapshotFactory != nil {
291 source, _ := model.AsPathSyncSource(s.Source)
292 targetAsSource, _ := model.AsPathSyncSource(s.Target)
293 if leftSnap, err := s.snapshotFactory.Load(source); err == nil {
294 endpoints[source.GetEndpointInfo().URI] = leftSnap
295 }
296 if rightSnap, err := s.snapshotFactory.Load(targetAsSource); err == nil {
297 endpoints[s.Target.GetEndpointInfo().URI] = rightSnap
298 }
299 }
300 lock := sync.Mutex{}
301 result := make(map[string]*model.EndpointRootStat, len(endpoints))
302
303 wg := &sync.WaitGroup{}
304 wg.Add(len(endpoints))
305 var errs []error
306 for key, ep := range endpoints {
307 epCopy := ep
308 keyCopy := key
309 go func() {
310 defer wg.Done()
311 if sourceRoots, e := s.statRoots(ctx, epCopy); e == nil {
312 lock.Lock()
313 log.Logger(ctx).Info("Got Stats for "+keyCopy, zap.Any("stats", *sourceRoots))
314 result[keyCopy] = sourceRoots
315 lock.Unlock()
316 if !useSnapshots && s.watchConn != nil {
317 go func() {
318 s.watchConn <- &model.EndpointStatus{
319 WatchConnection: model.WatchStats,
320 EndpointInfo: epCopy.GetEndpointInfo(),
321 Stats: sourceRoots,
322 }
323 }()
324 }
325 } else {
326 errs = append(errs, e)
327 if !useSnapshots && s.watchConn != nil {
328 go func() {
329 s.watchConn <- &model.EndpointStatus{
330 WatchConnection: model.WatchDisconnected,
331 EndpointInfo: epCopy.GetEndpointInfo(),
332 }
333 }()
334 }
335 }
336 }()
337 }
338 wg.Wait()
339 if len(errs) > 0 {
340 return nil, errs[0]
341 }

Callers 1

runMethod · 0.95

Calls 12

statRootsMethod · 0.95
AsPathSyncSourceFunction · 0.92
LoggerFunction · 0.92
makeFunction · 0.85
WaitMethod · 0.80
GetEndpointInfoMethod · 0.65
LoadMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
LockMethod · 0.65
InfoMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected