diff options
Diffstat (limited to 'objectstore/chain')
| -rw-r--r-- | objectstore/chain/bytes.go | 8 | ||||
| -rw-r--r-- | objectstore/chain/chain.go | 5 | ||||
| -rw-r--r-- | objectstore/chain/close.go | 25 | ||||
| -rw-r--r-- | objectstore/chain/header.go | 4 | ||||
| -rw-r--r-- | objectstore/chain/new.go | 3 | ||||
| -rw-r--r-- | objectstore/chain/reader.go | 8 | ||||
| -rw-r--r-- | objectstore/chain/refresh.go | 4 | ||||
| -rw-r--r-- | objectstore/chain/size.go | 4 |
8 files changed, 13 insertions, 48 deletions
diff --git a/objectstore/chain/bytes.go b/objectstore/chain/bytes.go index 007c7522..64771608 100644 --- a/objectstore/chain/bytes.go +++ b/objectstore/chain/bytes.go @@ -12,10 +12,6 @@ import ( // ReadBytesFull reads a full serialized object from the first backend that has it. func (chain *Chain) ReadBytesFull(id objectid.ObjectID) ([]byte, error) { for i, backend := range chain.backends { - if backend == nil { - continue - } - full, err := backend.ReadBytesFull(id) if err == nil { return full, nil @@ -34,10 +30,6 @@ func (chain *Chain) ReadBytesFull(id objectid.ObjectID) ([]byte, error) { // ReadBytesContent reads an object's type and content bytes from the first backend that has it. func (chain *Chain) ReadBytesContent(id objectid.ObjectID) (objecttype.Type, []byte, error) { for i, backend := range chain.backends { - if backend == nil { - continue - } - ty, content, err := backend.ReadBytesContent(id) if err == nil { return ty, content, nil diff --git a/objectstore/chain/chain.go b/objectstore/chain/chain.go index 2b17369d..00e98b91 100644 --- a/objectstore/chain/chain.go +++ b/objectstore/chain/chain.go @@ -1,4 +1,5 @@ -// Package chain provides a wrapper object storage backend to query a chain of backends. +// Package chain provides a wrapper object storage backend to query a chain of +// backends. package chain import ( @@ -6,6 +7,8 @@ import ( ) // Chain queries multiple object databases in order. +// +// Chain borrows its backend stores. type Chain struct { backends []objectstore.Store } diff --git a/objectstore/chain/close.go b/objectstore/chain/close.go index 440afb10..6bd74565 100644 --- a/objectstore/chain/close.go +++ b/objectstore/chain/close.go @@ -1,21 +1,8 @@ package chain -import "errors" - -// Close closes all backends and joins close errors. -func (chain *Chain) Close() error { - var errs []error - - for _, backend := range chain.backends { - if backend == nil { - continue - } - - err := backend.Close() - if err != nil { - errs = append(errs, err) - } - } - - return errors.Join(errs...) -} +// Close releases wrapper-local resources. +// +// Chain borrows its backends, so Close does not close them. +// +// Repeated calls to Close are undefined behavior. +func (chain *Chain) Close() error { return nil } diff --git a/objectstore/chain/header.go b/objectstore/chain/header.go index c1d4692c..59f6bba6 100644 --- a/objectstore/chain/header.go +++ b/objectstore/chain/header.go @@ -12,10 +12,6 @@ import ( // ReadHeader reads object header data from the first backend that has it. func (chain *Chain) ReadHeader(id objectid.ObjectID) (objecttype.Type, int64, error) { for i, backend := range chain.backends { - if backend == nil { - continue - } - ty, size, err := backend.ReadHeader(id) if err == nil { return ty, size, nil diff --git a/objectstore/chain/new.go b/objectstore/chain/new.go index ca00e9be..887904e3 100644 --- a/objectstore/chain/new.go +++ b/objectstore/chain/new.go @@ -3,6 +3,9 @@ package chain import "codeberg.org/lindenii/furgit/objectstore" // New creates an ordered object database chain. +// +// The provided backends must be non-nil and distinct. +// Chain borrows the provided backends and does not close them in Close. func New(backends ...objectstore.Store) *Chain { return &Chain{ backends: append([]objectstore.Store(nil), backends...), diff --git a/objectstore/chain/reader.go b/objectstore/chain/reader.go index e005d929..41060a5b 100644 --- a/objectstore/chain/reader.go +++ b/objectstore/chain/reader.go @@ -13,10 +13,6 @@ import ( // ReadReaderFull reads a full serialized object stream from the first backend that has it. func (chain *Chain) ReadReaderFull(id objectid.ObjectID) (io.ReadCloser, error) { for i, backend := range chain.backends { - if backend == nil { - continue - } - reader, err := backend.ReadReaderFull(id) if err == nil { return reader, nil @@ -35,10 +31,6 @@ func (chain *Chain) ReadReaderFull(id objectid.ObjectID) (io.ReadCloser, error) // ReadReaderContent reads an object's type, declared content length, and content stream from the first backend that has it. func (chain *Chain) ReadReaderContent(id objectid.ObjectID) (objecttype.Type, int64, io.ReadCloser, error) { for i, backend := range chain.backends { - if backend == nil { - continue - } - ty, size, reader, err := backend.ReadReaderContent(id) if err == nil { return ty, size, reader, nil diff --git a/objectstore/chain/refresh.go b/objectstore/chain/refresh.go index 66c6f0a0..c47352dc 100644 --- a/objectstore/chain/refresh.go +++ b/objectstore/chain/refresh.go @@ -7,10 +7,6 @@ func (chain *Chain) Refresh() error { var errs []error for _, backend := range chain.backends { - if backend == nil { - continue - } - err := backend.Refresh() if err != nil { errs = append(errs, err) diff --git a/objectstore/chain/size.go b/objectstore/chain/size.go index 38aa7abc..9815317f 100644 --- a/objectstore/chain/size.go +++ b/objectstore/chain/size.go @@ -11,10 +11,6 @@ import ( // ReadSize reads object content length from the first backend that has it. func (chain *Chain) ReadSize(id objectid.ObjectID) (int64, error) { for i, backend := range chain.backends { - if backend == nil { - continue - } - size, err := backend.ReadSize(id) if err == nil { return size, nil |
