Skip to content

Commit

Permalink
libovsdb: use exponential backoff
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Sep 6, 2024
1 parent fd5ce31 commit e343795
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/ovs/ovn-nb-suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,13 @@ func newNbClient(addr string, timeout int) (client.Client, error) {
WithValues("database", dbModel.Name())
stdr.SetVerbosity(1)

bo := &backoff.ExponentialBackOff{
InitialInterval: time.Second,
Multiplier: 2,
MaxInterval: time.Minute,
}
options := []client.Option{
client.WithReconnect(time.Duration(timeout)*time.Second, &backoff.ZeroBackOff{}),
client.WithReconnect(time.Duration(timeout)*time.Second, bo),
client.WithLeaderOnly(false),
client.WithLogger(&logger),
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/ovsdb/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ func NewOvsDbClient(
logger := klog.NewKlogr().WithName("libovsdb").WithValues("db", db)
connectTimeout := time.Duration(ovsDbConTimeout) * time.Second
inactivityTimeout := time.Duration(ovsDbInactivityTimeout) * time.Second
bo := &backoff.ExponentialBackOff{
InitialInterval: time.Second,
Multiplier: 2,
MaxInterval: time.Minute,
}
options := []client.Option{
// Reading and parsing the DB after reconnect at scale can (unsurprisingly)
// take longer than a normal ovsdb operation. Give it a bit more time so
// we don't time out and enter a reconnect loop. In addition it also enables
// inactivity check on the ovsdb connection.
client.WithInactivityCheck(inactivityTimeout, connectTimeout, &backoff.ZeroBackOff{}),
client.WithInactivityCheck(inactivityTimeout, connectTimeout, bo),

client.WithLeaderOnly(true),
client.WithLogger(&logger),
Expand Down

0 comments on commit e343795

Please sign in to comment.