Documentation ¶
Overview ¶
Example ¶
dir, err := os.MkdirTemp("", "testdir") if err != nil { panic(err) } log, err := Open(dir) if err != nil { panic(err) } i1, _ := log.Write([]byte("data1")) i2, _ := log.Write([]byte("data2")) _ = log.WriteAt(Index(100), []byte("data3")) data1, _ := log.Read(i1) fmt.Println(string(data1)) data3, _ := log.Read(Index(100)) fmt.Println(string(data3)) // delete logs on memory if err := log.Delete(i1, i2); err != nil { panic(err) } // compaction of deleted logs to free disk space if err := log.Compact(); err != nil { panic(err) }
Output: data1 data3
Index ¶
- Constants
- Variables
- type DataLoadFunc
- type FileID
- type FileLocker
- type Index
- type Locker
- type Log
- func (l *Log) Close() error
- func (l *Log) Compact() error
- func (l *Log) Delete(idxs ...Index) error
- func (l *Log) LastIndex() Index
- func (l *Log) Len() int
- func (l *Log) NeedCompaction() bool
- func (l *Log) Read(idx Index) ([]byte, error)
- func (l *Log) ReadFrom(r io.Reader) (int64, error)
- func (l *Log) ReclaimableSpace() uint64
- func (l *Log) Segments() int
- func (l *Log) Size() uint64
- func (l *Log) Sync() error
- func (l *Log) Write(data []byte) (Index, error)
- func (l *Log) WriteAt(idx Index, data []byte) error
- func (l *Log) WriteTo(w io.Writer) (int64, error)
- type OptionFunc
Examples ¶
Constants ¶
View Source
const ( AppName string = "wal" Version string = "1.1.0" )
View Source
const (
FileIDByteSize int = 8 + 8
)
Variables ¶
View Source
var ( ErrClosed = errors.New("closed") ErrCompactRunning = errors.New("compat already in progress") ErrNotFound = errors.New("not found") ErrSegmentNotOpen = errors.New("segment not open") )
View Source
var (
ErrLocked = errors.Errorf("locked")
)
Functions ¶
This section is empty.
Types ¶
type DataLoadFunc ¶ added in v1.0.4
type FileID ¶ added in v1.1.0
func CreateFileID ¶ added in v1.1.0
func NextFileID ¶ added in v1.1.0
func NextFileID() FileID
func ParseFileID ¶ added in v1.1.0
type FileLocker ¶ added in v1.0.2
type FileLocker struct {
// contains filtered or unexported fields
}
func NewFileLocker ¶ added in v1.0.2
func NewFileLocker(path string) *FileLocker
func (*FileLocker) TryLock ¶ added in v1.0.2
func (lock *FileLocker) TryLock() error
func (*FileLocker) Unlock ¶ added in v1.0.2
func (lock *FileLocker) Unlock() error
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func (*Log) NeedCompaction ¶ added in v1.0.2
func (*Log) ReclaimableSpace ¶
type OptionFunc ¶
type OptionFunc func(*logOpt)
func WithCloseCompaction ¶ added in v1.0.2
func WithCloseCompaction(enable bool) OptionFunc
func WithDataLoadFunc ¶ added in v1.0.4
func WithDataLoadFunc(fn DataLoadFunc) OptionFunc
func WithMaxSegmentSize ¶ added in v1.1.0
func WithMaxSegmentSize(size uint64) OptionFunc
func WithSync ¶
func WithSync(enable bool) OptionFunc
func WithWriteBufferSize ¶
func WithWriteBufferSize(size int) OptionFunc
Source Files ¶
Click to show internal directories.
Click to hide internal directories.