From 087a34a5444897ba2bce7dd084e84409fa5ddef7 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 19 Mar 2015 17:37:04 -0300 Subject: [PATCH 1/7] slab: free slab page if page desc alloc failed Signed-off-by: Raphael S. Carvalho --- core/slab.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/slab.hh b/core/slab.hh index e661ef5cfc..91684f69f7 100644 --- a/core/slab.hh +++ b/core/slab.hh @@ -222,7 +222,7 @@ public: auto objects = max_object_size / _size; desc = new slab_page_desc(slab_page, objects, _size, _slab_class_id, slab_page_index); } catch (const std::bad_alloc& e) { - // FIXME: Is there really a need to re-throw std::bad_alloc? + ::free(slab_page); throw std::bad_alloc{}; } From 54875279f69045b03b88eab4736924825b11ab23 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 19 Mar 2015 17:37:05 -0300 Subject: [PATCH 2/7] slab: fix comment Signed-off-by: Raphael S. Carvalho --- core/slab.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/slab.hh b/core/slab.hh index 91684f69f7..c3e9db21bc 100644 --- a/core/slab.hh +++ b/core/slab.hh @@ -328,7 +328,7 @@ private: auto objects = _max_object_size / object_size; for (auto i = 0u; i < objects; i++, object += object_size) { if (!desc.empty()) { - // if binary_search returns false, it means that object at the current + // if binary_search returns true, it means that object at the current // offset isn't an item. if (std::binary_search(free_objects.begin(), free_objects.end(), object)) { continue; From 8abd982ec9d83e66e2d0cc471c4594c94c4fcbe4 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Tue, 24 Mar 2015 19:26:42 +0100 Subject: [PATCH 3/7] distributed: Do not move arguments when passing to many cores --- core/distributed.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/distributed.hh b/core/distributed.hh index f9e5002292..e49a0e105a 100644 --- a/core/distributed.hh +++ b/core/distributed.hh @@ -174,7 +174,7 @@ distributed::start(Args&&... args) { unsigned c = 0; return parallel_for_each(_instances.begin(), _instances.end(), [this, &c, args = std::make_tuple(std::forward(args)...)] (Service*& inst) mutable { - return smp::submit_to(c++, [&inst, args = std::move(args)] () mutable { + return smp::submit_to(c++, [&inst, args] () mutable { inst = apply([] (Args&&... args) { return new Service(std::forward(args)...); }, std::move(args)); From 040f8ffcfb1ce1a083c44adb0a79278974e415c1 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 25 Mar 2015 09:26:39 +0100 Subject: [PATCH 4/7] tests: Convert tabs to spaces --- tests/map_reduce_test.cc | 60 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/map_reduce_test.cc b/tests/map_reduce_test.cc index 80056bc74d..6f2b0041bd 100644 --- a/tests/map_reduce_test.cc +++ b/tests/map_reduce_test.cc @@ -25,47 +25,47 @@ #include "core/future-util.hh" struct X { - sstring echo(sstring arg) { - return arg; - } - future<> stop() { return make_ready_future<>(); } + sstring echo(sstring arg) { + return arg; + } + future<> stop() { return make_ready_future<>(); } }; template future<> do_with_distributed(Func&& func) { - auto x = make_shared>(); - return func(*x).finally([x] { - return x->stop(); - }).finally([x]{}); + auto x = make_shared>(); + return func(*x).finally([x] { + return x->stop(); + }).finally([x]{}); } future<> test_that_each_core_gets_the_arguments() { - return do_with_distributed([] (auto& x) { - return x.map_reduce([] (sstring msg){ - if (msg != "hello") { - throw std::runtime_error("wrong message"); - } - }, &X::echo, sstring("hello")); - }); + return do_with_distributed([] (auto& x) { + return x.map_reduce([] (sstring msg){ + if (msg != "hello") { + throw std::runtime_error("wrong message"); + } + }, &X::echo, sstring("hello")); + }); } future<> test_functor_version() { - return do_with_distributed([] (auto& x) { - return x.map_reduce([] (sstring msg){ - if (msg != "hello") { - throw std::runtime_error("wrong message"); - } - }, [] (X& x) { return x.echo("hello"); }); - }); + return do_with_distributed([] (auto& x) { + return x.map_reduce([] (sstring msg){ + if (msg != "hello") { + throw std::runtime_error("wrong message"); + } + }, [] (X& x) { return x.echo("hello"); }); + }); } int main(int argc, char** argv) { - app_template app; - return app.run(argc, argv, [] { - test_that_each_core_gets_the_arguments().then([] { - return test_functor_version(); - }).then([] { - return engine().exit(0); - }).or_terminate(); - }); + app_template app; + return app.run(argc, argv, [] { + test_that_each_core_gets_the_arguments().then([] { + return test_functor_version(); + }).then([] { + return engine().exit(0); + }).or_terminate(); + }); } From dc4eb7af2d2e3910c3a3ebb6dc188847bbbedd04 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 25 Mar 2015 09:36:26 +0100 Subject: [PATCH 5/7] tests: Rename map_reduce_test.cc to distributed_test.cc --- configure.py | 4 ++-- test.py | 2 +- tests/{map_reduce_test.cc => distributed_test.cc} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename tests/{map_reduce_test.cc => distributed_test.cc} (100%) diff --git a/configure.py b/configure.py index ba3bf36374..939fc06af1 100755 --- a/configure.py +++ b/configure.py @@ -105,7 +105,7 @@ tests = [ 'tests/shared_ptr_test', 'tests/slab_test', 'tests/fstream_test', - 'tests/map_reduce_test', + 'tests/distributed_test', 'tests/rpc', ] @@ -237,7 +237,7 @@ deps = { 'tests/shared_ptr_test': ['tests/shared_ptr_test.cc'] + core, 'tests/slab_test': ['tests/slab_test.cc'] + core, 'tests/fstream_test': ['tests/fstream_test.cc'] + core, - 'tests/map_reduce_test': ['tests/map_reduce_test.cc'] + core, + 'tests/distributed_test': ['tests/distributed_test.cc'] + core, 'tests/rpc': ['tests/rpc.cc'] + core + libnet, } diff --git a/test.py b/test.py index 54ce9dc717..29e1116691 100755 --- a/test.py +++ b/test.py @@ -70,7 +70,7 @@ if __name__ == "__main__": for test in boost_tests: test_to_run.append((os.path.join(prefix, test),'boost')) test_to_run.append(('tests/memcached/test.py --mode ' + mode + (' --fast' if args.fast else ''),'other')) - test_to_run.append((os.path.join(prefix, 'map_reduce_test') + ' -c 2','other')) + test_to_run.append((os.path.join(prefix, 'distributed_test') + ' -c 2','other')) allocator_test_path = os.path.join(prefix, 'allocator_test') diff --git a/tests/map_reduce_test.cc b/tests/distributed_test.cc similarity index 100% rename from tests/map_reduce_test.cc rename to tests/distributed_test.cc From 5133a0b2abc34349695f983846aa7c0ea21c8a71 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 25 Mar 2015 09:37:01 +0100 Subject: [PATCH 6/7] tests: distributed_test: Add missing start() invocation --- tests/distributed_test.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/distributed_test.cc b/tests/distributed_test.cc index 6f2b0041bd..30e96134b5 100644 --- a/tests/distributed_test.cc +++ b/tests/distributed_test.cc @@ -41,21 +41,24 @@ future<> do_with_distributed(Func&& func) { future<> test_that_each_core_gets_the_arguments() { return do_with_distributed([] (auto& x) { - return x.map_reduce([] (sstring msg){ - if (msg != "hello") { - throw std::runtime_error("wrong message"); - } - }, &X::echo, sstring("hello")); + return x.start().then([&x] { + return x.map_reduce([] (sstring msg){ + if (msg != "hello") { + throw std::runtime_error("wrong message"); + } + }, &X::echo, sstring("hello")); + }); }); } future<> test_functor_version() { return do_with_distributed([] (auto& x) { - return x.map_reduce([] (sstring msg){ - if (msg != "hello") { - throw std::runtime_error("wrong message"); - } - }, [] (X& x) { return x.echo("hello"); }); + return x.start().then([&x] { + return x.map_reduce([] (sstring msg){ + if (msg != "hello") { + throw std::runtime_error("wrong message"); + } + }, [] (X& x) { return x.echo("hello"); }); }); } From 4dc8a6a09cb8fda6e769316a645d4b8aa58f0f4d Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Wed, 25 Mar 2015 09:37:30 +0100 Subject: [PATCH 7/7] test: distrubuted_test: Test that constructor arguments are copied on each core --- tests/distributed_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/distributed_test.cc b/tests/distributed_test.cc index 30e96134b5..c80cb4941f 100644 --- a/tests/distributed_test.cc +++ b/tests/distributed_test.cc @@ -59,6 +59,25 @@ future<> test_functor_version() { throw std::runtime_error("wrong message"); } }, [] (X& x) { return x.echo("hello"); }); + }); + }); +} + +struct Y { + sstring s; + Y(sstring s) : s(std::move(s)) {} + future<> stop() { return make_ready_future<>(); } +}; + +future<> test_constructor_argument_is_passed_to_each_core() { + return do_with_distributed([] (auto& y) { + return y.start(sstring("hello")).then([&y] { + return y.invoke_on_all([] (Y& y) { + if (y.s != "hello") { + throw std::runtime_error(sprint("expected message mismatch, is \"%s\"", y.s)); + } + }); + }); }); } @@ -67,6 +86,8 @@ int main(int argc, char** argv) { return app.run(argc, argv, [] { test_that_each_core_gets_the_arguments().then([] { return test_functor_version(); + }).then([] { + return test_constructor_argument_is_passed_to_each_core(); }).then([] { return engine().exit(0); }).or_terminate();