Files
scylladb/dht/byte_ordered_partitioner.cc
Avi Kivity f915ff1fcd dht: introduce i_partitioner::shard_of() and implement msb sharding
Make sharding partitioner-specific, since different partitioners interpret
the byte content differently.

Implement it by extracting the shard from the most significant bits, which
can be used to minimize cross shard traffic for range queries, and reduces
sstable sharing.
2015-08-03 20:17:40 +03:00

42 lines
1.2 KiB
C++

/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
#include "byte_ordered_partitioner.hh"
#include "utils/class_registrator.hh"
namespace dht {
token byte_ordered_partitioner::get_random_token()
{
bytes b(bytes::initialized_later(), 16);
*unaligned_cast<uint64_t>(b.begin()) = dht::get_random_number<uint64_t>();
*unaligned_cast<uint64_t>(b.begin() + 8) = dht::get_random_number<uint64_t>();
return token(token::kind::key, std::move(b));
}
std::map<token, float> byte_ordered_partitioner::describe_ownership(const std::vector<token>& sorted_tokens)
{
throw std::runtime_error("not implemented");
}
token byte_ordered_partitioner::midpoint(const token& t1, const token& t2) const
{
throw std::runtime_error("not implemented");
}
unsigned
byte_ordered_partitioner::shard_of(const token& t) const {
if (t._data.empty()) {
return 0;
}
// treat first byte as a fraction in the range [0, 1) and divide it evenly:
return (uint8_t(t._data[0]) * smp::count) >> 8;
}
using registry = class_registrator<i_partitioner, byte_ordered_partitioner>;
static registry registrator("org.apache.cassandra.dht.ByteOrderedPartitioner");
static registry registrator_short_name("ByteOrderedPartitioner");
}