Skip to content

Commit c0978e8

Browse files
authored
Merge pull request #942 from 00k/master
issue=#941 bugfix of cookie file name
2 parents 8d8391b + 1bf1d33 commit c0978e8

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/sdk/sdk_zk.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ std::string ClusterFinder::RootTableAddr(bool update) {
5454
return _root_table_addr;
5555
}
5656

57+
std::string ClusterFinder::ClusterId() {
58+
std::string name = Name();
59+
std::string authority = Authority();
60+
std::string path = Path();
61+
if (name.empty() || authority.empty() || path.empty()) {
62+
LOG(FATAL) << "cluster name/authority/path must be non-empty";
63+
}
64+
std::string cluster_id = name + "://" + authority;
65+
if (path[0] != '/') {
66+
cluster_id += "/";
67+
}
68+
cluster_id += path;
69+
return cluster_id;
70+
}
71+
5772
ZkClusterFinder::ZkClusterFinder(const std::string& zk_root_path,
5873
const std::string& zk_addr_list)
5974
: _zk_root_path(zk_root_path), _zk_addr_list(zk_addr_list) {

src/sdk/sdk_zk.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ class ClusterFinder
1919
virtual ~ClusterFinder() {}
2020
std::string MasterAddr(bool update = false);
2121
std::string RootTableAddr(bool update = false);
22+
std::string ClusterId(); // cluster URI: <scheme>://<authority>/<path>
2223

2324
private:
2425
virtual bool ReadNode(const std::string& path, std::string* value) = 0;
26+
virtual std::string Name() = 0;
27+
virtual std::string Authority() = 0;
28+
virtual std::string Path() = 0;
2529

2630
mutable Mutex _mutex;
2731
std::string _master_addr;
@@ -33,6 +37,9 @@ class ZkClusterFinder : public ClusterFinder {
3337
ZkClusterFinder(const std::string& zk_root_path, const std::string& zk_addr_list);
3438
private:
3539
virtual bool ReadNode(const std::string& path, std::string* value);
40+
virtual std::string Name() { return "zk"; };
41+
virtual std::string Authority() { return _zk_addr_list; }
42+
virtual std::string Path() { return _zk_root_path; }
3643
std::string _zk_root_path;
3744
std::string _zk_addr_list;
3845
};
@@ -42,6 +49,9 @@ class InsClusterFinder : public ClusterFinder {
4249
InsClusterFinder(const std::string& ins_root_path, const std::string& ins_addr_list);
4350
private:
4451
virtual bool ReadNode(const std::string& path, std::string* value);
52+
virtual std::string Name() { return "ins"; };
53+
virtual std::string Authority() { return _ins_addr_list; }
54+
virtual std::string Path() { return _ins_root_path; }
4555
std::string _ins_root_path;
4656
std::string _ins_addr_list;
4757
};
@@ -51,6 +61,9 @@ class FakeZkClusterFinder : public ClusterFinder {
5161
FakeZkClusterFinder(const std::string& fake_zk_path_prefix);
5262
private:
5363
virtual bool ReadNode(const std::string& path, std::string* value);
64+
virtual std::string Name() { return "fakezk"; };
65+
virtual std::string Authority() { return "localhost"; }
66+
virtual std::string Path() { return _fake_zk_path_prefix; }
5467
std::string _fake_zk_path_prefix;
5568
};
5669

src/sdk/table_impl.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ bool TableImpl::OpenInternal(ErrorCode* err) {
461461
if (FLAGS_tera_sdk_perf_counter_enabled) {
462462
DumpPerfCounterLogDelay();
463463
}
464+
LOG(INFO) << "open table " << _name << " at cluster " << _cluster->ClusterId();
464465
return true;
465466
}
466467

@@ -1861,7 +1862,7 @@ bool TableImpl::RestoreCookie() {
18611862

18621863
std::string TableImpl::GetCookieFilePathName(void) {
18631864
return FLAGS_tera_sdk_cookie_path + "/"
1864-
+ GetCookieFileName(_name, _zk_addr_list, _zk_root_path, _create_time);
1865+
+ GetCookieFileName(_name, _cluster->ClusterId(), _create_time);
18651866
}
18661867

18671868
std::string TableImpl::GetCookieLockFilePathName(void) {
@@ -1902,12 +1903,10 @@ void TableImpl::EnableCookieUpdateTimer() {
19021903
}
19031904

19041905
std::string TableImpl::GetCookieFileName(const std::string& tablename,
1905-
const std::string& zk_addr,
1906-
const std::string& zk_path,
1906+
const std::string& cluster_id,
19071907
int64_t create_time) {
19081908
uint32_t hash = 0;
1909-
if (GetHashNumber(zk_addr, hash, &hash) != 0
1910-
|| GetHashNumber(zk_path, hash, &hash) != 0) {
1909+
if (GetHashNumber(cluster_id, hash, &hash) != 0) {
19111910
LOG(FATAL) << "invalid arguments";
19121911
}
19131912
char hash_str[9] = {'\0'};

src/sdk/table_impl.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ class TableImpl : public Table {
363363
void DumpCookie();
364364
void DoDumpCookie();
365365
std::string GetCookieFileName(const std::string& tablename,
366-
const std::string& zk_addr,
367-
const std::string& zk_path,
366+
const std::string& cluster_id,
368367
int64_t create_time);
369368
std::string GetCookieFilePathName();
370369
std::string GetCookieLockFilePathName();
@@ -429,9 +428,6 @@ class TableImpl : public Table {
429428
master::MasterClient* _master_client;
430429
tabletnode::TabletNodeClient* _tabletnode_client;
431430

432-
std::string _zk_root_path;
433-
std::string _zk_addr_list;
434-
435431
ThreadPool* _thread_pool;
436432
mutable Mutex _delay_task_id_mutex;
437433
std::set<int64_t> _delay_task_ids;

0 commit comments

Comments
 (0)