mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-27 06:20:11 +00:00
logging & redis standalone fix
This commit is contained in:
parent
9de863e68b
commit
355d3f44fb
@ -515,13 +515,16 @@ void PostgreSQL::initializeNetworks()
|
|||||||
fprintf(stderr, "Initializing Networks...\n");
|
fprintf(stderr, "Initializing Networks...\n");
|
||||||
|
|
||||||
if (_redisMemberStatus) {
|
if (_redisMemberStatus) {
|
||||||
|
fprintf(stderr, "Init Redis for networks...\n");
|
||||||
try {
|
try {
|
||||||
if (_rc->clusterMode) {
|
if (_rc->clusterMode) {
|
||||||
_cluster->del(setKey);
|
_cluster->del(setKey);
|
||||||
} else {
|
} else {
|
||||||
_redis->del(setKey);
|
_redis->del(setKey);
|
||||||
}
|
}
|
||||||
} catch (...) {}
|
} catch (sw::redis::Error &e) {
|
||||||
|
// ignore. if this key doesn't exist, there's no reason to delete it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_set<std::string> networkSet;
|
std::unordered_set<std::string> networkSet;
|
||||||
@ -543,6 +546,7 @@ void PostgreSQL::initializeNetworks()
|
|||||||
auto c2 = _pool->borrow();
|
auto c2 = _pool->borrow();
|
||||||
pqxx::work w{*c->c};
|
pqxx::work w{*c->c};
|
||||||
|
|
||||||
|
fprintf(stderr, "Load networks from psql...\n");
|
||||||
auto stream = pqxx::stream_from::query(w, qbuf);
|
auto stream = pqxx::stream_from::query(w, qbuf);
|
||||||
|
|
||||||
std::tuple<
|
std::tuple<
|
||||||
@ -695,18 +699,21 @@ void PostgreSQL::initializeNetworks()
|
|||||||
w.commit();
|
w.commit();
|
||||||
_pool->unborrow(c2);
|
_pool->unborrow(c2);
|
||||||
_pool->unborrow(c);
|
_pool->unborrow(c);
|
||||||
|
fprintf(stderr, "done.\n");
|
||||||
|
|
||||||
if (!networkSet.empty()) {
|
if (!networkSet.empty()) {
|
||||||
if (_redisMemberStatus) {
|
if (_redisMemberStatus) {
|
||||||
|
fprintf(stderr, "adding networks to redis...\n");
|
||||||
if (_rc->clusterMode) {
|
if (_rc->clusterMode) {
|
||||||
auto tx = _cluster->transaction(_myAddressStr, true);
|
auto tx = _cluster->transaction(_myAddressStr, true);
|
||||||
tx.sadd(setKey, networkSet.begin(), networkSet.end());
|
tx.sadd(setKey, networkSet.begin(), networkSet.end());
|
||||||
tx.exec();
|
tx.exec();
|
||||||
} else {
|
} else {
|
||||||
auto tx = _cluster->transaction(_myAddressStr, true);
|
auto tx = _redis->transaction(true);
|
||||||
tx.sadd(setKey, networkSet.begin(), networkSet.end());
|
tx.sadd(setKey, networkSet.begin(), networkSet.end());
|
||||||
tx.exec();
|
tx.exec();
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "done.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,11 +723,14 @@ void PostgreSQL::initializeNetworks()
|
|||||||
}
|
}
|
||||||
_readyLock.unlock();
|
_readyLock.unlock();
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "network init done.\n");
|
||||||
} catch (sw::redis::Error &e) {
|
} catch (sw::redis::Error &e) {
|
||||||
fprintf(stderr, "ERROR: Error initializing networks in Redis: %s\n", e.what());
|
fprintf(stderr, "ERROR: Error initializing networks in Redis: %s\n", e.what());
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
exit(-1);
|
exit(-1);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
fprintf(stderr, "ERROR: Error initializing networks: %s\n", e.what());
|
fprintf(stderr, "ERROR: Error initializing networks: %s\n", e.what());
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -736,6 +746,7 @@ void PostgreSQL::initializeMembers()
|
|||||||
std::string setKeyBase = "network-nodes-all:{" + _myAddressStr + "}:";
|
std::string setKeyBase = "network-nodes-all:{" + _myAddressStr + "}:";
|
||||||
|
|
||||||
if (_redisMemberStatus) {
|
if (_redisMemberStatus) {
|
||||||
|
fprintf(stderr, "Initialize Redis for members...\n");
|
||||||
std::lock_guard<std::mutex> l(_networks_l);
|
std::lock_guard<std::mutex> l(_networks_l);
|
||||||
std::unordered_set<std::string> deletes;
|
std::unordered_set<std::string> deletes;
|
||||||
for ( auto it : _networks) {
|
for ( auto it : _networks) {
|
||||||
@ -762,7 +773,9 @@ void PostgreSQL::initializeMembers()
|
|||||||
}
|
}
|
||||||
tx.exec();
|
tx.exec();
|
||||||
}
|
}
|
||||||
} catch (...) {}
|
} catch (sw::redis::Error &e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,6 +800,7 @@ void PostgreSQL::initializeMembers()
|
|||||||
auto c2 = _pool->borrow();
|
auto c2 = _pool->borrow();
|
||||||
pqxx::work w{*c->c};
|
pqxx::work w{*c->c};
|
||||||
|
|
||||||
|
fprintf(stderr, "Load members from psql...\n");
|
||||||
auto stream = pqxx::stream_from::query(w, qbuf);
|
auto stream = pqxx::stream_from::query(w, qbuf);
|
||||||
|
|
||||||
std::tuple<
|
std::tuple<
|
||||||
@ -901,9 +915,11 @@ void PostgreSQL::initializeMembers()
|
|||||||
w.commit();
|
w.commit();
|
||||||
_pool->unborrow(c2);
|
_pool->unborrow(c2);
|
||||||
_pool->unborrow(c);
|
_pool->unborrow(c);
|
||||||
|
fprintf(stderr, "done.\n");
|
||||||
|
|
||||||
if (!networkMembers.empty()) {
|
if (!networkMembers.empty()) {
|
||||||
if (_redisMemberStatus) {
|
if (_redisMemberStatus) {
|
||||||
|
fprintf(stderr, "Load member data into redis...\n");
|
||||||
if (_rc->clusterMode) {
|
if (_rc->clusterMode) {
|
||||||
auto tx = _cluster->transaction(_myAddressStr, true);
|
auto tx = _cluster->transaction(_myAddressStr, true);
|
||||||
for (auto it : networkMembers) {
|
for (auto it : networkMembers) {
|
||||||
@ -917,9 +933,12 @@ void PostgreSQL::initializeMembers()
|
|||||||
}
|
}
|
||||||
tx.exec();
|
tx.exec();
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "done.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Done loading members...\n");
|
||||||
|
|
||||||
if (++this->_ready == 2) {
|
if (++this->_ready == 2) {
|
||||||
if (_waitNoticePrinted) {
|
if (_waitNoticePrinted) {
|
||||||
fprintf(stderr,"[%s] NOTICE: %.10llx controller PostgreSQL data download complete." ZT_EOL_S,_timestr(),(unsigned long long)_myAddress.toInt());
|
fprintf(stderr,"[%s] NOTICE: %.10llx controller PostgreSQL data download complete." ZT_EOL_S,_timestr(),(unsigned long long)_myAddress.toInt());
|
||||||
@ -971,7 +990,7 @@ void PostgreSQL::heartbeat()
|
|||||||
std::string redis_mem_status = (_redisMemberStatus) ? "true" : "false";
|
std::string redis_mem_status = (_redisMemberStatus) ? "true" : "false";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pqxx::result res = w.exec0("INSERT INTO ztc_controller (id, cluster_host, last_alive, public_identity, v_major, v_minor, v_rev, v_build, host_port, use_redis) "
|
pqxx::result res = w.exec0("INSERT INTO ztc_controller (id, cluster_host, last_alive, public_identity, v_major, v_minor, v_rev, v_build, host_port, use_redis, redis_member_status) "
|
||||||
"VALUES ("+w.quote(controllerId)+", "+w.quote(hostname)+", TO_TIMESTAMP("+now+"::double precision/1000), "+
|
"VALUES ("+w.quote(controllerId)+", "+w.quote(hostname)+", TO_TIMESTAMP("+now+"::double precision/1000), "+
|
||||||
w.quote(publicIdentity)+", "+major+", "+minor+", "+rev+", "+build+", "+host_port+", "+use_redis+", "+redis_mem_status+") "
|
w.quote(publicIdentity)+", "+major+", "+minor+", "+rev+", "+build+", "+host_port+", "+use_redis+", "+redis_mem_status+") "
|
||||||
"ON CONFLICT (id) DO UPDATE SET cluster_host = EXCLUDED.cluster_host, last_alive = EXCLUDED.last_alive, "
|
"ON CONFLICT (id) DO UPDATE SET cluster_host = EXCLUDED.cluster_host, last_alive = EXCLUDED.last_alive, "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user