From d4d2e2fa0ee4c46a3b8a6601370f7cb591ea554e Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 15 Jul 2015 11:08:58 +0300 Subject: [PATCH] service/storage_proxy: add get_storage_proxy() helpers Make storage proxy a singleton and add helpers to look up a reference. This makes it easier to convert code from Origin in areas such as storage service. Signed-off-by: Pekka Enberg --- main.cc | 2 +- service/storage_proxy.cc | 2 ++ service/storage_proxy.hh | 11 +++++++++++ tests/urchin/cql_test_env.cc | 17 +++++++---------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/main.cc b/main.cc index 5e48af78ea..c216050e61 100644 --- a/main.cc +++ b/main.cc @@ -66,7 +66,7 @@ int main(int ac, char** av) { distributed db; distributed qp; - distributed proxy; + auto& proxy = service::get_storage_proxy(); api::http_context ctx(db, proxy); return app.run(ac, av, [&] { diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 8ff51ba9bf..0d9b351308 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -52,6 +52,8 @@ namespace service { +distributed _the_storage_proxy; + struct mutation_write_timeout_error : public std::exception { size_t total_block_for; size_t acks; diff --git a/service/storage_proxy.hh b/service/storage_proxy.hh index 3a22b61bf0..8b453b06cf 100644 --- a/service/storage_proxy.hh +++ b/service/storage_proxy.hh @@ -149,4 +149,15 @@ public: } }; +extern distributed _the_storage_proxy; + +inline distributed& get_storage_proxy() { + return _the_storage_proxy; +} + +inline storage_proxy& get_local_storage_proxy() { + return _the_storage_proxy.local(); +} + + } diff --git a/tests/urchin/cql_test_env.cc b/tests/urchin/cql_test_env.cc index b235c99aec..28afb908b6 100644 --- a/tests/urchin/cql_test_env.cc +++ b/tests/urchin/cql_test_env.cc @@ -20,7 +20,6 @@ public: private: ::shared_ptr> _db; ::shared_ptr> _qp; - ::shared_ptr> _proxy; private: struct core_local_state { service::client_state client_state; @@ -42,11 +41,9 @@ private: public: in_memory_cql_env( ::shared_ptr> db, - ::shared_ptr> qp, - ::shared_ptr> proxy) + ::shared_ptr> qp) : _db(db) , _qp(qp) - , _proxy(proxy) { } virtual future<::shared_ptr> execute_cql(const sstring& text) override { @@ -180,7 +177,7 @@ public: virtual future<> stop() override { return _core_local.stop().then([this] { return _qp->stop().then([this] { - return _proxy->stop().then([this] { + return service::get_storage_proxy().stop().then([this] { return _db->stop().then([] { return locator::i_endpoint_snitch::stop_snitch(); }); @@ -210,13 +207,13 @@ future<::shared_ptr> make_env_for_test() { auto cfg = make_lw_shared(); cfg->data_file_directories() = {}; return db->start(std::move(*cfg)).then([db] { - auto proxy = ::make_shared>(); + distributed& proxy = service::get_storage_proxy(); auto qp = ::make_shared>(); - return proxy->start(std::ref(*db)).then([qp, db, proxy] { - return qp->start(std::ref(*proxy), std::ref(*db)).then([db, proxy, qp] { + return proxy.start(std::ref(*db)).then([qp, db, &proxy] { + return qp->start(std::ref(proxy), std::ref(*db)).then([db, &proxy, qp] { auto& ss = service::get_local_storage_service(); - return ss.init_server().then([db, proxy, qp] { - auto env = ::make_shared(db, qp, proxy); + return ss.init_server().then([db, qp] { + auto env = ::make_shared(db, qp); return env->start().then([env] () -> ::shared_ptr { return env; });