From Avi:
The protocol_version variable is problematic for two reasons:
- as an integer, it can get confused with a nearby unrelated integer argument
- it represents a layering violation, where the transport protocol leaks into
the database layer
Fix by abstracting it with a new serialization_format class. The transport
layer converts protocol_version to serialization_format.
This is an abstraction layer boundary between transport and the rest of the
code. Instead of the protocol version permeating through the code, encapsulate
it in a serialization_format variable.
This is intended to replace all uses of protocol_version outside transport.
Seastar applications obviously cannot use the Posix sleep() function, or
the entire thread will block. This patch implements future<> sleep(duration)
where as expected, the future becomes ready when the given duration passes.
For example, one can do:
sleep(1s).then([] { std::cout << "Done.\n"; });
This can be useful as an example of futures and continuations in the
Seastar tutorial, and people might find other uses for it.
This sleep() is implemented in terms of timer<>. sleep() is easier to use
and more aligned with the rest of Seastar (it uses then() for the
continuation instead of a set_callback() method). The downside of sleep()
compared to a timer is that it cannot be canceled once started.
In this version, sleep() is implemented without shared_ptr, making the
implementation a tiny bit more efficient. There is still a heap allocation
(this is unavoidable because std::function requires a copyable type)
but no reference counting. Unfortunately, this requires us to use bare
"new" and "delete".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Instead of using inefficient std::ostream, use our own 'bytes' iterator class.
Compute ahead of time the length of the byte buffer.
Afterwards serialize the objects into it.
Gives ~X5 boost over previus results (that sometimes don't even
finish in reasonable time)
[avi: add missing include]
engine_exit() without a parameter is meant to do engine().exit(0).
We do this, but forget to return from this function, so after calling
engine().exit(0), it continued on and crashed.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
This patch makes compiling a file "hello.cc" using seastar as simple as:
g++ `pkg-config --cflags --libs build/release/seastar.pc` hello.cc
Our current build system makes it very hard for users to build a project
*using* Seastar - basically requiring them to integrate their project into
the Seastar tree and its Makefile into our "ninja" framework.
This patch simplifies things considerably by doing two things:
First it builds an archive of all Seastar objects - build/$mode/libseastar.a.
But this in itself is not enough - the user wouldn't know how to use it
(currently, -Wl,--whole-archive is needed, unfortunately, because of reliance
of C++ static constructors), and will also need a long list of other
libraries, as wall as various definitions and include paths during compilation.
The solution is to use pkg-config, which has become the de-facto standard
method on Linux for makefiles to figure out how to compile with a certain
library. With this patch, someone can do this for example, to compile
tests/fileiotests.cc:
g++ `pkg-config --cflags --libs build/release/seastar.pc` tests/fileiotest.cc
Note how we have a different ".pc" file for each mode, with the appropriate
compile and link flags. A more eleborate example with separate compile and
link stages will use "pkg-config --cflags" on the compilation stage, and
"--libs" on the linking stage.
Eventually, we should have a "ninja install", which will install libseastar.a
and seastar.pc to their system-wide default location, and then the above
command line will become as simple as:
g++ `pkg-config --cflags --libs seastar` tests/fileiotest.cc
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>