storage

package
v0.0.0-...-1975910 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2013 License: BSD-2-Clause Imports: 11 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("invalid file for argument")
	ErrLocked      = errors.New("already locked")
	ErrNotLocked   = errors.New("not locked")
	ErrInvalidLock = errors.New("invalid lock handle")
)

Functions

This section is empty.

Types

type File

type File interface {
	// Open file for read.
	// Should return os.ErrNotExist if the file does not exist.
	Open() (r Reader, err error)

	// Create file for write. Truncate if file already exist.
	Create() (w Writer, err error)

	// Rename to given number and type.
	Rename(number uint64, t FileType) error

	// Return true if the file is exist.
	Exist() bool

	// Return file type.
	Type() FileType

	// Return file number
	Num() uint64

	// Return size of the file.
	Size() (size uint64, err error)

	// Remove file.
	Remove() error
}

type FileStorage

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

FileStorage provide implementation of file-system backed storage.

func OpenFile

func OpenFile(dbpath string) (d *FileStorage, err error)

OpenFile creates new initialized FileStorage for given path. This will also hold file lock; thus any subsequent attempt to open same file path will fail.

func (*FileStorage) Close

func (d *FileStorage) Close() error

Close closes the storage and release the lock.

func (*FileStorage) GetFile

func (d *FileStorage) GetFile(number uint64, t FileType) File

GetFile get file with given number and type.

func (*FileStorage) GetFiles

func (d *FileStorage) GetFiles(t FileType) (r []File)

GetFiles get all files that match given file types; multiple file type may OR'ed together.

func (*FileStorage) GetManifest

func (d *FileStorage) GetManifest() (f File, err error)

GetManifest get manifest file.

func (*FileStorage) Lock

func (d *FileStorage) Lock() (l Locker, err error)

Lock lock the storage.

func (*FileStorage) Print

func (d *FileStorage) Print(str string)

Print write given str to the log file.

func (*FileStorage) SetManifest

func (d *FileStorage) SetManifest(f File) (err error)

SetManifest set manifest to given file.

type FileType

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

	TypeAll = TypeManifest | TypeJournal | TypeTable
)

func (FileType) String

func (t FileType) String() string

type Locker

type Locker interface {
	Release() error
}

type MemStorage

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

MemStorage provide implementation of memory backed storage.

func (*MemStorage) GetFile

func (m *MemStorage) GetFile(num uint64, t FileType) File

GetFile get file with given number and type.

func (*MemStorage) GetFiles

func (m *MemStorage) GetFiles(t FileType) (r []File)

GetFiles get all files that match given file types; multiple file type may OR'ed together.

func (*MemStorage) GetManifest

func (m *MemStorage) GetManifest() (f File, err error)

GetManifest get manifest file.

func (*MemStorage) Lock

func (m *MemStorage) Lock() (l Locker, err error)

Lock lock the storage.

func (*MemStorage) Print

func (*MemStorage) Print(str string)

Print will do nothing.

func (*MemStorage) SetManifest

func (m *MemStorage) SetManifest(f File) error

SetManifest set manifest to given file.

type Reader

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

type Storage

type Storage interface {
	// Lock the storage, so any subsequent attempt to lock the same storage
	// will fail.
	Lock() (l Locker, err error)

	// Print a string, for logging.
	Print(str string)

	// Get file with given number and type.
	GetFile(number uint64, t FileType) File

	// Get all files that match given file types; multiple file type
	// may OR'ed together.
	GetFiles(t FileType) []File

	// Get manifest file.
	// Should return os.ErrNotExist if there's no current manifest file.
	GetManifest() (f File, err error)

	// Set manifest to given file.
	SetManifest(f File) error
}

type Syncer

type Syncer interface {
	Sync() error
}

type Writer

type Writer interface {
	io.Writer
	io.Closer
	Syncer
}

Jump to

Keyboard shortcuts

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