Skip to content

Commit 0e51f4f

Browse files
committed
fix(solver) resolve a data race with ops counters
1 parent 729559e commit 0e51f4f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

solver/solver.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package solver
22

33
import (
44
"context"
5+
"sync/atomic"
56

67
"github.com/kong/deck/crud"
78
"github.com/kong/deck/diff"
@@ -14,9 +15,9 @@ import (
1415

1516
// Stats holds the stats related to a Solve.
1617
type Stats struct {
17-
CreateOps int
18-
UpdateOps int
19-
DeleteOps int
18+
CreateOps int32
19+
UpdateOps int32
20+
DeleteOps int32
2021
}
2122

2223
// Solve generates a diff and walks the graph.
@@ -27,14 +28,15 @@ func Solve(ctx context.Context, syncer *diff.Syncer,
2728
r := buildRegistry(client, konnectClient)
2829

2930
var stats Stats
31+
3032
recordOp := func(op crud.Op) {
3133
switch op {
3234
case crud.Create:
33-
stats.CreateOps = stats.CreateOps + 1
35+
atomic.AddInt32(&stats.CreateOps, 1)
3436
case crud.Update:
35-
stats.UpdateOps = stats.UpdateOps + 1
37+
atomic.AddInt32(&stats.UpdateOps, 1)
3638
case crud.Delete:
37-
stats.DeleteOps = stats.DeleteOps + 1
39+
atomic.AddInt32(&stats.DeleteOps, 1)
3840
}
3941
}
4042

0 commit comments

Comments
 (0)