Browse Source

cswal: write #HEIGHT:1 for empty wal

pull/314/head
Ethan Buchman 8 years ago
parent
commit
81e6df0d57
1 changed files with 18 additions and 3 deletions
  1. +18
    -3
      consensus/wal.go

+ 18
- 3
consensus/wal.go View File

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

Loading…
Cancel
Save