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