filestore

package
v1.23.2-rc-multipart Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2021 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FormatV0 is the identifier for storage format v0, which also corresponds to an absence of
	// format version information.
	FormatV0 storage.FormatVersion = 0
	// FormatV1 is the identifier for storage format v1.
	FormatV1 storage.FormatVersion = 1
)
View Source
const (
	// MaxFormatVersionSupported is the highest supported storage format version for reading, and
	// the only supported storage format version for writing. If stored blobs claim a higher
	// storage format version than this, or a caller requests _writing_ a storage format version
	// which is not this, this software will not know how to perform the read or write and an error
	// will be returned.
	MaxFormatVersionSupported = FormatV1

	// MinFormatVersionSupported is the lowest supported storage format version for reading. If
	// stored blobs claim a lower storage format version than this, this software will not know how
	// to perform the read and an error will be returned.
	MinFormatVersionSupported = FormatV0
)

Variables

View Source
var DefaultConfig = Config{
	WriteBufferSize: 128 * memory.KiB,
}

DefaultConfig is the default value for Config.

View Source
var (
	// Error is the default filestore error class.
	Error = errs.Class("filestore error")
)

Functions

func New

func New(log *zap.Logger, dir *Dir, config Config) storage.Blobs

New creates a new disk blob store in the specified directory.

func NewAt

func NewAt(log *zap.Logger, path string, config Config) (storage.Blobs, error)

NewAt creates a new disk blob store in the specified directory.

Types

type Config added in v1.4.1

type Config struct {
	WriteBufferSize memory.Size `help:"in-memory buffer for uploads" default:"128KiB"`
}

Config is configuration for the blob store.

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

Dir represents single folder for storing blobs.

func NewDir

func NewDir(log *zap.Logger, path string) (*Dir, error)

NewDir returns folder for storing blobs.

func OpenDir added in v1.10.1

func OpenDir(log *zap.Logger, path string) (*Dir, error)

OpenDir opens existing folder for storing blobs.

func (*Dir) Commit

func (dir *Dir) Commit(ctx context.Context, file *os.File, ref storage.BlobRef, formatVersion storage.FormatVersion) (err error)

Commit commits the temporary file to permanent storage.

func (*Dir) CreateTemporaryFile

func (dir *Dir) CreateTemporaryFile(ctx context.Context, prealloc int64) (_ *os.File, err error)

CreateTemporaryFile creates a preallocated temporary file in the temp directory prealloc preallocates file to make writing faster.

func (*Dir) CreateVerificationFile added in v1.11.1

func (dir *Dir) CreateVerificationFile(id storj.NodeID) error

CreateVerificationFile creates a file to be used for storage directory verification.

func (*Dir) Delete

func (dir *Dir) Delete(ctx context.Context, ref storage.BlobRef) (err error)

Delete deletes blobs with the specified ref (in all supported storage formats).

It doesn't return an error if the blob is not found for any reason or it cannot be deleted at this moment and it's delayed.

func (*Dir) DeleteNamespace added in v1.8.1

func (dir *Dir) DeleteNamespace(ctx context.Context, ref []byte) (err error)

DeleteNamespace deletes blobs folder for a specific namespace.

func (*Dir) DeleteTemporary

func (dir *Dir) DeleteTemporary(ctx context.Context, file *os.File) (err error)

DeleteTemporary deletes a temporary file.

func (*Dir) DeleteWithStorageFormat added in v0.25.0

func (dir *Dir) DeleteWithStorageFormat(ctx context.Context, ref storage.BlobRef, formatVer storage.FormatVersion) (err error)

DeleteWithStorageFormat deletes the blob with the specified ref for one specific format version. The method tries the following strategies, in order of preference until one succeeds:

* moves the blob to garbage dir. * directly deletes the blob. * push the blobs to queue for retrying later.

It doesn't return an error if the piece isn't found for any reason.

func (*Dir) EmptyTrash added in v0.27.0

func (dir *Dir) EmptyTrash(ctx context.Context, namespace []byte, trashedBefore time.Time) (bytesEmptied int64, deletedKeys [][]byte, err error)

