Commit Graph

109 Commits

Author SHA1 Message Date
Pekka Enberg
a95a7294ef types: Fix 'varint' type value compatibility check
Fixes #575.

Signed-off-by: Pekka Enberg <penberg@scylladb.com>
2015-12-04 13:25:34 +01:00
Vlad Zolotarov
cd215fc552 types: map::to_string() - non-empty implementation
Print a map in the form of [(]{ key0 : value0 }[, { keyN : valueN }]*[)]
The map is printed inside () brackets if it's frozen.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-12-03 18:46:12 +01:00
Avi Kivity
23895ac7f5 types: fix up confusion around empty serialized representation
An empty serialized representation means an empty value, not NULL.

Fix up the confusion by converting incorrect make_null() calls to a new
make_empty(), and removing make_null() in empty-capable types like
bytes_type.

Collections don't support empty serialized representations, so remove
the call there.
2015-11-22 12:20:24 +02:00
Avi Kivity
0b91b643ba types: empty value support for non-container types
Origin supports (https://issues.apache.org/jira/browse/CASSANDRA-5648) "empty"
values even for non-container types such as int.  Use maybe_empty<> to
encapsulate abstract_type::native_type, adding an empty flag if needed.
2015-11-18 18:38:38 +02:00
Avi Kivity
79f7431a03 db: change collection_mutation::{one,view} not to use nested classes
Nested classes cannot be forward-declared, so change the naming
not to use them.  Follows atomic_cell{,_view}.
2015-11-13 17:13:07 +02:00
Avi Kivity
3fcb7add2e types: fix concrete_type::native_type_move()
The source is modified during a move, and so must not be const.
2015-11-13 17:13:07 +02:00
Avi Kivity
68a902ad0c data_value: add constructor from bool
schema_tables manages some boolean columns stored in system tables; it
dynamically creates them from C++ values.  But as we lacked bool->data_value
conversion, the C++ value was converted to a int32_type.  Somehow this didn't
cause any problems, but with some pending patches I have, it does.

Add a bool->data_value converting constructor to fix this.
2015-11-13 17:13:07 +02:00
Avi Kivity
74faaa4698 types: implement date_type::from_string()
Luckily all the hard work was already done for timestamp_type.

Fixes #522.
2015-11-03 10:33:20 +01:00
Avi Kivity
2c3591cbd9 data_value de-any-fication
We use boost::any to convert to and from database values (stored in
serlialized form) and native C++ values.  boost::any captures information
about the data type (how to copy/move/delete etc.) and stores it inside
the boost::any instance.  We later retrieve the real value using
boost::any_cast.

However, data_value (which has a boost::any member) already has type
information as a data_type instance.  By teaching data_type intances about
the corresponding native type, we can elimiante the use of boost::any.

While boost::any is evil and eliminating it improves efficiency somewhat,
the real goal is growing native type support in data_type.  We will use that
later to store native types in the cache, enabling O(log n) access to
collections, O(1) access to tuples, and more efficient large blob support.
2015-10-30 17:38:51 +01:00
Paweł Dziepak
75df23dd3c types: add collection_type_impl::difference()
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2015-10-22 12:08:53 +02:00
Avi Kivity
c48a826c65 db: fix string type incorrectly unvalidated
We call the conversion function that expectes a NUL terminated string,
but provide a string view, which is not.

Fix by using the begin/end variant, which doesn't require a NUL terminator.

Fixes #437.
2015-10-07 12:22:01 +02:00
Avi Kivity
c52d9f8da4 db: fix circular reference collection_type_impl <-> cql3_type
cql2_type is a simple wrapper around data_type.  But some data_types
(collection_type_impl) contain a cql3_type as a cache to avoid recomputing
it, resulting in a circular reference.  This leaks memory when as_cql3_type()
is called.

Fix by using a static hash table for the cache.
2015-09-29 08:38:15 +02:00
Avi Kivity
d5cf0fb2b1 Add license notices 2015-09-20 10:43:39 +03:00
Paweł Dziepak
39c29a3fb4 types: add decimal type
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-09-08 16:04:48 +02:00
Paweł Dziepak
f45aceb436 mutation_partition: purge tombstones in compact_and_expire()
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-09-07 21:18:45 +02:00
Pekka Enberg
78b8ca1a2c types: Unify type names
Fix duplicate type names in the types map and the classes themselves.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-08-28 14:39:46 +03:00
Pekka Enberg
dfbf84ce18 types: Introduce ascii_type_impl and utf8_type_impl classes
In preparation for reducing type name duplication, introduce classes for
ascii and utf8 types.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-08-28 14:01:55 +03:00
Pekka Enberg
d63649bf65 cql3: Fix CQL parser error message for counter types
The CQL tokenizer recognizes "COUNTER" token but the parser rule for
counter type is disabled. This causes users to see the following error
in cqlsh, for example:

  CREATE TABLE count (u int PRIMARY KEY, c counter);
  SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message=" : cannot match to any predicted input...  ">

We cannot disable the "COUNTER" token because it's also used in batch
statements. Instead, fix the issue by implementing a stub counter type.

Fixes #195.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-08-27 15:34:43 +03:00
Avi Kivity
ddee5e817a Workaround boost::any_cast bug
any_cast<X> is supposed to return X, but boost 1.55's any_cast<X> returns
X&&.  This means the lifetime-extending construct

   auto&& x = boost::any_cast<X>(...);

will not work, because the result of the expression is an rvalue reference,
not a true temporary.

Fix by using a temporary, not a lifetime-extending reference.

Fixes #163.
2015-08-19 09:15:31 +03:00
Paweł Dziepak
f846eb2032 types: tuple: fix std::move() in constructor
In an expression like:

  tuple_type_impl(make_name(types), std::move(types));

the order in which arguments are evaluated is unspecified and it
is possible that make_name() is called with types already moved
away.

This is fixed by using initialization list (for which order of
evalutaion is specified). Unfortunately, this also requires some code
duplication.

Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-08-17 14:25:39 +02:00
Paweł Dziepak
08b2c5801d types: tuple: use fully qualified class name as type name
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-08-17 14:24:17 +02:00
Gleb Natapov
dadd097f9c do not use boost::multiprecision::msb()
It is not available in boost older than 1.55.
2015-07-23 17:55:12 +03:00
Paweł Dziepak
babb2fa261 types: add varint type
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-21 14:46:34 +02:00
Asias He
fa2aee57ac utils: Move util/serialization.hh to utils/serialization.hh
Now we will not have the ugly utils and util directories, only utils.
2015-07-21 16:12:54 +08:00
Avi Kivity
99a15de9e5 logger: de-thread_local-ize logger
The logger class constructor registers itself with the logger registry,
in order to enable dynamically setting log levels.  However, since
thread_local variables may be (and are) initialized at the time of first
use, when the program starts up no loggers are registered.

Fix by making loggers global, not thread_local.  This requires that the
registry use locking to prevent registration happening on different threads
from corrupting the registry.

Note that technically global variables can also be initialized at the
point of first use, and there is no portable way for classes to self-register.
However this is the best we can do.
2015-07-14 17:18:11 +03:00
Tomasz Grabiec
4a1bf56b48 types: Introduce collection_type_impl::mutation::compact_and_expire()
Will be needed by mutation query.
2015-07-12 12:51:38 +02:00
Tomasz Grabiec
a0cb362838 types: Support serialization of empty values
deserialization already can produce empty values, so we should also be
able to serialize them.
2015-07-09 19:55:01 +02:00
Paweł Dziepak
cf07b4c09a types: make comparing floating point values follow Java behavior
In Java method compareTo() of Float and Double types doesn't strictly
follow IEEE 754. Firstly, NaN is equal NaN and is greater than any other
value. Secondly, positive zero is larger than negative zero.

Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-09 17:52:45 +02:00
Paweł Dziepak
c139f1c1d7 types: implement validation for built-in types
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-07 13:57:47 +02:00
Paweł Dziepak
22568a1995 types: implement timestamp_type_impl::from_string()
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-06 23:36:18 +02:00
Paweł Dziepak
d993ec69f6 types: implement inet_addr_type_impl::{from, to}_sstring()
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-06 23:33:03 +02:00
Paweł Dziepak
bb30e05149 types: implement uuid_type_impl::{from, to}_sstring()
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-06 23:31:22 +02:00
Paweł Dziepak
b33a401f01 types: implement timeuuid_type_impl::{from, to}_sstring()
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-06 23:30:44 +02:00
Paweł Dziepak
f8598a668a types: implement floating_type_impl::{from, to}_string()
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-06 23:26:17 +02:00
Paweł Dziepak
183b6fc6d9 db: do not return already expired cells in queries
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-07-02 17:25:41 +02:00
Tomasz Grabiec
de23b54764 types: Implement to_string()/from_string() for boolean_type 2015-06-23 17:07:37 +03:00
Pekka Enberg
f7f06758a6 types: Fix data type naming
Fix data type naming to follow Origin's conventions so that we can
serialize the names to database.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-17 12:25:18 +03:00
Pekka Enberg
fab1289857 types: Add abstract_type::parse_type() helper
Add a parse_type() function for parsing a serialized type name and
returning a data_type for it. Please note that collection types are
handled elsewhere.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-17 12:25:18 +03:00
Pekka Enberg
42cfcfb32d database: Remove compose() function
Convert code to use the deserialize() function and drop the duplicate
compose() wrapper that we inherited from Origin.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-05-27 16:22:35 +03:00
Tomasz Grabiec
2693dd2c7b db: Extract bytes related stuff from database.cc to bytes.cc
Some tests (eg murmur_hash_test) need only byte manipulation
functions. By specifying dependencies precisely we can drastically
reduce recompilation times, which speeds up development cycle.

I managed to reduce recompilation time for murmur_hash_test from 5
minutes to 4 seconds by breaking dependency on whole urchin object
set.
2015-04-29 15:50:16 +03:00
Avi Kivity
6290dee438 db: const correctness for abstract_type and friends
Types are immutable.
2015-04-29 15:40:38 +03:00
Avi Kivity
ab60ed8813 db: s/shared_ptr<abstract_type>/data_type/
Also replace derived types (map_type, collection_type, etc.).

As we'll change data_type's definition, this reduces the number of places
that need to be modified later, and is more readable.
2015-04-29 15:09:04 +03:00
Avi Kivity
3179f05e12 db: implement user types (user_type_impl)
Like a C struct.  Following origin, implemented as a tuple with an additional
vector of field names.

cql3_type integration deferred to the next patch.
2015-04-20 16:15:34 +03:00
Tomasz Grabiec
560c972bb3 Merge tag 'avi/tuples/v3' from seastar-dev.git
Resolved trivial conflicts in:
	cql3/lists.cc
	tests/urchin/cql_query_test.cc
2015-04-15 18:01:37 +02:00
Avi Kivity
7bd1d0b2ad cql3: support for tuple cql3_type 2015-04-15 15:35:30 +03:00
Avi Kivity
4e43fab7f1 db: add tuple_type_impl
cql3_type integration is deferred to the next patch.
2015-04-15 15:35:30 +03:00
Avi Kivity
4abad8f357 db: add collection_type_impl::reserialize()
Allows switching between serialization formats.
2015-04-15 15:35:30 +03:00
Nadav Har'El
bae3cbf7a2 db: fix typo in set_type_impl user-visible name
Noticed this typo while browsing the code. I have no idea what this typo
broke, if anything, but it couldn't have been intentional...

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-04-13 18:53:03 +03:00
Avi Kivity
77552d3407 db: fix float_type's implementation
Was double, should be float.
2015-04-11 00:54:10 +03:00
Avi Kivity
30b40bf7b1 db: make bytes even more distinct from sstring
bytes and sstring are distinct types, since their internal buffers are of
different length, but bytes_view is an alias of sstring_view, which makes
it possible of objects of different types to leak across the abstraction
boundary.

Fix this by making bytes a basic_sstring<int8_t, ...> instead of using char.
int8_t is a 'signed char', which is a distinct type from char, so now
bytes_view is a distinct type from sstring_view.

uint8_t would have been an even better choice, but that diverges from Origin
and would have required an audit.
2015-04-07 10:56:19 +03:00