storage

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 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")
)

Functions

This section is empty.

Types

type File

type File interface {
	// Open opens the file for read. Returns os.ErrNotExist error
	// if the file does not exist.
	// Returns ErrClosed if the underlying storage is closed.
	Open() (r Reader, err error)

	// Create creates the file for writting. Truncate the file if
	// already exist.
	// Returns ErrClosed if the underlying storage is closed.
	Create() (w Writer, err error)

	// Replace replaces file with newfile.
	// Returns ErrClosed if the underlying storage is closed.
	Replace(newfile File) error

	// Type returns the file type
	Type() FileType

	// Num returns the file number.
	Num() uint64

	// Remove removes the file.
	// Returns ErrClosed if the underlying storage is closed.
	Remove() error
}

File is the file. A file instance must be goroutine-safe.

type FileInfo

type FileInfo struct {
	Type FileType
	Num  uint64
}

FileInfo wraps basic file info.

func NewFileInfo

func NewFileInfo(f File) *FileInfo

NewFileInfo creates new FileInfo from the given File. It will returns nil if File is nil.

func (FileInfo) String

func (fi FileInfo) String() string

type FileType

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

	TypeAll = TypeManifest | TypeJournal | TypeTable | TypeTemp
)

func (FileType) String

func (t FileType) String() string

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.
	// After use the caller should call the Release method.
	Lock() (l util.Releaser, err 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)

	// GetFile returns a file for the given number and type. GetFile will never
	// returns nil, even if the underlying storage is closed.
	GetFile(num uint64, t FileType) File

	// GetFiles returns a slice of files that match the given file types.
	// The file types may be OR'ed together.
	GetFiles(t FileType) ([]File, error)

	// GetManifest returns a manifest file. Returns os.ErrNotExist if manifest
	// file does not exist.
	GetManifest() (File, error)

	// SetManifest sets the given file as manifest file. The given file should
	// be a manifest file type or error will be returned.
	SetManifest(f File) 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 goroutine-safe.

func NewMemStorage

func NewMemStorage() Storage

NewMemStorage returns a new memory-backed storage implementation.

func OpenFile

func OpenFile(path string) (Storage, error)

OpenFile returns a new filesytem-backed storage implementation with the given path. This also hold 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