Commit Graph

140 Commits

Author SHA1 Message Date
Tomasz Grabiec
ce768858f5 types: Fix update_types()
We should replace the old type, not insert the new type before the old type.

Fixes #1465

Message-Id: <1468861076-20397-1-git-send-email-tgrabiec@scylladb.com>
2016-07-18 20:14:22 +03:00
Paweł Dziepak
10c144ffd4 types: fix type aliasing violation
Any pointer can be casted to char*, but not the other way around. This
causes GCC6 to misoptimize timestamp_type_impl::from_string().

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
Message-Id: <1468413349-27267-1-git-send-email-pdziepak@scylladb.com>
2016-07-13 17:22:16 +03:00
Tomasz Grabiec
8c4b5e4283 db: Avoiding checking bloom filters during compaction
Checking bloom filters of sstables to compute max purgeable timestamp
for compaction is expensive in terms of CPU time. We can avoid
calculating it if we're not about to GC any tombstone.

This patch changes compacting functions to accept a function instead
of ready value for max_purgeable.

I verified that bloom filter operations no longer appear on flame
graphs during compaction-heavy workload (without tombstones).

Refs #1322.
2016-07-10 09:54:20 +02:00
Nadav Har'El
c4e871ea2d Work around unexpected data_value constructor
If someone tried to naively use utf8_type->decompose("18wX"), this would
mysteriously fail, returning an empty key.

decompose takes a data_value, so the compiler looked for an implict
conversion from the string constant (const char*) to data_value. We did
not have such a conversion, only conversion from sstring. But the compiler
chose (backed by the C++ standard, no doubt) to implicitly convert the
const char* to a bool (!), and then use data_value(bool). It did not
convert the const char* to an sstring, nor did it warn about the possible
ambiguity.

So this patch adds a data_value(const char*) constructor, so people will
not fall into the same trap that I fell into...

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <1467643462-6349-1-git-send-email-nyh@scylladb.com>
2016-07-04 17:50:53 +03:00
Gleb Natapov
5fef0717cc query: find latest modification timestamp while calculating result digest 2016-05-24 13:27:34 +03:00
Duarte Nunes
bc90d6a730 udt: type_parser handles user defined types
This patch ensures type_parser can handle user defined types. It also
prefixes user_type_impl::make_name() with
org.apache.cassandra.db.marshal.UserType.

Fixes #631

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
2016-04-20 18:07:07 +02:00
Duarte Nunes
3e663cfa9a udt: Add capability to replace a user_type
This patch adds a function to abstract_type that locates the usage of
a given user_type and recursively returns an updated version of the
containing type containing the updated user type.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
2016-04-20 18:07:06 +02:00
Duarte Nunes
66c60f03fe udt: Add references_user_type to abstract_type
This patch adds a virtual function to the abstract_type hierarchy to
tell whether a given type references the specified type. Needed to
implement the drop and alter type statements.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
2016-04-20 09:54:07 +02:00
Duarte Nunes
ddb4a4b29b udt: Implement as_cql3_type for user_type_impl
Signed-off-by: Duarte Nunes <duarte@scylladb.com>
2016-04-20 09:54:06 +02:00
Duarte Nunes
fdddcfb3ea udt: Fix user type compatibility check
A new user type is checked for compatibility against the previous
version of that type, so as to ensure that an updated field type
is compatible with the previous field type (e.g., altering a field
type from text to blob is allowed, but not the other way around).

However, it is also possible to add new fields to a user type. So,
when comparing a user type against its previous version, we should
also allow the current, new type to be longer than the previous one.
The current code instead allows for the previous type to be longer,
which this patch fixes.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
2016-04-20 09:54:06 +02:00
Duarte Nunes
0aeb4dcaaf udt: Implement equals() for user_type_impl
Signed-off-by: Duarte Nunes <duarte@scylladb.com>
2016-04-20 09:54:06 +02:00
Duarte Nunes
f8d8dbdeb7 types: Don't wrap tombstone in an std::optional
All the callers of do_serialize_mutation_form pass a valid tombstone
that is converted into a non-empty optional. This happens even if the
tombstone is empty (tombstone::timestamp == api::missing_timestamp).

This patch fixes this by passing in a reference to the tombstone which
is convertible to bool, based on whether it is empty or not.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
Message-Id: <1460620528-3628-1-git-send-email-duarte@scylladb.com>
2016-04-20 09:22:01 +02:00
Duarte Nunes
40c1b29701 cql3: Implement contains relation
Although it doesn't work in the absence of secondary indexes,
now we provide the same error messages as origin when trying to use
the contains relation.

