Commit Graph

27 Commits

Author SHA1 Message Date
Tomasz Grabiec
96bbac8a57 dht: Make partitioner work on partition_key_view 2015-05-06 15:52:56 +02:00
Tomasz Grabiec
aec740f895 db: Make decorated_key have ordering compatible with Origin 2015-04-30 12:02:39 +02:00
Tomasz Grabiec
359af7745c dht: murmur3_partitioner: move get_token() implementation to .cc 2015-04-30 11:16:53 +02:00
Avi Kivity
65b8b19ca7 Merge branch 'tgrabiec/order-partitions-by-decorated-key' of github.com:cloudius-systems/seastar-dev into db
Use decorated_key in partition maps, from Tomasz:

"Partitions should be ordered using Origin's ordering, which is the natural
ordering of decorated_key. This is achieved by switching column_family's
partition map to use decorated_key instead of a bare partition_key.

This also includes some cleanups."

[avi] trivial adjustments to sstables/keys.cc
2015-04-25 19:22:51 +03:00
Tomasz Grabiec
71041eb0d6 dht: Implement operator<< for decorated_key 2015-04-24 18:01:01 +02:00
Tomasz Grabiec
841a13da93 dht: Implement operator!= for decorated_key 2015-04-24 18:01:01 +02:00
Glauber Costa
7c7da26347 dht: generate a token from a bytes_view
It has been determined that we will store partition_keys in the decorated_keys.
That is totally fine, but the token needs to be generatable from an sstable::key
as well.

Since both types convert well to a bytes_view - and the first thing get_token() does
is precisely to generate that view, let's generate the token from a bytes_view instead.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-04-24 10:11:49 -04:00
Pekka Enberg
d23b7796f8 dht/i_partitioner.hh: Make decorated key operators visible
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-04-23 10:34:34 +02:00
Gleb Natapov
02fb270fbe token operator<< 2015-04-19 10:15:14 +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
Glauber Costa
eee72251d0 add comparison and hash operators for dht::token
Inspired in Gleb's previous patch, this patch adds a hash and comparison
operator for dht::token.

The previous patch, however, had a number of problems. Comparisons were failing
in tokens that were verified (by me) to be equal to the ones Origin was
generating.

The main reasons for that, was that the byte-comparison loop must be unsigned,
not signed.

With the above change, the comparison function would always succeed *except*
when the integer version of _data was that of a signed one.

Looking at Origin, one verifies that the Murmur3Partitioner class overrides the
comparison functions, and just does a Long comparison with the token.

This patch implements a similar mechanism. With that, a list of tokens
generated by origin in ascending order is verified by us to also be in
ascending order.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-04-02 16:16:39 +02: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
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
f321b9e9b5 util: Make hash functions work on bytes_view 2015-03-17 15:56:28 +01:00
Avi Kivity
678c259c66 murmur3: switch to unsigned types
C++ doesn't define overflow on signed types, so use unsigned types instead.
Luckily all right shifts were unsigned anyway.

Some signed extension was happening (handling remainders after processing
8-byte chunks) but should still be there.

Caught by debug build.
2015-02-24 15:29:08 +02:00
Avi Kivity
6f7dff825c dht: add global partitioner
Skip configuration for now and go for murmur3 instead.
2015-02-23 11:37:12 +02:00
Avi Kivity
d0dae3f938 dht: add murmur3_partitioner
We don't follow origin precisely in normalizing the token (converting a
zero to something else).  We probably should, to allow direct import of
a database.
2015-02-23 11:37:12 +02:00
Avi Kivity
fd9f90f45a dht: implement token minimum and midpoint
Rather than converting to unsigned longs for the fractional computations,
do them it bytes.  The overhead of allocating longs will be larger than
the computation, given that tokens are usually short (8 bytes), and
our bytes type stores them inline.
2015-02-23 10:20:24 +02:00
Avi Kivity
edc4ac4231 dht: de-virtualize token
Origin uses abstract types for Token; for two reasons:

 1. To create a distinction between tokens for keys and tokens
    that represent the end of the range
 2. To use different implementations for tokens belonging to different
    partitioners.

Using abstract types carries a penalty of indirection, more complex
memory management, and performance.  We can eliminate it by using
a concrete type, and defer any differences in the implementation
to the partitioner.  End-of-range token representation is folded into
the token class.
2015-02-23 10:20:24 +02:00
Avi Kivity
41ba192590 dht: make i_partitioner's methods public, and add a destructor 2015-02-23 10:20:22 +02:00
Avi Kivity
a166f74a54 dht: rename DecoratedKey and Token to fit with naming conventions 2015-02-22 17:53:32 +02:00
Asias He
bf78e14d17 db: Switch to seastar shared_ptr from std::shared_ptr 2015-01-15 09:05:48 +08:00
Asias He
dfc19433bb dht: Switch to i_partitioner in ring_position 2015-01-14 14:51:06 +02:00
Asias He
65173589b9 dht: Convert dht/IPartitioner.java to C++ 2015-01-07 20:49:57 +08:00
Asias He
0581c0de12 dht: Import dht/IPartitioner.java 2015-01-07 20:44:55 +08:00
Asias He
e145946c97 dht: Convert dht/RingPosition.java to C++ 2015-01-07 20:44:54 +08:00
Asias He
348d447bf1 dht: Import dht/RingPosition.java 2015-01-07 20:44:54 +08:00