From 48256c91b5602438b0afc2e8b6cada0ef5c4cb0a Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 6 Apr 2023 16:44:54 +0300 Subject: [PATCH] storage: move errors to better locations Change-Id: Ia44570949a8f6bb50220dc838c5b6aa21e851a4d --- satellite/metabase/update.go | 6 ++++-- satellite/metabase/update_test.go | 3 +-- satellite/repair/queue/common.go | 3 +++ satellite/repair/queue/queue2_test.go | 9 ++++----- satellite/repair/queue/queue_test.go | 3 +-- satellite/repair/repairer/repairer.go | 3 +-- satellite/satellitedb/repairqueue.go | 3 +-- storage/common.go | 9 --------- 8 files changed, 15 insertions(+), 24 deletions(-) diff --git a/satellite/metabase/update.go b/satellite/metabase/update.go index 2cbe7f7b8..447cf843a 100644 --- a/satellite/metabase/update.go +++ b/satellite/metabase/update.go @@ -13,9 +13,11 @@ import ( "storj.io/common/storj" "storj.io/common/uuid" - "storj.io/storj/storage" ) +// ErrValueChanged is returned when the current value of the key does not match the oldValue in UpdateSegmentPieces. +var ErrValueChanged = errs.Class("value changed") + // UpdateSegmentPieces contains arguments necessary for updating segment pieces. type UpdateSegmentPieces struct { StreamID uuid.UUID @@ -103,7 +105,7 @@ func (db *DB) UpdateSegmentPieces(ctx context.Context, opts UpdateSegmentPieces) } if !EqualAliasPieces(newPieces, resultPieces) { - return storage.ErrValueChanged.New("segment remote_alias_pieces field was changed") + return ErrValueChanged.New("segment remote_alias_pieces field was changed") } mon.Meter("segment_update").Mark(1) diff --git a/satellite/metabase/update_test.go b/satellite/metabase/update_test.go index 2c9f643b5..9090ad966 100644 --- a/satellite/metabase/update_test.go +++ b/satellite/metabase/update_test.go @@ -15,7 +15,6 @@ import ( "storj.io/common/testrand" "storj.io/storj/satellite/metabase" "storj.io/storj/satellite/metabase/metabasetest" - "storj.io/storj/storage" ) func TestUpdateSegmentPieces(t *testing.T) { @@ -257,7 +256,7 @@ func TestUpdateSegmentPieces(t *testing.T) { }, }, }, - ErrClass: &storage.ErrValueChanged, + ErrClass: &metabase.ErrValueChanged, ErrText: "segment remote_alias_pieces field was changed", }.Check(ctx, t, db) diff --git a/satellite/repair/queue/common.go b/satellite/repair/queue/common.go index df570e250..2d7a90f36 100644 --- a/satellite/repair/queue/common.go +++ b/satellite/repair/queue/common.go @@ -9,3 +9,6 @@ import ( // Error is a standard error class for this package. var Error = errs.Class("repair queue") + +// ErrEmpty is returned when attempting to Dequeue from an empty queue. +var ErrEmpty = errs.Class("empty queue") diff --git a/satellite/repair/queue/queue2_test.go b/satellite/repair/queue/queue2_test.go index e89d32776..7b47ca5e4 100644 --- a/satellite/repair/queue/queue2_test.go +++ b/satellite/repair/queue/queue2_test.go @@ -22,7 +22,6 @@ import ( "storj.io/storj/satellite/repair/queue" "storj.io/storj/satellite/satellitedb" "storj.io/storj/satellite/satellitedb/satellitedbtest" - "storj.io/storj/storage" ) func TestUntilEmpty(t *testing.T) { @@ -45,7 +44,7 @@ func TestUntilEmpty(t *testing.T) { for { injuredSeg, err := repairQueue.Select(ctx) if err != nil { - require.True(t, storage.ErrEmptyQueue.Has(err)) + require.True(t, queue.ErrEmpty.Has(err)) break } idsMap[injuredSeg.StreamID]++ @@ -108,7 +107,7 @@ func TestOrder(t *testing.T) { // segment should be considered "empty" now injuredSeg, err = repairQueue.Select(ctx) - assert.True(t, storage.ErrEmptyQueue.Has(err)) + assert.True(t, queue.ErrEmpty.Has(err)) assert.Nil(t, injuredSeg) }) } @@ -205,7 +204,7 @@ func testorderHealthyPieces(t *testing.T, connStr string) { // queue should be considered "empty" now injuredSeg, err := repairQueue.Select(ctx) - assert.True(t, storage.ErrEmptyQueue.Has(err)) + assert.True(t, queue.ErrEmpty.Has(err)) assert.Nil(t, injuredSeg) } @@ -255,7 +254,7 @@ func TestOrderOverwrite(t *testing.T) { // queue should be considered "empty" now injuredSeg, err := repairQueue.Select(ctx) - assert.True(t, storage.ErrEmptyQueue.Has(err)) + assert.True(t, queue.ErrEmpty.Has(err)) assert.Nil(t, injuredSeg) }) } diff --git a/satellite/repair/queue/queue_test.go b/satellite/repair/queue/queue_test.go index 01b7bff75..d2476eb92 100644 --- a/satellite/repair/queue/queue_test.go +++ b/satellite/repair/queue/queue_test.go @@ -17,7 +17,6 @@ import ( "storj.io/storj/satellite" "storj.io/storj/satellite/repair/queue" "storj.io/storj/satellite/satellitedb/satellitedbtest" - "storj.io/storj/storage" ) func TestInsertSelect(t *testing.T) { @@ -135,7 +134,7 @@ func TestDequeueEmptyQueue(t *testing.T) { _, err := q.Select(ctx) require.Error(t, err) - require.True(t, storage.ErrEmptyQueue.Has(err), "error should of class EmptyQueue") + require.True(t, queue.ErrEmpty.Has(err), "error should of class EmptyQueue") }) } diff --git a/satellite/repair/repairer/repairer.go b/satellite/repair/repairer/repairer.go index 093dc68bd..4c272785a 100644 --- a/satellite/repair/repairer/repairer.go +++ b/satellite/repair/repairer/repairer.go @@ -15,7 +15,6 @@ import ( "storj.io/common/memory" "storj.io/common/sync2" "storj.io/storj/satellite/repair/queue" - "storj.io/storj/storage" ) // Error is a standard error class for this package. @@ -105,7 +104,7 @@ func (service *Service) processWhileQueueHasItems(ctx context.Context) error { for { err := service.process(ctx) if err != nil { - if storage.ErrEmptyQueue.Has(err) { + if queue.ErrEmpty.Has(err) { return nil } service.log.Error("process", zap.Error(Error.Wrap(err))) diff --git a/satellite/satellitedb/repairqueue.go b/satellite/satellitedb/repairqueue.go index 5a0c6272d..580bc1127 100644 --- a/satellite/satellitedb/repairqueue.go +++ b/satellite/satellitedb/repairqueue.go @@ -17,7 +17,6 @@ import ( "storj.io/storj/satellite/metabase" "storj.io/storj/satellite/repair/queue" "storj.io/storj/satellite/satellitedb/dbx" - "storj.io/storj/storage" ) // RepairQueueSelectLimit defines how many items can be selected at the same time. @@ -222,7 +221,7 @@ func (r *repairQueue) Select(ctx context.Context) (seg *queue.InjuredSegment, er } if err != nil { if errors.Is(err, sql.ErrNoRows) { - return nil, storage.ErrEmptyQueue.New("") + return nil, queue.ErrEmpty.New("") } return nil, err } diff --git a/storage/common.go b/storage/common.go index e33597da0..d63f64212 100644 --- a/storage/common.go +++ b/storage/common.go @@ -22,15 +22,6 @@ var ErrKeyNotFound = errs.Class("key not found") // ErrEmptyKey is returned when an empty key is used in Put or in CompareAndSwap. var ErrEmptyKey = errs.Class("empty key") -// ErrValueChanged is returned when the current value of the key does not match the oldValue in CompareAndSwap. -var ErrValueChanged = errs.Class("value changed") - -// ErrEmptyQueue is returned when attempting to Dequeue from an empty queue. -var ErrEmptyQueue = errs.Class("empty queue") - -// ErrLimitExceeded is returned when request limit is exceeded. -var ErrLimitExceeded = errs.Class("limit exceeded") - // Key is the type for the keys in a `KeyValueStore`. type Key []byte