2018-01-29 14:37:26 -05:00
|
|
|
package store
|
|
|
|
|
2019-10-03 16:34:57 -04:00
|
|
|
import (
|
2019-11-13 19:11:35 -05:00
|
|
|
"github.com/lbryio/lbry.go/v2/extras/errors"
|
|
|
|
"github.com/lbryio/lbry.go/v2/stream"
|
2019-10-03 16:34:57 -04:00
|
|
|
)
|
2018-02-07 15:21:20 -05:00
|
|
|
|
2019-10-03 16:47:23 -04:00
|
|
|
// BlobStore is an interface for handling blob storage.
|
2018-01-29 14:37:26 -05:00
|
|
|
type BlobStore interface {
|
2020-10-22 13:49:02 -04:00
|
|
|
// Name of blob store (useful for metrics)
|
|
|
|
Name() string
|
2020-10-29 14:22:58 -04:00
|
|
|
// Does blob exist in the store.
|
2018-09-20 11:24:36 -04:00
|
|
|
Has(hash string) (bool, error)
|
2020-10-29 14:22:58 -04:00
|
|
|
// Get the blob from the store. Must return ErrBlobNotFound if blob is not in store.
|
2019-10-03 16:34:57 -04:00
|
|
|
Get(hash string) (stream.Blob, error)
|
2020-10-29 14:22:58 -04:00
|
|
|
// Put the blob into the store.
|
2019-10-03 16:34:57 -04:00
|
|
|
Put(hash string, blob stream.Blob) error
|
2020-10-29 14:22:58 -04:00
|
|
|
// Put an SD blob into the store.
|
2019-10-03 16:34:57 -04:00
|
|
|
PutSD(hash string, blob stream.Blob) error
|
2020-10-29 14:22:58 -04:00
|
|
|
// Delete the blob from the store.
|
2018-09-20 11:24:36 -04:00
|
|
|
Delete(hash string) error
|
|
|
|
}
|
|
|
|
|
2019-10-03 13:36:35 -04:00
|
|
|
// Blocklister is a store that supports blocking blobs to prevent their inclusion in the store.
|
2018-09-20 11:24:36 -04:00
|
|
|
type Blocklister interface {
|
|
|
|
// Block deletes the blob and prevents it from being uploaded in the future
|
|
|
|
Block(hash string) error
|
2019-10-03 13:36:35 -04:00
|
|
|
// Wants returns false if the hash exists in store or is blocked, true otherwise
|
2018-09-20 11:24:36 -04:00
|
|
|
Wants(hash string) (bool, error)
|
2018-01-29 14:37:26 -05:00
|
|
|
}
|
2018-02-07 15:21:20 -05:00
|
|
|
|
2020-10-22 12:18:31 -04:00
|
|
|
// lister is a store that can list cached blobs. This is helpful when an overlay
|
|
|
|
// cache needs to track blob existence.
|
|
|
|
type lister interface {
|
|
|
|
list() ([]string, error)
|
|
|
|
}
|
|
|
|
|
2018-05-29 21:38:55 -04:00
|
|
|
//ErrBlobNotFound is a standard error when a blob is not found in the store.
|
2018-02-07 15:21:20 -05:00
|
|
|
var ErrBlobNotFound = errors.Base("blob not found")
|