Skip to content

Commit

Permalink
Go API: amend 'wait-idle' helper method
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jan 18, 2024
1 parent 3211b59 commit b721797
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
31 changes: 20 additions & 11 deletions api/xaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,30 @@ func getxst(out any, q url.Values, bp BaseParams, args *xact.ArgsMsg) (err error
//

type consIdle struct {
xid string
cnt int
xid string
cnt int
delayed bool
}

func (ci *consIdle) check(snaps xact.MultiSnap) (done, resetProbeFreq bool) {
found, idle := snaps.IsIdle(ci.xid)
if idle || !found {
ci.cnt++
// TODO: !found may mean "hasn't started yet" unless it's a "won't start"
// situation; resetting frequency only if found
done, resetProbeFreq = ci.cnt >= xact.NumConsecutiveIdle, found
return
aborted, running, notstarted := snaps.IsIdle(ci.xid)
if aborted {
return true, false
}
ci.cnt = 0
return
if running {
ci.cnt = 0
return false, false
}
if notstarted && ci.cnt == 0 {
if !ci.delayed {
time.Sleep(min(2*xact.MinPollTime, 4*time.Second))
ci.delayed = true
}
return false, false
}
// is idle
ci.cnt++
return ci.cnt >= xact.NumConsecutiveIdle, true
}

// WaitForXactionIdle waits for a given on-demand xaction to be idle.
Expand Down
2 changes: 1 addition & 1 deletion ec/ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func writeObject(lom *core.LOM, reader io.Reader, size int64, xctn core.Xact) er
params.Atime = time.Now()
params.Size = size
params.Xact = xctn
params.OWT = cmn.OwtCopy
params.OWT = cmn.OwtRebalance
}
err := core.T.PutObject(lom, params)
core.FreePutParams(params)
Expand Down
40 changes: 25 additions & 15 deletions xact/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,35 +477,45 @@ func (xs MultiSnap) IsAborted(xid string) (bool, error) {
}

// (all targets, all xactions)
func (xs MultiSnap) IsIdle(xid string) (found, idle bool) {
func (xs MultiSnap) IsIdle(xid string) (aborted, running, notstarted bool) {
if xid != "" {
debug.Assert(IsValidUUID(xid), xid)
return xs._idle(xid)
return xs._get(xid)
}
uuids := xs.GetUUIDs()
idle = true
for _, xid = range uuids {
f, i := xs._idle(xid)
found = found || f
idle = idle && i
a, r, ns := xs._get(xid)
aborted = aborted || a
notstarted = notstarted || ns
running = running || r
}
return
return aborted, running, notstarted
}

// (all targets, given xaction)
func (xs MultiSnap) _idle(xid string) (found, idle bool) {
func (xs MultiSnap) _get(xid string) (aborted, running, notstarted bool) {
var nt, nr, ns, nf int
for _, snaps := range xs {
nt++
for _, xsnap := range snaps {
if xid == xsnap.ID {
found = true
// (one target, one xaction)
if xsnap.Started() && !xsnap.IsAborted() && !xsnap.IsIdle() {
return true, false
}
if xid != xsnap.ID {
continue
}
nf++
// (one target, one xaction)
switch {
case xsnap.IsAborted():
return true, false, false
case !xsnap.Started():
ns++
case !xsnap.IsIdle():
nr++
}
break
}
}
idle = true // (read: not-idle not found)
running = nr > 0
notstarted = ns > 0 || nf == 0
return
}

Expand Down

0 comments on commit b721797

Please sign in to comment.