Skip to content

Commit 49ac6b4

Browse files
authored
Qtree async delete fix
1 parent 45a5f70 commit 49ac6b4

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

storage_drivers/ontap/api/ontap_rest.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4903,7 +4903,20 @@ func (c *RestClient) QtreeDestroyAsync(ctx context.Context, path string, force b
49034903
return nil
49044904
} else if deleteAccepted != nil {
49054905
jobLink := getGenericJobLinkFromQtreeJobLink(deleteAccepted.Payload)
4906-
return c.PollJobStatus(ctx, jobLink)
4906+
job := jobLink.Job
4907+
if job == nil {
4908+
return fmt.Errorf("missing job result")
4909+
}
4910+
if job.UUID == nil {
4911+
return fmt.Errorf("missing job uuid for result")
4912+
}
4913+
jobUUID := *job.UUID
4914+
// qtree files take a long time to delete, so we return immediately without polling for job completion.
4915+
Logc(ctx).WithFields(LogFields{
4916+
"path": path,
4917+
"jobUUID": jobUUID,
4918+
}).Debug("Qtree deleting asynchronously.")
4919+
return nil
49074920
}
49084921
return fmt.Errorf("unexpected response from qtree delete")
49094922
}

storage_drivers/ontap/api/ontap_rest_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6552,16 +6552,40 @@ func TestOntapQtree_DestroyAsync(t *testing.T) {
65526552
}
65536553
for _, test := range tests {
65546554
t.Run(test.name, func(t *testing.T) {
6555-
server := httptest.NewServer(http.HandlerFunc(test.mockFunction))
6555+
var requests []struct {
6556+
Method string
6557+
Path string
6558+
}
6559+
var mu sync.Mutex
6560+
handler := func(w http.ResponseWriter, r *http.Request) {
6561+
mu.Lock()
6562+
requests = append(requests, struct {
6563+
Method string
6564+
Path string
6565+
}{Method: r.Method, Path: r.URL.Path})
6566+
mu.Unlock()
6567+
test.mockFunction(w, r)
6568+
}
6569+
6570+
server := httptest.NewServer(http.HandlerFunc(handler))
6571+
65566572
rs := newRestClient(server.Listener.Addr().String(), server.Client())
65576573
assert.NotNil(t, rs)
65586574

65596575
err := rs.QtreeDestroyAsync(ctx, "/vol1/qtree_vol1", false)
65606576
if !test.isErrorExpected {
65616577
assert.NoError(t, err, "could not delete the qtree")
6578+
mu.Lock()
6579+
assert.Len(t, requests, 2, "expected exactly 2 requests (qtree lookup + delete); job poll would add GET to cluster/jobs")
6580+
for _, req := range requests {
6581+
assert.NotRegexp(t, `.*/cluster/jobs/.*`, req.Path,
6582+
"must not poll job endpoint when qtree delete returns 202 Accepted; got %s %s", req.Method, req.Path)
6583+
}
6584+
mu.Unlock()
65626585
} else {
65636586
assert.Error(t, err, "qtree deleted")
65646587
}
6588+
65656589
server.Close()
65666590
})
65676591
}

0 commit comments

Comments
 (0)