Browse Source

[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).
pull/931/head
Anton Kaliaev 7 years ago
parent
commit
07571741c5
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 2 additions and 30 deletions
  1. +0
    -28
      consensus/wal.go
  2. +1
    -1
      consensus/wal_generator.go
  3. +1
    -1
      rpc/test/helpers.go

+ 0
- 28
consensus/wal.go View File

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


+ 1
- 1
consensus/wal_generator.go View File

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


+ 1
- 1
rpc/test/helpers.go View File

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


Loading…
Cancel
Save