Skip to content

Commit 3a2e497

Browse files
authored
Merge pull request #19681 from serathius/robustness-merge-categorization
Merge operation categorization into one function
2 parents e9fcb41 + 6caa1ec commit 3a2e497

File tree

2 files changed

+20
-39
lines changed

2 files changed

+20
-39
lines changed

tests/robustness/validate/patch_history_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,9 @@ func TestPatchHistory(t *testing.T) {
412412
Watch: tc.watchOperations,
413413
},
414414
}
415-
operations := patchLinearizableOperations(relevantOperations(patchFailedRequestWithInfiniteReturnTime(reports)), reports, tc.persistedRequest)
416-
if diff := cmp.Diff(tc.expectedRemainingOperations, operations,
415+
operations, _ := prepareAndCategorizeOperations(reports)
416+
patched := patchLinearizableOperations(operations, reports, tc.persistedRequest)
417+
if diff := cmp.Diff(tc.expectedRemainingOperations, patched,
417418
cmpopts.EquateEmpty(),
418419
cmpopts.IgnoreFields(porcupine.Operation{}, "Input", "Call", "ClientId"),
419420
); diff != "" {

tests/robustness/validate/validate.go

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,27 @@ type Config struct {
6262
ExpectRevisionUnique bool
6363
}
6464

65-
func prepareAndCategorizeOperations(reports []report.ClientReport) ([]porcupine.Operation, []porcupine.Operation) {
66-
patchedOperations := patchFailedRequestWithInfiniteReturnTime(reports)
67-
return relevantOperations(patchedOperations), filterSerializableOperations(patchedOperations)
68-
}
69-
70-
func relevantOperations(operations []porcupine.Operation) []porcupine.Operation {
71-
var ops []porcupine.Operation
72-
for _, op := range operations {
73-
request := op.Input.(model.EtcdRequest)
74-
resp := op.Output.(model.MaybeEtcdResponse)
75-
// Remove failed read requests as they are not relevant for linearization.
76-
if resp.Error == "" || !request.IsRead() {
77-
ops = append(ops, op)
78-
}
79-
}
80-
return ops
81-
}
82-
83-
func filterSerializableOperations(operations []porcupine.Operation) []porcupine.Operation {
84-
resp := []porcupine.Operation{}
85-
for _, op := range operations {
86-
request := op.Input.(model.EtcdRequest)
87-
if request.Type == model.Range && request.Range.Revision != 0 {
88-
resp = append(resp, op)
89-
}
90-
}
91-
return resp
92-
}
93-
94-
func patchFailedRequestWithInfiniteReturnTime(reports []report.ClientReport) []porcupine.Operation {
95-
operations := make([]porcupine.Operation, 0)
65+
func prepareAndCategorizeOperations(reports []report.ClientReport) (linearizable []porcupine.Operation, serializable []porcupine.Operation) {
9666
for _, report := range reports {
97-
for _, operation := range report.KeyValue {
98-
// Failed writes can still be persisted, setting to infinite for now as we don't know when request has taken effect.
99-
if operation.Output.(model.MaybeEtcdResponse).Error != "" {
100-
operation.Return = math.MaxInt64
67+
for _, op := range report.KeyValue {
68+
request := op.Input.(model.EtcdRequest)
69+
response := op.Output.(model.MaybeEtcdResponse)
70+
// serializable operations include only Range requests on non-zero revision
71+
if request.Type == model.Range && request.Range.Revision != 0 {
72+
serializable = append(serializable, op)
73+
}
74+
// Remove failed read requests as they are not relevant for linearization.
75+
if response.Error == "" || !request.IsRead() {
76+
// For linearization, we set the return time of failed requests to MaxInt64.
77+
// Failed requests can still be persisted, however we don't know when request has taken effect.
78+
if response.Error != "" {
79+
op.Return = math.MaxInt64
80+
}
81+
linearizable = append(linearizable, op)
10182
}
102-
operations = append(operations, operation)
10383
}
10484
}
105-
return operations
85+
return linearizable, serializable
10686
}
10787

10888
func checkValidationAssumptions(reports []report.ClientReport, persistedRequests []model.EtcdRequest) error {

0 commit comments

Comments
 (0)