Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get label key/value from config file #45

Merged
merged 7 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion contrib/client-c/include/tikv/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ using RPCContextPtr = std::shared_ptr<RPCContext>;

class RegionCache {
public:
RegionCache(pd::ClientPtr pdClient_) : pdClient(pdClient_), log(&Logger::get("pingcap.tikv")) {
RegionCache(pd::ClientPtr pdClient_, std::string key_, std::string value_) : pdClient(pdClient_), learner_key(key_), learner_value(value_), log(&Logger::get("pingcap.tikv")) {
}

RPCContextPtr getRPCContext(Backoffer & bo, const RegionVerID & id, bool is_learner);
Expand Down Expand Up @@ -175,6 +175,10 @@ class RegionCache {

std::mutex store_mutex;

std::string learner_key;

std::string learner_value;

Logger * log;
};

Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/src/test/get_region_id_wrong_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool testReadIndex () {
::sleep(1);

pd::ClientPtr clt = std::make_shared<pd::Client>(addrs);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt, "zone", "engine");
kv::RpcClientPtr rpc = std::make_shared<kv::RpcClient>();
kv::RegionClient client(cache, rpc, verID);
int idx = client.getReadIndex();
Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/src/test/get_store_id_wrong_2_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool testReadIndex () {
::sleep(1);

pd::ClientPtr clt = std::make_shared<pd::Client>(addrs);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt, "zone", "engine");
kv::RpcClientPtr rpc = std::make_shared<kv::RpcClient>();
kv::RegionClient client(cache, rpc, verID);
if( 5 != client.getReadIndex()) {
Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/src/test/get_store_id_wrong_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool testReadIndex () {
::sleep(1);

pd::ClientPtr clt = std::make_shared<pd::Client>(addrs);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt, "zone", "engine");
kv::RpcClientPtr rpc = std::make_shared<kv::RpcClient>();
kv::RegionClient client(cache, rpc, verID);
int idx = client.getReadIndex();
Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/src/test/grpc_error_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool testReadIndex () {
::sleep(1);

pd::ClientPtr clt = std::make_shared<pd::Client>(addrs);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt, "zone", "engine");
kv::RpcClientPtr rpc = std::make_shared<kv::RpcClient>();
kv::RegionClient client(cache, rpc, verID);
int idx = client.getReadIndex();
Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/src/test/read_index_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool testReadIndex () {

::sleep(1);
pd::ClientPtr clt = std::make_shared<pd::Client>(addrs);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt);
kv::RegionCachePtr cache = std::make_shared<kv::RegionCache>(clt, "zone", "engine");
kv::RpcClientPtr rpc = std::make_shared<kv::RpcClient>();
kv::RegionClient client(cache, rpc, verID);
int idx = client.getReadIndex();
Expand Down
2 changes: 1 addition & 1 deletion contrib/client-c/src/tikv/Region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ metapb::Peer RegionCache::selectLearner(Backoffer & bo, const std::vector<metapb
for (auto slave : slaves) {
auto store_id = slave.store_id();
auto labels = getStore(bo, store_id).labels;
if (labels["zone"] == "engine") {
if (labels[learner_key] == learner_value) {
return slave;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ TMTContext & Context::getTMTContext()
{
auto lock = getLock();
if (!shared->tmt_context)
shared->tmt_context = std::make_shared<TMTContext>(*this, pd_addrs);
shared->tmt_context = std::make_shared<TMTContext>(*this, pd_addrs, learner_key, learner_value);
return *(shared->tmt_context);
}

Expand Down
12 changes: 12 additions & 0 deletions dbms/src/Interpreters/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ class Context
pd_addrs = std::move(addrs_);
}

void setLearnerKey(std::string key_) {
learner_key = key_;
}

void setLearnerValue(std::string value_) {
learner_value = value_;
}

BackgroundProcessingPool & getBackgroundPool();

void setDDLWorker(std::shared_ptr<DDLWorker> ddl_worker);
Expand Down Expand Up @@ -447,6 +455,10 @@ class Context
void scheduleCloseSession(const SessionKey & key, std::chrono::steady_clock::duration timeout);

std::vector<String> pd_addrs;

std::string learner_key;

std::string learner_value;
};


Expand Down
15 changes: 15 additions & 0 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ int Server::main(const std::vector<std::string> & /*args*/)
} else {
LOG_INFO(log, "Not found pd addrs.");
}

if (config().has("raft.learner_key"))
{
String learner_key = config().getString("raft.learner_key");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we have different format of conf key? it seems all others are xx_yy_zz style.

global_context->setLearnerKey(learner_key);
} else {
global_context->setLearnerKey("zone");
}
if (config().has("raft.learner_value"))
{
String learner_value = config().getString("raft.learner_value");
global_context->setLearnerValue(learner_value);
} else {
global_context->setLearnerKey("engine");
}
global_context->initializeRaftService(raft_service_addr);
}
if (config().has("tidb"))
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/Transaction/TMTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
namespace DB
{

TMTContext::TMTContext(Context & context, std::vector<String> addrs)
TMTContext::TMTContext(Context & context, std::vector<String> addrs, std::string learner_key_, std::string learner_value_)
: kvstore(std::make_shared<KVStore>(context.getPath() + "kvstore/")),
region_table(context, context.getPath() + "regmap/"),
schema_syncer(std::make_shared<HttpJsonSchemaSyncer>()),
pd_client(addrs.size() == 0 ? static_cast<pingcap::pd::IClient *>(new pingcap::pd::MockPDClient())
: static_cast<pingcap::pd::IClient *>(new pingcap::pd::Client(addrs))),
region_cache(std::make_shared<pingcap::kv::RegionCache>(pd_client)),
region_cache(std::make_shared<pingcap::kv::RegionCache>(pd_client, learner_key_, learner_value_)),
rpc_client(std::make_shared<pingcap::kv::RpcClient>())
{
kvstore->restore(
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/Transaction/TMTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TMTContext

public:
// TODO: get flusher args from config file
explicit TMTContext(Context & context_, std::vector<String> addrs);
explicit TMTContext(Context & context_, std::vector<String> addrs, std::string learner_key_, std::string learner_value_);

SchemaSyncerPtr getSchemaSyncer() const;
void setSchemaSyncer(SchemaSyncerPtr);
Expand Down