From 57381d25bc4db538d2b672beaf24762d0e1b56cb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 24 Aug 2024 04:13:53 +0000 Subject: [PATCH] fix(deps): update github.com/longhorn/longhorn-engine digest to 3b01da8 --- go.mod | 2 +- go.sum | 4 +- .../longhorn-engine/pkg/types/types.go | 9 ++- .../pkg/util/shared_timeouts.go | 63 +++++++++++++++++++ vendor/modules.txt | 2 +- 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 vendor/github.com/longhorn/longhorn-engine/pkg/util/shared_timeouts.go diff --git a/go.mod b/go.mod index 074503723..7f37a06fd 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff - github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823034826-e3fc0af7f92e + github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823152554-3b01da86d648 github.com/longhorn/longhorn-spdk-engine v0.0.0-20240821075759-df0d2ae1b9bb github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 86823c8e5..f9998c1d0 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58 h1:fzLAnC github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58/go.mod h1:TobRDCXmF0Ni+jz6+nLJamw3uVu+gNDZoZre1JczGwc= github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff h1:8vR29tkbmzmdqRVtOo5kL7Rs7nfhA6duXsmetIh1Tbg= github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff/go.mod h1:Bzz7kGNYikAJqpmeV3cgN8jP1y9M+/oaiBc5iolIxuA= -github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823034826-e3fc0af7f92e h1:ypmfAXFXi7rXAUCs1NYrjk8z/0WyG+TFQ0KrfpWYN2Q= -github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823034826-e3fc0af7f92e/go.mod h1:PBqPVim1yRTsdUKCdstkRicX8xzb0pmwXf78Bz+7ITE= +github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823152554-3b01da86d648 h1:g3pjHv4BgsFxBiQ+1NZ/4mgTu7kdhqt01nmV9IWVyzk= +github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823152554-3b01da86d648/go.mod h1:PBqPVim1yRTsdUKCdstkRicX8xzb0pmwXf78Bz+7ITE= github.com/longhorn/longhorn-spdk-engine v0.0.0-20240821075759-df0d2ae1b9bb h1:Bon92kq45spPKp1JZEQrlDm+DJI37z56D64cL+/64Po= github.com/longhorn/longhorn-spdk-engine v0.0.0-20240821075759-df0d2ae1b9bb/go.mod h1:j6SIrhGW6mFc18MjzXfTHkAZA0ms4k/oL3piCYNlZPo= github.com/longhorn/nsfilelock v0.0.0-20200723175406-fa7c83ad0003 h1:Jw9uANsGcHTxp6HcC++/vN17LfeuDmozHI2j6DoZf5E= diff --git a/vendor/github.com/longhorn/longhorn-engine/pkg/types/types.go b/vendor/github.com/longhorn/longhorn-engine/pkg/types/types.go index 3e02bbb7e..83197a71e 100644 --- a/vendor/github.com/longhorn/longhorn-engine/pkg/types/types.go +++ b/vendor/github.com/longhorn/longhorn-engine/pkg/types/types.go @@ -109,7 +109,14 @@ type Backend interface { } type BackendFactory interface { - Create(volumeName, address string, dataServerProtocol DataServerProtocol, engineReplicaTimeout time.Duration) (Backend, error) + Create(volumeName, address string, dataServerProtocol DataServerProtocol, + sharedTimeouts SharedTimeouts) (Backend, error) +} + +type SharedTimeouts interface { + Increment() + Decrement() + CheckAndDecrement(duration time.Duration) time.Duration } type Controller interface { diff --git a/vendor/github.com/longhorn/longhorn-engine/pkg/util/shared_timeouts.go b/vendor/github.com/longhorn/longhorn-engine/pkg/util/shared_timeouts.go new file mode 100644 index 000000000..c609d1cec --- /dev/null +++ b/vendor/github.com/longhorn/longhorn-engine/pkg/util/shared_timeouts.go @@ -0,0 +1,63 @@ +package util + +import ( + "sync" + "time" +) + +// SharedTimeouts has the following use case: +// - Multiple goroutines may need to time out eventually. +// - Only the goroutines themselves know if the conditions for a timeout have been met. +// - It is fine for some of the goroutines to time out quickly. +// - The last goroutine should time out more slowly. +// SharedTimeouts implements the types.SharedTimeouts instead of directly defining the concrete type to avoid an import +// loop. +type SharedTimeouts struct { + mutex sync.RWMutex + longTimeout time.Duration + shortTimeout time.Duration + numConsumers int +} + +func NewSharedTimeouts(shortTimeout, longTimeout time.Duration) *SharedTimeouts { + return &SharedTimeouts{ + longTimeout: longTimeout, + shortTimeout: shortTimeout, + } +} + +func (t *SharedTimeouts) Increment() { + t.mutex.Lock() + defer t.mutex.Unlock() + t.numConsumers++ +} + +func (t *SharedTimeouts) Decrement() { + t.mutex.Lock() + defer t.mutex.Unlock() + t.numConsumers-- +} + +// CheckAndDecrement checks if duration exceeds longTimeout or shortTimeout, returns the timeout exceeded (if +// applicable) and decrements numConsumers. +// - shortTimeout is only considered exceeded if there is still one other consumer to wait for longTimeout. +// - The caller MUST take whatever action is required for a timeout if a value > 0 is returned. +func (t *SharedTimeouts) CheckAndDecrement(duration time.Duration) time.Duration { + if duration > t.longTimeout { + t.mutex.Lock() + defer t.mutex.Unlock() + t.numConsumers-- + return t.longTimeout + } + + if duration > t.shortTimeout { + t.mutex.Lock() + defer t.mutex.Unlock() + if t.numConsumers > 1 { + t.numConsumers-- + return t.shortTimeout + } + } + + return 0 +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 43e55eeda..563bc4b43 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -254,7 +254,7 @@ github.com/longhorn/go-spdk-helper/pkg/spdk/setup github.com/longhorn/go-spdk-helper/pkg/spdk/types github.com/longhorn/go-spdk-helper/pkg/types github.com/longhorn/go-spdk-helper/pkg/util -# github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823034826-e3fc0af7f92e +# github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240823152554-3b01da86d648 ## explicit; go 1.22.2 github.com/longhorn/longhorn-engine/pkg/backingfile github.com/longhorn/longhorn-engine/pkg/controller/client