From 08b5332f703b2c6bfaed7982760c7adb51c210f2 Mon Sep 17 00:00:00 2001 From: Kostas Christidis Date: Mon, 12 Nov 2018 11:07:00 -0500 Subject: [PATCH] Write WAL and snapshots in temp dir when testing 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 --- orderer/common/server/etcdraft_test.go | 2 ++ orderer/consensus/etcdraft/chain.go | 2 +- orderer/consensus/etcdraft/storage.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/orderer/common/server/etcdraft_test.go b/orderer/common/server/etcdraft_test.go index 887bdd5007f..9b1364d100c 100644 --- a/orderer/common/server/etcdraft_test.go +++ b/orderer/common/server/etcdraft_test.go @@ -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) diff --git a/orderer/consensus/etcdraft/chain.go b/orderer/consensus/etcdraft/chain.go index b5f9212f3d7..1678263f472 100644 --- a/orderer/consensus/etcdraft/chain.go +++ b/orderer/consensus/etcdraft/chain.go @@ -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{ diff --git a/orderer/consensus/etcdraft/storage.go b/orderer/consensus/etcdraft/storage.go index 66afd8cd395..bfcac2fe033 100644 --- a/orderer/consensus/etcdraft/storage.go +++ b/orderer/consensus/etcdraft/storage.go @@ -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)