Commit Graph

96 Commits

Author SHA1 Message Date
Pekka Enberg
3150bb5b78 database: Initialize system keyspace in database constructor
System keyspace is used for things like keyspace and table metadata.
Initialize it in database constructor so that they're always available.
Needed for CQL create keyspace test case, for example.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-03-26 12:41:00 +02:00
Pekka Enberg
fd8e92ab07 database: Add mutation::set_cell() variant
This adds a set_cell() variant which accepts a column name and a
boost::any value and does column definition lookup and decomposition
under the hood. Simplifies code that manipulates system tables directly
in db/legacy_schema_tables.cc.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-03-26 12:40:58 +02:00
Tomasz Grabiec
b26b39504a db: Add find_or_create_keyspace()
Needed for tests.
2015-03-25 10:36:19 +01:00
Tomasz Grabiec
9eafa69d43 db: Avoid unnecessary lookup of row key when applying range tombstones 2015-03-25 10:36:19 +01:00
Tomasz Grabiec
7bd076ed85 db: Extract range tombstone lookup to separate method
While at it, convert affected methods to take a schema by const& instead
of a shared pointer to save on unnecessary shared ptr copies.
2015-03-25 10:36:19 +01:00
Tomasz Grabiec
866dd449db db: Remove unused methods 2015-03-25 10:36:18 +01:00
Glauber Costa
1880baa873 database: read-in sstables metadata
Now that the code for sstable metadata is ready, we can read it when we are
loading the keyspaces.

At this moment, only the system tables are processed. This is because we will
require the schema to be already determined in order to properly read the
sstables. The system schema is known at compile time. The others will have to
be derived when we are able to read it from the system tables themselves.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-03-24 15:52:24 +02:00
Avi Kivity
1d5f94bad1 db: add mutation_partition::get_cell()
While most mutations don't need existing column values, some (SET my_list[3]=2)
do.  Add an accessor function for them.
2015-03-23 16:04:29 +02:00
Tomasz Grabiec
0330568977 db: Handle range queries on clustering key
That also includes prefix range queries (partially constrained keys).
2015-03-20 19:20:59 +01:00
Tomasz Grabiec
bdbd5547e3 db: Cleanup key names
clustering_key::one -> clustering_key
clustering_key::prefix::one -> clustering_key_prefix
partition_key::one -> partition_key
clustering_prefix -> exploded_clustering_prefix
2015-03-20 18:59:29 +01:00
Tomasz Grabiec
6197c5306d db: Optimize range tombstone lookups
From O(N) to O(log(N)) where N is the number of range tombstones.
2015-03-17 15:56:29 +01:00
Tomasz Grabiec
9f60853271 db: Switch clustering key map and row tombstones to boost::intrusive::set
std::map<> does not support lookup using different comparator than the
one used to compare keys. For range prefix queries and for row prefix
tombstone queries we will need to perform lookups using different
comparators.
2015-03-17 15:56:29 +01:00
Tomasz Grabiec
1b1af8cdfd db: Introduce types to hold keys
Holding keys and their prefixes as "bytes" is error prone. It's easy
to mix them up (or use wrong types). This change adds wrappers for
keys with accessors which are meant to make misuses as difficult as
possible.

Prefix and full keys are now distinguished. Places which assumed that
the representation is the same (it currently is) were changed not to
do so. This will allow us to introduce more compact storage for non-prefix
keys.
2015-03-17 15:56:29 +01:00
Avi Kivity
0d0a4192f4 db: add mutation::set_cell() helper
Rather than checking for a static vs. clustered cell at the call site,
to this in one place.
2015-03-16 16:36:14 +02:00
Tomasz Grabiec
2f6d9a4113 db: Introduce query interface 2015-03-11 16:01:13 +01:00
Tomasz Grabiec
acda112314 db: Register system keyspace
This also changes populate() interface a bit. They now work on
existing objects, so that system keyspace definition is not
overriden. For non-system keyspace, the keyspace definition would come
from the data in the system tables.
2015-03-11 16:01:13 +01:00
Tomasz Grabiec
262fed73f5 db: Add stub for secondary_index_manager class 2015-03-11 14:56:10 +01:00
Avi Kivity
bb0d2a4f03 db: fix mutation::set_*_cell() applied twice to same column
With a collection, setting two separate elements in a collection would
cause the second to override the first.  This also applies, with much
smaller effect, to normal cells (for example, updating the same counter
twice, or issuing two updates to the same cell but with different timestamps,
via thrift).

Fix by merging the two values rather than replacing the old one.
2015-03-05 19:04:02 +02:00
Avi Kivity
b14d9f1f02 mutation: support for collections
We simply store the collection mutation as we do atomic cells -- merging
will be done by the consumer.
2015-03-05 14:03:36 +02:00
Avi Kivity
6d18aa8f20 Decompose database.hh, types.hh into smaller headers
Avoid include hell for new code.
2015-03-04 16:18:48 +02:00
Avi Kivity
a49330095a db: wrap bytes in atomic_cell format
We use bytes for many different things, and it is easy to get confused as
to what format the data is actually in.

Fix that for atomic_cell by proving wrappers.  atomic_cell::one corresponds
to a bytes object holding exactly one atomic cell, and atomic_cell::view is
a bytes_view to an atomic_cell.  The static functions of atomic_cell itself
are privatized to prevent the unwashed masses from using them on the wrong
objects.

Since a row entry can hold either a an atomic cell, or a collection,
depending on the schema, also introduce a variant type
atomic_cell_or_collection and allow the user to pick the type explicitly.
Internally both are stored as bytes object.
2015-03-04 15:49:35 +02:00
Tomasz Grabiec
74295a9759 db: Use opaque bytes for cell values instead of boost::any
Storing cells as boost::any objects makes us use expensive
boost::any_cast to access the data. This change replaces boost::any
with bytes object which holds the value in serialized form (the same
as will be used for on-wire format).

