From 6d3fd33ca33fcbdce20029bf2d8ad07f83a221a7 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Tue, 28 Sep 2021 16:10:11 +0300 Subject: [PATCH] satellite/metabase/segmentloop: start immediately on manual trigger Currently loops wait for the coalesce duration for TriggerWait. Let's skip the coalesce when we trigger it manually. Change-Id: If5bacd4e263d233f1f3ea41b989922d2ed5a48d4 --- go.mod | 2 +- go.sum | 4 ++-- satellite/metabase/segmentloop/service.go | 14 +++++++++++--- testsuite/go.mod | 2 +- testsuite/go.sum | 4 ++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 6db2c8804..440929478 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/segmentio/analytics-go.v3 v3.1.0 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c - storj.io/common v0.0.0-20210916151047-6aaeb34bb916 + storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4 storj.io/drpc v0.0.26 storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7 storj.io/private v0.0.0-20210810102517-434aeab3f17d diff --git a/go.sum b/go.sum index dc265a5ae..c756924c2 100644 --- a/go.sum +++ b/go.sum @@ -879,8 +879,8 @@ sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3 storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0nICqMwp7PM8HqnDuyUeldNA0= storj.io/common v0.0.0-20210805073808-8e0feb09e92a/go.mod h1:mhZYWpTojKsACxWE66RfXNz19zbyr/uEDVWHJH8dHog= storj.io/common v0.0.0-20210915201516-56ad343b6a7e/go.mod h1:i35B7Zr9WpXWSePOUAQXffRgvt0fWKpdfiB5mtbBbaA= -storj.io/common v0.0.0-20210916151047-6aaeb34bb916 h1:G+EqGYEbW4lUBSkdt2uQE2BRc2ZvnhJSj0czlqL3SuA= -storj.io/common v0.0.0-20210916151047-6aaeb34bb916/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg= +storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4 h1:G0ePy32obot7DamdE/KcwwKcquE2r6T2pG0G6qyhr6Y= +storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg= storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw= storj.io/drpc v0.0.24/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko= storj.io/drpc v0.0.25/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko= diff --git a/satellite/metabase/segmentloop/service.go b/satellite/metabase/segmentloop/service.go index cc5d6dd59..b846067ec 100644 --- a/satellite/metabase/segmentloop/service.go +++ b/satellite/metabase/segmentloop/service.go @@ -15,6 +15,7 @@ import ( "golang.org/x/time/rate" "storj.io/common/errs2" + "storj.io/common/sync2" "storj.io/storj/satellite/metabase" ) @@ -76,8 +77,9 @@ func (NullObserver) InlineSegment(context.Context, *Segment) error { } type observerContext struct { - trigger bool - observer Observer + immediate bool + trigger bool + observer Observer ctx context.Context done chan error @@ -206,7 +208,8 @@ func (loop *Service) joinObserver(ctx context.Context, trigger bool, obs Observe defer mon.Task()(&ctx)(&err) obsctx := newObserverContext(ctx, obs) - obsctx.trigger = trigger + obsctx.immediate = sync2.IsManuallyTriggeredCycle(ctx) + obsctx.trigger = trigger || obsctx.immediate select { case loop.join <- obsctx: @@ -290,9 +293,14 @@ waitformore: timerStarted = true } } + observers = append(observers, obsctx) go monitorEarlyExit(obsctx) + if obsctx.immediate { + break waitformore + } + // remove an observer from waiting when it's canceled before the loop starts. case obsctx := <-earlyExit: for i, obs := range observers { diff --git a/testsuite/go.mod b/testsuite/go.mod index dc6eed7c8..73057107c 100644 --- a/testsuite/go.mod +++ b/testsuite/go.mod @@ -8,6 +8,6 @@ require ( github.com/go-rod/rod v0.100.0 github.com/stretchr/testify v1.7.0 go.uber.org/zap v1.17.0 - storj.io/common v0.0.0-20210916151047-6aaeb34bb916 + storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4 storj.io/storj v0.12.1-0.20210916114455-b2d724962c24 ) diff --git a/testsuite/go.sum b/testsuite/go.sum index d9b3b4e83..c55031cae 100644 --- a/testsuite/go.sum +++ b/testsuite/go.sum @@ -841,8 +841,8 @@ sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3 storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0nICqMwp7PM8HqnDuyUeldNA0= storj.io/common v0.0.0-20210805073808-8e0feb09e92a/go.mod h1:mhZYWpTojKsACxWE66RfXNz19zbyr/uEDVWHJH8dHog= storj.io/common v0.0.0-20210915201516-56ad343b6a7e/go.mod h1:i35B7Zr9WpXWSePOUAQXffRgvt0fWKpdfiB5mtbBbaA= -storj.io/common v0.0.0-20210916151047-6aaeb34bb916 h1:G+EqGYEbW4lUBSkdt2uQE2BRc2ZvnhJSj0czlqL3SuA= -storj.io/common v0.0.0-20210916151047-6aaeb34bb916/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg= +storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4 h1:G0ePy32obot7DamdE/KcwwKcquE2r6T2pG0G6qyhr6Y= +storj.io/common v0.0.0-20210928125533-ecbc7f49b8a4/go.mod h1:objobGrIWQwhmTSpSm6Y7ykd40wZjB7CezNfic5YLKg= storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw= storj.io/drpc v0.0.24/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko= storj.io/drpc v0.0.25/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=