@@ -54,14 +54,14 @@ func (cs *ConsulStorage) prefixKey(key string) string {
54
54
55
55
// Lock acquires a distributed lock for the given key or blocks until it gets one
56
56
func (cs * ConsulStorage ) Lock (ctx context.Context , key string ) error {
57
- cs .logger .Debugf ("trying lock for %s" , key )
57
+ cs .logger .Infof ("trying lock for %s" , key )
58
58
59
59
if _ , isLocked := cs .GetLock (key ); isLocked {
60
60
return nil
61
61
}
62
62
63
63
// prepare the distributed lock
64
- cs .logger .Debugf ("creating Consul lock for %s" , key )
64
+ cs .logger .Infof ("creating Consul lock for %s" , key )
65
65
lock , err := cs .ConsulClient .LockOpts (& consul.LockOptions {
66
66
Key : cs .prefixKey (key ),
67
67
LockWaitTime : time .Duration (cs .Timeout ) * time .Second ,
@@ -105,9 +105,6 @@ func (cs *ConsulStorage) GetLock(key string) (*consul.Lock, bool) {
105
105
106
106
// Unlock releases a specific lock
107
107
func (cs * ConsulStorage ) Unlock (key string ) error {
108
- cs .muLocks .Lock ()
109
- defer cs .muLocks .Unlock ()
110
-
111
108
// check if we own it and unlock
112
109
lock , exists := cs .GetLock (key )
113
110
if ! exists {
@@ -119,7 +116,10 @@ func (cs *ConsulStorage) Unlock(key string) error {
119
116
return errors .Wrapf (err , "unable to unlock %s" , cs .prefixKey (key ))
120
117
}
121
118
119
+ cs .muLocks .Lock ()
122
120
delete (cs .locks , key )
121
+ cs .muLocks .Unlock ()
122
+
123
123
return nil
124
124
}
125
125
@@ -149,7 +149,7 @@ func (cs ConsulStorage) Store(key string, value []byte) error {
149
149
150
150
// Load retrieves the value for a key from Consul KV
151
151
func (cs ConsulStorage ) Load (key string ) ([]byte , error ) {
152
- cs .logger .Debugf ("loading data from Consul for %s" , key )
152
+ cs .logger .Infof ("loading data from Consul for %s" , key )
153
153
154
154
kv , _ , err := cs .ConsulClient .KV ().Get (cs .prefixKey (key ), & consul.QueryOptions {RequireConsistent : true })
155
155
if err != nil {
@@ -168,7 +168,7 @@ func (cs ConsulStorage) Load(key string) ([]byte, error) {
168
168
169
169
// Delete a key from Consul KV
170
170
func (cs ConsulStorage ) Delete (key string ) error {
171
- cs .logger .Debugf ("deleting key %s from Consul" , key )
171
+ cs .logger .Infof ("deleting key %s from Consul" , key )
172
172
173
173
// first obtain existing keypair
174
174
kv , _ , err := cs .ConsulClient .KV ().Get (cs .prefixKey (key ), & consul.QueryOptions {RequireConsistent : true })
0 commit comments