mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-30 21:21:39 +00:00
[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).
This commit is contained in:
@ -20,10 +20,6 @@ import (
|
|||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
// types and functions for savings consensus messages
|
// types and functions for savings consensus messages
|
||||||
|
|
||||||
var (
|
|
||||||
walSeparator = []byte{55, 127, 6, 130} // 0x377f0682 - magic number
|
|
||||||
)
|
|
||||||
|
|
||||||
type TimedWALMessage struct {
|
type TimedWALMessage struct {
|
||||||
Time time.Time `json:"time"` // for debugging purposes
|
Time time.Time `json:"time"` // for debugging purposes
|
||||||
Msg WALMessage `json:"msg"`
|
Msg WALMessage `json:"msg"`
|
||||||
@ -209,11 +205,6 @@ func (enc *WALEncoder) Encode(v interface{}) error {
|
|||||||
|
|
||||||
_, err := enc.wr.Write(msg)
|
_, err := enc.wr.Write(msg)
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// TODO [Anton Kaliaev 23 Oct 2017]: remove separator
|
|
||||||
_, err = enc.wr.Write(walSeparator)
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,28 +269,9 @@ func (dec *WALDecoder) Decode() (*TimedWALMessage, error) {
|
|||||||
return nil, fmt.Errorf("failed to decode data: %v", err)
|
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
|
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{}
|
type nilWAL struct{}
|
||||||
|
|
||||||
func (nilWAL) Save(m WALMessage) {}
|
func (nilWAL) Save(m WALMessage) {}
|
||||||
|
@ -103,7 +103,7 @@ func makePathname() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(p)
|
// fmt.Println(p)
|
||||||
sep := string(filepath.Separator)
|
sep := string(filepath.Separator)
|
||||||
return strings.Replace(p, sep, "_", -1)
|
return strings.Replace(p, sep, "_", -1)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func makePathname() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(p)
|
// fmt.Println(p)
|
||||||
sep := string(filepath.Separator)
|
sep := string(filepath.Separator)
|
||||||
return strings.Replace(p, sep, "_", -1)
|
return strings.Replace(p, sep, "_", -1)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user