mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-20 17:52:46 +00: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
@ -159,6 +159,7 @@ struct NetworkRecord {
|
||||
SqliteNetworkController::SqliteNetworkController(Node *node,const char *dbPath,const char *circuitTestPath) :
|
||||
_node(node),
|
||||
_backupThreadRun(true),
|
||||
_backupNeeded(true),
|
||||
_dbPath(dbPath),
|
||||
_circuitTestPath(circuitTestPath),
|
||||
_db((sqlite3 *)0)
|
||||
@ -445,6 +446,8 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
|
||||
return 404;
|
||||
Mutex::Lock _l(_lock);
|
||||
|
||||
_backupNeeded = true;
|
||||
|
||||
if (path[0] == "network") {
|
||||
|
||||
if ((path.size() >= 2)&&(path[1].length() == 16)) {
|
||||
@ -1042,6 +1045,8 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpDELETE(
|
||||
return 404;
|
||||
Mutex::Lock _l(_lock);
|
||||
|
||||
_backupNeeded = true;
|
||||
|
||||
if (path[0] == "network") {
|
||||
|
||||
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();
|
||||
|
||||
char backupPath[4096],backupPath2[4096];
|
||||
@ -1169,6 +1174,8 @@ void SqliteNetworkController::threadMain()
|
||||
|
||||
OSUtils::rm(backupPath2);
|
||||
::rename(backupPath,backupPath2);
|
||||
|
||||
_backupNeeded = false;
|
||||
}
|
||||
|
||||
Thread::sleep(250);
|
||||
@ -1634,6 +1641,8 @@ NetworkController::ResultCode SqliteNetworkController::_doNetworkConfigRequest(c
|
||||
lrt = now;
|
||||
}
|
||||
|
||||
_backupNeeded = true;
|
||||
|
||||
NetworkRecord network;
|
||||
memset(&network,0,sizeof(network));
|
||||
Utils::snprintf(network.id,sizeof(network.id),"%.16llx",(unsigned long long)nwid);
|
||||
|
@ -121,6 +121,7 @@ private:
|
||||
Node *_node;
|
||||
Thread _backupThread;
|
||||
volatile bool _backupThreadRun;
|
||||
volatile bool _backupNeeded;
|
||||
std::string _dbPath;
|
||||
std::string _circuitTestPath;
|
||||
std::string _instanceId;
|
||||
|
Loading…
x
Reference in New Issue
Block a user