Skip to content

Commit 3ad4c65

Browse files
authored
perf: Store Lock timeout for CNI in Windows is increased to 1 minute. (#1924)
* fix: Store Lock timeout for CNI in Windows is increased to 1 minute. * rollback the telemtry lock timeout to 10 sec.
1 parent e45ad21 commit 3ad4c65

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

aitelemetry/telemetrywrapper.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ func getMetadata(th *telemetryHandle) {
116116
debugLog("[AppInsights] Error initializing kvs store: %v", err)
117117
return
118118
}
119-
120-
err = kvs.Lock(store.DefaultLockTimeout)
121-
if err != nil {
119+
// Acquire store lock.
120+
if err = kvs.Lock(store.DefaultLockTimeout); err != nil {
122121
log.Errorf("getMetadata: Not able to acquire lock:%v", err)
123122
return
124123
}

cni/plugin.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"os"
1010
"runtime"
11+
"time"
1112

1213
"github.com/Azure/azure-container-networking/common"
1314
"github.com/Azure/azure-container-networking/log"
@@ -174,8 +175,12 @@ func (plugin *Plugin) InitializeKeyValueStore(config *common.PluginConfig) error
174175
}
175176
}
176177

177-
// Acquire store lock.
178-
if err := plugin.Store.Lock(store.DefaultLockTimeout); err != nil {
178+
// Acquire store lock. For windows 1m timeout is used while for Linux 10s timeout is assigned.
179+
var lockTimeoutValue time.Duration = store.DefaultLockTimeout
180+
if runtime.GOOS == "windows" {
181+
lockTimeoutValue = store.DefaultLockTimeoutWindows
182+
}
183+
if err := plugin.Store.Lock(lockTimeoutValue); err != nil {
179184
log.Printf("[cni] Failed to lock store: %v.", err)
180185
return errors.Wrap(err, "error Acquiring store lock")
181186
}

store/json.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const (
2323
LockExtension = ".lock"
2424

2525
// DefaultLockTimeout - lock timeout in milliseconds
26-
DefaultLockTimeout = 10000 * time.Millisecond
26+
DefaultLockTimeout = 10000 * time.Millisecond
27+
DefaultLockTimeoutWindows = 60000 * time.Millisecond
2728
)
2829

2930
// jsonFileStore is an implementation of KeyValueStore using a local JSON file.
@@ -35,8 +36,9 @@ type jsonFileStore struct {
3536
sync.Mutex
3637
}
3738

38-
//nolint:revive // ignoring name change
3939
// NewJsonFileStore creates a new jsonFileStore object, accessed as a KeyValueStore.
40+
//
41+
//nolint:revive // ignoring name change
4042
func NewJsonFileStore(fileName string, lockclient processlock.Interface) (KeyValueStore, error) {
4143
if fileName == "" {
4244
return &jsonFileStore{}, errors.New("need to pass in a json file path")
@@ -195,7 +197,7 @@ func (kvs *jsonFileStore) Lock(timeout time.Duration) error {
195197
return errors.Wrap(err, "processLock acquire error")
196198
}
197199

198-
log.Printf("Acquired process lock")
200+
log.Printf("Acquired process lock with timeout value of %v ", timeout)
199201
return nil
200202
}
201203

0 commit comments

Comments
 (0)