EmptyTrash walks the trash files for the given namespace and deletes any file whose mtime is older than trashedBefore. The mtime is modified when Trash is called.

func (*Dir) GarbageCollect

func (dir *Dir) GarbageCollect(ctx context.Context) (err error)

GarbageCollect collects files that are pending deletion.

func (*Dir) Info

func (dir *Dir) Info() (DiskInfo, error)

Info returns information about the current state of the dir.

func (*Dir) ListNamespaces added in v0.18.0

func (dir *Dir) ListNamespaces(ctx context.Context) (ids [][]byte, err error)

ListNamespaces finds all known namespace IDs in use in local storage. They are not guaranteed to contain any blobs.

func (*Dir) Open

func (dir *Dir) Open(ctx context.Context, ref storage.BlobRef) (_ *os.File, _ storage.FormatVersion, err error)

Open opens the file with the specified ref. It may need to check in more than one location in order to find the blob, if it was stored with an older version of the storage node software. In cases where the storage format version of a blob is already known, OpenWithStorageFormat() will generally be a better choice.

func (*Dir) OpenWithStorageFormat added in v0.18.0

func (dir *Dir) OpenWithStorageFormat(ctx context.Context, ref storage.BlobRef, formatVer storage.FormatVersion) (_ *os.File, err error)

OpenWithStorageFormat opens an already-located blob file with a known storage format version, which avoids the potential need to search through multiple storage formats to find the blob.

func (*Dir) Path

func (dir *Dir) Path() string

Path returns the directory path.

func (*Dir) ReplaceTrashnow added in v0.27.0

func (dir *Dir) ReplaceTrashnow(trashnow func() time.Time)

ReplaceTrashnow is a helper for tests to replace the trashnow function used when moving files to the trash.

func (*Dir) RestoreTrash added in v0.26.0

func (dir *Dir) RestoreTrash(ctx context.Context, namespace []byte) (keysRestored [][]byte, err error)

RestoreTrash moves every piece in the trash folder back into blobsdir.

func (*Dir) Stat added in v0.18.0

func (dir *Dir) Stat(ctx context.Context, ref storage.BlobRef) (_ storage.BlobInfo, err error)

Stat looks up disk metadata on the blob file. It may need to check in more than one location in order to find the blob, if it was stored with an older version of the storage node software. In cases where the storage format version of a blob is already known, StatWithStorageFormat() will generally be a better choice.

func (*Dir) StatWithStorageFormat added in v0.18.0

func (dir *Dir) StatWithStorageFormat(ctx context.Context, ref storage.BlobRef, formatVer storage.FormatVersion) (_ storage.BlobInfo, err error)

StatWithStorageFormat looks up disk metadata on the blob file with the given storage format version. This avoids the need for checking for the file in multiple different storage format types.

func (*Dir) Trash added in v0.26.0

func (dir *Dir) Trash(ctx context.Context, ref storage.BlobRef) (err error)

Trash moves the piece specified by ref to the trashdir for every format version.

func (*Dir) TrashWithStorageFormat added in v0.26.0

func (dir *Dir) TrashWithStorageFormat(ctx context.Context, ref storage.BlobRef, formatVer storage.FormatVersion) (err error)

TrashWithStorageFormat moves the piece specified by ref to the trashdir for the specified format version.

func (*Dir) Verify added in v1.11.1

func (dir *Dir) Verify(id storj.NodeID) error

Verify verifies that the storage directory is correct by checking for the existence and validity of the verification file.

func (*Dir) WalkNamespace added in v0.18.0

func (dir *Dir) WalkNamespace(ctx context.Context, namespace []byte, walkFunc func(storage.BlobInfo) error) (err error)

WalkNamespace executes walkFunc for each locally stored blob, stored with storage format V1 or greater, in the given namespace. If walkFunc returns a non-nil error, WalkNamespace will stop iterating and return the error immediately. The ctx parameter is intended specifically to allow canceling iteration early.

type DiskInfo

type DiskInfo struct {
	ID             string
	AvailableSpace int64
}

DiskInfo contains statistics about this dir.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL