You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2021/11/12 21:45:28 UTC

[GitHub] [qpid-dispatch] ted-ross opened a new pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

ted-ross opened a new pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435


   Added API to the core header file, implemented the feature, and added a test.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] ted-ross commented on a change in pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
ted-ross commented on a change in pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#discussion_r751250679



##########
File path: src/router_core/address_watch.c
##########
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "router_core_private.h"
+#include "qpid/dispatch/amqp.h"
+
+struct qdr_address_watch_t {
+    DEQ_LINKS(struct qdr_address_watch_t);
+    qdr_watch_handle_t          watch_handle;
+    char                       *address_hash;
+    qdr_address_watch_update_t  handler;
+    void                       *context;
+};
+
+ALLOC_DECLARE(qdr_address_watch_t);
+ALLOC_DEFINE(qdr_address_watch_t);
+
+static void qdr_watch_invoker(qdr_core_t *core, qdr_general_work_t *work);
+static void qdr_core_watch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_core_unwatch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_address_watch_free_CT(qdr_address_watch_t *watch);
+
+//==================================================================================
+// Core Interface Functions
+//==================================================================================
+qdr_watch_handle_t qdr_core_watch_address(qdr_core_t                 *core,
+                                          const char                 *address,
+                                          char                        aclass,
+                                          char                        phase,
+                                          qdr_address_watch_update_t  on_watch,
+                                          void                       *context)
+{
+    static sys_atomic_t next_handle;
+    qdr_action_t *action = qdr_action(qdr_core_watch_address_CT, "watch_address");
+
+    action->args.io.address       = qdr_field(address);
+    action->args.io.address_class = aclass;
+    action->args.io.address_phase = phase;
+    action->args.io.watch_handler = on_watch;
+    action->args.io.context       = context;
+    action->args.io.value32_1     = sys_atomic_inc(&next_handle);
+
+    qdr_action_enqueue(core, action);
+    return action->args.io.value32_1;
+}
+
+
+void qdr_core_unwatch_address(qdr_core_t *core, qdr_watch_handle_t handle)
+{
+    qdr_action_t *action = qdr_action(qdr_core_unwatch_address_CT, "unwatch_address");
+
+    action->args.io.value32_1 = handle;
+    qdr_action_enqueue(core, action);
+}
+
+
+//==================================================================================
+// In-Core API Functions
+//==================================================================================
+void qdr_trigger_address_watch_CT(qdr_core_t *core, qdr_address_t *addr)
+{
+    const char          *address_hash = (char*) qd_hash_key_by_handle(addr->hash_handle);
+    qdr_address_watch_t *watch        = DEQ_HEAD(core->addr_watches);
+
+    while (!!watch) {
+        if (strcmp(watch->address_hash, address_hash) == 0) {
+            qdr_general_work_t *work = qdr_general_work(qdr_watch_invoker);
+            work->watch_handler     = watch->handler;
+            work->context           = watch->context;
+            work->local_consumers   = DEQ_SIZE(addr->rlinks);
+            work->in_proc_consumers = DEQ_SIZE(addr->subscriptions);
+            work->remote_consumers  = qd_bitmask_cardinality(addr->rnodes);
+            work->local_producers   = DEQ_SIZE(addr->inlinks);
+            qdr_post_general_work_CT(core, work);
+        }
+        watch = DEQ_NEXT(watch);
+    }
+}
+
+void qdr_address_watch_shutdown(qdr_core_t *core)
+{
+    qdr_address_watch_t *watch = DEQ_HEAD(core->addr_watches);
+    while (!!watch) {
+        DEQ_REMOVE(core->addr_watches, watch);
+        qdr_address_watch_free_CT(watch);
+        watch = DEQ_HEAD(core->addr_watches);
+    }
+}
+
+
+//==================================================================================
+// Local Functions
+//==================================================================================
+static void qdr_address_watch_free_CT(qdr_address_watch_t *watch)
+{
+    free(watch->address_hash);
+    free_qdr_address_watch_t(watch);
+}
+
+
+static void qdr_watch_invoker(qdr_core_t *core, qdr_general_work_t *work)
+{
+    work->watch_handler(work->context,
+                        work->local_consumers, work->in_proc_consumers, work->remote_consumers, work->local_producers);
+}
+
+
+static void qdr_core_watch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard)

Review comment:
       Yes, it should.  I'll make this change.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] ted-ross commented on a change in pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
