You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2015/09/24 20:02:19 UTC

qpid-dispatch git commit: DISPATCH-144 - Configurable heartbeats for listeners and connectors

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 43488732c -> d1400785e


DISPATCH-144 - Configurable heartbeats for listeners and connectors


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/d1400785
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/d1400785
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/d1400785

Branch: refs/heads/master
Commit: d1400785e8dbf7e2006dcc9e240c317d9d0adeb3
Parents: 4348873
Author: Ted Ross <tr...@redhat.com>
Authored: Thu Sep 24 13:43:58 2015 -0400
Committer: Ted Ross <tr...@redhat.com>
Committed: Thu Sep 24 13:44:35 2015 -0400

----------------------------------------------------------------------
 include/qpid/dispatch/driver.h                |  4 ++
 include/qpid/dispatch/server.h                |  6 +++
 python/qpid_dispatch/management/qdrouter.json | 13 ++++++-
 src/connection_manager.c                      |  1 +
 src/posix/driver.c                            | 43 ++++++++++------------
 src/router_node.c                             |  3 +-
 src/server.c                                  | 19 ++++++++++
 src/server_private.h                          |  1 +
 tests/system_test.py                          |  4 +-
 9 files changed, 66 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/include/qpid/dispatch/driver.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/driver.h b/include/qpid/dispatch/driver.h
index 351d1c4..c286c44 100644
--- a/include/qpid/dispatch/driver.h
+++ b/include/qpid/dispatch/driver.h
@@ -352,6 +352,10 @@ void qdpn_connector_free(qdpn_connector_t *connector);
  */
 void qdpn_connector_activate(qdpn_connector_t *connector, qdpn_activate_criteria_t criteria);
 
+/** Activate all of the open file descriptors
+ */
+void qdpn_activate_all(qdpn_driver_t *driver);
+
 /** Return the activation status of the connector for a criteria
  *
  * Return the activation status (i.e. readable, writable) for the connector.  This function

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/include/qpid/dispatch/server.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/server.h b/include/qpid/dispatch/server.h
index b5ebc04..3eca75c 100644
--- a/include/qpid/dispatch/server.h
+++ b/include/qpid/dispatch/server.h
@@ -363,6 +363,12 @@ typedef struct qd_server_config_t {
      * The maximum size of an AMQP frame in octets.
      */
     uint32_t max_frame_size;
+
+    /**
+     * The idle timeout, in seconds.  If the peer sends no data frames in this many seconds, the
+     * connection will be automatically closed.
+     */
+    int idle_timeout_seconds;
 } qd_server_config_t;
 
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/python/qpid_dispatch/management/qdrouter.json
----------------------------------------------------------------------
diff --git a/python/qpid_dispatch/management/qdrouter.json b/python/qpid_dispatch/management/qdrouter.json
index c5b1edb..3103224 100644
--- a/python/qpid_dispatch/management/qdrouter.json
+++ b/python/qpid_dispatch/management/qdrouter.json
@@ -609,7 +609,12 @@
                     "description": "Defaults to 65536.  If specified, it is the maximum frame size in octets that will be used in the connection-open negotiation with a connected peer.  The frame size is the largest contiguous set of uninterrupted data that can be sent for a message delivery over the connection. Interleaving of messages on different links is done at frame granularity.",
                     "create": true
                 },
-
+                "idleTimeoutSeconds": {
+                    "type": "integer",
+                    "default": 16,
+                    "description": "The idle timeout, in seconds, for connections through this listener.  If no frames are received on the connection for this time interval, the connection shall be closed.",
+                    "create": true
+                },
                 "requirePeerAuth": {
                     "type": "boolean",
                     "create": true,
@@ -662,6 +667,12 @@
                     "description": "Maximum frame size in octets that will be used in the connection-open negotiation with a connected peer.  The frame size is the largest contiguous set of uninterrupted data that can be sent for a message delivery over the connection. Interleaving of messages on different links is done at frame granularity.",
                     "create": true
                 },
