diff --git a/go.mod b/go.mod index 3fdd0e1f..ec3f7b3e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/gorilla/mux v1.8.1 github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f - github.com/longhorn/longhorn-engine v1.7.0 + github.com/longhorn/longhorn-engine v1.7.1-dev-20240825.0.20240827003924-735156f051b5 github.com/longhorn/sparse-tools v0.0.0-20240729132735-18b207e459ff 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 44bca84a..cebb8dd9 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,8 @@ github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f h1:hjqUs3W github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f/go.mod h1:Qv34svr/msf6XoUwnrltNBTwMhQljbHEhb5ZKWiRdxo= github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58 h1:fzLAnCLCecoUnsSYyyo7li5GD17xckyBl/zietxz168= github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58/go.mod h1:TobRDCXmF0Ni+jz6+nLJamw3uVu+gNDZoZre1JczGwc= -github.com/longhorn/longhorn-engine v1.7.0 h1:aScx5OBayf9mdrjIhD+mqnyorZj4T71baz+Cd4NdahI= -github.com/longhorn/longhorn-engine v1.7.0/go.mod h1:doPP8g43e2PusQPnVLUsW/OdCadqTAZAMIFEOWowSA4= +github.com/longhorn/longhorn-engine v1.7.1-dev-20240825.0.20240827003924-735156f051b5 h1:M3tbQ1Zqwn563m1Nx0yCaRb9ZifXaYmBQ/F5VFI6Vcw= +github.com/longhorn/longhorn-engine v1.7.1-dev-20240825.0.20240827003924-735156f051b5/go.mod h1:E1ec7ub7SNGvASDtiFHL1dXX4bhEQiroBixD2GGeRbQ= github.com/longhorn/sparse-tools v0.0.0-20240729132735-18b207e459ff h1:gmdQDbnaGJ/zmrK+QJzSys8mH679os6i7vW/pOpRn1U= github.com/longhorn/sparse-tools v0.0.0-20240729132735-18b207e459ff/go.mod h1:iUJCZtOKG/9xv2rfrUAYZntFTzP5dZtvy4Kwe6dMcUc= github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 h1:L2g0sIJ2fXt4BSFRYNnF6ObtKryCUFm9qLcCXHWssCk= 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 3e02bbb7..83197a71 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 00000000..c609d1ce --- /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 d91db429..8495ad86 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -190,7 +190,7 @@ github.com/longhorn/go-iscsi-helper/iscsidev github.com/longhorn/go-iscsi-helper/longhorndev github.com/longhorn/go-iscsi-helper/types github.com/longhorn/go-iscsi-helper/util -# github.com/longhorn/longhorn-engine v1.7.0 +# github.com/longhorn/longhorn-engine v1.7.1-dev-20240825.0.20240827003924-735156f051b5 ## explicit; go 1.22.2 github.com/longhorn/longhorn-engine/pkg/interceptor github.com/longhorn/longhorn-engine/pkg/replica/client