99 "sort"
1010 "strings"
1111 "sync"
12- "sync/atomic"
1312 "time"
1413
1514 v "github.com/hashicorp/go-version"
@@ -43,6 +42,7 @@ import (
4342 "github.com/percona/percona-server-mongodb-operator/pkg/psmdb/secret"
4443 "github.com/percona/percona-server-mongodb-operator/pkg/psmdb/tls"
4544 "github.com/percona/percona-server-mongodb-operator/pkg/util"
45+ "github.com/percona/percona-server-mongodb-operator/pkg/util/lockstore"
4646 "github.com/percona/percona-server-mongodb-operator/pkg/version"
4747)
4848
@@ -94,7 +94,7 @@ func newReconciler(mgr manager.Manager) (reconcile.Reconciler, error) {
9494 serverVersion : sv ,
9595 reconcileIn : time .Second * 5 ,
9696 crons : NewCronRegistry (),
97- lockers : newLockStore (),
97+ lockers : lockstore . New (),
9898 newPBM : backup .NewPBM ,
9999 restConfig : mgr .GetConfig (),
100100 newCertManagerCtrlFunc : tls .NewCertManagerController ,
@@ -191,40 +191,9 @@ type ReconcilePerconaServerMongoDB struct {
191191
192192 initImage string
193193
194- lockers lockStore
194+ lockers * lockstore. LockStore
195195}
196196
197- type lockStore struct {
198- store * sync.Map
199- }
200-
201- func newLockStore () lockStore {
202- return lockStore {
203- store : new (sync.Map ),
204- }
205- }
206-
207- func (l lockStore ) LoadOrCreate (key string ) lock {
208- val , _ := l .store .LoadOrStore (key , lock {
209- statusMutex : new (sync.Mutex ),
210- resyncMutex : new (sync.Mutex ),
211- updateSync : new (int32 ),
212- })
213-
214- return val .(lock )
215- }
216-
217- type lock struct {
218- statusMutex * sync.Mutex
219- resyncMutex * sync.Mutex
220- updateSync * int32
221- }
222-
223- const (
224- updateDone = 0
225- updateWait = 1
226- )
227-
228197// Reconcile reads that state of the cluster for a PerconaServerMongoDB object and makes changes based on the state read
229198// and what is in the PerconaServerMongoDB.Spec
230199// Note:
@@ -239,16 +208,19 @@ func (r *ReconcilePerconaServerMongoDB) Reconcile(ctx context.Context, request r
239208
240209 // As operator can handle a few clusters
241210 // lock should be created per cluster to not lock cron jobs of other clusters
242- l := r .lockers .LoadOrCreate (request .NamespacedName .String ())
211+ lock := r .lockers .LoadOrCreate (request .NamespacedName .String ())
243212
244213 // PerconaServerMongoDB object is also accessed and changed by a version service's cron job (that runs concurrently)
245- l . statusMutex .Lock ()
246- defer l . statusMutex .Unlock ()
214+ lock . ReconcileMutex .Lock ()
215+ defer lock . ReconcileMutex .Unlock ()
247216 // we have to be sure the reconcile loop will be run at least once
248217 // in-between any version service jobs (hence any two vs jobs shouldn't be run sequentially).
249218 // the version service job sets the state to `updateWait` and the next job can be run only
250219 // after the state was dropped to`updateDone` again
251- defer atomic .StoreInt32 (l .updateSync , updateDone )
220+ defer lock .SetToUpdateDone ()
221+
222+ log .V (1 ).Info ("Reconciling" )
223+ defer log .V (1 ).Info ("Reconcile finished" )
252224
253225 // Fetch the PerconaServerMongoDB instance
254226 cr := & api.PerconaServerMongoDB {}
0 commit comments