ted-ross commented on a change in pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#discussion_r749717375



##########
File path: src/router_core/address_watch.c
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "router_core_private.h"
+#include "qpid/dispatch/amqp.h"
+
+struct qdr_address_watch_t {
+    DEQ_LINKS(struct qdr_address_watch_t);
+    qdr_watch_handle_t          watch_handle;
+    char                       *address_hash;
+    qdr_address_watch_update_t  handler;
+    void                       *context;
+};
+
+ALLOC_DECLARE(qdr_address_watch_t);
+ALLOC_DEFINE(qdr_address_watch_t);
+
+static void qdr_watch_invoker(qdr_core_t *core, qdr_general_work_t *work);
+static void qdr_core_watch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_core_unwatch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+
+//==================================================================================
+// Core Interface Functions
+//==================================================================================
+qdr_watch_handle_t qdr_core_watch_address(qdr_core_t                 *core,
+                                          const char                 *address,
+                                          char                        aclass,
+                                          char                        phase,
+                                          qdr_address_watch_update_t  on_watch,
+                                          void                       *context)
+{
+    static sys_atomic_t next_handle;
+    qdr_action_t *action = qdr_action(qdr_core_watch_address_CT, "watch_address");
+
+    action->args.io.address       = qdr_field(address);
+    action->args.io.address_class = aclass;
+    action->args.io.address_phase = phase;
+    action->args.io.watch_handler = on_watch;
+    action->args.io.context       = context;
+    action->args.io.value32_1     = sys_atomic_inc(&next_handle);
+
+    qdr_action_enqueue(core, action);
+    return action->args.io.value32_1;
+}
+
+
+void qdr_core_unwatch_address(qdr_core_t *core, qdr_watch_handle_t handle)
+{
+    qdr_action_t *action = qdr_action(qdr_core_unwatch_address_CT, "unwatch_address");
+
+    action->args.io.value32_1 = handle;
+    qdr_action_enqueue(core, action);
+}
+
+
+//==================================================================================
+// In-Core API Functions
+//==================================================================================
+void qdr_trigger_address_watch_CT(qdr_core_t *core, qdr_address_t *addr)
+{
+    const char          *address_hash = (char*) qd_hash_key_by_handle(addr->hash_handle);
+    qdr_address_watch_t *watch        = DEQ_HEAD(core->addr_watches);
+
+    while (!!watch) {
+        if (strcmp(watch->address_hash, address_hash) == 0) {
+            qdr_general_work_t *work = qdr_general_work(qdr_watch_invoker);
+            work->watch_handler     = watch->handler;
+            work->context           = watch->context;
+            work->local_consumers   = DEQ_SIZE(addr->rlinks);
+            work->in_proc_consumers = DEQ_SIZE(addr->subscriptions);
+            work->remote_consumers  = qd_bitmask_cardinality(addr->rnodes);
+            work->local_producers   = DEQ_SIZE(addr->inlinks);
+            qdr_post_general_work_CT(core, work);
+        }
+        watch = DEQ_NEXT(watch);
+    }
+}
+
+void qdr_address_watch_shutdown(qdr_core_t *core)
+{
+    qdr_address_watch_t *watch = DEQ_HEAD(core->addr_watches);
+    while (!!watch) {
+        DEQ_REMOVE(core->addr_watches, watch);
+        free(watch->address_hash);

Review comment:
       This is a good idea.  I'll add it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] codecov-commenter commented on pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#issuecomment-967755483


   # [Codecov](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#1435](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (662f41f) into [main](https://codecov.io/gh/apache/qpid-dispatch/commit/f14a4b8d14f9c1280461ee43c306b0866f09535d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (f14a4b8) will **decrease** coverage by `0.07%`.
   > The diff coverage is `85.43%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/graphs/tree.svg?width=650&height=150&src=pr&token=rk2Cgd27pP&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##             main    #1435      +/-   ##
   ==========================================
   - Coverage   84.78%   84.71%   -0.08%     
   ==========================================
     Files         116      118       +2     
     Lines       28613    28706      +93     
   ==========================================
   + Hits        24259    24317      +58     
   - Misses       4354     4389      +35     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [src/router\_core/route\_tables.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL3JvdXRlX3RhYmxlcy5j) | `81.38% <0.00%> (-0.23%)` | :arrow_down: |
   | [...outer\_core/modules/heartbeat\_edge/heartbeat\_edge.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL21vZHVsZXMvaGVhcnRiZWF0X2VkZ2UvaGVhcnRiZWF0X2VkZ2UuYw==) | `91.52% <50.00%> (-2.92%)` | :arrow_down: |
   | [src/router\_core/modules/mobile\_sync/mobile.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL21vZHVsZXMvbW9iaWxlX3N5bmMvbW9iaWxlLmM=) | `92.19% <75.00%> (-0.41%)` | :arrow_down: |
   | [src/router\_core/address\_watch.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL2FkZHJlc3Nfd2F0Y2guYw==) | `85.71% <85.71%> (ø)` | |
   | [src/adaptors/test\_adaptor.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL2FkYXB0b3JzL3Rlc3RfYWRhcHRvci5j) | `100.00% <100.00%> (ø)` | |
   | [src/router\_core/router\_core.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL3JvdXRlcl9jb3JlLmM=) | `87.18% <100.00%> (+0.14%)` | :arrow_up: |
   | [src/adaptors/tcp\_adaptor.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL2FkYXB0b3JzL3RjcF9hZGFwdG9yLmM=) | `77.21% <0.00%> (-1.90%)` | :arrow_down: |
   | [src/router\_core/connections.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL2Nvbm5lY3Rpb25zLmM=) | `89.15% <0.00%> (-0.68%)` | :arrow_down: |
   | [src/router\_core/forwarder.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL2ZvcndhcmRlci5j) | `93.06% <0.00%> (-0.40%)` | :arrow_down: |
   | [src/message.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21lc3NhZ2UuYw==) | `87.21% <0.00%> (-0.28%)` | :arrow_down: |
   | ... and [5 more](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [6769203...662f41f](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
kgiusti commented on a change in pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#discussion_r750472044



##########
File path: include/qpid/dispatch/router_core.h
##########
@@ -160,6 +169,64 @@ void qdr_send_to2(qdr_core_t *core, qd_message_t *msg, const char *addr,
                   bool exclude_inprocess, bool control);
 
 
+/**
+ ******************************************************************************
+ * Address watch functions
+ ******************************************************************************
+ */
+
+typedef uint32_t qdr_watch_handle_t;
+
+/**
+ * Handler for updates on watched addresses.  This function shall be invoked on an IO thread.
+ * 
+ * Note:  This function will be invoked when a watched address has a change in reachability.
+ * It is possible that the function may be called when no change occurs, particularly when an
+ * address is removed from the core address table.
+ *
+ * @param context The opaque context supplied in the call to qdr_core_watch_address
+ * @param local_consumers Number of consuming (outgoing) links for this address on this router
+ * @param in_proc_consumers Number of in-process consumers for this address on this router
+ * @param remote_consumers Number of remote routers with consumers for this address
+ * @param local_producers Number of producing (incoming) links for this address on this router
+ */
+typedef void (*qdr_address_watch_update_t)(void     *context,
+                                           uint32_t  local_consumers,
+                                           uint32_t  in_proc_consumers,
+                                           uint32_t  remote_consumers,
+                                           uint32_t  local_producers);
+
+/**
+ * qdr_core_watch_address
+ *
+ * Subscribe to watch for changes in the reachability for an address.  It is safe to invoke this
+ * function from an IO thread.
+ * 
+ * @param core Pointer to the core module
+ * @param address The address to be watched
+ * @param aclass Address class character
+ * @param phase Address phase character ('0' .. '9')
+ * @param on_watch The handler function
+ * @param context The opaque context sent to the handler on all invocations
+ * @return Watch handle to be used when canceling the watch
+ */
+qdr_watch_handle_t qdr_core_watch_address(qdr_core_t                 *core,
+                                          const char                 *address,
+                                          char                        aclass,
+                                          char                        phase,
+                                          qdr_address_watch_update_t  on_watch,
+                                          void                       *context);
+
+/**
+ * qdr_core_unwatch_address
+ * 
+ * Cancel an address watch subscription.  It is safe to invoke this function from an IO thread.

Review comment:
       It is possible for the update handler to be invoked during or after this call on another I/O thread. That brings up a possible race:  whatever the context pointer addresses has to remain valid until we're sure that the handler will no longer be invoked, which isn't possible to tell from the caller's point of view.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] ganeshmurthy commented on a change in pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
ganeshmurthy commented on a change in pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#discussion_r749705144



##########
File path: src/router_core/address_watch.c
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "router_core_private.h"
+#include "qpid/dispatch/amqp.h"
+
+struct qdr_address_watch_t {
+    DEQ_LINKS(struct qdr_address_watch_t);
+    qdr_watch_handle_t          watch_handle;
+    char                       *address_hash;
+    qdr_address_watch_update_t  handler;
+    void                       *context;
+};
+
+ALLOC_DECLARE(qdr_address_watch_t);
+ALLOC_DEFINE(qdr_address_watch_t);
+
+static void qdr_watch_invoker(qdr_core_t *core, qdr_general_work_t *work);
+static void qdr_core_watch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_core_unwatch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+
+//==================================================================================
+// Core Interface Functions
+//==================================================================================
+qdr_watch_handle_t qdr_core_watch_address(qdr_core_t                 *core,
+                                          const char                 *address,
+                                          char                        aclass,
+                                          char                        phase,
+                                          qdr_address_watch_update_t  on_watch,
+                                          void                       *context)
+{
+    static sys_atomic_t next_handle;
+    qdr_action_t *action = qdr_action(qdr_core_watch_address_CT, "watch_address");
+
+    action->args.io.address       = qdr_field(address);
+    action->args.io.address_class = aclass;
+    action->args.io.address_phase = phase;
+    action->args.io.watch_handler = on_watch;
+    action->args.io.context       = context;
+    action->args.io.value32_1     = sys_atomic_inc(&next_handle);
+
+    qdr_action_enqueue(core, action);
+    return action->args.io.value32_1;
+}
+
+
+void qdr_core_unwatch_address(qdr_core_t *core, qdr_watch_handle_t handle)
+{
+    qdr_action_t *action = qdr_action(qdr_core_unwatch_address_CT, "unwatch_address");
+
+    action->args.io.value32_1 = handle;
+    qdr_action_enqueue(core, action);
+}
+
+
+//==================================================================================
+// In-Core API Functions
+//==================================================================================
+void qdr_trigger_address_watch_CT(qdr_core_t *core, qdr_address_t *addr)
+{
+    const char          *address_hash = (char*) qd_hash_key_by_handle(addr->hash_handle);
+    qdr_address_watch_t *watch        = DEQ_HEAD(core->addr_watches);
+
+    while (!!watch) {
+        if (strcmp(watch->address_hash, address_hash) == 0) {
+            qdr_general_work_t *work = qdr_general_work(qdr_watch_invoker);
+            work->watch_handler     = watch->handler;
+            work->context           = watch->context;
+            work->local_consumers   = DEQ_SIZE(addr->rlinks);
+            work->in_proc_consumers = DEQ_SIZE(addr->subscriptions);
+            work->remote_consumers  = qd_bitmask_cardinality(addr->rnodes);
+            work->local_producers   = DEQ_SIZE(addr->inlinks);
+            qdr_post_general_work_CT(core, work);
+        }
+        watch = DEQ_NEXT(watch);
+    }
+}
+
+void qdr_address_watch_shutdown(qdr_core_t *core)
+{
+    qdr_address_watch_t *watch = DEQ_HEAD(core->addr_watches);
+    while (!!watch) {
+        DEQ_REMOVE(core->addr_watches, watch);
+        free(watch->address_hash);

Review comment:
       can we introduce a function called qdr_free_address_watch() or qdr_address_watch_free() where we free watch->address_hash and then call free_qdr_address_watch_t(watch); ? 
   free_qdr_address_watch_t is called from two places and so the new function can be called instead of that.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] codecov-commenter edited a comment on pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#issuecomment-967755483


   # [Codecov](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#1435](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (f63ca53) into [main](https://codecov.io/gh/apache/qpid-dispatch/commit/138d084d7a0d9dbeed2991affffc8f669563be68?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (138d084) will **increase** coverage by `0.02%`.
   > The diff coverage is `88.77%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/graphs/tree.svg?width=650&height=150&src=pr&token=rk2Cgd27pP&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##             main    #1435      +/-   ##
   ==========================================
   + Coverage   84.71%   84.73%   +0.02%     
   ==========================================
     Files         116      118       +2     
     Lines       28617    28706      +89     
   ==========================================
   + Hits        24242    24324      +82     
   - Misses       4375     4382       +7     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [src/router\_core/route\_tables.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL3JvdXRlX3RhYmxlcy5j) | `81.38% <0.00%> (-0.23%)` | :arrow_down: |
   | [src/router\_core/modules/mobile\_sync/mobile.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL21vZHVsZXMvbW9iaWxlX3N5bmMvbW9iaWxlLmM=) | `92.19% <75.00%> (-0.17%)` | :arrow_down: |
   | [src/router\_core/address\_watch.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL2FkZHJlc3Nfd2F0Y2guYw==) | `87.50% <87.50%> (ø)` | |
   | [src/adaptors/test\_adaptor.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL2FkYXB0b3JzL3Rlc3RfYWRhcHRvci5j) | `100.00% <100.00%> (ø)` | |
   | [src/router\_core/router\_core.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL3JvdXRlcl9jb3JlLmM=) | `87.18% <100.00%> (+0.14%)` | :arrow_up: |
   | [src/adaptors/tcp\_adaptor.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL2FkYXB0b3JzL3RjcF9hZGFwdG9yLmM=) | `77.00% <0.00%> (-0.32%)` | :arrow_down: |
   | [src/parse.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3BhcnNlLmM=) | `87.96% <0.00%> (-0.22%)` | :arrow_down: |
   | [src/router\_core/connections.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL2Nvbm5lY3Rpb25zLmM=) | `90.00% <0.00%> (-0.01%)` | :arrow_down: |
   | [src/message.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21lc3NhZ2UuYw==) | `87.49% <0.00%> (+0.07%)` | :arrow_up: |
   | [src/router\_core/delivery.c](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL3JvdXRlcl9jb3JlL2RlbGl2ZXJ5LmM=) | `93.90% <0.00%> (+0.55%)` | :arrow_up: |
   | ... and [1 more](https://codecov.io/gh/apache/qpid-dispatch/pull/1435/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [138d084...f63ca53](https://codecov.io/gh/apache/qpid-dispatch/pull/1435?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
kgiusti commented on a change in pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#discussion_r750481682



##########
File path: src/router_core/address_watch.c
##########
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "router_core_private.h"
+#include "qpid/dispatch/amqp.h"
+
+struct qdr_address_watch_t {
+    DEQ_LINKS(struct qdr_address_watch_t);
+    qdr_watch_handle_t          watch_handle;
+    char                       *address_hash;
+    qdr_address_watch_update_t  handler;
+    void                       *context;
+};
+
+ALLOC_DECLARE(qdr_address_watch_t);
+ALLOC_DEFINE(qdr_address_watch_t);
+
+static void qdr_watch_invoker(qdr_core_t *core, qdr_general_work_t *work);
+static void qdr_core_watch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_core_unwatch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_address_watch_free_CT(qdr_address_watch_t *watch);
+
+//==================================================================================
+// Core Interface Functions
+//==================================================================================
+qdr_watch_handle_t qdr_core_watch_address(qdr_core_t                 *core,
+                                          const char                 *address,
+                                          char                        aclass,
+                                          char                        phase,
+                                          qdr_address_watch_update_t  on_watch,
+                                          void                       *context)
+{
+    static sys_atomic_t next_handle;
+    qdr_action_t *action = qdr_action(qdr_core_watch_address_CT, "watch_address");
+
+    action->args.io.address       = qdr_field(address);
+    action->args.io.address_class = aclass;
+    action->args.io.address_phase = phase;
+    action->args.io.watch_handler = on_watch;
+    action->args.io.context       = context;
+    action->args.io.value32_1     = sys_atomic_inc(&next_handle);
+
+    qdr_action_enqueue(core, action);
+    return action->args.io.value32_1;
+}
+
+
+void qdr_core_unwatch_address(qdr_core_t *core, qdr_watch_handle_t handle)
+{
+    qdr_action_t *action = qdr_action(qdr_core_unwatch_address_CT, "unwatch_address");
+
+    action->args.io.value32_1 = handle;
+    qdr_action_enqueue(core, action);
+}
+
+
+//==================================================================================
+// In-Core API Functions
+//==================================================================================
+void qdr_trigger_address_watch_CT(qdr_core_t *core, qdr_address_t *addr)
+{
+    const char          *address_hash = (char*) qd_hash_key_by_handle(addr->hash_handle);
+    qdr_address_watch_t *watch        = DEQ_HEAD(core->addr_watches);
+
+    while (!!watch) {
+        if (strcmp(watch->address_hash, address_hash) == 0) {
+            qdr_general_work_t *work = qdr_general_work(qdr_watch_invoker);
+            work->watch_handler     = watch->handler;
+            work->context           = watch->context;
+            work->local_consumers   = DEQ_SIZE(addr->rlinks);
+            work->in_proc_consumers = DEQ_SIZE(addr->subscriptions);
+            work->remote_consumers  = qd_bitmask_cardinality(addr->rnodes);
+            work->local_producers   = DEQ_SIZE(addr->inlinks);
+            qdr_post_general_work_CT(core, work);
+        }
+        watch = DEQ_NEXT(watch);
+    }
+}
+
+void qdr_address_watch_shutdown(qdr_core_t *core)
+{
+    qdr_address_watch_t *watch = DEQ_HEAD(core->addr_watches);
+    while (!!watch) {
+        DEQ_REMOVE(core->addr_watches, watch);
+        qdr_address_watch_free_CT(watch);
+        watch = DEQ_HEAD(core->addr_watches);
+    }
+}
+
+
+//==================================================================================
+// Local Functions
+//==================================================================================
+static void qdr_address_watch_free_CT(qdr_address_watch_t *watch)
+{
+    free(watch->address_hash);
+    free_qdr_address_watch_t(watch);
+}
+
+
+static void qdr_watch_invoker(qdr_core_t *core, qdr_general_work_t *work)
+{
+    work->watch_handler(work->context,
+                        work->local_consumers, work->in_proc_consumers, work->remote_consumers, work->local_producers);
+}
+
+
+static void qdr_core_watch_address_CT(qdr_core_t *core, qdr_action_t *action, bool discard)

Review comment:
       Should this invoke the watch handler if there is a pre-existing address that matches?  So the initial subscriber (etc) state can be published?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] ted-ross commented on a change in pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
ted-ross commented on a change in pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435#discussion_r751254686



##########
File path: include/qpid/dispatch/router_core.h
##########
@@ -160,6 +169,64 @@ void qdr_send_to2(qdr_core_t *core, qd_message_t *msg, const char *addr,
                   bool exclude_inprocess, bool control);
 
 
+/**
+ ******************************************************************************
+ * Address watch functions
+ ******************************************************************************
+ */
+
+typedef uint32_t qdr_watch_handle_t;
+
+/**
+ * Handler for updates on watched addresses.  This function shall be invoked on an IO thread.
+ * 
+ * Note:  This function will be invoked when a watched address has a change in reachability.
+ * It is possible that the function may be called when no change occurs, particularly when an
+ * address is removed from the core address table.
+ *
+ * @param context The opaque context supplied in the call to qdr_core_watch_address
+ * @param local_consumers Number of consuming (outgoing) links for this address on this router
+ * @param in_proc_consumers Number of in-process consumers for this address on this router
+ * @param remote_consumers Number of remote routers with consumers for this address
+ * @param local_producers Number of producing (incoming) links for this address on this router
+ */
+typedef void (*qdr_address_watch_update_t)(void     *context,
+                                           uint32_t  local_consumers,
+                                           uint32_t  in_proc_consumers,
+                                           uint32_t  remote_consumers,
+                                           uint32_t  local_producers);
+
+/**
+ * qdr_core_watch_address
+ *
+ * Subscribe to watch for changes in the reachability for an address.  It is safe to invoke this
+ * function from an IO thread.
+ * 
+ * @param core Pointer to the core module
+ * @param address The address to be watched
+ * @param aclass Address class character
+ * @param phase Address phase character ('0' .. '9')
+ * @param on_watch The handler function
+ * @param context The opaque context sent to the handler on all invocations
+ * @return Watch handle to be used when canceling the watch
+ */
+qdr_watch_handle_t qdr_core_watch_address(qdr_core_t                 *core,
+                                          const char                 *address,
+                                          char                        aclass,
+                                          char                        phase,
+                                          qdr_address_watch_update_t  on_watch,
+                                          void                       *context);
+
+/**
+ * qdr_core_unwatch_address
+ * 
+ * Cancel an address watch subscription.  It is safe to invoke this function from an IO thread.

Review comment:
       Yes, this is a good catch.  It will require a bit of re-work, but I'll make it so that this cannot happen.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [qpid-dispatch] ganeshmurthy closed pull request #1435: DISPATCH-2267 - IO-thread facility to watch for changes to address reachability

Posted by GitBox <gi...@apache.org>.
ganeshmurthy closed pull request #1435:
URL: https://github.com/apache/qpid-dispatch/pull/1435


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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