Fixes #1158

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
Message-Id: <1461088626-26958-1-git-send-email-duarte@scylladb.com>
2016-04-20 09:22:25 +03:00
Pekka Enberg
38a54df863 Fix pre-ScyllaDB copyright statements
People keep tripping over the old copyrights and copy-pasting them to
new files. Search and replace "Cloudius Systems" with "ScyllaDB".

Message-Id: <1460013664-25966-1-git-send-email-penberg@scylladb.com>
2016-04-08 08:12:47 +03:00
Piotr Jastrzebski
d3f91eec61 Implement tuple_type_impl::from_string
This is a fix for:
https://github.com/scylladb/scylla/issues/574

It mirrors the behavior of:
org.apache.cassandra.db.marshal.TupleType.java#fromString

Signed-off-by: Piotr Jastrzebski <piotr@scylladb.com>
Message-Id: <24a7d6253727d0faebb1df117c2f52410523d42f.1459843091.git.piotr@scylladb.com>
2016-04-05 16:00:18 +03:00
Paweł Dziepak
23ee493d91 types: make collection_type_impl::deserialize_mutation_form static
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-03-11 18:27:13 +00:00
Pekka Enberg
ab502bcfa8 types: Implement to_string for timestamps and dates
The to_string() function is used for logging purpose so use boost
to_iso_extended_string() to format both timestamps and dates.

Fixes #968 (showstopper)
Message-Id: <1457528755-6164-1-git-send-email-penberg@scylladb.com>
2016-03-09 14:08:33 +01:00
Paweł Dziepak
e332f95960 types: make serialize_mutation_form() static
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-02-19 21:47:42 +00:00
Tomasz Grabiec
9d11968ad8 Rename serialization_format to cql_serialization_format 2016-02-15 16:53:56 +01:00
Paweł Dziepak
dbb878d16e Revert "do not use boost::multiprecision::msb()"
This reverts commit dadd097f9c.

That commit caused serialized forms of varint and decimal to have some
excess leading zeros. They didn't affect deserialization in any way but
caused computed tokens to differ from the Cassandra ones.

Fixes #898.

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
Message-Id: <1455537278-20106-1-git-send-email-pdziepak@scylladb.com>
2016-02-15 14:24:37 +02:00
Paweł Dziepak
900f5338e7 types: make timestamp_type and date_type compatible
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-01-19 14:03:15 +01:00
Paweł Dziepak
a6171d3e99 types: add date type to parse_type()
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-01-19 13:43:36 +01:00
Paweł Dziepak
f77ab67809 types: use correct name for date_type
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-01-19 13:42:53 +01:00
Paweł Dziepak
440b6d058e types: fix compatibility for text types
bytes_type is_compatible_with utf8_type and ascii_type
utf8_type is_compatible_with ascii_type

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2016-01-19 09:39:16 +01:00
Avi Kivity
78429ad818 types: implement collection compatibility checks
compatible: can be cast, keeps sort order
value-compatible: can be cast, may change sort order

frozen: values participate in sort order
unfrozen: only sort keys participate in sort order

Fixes #740.
2016-01-04 11:02:21 +01:00
Paweł Dziepak
633a13f7b3 types: timestamp_from_string: accept more date formats
Boost::date_time doesn't accept some of the date and time formats that
the origin do (e.g. 2013-9-22 or 2013-009-22).

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2015-12-21 15:30:35 +01:00
Paweł Dziepak
d41807cb66 types: timestamp_from_string(): restore indentation
Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2015-12-21 15:17:50 +01:00
Paweł Dziepak
873ed78358 types: catch parsing errors in timestamp_from_string()
timestamp_from_string() is used by both timestamp and date types, so it
is better to move the try { } catch { } to the functions itself instead
of expecting its callers to catch exceptions.

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
2015-12-21 15:14:36 +01:00
Pekka Enberg
e56bf8933f Improve not implemented errors
Print out the function name where we're throwing the exception from to
make it easier to debug such exceptions.
2015-12-18 10:51:37 +01:00
Tomasz Grabiec
de09c86681 data_value: Make printable 2015-12-16 18:06:54 +01:00
Pekka Enberg
0d8a02453e types: Fix frozen collection type names
Frozen collection type names must be wrapped in FrozenType so that we
are able to store the types correctly in system tables.

This fixes #646 and fixes #580.

Signed-off-by: Pekka Enberg <penberg@scylladb.com>
2015-12-11 10:41:11 +01:00
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