@@ -25,7 +25,6 @@ package deployment
25
25
import (
26
26
"context"
27
27
"fmt"
28
- "sync/atomic"
29
28
30
29
"github.com/arangodb/arangosync/client"
31
30
"github.com/arangodb/arangosync/tasks"
@@ -78,7 +77,10 @@ func (d *Deployment) GetSpec() api.DeploymentSpec {
78
77
// GetStatus returns the current status of the deployment
79
78
// together with the current version of that status.
80
79
func (d * Deployment ) GetStatus () (api.DeploymentStatus , int32 ) {
81
- version := atomic .LoadInt32 (& d .status .version )
80
+ d .status .mutex .Lock ()
81
+ defer d .status .mutex .Unlock ()
82
+
83
+ version := d .status .version
82
84
return * d .status .last .DeepCopy (), version
83
85
}
84
86
@@ -87,14 +89,18 @@ func (d *Deployment) GetStatus() (api.DeploymentStatus, int32) {
87
89
// If the given last version does not match the actual last version of the status object,
88
90
// an error is returned.
89
91
func (d * Deployment ) UpdateStatus (status api.DeploymentStatus , lastVersion int32 , force ... bool ) error {
90
- if ! atomic .CompareAndSwapInt32 (& d .status .version , lastVersion , lastVersion + 1 ) {
92
+ d .status .mutex .Lock ()
93
+ defer d .status .mutex .Unlock ()
94
+
95
+ if d .status .version != lastVersion {
91
96
// Status is obsolete
92
97
d .deps .Log .Error ().
93
98
Int32 ("expected-version" , lastVersion ).
94
99
Int32 ("actual-version" , d .status .version ).
95
100
Msg ("UpdateStatus version conflict error." )
96
101
return maskAny (fmt .Errorf ("Status conflict error. Expected version %d, got %d" , lastVersion , d .status .version ))
97
102
}
103
+ d .status .version ++
98
104
d .status .last = * status .DeepCopy ()
99
105
if err := d .updateCRStatus (force ... ); err != nil {
100
106
return maskAny (err )
0 commit comments