From 35073fb61bbfe8c0d1cf907b2cb707f321e7cab2 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 19 Feb 2021 17:08:41 +0300 Subject: [PATCH] [#217] storage engine: Add GC marking to Inhume operation Add `InhumePrm.MarkAsGarbage` method which marks passed objects to be removed from local storage. Update `InhumePrm.WithTarget` doc to prevent conflicting use with the new method. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/engine/inhume.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index a2dc130c..487e1a31 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -22,6 +22,7 @@ type InhumeRes struct{} // as the reason for inhume operation. // // tombstone should not be nil, addr should not be empty. +// Should not be called along with MarkAsGarbage. func (p *InhumePrm) WithTarget(tombstone *objectSDK.Address, addrs ...*objectSDK.Address) *InhumePrm { if p != nil { p.addrs = addrs @@ -31,6 +32,18 @@ func (p *InhumePrm) WithTarget(tombstone *objectSDK.Address, addrs ...*objectSDK return p } +// MarkAsGarbage marks object to be physically removed from local storage. +// +// Should not be called along with WithTarget. +func (p *InhumePrm) MarkAsGarbage(addrs ...*objectSDK.Address) *InhumePrm { + if p != nil { + p.addrs = addrs + p.tombstone = nil + } + + return p +} + var errInhumeFailure = errors.New("inhume operation failed") // Inhume calls metabase. Inhume method to mark object as removed. It won't be @@ -39,7 +52,11 @@ func (e *StorageEngine) Inhume(prm *InhumePrm) (*InhumeRes, error) { shPrm := new(shard.InhumePrm) for i := range prm.addrs { - shPrm.WithTarget(prm.tombstone, prm.addrs[i]) + if prm.tombstone != nil { + shPrm.WithTarget(prm.tombstone, prm.addrs[i]) + } else { + shPrm.MarkAsGarbage(prm.addrs[i]) + } ok := e.inhume(prm.addrs[i], shPrm, true) if ok {