cswal -> cs_wal_dir

This commit is contained in:
Jae Kwon
2016-10-30 03:55:27 -07:00
parent 1788a68b1c
commit 3d3d8b5b7b
10 changed files with 43 additions and 55 deletions

View File

@@ -41,10 +41,10 @@ Commands:
case "node":
node.RunNode(config)
case "replay":
if len(args) > 1 && args[1] == "console" {
node.RunReplayConsole(config)
if len(args) > 2 && args[1] == "console" {
node.RunReplayConsole(config, args[2])
} else {
node.RunReplay(config)
node.RunReplay(config, args[1])
}
case "init":
init_files()

View File

@@ -11,7 +11,7 @@ import (
func reset_all() {
reset_priv_validator()
os.RemoveAll(config.GetString("db_dir"))
os.Remove(config.GetString("cswal"))
os.RemoveAll(config.GetString("cs_wal_dir"))
}
// NOTE: this is totally unsafe.

View File

@@ -22,6 +22,7 @@ func getTMRoot(rootDir string) string {
func initTMRoot(rootDir string) {
rootDir = getTMRoot(rootDir)
EnsureDir(rootDir, 0700)
EnsureDir(rootDir+"/data", 0700)
configFilePath := path.Join(rootDir, "config.toml")
@@ -68,8 +69,8 @@ func GetConfig(rootDir string) cfg.Config {
mapConfig.SetDefault("rpc_laddr", "tcp://0.0.0.0:46657")
mapConfig.SetDefault("prof_laddr", "")
mapConfig.SetDefault("revision_file", rootDir+"/revision")
mapConfig.SetDefault("cswal", rootDir+"/data/cswal")
mapConfig.SetDefault("cswal_light", false)
mapConfig.SetDefault("cs_wal_dir", rootDir+"/data/cs.wal")
mapConfig.SetDefault("cs_wal_light", false)
mapConfig.SetDefault("filter_peers", false)
mapConfig.SetDefault("block_size", 10000)
@@ -84,7 +85,7 @@ func GetConfig(rootDir string) cfg.Config {
mapConfig.SetDefault("mempool_recheck", true)
mapConfig.SetDefault("mempool_recheck_empty", true)
mapConfig.SetDefault("mempool_broadcast", true)
mapConfig.SetDefault("mempool_wal", rootDir+"/data/mempool_wal")
mapConfig.SetDefault("mempool_wal_dir", rootDir+"/data/mempool.wal")
return mapConfig
}

View File

@@ -33,6 +33,7 @@ func initTMRoot(rootDir string) {
}
// Create new dir
EnsureDir(rootDir, 0700)
EnsureDir(rootDir+"/data", 0700)
configFilePath := path.Join(rootDir, "config.toml")
genesisFilePath := path.Join(rootDir, "genesis.json")
@@ -81,8 +82,8 @@ func ResetConfig(localPath string) cfg.Config {
mapConfig.SetDefault("rpc_laddr", "tcp://0.0.0.0:36657")
mapConfig.SetDefault("prof_laddr", "")
mapConfig.SetDefault("revision_file", rootDir+"/revision")
mapConfig.SetDefault("cswal", rootDir+"/data/cswal")
mapConfig.SetDefault("cswal_light", false)
mapConfig.SetDefault("cs_wal_dir", rootDir+"/data/cs.wal")
mapConfig.SetDefault("cs_wal_light", false)
mapConfig.SetDefault("filter_peers", false)
mapConfig.SetDefault("block_size", 10000)
@@ -97,7 +98,7 @@ func ResetConfig(localPath string) cfg.Config {
mapConfig.SetDefault("mempool_recheck", true)
mapConfig.SetDefault("mempool_recheck_empty", true)
mapConfig.SetDefault("mempool_broadcast", true)
mapConfig.SetDefault("mempool_wal", "")
mapConfig.SetDefault("mempool_wal_dir", "")
return mapConfig
}

View File

@@ -28,7 +28,7 @@ var testCases = []*testCase{
type testCase struct {
name string
log string //full cswal
log string //full cs wal
stepMap map[int]int8 // map lines of log to privval step
proposeLine int
@@ -71,21 +71,20 @@ func readWAL(p string) string {
return string(b)
}
func writeWAL(log string) string {
fmt.Println("writing", log)
// write the needed wal to file
f, err := ioutil.TempFile(os.TempDir(), "replay_test_")
func writeWAL(walMsgs string) string {
tempDir := os.TempDir()
walDir := tempDir + "/wal" + RandStr(12)
// Create WAL directory
err := EnsureDir(walDir, 0700)
if err != nil {
panic(err)
}
_, err = f.WriteString(log)
// Write the needed WAL to file
err = WriteFile(walDir+"/wal", []byte(walMsgs), 0600)
if err != nil {
panic(err)
}
name := f.Name()
f.Close()
return name
return walDir
}
func waitForBlock(newBlockCh chan interface{}, thisCase *testCase, i int) {
@@ -97,10 +96,10 @@ func waitForBlock(newBlockCh chan interface{}, thisCase *testCase, i int) {
}
}
func runReplayTest(t *testing.T, cs *ConsensusState, fileName string, newBlockCh chan interface{},
func runReplayTest(t *testing.T, cs *ConsensusState, walDir string, newBlockCh chan interface{},
thisCase *testCase, i int) {
cs.config.Set("cswal", fileName)
cs.config.Set("cs_wal_dir", walDir)
cs.Start()
// Wait to make a new block.
// This is just a signal that we haven't halted; its not something contained in the WAL itself.
@@ -124,7 +123,7 @@ func setupReplayTest(thisCase *testCase, nLines int, crashAfter bool) (*Consensu
lastMsg := split[nLines]
// we write those lines up to (not including) one with the signature
fileName := writeWAL(strings.Join(split[:nLines], "\n") + "\n")
walDir := writeWAL(strings.Join(split[:nLines], "\n") + "\n")
cs := fixedConsensusStateDummy()
@@ -136,7 +135,7 @@ func setupReplayTest(thisCase *testCase, nLines int, crashAfter bool) (*Consensu
newBlockCh := subscribeToEvent(cs.evsw, "tester", types.EventStringNewBlock(), 1)
return cs, newBlockCh, lastMsg, fileName
return cs, newBlockCh, lastMsg, walDir
}
//-----------------------------------------------
@@ -147,8 +146,8 @@ func TestReplayCrashAfterWrite(t *testing.T) {
for _, thisCase := range testCases {
split := strings.Split(thisCase.log, "\n")
for i := 0; i < len(split)-1; i++ {
cs, newBlockCh, _, f := setupReplayTest(thisCase, i+1, true)
runReplayTest(t, cs, f, newBlockCh, thisCase, i+1)
cs, newBlockCh, _, walDir := setupReplayTest(thisCase, i+1, true)
runReplayTest(t, cs, walDir, newBlockCh, thisCase, i+1)
}
}
}
@@ -160,7 +159,7 @@ func TestReplayCrashAfterWrite(t *testing.T) {
func TestReplayCrashBeforeWritePropose(t *testing.T) {
for _, thisCase := range testCases {
lineNum := thisCase.proposeLine
cs, newBlockCh, proposalMsg, f := setupReplayTest(thisCase, lineNum, false) // propose
cs, newBlockCh, proposalMsg, walDir := setupReplayTest(thisCase, lineNum, false) // propose
// Set LastSig
var err error
var msg TimedWALMessage
@@ -171,14 +170,14 @@ func TestReplayCrashBeforeWritePropose(t *testing.T) {
}
cs.privValidator.LastSignBytes = types.SignBytes(cs.state.ChainID, proposal.Proposal)
cs.privValidator.LastSignature = proposal.Proposal.Signature
runReplayTest(t, cs, f, newBlockCh, thisCase, lineNum)
runReplayTest(t, cs, walDir, newBlockCh, thisCase, lineNum)
}
}
func TestReplayCrashBeforeWritePrevote(t *testing.T) {
for _, thisCase := range testCases {
lineNum := thisCase.prevoteLine
cs, newBlockCh, voteMsg, f := setupReplayTest(thisCase, lineNum, false) // prevote
cs, newBlockCh, voteMsg, walDir := setupReplayTest(thisCase, lineNum, false) // prevote
types.AddListenerForEvent(cs.evsw, "tester", types.EventStringCompleteProposal(), func(data types.TMEventData) {
// Set LastSig
var err error
@@ -191,14 +190,14 @@ func TestReplayCrashBeforeWritePrevote(t *testing.T) {
cs.privValidator.LastSignBytes = types.SignBytes(cs.state.ChainID, vote.Vote)
cs.privValidator.LastSignature = vote.Vote.Signature
})
runReplayTest(t, cs, f, newBlockCh, thisCase, lineNum)
runReplayTest(t, cs, walDir, newBlockCh, thisCase, lineNum)
}
}
func TestReplayCrashBeforeWritePrecommit(t *testing.T) {
for _, thisCase := range testCases {
lineNum := thisCase.precommitLine
cs, newBlockCh, voteMsg, f := setupReplayTest(thisCase, lineNum, false) // precommit
cs, newBlockCh, voteMsg, walDir := setupReplayTest(thisCase, lineNum, false) // precommit
types.AddListenerForEvent(cs.evsw, "tester", types.EventStringPolka(), func(data types.TMEventData) {
// Set LastSig
var err error
@@ -211,6 +210,6 @@ func TestReplayCrashBeforeWritePrecommit(t *testing.T) {
cs.privValidator.LastSignBytes = types.SignBytes(cs.state.ChainID, vote.Vote)
cs.privValidator.LastSignature = vote.Vote.Signature
})
runReplayTest(t, cs, f, newBlockCh, thisCase, lineNum)
runReplayTest(t, cs, walDir, newBlockCh, thisCase, lineNum)
}
}

View File

@@ -304,7 +304,7 @@ func (cs *ConsensusState) SetPrivValidator(priv *types.PrivValidator) {
func (cs *ConsensusState) OnStart() error {
cs.BaseService.OnStart()
err := cs.OpenWAL(cs.config.GetString("cswal"))
err := cs.OpenWAL(cs.config.GetString("cs_wal_dir"))
if err != nil {
return err
}
@@ -350,10 +350,10 @@ func (cs *ConsensusState) OnStop() {
}
// Open file to log all consensus messages and timeouts for deterministic accountability
func (cs *ConsensusState) OpenWAL(file string) (err error) {
func (cs *ConsensusState) OpenWAL(walDir string) (err error) {
cs.mtx.Lock()
defer cs.mtx.Unlock()
wal, err := NewWAL(file, cs.config.GetBool("cswal_light"))
wal, err := NewWAL(walDir, cs.config.GetBool("cs_wal_light"))
if err != nil {
return err
}

View File

@@ -2,7 +2,6 @@
The easiest way to generate this data is to copy `~/.tendermint_test/somedir/*` to `~/.tendermint`
and to run a local node.
Be sure to set the db to "leveldb" to create a cswal file in `~/.tendermint/data/cswal`.
If you need to change the signatures, you can use a script as follows:
The privBytes comes from `config/tendermint_test/...`:

View File

@@ -40,8 +40,8 @@ type WAL struct {
light bool // ignore block parts
}
func NewWAL(path string, light bool) (*WAL, error) {
head, err := auto.OpenAutoFile(path)
func NewWAL(walDir string, light bool) (*WAL, error) {
head, err := auto.OpenAutoFile(walDir + "/wal")
if err != nil {
return nil, err
}

View File

@@ -85,9 +85,9 @@ func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
}
func (mem *Mempool) initWAL() {
walFileName := mem.config.GetString("mempool_wal")
if walFileName != "" {
af, err := auto.OpenAutoFile(walFileName)
walDir := mem.config.GetString("mempool_wal_dir")
if walDir != "" {
af, err := auto.OpenAutoFile(walDir + "/wal")
if err != nil {
PanicSanity(err)
}

View File

@@ -52,8 +52,6 @@ func NewNodeDefault(config cfg.Config) *Node {
func NewNode(config cfg.Config, privValidator *types.PrivValidator, clientCreator proxy.ClientCreator) *Node {
EnsureDir(config.GetString("db_dir"), 0700) // incase we use memdb, cswal still gets written here
// Get BlockStore
blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir"))
blockStore := bc.NewBlockStore(blockStoreDB)
@@ -414,12 +412,7 @@ func newConsensusState(config cfg.Config) *consensus.ConsensusState {
return consensusState
}
func RunReplayConsole(config cfg.Config) {
walFile := config.GetString("cswal")
if walFile == "" {
Exit("cswal file name not set in tendermint config")
}
func RunReplayConsole(config cfg.Config, walFile string) {
consensusState := newConsensusState(config)
if err := consensusState.ReplayConsole(walFile); err != nil {
@@ -427,12 +420,7 @@ func RunReplayConsole(config cfg.Config) {
}
}
func RunReplay(config cfg.Config) {
walFile := config.GetString("cswal")
if walFile == "" {
Exit("cswal file name not set in tendermint config")
}
func RunReplay(config cfg.Config, walFile string) {
consensusState := newConsensusState(config)
if err := consensusState.ReplayMessages(walFile); err != nil {