storage

package
v0.0.0-...-4c02118 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 12 Imported by: 0

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
	ALl
)

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 = map[string]uint16{"str": 0, "list": 1, "hash": 2, "set": 3, "zset": 4}
)
View Source
var (
	// ErrEmptyEntry the entry is empty.
	ErrEmptyEntry = errors.New("storage/db_file: entry or the Key of entry is empty")
	// ErrEntryTooLarge the entry is too large.
	ErrEntryTooLarge = errors.New("storage/db_file: entry is too large to store in mmap mode")
)
View Source
var (
	// ErrInvalidEntry invalid entry.
	ErrInvalidEntry = errors.New("storage/entry: invalid entry")
	// ErrInvalidCrc invalid crc.
	ErrInvalidCrc = errors.New("storage/entry: invalid crc")
)

Functions

func Build

func Build(path string, method FileRWMethod, blockSize int64) (ArchivedFiles, FileIds, error)

Build load all db files from disk.

func BuildType

func BuildType(path string, method FileRWMethod, blockSize int64, eType uint16) (ArchivedFiles, FileIds, error)

Types

type ArchivedFiles

type ArchivedFiles map[uint16]map[uint32]*DBFile

ArchivedFiles define the archived files, which mean these files can only be read. and will never be opened for writing.

type DBFile

type DBFile struct {
	Id   uint32
	Path string
	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) FindValidEntries

func (df *DBFile) FindValidEntries(validFn func(*Entry, int64, uint32) bool) (entries []*Entry, err error)

func (*DBFile) Read

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

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) (err error)

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

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

NewEntryWithExpire create a new Entry with expired info.

func NewEntryWithTxn

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

func (e *Entry) GetMark() uint16

GetMark state low 8 bits is operation mark.

func (*Entry) GetType

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 FileIds

type FileIds map[uint16]uint32

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