From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:01 +0000 (-0700) Subject: CAF changes to prevent NamespaceDB frequent polling. X-Git-Tag: stable-10.2.0~558 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b0d2f41dcacd2181b36855fa5b2a2b43def8e216;p=thirdparty%2Fopen-vm-tools.git CAF changes to prevent NamespaceDB frequent polling. --- diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.cpp b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.cpp index 2c702c671..7bc2792ba 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.cpp +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.cpp @@ -24,6 +24,12 @@ using namespace Caf; CPersistenceNamespaceDb::CPersistenceNamespaceDb() : _isInitialized(false), _isReady(false), + _dataReady2Read(false), + _dataReady2Update(false), + _dataReady2Remove(false), + _polledDuringStart(false), + _pollingIntervalSecs(86400), + _pollingStartedTimeMs(0), CAF_CM_INIT_LOG("CPersistenceNamespaceDb") { CAF_CM_INIT_THREADSAFE; _nsdbNamespace = "com.vmware.caf.guest.rw"; @@ -44,6 +50,10 @@ void CPersistenceNamespaceDb::initialize() { CAF_CM_LOCK_UNLOCK; if (! _isInitialized) { + _polledDuringStart = false; + _nsdbPollerSignalFile = AppConfigUtils::getRequiredString("monitor", "nsdb_poller_signal_file"); + _pollingIntervalSecs = AppConfigUtils::getRequiredUint32("monitor", "nsdb_polling_interval_secs"); + _pollingStartedTimeMs = CDateTimeUtils::getTimeMs(); setCmd(); _isInitialized = true; } @@ -55,8 +65,9 @@ SmartPtrCPersistenceDoc CPersistenceNamespaceDb::getUpdated( CAF_CM_LOCK_UNLOCK; CAF_CM_PRECOND_ISINITIALIZED(_isInitialized); + CAF_CM_LOG_DEBUG_VA0("getUpdated"); SmartPtrCPersistenceDoc rc; - if (isReady()) { + if (isDataReady2Read() && isReady()) { const std::string updatesCur = getValue("updates"); if (_updates.compare(updatesCur) != 0) { _updates = updatesCur; @@ -156,6 +167,13 @@ SmartPtrCPersistenceDoc CPersistenceNamespaceDb::getUpdated( } } + if (rc.IsNull()) { + rc = _persistenceUpdate; + } + + _dataReady2Read = false; + + return rc; } @@ -165,7 +183,8 @@ void CPersistenceNamespaceDb::update( CAF_CM_LOCK_UNLOCK; CAF_CM_PRECOND_ISINITIALIZED(_isInitialized); - if (isReady()) { + CAF_CM_LOG_DEBUG_VA0("update"); + if (isDataReady2Update() && isReady()) { const SmartPtrCPersistenceDoc persistenceCur = persistenceDoc.IsNull() ? _persistenceUpdate : persistenceDoc; if (! persistenceCur.IsNull()) { _persistenceUpdate = SmartPtrCPersistenceDoc(); @@ -249,6 +268,8 @@ void CPersistenceNamespaceDb::update( _persistenceUpdate = persistenceDoc; } } + + _dataReady2Update = false; } void CPersistenceNamespaceDb::remove( @@ -257,7 +278,8 @@ void CPersistenceNamespaceDb::remove( CAF_CM_LOCK_UNLOCK; CAF_CM_PRECOND_ISINITIALIZED(_isInitialized); - if (isReady()) { + CAF_CM_LOG_DEBUG_VA0("remove"); + if (isDataReady2Remove() && isReady()) { const SmartPtrCPersistenceDoc persistenceCur = persistenceDoc.IsNull() ? _persistenceRemove : persistenceDoc; if (! persistenceCur.IsNull()) { _persistenceRemove = SmartPtrCPersistenceDoc(); @@ -330,6 +352,8 @@ void CPersistenceNamespaceDb::remove( _persistenceRemove = persistenceDoc; } } + + _dataReady2Remove = false; } void CPersistenceNamespaceDb::setCmd() { @@ -364,6 +388,7 @@ std::string CPersistenceNamespaceDb::getValue(const std::string& key) { CAF_CM_FUNCNAME("getValue"); CAF_CM_VALIDATE_STRING(key); + CAF_CM_LOG_DEBUG_VA0("getValue"); std::string value; std::string stdoutContent; std::string stderrContent; @@ -387,6 +412,7 @@ void CPersistenceNamespaceDb::setValue( CAF_CM_FUNCNAME("setValue"); CAF_CM_VALIDATE_STRING(key); + CAF_CM_LOG_DEBUG_VA0("setValue"); if (_removedKeys.find(key) == _removedKeys.end()) { if (value.empty()) { CAF_CM_LOG_DEBUG_VA1("Cannot set empty value: %s", key.c_str()); @@ -431,6 +457,7 @@ void CPersistenceNamespaceDb::removeKey(const std::string& key) { CAF_CM_FUNCNAME("removeKey"); CAF_CM_VALIDATE_STRING(key); + CAF_CM_LOG_DEBUG_VA0("removeKey"); if (_removedKeys.find(key) == _removedKeys.end()) { std::string stdoutContent; std::string stderrContent; @@ -459,9 +486,67 @@ void CPersistenceNamespaceDb::removeKey(const std::string& key) { } } +bool CPersistenceNamespaceDb::isDataReady() { + CAF_CM_FUNCNAME_VALIDATE("isDataReady"); + + CAF_CM_LOG_DEBUG_VA0("isDataReady method"); + + // Check if data is ready to read/modify + bool rc = false; + if (!_polledDuringStart) { + rc = true; + _polledDuringStart = true; + CAF_CM_LOG_DEBUG_VA0("Set NSDB polling during service start"); + } + if (FileSystemUtils::doesFileExist(_nsdbPollerSignalFile)) { + rc = true; + CAF_CM_LOG_DEBUG_VA1("NSDB poller signal file %s exists.", _nsdbPollerSignalFile.c_str()); + FileSystemUtils::removeFile(_nsdbPollerSignalFile); + } + CAF_CM_LOG_DEBUG_VA4("NSDB poller signal file %s, _pollingStartedTimeMs=%ld, _pollingIntervalSecs=%ld, rc=%s.", + _nsdbPollerSignalFile.c_str(), long(_pollingStartedTimeMs), long(_pollingIntervalSecs), rc?"true":"false"); + if (CDateTimeUtils::calcRemainingTime(_pollingStartedTimeMs, _pollingIntervalSecs * 1000) <= 0) { + rc = true; + CAF_CM_LOG_DEBUG_VA0("The next polling interval reached."); + } + if (rc) { + _pollingStartedTimeMs = CDateTimeUtils::getTimeMs(); + _dataReady2Read = _dataReady2Update = _dataReady2Remove = true; + } + + return rc; +} + +bool CPersistenceNamespaceDb::isDataReady2Read() { + CAF_CM_FUNCNAME_VALIDATE("isDataReady2Read"); + + CAF_CM_LOG_DEBUG_VA1("_dataReady2Read = %s", _dataReady2Read?"true":"false"); + + return (isDataReady() || _dataReady2Read); +} + +bool CPersistenceNamespaceDb::isDataReady2Update() { + CAF_CM_FUNCNAME_VALIDATE("isDataReady2Update"); + + CAF_CM_LOG_DEBUG_VA1("_dataReady2Update = %s", _dataReady2Update?"true":"false"); + return (isDataReady() || _dataReady2Update); + +} + +bool CPersistenceNamespaceDb::isDataReady2Remove() { + CAF_CM_FUNCNAME_VALIDATE("isDataReady2Remove"); + + CAF_CM_LOG_DEBUG_VA1("_dataReady2Remove = %s", _dataReady2Remove?"true":"false"); + return (isDataReady() || _dataReady2Remove); + +} + bool CPersistenceNamespaceDb::isReady() { CAF_CM_FUNCNAME("isReady"); + CAF_CM_LOG_DEBUG_VA0("isReady method"); + + bool rc = true; if (! _isReady) { std::string stdoutContent; @@ -496,6 +581,7 @@ std::string CPersistenceNamespaceDb::getValueRaw( CAF_CM_FUNCNAME_VALIDATE("getValueRaw"); CAF_CM_VALIDATE_STRING(key); + CAF_CM_LOG_ERROR_VA0("getValueRaw"); Cdeqstr argv; argv.push_back(_nsdbCmdPath); argv.push_back("get-value"); diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.h b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.h index e4e07a0d0..c8f0ad0e3 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.h +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceNamespaceDb.h @@ -66,6 +66,14 @@ private: bool isReady(); + bool isDataReady(); + + bool isDataReady2Read(); + + bool isDataReady2Update(); + + bool isDataReady2Remove(); + std::string getValueRaw( const std::string& key, std::string& stdoutContent, @@ -74,9 +82,17 @@ private: private: bool _isInitialized; bool _isReady; + bool _dataReady2Read; + bool _dataReady2Update; + bool _dataReady2Remove; + + bool _polledDuringStart; + uint32 _pollingIntervalSecs; + uint64 _pollingStartedTimeMs; std::string _nsdbCmdPath; std::string _nsdbNamespace; + std::string _nsdbPollerSignalFile; Csetstr _removedKeys; std::string _updates; diff --git a/open-vm-tools/common-agent/etc/config/ma-appconfig b/open-vm-tools/common-agent/etc/config/ma-appconfig index f86f15634..1818b9bac 100644 --- a/open-vm-tools/common-agent/etc/config/ma-appconfig +++ b/open-vm-tools/common-agent/etc/config/ma-appconfig @@ -49,6 +49,8 @@ diagFileAlias_IntBeanConfigFile=file://${root_dir}/config/IntBeanConfigFile.xml? listener_retry_max=-1 listener_startup_type=Automatic listener_restart_hours=48 +nsdb_poller_signal_file=${monitor_dir}/nsdbPollerSignal.txt +nsdb_polling_interval_secs=86400 [subsystems] # Integration System Beans diff --git a/open-vm-tools/common-agent/etc/config/ma-context.xml b/open-vm-tools/common-agent/etc/config/ma-context.xml index b32dfdbe0..cf0c0a4b2 100644 --- a/open-vm-tools/common-agent/etc/config/ma-context.xml +++ b/open-vm-tools/common-agent/etc/config/ma-context.xml @@ -309,7 +309,7 @@ id="persistenceInboundChannelAdapterId" channel="configenvOutboundChannel" ref="persistenceNsdbBean"> - +