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

Function change_routine

test/test_node.cpp:2765–2795  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2763};
2764
2765static void* change_routine(void* arg) {
2766 ChangeArg* ca = (ChangeArg*)arg;
2767 while (!ca->stop) {
2768 ca->c->wait_leader();
2769 braft::Node* leader = ca->c->leader();
2770 if (!leader) {
2771 continue;
2772 }
2773 // Randomly select peers
2774 braft::Configuration conf;
2775 if (ca->dont_remove_first_peer) {
2776 conf.add_peer(ca->peers[0]);
2777 }
2778 for (size_t i = 0; i < ca->peers.size(); ++i) {
2779 bool select = butil::fast_rand_less_than(64) < 32;
2780 if (select) {
2781 conf.add_peer(ca->peers[i]);
2782 }
2783 }
2784 if (conf.empty()) {
2785 LOG(WARNING) << "No peer has been selected";
2786 // Bad luck here
2787 continue;
2788 }
2789 braft::SynchronizedClosure done;
2790 leader->change_peers(conf, &done);
2791 done.wait();
2792 CHECK(done.status().ok());
2793 }
2794 return NULL;
2795}
2796
2797TEST_P(NodeTest, change_peers_chaos_with_snapshot) {
2798 g_dont_print_apply_log = true;

Callers

nothing calls this directly

Calls 7

wait_leaderMethod · 0.80
leaderMethod · 0.80
add_peerMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
change_peersMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected