From: Gunnar Beutner Date: Fri, 5 Apr 2013 12:05:00 +0000 (+0200) Subject: Optimize replication messages. X-Git-Tag: v0.0.2~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1682ff283936fd5c6f127b73678292c72985ad1d;p=icinga2 Optimize replication messages. --- diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index a347fc662..34912851e 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -181,6 +181,10 @@ void ReplicationComponent::FlushObjectHandler(double tx, const DynamicObject::Pt if (!ShouldReplicateObject(object)) return; + /* Don't replicate objects that haven't had any local updates. */ + if (object->GetLocalTx() < tx) + return; + RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", tx, true); EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request); } diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index fe1873d76..1418d1756 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -49,7 +49,7 @@ boost::signals2::signal&)> boost::signals2::signal DynamicObject::OnFlushObject; DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject) - : m_ConfigTx(0), m_Registered(false) + : m_ConfigTx(0), m_LocalTx(0), m_Registered(false) { RegisterAttribute("__name", Attribute_Config, &m_Name); RegisterAttribute("__type", Attribute_Config, &m_Type); @@ -241,7 +241,9 @@ void DynamicObject::Touch(const String& name) if (it == m_Attributes.end()) BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name)); - it->second.SetTx(GetCurrentTx()); + double tx = GetCurrentTx(); + it->second.SetTx(tx); + m_LocalTx = tx; m_ModifiedAttributes.insert(name); @@ -251,6 +253,12 @@ void DynamicObject::Touch(const String& name) } } +double DynamicObject::GetLocalTx(void) const +{ + boost::mutex::scoped_lock lock(m_AttributeMutex); + return m_LocalTx; +} + Value DynamicObject::Get(const String& name) const { ASSERT(!OwnsLock()); diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index b3a809454..0ad599c74 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -90,6 +90,8 @@ public: virtual void Start(void); virtual void Stop(void); + double GetLocalTx(void) const; + const AttributeMap& GetAttributes(void) const; static DynamicObject::Ptr GetObject(const String& type, const String& name); @@ -117,6 +119,7 @@ private: AttributeMap m_Attributes; std::set m_ModifiedAttributes; double m_ConfigTx; + double m_LocalTx; Attribute m_Name; Attribute m_Type; diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index d0f6bbc8b..cc12f422f 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -65,26 +65,14 @@ void FIFO::ResizeBuffer(size_t newSize) */ void FIFO::Optimize(void) { - //char *newBuffer; - if (m_DataSize < m_Offset) { memcpy(m_Buffer, m_Buffer + m_Offset, m_DataSize); m_Offset = 0; - return; - } + ResizeBuffer(m_DataSize); - /*newBuffer = (char *)ResizeBuffer(NULL, 0, m_BufferSize - m_Offset); - - if (newBuffer == NULL) return; - - memcpy(newBuffer, m_Buffer + m_Offset, m_BufferSize - m_Offset); - - free(m_Buffer); - m_Buffer = newBuffer; - m_BufferSize -= m_Offset; - m_Offset = 0;*/ + } } /**