From 56adf02b130529e4dec7067c902baa76297dc23a Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 4 Apr 2024 11:21:46 +0200 Subject: [PATCH] stores: address comments --- stores/metadata.go | 2 +- stores/metadata_test.go | 3 --- stores/sql.go | 10 ++++++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/stores/metadata.go b/stores/metadata.go index d8e4962c9..ad4c7d496 100644 --- a/stores/metadata.go +++ b/stores/metadata.go @@ -2727,7 +2727,7 @@ func (s *SQLStore) pruneSlabsLoop() { return } - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second+sumDurations(s.retryTransactionIntervals)) err := s.retryTransaction(ctx, pruneSlabs) if err != nil { s.logger.Errorw("failed to prune slabs", zap.Error(err)) diff --git a/stores/metadata_test.go b/stores/metadata_test.go index ebb5f0df1..bdd955808 100644 --- a/stores/metadata_test.go +++ b/stores/metadata_test.go @@ -4097,7 +4097,6 @@ func TestSlabCleanup(t *testing.T) { if err != nil { t.Fatal(err) } - time.Sleep(100 * time.Millisecond) // check slice count var slabCntr int64 @@ -4115,7 +4114,6 @@ func TestSlabCleanup(t *testing.T) { if err != nil { t.Fatal(err) } - time.Sleep(100 * time.Millisecond) ss.Retry(100, 100*time.Millisecond, func() error { if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { @@ -4164,7 +4162,6 @@ func TestSlabCleanup(t *testing.T) { if err != nil { t.Fatal(err) } - time.Sleep(100 * time.Millisecond) ss.Retry(100, 100*time.Millisecond, func() error { if err := ss.db.Model(&dbSlab{}).Count(&slabCntr).Error; err != nil { diff --git a/stores/sql.go b/stores/sql.go index b64adddca..02e250e78 100644 --- a/stores/sql.go +++ b/stores/sql.go @@ -250,8 +250,6 @@ func NewSQLStore(cfg Config) (*SQLStore, modules.ConsensusChangeID, error) { } shutdownCtx, shutdownCtxCancel := context.WithCancel(context.Background()) - slabPruneOngoing := make(chan struct{}) - close(slabPruneOngoing) ss := &SQLStore{ alerts: cfg.Alerts, db: db, @@ -622,3 +620,11 @@ func (s *SQLStore) ResetConsensusSubscription(ctx context.Context) error { s.persistMu.Unlock() return nil } + +func sumDurations(durations []time.Duration) time.Duration { + var sum time.Duration + for _, d := range durations { + sum += d + } + return sum +}