mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Return error 503 if RethinkDB is down when built as RethinkDB-based controller.
This commit is contained in:
parent
37ae3b2b80
commit
f94aea8119
6 changed files with 20 additions and 12 deletions
|
@ -82,6 +82,7 @@ public:
|
||||||
virtual ~DB();
|
virtual ~DB();
|
||||||
|
|
||||||
virtual bool waitForReady() = 0;
|
virtual bool waitForReady() = 0;
|
||||||
|
virtual bool isReady() = 0;
|
||||||
|
|
||||||
inline bool hasNetwork(const uint64_t networkId) const
|
inline bool hasNetwork(const uint64_t networkId) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -596,10 +596,11 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
||||||
// Controller status
|
// Controller status
|
||||||
|
|
||||||
char tmp[4096];
|
char tmp[4096];
|
||||||
OSUtils::ztsnprintf(tmp,sizeof(tmp),"{\n\t\"controller\": true,\n\t\"apiVersion\": %d,\n\t\"clock\": %llu\n}\n",ZT_NETCONF_CONTROLLER_API_VERSION,(unsigned long long)OSUtils::now());
|
const bool dbOk = _db->isReady();
|
||||||
|
OSUtils::ztsnprintf(tmp,sizeof(tmp),"{\n\t\"controller\": true,\n\t\"apiVersion\": %d,\n\t\"clock\": %llu,\n\t\"databaseReady\": %s\n}\n",ZT_NETCONF_CONTROLLER_API_VERSION,(unsigned long long)OSUtils::now(),dbOk ? "true" : "false");
|
||||||
responseBody = tmp;
|
responseBody = tmp;
|
||||||
responseContentType = "application/json";
|
responseContentType = "application/json";
|
||||||
return 200;
|
return dbOk ? 200 : 503;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,14 +63,10 @@ FileDB::FileDB(EmbeddedNetworkController *const nc,const Identity &myId,const ch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDB::~FileDB()
|
FileDB::~FileDB() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileDB::waitForReady()
|
bool FileDB::waitForReady() { return true; }
|
||||||
{
|
bool FileDB::isReady() { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileDB::save(nlohmann::json *orig,nlohmann::json &record)
|
void FileDB::save(nlohmann::json *orig,nlohmann::json &record)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual ~FileDB();
|
virtual ~FileDB();
|
||||||
|
|
||||||
virtual bool waitForReady();
|
virtual bool waitForReady();
|
||||||
|
virtual bool isReady();
|
||||||
virtual void save(nlohmann::json *orig,nlohmann::json &record);
|
virtual void save(nlohmann::json *orig,nlohmann::json &record);
|
||||||
virtual void eraseNetwork(const uint64_t networkId);
|
virtual void eraseNetwork(const uint64_t networkId);
|
||||||
virtual void eraseMember(const uint64_t networkId,const uint64_t memberId);
|
virtual void eraseMember(const uint64_t networkId,const uint64_t memberId);
|
||||||
|
|
|
@ -263,9 +263,13 @@ RethinkDB::RethinkDB(EmbeddedNetworkController *const nc,const Identity &myId,co
|
||||||
std::unique_ptr<R::Connection> rdb;
|
std::unique_ptr<R::Connection> rdb;
|
||||||
while (_run == 1) {
|
while (_run == 1) {
|
||||||
try {
|
try {
|
||||||
if (!rdb)
|
if (!rdb) {
|
||||||
|
_connected = 0;
|
||||||
rdb = R::connect(this->_host,this->_port,this->_auth);
|
rdb = R::connect(this->_host,this->_port,this->_auth);
|
||||||
|
}
|
||||||
|
|
||||||
if (rdb) {
|
if (rdb) {
|
||||||
|
_connected = 1;
|
||||||
R::Array batch;
|
R::Array batch;
|
||||||
R::Object tmpobj;
|
R::Object tmpobj;
|
||||||
|
|
||||||
|
@ -434,6 +438,11 @@ bool RethinkDB::waitForReady()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RethinkDB::isReady()
|
||||||
|
{
|
||||||
|
return ((_ready)&&(_connected));
|
||||||
|
}
|
||||||
|
|
||||||
void RethinkDB::save(nlohmann::json *orig,nlohmann::json &record)
|
void RethinkDB::save(nlohmann::json *orig,nlohmann::json &record)
|
||||||
{
|
{
|
||||||
if (!record.is_object()) // sanity check
|
if (!record.is_object()) // sanity check
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
virtual ~RethinkDB();
|
virtual ~RethinkDB();
|
||||||
|
|
||||||
virtual bool waitForReady();
|
virtual bool waitForReady();
|
||||||
|
virtual bool isReady();
|
||||||
virtual void save(nlohmann::json *orig,nlohmann::json &record);
|
virtual void save(nlohmann::json *orig,nlohmann::json &record);
|
||||||
virtual void eraseNetwork(const uint64_t networkId);
|
virtual void eraseNetwork(const uint64_t networkId);
|
||||||
virtual void eraseMember(const uint64_t networkId,const uint64_t memberId);
|
virtual void eraseMember(const uint64_t networkId,const uint64_t memberId);
|
||||||
|
@ -72,8 +73,7 @@ protected:
|
||||||
std::thread _heartbeatThread;
|
std::thread _heartbeatThread;
|
||||||
|
|
||||||
mutable std::mutex _readyLock; // locked until ready
|
mutable std::mutex _readyLock; // locked until ready
|
||||||
std::atomic<int> _ready;
|
std::atomic<int> _ready,_connected,_run;
|
||||||
std::atomic<int> _run;
|
|
||||||
mutable volatile bool _waitNoticePrinted;
|
mutable volatile bool _waitNoticePrinted;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue