Skip to content

Commit

Permalink
issue=baidu#1271 Add mock zk adapter for test
Browse files Browse the repository at this point in the history
  • Loading branch information
yangce committed May 22, 2017
1 parent b65f535 commit 1bca282
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/master/master_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ DECLARE_string(tera_zk_root_path);
DECLARE_string(tera_zk_addr_list);
DECLARE_string(tera_local_addr);
DECLARE_bool(tera_ins_enabled);
DECLARE_bool(tera_mock_ins_enabled);

DECLARE_int64(tera_sdk_perf_counter_log_interval);

Expand Down Expand Up @@ -169,6 +170,9 @@ bool MasterImpl::Init() {
} else if (FLAGS_tera_ins_enabled) {
LOG(INFO) << "ins mode" ;
zk_adapter_.reset(new InsMasterZkAdapter(this, local_addr_));
} else if (FLAGS_tera_mock_ins_enabled) {
LOG(INFO) << "mock ins mode" ;
zk_adapter_.reset(new MockInsMasterZkAdapter(this, local_addr_));
} else {
LOG(INFO) << "fake zk mode!";
zk_adapter_.reset(new FakeMasterZkAdapter(this, local_addr_));
Expand Down
7 changes: 7 additions & 0 deletions src/master/master_zk_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ class InsMasterZkAdapter: public MasterZkAdapterBase {
galaxy::ins::sdk::InsSDK* ins_sdk_;
};

class MockInsMasterZkAdapter : public InsMasterZkAdapter {
public:
MockInsMasterZkAdapter(MasterImpl* master_impl, const std::string& server_addr) :
InsMasterZkAdapter(master_impl, server_addr) {}
virtual ~MockInsMasterZkAdapter() {}
};

} // namespace master
} // namespace tera

Expand Down
3 changes: 3 additions & 0 deletions src/sdk/sdk_zk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DECLARE_string(tera_zk_root_path);
DECLARE_bool(tera_ins_enabled);
DECLARE_string(tera_ins_root_path);
DECLARE_string(tera_ins_addr_list);
DECLARE_bool(tera_mock_ins_enabled);

