Write-ahead log implementation for Golang.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
582 B

package wal
import (
"fmt"
)
type segmentTX struct {
seg *segment
nextID int64
tailOffset int64
insertAt int
}
func (tx *segmentTX) Append(walID int64, data []byte) {
if walID != tx.nextID && tx.nextID != -1 {
panic(fmt.Sprintf("Invalid WAL ID. Expected %d but got %d",
tx.nextID, walID))
}
tx.nextID = walID + 1
writeRecord(
tx.seg.mapped,
int64(tx.insertAt),
walID,
data)
tx.tailOffset = int64(tx.insertAt)
tx.insertAt += len(data) + recOffsetData
}
func (tx *segmentTX) ReminaingSpace() int {
return len(tx.seg.mapped) - tx.insertAt
}