MCPcopy Create free account
hub / github.com/baidu/braft / start

Method start

example/block/server.cpp:82–117  ·  view source on GitHub ↗

Starts this node

Source from the content-addressed store, hash-verified

80
81 // Starts this node
82 int start() {
83 if (!butil::CreateDirectory(butil::FilePath(FLAGS_data_path))) {
84 LOG(ERROR) << "Fail to create directory " << FLAGS_data_path;
85 return -1;
86 }
87 std::string data_path = FLAGS_data_path + "/data";
88 int fd = ::open(data_path.c_str(), O_CREAT | O_RDWR, 0644);
89 if (fd < 0) {
90 PLOG(ERROR) << "Fail to open " << data_path;
91 return -1;
92 }
93 _fd = new SharedFD(fd);
94 butil::EndPoint addr(butil::my_ip(), FLAGS_port);
95 braft::NodeOptions node_options;
96 if (node_options.initial_conf.parse_from(FLAGS_conf) != 0) {
97 LOG(ERROR) << "Fail to parse configuration `" << FLAGS_conf << '\'';
98 return -1;
99 }
100 node_options.election_timeout_ms = FLAGS_election_timeout_ms;
101 node_options.fsm = this;
102 node_options.node_owns_fsm = false;
103 node_options.snapshot_interval_s = FLAGS_snapshot_interval;
104 std::string prefix = "local://" + FLAGS_data_path;
105 node_options.log_uri = prefix + "/log";
106 node_options.raft_meta_uri = prefix + "/raft_meta";
107 node_options.snapshot_uri = prefix + "/snapshot";
108 node_options.disable_cli = FLAGS_disable_cli;
109 braft::Node* node = new braft::Node(FLAGS_group, braft::PeerId(addr));
110 if (node->init(node_options) != 0) {
111 LOG(ERROR) << "Fail to init raft node";
112 delete node;
113 return -1;
114 }
115 _node = node;
116 return 0;
117 }
118
119 // Impelements Service methods
120 void write(const BlockRequest* request,

Callers 1

mainFunction · 0.45

Calls 3

PeerIdClass · 0.85
parse_fromMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected