From 2c6ba8971f38225549fdd790fb8ba5a687b8afbd Mon Sep 17 00:00:00 2001 From: Shlomi Livne Date: Sun, 14 Jun 2015 11:32:57 +0300 Subject: [PATCH 1/3] Different seperator for map elements Origin's --seed-provider-parameters format is seeds=,, to align with yaml configuration file format and command line options a different seperator must be used instead of "," - switched to using ";" Signed-off-by: Shlomi Livne --- db/config.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/config.cc b/db/config.cc index cd3adb45f3..ced4fd19ee 100644 --- a/db/config.cc +++ b/db/config.cc @@ -130,7 +130,7 @@ std::basic_ostream & operator<<(std::basic_ostream & os, const int n = 0; for (auto& e : map) { if (n > 0) { - os << ","; + os << ":"; } os << e.first << "=" << e.second; } @@ -142,9 +142,9 @@ std::basic_istream & operator>>(std::basic_istream & is, db::c std::string str; is >> str; - std::regex comma(","); + std::regex colon(":"); - std::sregex_token_iterator s(str.begin(), str.end(), comma, -1); + std::sregex_token_iterator s(str.begin(), str.end(), colon, -1); std::sregex_token_iterator e; while (s != e) { sstring p = std::string(*s++); From edfb4fc6719d2accdca99c14393451c59be1f327 Mon Sep 17 00:00:00 2001 From: Shlomi Livne Date: Sun, 14 Jun 2015 11:43:36 +0300 Subject: [PATCH 2/3] Add support for read seeds from configuration Moved setting of configuration variables after the configuration file has been read. Updated the code parsing seeds to comply with configuration file format - seeds: ,, Signed-off-by: Shlomi Livne --- main.cc | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/main.cc b/main.cc index 04daf80d28..2601f293e9 100644 --- a/main.cc +++ b/main.cc @@ -36,8 +36,14 @@ future<> init_storage_service() { future<> init_messaging_service(auto listen_address, auto seed_provider) { const gms::inet_address listen(listen_address); std::set seeds; - for (auto& x : seed_provider.parameters) { - seeds.emplace(x.first); + if (seed_provider.parameters.count("seeds") > 0) { + size_t begin = 0; + size_t next = 0; + sstring& seeds_str = seed_provider.parameters.find("seeds")->second; + while (begin < seeds_str.length() && begin != (next=seeds_str.find(",",begin))) { + seeds.emplace(gms::inet_address(seeds_str.substr(begin,next-begin))); + begin = next+1; + } } if (seeds.empty()) { seeds.emplace(gms::inet_address("127.0.0.1")); @@ -75,16 +81,15 @@ int main(int ac, char** av) { return app.run(ac, av, [&] { auto&& opts = app.configuration(); - uint16_t thrift_port = cfg->rpc_port(); - uint16_t cql_port = cfg->native_transport_port(); - uint16_t api_port = opts["api-port"].as(); - sstring listen_address = cfg->listen_address(); - sstring rpc_address = cfg->rpc_address(); - auto seed_provider= cfg->seed_provider(); - return read_config(opts, *cfg).then([cfg, &db]() { - return db.start(std::move(*cfg)); - }).then([&db] { + return read_config(opts, *cfg).then([&cfg, &db, &qp, &proxy, &ctx, &server, &opts]() { + uint16_t thrift_port = cfg->rpc_port(); + uint16_t cql_port = cfg->native_transport_port(); + uint16_t api_port = opts["api-port"].as(); + sstring listen_address = cfg->listen_address(); + sstring rpc_address = cfg->rpc_address(); + auto seed_provider= cfg->seed_provider(); + return db.start(std::move(*cfg)).then([&db, &qp, &proxy, &ctx, &server] { engine().at_exit([&db] { return db.stop(); }); return db.invoke_on_all(&database::init_from_data_directory); }).then([] { @@ -121,4 +126,5 @@ int main(int ac, char** av) { }); }).or_terminate(); }); + }); } From 39429e248153204effe9a043d0cb1a9439686b8a Mon Sep 17 00:00:00 2001 From: Shlomi Livne Date: Sun, 14 Jun 2015 12:19:11 +0300 Subject: [PATCH 3/3] Alignment Signed-off-by: Shlomi Livne --- main.cc | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/main.cc b/main.cc index 2601f293e9..fc25776592 100644 --- a/main.cc +++ b/main.cc @@ -90,41 +90,41 @@ int main(int ac, char** av) { sstring rpc_address = cfg->rpc_address(); auto seed_provider= cfg->seed_provider(); return db.start(std::move(*cfg)).then([&db, &qp, &proxy, &ctx, &server] { - engine().at_exit([&db] { return db.stop(); }); - return db.invoke_on_all(&database::init_from_data_directory); - }).then([] { - return init_storage_service(); - }).then([listen_address, seed_provider] { - return init_messaging_service(listen_address, seed_provider); - }).then([&db, &proxy, &qp] { - return qp.start(std::ref(proxy), std::ref(db)).then([&qp] { - engine().at_exit([&qp] { return qp.stop(); }); - }); - }).then([rpc_address] { - return dns::gethostbyname(rpc_address); - }).then([&db, &proxy, &qp, cql_port, thrift_port] (dns::hostent e) { - auto rpc_address = e.addresses[0].in.s_addr; - auto cserver = new distributed; - cserver->start(std::ref(proxy), std::ref(qp)).then([server = std::move(cserver), cql_port, rpc_address] () mutable { - server->invoke_on_all(&cql_server::listen, ipv4_addr{rpc_address, cql_port}); - }).then([cql_port] { - std::cout << "CQL server listening on port " << cql_port << " ...\n"; - }); - auto tserver = new distributed; - tserver->start(std::ref(db)).then([server = std::move(tserver), thrift_port, rpc_address] () mutable { - server->invoke_on_all(&thrift_server::listen, ipv4_addr{rpc_address, thrift_port}); - }).then([thrift_port] { - std::cout << "Thrift server listening on port " << thrift_port << " ...\n"; - }); - }).then([&db, api_port, &ctx]{ - ctx.http_server.start().then([api_port, &ctx] { - return set_server(ctx); - }).then([&ctx, api_port] { - ctx.http_server.listen(api_port); - }).then([api_port] { - std::cout << "Seastar HTTP server listening on port " << api_port << " ...\n"; - }); - }).or_terminate(); - }); + engine().at_exit([&db] { return db.stop(); }); + return db.invoke_on_all(&database::init_from_data_directory); + }).then([] { + return init_storage_service(); + }).then([listen_address, seed_provider] { + return init_messaging_service(listen_address, seed_provider); + }).then([&db, &proxy, &qp] { + return qp.start(std::ref(proxy), std::ref(db)).then([&qp] { + engine().at_exit([&qp] { return qp.stop(); }); + }); + }).then([rpc_address] { + return dns::gethostbyname(rpc_address); + }).then([&db, &proxy, &qp, cql_port, thrift_port] (dns::hostent e) { + auto rpc_address = e.addresses[0].in.s_addr; + auto cserver = new distributed; + cserver->start(std::ref(proxy), std::ref(qp)).then([server = std::move(cserver), cql_port, rpc_address] () mutable { + server->invoke_on_all(&cql_server::listen, ipv4_addr{rpc_address, cql_port}); + }).then([cql_port] { + std::cout << "CQL server listening on port " << cql_port << " ...\n"; + }); + auto tserver = new distributed; + tserver->start(std::ref(db)).then([server = std::move(tserver), thrift_port, rpc_address] () mutable { + server->invoke_on_all(&thrift_server::listen, ipv4_addr{rpc_address, thrift_port}); + }).then([thrift_port] { + std::cout << "Thrift server listening on port " << thrift_port << " ...\n"; + }); + }).then([&db, api_port, &ctx]{ + ctx.http_server.start().then([api_port, &ctx] { + return set_server(ctx); + }).then([&ctx, api_port] { + ctx.http_server.listen(api_port); + }).then([api_port] { + std::cout << "Seastar HTTP server listening on port " << api_port << " ...\n"; + }); + }).or_terminate(); + }); }); }