@@ -25,7 +25,6 @@ package deployment
2525import (
2626 "context"
2727 "fmt"
28- "sync/atomic"
2928
3029 "github.com/arangodb/arangosync/client"
3130 "github.com/arangodb/arangosync/tasks"
@@ -78,7 +77,10 @@ func (d *Deployment) GetSpec() api.DeploymentSpec {
7877// GetStatus returns the current status of the deployment
7978// together with the current version of that status.
8079func (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
8284 return * d .status .last .DeepCopy (), version
8385}
8486
@@ -87,14 +89,18 @@ func (d *Deployment) GetStatus() (api.DeploymentStatus, int32) {
8789// If the given last version does not match the actual last version of the status object,
8890// an error is returned.
8991func (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 {
9196 // Status is obsolete
9297 d .deps .Log .Error ().
9398 Int32 ("expected-version" , lastVersion ).
9499 Int32 ("actual-version" , d .status .version ).
95100 Msg ("UpdateStatus version conflict error." )
96101 return maskAny (fmt .Errorf ("Status conflict error. Expected version %d, got %d" , lastVersion , d .status .version ))
97102 }
103+ d .status .version ++
98104 d .status .last = * status .DeepCopy ()
99105 if err := d .updateCRStatus (force ... ); err != nil {
100106 return maskAny (err )
0 commit comments