namespace tera {
namespace sdk {
Expand Down Expand Up @@ -123,6 +124,8 @@ bool FakeZkClusterFinder::ReadNode(const std::string& name, std::string* value)
ClusterFinder* NewClusterFinder() {
if (FLAGS_tera_ins_enabled) {
return new sdk::InsClusterFinder(FLAGS_tera_ins_root_path, FLAGS_tera_ins_addr_list);
} else if (FLAGS_tera_mock_ins_enabled) {
return new sdk::MockInsClusterFinder(FLAGS_tera_ins_root_path, FLAGS_tera_ins_addr_list);
} else if (!FLAGS_tera_zk_enabled) {
return new sdk::FakeZkClusterFinder(FLAGS_tera_fake_zk_path_prefix);
} else {
Expand Down
22 changes: 17 additions & 5 deletions src/sdk/sdk_zk.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class ClusterFinder
std::string RootTableAddr(bool update = false);
std::string ClusterId(); // cluster URI: <scheme>://<authority>/<path>

private:
protected:
virtual bool ReadNode(const std::string& path, std::string* value) = 0;
virtual std::string Name() = 0;
virtual std::string Authority() = 0;
virtual std::string Path() = 0;

private:
mutable Mutex mutex_;
std::string master_addr_;
std::string root_table_addr_;
Expand All @@ -35,35 +36,46 @@ class ClusterFinder
class ZkClusterFinder : public ClusterFinder {
public:
ZkClusterFinder(const std::string& zk_root_path, const std::string& zk_addr_list);
private:
protected:
virtual bool ReadNode(const std::string& path, std::string* value);
virtual std::string Name() { return "zk"; };
virtual std::string Authority() { return zk_addr_list_; }
virtual std::string Path() { return zk_root_path_; }
private:
std::string zk_root_path_;
std::string zk_addr_list_;
};

class InsClusterFinder : public ClusterFinder {
public:
InsClusterFinder(const std::string& ins_root_path, const std::string& ins_addr_list);
private:
protected:
virtual bool ReadNode(const std::string& path, std::string* value);
virtual std::string Name() { return "ins"; };
virtual std::string Name() { return "ins"; }
virtual std::string Authority() { return ins_addr_list_; }
virtual std::string Path() { return ins_root_path_; }
private:
std::string ins_root_path_;
std::string ins_addr_list_;
};

class MockInsClusterFinder : public InsClusterFinder {
public:
MockInsClusterFinder(const std::string& ins_root_path, const std::string& ins_addr_list) :
InsClusterFinder(ins_root_path, ins_addr_list) {}
protected:
virtual std::string Name() { return "mock ins"; }
};

class FakeZkClusterFinder : public ClusterFinder {
public:
FakeZkClusterFinder(const std::string& fake_zk_path_prefix);
private:
protected:
virtual bool ReadNode(const std::string& path, std::string* value);
virtual std::string Name() { return "fakezk"; };
virtual std::string Authority() { return "localhost"; }
virtual std::string Path() { return fake_zk_path_prefix_; }
private:
std::string fake_zk_path_prefix_;
};

Expand Down
4 changes: 4 additions & 0 deletions src/tabletnode/tabletnode_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ DECLARE_int32(tera_tabletnode_gc_log_level);
DECLARE_string(tera_leveldb_env_type);
DECLARE_string(tera_local_addr);
DECLARE_bool(tera_ins_enabled);
DECLARE_bool(tera_mock_ins_enabled);

DECLARE_bool(tera_io_cache_path_vanish_allowed);
DECLARE_int64(tera_tabletnode_tcm_cache_size);
Expand Down Expand Up @@ -160,6 +161,9 @@ bool TabletNodeImpl::Init() {
} else if(FLAGS_tera_ins_enabled) {
LOG(INFO) << "ins mode!";
zk_adapter_.reset(new InsTabletNodeZkAdapter(this, local_addr_));
} else if (FLAGS_tera_mock_ins_enabled) {
LOG(INFO) << "mock ins mode!";
zk_adapter_.reset(new MockInsTabletNodeZkAdapter(this, local_addr_));
} else {
LOG(INFO) << "fake zk mode!";
zk_adapter_.reset(new FakeTabletNodeZkAdapter(this, local_addr_));
Expand Down
14 changes: 12 additions & 2 deletions src/tabletnode/tabletnode_zk_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class InsTabletNodeZkAdapter : public TabletNodeZkAdapterBase {
virtual ~InsTabletNodeZkAdapter() {}
virtual void Init();
virtual bool GetRootTableAddr(std::string* root_table_addr);
void OnKickMarkCreated();
void OnLockChange(std::string session_id, bool deleted);
virtual void OnKickMarkCreated();
virtual void OnLockChange(std::string session_id, bool deleted);
void OnMetaChange(std::string meta_addr, bool deleted);
private:
virtual void OnChildrenChanged(const std::string& path,
Expand All @@ -132,6 +132,16 @@ class InsTabletNodeZkAdapter : public TabletNodeZkAdapterBase {
galaxy::ins::sdk::InsSDK* ins_sdk_;
};

class MockInsTabletNodeZkAdapter : public InsTabletNodeZkAdapter {
public:
MockInsTabletNodeZkAdapter(TabletNodeImpl* tabletnode_impl,
const std::string& server_addr) :
InsTabletNodeZkAdapter(tabletnode_impl, server_addr) {}
virtual ~MockInsTabletNodeZkAdapter() {}
virtual void OnKickMarkCreated() {}
virtual void OnLockChange(std::string /*session_id*/, bool /*deleted*/) {}
};

} // namespace tabletnode
} // namespace tera

Expand Down
1 change: 1 addition & 0 deletions src/tera_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ DEFINE_int64(batch_scan_delay_retry_in_us, 1000000, "timewait in us before retry
DEFINE_string(tera_ins_addr_list, "", "the ins cluster addr. e.g. abc.com:1234,abb.com:1234");
DEFINE_string(tera_ins_root_path, "", "root path on ins. e.g /ps/sandbox");
DEFINE_bool(tera_ins_enabled, false, "option to open ins naming");
DEFINE_bool(tera_mock_ins_enabled, false, "option to open mock ins naming");

DEFINE_int64(tera_sdk_status_timeout, 600, "(s) check tablet/tabletnode status timeout");

Expand Down

0 comments on commit 1bca282

Please sign in to comment.