Documentation
¶
Index ¶
- Constants
- Variables
- func MkDirIfNotExist(dir string) result.Result[struct{}]
- func NewWAL(dir string, config Config) result.Result[*WAL]
- func Open(dir string, config Config) result.Result[*WAL]
- type Batch
- type BinaryEncoder
- func (e BinaryEncoder) Decode(data []byte) result.Result[Entry]
- func (e BinaryEncoder) DecodeZeroCopy(data []byte) result.Result[Entry]
- func (e BinaryEncoder) Encode(entry Entry) result.Result[[]byte]
- func (e BinaryEncoder) EncodeInPlace(entry Entry, buffer []byte) result.Result[int]
- func (e BinaryEncoder) EstimateSize(entry Entry) int
- type Config
- type Cursor
- type Encoder
- type Entry
- type JSONEncoder
- func (e JSONEncoder) Decode(data []byte) result.Result[Entry]
- func (e JSONEncoder) DecodeZeroCopy(data []byte) result.Result[Entry]
- func (e JSONEncoder) Encode(entry Entry) result.Result[[]byte]
- func (e JSONEncoder) EncodeInPlace(entry Entry, buffer []byte) result.Result[int]
- func (e JSONEncoder) EstimateSize(entry Entry) int
- type LogFormat
- type Logger
- type NoOpLogger
- type Permission
- type Segment
- func (s *Segment) Close() error
- func (s *Segment) ContainsIndex(entryIndex uint64) bool
- func (s *Segment) GetEntryByIndex(entryIndex uint64) ([]byte, error)
- func (s *Segment) GetEntryByIndexZeroCopy(entryIndex uint64) ([]byte, error)
- func (s *Segment) ReadAll() ([][]byte, error)
- func (s *Segment) ReadAt(offset int64) ([]byte, int64, error)
- func (s *Segment) ReadAtZeroCopy(offset int64) ([]byte, int64, error)
- func (s *Segment) Size() (int64, error)
- func (s *Segment) Sync() error
- func (s *Segment) TrackEntry(entryIndex uint64, offset int64)
- func (s *Segment) Write(data []byte) (int, error)
- type State
- type Status
- type Transaction
- type TransactionID
- type TransactionState
- type WAL
- func (w *WAL) AddToTransaction(txID TransactionID, entry Entry) result.Result[struct{}]
- func (w *WAL) Append(entry Entry) result.Result[uint64]
- func (w *WAL) AppendWithContext(ctx context.Context, entry Entry) result.Result[uint64]
- func (w *WAL) BeginTransaction(timeout time.Duration) result.Result[TransactionID]
- func (w *WAL) CleanupExpiredTransactions() int
- func (w *WAL) Close() error
- func (w *WAL) CommitTransaction(txID TransactionID) result.Result[[]uint64]
- func (w *WAL) Get(index uint64) result.Result[Entry]
- func (w *WAL) GetActiveTransactionCount() int
- func (w *WAL) GetFirstIndex() uint64
- func (w *WAL) GetLastIndex() uint64
- func (w *WAL) GetRange(start, end uint64) result.Result[[]Entry]
- func (w *WAL) GetRangeZeroCopy(start, end uint64) result.Result[[]Entry]
- func (w *WAL) GetTransactionState(txID TransactionID) result.Result[TransactionState]
- func (w *WAL) GetZeroCopy(index uint64) result.Result[Entry]
- func (w *WAL) RollbackTransaction(txID TransactionID) result.Result[struct{}]
- func (w *WAL) StartTransactionCleanup()
- func (w *WAL) Truncate(index uint64) result.Result[struct{}]
- func (w *WAL) WriteBatch(entries []Entry) result.Result[[]uint64]
- func (w *WAL) WriteBatchWithContext(ctx context.Context, entries []Entry) result.Result[[]uint64]
- type ZeroCopyEncoder
Constants ¶
View Source
const ( SegmentFileExtension = ".wal" SegmentFilePrefix = "segment_" EntryLengthSize = 4 )
View Source
const (
// Layout: Index(8) + Term(8) + Timestamp(8) + DataLen(4) + TxIDLen(4) + Checksum(4) = 36 bytes
EntryHeaderSize = 8 + 8 + 8 + 4 + 4 + 4
)
Variables ¶
View Source
var ( ErrChecksumMismatch = errors.New("checksum mismatch: data may be corrupted") ErrEmptyData = errors.New("entry data cannot be empty") ErrInvalidEntry = errors.New("invalid entry") ErrWALCorrupted = errors.New("WAL is corrupted") ErrWALClosed = errors.New("WAL is closed") ErrIndexOutOfRange = errors.New("index out of range") ErrSegmentNotFound = errors.New("segment not found") ErrSegmentFull = errors.New("segment is full") ErrUnsupportedFormat = errors.New("unsupported encode format") ErrTransactionNotFound = errors.New("transaction not found") ErrTransactionNotPending = errors.New("transaction is not in pending state") ErrTransactionExpired = errors.New("transaction has expired") ErrTransactionTooLarge = errors.New("transaction has too many entries") UnknownError = errors.New("Unknown error") )
Functions ¶
func MkDirIfNotExist ¶
Types ¶
type BinaryEncoder ¶
type BinaryEncoder struct{}
func (BinaryEncoder) DecodeZeroCopy ¶
func (e BinaryEncoder) DecodeZeroCopy(data []byte) result.Result[Entry]
func (BinaryEncoder) EncodeInPlace ¶
func (BinaryEncoder) EstimateSize ¶
func (e BinaryEncoder) EstimateSize(entry Entry) int
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func DefaultConfig ¶
func DefaultConfig() Config
type Cursor ¶
func StartCursor ¶
func StartCursor() Cursor
type JSONEncoder ¶
type JSONEncoder struct{}
func (JSONEncoder) DecodeZeroCopy ¶
func (e JSONEncoder) DecodeZeroCopy(data []byte) result.Result[Entry]
func (JSONEncoder) EncodeInPlace ¶
func (JSONEncoder) EstimateSize ¶
func (e JSONEncoder) EstimateSize(entry Entry) int
type Logger ¶
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
}
Logger interface for WAL logging
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a logger that does nothing (default)
func (NoOpLogger) Debug ¶
func (n NoOpLogger) Debug(msg string, args ...any)
func (NoOpLogger) Error ¶
func (n NoOpLogger) Error(msg string, args ...any)
func (NoOpLogger) Info ¶
func (n NoOpLogger) Info(msg string, args ...any)
func (NoOpLogger) Warn ¶
func (n NoOpLogger) Warn(msg string, args ...any)
type Permission ¶
const ( DefaultFilePermission Permission = 0644 DirectoryPermission Permission = 0750 FilePermission Permission = 0640 )
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
func (*Segment) ContainsIndex ¶
func (*Segment) GetEntryByIndex ¶
func (*Segment) GetEntryByIndexZeroCopy ¶
func (*Segment) ReadAtZeroCopy ¶
func (*Segment) TrackEntry ¶
type Transaction ¶
type Transaction struct {
ID TransactionID
State TransactionState
Entries []Entry
StartTime time.Time
Timeout time.Duration
Batch Batch
}
func (*Transaction) IsExpired ¶
func (t *Transaction) IsExpired() bool
func (*Transaction) Reset ¶
func (t *Transaction) Reset()
type TransactionID ¶
type TransactionID string
type TransactionState ¶
type TransactionState int
const ( TransactionPending TransactionState = iota TransactionCommitted TransactionAborted )
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
func (*WAL) AddToTransaction ¶
func (w *WAL) AddToTransaction(txID TransactionID, entry Entry) result.Result[struct{}]
func (*WAL) AppendWithContext ¶
func (*WAL) BeginTransaction ¶
func (*WAL) CleanupExpiredTransactions ¶
func (*WAL) CommitTransaction ¶
func (w *WAL) CommitTransaction(txID TransactionID) result.Result[[]uint64]
func (*WAL) GetActiveTransactionCount ¶
func (*WAL) GetFirstIndex ¶
func (*WAL) GetLastIndex ¶
func (*WAL) GetRangeZeroCopy ¶
func (*WAL) GetTransactionState ¶
func (w *WAL) GetTransactionState(txID TransactionID) result.Result[TransactionState]
func (*WAL) RollbackTransaction ¶
func (w *WAL) RollbackTransaction(txID TransactionID) result.Result[struct{}]
func (*WAL) StartTransactionCleanup ¶
func (w *WAL) StartTransactionCleanup()
Click to show internal directories.
Click to hide internal directories.
