mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Don't back up sqlite db if it hasn't changed to prevent constant thrashing on inactive controllers.
This commit is contained in:
parent
90cdef8400
commit
3740b83f63
2 changed files with 11 additions and 1 deletions
|
@ -159,6 +159,7 @@ struct NetworkRecord {
|
||||||
SqliteNetworkController::SqliteNetworkController(Node *node,const char *dbPath,const char *circuitTestPath) :
|
SqliteNetworkController::SqliteNetworkController(Node *node,const char *dbPath,const char *circuitTestPath) :
|
||||||
_node(node),
|
_node(node),
|
||||||
_backupThreadRun(true),
|
_backupThreadRun(true),
|
||||||
|
_backupNeeded(true),
|
||||||
_dbPath(dbPath),
|
_dbPath(dbPath),
|
||||||
_circuitTestPath(circuitTestPath),
|
_circuitTestPath(circuitTestPath),
|
||||||
_db((sqlite3 *)0)
|
_db((sqlite3 *)0)
|
||||||
|
@ -445,6 +446,8 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||||
return 404;
|
return 404;
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
|
|
||||||
|
_backupNeeded = true;
|
||||||
|
|
||||||
if (path[0] == "network") {
|
if (path[0] == "network") {
|
||||||
|
|
||||||
if ((path.size() >= 2)&&(path[1].length() == 16)) {
|
if ((path.size() >= 2)&&(path[1].length() == 16)) {
|
||||||
|
@ -1042,6 +1045,8 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpDELETE(
|
||||||
return 404;
|
return 404;
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
|
|
||||||
|
_backupNeeded = true;
|
||||||
|
|
||||||
if (path[0] == "network") {
|
if (path[0] == "network") {
|
||||||
|
|
||||||
if ((path.size() >= 2)&&(path[1].length() == 16)) {
|
if ((path.size() >= 2)&&(path[1].length() == 16)) {
|
||||||
|
@ -1126,7 +1131,7 @@ void SqliteNetworkController::threadMain()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((OSUtils::now() - lastBackupTime) >= ZT_NETCONF_BACKUP_PERIOD) {
|
if (((OSUtils::now() - lastBackupTime) >= ZT_NETCONF_BACKUP_PERIOD)&&(_backupNeeded)) {
|
||||||
lastBackupTime = OSUtils::now();
|
lastBackupTime = OSUtils::now();
|
||||||
|
|
||||||
char backupPath[4096],backupPath2[4096];
|
char backupPath[4096],backupPath2[4096];
|
||||||
|
@ -1169,6 +1174,8 @@ void SqliteNetworkController::threadMain()
|
||||||
|
|
||||||
OSUtils::rm(backupPath2);
|
OSUtils::rm(backupPath2);
|
||||||
::rename(backupPath,backupPath2);
|
::rename(backupPath,backupPath2);
|
||||||
|
|
||||||
|
_backupNeeded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::sleep(250);
|
Thread::sleep(250);
|
||||||
|
@ -1634,6 +1641,8 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||||
lrt = now;
|
lrt = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_backupNeeded = true;
|
||||||
|
|
||||||
NetworkRecord network;
|
NetworkRecord network;
|
||||||
memset(&network,0,sizeof(network));
|
memset(&network,0,sizeof(network));
|
||||||
Utils::snprintf(network.id,sizeof(network.id),"%.16llx",(unsigned long long)nwid);
|
Utils::snprintf(network.id,sizeof(network.id),"%.16llx",(unsigned long long)nwid);
|
||||||
|
|
|
@ -121,6 +121,7 @@ private:
|
||||||
Node *_node;
|
Node *_node;
|
||||||
Thread _backupThread;
|
Thread _backupThread;
|
||||||
volatile bool _backupThreadRun;
|
volatile bool _backupThreadRun;
|
||||||
|
volatile bool _backupNeeded;
|
||||||
std::string _dbPath;
|
std::string _dbPath;
|
||||||
std::string _circuitTestPath;
|
std::string _circuitTestPath;
|
||||||
std::string _instanceId;
|
std::string _instanceId;
|
||||||
|
|
Loading…
Add table
Reference in a new issue