The conversion is not 1:1 because 'enum class' in C++ does not support
methods. As the methods are rather simple, I moved them out of the class
as standalone functions.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
In the original Java code, MurmurHash was in the "utils" package, not
"util", so move it to a new "utils" directory (and namespace), not
"util".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
std::to_string() can also convert a floating-point argument to string,
using the "%f" printf format (see
http://en.cppreference.com/w/cpp/string/basic_string/to_string )
So add this support to our to_sstring() as well.
Note that if you want to use a different format, e.g., "%g", you can,
by using the to_sstring_sprintf function, for example
to_sstring_sprintf(12345678.9, "%g")
results in "1.23457e+07".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
We cannot keep a C++ reference to the statement object because we then
lose ownership information. Start using unique_ptr as suggested by Avi
instead.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Unfortunately at_exit() cannot be used to delete objects since when
it runs the reactor is still active and deleted object may still been used.
We need another API that runs its task after reactor is already stopped.
at_destroy() will be such api.
Port the Murmur hash functions from Java to C++. This is ironic,
because these functions actually originated in C code, which the
Cassandra guys converted to Java :-)
The Murmur hash is used in Cassandra for several things, including the
bloom filter (which is part of each sstable), and the default
data partitioner (Murmur3Partitioner).
I tested on some example string that all three methods (hash32, hash2_64
and hash3_x64_128) produce exactly the same output in the new C++ code as
they do in the original Java functions. This is important, because we want
the C++ node to be able to run alongside Java nodes, so they have to agree
on the same hash function.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
[avi: update configure.py]
The constructor from "const char_type *" wouldn't really work when
char_type != char, because strlen() won't work on such pointers.
It is more convenient to have a constructor from an ordinary const char *
(e.g., a C string literal), and solve the type problem with an ugly cast.
This only makes sense when sizeof(char_type)==1 (i.e., it is char, unsigned
char, or signed char), but I think we make this assumption in other places
as well (e.g., in determining the size we need to allocate).
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
std::string has an operator[] to get access (read or modify) to one
character in the string. This patch adds the same operator for our
sstring.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
The basic_sstring<> template allows picking char_type - which instead of
being just "char" could be chosen to be something similar, like "unsigned char"
or "signed char".
Unfortunately some hard-coded uses of "char" were left in the code. This
did not cause any problems for existing code because of implicit conversions,
but it does cause problems once I try to implement operator[] when char_type
is not char. This results in an attempt to return a reference to the result
of a conversion, which is not allowed.
So this patch fixes the leftover uses of "char" to "char_type".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Supports variadic logging with placeholders, e.g.
logger.error("what happened? x = {}, y = {}", x, y);
Instantiate loggers as static thread_local, e.g.
class foo {
static thread_local logging::logger logger;
};
thread_local logging::logger foo::logger{logging::logger_for<foo>};
Add partial support for get_slice(). With this, the cassandra-stress read
test can complete in thrift mode (yielding 78krps on my desktop).
Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
Remove pre-poll-mode code, from Gleb:
"This series moves most of eventfd users to use other form of notification
which can be polled without entering the kernel and moving epoll in its own
poller which is enabled only if there is an fd that needs to be polled."
[avi: add -lrt to linker command line]