wal: support auto-cut in wal

WAL should control the cut logic itself. We want to do falloc to
per allocate the space for a segmented wal file at the beginning
and cut it when it size reaches the limit.
This commit is contained in:
Xiang Li
2015-02-19 15:41:37 -08:00
committed by Yicheng Qin
parent c3d3ad931b
commit 86429264fb
6 changed files with 32 additions and 35 deletions

View File

@ -720,15 +720,12 @@ func TestSnapshot(t *testing.T) {
t.Errorf("action = %s, want Save", gaction[0])
}
gaction = p.Action()
if len(gaction) != 2 {
t.Fatalf("len(action) = %d, want 2", len(gaction))
if len(gaction) != 1 {
t.Fatalf("len(action) = %d, want 1", len(gaction))
}
if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "SaveSnap"}) {
t.Errorf("action = %s, want SaveSnap", gaction[0])
}
if !reflect.DeepEqual(gaction[1], testutil.Action{Name: "Cut"}) {
t.Errorf("action = %s, want Cut", gaction[1])
}
}
// Applied > SnapCount should trigger a SaveSnap event
@ -755,12 +752,12 @@ func TestTriggerSnap(t *testing.T) {
gaction := p.Action()
// each operation is recorded as a Save
// (SnapCount+1) * Puts + Cut + SaveSnap = (SnapCount+1) * Save + SaveSnap + CUT
wcnt := 3 + snapc
// (SnapCount+1) * Puts + SaveSnap = (SnapCount+1) * Save + SaveSnap
wcnt := 2 + snapc
if len(gaction) != wcnt {
t.Fatalf("len(action) = %d, want %d", len(gaction), wcnt)
}
if !reflect.DeepEqual(gaction[wcnt-2], testutil.Action{Name: "SaveSnap"}) {
if !reflect.DeepEqual(gaction[wcnt-1], testutil.Action{Name: "SaveSnap"}) {
t.Errorf("action = %s, want SaveSnap", gaction[wcnt-1])
}
}
@ -1267,10 +1264,6 @@ func (p *storageRecorder) Save(st raftpb.HardState, ents []raftpb.Entry) error {
p.Record(testutil.Action{Name: "Save"})
return nil
}
func (p *storageRecorder) Cut() error {
p.Record(testutil.Action{Name: "Cut"})
return nil
}
func (p *storageRecorder) SaveSnap(st raftpb.Snapshot) error {
if !raft.IsEmptySnap(st) {
p.Record(testutil.Action{Name: "SaveSnap"})