lease

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2015 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package lease contains types to help manage disk usage of temporary files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileLeaser

type FileLeaser interface {
	// Create a new anonymous file, and return a read/write lease for it. The
	// read/write lease will pin resources until rwl.Downgrade is called. It need
	// not be called if the process is exiting.
	NewFile() (rwl ReadWriteLease, err error)

	// Revoke all read leases that have been issued. For testing use only.
	RevokeReadLeases()
}

A type that manages read and read/write leases for anonymous temporary files.

Safe for concurrent access.

func NewFileLeaser

func NewFileLeaser(
	dir string,
	limitNumFiles int,
	limitBytes int64) (fl FileLeaser)

Create a new file leaser that uses the supplied directory for temporary files (before unlinking them) and attempts to keep usage in number of files and bytes below the given limits. If dir is empty, the system default will be used.

Usage may exceed the given limits if there are read/write leases whose total size exceeds the limits, since such leases cannot be revoked.

type ReadLease

type ReadLease interface {
	io.ReadSeeker
	io.ReaderAt

	// Return the size of the underlying file, or what the size used to be if the
	// lease has been revoked.
	Size() (size int64)

	// Has the lease been revoked? Note that this is completely racy in the
	// absence of external synchronization on all leases and the file leaser, so
	// is suitable only for testing purposes.
	Revoked() (revoked bool)

	// Attempt to upgrade the lease to a read/write lease. After successfully
	// upgrading, it is as if the lease has been revoked.
	Upgrade() (rwl ReadWriteLease, err error)

	// Cause the lease to be revoked and any associated resources to be cleaned
	// up, if it has not already been revoked.
	Revoke()
}

A read-only wrapper around a file that may be revoked, when e.g. there is temporary disk space pressure. A read lease may also be upgraded to a write lease, if it is still valid.

All methods are safe for concurrent access.

type ReadProxy

type ReadProxy interface {
	// Return the size of the proxied content. Guarantees to not block.
	Size() (size int64)

	// Semantics matching io.ReaderAt, except with context support and without
	// the guarantee of being thread-safe.
	ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

	// Return a read/write lease for the proxied contents, destroying the read
	// proxy. The read proxy must not be used after calling this method.
	Upgrade(ctx context.Context) (rwl ReadWriteLease, err error)

	// Destroy any resources in use by the read proxy. It must not be used
	// further.
	Destroy()

	// Panic if any internal invariants are violated.
	CheckInvariants()
}

A wrapper around a read lease, exposing a similar interface with the following differences:

  • Contents are fetched and re-fetched automatically when needed. Therefore the user need not worry about lease expiration.

  • Methods that may involve fetching the contents (reading, seeking) accept context arguments, so as to be cancellable.

  • Only random access reading is supported.

External synchronization is required.

func NewMultiReadProxy

func NewMultiReadProxy(
	fl FileLeaser,
	refreshers []Refresher,
	rl ReadLease) (rp ReadProxy)

Create a read proxy consisting of the contents defined by the supplied refreshers concatenated. See NewReadProxy for more.

If rl is non-nil, it will be used as the first temporary copy of the contents, and must match the concatenation of the content returned by the refreshers.

func NewReadProxy

func NewReadProxy(
	fl FileLeaser,
	r Refresher,
	rl ReadLease) (rp ReadProxy)

Create a read proxy.

The supplied refresher will be used to obtain the proxy's contents whenever the file leaser decides to expire the temporary copy thus obtained.

If rl is non-nil, it will be used as the first temporary copy of the contents, and must match what the refresher returns.

type ReadWriteLease

type ReadWriteLease interface {
	// Methods with semantics matching *os.File.
	io.ReadWriteSeeker
	io.ReaderAt
	io.WriterAt
	Truncate(size int64) (err error)

	// Return the current size of the underlying file.
	Size() (size int64, err error)

	// Downgrade to a read lease, releasing any resources pinned by this lease to
	// the pool that may be revoked, as with any read lease. After downgrading,
	// this lease must not be used again.
	Downgrade() (rl ReadLease)
}

A read-write wrapper around a file. Unlike a read lease, this cannot be revoked.

All methods are safe for concurrent access.

type Refresher

type Refresher interface {
	// Return the size of the underlying contents.
	Size() (size int64)

	// Return a read-closer for the contents. The same contents will always be
	// returned, and they will always be of length Size().
	Refresh(ctx context.Context) (rc io.ReadCloser, err error)
}

A type used by read proxies to refresh their contents. See notes on NewReadProxy.

type RevokedError

type RevokedError struct {
}

A sentinel error used when a lease has been revoked.

func (*RevokedError) Error

func (re *RevokedError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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