mount

package
v0.0.0-...-537c012 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSeekUnsupported is returned when Seek is called on a mount that is
	// not seekable.
	ErrSeekUnsupported = errors.New("mount does not support seek")

	// ErrRandomAccessUnsupported is returned when ReadAt is called on a mount
	// that does not support random access.
	ErrRandomAccessUnsupported = errors.New("mount does not support random access")
)
View Source
var (
	// ErrUnrecognizedScheme is returned by Instantiate() when attempting to
	// initialize a Mount with an unrecognized URL scheme.
	ErrUnrecognizedScheme = errors.New("unrecognized mount scheme")

	// ErrUnrecognizedType is returned by Encode() when attempting to
	// represent a Mount whose type has not been registered.
	ErrUnrecognizedType = errors.New("unrecognized mount type")
)

Functions

This section is empty.

Types

type BytesMount

type BytesMount struct {
	Bytes []byte
}

BytesMount encloses a byte slice. It is mainly used for testing. The Upgrader passes through it.

func (*BytesMount) Close

func (b *BytesMount) Close() error

func (*BytesMount) Deserialize

func (b *BytesMount) Deserialize(u *url.URL) error

func (*BytesMount) Fetch

func (b *BytesMount) Fetch(_ context.Context) (Reader, error)

func (*BytesMount) Info

func (b *BytesMount) Info() Info

func (*BytesMount) Serialize

func (b *BytesMount) Serialize() *url.URL

func (*BytesMount) Stat

func (b *BytesMount) Stat(_ context.Context) (Stat, error)

type Counting

type Counting struct {
	Mount
	// contains filtered or unexported fields
}

Counting is a mount that proxies to another mount and counts the number of calls made to Fetch. It is mostly used in tests.

func (*Counting) Count

func (c *Counting) Count() int

func (*Counting) Fetch

func (c *Counting) Fetch(ctx context.Context) (Reader, error)

type FSMount

type FSMount struct {
	FS   fs.FS
	Path string
}

FSMount is a mount that opens the file indicated by Path, using the provided fs.FS. Given that io/fs does not support random access patterns, this mount requires an Upgrade. It is suitable for testing.

func (*FSMount) Close

func (f *FSMount) Close() error

func (*FSMount) Deserialize

func (f *FSMount) Deserialize(u *url.URL) error

func (*FSMount) Fetch

func (f *FSMount) Fetch(ctx context.Context) (Reader, error)

func (*FSMount) Info

func (f *FSMount) Info() Info

func (*FSMount) Serialize

func (f *FSMount) Serialize() *url.URL

func (*FSMount) Stat

func (f *FSMount) Stat(_ context.Context) (Stat, error)

type FileMount

type FileMount struct {
	Path string
}

func (*FileMount) Close

func (f *FileMount) Close() error

func (*FileMount) Deserialize

func (f *FileMount) Deserialize(u *url.URL) error

func (*FileMount) Fetch

func (f *FileMount) Fetch(_ context.Context) (Reader, error)

func (*FileMount) Info

func (f *FileMount) Info() Info

func (*FileMount) Serialize

func (f *FileMount) Serialize() *url.URL

func (*FileMount) Stat

func (f *FileMount) Stat(_ context.Context) (Stat, error)

type Info

type Info struct {
	// Kind indicates the kind of mount.
	Kind Kind

	// TODO convert to bitfield
	AccessSequential bool
	AccessSeek       bool
	AccessRandom     bool
}

Info describes a mount.

type Kind

type Kind int

Kind is an enum describing the source of a Mount.

const (
	// KindLocal indicates that the asset represented by this mount is of
	// transient provenance (e.g. filesystem mount). A call to Fetch() will open a
	// transient stream.
	//
	// Note that mounts of this kind may be indirectly backed by underlying storage
	// (e.g. NFS, FUSE), but from the viewpoint of the DAG store, the resource
	// is considered transient.
	KindLocal Kind = iota

	// KindRemote indicates that the asset represented by this mount is
	// fetched from a underlying provenance (e.g. HTTP, Filecoin sealing cluster,
	// IPFS, etc.) A call to Fetch() is likely to download the asset from
	// a underlying source, thus it is advisable to cache the asset locally once
	// downloaded.
	KindRemote
)

type Mount

type Mount interface {
	io.Closer

	// Fetch returns a Reader for this mount. Not all read access methods
	// may be supported. Check the Info object to determine which access methods
	// are effectively supported.
	//
	// To seamlessly upgrade a Mount to a fully-featured mount by using a transient
	// transient file, use the Upgrader.
	Fetch(ctx context.Context) (Reader, error)

	// Info describes the Mount. This is a pure function.
	Info() Info

	// Stat describes the underlying resource.
	Stat(ctx context.Context) (Stat, error)

	// Serialize returns a canonical URL that can be used to revive the Mount
	// after a restart.
	Serialize() *url.URL

	// Deserialize configures this Mount from the specified URL.
	Deserialize(*url.URL) error
}

