From aa2151fbeb94c12b82fe9fb8cd53e1b0c9608189 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 31 Aug 2021 13:52:09 +0300 Subject: [PATCH] [#762] write-cache: Implement Head operation Write cache should be able to execute HEAD operations according to spec. Add simple implementation of `Head` method through the `Get` one. Leave notes for future optimization. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/writecache/get.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/local_object_storage/writecache/get.go b/pkg/local_object_storage/writecache/get.go index 1199d8cef..5c3593b41 100644 --- a/pkg/local_object_storage/writecache/get.go +++ b/pkg/local_object_storage/writecache/get.go @@ -49,3 +49,20 @@ func (c *cache) Get(addr *objectSDK.Address) (*object.Object, error) { c.flushed.Get(saddr) return obj, nil } + +// Head returns object header from write-cache. +func (c *cache) Head(addr *objectSDK.Address) (*object.Object, error) { + // TODO: easiest to implement solution is presented here, consider more efficient way, e.g.: + // - provide header as common object.Object to Put, but marked to prevent correlation with full object + // (all write-cache logic will automatically spread to headers, except flushing) + // - cut header from in-memory objects directly and persist headers into particular bucket of DB + // (explicit sync with full objects is needed) + // - try to pull out binary header from binary full object (not sure if it is possible) + obj, err := c.Get(addr) + if err != nil { + return nil, err + } + + // NOTE: resetting the payload via the setter can lead to data corruption of in-memory objects, but ok for others + return object.NewRawFromObject(obj).CutPayload().Object(), nil +}