forked from fastio/1store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.cc
124 lines (112 loc) · 4.5 KB
/
init.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (C) 2015 ScyllaDB
* Modified by Peng Jian, [email protected]
*/
/*
* This file is part of Pedis.
*
* Pedis is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pedis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Pedis. If not, see <http://www.gnu.org/licenses/>.
*/
#include "init.hh"
#include "message/messaging_service.hh"
#include "gms/failure_detector.hh"
#include "gms/gossiper.hh"
#include "utils/to_string.hh"
#include "gms/inet_address.hh"
#include "db.hh"
#include "config.hh"
#include "core/future.hh"
logging::logger startlog("init");
future<> init_message_failuredetector_gossiper(sstring listen_address
, uint16_t storage_port
, uint16_t ssl_storage_port
, sstring ms_encrypt_what
, sstring ms_trust_store
, sstring ms_cert
, sstring ms_key
, sstring ms_compress
, sstring seeds_str
, sstring cluster_name
, double phi
, bool sltba)
{
const gms::inet_address listen(listen_address);
using encrypt_what = netw::messaging_service::encrypt_what;
using compress_what = netw::messaging_service::compress_what;
using namespace seastar::tls;
encrypt_what ew = encrypt_what::none;
if (ms_encrypt_what == "all") {
ew = encrypt_what::all;
} else if (ms_encrypt_what == "dc") {
ew = encrypt_what::dc;
} else if (ms_encrypt_what == "rack") {
ew = encrypt_what::rack;
}
compress_what cw = compress_what::none;
if (ms_compress == "all") {
cw = compress_what::all;
} else if (ms_compress == "dc") {
cw = compress_what::dc;
}
auto tndw = netw::messaging_service::tcp_nodelay_what::all;
future<> f = make_ready_future<>();
std::shared_ptr<credentials_builder> creds;
if (ew != encrypt_what::none) {
creds = std::make_shared<credentials_builder>();
creds->set_dh_level(dh_params::level::MEDIUM);
creds->set_x509_key_file(ms_cert, ms_key, x509_crt_format::PEM).get();
if (ms_trust_store.empty()) {
creds->set_system_trust().get();
} else {
creds->set_x509_trust_file(ms_trust_store, x509_crt_format::PEM).get();
}
}
// Init messaging_service
// Delay listening messaging_service until gossip message handlers are registered
bool listen_now = false;
netw::get_messaging_service().start(listen, storage_port, ew, cw, tndw, ssl_storage_port, creds, sltba, listen_now).get();
// #293 - do not stop anything
//engine().at_exit([] { return netw::get_messaging_service().stop(); });
// Init failure_detector
gms::get_failure_detector().start(std::move(phi)).get();
// #293 - do not stop anything
//engine().at_exit([]{ return gms::get_failure_detector().stop(); });
// Init gossiper
std::set<gms::inet_address> seeds;
size_t begin = 0;
size_t next = 0;
while (begin < seeds_str.length() && begin != (next=seeds_str.find(",",begin))) {
auto seed = boost::trim_copy(seeds_str.substr(begin,next-begin));
seeds.emplace(gms::inet_address(std::move(seed)));
begin = next+1;
}
if (seeds.empty()) {
seeds.emplace(gms::inet_address("127.0.0.1"));
}
auto broadcast_address = utils::fb_utilities::get_broadcast_address();
if (broadcast_address != listen_address && seeds.count(listen_address)) {
print("Use broadcast_address instead of listen_address for seeds list: seeds=%s, listen_address=%s, broadcast_address=%s\n",
to_string(seeds), listen_address, broadcast_address);
throw std::runtime_error("Use broadcast_address for seeds list");
}
gms::get_gossiper().start().get();
auto& gossiper = gms::get_local_gossiper();
gossiper.set_seeds(seeds);
// #293 - do not stop anything
//engine().at_exit([]{ return gms::get_gossiper().stop(); });
gms::get_gossiper().invoke_on_all([cluster_name](gms::gossiper& g) {
g.set_cluster_name(cluster_name);
});
return make_ready_future<>();
}