[PATCH 1.1] ft.c: Multicast fault tolerance


John Gray <jgray@...>
 

Fault tolerance for multicast.

 

? ft.patch

Index: ft.c

===================================================================

RCS file: /cvsroot/products/mama/c_cpp/src/c/Attic/ft.c,v

retrieving revision 1.1.2.7

diff -w -u -r1.1.2.7 ft.c

--- ft.c    2 Oct 2011 19:02:17 -0000     1.1.2.7

+++ ft.c    30 Jan 2012 16:19:51 -0000

@@ -58,6 +58,7 @@

#define FT_FIELD_IPADDRESS          "MamaIPAddress"

#define FT_FIELD_IPADDRESS_FID      206

+#define FT_MAX_PROPERTY_NAME_LENGTH 1024

mama_status

multicastFt_setup (

     mamaFtMember                   member,

@@ -104,6 +105,7 @@

static void bridgeFt_sendHeartbeat (mamaFtMember member);

static int multicastFt_receiveHeartbeat(void* member);

static int bridgeFt_receiveHeartbeat(void* member);

+const char *multicastFt_getProperty(char *buffer, const char *propertyName, const char *transportName);

 static int foundheartbeat=0;

@@ -878,6 +880,28 @@

/****************************************************************************

*       Multicast FT specific

******************************************************************************/

+const char *multicastFt_getProperty(char *buffer, const char *propertyName, const char *transportName)

+{

+    /* Returns. */

+    const char *ret = NULL;

+

+    /* Format the full property name. */

+    int numberWritten = snprintf(buffer, (FT_MAX_PROPERTY_NAME_LENGTH - 1), propertyName, transportName);

+

+    /* If too many characters are written the log an error. */

+    if((FT_MAX_PROPERTY_NAME_LENGTH - 1) < numberWritten)

+    {

+        mama_log(MAMA_LOG_LEVEL_ERROR, "%s Property name too long. Length [%d], Max Length [%d].", transportName, strlen(transportName), (FT_MAX_PROPERTY_NAME_LENGTH - 1));

+    }

+

+    else

+    {

+        /* Otherwise get the property. */

+        ret = mama_getProperty(buffer);

+    }

+

+    return ret;

+}

mama_status

multicastFt_setup (

     mamaFtMember                   member,

@@ -904,46 +928,68 @@

     const char* ftNetwork   = NULL;

     const char* ftTtl       = NULL;

     const char* iorecvstr   = NULL;

+    const char* transportName   = NULL;

+    const char defTportName[3]  = "ft";

+    mama_status status          = MAMA_STATUS_OK;   

     struct in_addr iface;

     struct in_addr cFtIfAddr;

+    #ifdef WIN32

+    int nonBlock = 1;

+    #endif

+

+    /* This buffer is used for formatting property names. */

+    char propertyName[FT_MAX_PROPERTY_NAME_LENGTH] = "";

     mamaFtMemberImpl* impl = (mamaFtMemberImpl*) member;

     if (!impl || !groupName)

         return MAMA_STATUS_INVALID_ARG;

-    ftInterface = mama_getProperty ("mama.multicast.transport.ft.interface");

+    /* Get the transport name. */

+    if (transport)

+    {

+        status = mamaTransport_getName(transport, &transportName);

+        if((MAMA_STATUS_OK != status) || (NULL == transportName) || ('\0' == transportName[0]))

+        {

+            mama_log (MAMA_LOG_LEVEL_ERROR, "MAMA multicast FT: the transport name is invalid");

+            return MAMA_STATUS_INVALID_ARG;

+        }

+    }

+    else

+        transportName = defTportName;

+

+    ftInterface = multicastFt_getProperty(propertyName, "mama.multicast.transport.%s.interface", transportName);

     if (ftInterface == NULL)

     {

-    ftInterface = mama_getProperty ("mama.native.transport.ft.interface");

+    ftInterface = multicastFt_getProperty(propertyName, "mama.native.transport.%s.interface", transportName);       

     if (ftInterface == NULL)

             ftInterface = "";

     }

-    ftNetwork = mama_getProperty ("mama.multicast.transport.ft.network");

+    ftNetwork = multicastFt_getProperty (propertyName, "mama.multicast.transport.%s.network", transportName);

     if (ftNetwork == NULL)

     {

-        ftNetwork = mama_getProperty ("mama.native.transport.ft.network");

+        ftNetwork = multicastFt_getProperty (propertyName, "mama.native.transport.%s.network", transportName);

             if (ftNetwork == NULL)

                 ftNetwork = FT_NETWORK;

     }

-    ftService = mama_getProperty ("mama.multicast.transport.ft.service");

+    ftService = multicastFt_getProperty (propertyName, "mama.multicast.transport.%s.service", transportName);

     if (ftService == NULL)

     {

-        ftService = mama_getProperty ("mama.native.transport.ft.service");

+        ftService = multicastFt_getProperty (propertyName, "mama.native.transport.%s.service", transportName);

         if (ftService != NULL)

                 service = atol (ftService);

     }

-    ftTtl = mama_getProperty ("mama.multicast.transport.ft.ttl");

+    ftTtl = multicastFt_getProperty (propertyName, "mama.multicast.transport.%s.ttl", transportName);

     if (ftTtl == NULL)

     {

-        ftTtl = mama_getProperty ("mama.native.transport.ft.ttl");

+        ftTtl = multicastFt_getProperty (propertyName, "mama.native.transport.%s.ttl", transportName);

         if (ftTtl != NULL)

                 ttl = atol (ftTtl);

     }

-    iorecvstr = mama_getProperty ("mama.multicast.transport.ft.iowindow");

+    iorecvstr = multicastFt_getProperty (propertyName, "mama.multicast.transport.%s.iowindow", transportName);

     if (iorecvstr != NULL)

     {

         iorecv=atoi (iorecvstr);

 

Signed-off-by: John Gray <jgray@...>