Skip to content

Commit c2f8135

Browse files
committed
refactor: introduces "failed" status
This introduces "failed" status for the ProgressStatus, which is used only if table/view restore ended with error.
1 parent b2ea7e0 commit c2f8135

8 files changed

+188
-23
lines changed

Diff for: pkg/service/one2onerestore/model.go

+2
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,6 @@ var (
280280
ProgressStatusInProgress ProgressStatus = "in_progress"
281281
// ProgressStatusDone indicates that 1-1-restore of table/view is done.
282282
ProgressStatusDone ProgressStatus = "done"
283+
// ProgressStatusFailed indicates that 1-1-restore of table/view is failed due to some error.
284+
ProgressStatusFailed ProgressStatus = "failed"
283285
)

Diff for: pkg/service/one2onerestore/progress.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ func (w *worker) aggregateProgress(tableIter, viewIter dbIterator) Progress {
250250
}
251251

252252
func tableProgressStatus(rtp RunTableProgress) ProgressStatus {
253+
if rtp.Error != "" {
254+
return ProgressStatusFailed
255+
}
253256
if rtp.StartedAt == nil && rtp.CompletedAt == nil {
254257
return ProgressStatusNotStarted
255258
}
@@ -266,6 +269,9 @@ func tableProgressStatus(rtp RunTableProgress) ProgressStatus {
266269
}
267270

268271
func viewProgressStatus(rvp RunViewProgress) ProgressStatus {
272+
if rvp.Error != "" {
273+
return ProgressStatusFailed
274+
}
269275
switch rvp.ViewBuildStatus {
270276
case scyllaclient.StatusUnknown:
271277
return ProgressStatusNotStarted
@@ -282,14 +288,19 @@ func incrementProgress(dst, src progress) progress {
282288
dst.Restored += src.Restored
283289
dst.StartedAt = minTime(dst.StartedAt, src.StartedAt)
284290
dst.CompletedAt = maxTime(dst.CompletedAt, src.CompletedAt)
291+
dst.Status = mergeProgressStatus(dst.Status, src.Status)
292+
return dst
293+
}
285294

286-
if dst.Status == "" {
287-
dst.Status = src.Status
295+
// mergeProgressStatus decides which status should table/view progress have.
296+
func mergeProgressStatus(dst, src ProgressStatus) ProgressStatus {
297+
if dst == "" || dst == src {
298+
return src
288299
}
289-
if dst.Status == ProgressStatusDone && src.Status != ProgressStatusDone {
290-
dst.Status = ProgressStatusInProgress
300+
if dst == ProgressStatusFailed || src == ProgressStatusFailed {
301+
return ProgressStatusFailed
291302
}
292-
return dst
303+
return ProgressStatusInProgress
293304
}
294305

295306
func minTime(a, b *time.Time) *time.Time {

Diff for: pkg/service/one2onerestore/progress_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,59 @@ import (
1414
"github.com/scylladb/scylla-manager/v3/pkg/testutils"
1515
)
1616

17+
func TestMergeProgressStatus(t *testing.T) {
18+
testCases := []struct {
19+
name string
20+
dst, src ProgressStatus
21+
expected ProgressStatus
22+
}{
23+
{
24+
name: "empty + not_started(any) = not_started",
25+
src: ProgressStatusNotStarted,
26+
expected: ProgressStatusNotStarted,
27+
},
28+
{
29+
name: "done + done = done",
30+
src: ProgressStatusDone,
31+
dst: ProgressStatusDone,
32+
expected: ProgressStatusDone,
33+
},
34+
{
35+
name: "any + failed = failed",
36+
dst: ProgressStatusDone,
37+
src: ProgressStatusFailed,
38+
expected: ProgressStatusFailed,
39+
},
40+
{
41+
name: "failed + any = failed",
42+
dst: ProgressStatusFailed,
43+
src: ProgressStatusNotStarted,
44+
expected: ProgressStatusFailed,
45+
},
46+
{
47+
name: "done + in_progress = in_progress",
48+
dst: ProgressStatusDone,
49+
src: ProgressStatusInProgress,
50+
expected: ProgressStatusInProgress,
51+
},
52+
{
53+
name: "not_started + in_progress = in_progress",
54+
dst: ProgressStatusNotStarted,
55+
src: ProgressStatusInProgress,
56+
expected: ProgressStatusInProgress,
57+
},
58+
}
59+
60+
for _, tc := range testCases {
61+
t.Run(tc.name, func(t *testing.T) {
62+
actual := mergeProgressStatus(tc.dst, tc.src)
63+
if actual != tc.expected {
64+
t.Fatalf("Expected %q, but got %q", tc.expected, actual)
65+
}
66+
})
67+
}
68+
}
69+
1770
func TestAggregateProgress(t *testing.T) {
1871
testCases := []struct {
1972
name string
@@ -51,6 +104,11 @@ func TestAggregateProgress(t *testing.T) {
51104
tableRows: "testdata/6.run_table_progress.json",
52105
viewRows: "testdata/6.run_view_progress.json",
53106
},
107+
{
108+
name: "Tables and views progress, status failed",
109+
tableRows: "testdata/7.run_table_progress.json",
110+
viewRows: "testdata/7.run_view_progress.json",
111+
},
54112
}
55113

56114
for _, tc := range testCases {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"StartedAt": "2025-01-01T12:00:00Z",
4+
"CompletedAt": "2025-01-01T12:00:01Z",
5+
"KeyspaceName": "ks1",
6+
"TableName": "t1",
7+
"TableSize": 20,
8+
"Host": "192.168.1.1",
9+
"Downloaded": 20,
10+
"IsRefreshed": true
11+
},
12+
{
13+
"StartedAt": "2025-01-01T12:00:00Z",
14+
"KeyspaceName": "ks1",
15+
"TableName": "t1",
16+
"TableSize": 20,
17+
"Host": "192.168.1.3",
18+
"Downloaded": 20,
19+
"IsRefreshed": false,
20+
"Error": "failed to fail"
21+
},
22+
{
23+
"StartedAt": "2025-01-01T12:00:01Z",
24+
"CompletedAt": "2025-01-01T12:00:03Z",
25+
"KeyspaceName": "ks1",
26+
"TableName": "t2",
27+
"TableSize": 20,
28+
"Host": "192.168.1.2",
29+
"Downloaded": 20,
30+
"IsRefreshed": true
31+
}
32+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"StartedAt": "2025-01-01T12:00:01Z",
4+
"KeyspaceName": "ks1",
5+
"TableName": "v1",
6+
"ViewType": "MaterializedView",
7+
"ViewBuildStatus": "STARTED",
8+
"Error": "timeout"
9+
},
10+
{
11+
"StartedAt": "2025-01-01T12:01:03Z",
12+
"CompletedAt": "2025-01-01T12:00:04Z",
13+
"KeyspaceName": "ks1",
14+
"TableName": "v2",
15+
"ViewType": "MaterializedView",
16+
"ViewBuildStatus": "SUCCESS"
17+
}
18+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"tables": [
3+
{
4+
"started_at": "2025-01-01T12:00:00Z",
5+
"completed_at": null,
6+
"size": 40,
7+
"restored": 40,
8+
"status": "failed",
9+
"keyspace": "ks1",
10+
"table": "t1"
11+
},
12+
{
13+
"started_at": "2025-01-01T12:00:01Z",
14+
"completed_at": "2025-01-01T12:00:03Z",
15+
"size": 20,
16+
"restored": 20,
17+
"status": "done",
18+
"keyspace": "ks1",
19+
"table": "t2"
20+
}
21+
],
22+
"views": [
23+
{
24+
"started_at": "2025-01-01T12:00:01Z",
25+
"completed_at": null,
26+
"size": 0,
27+
"restored": 0,
28+
"status": "failed",
29+
"keyspace": "ks1",
30+
"table": "v1",
31+
"type": "MaterializedView"
32+
},
33+
{
34+
"started_at": "2025-01-01T12:01:03Z",
35+
"completed_at": "2025-01-01T12:00:04Z",
36+
"size": 0,
37+
"restored": 0,
38+
"status": "done",
39+
"keyspace": "ks1",
40+
"table": "v2",
41+
"type": "MaterializedView"
42+
}
43+
]
44+
}

Diff for: pkg/service/one2onerestore/testdata/AggregateProgress/Tables_and_views_progress,_status_in_progress.golden.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"tables": [
3-
{
4-
"started_at": "2025-01-01T12:00:01Z",
5-
"completed_at": "2025-01-01T12:00:03Z",
6-
"size": 20,
7-
"restored": 20,
8-
"status": "in_progress",
9-
"keyspace": "ks1",
10-
"table": "t2"
11-
},
123
{
134
"started_at": "2025-01-01T12:00:00Z",
145
"completed_at": "2025-01-01T12:00:01Z",
@@ -17,6 +8,15 @@
178
"status": "in_progress",
189
"keyspace": "ks1",
1910
"table": "t1"
11+
},
12+
{
13+
"started_at": "2025-01-01T12:00:01Z",
14+
"completed_at": "2025-01-01T12:00:03Z",
15+
"size": 20,
16+
"restored": 20,
17+
"status": "in_progress",
18+
"keyspace": "ks1",
19+
"table": "t2"
2020
}
2121
],
2222
"views": [

Diff for: pkg/service/one2onerestore/testdata/AggregateProgress/Tables_and_views_progress,_status_mixed.golden.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"tables": [
3-
{
4-
"started_at": "2025-01-01T12:00:01Z",
5-
"completed_at": "2025-01-01T12:00:03Z",
6-
"size": 20,
7-
"restored": 20,
8-
"status": "done",
9-
"keyspace": "ks1",
10-
"table": "t2"
11-
},
123
{
134
"started_at": "2025-01-01T12:00:00Z",
145
"completed_at": null,
@@ -17,6 +8,15 @@
178
"status": "in_progress",
189
"keyspace": "ks1",
1910
"table": "t1"
11+
},
12+
{
13+
"started_at": "2025-01-01T12:00:01Z",
14+
"completed_at": "2025-01-01T12:00:03Z",
15+
"size": 20,
16+
"restored": 20,
17+
"status": "done",
18+
"keyspace": "ks1",
19+
"table": "t2"
2020
}
2121
],
2222
"views": [

0 commit comments

Comments
 (0)