Commit Graph

30 Commits

Author SHA1 Message Date
Avi Kivity
3d38708434 cql3: pass a database& instance to most foo::raw::prepare() variants
To prepare a user-defined type, we need to look up its name in the keyspace.
While we get the keyspace name as an argument to prepare(), it is useless
without the database instance.

Fix the problem by passing a database reference along with the keyspace.
This precolates through the class structure, so most cql3 raw types end up
receiving this treatment.

Origin gets along without it by using a singleton.  We can't do this due
to sharding (we could use a thread-local instance, but that's ugly too).

Hopefully the transition to a visitor will clean this up.
2015-04-20 16:15:34 +03:00
Tomasz Grabiec
00f99cefd4 db: split query.hh to reduce header dependencies 2015-04-15 20:44:59 +02:00
Tomasz Grabiec
878a740b9d db: Write query results in serialized form
This gives about 30% increase in tps in:

  build/release/tests/perf/perf_simple_query -c1 --query-single-key

This patch switches query result format from a structured one to a
serialized one. The problems with structured format are:

  - high level of indirection (vector of vectors of vectors of blobs), which
    is not CPU cache friendly

  - high allocation rate due to fine-grained object structure

On replica side, the query results are probably going to be serialized
in the transport layer anyway, so this change only subtracts
work. There is no processing of the query results on replica other
than concatenation in case of range queries. If query results are
collected in serialized form from different cores, we can concatenate
them without copying by simply appending the fragments into the
packet. This optimization is not implemented yet.

On coordinator side, the query results would have to be parsed from
the transport layer buffers anyway, so this also doesn't add work, but
again saves allocations and copying. The CQL server doesn't need
complex data structures to process the results, it just goes over it
linearly consuming it. This patch provides views, iterators and
visitors for consuming query results in serialized form. Currently the
iterators assume that the buffer is contiguous but we could easily
relax this in future so that we can avoid linearization of data
received from seastar sockets.

The coordinator side could be optimized even further for CQL queries
which do not need processing (eg. select * from cf where ...)  we
could make the replica send the query results in the format which is
expected by the CQL binary protocol client. So in the typical case the
coordinator would just pass the data using zero-copy to the client,
prepending a header.

We do need structure for prefetched rows (needed by list
manipulations), and this change adds query result post-processing
which converts serialized query result into a structured one, tailored
particularly for prefetched rows needs.

This change also introduces partition_slice options. In some queries
(maybe even in typical ones), we don't need to send partition or
clustering keys back to the client, because they are already specified
in the query request, and not queried for. The query results hold now
keys as optional elements. Also, meta-data like cell timestamp and
ttl is now also optional. It is only needed if the query has
writetime() or ttl() functions in it, which it typically won't have.
2015-04-15 20:44:50 +02:00
Tomasz Grabiec
7ebc7830b7 db: Optimize column family lookup in query path 2015-04-15 20:33:48 +02:00
Avi Kivity
b3f3c76dd8 cql3: fix overzealous move in modification_statement::get_mutations()
'keys' and 'prefix' are used twice in the same expression, and as the language
does not guarantee any ordering in this case, any moves are illegal.

Get rid of them.
2015-03-26 12:14:01 +02:00
Avi Kivity
b650383d67 cql3: implement read_required_rows()
Some modification statements require reading rows before modifying them;
implement it.
2015-03-26 12:14:01 +02:00
Tomasz Grabiec
e3422525c0 Use column_definition via const reference 2015-03-24 12:03:00 +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
49b7a166a8 keys: Make key components non-optional 2015-03-19 14:54:41 +01:00
Avi Kivity
bdd188f459 Merge branch 'tgrabiec/select' of github.com:cloudius-systems/seastar-dev into db
Preparation for range queries, from Tomasz:

"This series adds static typic for different key variants.

It also changes clustered row map to boost implementation which allows to use
heterogenous keys, so that we can lookup a row by a full prefix without
reserializing it.

Similar change is made to row prefix tombstones."
2015-03-18 12:58:01 +02:00
Pekka Enberg
b40661c330 cql3: Use shared_ptr for prepared statements
Query processor needs to store prepared statements as part of a client
session for PREPARE and EXECUTE requests. Switch from unique_ptr to
shared_ptr in preparation for that.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-03-18 10:49:41 +02: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
Tomasz Grabiec
1f6360ec3b cql3: Drop redundant key validation
Keys are also validated right before in build_partition_keys().
2015-03-17 15:56:28 +01:00
Tomasz Grabiec
1a0ffdfb99 schema: Encapsulate column sets 2015-02-27 10:48:56 +01:00
Tomasz Grabiec
b77367dabe cql3: Simplify primary key membership checks 2015-02-27 10:48:56 +01:00
Tomasz Grabiec
609e893055 unimplemented: Separate subject from behavior
You can now do:

  fail(unimplemented::cause::PAGING);

and:

  warn(unimplemented::cause::PAGING);
2015-02-27 10:48:56 +01:00
Tomasz Grabiec
0293b151dc cql3: Fix bug in modification_statement::process_where_clause() 2015-02-12 19:40:58 +01:00
Tomasz Grabiec
43300e9998 cql3: Use find() instead of [] when looking up processed keys
find() is sufficient and it has less surprising side effects. This
doesn't fix any issue.
2015-02-12 19:40:58 +01:00
Tomasz Grabiec
f3130d395f cql3: Return shared_ptr<result_message> instead of optional
It's polymorphic type in Origin.
2015-02-12 19:40:57 +01:00
Tomasz Grabiec
524c6a4e40 cql3: Implement modification_statement::validate() 2015-02-12 19:40:57 +01:00
Tomasz Grabiec
9530a372cc cql3: Take reference to storage_proxy and call instance methods 2015-02-09 10:28:44 +01:00
Tomasz Grabiec
800ba79efa db: Drop api:: namespace from mutation model classes
In preparation for merging into database.hh
2015-02-09 10:28:44 +01:00
Tomasz Grabiec
87597ba3a4 cql3: Fix typo in process_where_clause() 2015-02-09 10:28:43 +01:00
Tomasz Grabiec
208fdfab45 cql3: Move methods from header to source file 2015-02-09 10:28:09 +01:00
Tomasz Grabiec
bad22fe50e cql3: Convert ModificationStatement.Parsed.prepare()
Together with ParsedInsert descendant.
2015-02-04 10:29:05 +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
5710a99f44 cql3: Fix mis-overrides of cql_statement::execute*()
The method may defer so the result is wrapped in future<>.

I think we don't need to wrap arguments in shared_ptr<> because they
may come from the request state object.
2015-02-04 10:28:51 +01:00
Tomasz Grabiec
496e5c651f cql3: Convert more of ModificationStatement 2015-01-29 19:41:00 +01:00
Tomasz Grabiec
78eaabf9d9 cql3: Make statement_type printable 2015-01-23 18:45:28 +01:00
Pekka Enberg
e4a8d7cf71 cql3: Convert ModificationStatement to C++
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-01-20 11:48:26 +02:00