storage

package
v0.0.0-...-1c06873 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FilePerm 默认的创建文件权限 permission
	FilePerm = 0644

	// DBFileFormatName default数据文件名称格式化
	DBFileFormatName = "%09d.data"

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

Value的数据结构类型

Variables

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[uint32]*DBFile, uint32, error)

Build 加载数据文件

Types

type DBFile

type DBFile struct {
	Id uint32

	File *os.File

	Offset int64
	// contains filtered or unexported fields
}

func NewDBFile

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

NewDBFile 新建一个数据读写文件,如果是MMap,则需要Truncate文件并进行加载

func (*DBFile) Close

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

Close 读写后进行关闭擦偶走 sync 关闭前是否持久化数据

func (*DBFile) Read

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

Read 从数据文件读数据, offset是读的起始位置

func (*DBFile) Sync

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

Sync 数据持久化

func (*DBFile) Write

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

Write 从文件的offset处开始写数据

type DBMeta

type DBMeta struct {
	ActiveWriteOff int64 `json:"active_write_off"` //当前数据库文件的写偏移
}

DBMeta 保存数据库的一些额外信息

func LoadMeta

func LoadMeta(path string) (m *DBMeta)

LoadMeta 加载数据库的额外信息

func (*DBMeta) Store

func (m *DBMeta) Store(path string) error

Store 存储数据信息

type Entry

type Entry struct {
	Meta *Meta
	Type uint16 //data type
	Mark uint16 //data operation type
	// contains filtered or unexported fields
}

Entry 数据entry定义

func Decode

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

Decode 解码字节数据, 返回Entry

func NewEntry

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

NewEntry new an entry

func NewEntryNoExtra

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

NewEntryNoExtra New a entry without extra info

func (*Entry) Encode

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

Encode 对Entry进行编码, 返回字节数组

func (*Entry) Size

func (e *Entry) Size() uint32

Size returns the entry size

type Expires

type Expires map[string]uint32

Expires 过期字典定义

func LoadExpires

func LoadExpires(path string) (expires Expires)

LoadExpires 加载过期字典信息

func (*Expires) SaveExpires

func (e *Expires) SaveExpires(path string) (err error)

SaveExpires 保存过期字典信息

type ExpiresValue

type ExpiresValue struct {
	Key      []byte
	KeySize  uint32
	Deadline uint64
}

ExpiresValue expires value

type FileRWMethod

type FileRWMethod uint8

FileRWMethod 文件数据读写方式

const (
	// FileIO 表示文件数据读写使用系统标准IO
	FileIO FileRWMethod = iota

	// MMap 表示文件数据读写使用Mmap
	// MMap 指的是将文件或其他设备映射至内存 via https://en.wikipedia.org/wiki/Mmap
	MMap
)

type Meta

type Meta struct {
	Key       []byte
	Value     []byte
	Extra     []byte //操作entry所需的额外信息
	KeySize   uint32
	ValueSize uint32
	ExtraSize uint32
}

Meta meta 数据

Jump to

Keyboard shortcuts

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