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
|
|
}
|