github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/core/xaction.go (about) 1 // Package core provides core metadata and in-cluster API 2 /* 3 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package core 6 7 import ( 8 "sync" 9 "time" 10 11 "github.com/NVIDIA/aistore/cmn" 12 "github.com/NVIDIA/aistore/core/meta" 13 ) 14 15 type QuiRes int 16 17 const ( 18 QuiInactiveCB = QuiRes(iota) // e.g., no pending requests (NOTE: used exclusively by `quicb` callbacks) 19 QuiActive // active (e.g., receiving data) 20 QuiActiveRet // active that immediately breaks waiting for quiecscence 21 QuiDone // all done 22 QuiAborted // aborted 23 QuiTimeout // timeout 24 Quiescent // idle => quiescent 25 ) 26 27 type ( 28 QuiCB func(elapsed time.Duration) QuiRes // see enum below 29 30 Xact interface { 31 Run(*sync.WaitGroup) 32 ID() string 33 Kind() string 34 Bck() *meta.Bck 35 FromTo() (*meta.Bck, *meta.Bck) 36 StartTime() time.Time 37 EndTime() time.Time 38 Finished() bool 39 Running() bool 40 Quiesce(time.Duration, QuiCB) QuiRes 41 42 // abrt 43 IsAborted() bool 44 AbortErr() error 45 AbortedAfter(time.Duration) error 46 ChanAbort() <-chan error 47 // err (info) 48 AddErr(error, ...int) 49 50 Snap() *Snap // (struct below) 51 52 // reporting: log, err 53 String() string 54 Name() string 55 Cname() string 56 57 // modifiers 58 Finish() 59 Abort(error) bool 60 AddNotif(n Notif) 61 62 // common stats 63 Objs() int64 64 ObjsAdd(int, int64) // locally processed 65 OutObjsAdd(int, int64) // transmit 66 InObjsAdd(int, int64) // receive 67 InBytes() int64 68 OutBytes() int64 69 } 70 ) 71 72 type ( 73 Stats struct { 74 Objs int64 `json:"loc-objs,string"` // locally processed 75 Bytes int64 `json:"loc-bytes,string"` // 76 OutObjs int64 `json:"out-objs,string"` // transmit 77 OutBytes int64 `json:"out-bytes,string"` // 78 InObjs int64 `json:"in-objs,string"` // receive 79 InBytes int64 `json:"in-bytes,string"` 80 } 81 Snap struct { 82 // xaction-specific stats counters 83 Ext any `json:"ext"` 84 85 // common static props 86 StartTime time.Time `json:"start-time"` 87 EndTime time.Time `json:"end-time"` 88 Bck cmn.Bck `json:"bck"` 89 SrcBck cmn.Bck `json:"src-bck"` 90 DstBck cmn.Bck `json:"dst-bck"` 91 ID string `json:"id"` 92 Kind string `json:"kind"` 93 94 // extended error info 95 AbortErr string `json:"abort-err"` 96 Err string `json:"err"` 97 98 // rebalance-only 99 RebID int64 `json:"glob.id,string"` 100 101 // common runtime: stats counters (above) and state 102 Stats Stats `json:"stats"` 103 AbortedX bool `json:"aborted"` 104 IdleX bool `json:"is_idle"` 105 } 106 AllRunningInOut struct { 107 Kind string 108 Running []string 109 Idle []string // NOTE: returning only when not nil 110 } 111 ) 112 113 ////////// 114 // Snap // 115 ////////// 116 117 func (snp *Snap) IsAborted() bool { return snp.AbortedX } 118 func (snp *Snap) IsIdle() bool { return snp.IdleX } 119 func (snp *Snap) Started() bool { return !snp.StartTime.IsZero() } 120 func (snp *Snap) Running() bool { return snp.Started() && !snp.IsAborted() && snp.EndTime.IsZero() } 121 func (snp *Snap) Finished() bool { return snp.Started() && !snp.EndTime.IsZero() }