+                "idleTimeoutSeconds": {
+                    "type": "integer",
+                    "default": 16,
+                    "description": "The idle timeout, in seconds, for connections through this connector.  If no frames are received on the connection for this time interval, the connection shall be closed.",
+                    "create": true
+                },
                 "stripAnnotations": {
                     "type": ["in", "out", "both", "no"],
                     "default": "both",

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/src/connection_manager.c
----------------------------------------------------------------------
diff --git a/src/connection_manager.c b/src/connection_manager.c
index 218597c..c9dc81c 100644
--- a/src/connection_manager.c
+++ b/src/connection_manager.c
@@ -143,6 +143,7 @@ static qd_error_t load_server_config(qd_dispatch_t *qd, qd_server_config_t *conf
     config->port            = qd_entity_get_string(entity, "port"); CHECK();
     config->role            = qd_entity_get_string(entity, "role"); CHECK();
     config->max_frame_size  = qd_entity_get_long(entity, "maxFrameSize"); CHECK();
+    config->idle_timeout_seconds = qd_entity_get_long(entity, "idleTimeoutSeconds"); CHECK();
     config->sasl_mechanisms = qd_entity_opt_string(entity, "saslMechanisms", 0); CHECK();
     config->ssl_enabled = has_attrs(entity, ssl_attributes, ssl_attributes_count);
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/src/posix/driver.c
----------------------------------------------------------------------
diff --git a/src/posix/driver.c b/src/posix/driver.c
index 11fb728..eed8e2f 100644
--- a/src/posix/driver.c
+++ b/src/posix/driver.c
@@ -35,6 +35,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <assert.h>
+#include <time.h>
 
 #include <qpid/dispatch/driver.h>
 #include <qpid/dispatch/threading.h>
@@ -129,35 +130,17 @@ static void pni_fatal(const char *text)
     exit(1);
 }
 
-#ifdef USE_CLOCK_GETTIME
-#include <time.h>
 pn_timestamp_t pn_i_now(void)
 {
     struct timespec now;
-    if (clock_gettime(CLOCK_REALTIME, &now)) pni_fatal("clock_gettime() failed");
-    return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_nsec / 1000000);
-}
-#elif defined(USE_WIN_FILETIME)
-#include <windows.h>
-pn_timestamp_t pn_i_now(void)
-{
-    FILETIME now;
-    GetSystemTimeAsFileTime(&now);
-    ULARGE_INTEGER t;
-    t.u.HighPart = now.dwHighDateTime;
-    t.u.LowPart = now.dwLowDateTime;
-    // Convert to milliseconds and adjust base epoch
-    return t.QuadPart / 10000 - 11644473600000;
-}
+#ifdef CLOCK_MONOTONIC_COARSE
+    int cid = CLOCK_MONOTONIC_COARSE;
 #else
-#include <sys/time.h>
-pn_timestamp_t pn_i_now(void)
-{
-    struct timeval now;
-    if (gettimeofday(&now, NULL)) pni_fatal("gettimeofday failed");
-    return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_usec / 1000);
-}
+    int cid = CLOCK_MONOTONIC;
 #endif
