[icinga-checkins] icinga.org: icinga2/master: Optimize replication messages.

git at icinga.org git at icinga.org
Fri Apr 5 14:32:32 CEST 2013


Module: icinga2
Branch: master
Commit: 1682ff283936fd5c6f127b73678292c72985ad1d
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=1682ff283936fd5c6f127b73678292c72985ad1d

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Fri Apr  5 14:05:00 2013 +0200

Optimize replication messages.

---

 components/replication/replicationcomponent.cpp |    4 ++++
 lib/base/dynamicobject.cpp                      |   12 ++++++++++--
 lib/base/dynamicobject.h                        |    3 +++
 lib/base/fifo.cpp                               |   16 ++--------------
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp
index a347fc6..3491285 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 fe1873d..1418d17 100644
--- a/lib/base/dynamicobject.cpp
+++ b/lib/base/dynamicobject.cpp
@@ -49,7 +49,7 @@ boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)>
 boost::signals2::signal<void (double, const DynamicObject::Ptr&)> 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 b3a8094..0ad599c 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<String, string_iless> m_ModifiedAttributes;
 	double m_ConfigTx;
+	double m_LocalTx;
 
 	Attribute<String> m_Name;
 	Attribute<String> m_Type;
diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp
index d0f6bbc..cc12f42 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;*/
+	}
 }
 
 /**





More information about the icinga-checkins mailing list