changeset 1188:f40de74bd1c7

Don't block PSM during failover
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 10 Jun 2013 14:27:15 +0800
parents 436e4342ecd0
children 50bf33dc8fe0
files include/freeDiameter/libfdproto.h libfdcore/p_sr.c libfdcore/peers.c libfdproto/fifo.c
diffstat 4 files changed, 32 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h	Mon Jun 10 12:04:50 2013 +0800
+++ b/include/freeDiameter/libfdproto.h	Mon Jun 10 14:27:15 2013 +0800
@@ -3121,6 +3121,10 @@
 #define fd_fifo_post(queue, item) \
 	fd_fifo_post_int((queue), (void *)(item))
 
+/* Similar function but does not block. It can cause the number of items in the queue to exceed the maximum set. Do not use for normal operation,
+only for failure recovery for example. */
+int fd_fifo_post_noblock( struct fifo * queue, void ** item );
+
 /*
  * FUNCTION:	fd_fifo_get
  *
--- a/libfdcore/p_sr.c	Mon Jun 10 12:04:50 2013 +0800
+++ b/libfdcore/p_sr.c	Mon Jun 10 14:27:15 2013 +0800
@@ -326,7 +326,7 @@
 			fd_hook_call(HOOK_MESSAGE_FAILOVER, sr->req, (struct fd_peer *)srlist->srs.o, NULL, fd_msg_pmdl_get(sr->req));
 			
 			/* Requeue for sending to another peer */
-			CHECK_FCT_DO( ret = fd_fifo_post(fd_g_outgoing, &sr->req),
+			CHECK_FCT_DO( ret = fd_fifo_post_noblock(fd_g_outgoing, (void *)&sr->req),
 				{
 					char buf[256];
 					snprintf(buf, sizeof(buf), "Internal error: error while requeuing during failover: %s", strerror(ret));
--- a/libfdcore/peers.c	Mon Jun 10 12:04:50 2013 +0800
+++ b/libfdcore/peers.c	Mon Jun 10 14:27:15 2013 +0800
@@ -242,7 +242,7 @@
 	/* Requeue all messages in the "out" queue */
 	while ( fd_fifo_tryget(peer->p_tosend, &m) == 0 ) {
 		fd_hook_call(HOOK_MESSAGE_FAILOVER, m, peer, NULL, fd_msg_pmdl_get(m));
-		CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &m), 
+		CHECK_FCT_DO(fd_fifo_post_noblock(fd_g_outgoing, (void *)&m), 
 			{
 				/* fallback: destroy the message */
 				fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Internal error: unable to requeue this message during failover process", fd_msg_pmdl_get(m));
--- a/libfdproto/fifo.c	Mon Jun 10 12:04:50 2013 +0800
+++ b/libfdproto/fifo.c	Mon Jun 10 14:27:15 2013 +0800
@@ -376,24 +376,19 @@
 
 
 /* Post a new item in the queue */
-int fd_fifo_post_int ( struct fifo * queue, void ** item )
+int fd_fifo_post_internal ( struct fifo * queue, void ** item, int skip_max )
 {
 	struct fifo_item * new;
 	int call_cb = 0;
 	struct timespec posted_on, queued_on;
 	
-	TRACE_ENTRY( "%p %p", queue, item );
-	
-	/* Check the parameters */
-	CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item );
-	
 	/* Get the timing of this call */
 	CHECK_SYS(  clock_gettime(CLOCK_REALTIME, &posted_on)  );
 	
 	/* lock the queue */
 	CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
 	
-	if (queue->max) {
+	if ((!skip_max) && (queue->max)) {
 		while (queue->count >= queue->max) {
 			int ret = 0;
 			
@@ -461,6 +456,30 @@
 	return 0;
 }
 
+/* Post a new item in the queue */
+int fd_fifo_post_int ( struct fifo * queue, void ** item )
+{
+	TRACE_ENTRY( "%p %p", queue, item );
+	
+	/* Check the parameters */
+	CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item );
+	
+	return fd_fifo_post_internal ( queue,item, 0 );
+	
+}
+
+/* Post a new item in the queue, not blocking */
+int fd_fifo_post_noblock ( struct fifo * queue, void ** item )
+{
+	TRACE_ENTRY( "%p %p", queue, item );
+	
+	/* Check the parameters */
+	CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item );
+	
+	return fd_fifo_post_internal ( queue,item, 1 );
+	
+}
+
 /* Pop the first item from the queue */
 static void * mq_pop(struct fifo * queue)
 {
"Welcome to our mercurial repository"