Mount is a pluggable component that represents the original location of the data contained in a shard known to the DAG store. The backing resource is a CAR file.

Shards can be located anywhere, and can come and go dynamically e.g. Filecoin deals expire, removable media is attached/detached, or the IPFS user purges content.

It is possible to mount shards with CARs accessible through the transient filesystem, detachable mounts, NFS mounts, distributed filesystems like Ceph/GlusterFS, HTTP, FTP, etc.

Mount implementations are free to define constructor parameters or setters to supply arguments needed to initialize the mount, such as credentials, sector IDs, CIDs, etc.

MountTypes must define a deterministic URL representation which will be used to:

a. deserialise the Mount from DAG persistence when resuming the system by
   using a pre-defined Mount factory mapped to the URL scheme.
b. support adding mounts from configuration files.

type NopCloser

type NopCloser struct {
	io.Reader
	io.ReaderAt
	io.Seeker
}

func (*NopCloser) Close

func (*NopCloser) Close() error

type Reader

type Reader interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
}

Reader is a fully-featured Reader returned from MountTypes. It is the union of the standard IO sequential access method (Read), with seeking ability (Seek), as well random access (ReadAt).

type Registry

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

Registry is a registry of Mount factories known to the DAG store.

func NewRegistry

func NewRegistry() *Registry

NewRegistry constructs a blank registry.

func (*Registry) Instantiate

func (r *Registry) Instantiate(u *url.URL) (Mount, error)

Instantiate instantiates a new Mount from a URL.

It looks up the Mount template in the registry based on the URL scheme, creates a copy, and calls Deserialize() on it with the supplied URL before returning.

It propagates any error returned by the Mount#Deserialize method. If the scheme is not recognized, it returns ErrUnrecognizedScheme.

func (*Registry) Register

func (r *Registry) Register(scheme string, template Mount) error

Register adds a new mount type to the registry under the specified scheme.

The supplied Mount is used as a template to create new instances.

This means that the provided Mount can contain environmental configuration that will be automatically carried over to all instances.

func (*Registry) Represent

func (r *Registry) Represent(mount Mount) (*url.URL, error)

Represent returns the URL representation of a Mount, using the scheme that was registered for that type of mount.

type Stat

type Stat struct {
	// Exists indicates if the asset exists.
	Exists bool
	// Size is the size of the asset referred to by this Mount.
	Size int64
	// Ready indicates whether the mount can serve the resource immediately, or
	// if it needs to do work prior to serving it.
	Ready bool
}

Stat

type Upgrader

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

Upgrader is a bridge to upgrade any Mount into one with full-featured Reader capabilities, whether the original mount is of remote or local kind. It does this by managing a local transient copy.

If the underlying mount is fully-featured, the Upgrader has no effect, and simply passes through to the underlying mount.

func Upgrade

func Upgrade(underlying Mount, throttler throttle.Throttler, rootdir, key string, initial string) (*Upgrader, error)

Upgrade constructs a new Upgrader for the underlying Mount. If provided, it will reuse the file in path `initial` as the initial transient copy. Whenever a new transient copy has to be created, it will be created under `rootdir`.

func (*Upgrader) Close

func (u *Upgrader) Close() error

TODO implement

func (*Upgrader) DeleteTransient

func (u *Upgrader) DeleteTransient() error

DeleteTransient deletes the transient associated with this Upgrader, if one exists. It is the caller's responsibility to ensure the transient is not in use. If the tracked transient is gone, this will reset the internal state to "" (no transient) to enable recovery.

func (*Upgrader) Deserialize

func (u *Upgrader) Deserialize(url *url.URL) error

func (*Upgrader) Fetch

func (u *Upgrader) Fetch(ctx context.Context) (Reader, error)

func (*Upgrader) Info

func (u *Upgrader) Info() Info

func (*Upgrader) Serialize

func (u *Upgrader) Serialize() *url.URL

func (*Upgrader) Stat

func (u *Upgrader) Stat(ctx context.Context) (Stat, error)

func (*Upgrader) TimesFetched

func (u *Upgrader) TimesFetched() int

TimesFetched returns the number of times that the underlying has been fetched.

func (*Upgrader) TransientPath

func (u *Upgrader) TransientPath() string

TransientPath returns the local path of the transient file, if one exists.

func (*Upgrader) Underlying

func (u *Upgrader) Underlying() Mount

Underlying returns the underlying mount.

Jump to

Keyboard shortcuts

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