@@ -1011,8 +1011,6 @@ void PostgreSQL::heartbeat()
1011
1011
int64_t ts = OSUtils::now ();
1012
1012
1013
1013
if (c->c ) {
1014
- pqxx::work w{*c->c };
1015
-
1016
1014
std::string major = std::to_string (ZEROTIER_ONE_VERSION_MAJOR);
1017
1015
std::string minor = std::to_string (ZEROTIER_ONE_VERSION_MINOR);
1018
1016
std::string rev = std::to_string (ZEROTIER_ONE_VERSION_REVISION);
@@ -1023,21 +1021,25 @@ void PostgreSQL::heartbeat()
1023
1021
std::string redis_mem_status = (_redisMemberStatus) ? " true" : " false" ;
1024
1022
1025
1023
try {
1026
- 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) "
1027
- " VALUES (" +w.quote (controllerId)+" , " +w.quote (hostname)+" , TO_TIMESTAMP(" +now+" ::double precision/1000), " +
1028
- w.quote (publicIdentity)+" , " +major+" , " +minor+" , " +rev+" , " +build+" , " +host_port+" , " +use_redis+" , " +redis_mem_status+" ) "
1029
- " ON CONFLICT (id) DO UPDATE SET cluster_host = EXCLUDED.cluster_host, last_alive = EXCLUDED.last_alive, "
1030
- " public_identity = EXCLUDED.public_identity, v_major = EXCLUDED.v_major, v_minor = EXCLUDED.v_minor, "
1031
- " v_rev = EXCLUDED.v_rev, v_build = EXCLUDED.v_rev, host_port = EXCLUDED.host_port, "
1032
- " use_redis = EXCLUDED.use_redis, redis_member_status = EXCLUDED.redis_member_status" );
1024
+ pqxx::work w{*c->c };
1025
+
1026
+ pqxx::result res =
1027
+ 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) "
1028
+ " VALUES (" +w.quote (controllerId)+" , " +w.quote (hostname)+" , TO_TIMESTAMP(" +now+" ::double precision/1000), " +
1029
+ w.quote (publicIdentity)+" , " +major+" , " +minor+" , " +rev+" , " +build+" , " +host_port+" , " +use_redis+" , " +redis_mem_status+" ) "
1030
+ " ON CONFLICT (id) DO UPDATE SET cluster_host = EXCLUDED.cluster_host, last_alive = EXCLUDED.last_alive, "
1031
+ " public_identity = EXCLUDED.public_identity, v_major = EXCLUDED.v_major, v_minor = EXCLUDED.v_minor, "
1032
+ " v_rev = EXCLUDED.v_rev, v_build = EXCLUDED.v_rev, host_port = EXCLUDED.host_port, "
1033
+ " use_redis = EXCLUDED.use_redis, redis_member_status = EXCLUDED.redis_member_status" );
1034
+ w.commit ();
1033
1035
} catch (std::exception &e) {
1034
- fprintf (stderr, " Heartbeat update failed: %s\n " , e.what ());
1036
+ fprintf (stderr, " %s: Heartbeat update failed: %s\n " , controllerId , e.what ());
1035
1037
w.abort ();
1036
1038
_pool->unborrow (c);
1037
1039
std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
1038
1040
continue ;
1039
- }
1040
- w. commit ();
1041
+ }
1042
+
1041
1043
}
1042
1044
_pool->unborrow (c);
1043
1045
0 commit comments