Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raftlogdir #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
utils.LegacyBootnodesV4Flag,
utils.LegacyBootnodesV5Flag,
utils.DataDirFlag,
utils.RaftLogDirFlag,
utils.AncientFlag,
utils.KeyStoreDirFlag,
utils.ExternalSignerFlag,
Expand Down
18 changes: 16 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ var (
Usage: "Data directory for the databases and keystore",
Value: DirectoryString(node.DefaultDataDir()),
}
RaftLogDirFlag = DirectoryFlag{
Name: "raftlogdir",
Usage: "Raft log directory for the raft-state, raft-snap and raft-wal folders",
Value: DirectoryString(node.DefaultDataDir()),
}
AncientFlag = DirectoryFlag{
Name: "datadir.ancient",
Usage: "Data directory for ancient chain segments (default = inside chaindata)",
Expand Down Expand Up @@ -1386,6 +1391,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
setWS(ctx, cfg)
setNodeUserIdent(ctx, cfg)
setDataDir(ctx, cfg)
setRaftLogDir(ctx, cfg)
setSmartCard(ctx, cfg)

if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
Expand Down Expand Up @@ -1462,6 +1468,14 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
}
}

func setRaftLogDir(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(RaftLogDirFlag.Name) {
cfg.RaftLogDir = ctx.GlobalString(RaftLogDirFlag.Name)
} else {
cfg.RaftLogDir = cfg.DataDir
}
}

// Quorum
//
// Read plugin settings from --plugins flag. Overwrite settings defined in --config if any
Expand Down Expand Up @@ -2017,7 +2031,7 @@ func RegisterPermissionService(stack *node.Node, useDns bool) {

func RegisterRaftService(stack *node.Node, ctx *cli.Context, nodeCfg *node.Config, ethService *eth.Ethereum) {
blockTimeMillis := ctx.GlobalInt(RaftBlockTimeFlag.Name)
datadir := ctx.GlobalString(DataDirFlag.Name)
raftLogDir := nodeCfg.RaftLogDir // default value is set either 'datadir' or 'raftlogdir'
joinExistingId := ctx.GlobalInt(RaftJoinExistingFlag.Name)
useDns := ctx.GlobalBool(RaftDNSEnabledFlag.Name)
raftPort := uint16(ctx.GlobalInt(RaftPortFlag.Name))
Expand Down Expand Up @@ -2055,7 +2069,7 @@ func RegisterRaftService(stack *node.Node, ctx *cli.Context, nodeCfg *node.Confi
}
}

_, err := raft.New(stack, ethService.BlockChain().Config(), myId, raftPort, joinExisting, blockTimeNanos, ethService, peers, datadir, useDns)
_, err := raft.New(stack, ethService.BlockChain().Config(), myId, raftPort, joinExisting, blockTimeNanos, ethService, peers, raftLogDir, useDns)
if err != nil {
Fatalf("raft: Failed to register the Raft service: %v", err)
}
Expand Down
4 changes: 4 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type Config struct {
// in memory.
DataDir string

// RaftLogDir is the file system folder the node use for raft-state, raft-snap and
// raft-wal folders.
RaftLogDir string

// Configuration of peer-to-peer networking.
P2P p2p.Config

Expand Down
4 changes: 2 additions & 2 deletions raft/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RaftService struct {
pendingLogsFeed *event.Feed
}

func New(stack *node.Node, chainConfig *params.ChainConfig, raftId, raftPort uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*enode.Node, datadir string, useDns bool) (*RaftService, error) {
func New(stack *node.Node, chainConfig *params.ChainConfig, raftId, raftPort uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*enode.Node, raftLogDir string, useDns bool) (*RaftService, error) {
service := &RaftService{
eventMux: stack.EventMux(),
chainDb: e.ChainDb(),
Expand All @@ -56,7 +56,7 @@ func New(stack *node.Node, chainConfig *params.ChainConfig, raftId, raftPort uin
service.minter = newMinter(chainConfig, service, blockTime)

var err error
if service.raftProtocolManager, err = NewProtocolManager(raftId, raftPort, service.blockchain, service.eventMux, startPeers, joinExisting, datadir, service.minter, service.downloader, useDns, stack.Server()); err != nil {
if service.raftProtocolManager, err = NewProtocolManager(raftId, raftPort, service.blockchain, service.eventMux, startPeers, joinExisting, raftLogDir, service.minter, service.downloader, useDns, stack.Server()); err != nil {
return nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions raft/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ var errNoLeaderElected = errors.New("no leader is currently elected")
// Public interface
//

func NewProtocolManager(raftId uint16, raftPort uint16, blockchain *core.BlockChain, mux *event.TypeMux, bootstrapNodes []*enode.Node, joinExisting bool, datadir string, minter *minter, downloader *downloader.Downloader, useDns bool, p2pServer *p2p.Server) (*ProtocolManager, error) {
waldir := fmt.Sprintf("%s/raft-wal", datadir)
snapdir := fmt.Sprintf("%s/raft-snap", datadir)
quorumRaftDbLoc := fmt.Sprintf("%s/quorum-raft-state", datadir)
func NewProtocolManager(raftId uint16, raftPort uint16, blockchain *core.BlockChain, mux *event.TypeMux, bootstrapNodes []*enode.Node, joinExisting bool, raftLogDir string, minter *minter, downloader *downloader.Downloader, useDns bool, p2pServer *p2p.Server) (*ProtocolManager, error) {
waldir := fmt.Sprintf("%s/raft-wal", raftLogDir)
snapdir := fmt.Sprintf("%s/raft-snap", raftLogDir)
quorumRaftDbLoc := fmt.Sprintf("%s/quorum-raft-state", raftLogDir)

manager := &ProtocolManager{
bootstrapNodes: bootstrapNodes,
Expand Down
4 changes: 2 additions & 2 deletions raft/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func prepareServiceContext(key *ecdsa.PrivateKey) (stack *node.Node, cfg *node.C
}

func startRaftNode(id, port uint16, tmpWorkingDir string, key *ecdsa.PrivateKey, nodes []*enode.Node) (*RaftService, error) {
datadir := fmt.Sprintf("%s/node%d", tmpWorkingDir, id)
raftlogdir := fmt.Sprintf("%s/node%d", tmpWorkingDir, id)

stack, _, err := prepareServiceContext(key)
if err != nil {
Expand All @@ -166,7 +166,7 @@ func startRaftNode(id, port uint16, tmpWorkingDir string, key *ecdsa.PrivateKey,
return nil, err
}

s, err := New(stack, params.QuorumTestChainConfig, id, port, false, 100*time.Millisecond, e, nodes, datadir, false)
s, err := New(stack, params.QuorumTestChainConfig, id, port, false, 100*time.Millisecond, e, nodes, raftlogdir, false)
if err != nil {
return nil, err
}
Expand Down