Documentation
¶
Index ¶
- Constants
- Variables
- func SegmentFileName(dirPath, extName string, id SegmentID) string
- type ChunkLoc
- type ChunkType
- type Options
- type Reader
- type SegmentID
- type WAL
- func (w *WAL) ActiveSegID() SegmentID
- func (w *WAL) Close() error
- func (w *WAL) Delete() error
- func (w *WAL) IsEmpty() bool
- func (w *WAL) NewReader() *Reader
- func (w *WAL) NewReaderLE(segId SegmentID) *Reader
- func (w *WAL) NewReaderWithLoc(loc *ChunkLoc) (*Reader, error)
- func (w *WAL) OpenNewActiveSeg() error
- func (w *WAL) Read(loc *ChunkLoc) ([]byte, error)
- func (w *WAL) Sync() error
- func (w *WAL) Write(data []byte) (*ChunkLoc, error)
Constants ¶
const ( B = 1 KB = 1024 * B MB = 1024 * KB GB = 1024 * MB )
const (
DotSEG = ".SEG"
)
Variables ¶
var ( ErrClosed = errors.New("the segment file is closed") ErrInvalidCRC = errors.New("invalid crc, the data may be corrupted") )
Functions ¶
func SegmentFileName ¶
SegmentFileName returns the file name of a segment file.
Types ¶
type ChunkLoc ¶
ChunkLoc represents the location of a chunk in a segment file. Used to read the data from the segment file.
func DecodeChunkLoc ¶
DecodeChunkLoc decodes a ChunkLoc from bytes.
type Options ¶
type Options struct { // DirPath specifies the directory path where the WAL segment files will // be stored. DirPath string // SegmentSize specifies the maximum size of each segment file in bytes. SegmentSize int64 // SegmentFileExt specifies the file extension of the segment files. // The file extension must start with a dot ".", default value is ".SEG". // It is used to identify the different types of files(i.e. segment files // and hint files) in the directory. SegmentFileExt string // Sync is whether to synchronize writes through os buffer cache and down // onto the actual disk. Sync is required for durability of a single write // operation, but also results in slower writes. // // If false, and the machine crashes, then some recent writes may be lost. // Note that if it's just the process crashes, then no write will be lost. // // In other words, Sync being false has the same semantics as a normal // write system call. Sync being true means write followed by fsync. Sync bool // BytesPerSync specifies the number of bytes to write before calling fsync. BytesPerSync uint32 }
Options represents the configuration options for a Write-Ahead Log (WAL).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader represents a reader for WAL. The readers are *segmentReader for every segment, sorted by segment id. And the currIdx points to current segment reader.
func (*Reader) CurrChunkLoc ¶
CurrChunkLoc returns the location of current chunk.
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
WAL (Write-Ahead Log) provides durability and fault-tolerance for incoming writes.
It consists of an activeSeg, which is the current segment file used for new incoming writes, and olderSegs, which is a map of segment files used for read operations.
func (*WAL) ActiveSegID ¶
ActiveSegID returns the current active segment id.
func (*WAL) IsEmpty ¶
IsEmpty returns whether the WAL is empty. Only when there is only one active segment, and it's empty.
func (*WAL) NewReaderLE ¶
NewReaderLE returns a new reader for WAL which only read data from the segment whose id is less than or equal to the given segId. If segId is 0, meaning read from all segments. You may also call it in the merge process.
func (*WAL) NewReaderWithLoc ¶
NewReaderWithLoc returns a new reader for WAL which only read data from the given chunk location.
func (*WAL) OpenNewActiveSeg ¶
OpenNewActiveSeg opens a new segment file and sets it as the active segment file regardless of the old one. Calling it in merge process.