From 07571741c516455b92989bb2010391c2274fa863 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 7 Dec 2017 11:33:00 -0600 Subject: [PATCH] [consensus] remove WAL separator (Refs #785) We don't really need a separator unless we have complex structures (rows, cells like RDBMS have https://www.sqlite.org/fileformat.html). --- consensus/wal.go | 28 ---------------------------- consensus/wal_generator.go | 2 +- rpc/test/helpers.go | 2 +- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/consensus/wal.go b/consensus/wal.go index c6367c7d1..4ee4c09b0 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -20,10 +20,6 @@ import ( //-------------------------------------------------------- // types and functions for savings consensus messages -var ( - walSeparator = []byte{55, 127, 6, 130} // 0x377f0682 - magic number -) - type TimedWALMessage struct { Time time.Time `json:"time"` // for debugging purposes Msg WALMessage `json:"msg"` @@ -209,11 +205,6 @@ func (enc *WALEncoder) Encode(v interface{}) error { _, err := enc.wr.Write(msg) - if err == nil { - // TODO [Anton Kaliaev 23 Oct 2017]: remove separator - _, err = enc.wr.Write(walSeparator) - } - return err } @@ -278,28 +269,9 @@ func (dec *WALDecoder) Decode() (*TimedWALMessage, error) { return nil, fmt.Errorf("failed to decode data: %v", err) } - // TODO [Anton Kaliaev 23 Oct 2017]: remove separator - if err = readSeparator(dec.rd); err != nil { - return nil, err - } - return res, err } -// readSeparator reads a separator from r. It returns any error from underlying -// reader or if it's not a separator. -func readSeparator(r io.Reader) error { - b := make([]byte, len(walSeparator)) - _, err := r.Read(b) - if err != nil { - return fmt.Errorf("failed to read separator: %v", err) - } - if !bytes.Equal(b, walSeparator) { - return fmt.Errorf("not a separator: %v", b) - } - return nil -} - type nilWAL struct{} func (nilWAL) Save(m WALMessage) {} diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index 8a2e21821..6f8bb8df3 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -103,7 +103,7 @@ func makePathname() string { if err != nil { panic(err) } - fmt.Println(p) + // fmt.Println(p) sep := string(filepath.Separator) return strings.Replace(p, sep, "_", -1) } diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 73da30ad6..69fe7aa8c 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -51,7 +51,7 @@ func makePathname() string { if err != nil { panic(err) } - fmt.Println(p) + // fmt.Println(p) sep := string(filepath.Separator) return strings.Replace(p, sep, "_", -1) }