Skip to content

Commit

Permalink
Write WAL and snapshots in temp dir when testing
Browse files Browse the repository at this point in the history
Prevents the etcd/raft-based orderer from writing to the production path
during tests. Instead it uses os.TempDir for WALs and snapshots.

This makes FAB-12824 #done.

Change-Id: I6bcdf5b0ac59575158e6bdb9e8d0e033f926b369
Signed-off-by: Kostas Christidis <kostas@christidis.io>
  • Loading branch information
kchristidis committed Nov 12, 2018
1 parent 859de27 commit 08b5332
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions orderer/common/server/etcdraft_test.go
Expand Up @@ -81,6 +81,8 @@ func launchOrderer(gt *GomegaWithT, cmd *exec.Cmd, orderer, tempDir, genesisBloc
fmt.Sprintf("ORDERER_GENERAL_TLS_ROOTCAS=[%s]", filepath.Join(cwd, "testdata", "tls", "ca.crt")),
fmt.Sprintf("ORDERER_GENERAL_TLS_CERTIFICATE=%s", filepath.Join(cwd, "testdata", "tls", "server.crt")),
fmt.Sprintf("ORDERER_GENERAL_TLS_PRIVATEKEY=%s", filepath.Join(cwd, "testdata", "tls", "server.key")),
fmt.Sprintf("ORDERER_CONSENSUS_WALDIR=%s", filepath.Join(tempDir, "wal")),
fmt.Sprintf("ORDERER_CONSENSUS_SNAPDIR=%s", filepath.Join(tempDir, "snapshot")),
fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(fabricRootDir, "sampleconfig")),
}
sess, err := gexec.Start(cmd, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion orderer/consensus/etcdraft/chain.go
Expand Up @@ -118,7 +118,7 @@ func NewChain(
applied := opts.RaftMetadata.RaftIndex
storage, hasWAL, err := Restore(lg, applied, opts.WALDir, opts.MemoryStorage)
if err != nil {
return nil, errors.Errorf("failed to restore persited raft data: %s", err)
return nil, errors.Errorf("failed to restore persisted raft data: %s", err)
}

return &Chain{
Expand Down
2 changes: 1 addition & 1 deletion orderer/consensus/etcdraft/storage.go
Expand Up @@ -33,7 +33,7 @@ type RaftStorage struct {
wal *wal.WAL
}

// Restore attempts to restore a storage state from persited etcd/raft data.
// Restore attempts to restore a storage state from persisted etcd/raft data.
// If no data is found, it returns a fresh storage.
func Restore(lg *flogging.FabricLogger, applied uint64, walDir string, ram MemoryStorage) (*RaftStorage, bool, error) {
hasWAL := wal.Exist(walDir)
Expand Down

0 comments on commit 08b5332

Please sign in to comment.