Ntfd will not send response to a client when client already down.
This will avoid timeout when ntfd send via mds.
---
 src/ntf/ntfd/ntfs_com.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/ntf/ntfd/ntfs_com.h |   6 +++
 src/ntf/ntfd/ntfs_evt.c |   3 ++
 src/ntf/ntfd/ntfs_mds.c |   7 ++-
 4 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/src/ntf/ntfd/ntfs_com.c b/src/ntf/ntfd/ntfs_com.c
index 35435bb..c9fce2d 100644
--- a/src/ntf/ntfd/ntfs_com.c
+++ b/src/ntf/ntfd/ntfs_com.c
@@ -29,13 +29,133 @@
 #include "ntf/common/ntfsv_enc_dec.h"
 #include "ntf/common/ntfsv_mem.h"
 #include "ntfs_mbcsv.h"
+#include "base/osaf_utility.h"
 #if DISCARDED_TEST
 /* TODO REMOVE TEST */
 int disc_test_cntr = 1;
 #endif
 
+typedef struct client_down_list_tag {
+       MDS_DEST mds_dest;
+       struct client_down_list_tag *next;
+} CLIENT_DOWN_LIST;
+
+CLIENT_DOWN_LIST *client_down_list_head; /* Client down reccords */
+pthread_mutex_t client_down_mutex;
+bool client_finalized_flag;
+
 int activeController() { return (ntfs_cb->ha_state == SA_AMF_HA_ACTIVE); }
 
+void set_client_finalized_flag(void) { client_finalized_flag = true; }
+
+void mutex_client_down_init(void)
+{
+       int rc;
+
+       TRACE_ENTER();
+       rc = pthread_mutex_init(&client_down_mutex, NULL);
+       if (rc != 0)
+               osaf_abort(rc);
+       client_finalized_flag = false;
+       TRACE_LEAVE();
+}
+
+/**
+ * @brief Add mds_dest tag into client down list
+ * @param mds_dest
+ */
+void add_client_down_list(MDS_DEST mds_dest)
+{
+       TRACE_ENTER();
+       // Prevent add to down list when client has successfully initialized.
+       if (!client_finalized_flag) {
+               CLIENT_DOWN_LIST *client_down_rec = NULL;
+
+               client_down_rec =
+                   (CLIENT_DOWN_LIST *)(malloc(sizeof(CLIENT_DOWN_LIST)));
+               if (client_down_rec == NULL) {
+                       LOG_ER("memory allocation for the CLIENT_DOWN_LIST "
+                              "failed");
+                       return;
+               }
+               memset(client_down_rec, 0, sizeof(CLIENT_DOWN_LIST));
+               client_down_rec->mds_dest = mds_dest;
+               client_down_rec->next = NULL;
+               osaf_mutex_lock_ordie(&client_down_mutex);
+               if (client_down_list_head == NULL) {
+                       client_down_list_head = client_down_rec;
+               } else {
+                       CLIENT_DOWN_LIST *p = client_down_list_head;
+
+                       while (p->next != NULL)
+                               p = p->next;
+                       p->next = client_down_rec;
+               }
+               osaf_mutex_unlock_ordie(&client_down_mutex);
+               TRACE_1("Added MDS dest: %" PRIx64, client_down_rec->mds_dest);
+       }
+       client_finalized_flag = false;
+       TRACE_LEAVE();
+}
+
+/**
+ * @brief Find and remove client from client down list
+ * @param mds_dest
+ */
+void remove_client_down_list(MDS_DEST mds_dest)
+{
+       CLIENT_DOWN_LIST *client_down_rec = client_down_list_head;
+       CLIENT_DOWN_LIST *prev = NULL;
+       TRACE_ENTER();
+       osaf_mutex_lock_ordie(&client_down_mutex);
+       while (client_down_rec != NULL) {
+               if (mds_dest == client_down_rec->mds_dest) {
+                       if (client_down_rec == client_down_list_head) {
+                               if (client_down_rec->next == NULL) {
+                                       client_down_list_head = NULL;
+                               } else {
+                                       client_down_list_head =
+                                           client_down_rec->next;
+                               }
+                       } else if (prev) {
+                               prev->next = client_down_rec->next;
+                       }
+                       TRACE("Deleted MDS dest: %" PRIx64,
+                             client_down_rec->mds_dest);
+                       free(client_down_rec);
+                       client_down_rec = NULL;
+                       break;
+               }
+               prev = client_down_rec;
+               client_down_rec = client_down_rec->next;
+       }
+       osaf_mutex_unlock_ordie(&client_down_mutex);
+       TRACE_LEAVE();
+}
+
+/**
+ * @brief  Check if client exists in down list
+ * @param  mds_dest
+ * @return true/false
+ */
+bool is_in_down_list(MDS_DEST mds_dest)
+{
+       bool found = false;
+       CLIENT_DOWN_LIST *client_down_rec = client_down_list_head;
+       TRACE_ENTER();
+       osaf_mutex_lock_ordie(&client_down_mutex);
+       while (client_down_rec != NULL) {
+               if (mds_dest == client_down_rec->mds_dest) {
+                       found = true;
+                       break;
+               }
+               client_down_rec = client_down_rec->next;
+       }
+       osaf_mutex_unlock_ordie(&client_down_mutex);
+       TRACE_LEAVE();
+       return found;
+}
+
 void client_added_res_lib(SaAisErrorT error, unsigned int clientId,
                          MDS_DEST mdsDest, MDS_SYNC_SND_CTXT *mdsCtxt,
                          SaVersionT *version)
