Documentation
¶
Index ¶
Constants ¶
View Source
const ( KB = 1024 // 1 Kilobyte MB = KB * KB // 1 Megabyte )
Variables ¶
View Source
var DefaultConfig = Config{ WALDir: "./wal", BufferSize: 4 * KB, SegmentSize: 10 * MB, SegmentPrefix: "segment", SyncStrategy: SyncStrategyBackground, SyncInterval: 1000, }
DefaultConfig provides default configuration values for WAL.
View Source
var (
ErrInvalidCRC = errors.New("wal: invalid crc, data corruption detected")
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
WALDir string // Directory to store WAL files
BufferSize int // Buffered writes size in bytes (e.g., 4KB)
SegmentSize int64 // Maximum size of each file (e.g., 10MB)
SegmentPrefix string // Prefix for segment file names (e.g., "segment")
SyncStrategy SyncStrategy // Sync strategy
SyncInterval uint // Sync interval in milliseconds for background sync
}
Config holds the configuration for WAL.
func (*Config) SetDefault ¶
func (cfg *Config) SetDefault()
SetDefault sets default values for any zero-value fields in the Config.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator: Implementation of Reader
type Reader ¶
type Reader interface {
Next() bool // Move to the next log
Value() []byte // Get the data of the current log
Err() error // Get error if any
Close() error // Close the reader
}
Reader: Interface to read logs sequentially
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
Segment: Represents a physical file
type SyncStrategy ¶
type SyncStrategy int
SyncStrategy defines the synchronization strategy for WAL.
const ( // Fastest but highest risk, only write to buffer, Flush and Sync every second. // Data loss if app crash or OS crash. // Default strategy. SyncStrategyBackground SyncStrategy = 0 // The safest, Flush and Sync immediately on each Write. // Never lose data. Slowest. SyncStrategyAlways SyncStrategy = 1 // Balanced, Flush to OS Cache immediately, but Sync every second. (Recommended) // Safe on app crash. Only lose data on OS crash/power loss. SyncStrategyOSCache SyncStrategy = 2 )
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
WAL: Write-Ahead Log structure
func (*WAL) StopSync ¶
func (w *WAL) StopSync()
StopSync stops sync goroutine and WAITS for it to finish
Click to show internal directories.
Click to hide internal directories.