From d3a0079d1d7bbd054fb3de69da1cb7d2b6f8a374 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 15 Feb 2021 14:32:49 +0300 Subject: [PATCH] [#377] shard: Add Inhume parameter to mark the object as garbage Implement `InhumePrm.MarkAsGarbage` method that leads to marking object as garbage in metabase. Update `InhumePrm.WithTarget` doc indicating a conflict with the new method. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/inhume.go | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/shard/inhume.go b/pkg/local_object_storage/shard/inhume.go index b1ee560d8..0246a4775 100644 --- a/pkg/local_object_storage/shard/inhume.go +++ b/pkg/local_object_storage/shard/inhume.go @@ -17,6 +17,9 @@ type InhumeRes struct{} // WithTarget sets object address that should be inhumed and tombstone address // as the reason for inhume operation. +// +// Arguments should not be nil. +// Should not be called along with MarkAsGarbage. func (p *InhumePrm) WithTarget(addr, tombstone *objectSDK.Address) *InhumePrm { if p != nil { p.target = addr @@ -26,10 +29,30 @@ func (p *InhumePrm) WithTarget(addr, tombstone *objectSDK.Address) *InhumePrm { return p } +// MarkAsGarbage marks object to be physically removed from shard. +// +// Should not be called along with WithTarget. +func (p *InhumePrm) MarkAsGarbage(addr *objectSDK.Address) *InhumePrm { + if p != nil { + p.target = addr + p.tombstone = nil + } + + return p +} + // Inhume calls metabase. Inhume method to mark object as removed. It won't be // removed physically from blobStor and metabase until `Delete` operation. func (s *Shard) Inhume(prm *InhumePrm) (*InhumeRes, error) { - err := meta.Inhume(s.metaBase, prm.target, prm.tombstone) + metaPrm := new(meta.InhumePrm).WithAddress(prm.target) + + if prm.tombstone != nil { + metaPrm.WithTombstoneAddress(prm.tombstone) + } else { + metaPrm.WithGCMark() + } + + _, err := s.metaBase.Inhume(metaPrm) if err != nil { s.log.Debug("could not mark object to delete in metabase", zap.String("error", err.Error()),