wal

package module
v0.0.0-...-e1b8891 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

wal

write ahead of log, pure golang, highe performance

Documentation

Index

Constants

View Source
const (
	RecordSize    = 4
	IndexSize     = 8
	RecordMaxSize = 1 << 31
)
View Source
const HeaderSize = 32

Variables

View Source
var (
	ErrOutOfSize       = errors.New("out of the file size")
	ErrInvalidData     = errors.New("invalid data")
	ErrFile            = errors.New("error file")
	ErrNotFound        = errors.New("not found")
	ErrOutOfRecordSize = errors.New("out of the record max size")
)

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Offset uint64
	Size   uint64
	Header []byte
	Name   string
}

type IFile

type IFile interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Writer
	io.WriterAt

	// Stat returns os.FileInfo describing the file.
	Stat() (os.FileInfo, error)

	// Sync commits the current contents of the file.
	Sync() error

	// Truncate changes the size of the file.
	Truncate(size int64) error

	// Check check file format
	Check() error

	// First Record
	First() (*Record, error)

	// Last Record
	Last() (*Record, error)

	// write size
	WriteSize(size uint32)

	// Header
	Header() (*header, error)

	// Items
	Items() ([]*Item, error)

	// Item
	Item(idx uint64) (*Item, error)

	// Remove
	Remove(stx, end int64)

	// Info
	Info() *FileInfo
}

func OpenFile

func OpenFile(path string, opts *Option) (IFile, error)

type IWal

type IWal interface {
	Close() error
	Write(idx uint64, data []byte)
	Read(idx uint64) (data []byte, err error)
	TruncateFront(idx uint64) error
}

type Item

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

type Log

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

func Open

func Open(path string, opts *Option) (*Log, error)

func (*Log) Close

func (l *Log) Close() error

func (*Log) Read

func (l *Log) Read(idx uint64) (data []byte, err error)

func (*Log) ReadBatch

func (l *Log) ReadBatch(idxes ...uint64) (map[uint64][]byte, error)

func (*Log) TruncateFront

func (l *Log) TruncateFront(idx uint64) error

func (*Log) Write

func (l *Log) Write(data []byte) error

type OpType

type OpType int
const (
	RecordIns OpType = iota
	RecordDel
)

type Option

type Option struct {
	NoCopy   bool
	NoSync   bool
	MmapSize uint64
}

type Record

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

Record format: rsize(4B)+index(8B)+data(NB)+rsize(4B)

func (*Record) Marshal

func (r *Record) Marshal() ([]byte, error)

func (*Record) Unmarshal

func (r *Record) Unmarshal(data []byte) error

type UnixFile

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

func (*UnixFile) Check

func (f *UnixFile) Check() error

func (*UnixFile) Close

func (f *UnixFile) Close() error

func (*UnixFile) First

func (f *UnixFile) First() (*Record, error)

func (*UnixFile) Header

func (f *UnixFile) Header() (*header, error)

func (*UnixFile) Info

func (f *UnixFile) Info() *FileInfo

func (*UnixFile) Item

func (f *UnixFile) Item(idx uint64) (*Item, error)

func (*UnixFile) Items

func (f *UnixFile) Items() ([]*Item, error)

func (*UnixFile) Last

func (f *UnixFile) Last() (*Record, error)

func (*UnixFile) Read

func (f *UnixFile) Read(p []byte) (n int, err error)

func (*UnixFile) ReadAt

func (f *UnixFile) ReadAt(p []byte, off int64) (n int, err error)

func (*UnixFile) Remove

func (f *UnixFile) Remove(stx, end int64)

func (*UnixFile) Seek

func (f *UnixFile) Seek(offset int64, whence int) (int64, error)

func (*UnixFile) Stat

func (f *UnixFile) Stat() (os.FileInfo, error)

Stat returns os.FileInfo describing the file.

func (*UnixFile) Sync

func (f *UnixFile) Sync() error

Sync commits the current contents of the file.

func (*UnixFile) Truncate

func (f *UnixFile) Truncate(size int64) error

Truncate changes the size of the file.

func (*UnixFile) Write

func (f *UnixFile) Write(p []byte) (n int, err error)

func (*UnixFile) WriteAt

func (f *UnixFile) WriteAt(p []byte, off int64) (n int, err error)

func (*UnixFile) WriteSize

func (f *UnixFile) WriteSize(size uint32)

Jump to

Keyboard shortcuts

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