storage

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: MIT Imports: 11 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// FilePerm default permission of the newly created db file.
	FilePerm = 0644

	// PathSeparator the default path separator.
	PathSeparator = string(os.PathSeparator)
)
View Source
const (
	String uint16 = iota
	List
	Hash
	Set
	ZSet
)

data structure type of value, support five types now.

Variables

View Source
var (
	// DBFileFormatNames name format of the db files.
	DBFileFormatNames = map[uint16]string{
		0: "%09d.data.str",
		1: "%09d.data.list",
		2: "%09d.data.hash",
		3: "%09d.data.set",
		4: "%09d.data.zset",
	}

	// DBFileSuffixName represents the suffix names of the db files.
	DBFileSuffixName = []string{"str", "list", "hash", "set", "zset"}
)
View Source
var (
	// ErrInvalidEntry invalid entry.
	ErrInvalidEntry = errors.New("storage/entry: invalid entry")
	// ErrInvalidCrc invalid crc.
	ErrInvalidCrc = errors.New("storage/entry: invalid crc")
)
View Source
var (
	// ErrEmptyEntry the entry is empty.
	ErrEmptyEntry = errors.New("storage/db_file: entry or the Key of entry is empty")
)

Functions

func Build

func Build(path string, method FileRWMethod, blockSize int64) (map[uint16]map[uint32]*DBFile, map[uint16]uint32, error)

Build load all db files from disk.

Types

type DBFile

type DBFile struct {
	Id uint32

	File *os.File

	Offset int64
	// contains filtered or unexported fields
}

DBFile define the data file of rosedb.

func NewDBFile

func NewDBFile(path string, fileId uint32, method FileRWMethod, blockSize int64, eType uint16) (*DBFile, error)

NewDBFile create a new db file, truncate the file if rw method is mmap.

func (*DBFile) Close

func (df *DBFile) Close(sync bool) (err error)

Close close the db file, sync means whether to persist data before closing.

func (*DBFile) Read

func (df *DBFile) Read(offset int64) (e *Entry, err error)

Read read data from the db file, offset is the start position of reading.

func (*DBFile) Sync

func (df *DBFile) Sync() (err error)

Sync persist db file into disk.

func (*DBFile) Write

func (df *DBFile) Write(e *Entry) error

Write write data into db file from offset.

type Entry

type Entry struct {
	Meta *Meta

	Timestamp uint64 // Timestamp is the time when entry was written.
	TxId      uint64 // TxId represents transaction id of an Entry.
	// contains filtered or unexported fields
}

Entry is a record which will be appended to a db file.

func Decode

func Decode(buf []byte) (*Entry, error)

Decode decode the byte array and return the entry.

func NewEntry

func NewEntry(key, value, extra []byte, t, mark uint16) *Entry

NewEntry create a new entry.

func NewEntryNoExtra

func NewEntryNoExtra(key, value []byte, t, mark uint16) *Entry

NewEntryNoExtra create a new entry without extra info.

func NewEntryWithExpire added in v1.2.8

func NewEntryWithExpire(key, value []byte, deadline int64, t, mark uint16) *Entry

NewEntryWithExpire create a new Entry with expired info.

func NewEntryWithTxn added in v1.2.9

func NewEntryWithTxn(key, value, extra []byte, t, mark uint16, txId uint64) *Entry

NewEntryWithTx create a new Entry with transaction info.

func (*Entry) Encode

func (e *Entry) Encode() ([]byte, error)

Encode encode the entry and returns a byte array.

func (*Entry) GetMark added in v1.2.8

func (e *Entry) GetMark() uint16

GetMark state low 8 bits is operation mark.

func (*Entry) GetType added in v1.2.8

func (e *Entry) GetType() uint16

GetType state high 8 bits is data type.

func (*Entry) Size

func (e *Entry) Size() uint32

Size the entry`s total size.

type FileRWMethod

type FileRWMethod uint8

FileRWMethod db file read and write method.

const (

	// FileIO Indicates that data file read and write using system standard IO.
	FileIO FileRWMethod = iota

	// MMap Indicates that data file read and write using mmap.
	MMap
)

type Meta

type Meta struct {
	Key       []byte
	Value     []byte
	Extra     []byte // Extra info that operates the entry.
	KeySize   uint32
	ValueSize uint32
	ExtraSize uint32
}

Meta meta info.

Jump to

Keyboard shortcuts

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