[#1445] shard/gc: Make handler and callback names more descriptive
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m0s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m33s
Tests and linters / gopls check (pull_request) Successful in 4m29s
Tests and linters / Tests with -race (pull_request) Successful in 6m11s
Tests and linters / Run gofumpt (pull_request) Successful in 7m7s
DCO action / DCO (pull_request) Successful in 7m34s
Tests and linters / Staticcheck (pull_request) Successful in 9m23s
Tests and linters / Tests (pull_request) Successful in 9m30s
Build / Build Components (pull_request) Successful in 10m10s
Tests and linters / Lint (pull_request) Successful in 10m23s
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m0s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m33s
Tests and linters / gopls check (pull_request) Successful in 4m29s
Tests and linters / Tests with -race (pull_request) Successful in 6m11s
Tests and linters / Run gofumpt (pull_request) Successful in 7m7s
DCO action / DCO (pull_request) Successful in 7m34s
Tests and linters / Staticcheck (pull_request) Successful in 9m23s
Tests and linters / Tests (pull_request) Successful in 9m30s
Build / Build Components (pull_request) Successful in 10m10s
Tests and linters / Lint (pull_request) Successful in 10m23s
Consider the following methods: - `(*Shard).collectExpiredTombstones` - `(*StorageEngines).processExpiredTombstones` - `(*Shard).HandleExpiredTombstones` All of them handle not tombstones but graves. `HandleExpiredTombstones` in fact deletes tombstones but it does it based on graves it received. So, rename all `...Tombstones` methods to `...Graves` method. It'll make future changes in the garbage collector behavior simpler. Also, rename all `...Locks` methods to `...LockObjects` because they handle not locks but lock objects. Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
8ad8e2783a
commit
e2a6663ef6
7 changed files with 29 additions and 26 deletions
|
@ -285,9 +285,9 @@ func (e *StorageEngine) GetLocks(ctx context.Context, addr oid.Address) ([]Lock,
|
||||||
return allLocks, outErr
|
return allLocks, outErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *StorageEngine) processExpiredTombstones(ctx context.Context, addrs []meta.TombstonedObject) {
|
func (e *StorageEngine) processExpiredGraves(ctx context.Context, addrs []meta.TombstonedObject) {
|
||||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||||
sh.HandleExpiredTombstones(ctx, addrs)
|
sh.HandleExpiredGraves(ctx, addrs)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -298,9 +298,9 @@ func (e *StorageEngine) processExpiredTombstones(ctx context.Context, addrs []me
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *StorageEngine) processExpiredLocks(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
func (e *StorageEngine) processExpiredLockObjects(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
||||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||||
sh.HandleExpiredLocks(ctx, epoch, lockers)
|
sh.HandleExpiredLockObjects(ctx, epoch, lockers)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
|
@ -131,8 +131,8 @@ func (e *StorageEngine) createShard(ctx context.Context, opts []shard.Option) (*
|
||||||
|
|
||||||
sh := shard.New(append(opts,
|
sh := shard.New(append(opts,
|
||||||
shard.WithID(id),
|
shard.WithID(id),
|
||||||
shard.WithExpiredTombstonesCallback(e.processExpiredTombstones),
|
shard.WithExpiredTombstonesCallback(e.processExpiredGraves),
|
||||||
shard.WithExpiredLocksCallback(e.processExpiredLocks),
|
shard.WithExpiredLocksCallback(e.processExpiredLockObjects),
|
||||||
shard.WithDeletedLockCallback(e.processDeletedLocks),
|
shard.WithDeletedLockCallback(e.processDeletedLocks),
|
||||||
shard.WithReportErrorFunc(e.reportShardErrorByID),
|
shard.WithReportErrorFunc(e.reportShardErrorByID),
|
||||||
shard.WithZeroSizeCallback(e.processZeroSizeContainers),
|
shard.WithZeroSizeCallback(e.processZeroSizeContainers),
|
||||||
|
|
|
@ -116,9 +116,9 @@ func (s *Shard) Init(ctx context.Context) error {
|
||||||
eventNewEpoch: {
|
eventNewEpoch: {
|
||||||
cancelFunc: func() {},
|
cancelFunc: func() {},
|
||||||
handlers: []eventHandler{
|
handlers: []eventHandler{
|
||||||
s.collectExpiredLocks,
|
s.collectExpiredLockObjects,
|
||||||
s.collectExpiredObjects,
|
s.collectExpiredObjects,
|
||||||
s.collectExpiredTombstones,
|
s.collectExpiredGraves,
|
||||||
s.collectExpiredMetrics,
|
s.collectExpiredMetrics,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -462,7 +462,7 @@ func (s *Shard) getExpiredWithLinked(ctx context.Context, source []oid.Address)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Shard) collectExpiredTombstones(ctx context.Context, e Event) {
|
func (s *Shard) collectExpiredGraves(ctx context.Context, e Event) {
|
||||||
var err error
|
var err error
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ func (s *Shard) collectExpiredTombstones(ctx context.Context, e Event) {
|
||||||
|
|
||||||
log.Debug(ctx, logs.ShardHandlingExpiredTombstonesBatch, zap.Int("number", len(tssExp)))
|
log.Debug(ctx, logs.ShardHandlingExpiredTombstonesBatch, zap.Int("number", len(tssExp)))
|
||||||
if len(tssExp) > 0 {
|
if len(tssExp) > 0 {
|
||||||
s.expiredTombstonesCallback(ctx, tssExp)
|
s.expiredGravesCallback(ctx, tssExp)
|
||||||
}
|
}
|
||||||
|
|
||||||
iterPrm.SetOffset(tss[tssLen-1].Address())
|
iterPrm.SetOffset(tss[tssLen-1].Address())
|
||||||
|
@ -535,7 +535,7 @@ func (s *Shard) collectExpiredTombstones(ctx context.Context, e Event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Shard) collectExpiredLocks(ctx context.Context, e Event) {
|
func (s *Shard) collectExpiredLockObjects(ctx context.Context, e Event) {
|
||||||
var err error
|
var err error
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
|
|
||||||
|
@ -561,7 +561,7 @@ func (s *Shard) collectExpiredLocks(ctx context.Context, e Event) {
|
||||||
if len(batch) == batchSize {
|
if len(batch) == batchSize {
|
||||||
expired := batch
|
expired := batch
|
||||||
errGroup.Go(func() error {
|
errGroup.Go(func() error {
|
||||||
s.expiredLocksCallback(egCtx, e.(newEpoch).epoch, expired)
|
s.expiredLockObjectsCallback(egCtx, e.(newEpoch).epoch, expired)
|
||||||
return egCtx.Err()
|
return egCtx.Err()
|
||||||
})
|
})
|
||||||
batch = make([]oid.Address, 0, batchSize)
|
batch = make([]oid.Address, 0, batchSize)
|
||||||
|
@ -575,7 +575,7 @@ func (s *Shard) collectExpiredLocks(ctx context.Context, e Event) {
|
||||||
if len(batch) > 0 {
|
if len(batch) > 0 {
|
||||||
expired := batch
|
expired := batch
|
||||||
errGroup.Go(func() error {
|
errGroup.Go(func() error {
|
||||||
s.expiredLocksCallback(egCtx, e.(newEpoch).epoch, expired)
|
s.expiredLockObjectsCallback(egCtx, e.(newEpoch).epoch, expired)
|
||||||
return egCtx.Err()
|
return egCtx.Err()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -622,11 +622,11 @@ func (s *Shard) selectExpired(ctx context.Context, epoch uint64, addresses []oid
|
||||||
return s.metaBase.FilterExpired(ctx, epoch, addresses)
|
return s.metaBase.FilterExpired(ctx, epoch, addresses)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleExpiredTombstones marks tombstones themselves as garbage
|
// HandleExpiredGraves marks tombstones themselves as garbage
|
||||||
// and clears up corresponding graveyard records.
|
// and clears up corresponding graveyard records.
|
||||||
//
|
//
|
||||||
// Does not modify tss.
|
// Does not modify tss.
|
||||||
func (s *Shard) HandleExpiredTombstones(ctx context.Context, tss []meta.TombstonedObject) {
|
func (s *Shard) HandleExpiredGraves(ctx context.Context, tss []meta.TombstonedObject) {
|
||||||
s.m.RLock()
|
s.m.RLock()
|
||||||
defer s.m.RUnlock()
|
defer s.m.RUnlock()
|
||||||
|
|
||||||
|
@ -656,9 +656,9 @@ func (s *Shard) HandleExpiredTombstones(ctx context.Context, tss []meta.Tombston
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleExpiredLocks unlocks all objects which were locked by lockers.
|
// HandleExpiredLockObjects unlocks all objects which were locked by lockers.
|
||||||
// If successful, marks lockers themselves as garbage.
|
// If successful, marks lockers themselves as garbage.
|
||||||
func (s *Shard) HandleExpiredLocks(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
func (s *Shard) HandleExpiredLockObjects(ctx context.Context, epoch uint64, lockers []oid.Address) {
|
||||||
if s.GetMode().NoMetabase() {
|
if s.GetMode().NoMetabase() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) {
|
||||||
sh.HandleDeletedLocks(ctx, addresses)
|
sh.HandleDeletedLocks(ctx, addresses)
|
||||||
}),
|
}),
|
||||||
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
||||||
sh.HandleExpiredLocks(ctx, epoch, a)
|
sh.HandleExpiredLockObjects(ctx, epoch, a)
|
||||||
}),
|
}),
|
||||||
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
||||||
pool, err := ants.NewPool(sz)
|
pool, err := ants.NewPool(sz)
|
||||||
|
|
|
@ -46,8 +46,11 @@ type Shard struct {
|
||||||
// Option represents Shard's constructor option.
|
// Option represents Shard's constructor option.
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
||||||
// ExpiredTombstonesCallback is a callback handling list of expired tombstones.
|
// ExpiredGravesCallback is a callback handling list of expired graves.
|
||||||
type ExpiredTombstonesCallback func(context.Context, []meta.TombstonedObject)
|
//
|
||||||
|
// Need to mention, that [ExpiredGravesCallback] handles exactly graves,
|
||||||
|
// not tombstones. [ExpiredObjectsCallback] can be used to handle tombstones.
|
||||||
|
type ExpiredGravesCallback func(context.Context, []meta.TombstonedObject)
|
||||||
|
|
||||||
// ExpiredObjectsCallback is a callback handling list of expired objects.
|
// ExpiredObjectsCallback is a callback handling list of expired objects.
|
||||||
type ExpiredObjectsCallback func(context.Context, uint64, []oid.Address)
|
type ExpiredObjectsCallback func(context.Context, uint64, []oid.Address)
|
||||||
|
@ -82,9 +85,9 @@ type cfg struct {
|
||||||
|
|
||||||
gcCfg gcCfg
|
gcCfg gcCfg
|
||||||
|
|
||||||
expiredTombstonesCallback ExpiredTombstonesCallback
|
expiredGravesCallback ExpiredGravesCallback
|
||||||
|
|
||||||
expiredLocksCallback ExpiredObjectsCallback
|
expiredLockObjectsCallback ExpiredObjectsCallback
|
||||||
|
|
||||||
deletedLockCallBack DeletedLockCallback
|
deletedLockCallBack DeletedLockCallback
|
||||||
|
|
||||||
|
@ -248,9 +251,9 @@ func WithGCRemoverSleepInterval(dur time.Duration) Option {
|
||||||
|
|
||||||
// WithExpiredTombstonesCallback returns option to specify callback
|
// WithExpiredTombstonesCallback returns option to specify callback
|
||||||
// of the expired tombstones handler.
|
// of the expired tombstones handler.
|
||||||
func WithExpiredTombstonesCallback(cb ExpiredTombstonesCallback) Option {
|
func WithExpiredTombstonesCallback(cb ExpiredGravesCallback) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.expiredTombstonesCallback = cb
|
c.expiredGravesCallback = cb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +261,7 @@ func WithExpiredTombstonesCallback(cb ExpiredTombstonesCallback) Option {
|
||||||
// of the expired LOCK objects handler.
|
// of the expired LOCK objects handler.
|
||||||
func WithExpiredLocksCallback(cb ExpiredObjectsCallback) Option {
|
func WithExpiredLocksCallback(cb ExpiredObjectsCallback) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.expiredLocksCallback = cb
|
c.expiredLockObjectsCallback = cb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard
|
||||||
sh.HandleDeletedLocks(ctx, addresses)
|
sh.HandleDeletedLocks(ctx, addresses)
|
||||||
}),
|
}),
|
||||||
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) {
|
||||||
sh.HandleExpiredLocks(ctx, epoch, a)
|
sh.HandleExpiredLockObjects(ctx, epoch, a)
|
||||||
}),
|
}),
|
||||||
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
|
||||||
pool, err := ants.NewPool(sz)
|
pool, err := ants.NewPool(sz)
|
||||||
|
|
Loading…
Reference in a new issue