From dd210df6abaf97025201ca78fe6b257861a1d685 Mon Sep 17 00:00:00 2001 From: Nurzhan Saktaganov Date: Tue, 8 Oct 2024 12:38:37 +0300 Subject: [PATCH] resolve issue #93 * Add a pause between bucketsDiscovery requests (default is 10 ms) --- discovery.go | 4 ++++ vshard.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/discovery.go b/discovery.go index 39c086f..f8b0792 100644 --- a/discovery.go +++ b/discovery.go @@ -261,6 +261,10 @@ func (r *Router) DiscoveryAllBuckets(ctx context.Context) error { } bucketsDiscoveryPaginationFrom = resp.NextFrom + + // Don't spam many requests at once. Give storages time to handle them and other requests. + // https://github.com/tarantool/vshard/blob/b6fdbe950a2e4557f05b83bd8b846b126ec3724e/vshard/router/init.lua#L308 + time.Sleep(r.cfg.DiscoveryWorkStep) } }) } diff --git a/vshard.go b/vshard.go index ba3dfbb..214d33f 100644 --- a/vshard.go +++ b/vshard.go @@ -93,8 +93,9 @@ type Config struct { // Discovery // DiscoveryTimeout is timeout between cron discovery job; by default there is no timeout. - DiscoveryTimeout time.Duration - DiscoveryMode DiscoveryMode + DiscoveryTimeout time.Duration + DiscoveryWorkStep time.Duration + DiscoveryMode DiscoveryMode // BucketsSearchMode defines policy for BucketDiscovery method. // Default value is BucketsSearchLegacy. @@ -234,6 +235,7 @@ func (r *Router) RouteMapClean() { func prepareCfg(cfg Config) (Config, error) { const discoveryTimeoutDefault = 1 * time.Minute + const discoveryWorkStepDefault = 10 * time.Millisecond err := validateCfg(cfg) if err != nil { @@ -244,6 +246,10 @@ func prepareCfg(cfg Config) (Config, error) { cfg.DiscoveryTimeout = discoveryTimeoutDefault } + if cfg.DiscoveryWorkStep == 0 { + cfg.DiscoveryWorkStep = discoveryWorkStepDefault + } + if cfg.Loggerf == nil { cfg.Loggerf = emptyLogfProvider }