storage

package
v0.0.0-...-03c569e Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package storage provides storage abstraction for LevelDB.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFile = errors.New("leveldb/storage: invalid file for argument")
	ErrLocked      = errors.New("leveldb/storage: already locked")
	ErrClosed      = errors.New("leveldb/storage: closed")
)

Common error.

Functions

func FileDescOk

func FileDescOk(fd FileDesc) bool

FileDescOk returns true if fd is a valid 'file descriptor'.

Types

type ErrCorrupted

type ErrCorrupted struct {
	Fd  FileDesc
	Err error
}

ErrCorrupted is the type that wraps errors that indicate corruption of a file. Package storage has its own type instead of using errors.ErrCorrupted to prevent circular import.

func (*ErrCorrupted) Error

func (e *ErrCorrupted) Error() string

type FileDesc

type FileDesc struct {
	Type FileType
	Num  int64
}

FileDesc is a 'file descriptor'.

func (FileDesc) String

func (fd FileDesc) String() string

func (FileDesc) Zero

func (fd FileDesc) Zero() bool

Zero returns true if fd == (FileDesc{}).

type FileType

type FileType int

FileType represent a file type.

const (
	TypeManifest FileType = 1 << iota
	TypeJournal
	TypeTable
	TypeTemp

	TypeAll = TypeManifest | TypeJournal | TypeTable | TypeTemp
)

File types.

func (FileType) String

func (t FileType) String() string

type Locker

type Locker interface {
	Unlock()
}

Locker is the interface that wraps Unlock method.

type Reader

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

Reader is the interface that groups the basic Read, Seek, ReadAt and Close methods.

type Storage

type Storage interface {
	// Lock locks the storage. Any subsequent attempt to call Lock will fail
	// until the last lock released.
	// Caller should call Unlock method after use.
	Lock() (Locker, error)

	// Log logs a string. This is used for logging.
	// An implementation may write to a file, stdout or simply do nothing.
	Log(str string)

	// SetMeta store 'file descriptor' that can later be acquired using GetMeta
	// method. The 'file descriptor' should point to a valid file.
	// SetMeta should be implemented in such way that changes should happen
	// atomically.
	SetMeta(fd FileDesc) error

	// GetMeta returns 'file descriptor' stored in meta. The 'file descriptor'
	// can be updated using SetMeta method.
	// Returns os.ErrNotExist if meta doesn't store any 'file descriptor', or
	// 'file descriptor' point to nonexistent file.
	GetMeta() (FileDesc, error)

	// List returns file descriptors that match the given file types.
	// The file types may be OR'ed together.
	List(ft FileType) ([]FileDesc, error)

	// Open opens file with the given 'file descriptor' read-only.
	// Returns os.ErrNotExist error if the file does not exist.
	// Returns ErrClosed if the underlying storage is closed.
	Open(fd FileDesc) (Reader, error)

	// Create creates file with the given 'file descriptor', truncate if already
	// exist and opens write-only.
	// Returns ErrClosed if the underlying storage is closed.
	Create(fd FileDesc) (Writer, error)

	// Remove removes file with the given 'file descriptor'.
	// Returns ErrClosed if the underlying storage is closed.
	Remove(fd FileDesc) error

	// Rename renames file from oldfd to newfd.
	// Returns ErrClosed if the underlying storage is closed.
	Rename(oldfd, newfd FileDesc) error

	// Close closes the storage.
	// It is valid to call Close multiple times. Other methods should not be
	// called after the storage has been closed.
	Close() error
}

Storage is the storage. A storage instance must be safe for concurrent use.

func NewMemStorage

func NewMemStorage() Storage

NewMemStorage returns a new memory-backed storage implementation.

func OpenFile

func OpenFile(path string, readOnly bool) (Storage, error)

OpenFile returns a new filesystem-backed storage implementation with the given path. This also acquire a file lock, so any subsequent attempt to open the same path will fail.

The storage must be closed after use, by calling Close method.

type Syncer

type Syncer interface {
	// Sync commits the current contents of the file to stable storage.
	Sync() error
}

Syncer is the interface that wraps basic Sync method.

type Writer

type Writer interface {
	io.WriteCloser
	Syncer
}

Writer is the interface that groups the basic Write, Sync and Close methods.

Jump to

Keyboard shortcuts

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