diff --git a/src/ntf/ntfd/ntfs_com.h b/src/ntf/ntfd/ntfs_com.h
index b9e37da..92a9acc 100644
--- a/src/ntf/ntfd/ntfs_com.h
+++ b/src/ntf/ntfd/ntfs_com.h
@@ -205,6 +205,12 @@ bool is_client_clm_member(NODE_ID node_id, SaVersionT 
*client_ver);
 bool is_clm_init();
 bool is_stale_client(unsigned int clientId);
 
+void set_client_finalized_flag(void);
+void mutex_client_down_init(void);
+void add_client_down_list(MDS_DEST mds_dest);
+void remove_client_down_list(MDS_DEST mds_dest);
+bool is_in_down_list(MDS_DEST mds_dest);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/ntf/ntfd/ntfs_evt.c b/src/ntf/ntfd/ntfs_evt.c
index 19b2f60..a0be368 100644
--- a/src/ntf/ntfd/ntfs_evt.c
+++ b/src/ntf/ntfd/ntfs_evt.c
@@ -110,6 +110,7 @@ static uint32_t proc_ntfa_updn_mds_msg(ntfsv_ntfs_evt_t 
*evt)
                } else {
                        clientRemoveMDS(evt->fr_dest);
                }
+               remove_client_down_list(evt->fr_dest);
                break;
        default:
                TRACE("Unknown evt type!!!");
@@ -244,6 +245,7 @@ uint32_t ntfs_cb_init(ntfs_cb_t *ntfs_cb)
        } else {
                ntfs_cb->cache_size = NTFSV_READER_CACHE_DEFAULT;
        }
+       mutex_client_down_init();
        TRACE_LEAVE();
        return NCSCC_RC_SUCCESS;
 }
@@ -311,6 +313,7 @@ static uint32_t proc_finalize_msg(ntfs_cb_t *cb, 
ntfsv_ntfs_evt_t *evt)
            evt->info.msg.info.api_info.param.finalize.client_id;
 
        TRACE_ENTER2("client_id %u", client_id);
+       set_client_finalized_flag();
        clientRemoved(client_id);
        client_removed_res_lib(SA_AIS_OK, client_id, evt->fr_dest,
                               &evt->mds_ctxt);
diff --git a/src/ntf/ntfd/ntfs_mds.c b/src/ntf/ntfd/ntfs_mds.c
index 5f40c6e..eeb107a 100644
--- a/src/ntf/ntfd/ntfs_mds.c
+++ b/src/ntf/ntfd/ntfs_mds.c
@@ -950,10 +950,11 @@ static uint32_t mds_svc_event(struct ncsmds_callback_info 
*info)
                        // checkpoint of initializing new client in standby or
                        // checking if client has already downed in active.
                        SearchAndSetClientsDownFlag(evt->fr_dest);
+                       add_client_down_list(evt->fr_dest);
 
                        /* Push the event and we are done */
                        if (m_NCS_IPC_SEND(&ntfs_cb->mbx, evt,
-                                          NCS_IPC_PRIORITY_HIGH) !=
+                                          NCS_IPC_PRIORITY_LOW) !=
                            NCSCC_RC_SUCCESS) {
                                TRACE("ipc send failed");
                                ntfs_evt_destroy(evt);
@@ -974,6 +975,7 @@ static uint32_t mds_svc_event(struct ncsmds_callback_info 
*info)
                                TRACE_8("AVD ADEST UP");
                                ncs_sel_obj_ind(&ntfs_cb->usr2_sel_obj);
                        }
+                       remove_client_down_list(info->info.svc_evt.i_dest);
                }
        }
 
@@ -1280,6 +1282,9 @@ uint32_t ntfs_mds_msg_send(ntfs_cb_t *cb, ntfsv_msg_t 
*msg, MDS_DEST *dest,
        MDS_SEND_INFO *send_info = &mds_info.info.svc_send;
        uint32_t rc = NCSCC_RC_SUCCESS;
 
+       /* skip sending message if agent is already down */
+       if (is_in_down_list(*dest))
+               return rc;
        /* populate the mds params */
        memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
 
-- 
2.7.4



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to