+    if (clock_gettime(cid, &now)) pni_fatal("clock_gettime() failed");
+    return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_nsec / 1000000);
+}
 
 static bool pni_eq_nocase(const char *a, const char *b)
 {
@@ -649,6 +632,18 @@ void qdpn_connector_activate(qdpn_connector_t *ctor, qdpn_activate_criteria_t cr
 }
 
 
+void qdpn_activate_all(qdpn_driver_t *d)
+{
+    sys_mutex_lock(d->lock);
+    qdpn_connector_t *c = DEQ_HEAD(d->connectors);
+    while (c) {
+        c->status |= PN_SEL_WR;
+        c = DEQ_NEXT(c);
+    }
+    sys_mutex_unlock(d->lock);
+}
+
+
 bool qdpn_connector_activated(qdpn_connector_t *ctor, qdpn_activate_criteria_t crit)
 {
     bool result = false;

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/src/router_node.c
----------------------------------------------------------------------
diff --git a/src/router_node.c b/src/router_node.c
index a26a3af..9475cd2 100644
--- a/src/router_node.c
+++ b/src/router_node.c
@@ -1074,14 +1074,15 @@ static void qd_router_open_routed_link(void *context, bool discard)
     link_event_t *le = (link_event_t*) context;
 
     if (!discard) {
+        sys_mutex_lock(le->router->lock);
         qd_link_t *link = le->rlink->link;
-
         if (le->rlink->connected_link) {
             qd_link_t *peer = le->rlink->connected_link->link;
             pn_terminus_copy(qd_link_source(link), qd_link_remote_source(peer));
             pn_terminus_copy(qd_link_target(link), qd_link_remote_target(peer));
             pn_link_open(qd_link_pn(link));
         }
+        sys_mutex_unlock(le->router->lock);
     }
 
     free_link_event_t(le);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/src/server.c
----------------------------------------------------------------------
diff --git a/src/server.c b/src/server.c
index 2b7b19f..ea86f4d 100644
--- a/src/server.c
+++ b/src/server.c
@@ -36,6 +36,8 @@
 
 static __thread qd_server_t *thread_server = 0;
 
+#define HEARTBEAT_INTERVAL 1000
+
 ALLOC_DEFINE(qd_work_item_t);
 ALLOC_DEFINE(qd_listener_t);
 ALLOC_DEFINE(qd_connector_t);
@@ -278,6 +280,7 @@ static void thread_process_listeners_LH(qd_server_t *qd_server)
         //
         pn_transport_set_server(tport);
         pn_transport_set_max_frame(tport, config->max_frame_size);
+        pn_transport_set_idle_timeout(tport, config->idle_timeout_seconds * 1000);
 
         // Set up SSL if configured
         if (config->ssl_enabled) {
@@ -829,6 +832,7 @@ static void cxtr_try_open(void *context)
     // Configure the transport
     //
     pn_transport_set_max_frame(tport, config->max_frame_size);
+    pn_transport_set_idle_timeout(tport, config->idle_timeout_seconds * 1000);
 
     //
     // Set up SSL if appropriate
@@ -898,6 +902,14 @@ static void cxtr_try_open(void *context)
 }
 
 
+static void heartbeat_cb(void *context)
+{
+    qd_server_t *qd_server = (qd_server_t*) context;
+    qdpn_activate_all(qd_server->driver);
+    qd_timer_schedule(qd_server->heartbeat_timer, HEARTBEAT_INTERVAL);
+}
+
+
 qd_server_t *qd_server(qd_dispatch_t *qd, int thread_count, const char *container_name,
                        const char *sasl_config_path, const char *sasl_config_name)
 {
@@ -940,6 +952,7 @@ qd_server_t *qd_server(qd_dispatch_t *qd, int thread_count, const char *containe
     qd_server->pause_next_sequence = 0;
     qd_server->pause_now_serving   = 0;
     qd_server->pending_signal      = 0;
+    qd_server->heartbeat_timer     = 0;
 
     qd_log(qd_server->log_source, QD_LOG_INFO, "Container Name: %s", qd_server->container_name);
 
@@ -1014,6 +1027,9 @@ void qd_server_run(qd_dispatch_t *qd)
     for (i = 1; i < qd_server->thread_count; i++)
         thread_start(qd_server->threads[i]);
 
+    qd_server->heartbeat_timer = qd_timer(qd, heartbeat_cb, qd_server);
+    qd_timer_schedule(qd_server->heartbeat_timer, HEARTBEAT_INTERVAL);
+
     qd_server_announce(qd_server);
 
     thread_run((void*) qd_server->threads[0]);
@@ -1041,6 +1057,9 @@ void qd_server_start(qd_dispatch_t *qd)
     for (i = 0; i < qd_server->thread_count; i++)
         thread_start(qd_server->threads[i]);
 
+    qd_server->heartbeat_timer = qd_timer(qd, heartbeat_cb, qd_server);
+    qd_timer_schedule(qd_server->heartbeat_timer, HEARTBEAT_INTERVAL);
+
     qd_server_announce(qd_server);
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/src/server_private.h
----------------------------------------------------------------------
diff --git a/src/server_private.h b/src/server_private.h
index 117c8a3..6cc5eb7 100644
--- a/src/server_private.h
+++ b/src/server_private.h
@@ -161,6 +161,7 @@ struct qd_server_t {
     void                     *signal_context;
     int                       pending_signal;
     qd_connection_list_t      connections;
+    qd_timer_t               *heartbeat_timer;
 };
 
 ALLOC_DECLARE(qd_work_item_t);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d1400785/tests/system_test.py
----------------------------------------------------------------------
diff --git a/tests/system_test.py b/tests/system_test.py
index af8dd40..60f54c6 100644
--- a/tests/system_test.py
+++ b/tests/system_test.py
@@ -305,8 +305,8 @@ class Qdrouterd(Process):
         """
 
         DEFAULTS = {
-            'listener':{'addr':'0.0.0.0', 'saslMechanisms':'ANONYMOUS', 'authenticatePeer': 'no'},
-            'connector':{'addr':'127.0.0.1', 'saslMechanisms':'ANONYMOUS', 'role':'on-demand'},
+            'listener':{'addr':'0.0.0.0', 'saslMechanisms':'ANONYMOUS', 'idleTimeoutSeconds': '120', 'authenticatePeer': 'no'},
+            'connector':{'addr':'127.0.0.1', 'saslMechanisms':'ANONYMOUS', 'idleTimeoutSeconds': '120', 'role':'on-demand'},
             'container':{'debugDump':"qddebug.txt"}
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org