Skip to content

Commit

Permalink
storage_service: Remove ad-hoc token_metadata creation
Browse files Browse the repository at this point in the history
Use token_metadata from storage_service when creating a
replication_strategy in keyspace::create_replication_strategy.
  • Loading branch information
asias committed Jun 4, 2015
1 parent f1ed0cd commit a19d217
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
15 changes: 3 additions & 12 deletions database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "frozen_mutation.hh"
#include "mutation_partition_applier.hh"
#include "core/do_with.hh"
#include "service/storage_service.hh"

thread_local logging::logger dblog("database");

Expand Down Expand Up @@ -684,20 +685,10 @@ const column_family& database::find_column_family(const utils::UUID& uuid) const

void
keyspace::create_replication_strategy() {
static thread_local locator::token_metadata tm;
static locator::simple_snitch snitch;
static std::unordered_map<sstring, sstring> options = {{"replication_factor", "3"}};
auto d2t = [](double d) {
unsigned long l = net::hton(static_cast<unsigned long>(d*(std::numeric_limits<unsigned long>::max())));
std::array<int8_t, 8> a;
memcpy(a.data(), &l, 8);
return a;
};
tm.update_normal_token({dht::token::kind::key, {d2t(0).data(), 8}}, to_sstring("127.0.0.1"));
tm.update_normal_token({dht::token::kind::key, {d2t(1.0/4).data(), 8}}, to_sstring("127.0.0.2"));
tm.update_normal_token({dht::token::kind::key, {d2t(2.0/4).data(), 8}}, to_sstring("127.0.0.3"));
tm.update_normal_token({dht::token::kind::key, {d2t(3.0/4).data(), 8}}, to_sstring("127.0.0.4"));
_replication_strategy = locator::abstract_replication_strategy::create_replication_strategy(_metadata->name(), _metadata->strategy_name(), tm, snitch, options);
auto& ss = service::get_local_storage_service();
_replication_strategy = locator::abstract_replication_strategy::create_replication_strategy(_metadata->name(), _metadata->strategy_name(), ss.get_token_metadata(), snitch, options);
}

locator::abstract_replication_strategy&
Expand Down
2 changes: 1 addition & 1 deletion service/storage_service.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class storage_service : public gms::i_endpoint_state_change_subscriber
public:
static int RING_DELAY; // delay after which we assume ring has stablized

const locator::token_metadata& get_token_metadata() const {
locator::token_metadata& get_token_metadata() {
return _token_metadata;
}
private:
Expand Down

0 comments on commit a19d217

Please sign in to comment.