From 81e6df0d575f95276377d66a85527ee31f66d541 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 16 Nov 2016 01:15:39 -0500 Subject: [PATCH] cswal: write #HEIGHT:1 for empty wal --- consensus/wal.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/consensus/wal.go b/consensus/wal.go index 467baa037..2bd24c72d 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -33,7 +33,6 @@ var _ = wire.RegisterInterface( // Can be used for crash-recovery and deterministic replay // TODO: currently the wal is overwritten during replay catchup // give it a mode so it's either reading or appending - must read to end to start appending again -// TODO: #HEIGHT 1 is never printed ... type WAL struct { BaseService @@ -55,7 +54,19 @@ func NewWAL(walDir string, light bool) (*WAL, error) { light: light, } wal.BaseService = *NewBaseService(log, "WAL", wal) - return wal, nil + _, err = wal.Start() + return wal, err +} + +func (wal *WAL) OnStart() error { + wal.BaseService.OnStart() + size, err := wal.group.Head.Size() + if err != nil { + return err + } else if size == 0 { + wal.writeHeight(1) + } + return nil } func (wal *WAL) OnStop() { @@ -81,7 +92,7 @@ func (wal *WAL) Save(wmsg WALMessage) { // Write #HEIGHT: XYZ if new height if edrs, ok := wmsg.(types.EventDataRoundState); ok { if edrs.Step == RoundStepNewHeight.String() { - wal.group.WriteLine(Fmt("#HEIGHT: %v", edrs.Height)) + wal.writeHeight(edrs.Height) } } // Write the wal message @@ -91,3 +102,7 @@ func (wal *WAL) Save(wmsg WALMessage) { PanicQ(Fmt("Error writing msg to consensus wal. Error: %v \n\nMessage: %v", err, wmsg)) } } + +func (wal *WAL) writeHeight(height int) { + wal.group.WriteLine(Fmt("#HEIGHT: %v", height)) +}