If the cell type is atomic, you use fields accessors defined in
atomic_cell class, eg like this:

if (column.type.is_atomic()) {
   if (atomic_cell::is_live(c) {
      auto timestamp = atomic_cell::timestamp(c);
      ...
   }
}

Eventually we could switch to a more officient semi-serialized form
with native byte order but I don't want to introduce it just yet for
simplicity.
2015-02-27 10:59:43 +01:00
Avi Kivity
2720ba34bf db: shard data
Add database::shard_of() to compute the shard hosting the partition
(with a simplistic algorithm, but perhaps not too bad).

Convert non-metadata invoke_on_all() and local calls on the database
to use shard_of().
2015-02-23 11:37:12 +02:00
Avi Kivity
70381a6da5 db: distribute database object
s/database/distributed<database>/ everywhere.

Use simple distribution rules: writes are broadcast, reads are local.
This causes tremendous data duplication, but will change soon.
2015-02-19 17:53:13 +02:00
Avi Kivity
e8096ff2bb db: add database::stop()
Required by distributed<>'s contract.
2015-02-19 16:33:27 +02:00
Avi Kivity
8f9f794a73 db: make column_family::apply(mutation) not steal the contents
With replication, we want the contents of the mutation to be available
to multiple replicas.

(In this context, we will replicate the mutation to all shards in the same
node, as a temporary step in sharding a node; but the issue also occurs
when replicating to other nodes).
2015-02-19 16:23:09 +02:00
Avi Kivity
a2519926a6 db: add some iostream output operators
Helps debugging
2015-02-19 15:56:26 +02:00
Tomasz Grabiec
aaf9463568 db: Take names by const& in find_*() functions 2015-02-12 19:40:58 +01:00
Tomasz Grabiec
9a307918ef db: Cleanup comment 2015-02-12 19:40:58 +01:00
Tomasz Grabiec
06ccaa3b5b db: Move method definitions to source file 2015-02-12 19:40:56 +01:00
Tomasz Grabiec
fb6941bbee tests: Add test for row tombstones 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
7ea7a6822b db: Fix mutation_partition::apply_row_tombstone()
It was not updating already inserted tombstones.
2015-02-09 10:28:45 +01:00
Tomasz Grabiec
a6f4f2d6aa db: Add mutation_partition::tombstone_for_row() 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
0a5bf555ea types: Introduce tuple_type::is_prefix_of() 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
7b7f63645b db: Make tombstone::operator bool() explicit 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
37599d5d10 db: Define the rest of comparison operators in tombstone 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
0bde5f74e7 db: Introduce tombstone::compare() and express operators using it 2015-02-09 10:28:45 +01:00
Tomasz Grabiec
1b66f33455 db: Apply mutations locally from storage_proxy
Eventually we should rather send them to replicas, but for now we just
apply locally.
2015-02-09 10:28:44 +01:00
Tomasz Grabiec
2244eab6c1 db: Steal data from mutations when applying
Taking mutations by r-value reference allows us to avoid copies.
2015-02-09 10:28:44 +01:00
Tomasz Grabiec
d5a7f37c45 db: Merge api.hh into database.hh 2015-02-09 10:28:44 +01:00
Tomasz Grabiec
48c11a01db db: Add ability to apply mutations into the database
For simplicity partition data is stored using the same object which is
used for mutations: mutation_partition. Later we can introduce a more
efficient version.
2015-02-09 10:28:44 +01:00
Tomasz Grabiec
211f52e40a schema: Move to schema.hh 2015-02-09 10:28:44 +01:00
Tomasz Grabiec
609f6e0d31 schema: Add is_partition_key() tester 2015-02-04 10:29:04 +01:00
Tomasz Grabiec
77b37a7c03 schema: Add column_specification field to schema
In Origin, some places in CQL3 package treat ColumnDefinition as
ColumnSpecification. Origin solves that by making ColumnDefinition
extend ColumnSpecification.

I find it much simpler to provide an external adapter, which is cached
as a field for efficiency. Another, more important, reason for this
solution is that column_specifications are passed around as
shared_ptrs and I don't want to add unnecessary indirection to
column_definition accesses just because of that, to make it inherit
from column_specification.
2015-02-04 10:29:04 +01:00
Tomasz Grabiec
654372f368 schema: Allow regular column names to have arbitrary type
Regular columns may have names of arbitrary type. See
https://issues.apache.org/jira/browse/CASSANDRA-8178

Primary key columns are UTF8.

This change also does some refactoring of the schema object to make
the change easier to digest (more encapsulation).
2015-02-04 10:29:00 +01:00
Tomasz Grabiec
b7cf3a679d Convert ThriftValidation.validateColumnFamily(String,String)
Unlike origin, we don't use global singleton, but accept a database
reference instead.
2015-02-04 10:28:59 +01:00
Tomasz Grabiec
cbe1a3d403 schema: Introduce schema::get_column_definition() 2015-02-04 10:28:56 +01:00
Tomasz Grabiec
6ba3732620 schema: Rename column_kind::PRIMARY -> column_kind::PARTITION
The old name was incorrect.
2015-02-04 10:28:51 +01:00
Tomasz Grabiec
64128dc117 cql3: Convert UpdateParameters 2015-01-29 18:55:24 +01:00
Tomasz Grabiec
333d1f259f Stub schema::is_dense() and schema::is_counter() 2015-01-29 18:55:24 +01:00