On Tue July 28 2009 16:33:28 you wrote:
> It might indeed be solved by your latest patch - I would gladly test it.

Sorry, I wasn't able to test the patch I've written in detail but maybe it 
already solves your problem. You must use it in combination with the latest 
version of OpenDBX from the SVN trunk.


Norbert
-- 
OpenPGP public key
http://www.linuxnetworks.de/norbert.pubkey.asc


Index: odbxbackend.hh
===================================================================
--- odbxbackend.hh	(revision 1363)
+++ odbxbackend.hh	(working copy)
@@ -56,6 +56,7 @@
 	string m_myname;
 	string m_qname;
 	int m_default_ttl;
+	int m_timeout;
 	bool m_qlog;
 	odbx_t* m_handle[2];
 	odbx_result_t* m_result;
@@ -116,6 +117,7 @@
 		declare( suffix, "database", "Database name containing the DNS records","powerdns" );
 		declare( suffix, "username","User for connecting to the DBMS","powerdns");
 		declare( suffix, "password","Password for connecting to the DBMS","");
+		declare( suffix, "timeout","Timeout in seconds to wait for the database","5");
 
 		declare( suffix, "sql-list", "AXFR query", "SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id" );
 
Index: odbxbackend.cc
===================================================================
--- odbxbackend.cc	(revision 1363)
+++ odbxbackend.cc	(working copy)
@@ -45,6 +45,8 @@
 
 		setArgPrefix( "opendbx" + suffix );
 
+		m_timeout = arg().asNum( "timeout" );
+
 		if( getArg( "host" ).size() > 0 )
 		{
 			L.log( m_myname + " WARNING: Using depricated opendbx-host parameter", Logger::Warning );
@@ -194,7 +196,7 @@
 			if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
 			{
 				sd.ttl = strtoul( tmp, NULL, 10 );
-			} 
+			}
 
 			if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
 			{
Index: odbxprivate.cc
===================================================================
--- odbxprivate.cc	(revision 1363)
+++ odbxprivate.cc	(working copy)
@@ -80,12 +80,16 @@
 bool OdbxBackend::getRecord( QueryType type )
 {
 	int err = 3;
+	struct timeval timeout;
 
 
 	DLOG( L.log( m_myname + " getRecord()", Logger::Debug ) );
 
 	do
 	{
+		timeout.tv_sec = m_timeout;
+		timeout.tv_usec = 0;
+
 		if( err < 0 )
 		{
 			L.log( m_myname + " getRecord: Unable to get next result - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
@@ -94,46 +98,54 @@
 
 		if( m_result != NULL )
 		{
-			if( err == 3 )
+			switch( err )
 			{
-				if( ( err = odbx_row_fetch( m_result ) ) < 0 )
-				{
-					L.log( m_myname + " getRecord: Unable to get next row - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
-					throw( AhuException( "Error: odbx_row_fetch() failed" ) );
-				}
+				case 1: // Timeout
 
-				if( err > 0 )
-				{
-#ifdef VERBOSELOG
-					unsigned int i;
-					string fields;
+					L.log( m_myname + " getRecord: Timeout reached for retrieving '" + m_qname + "'",  Logger::Error );
+					break;
 
-					for( i = 0; i < odbx_column_count( m_result ); i++ )
+				case 3: // Rows available
+
+					if( ( err = odbx_row_fetch( m_result ) ) < ODBX_ROW_DONE )
 					{
-						fields += string( odbx_column_name( m_result, i ) );
+						L.log( m_myname + " getRecord: Unable to get next row - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+						throw( AhuException( "Error: odbx_row_fetch() failed" ) );
+					}
 
-						if( odbx_field_value( m_result, i ) != NULL )
+					if( err > ODBX_ROW_DONE )
+					{
+#ifdef VERBOSELOG
+						unsigned int i;
+						string fields;
+
+						for( i = 0; i < odbx_column_count( m_result ); i++ )
 						{
-							fields += "=" + string( odbx_field_value( m_result, i ) ) + ", ";
+							fields += string( odbx_column_name( m_result, i ) );
+
+							if( odbx_field_value( m_result, i ) != NULL )
+							{
+								fields += "=" + string( odbx_field_value( m_result, i ) ) + ", ";
+							}
+							else
+							{
+								fields += "=NULL, ";
+							}
 						}
-						else
-						{
-							fields += "=NULL, ";
-						}
-					}
 
-					L.log( m_myname + " Values: " + fields,  Logger::Error );
+						L.log( m_myname + " Values: " + fields,  Logger::Error );
 #endif
-					return true;
-				}
+						return true;
+					}
 
+					break;
 			}
 
 			odbx_result_free( m_result );
 			m_result = NULL;
 		}
 	}
-	while( ( err =  odbx_result( m_handle[type], &m_result, NULL, 0 ) ) != 0 );
+	while( ( err =  odbx_result( m_handle[type], &m_result, &timeout, 0 ) ) != ODBX_RES_DONE );
 
 	m_result = NULL;
 	return false;

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Pdns-users mailing list
[email protected]
http://mailman.powerdns.com/mailman/listinfo/pdns-users

Reply via email to