Skip to content

Commit

Permalink
tests: a job we try to abort may have already finished
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Sep 8, 2024
1 parent b17f422 commit 7b0b0bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ais/prxlso.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (b *lsobjBuffers) housekeep(now int64) (num int) {
b.buffers.Range(func(key, value any) bool {
buffer := value.(*lsobjBuffer)
num++
// mono.Since(buffer.lastAccess.Load()) > lsobjBufferTTL
// mono.Since(lastAccess)
if now-buffer.lastAccess.Load() > int64(lsobjBufferTTL) {
b.buffers.Delete(key)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func (c *lsobjCaches) housekeep(now int64) (num int) {
cache.mtx.Lock()
for _, interval := range cache.intervals {
num++
// mono.Since(interval.lastAccess) > cacheIntervalTTL
// mono.Since(lastAccess)
if now-interval.lastAccess > int64(cacheIntervalTTL) {
toRemove = append(toRemove, interval)
}
Expand Down
29 changes: 26 additions & 3 deletions ais/test/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2792,13 +2792,36 @@ func testCopyBucketAbort(t *testing.T, srcBck cmn.Bck, m *ioContext, sleep time.
time.Sleep(time.Second)
snaps, err := api.QueryXactionSnaps(baseParams, &xact.ArgsMsg{ID: xid})
tassert.CheckError(t, err)
aborted, err := snaps.IsAborted(xid)
aborted, finished := _isAbortedOrFinished(xid, snaps)
tassert.CheckError(t, err)
tassert.Errorf(t, aborted, "failed to abort copy-bucket: %q, %v", xid, err)
tassert.Errorf(t, aborted || finished, "expecting copy-bucket %q to abort or finish", xid)

if finished {
tlog.Logf("%s[%s] already finished\n", apc.ActCopyBck, xid)
}

bcks, err := api.ListBuckets(baseParams, cmn.QueryBcks(dstBck), apc.FltExists)
tassert.CheckError(t, err)
tassert.Errorf(t, !tools.BucketsContain(bcks, cmn.QueryBcks(dstBck)), "should not contain destination bucket %s", dstBck)
if aborted {
tassert.Errorf(t, !tools.BucketsContain(bcks, cmn.QueryBcks(dstBck)),
"when aborted, should not contain destination bucket %s", dstBck)
}
}

func _isAbortedOrFinished(xid string, xs xact.MultiSnap) (aborted, finished bool) {
for _, snaps := range xs {
for _, xsnap := range snaps {
if xid == xsnap.ID {
if xsnap.IsAborted() {
return true, false
}
if !xsnap.Finished() {
return false, false
}
}
}
}
return false, true
}

func testCopyBucketDryRun(t *testing.T, srcBck cmn.Bck, m *ioContext) {
Expand Down
14 changes: 0 additions & 14 deletions xact/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,6 @@ func (xs MultiSnap) RunningTarget(xid string) (string /*tid*/, *core.Snap, error
return "", nil, nil
}

func (xs MultiSnap) IsAborted(xid string) (bool, error) {
if err := xs.checkEmptyID(xid); err != nil {
return false, err
}
for _, snaps := range xs {
for _, xsnap := range snaps {
if (xid == xsnap.ID || xid == "") && xsnap.IsAborted() {
return true, nil
}
}
}
return false, nil
}

// (all targets, all xactions)
func (xs MultiSnap) IsIdle(xid string) (aborted, running, notstarted bool) {
if xid != "" {
Expand Down

0 comments on commit 7b0b0bc

Please sign in to comment.