Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Logic that needs to be processed in case of ndrxd restart.
0003  *
0004  * @file restart.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <errno.h>
0038 #include <memory.h>
0039 #include <sys/types.h>
0040 #include <dirent.h>
0041 #include <sys/stat.h>
0042 #include <utlist.h>
0043 
0044 #include <ndrstandard.h>
0045 #include <ndrxd.h>
0046 #include <atmi_int.h>
0047 #include <nstopwatch.h>
0048 
0049 #include <ndebug.h>
0050 #include <cmd_processor.h>
0051 #include <signal.h>
0052 
0053 #include "userlog.h"
0054 #include "sys_unix.h"
0055 
0056 /*---------------------------Externs------------------------------------*/
0057 /*---------------------------Macros-------------------------------------*/
0058 /*---------------------------Enums--------------------------------------*/
0059 /*---------------------------Typedefs-----------------------------------*/
0060 /*---------------------------Globals------------------------------------*/
0061 /*---------------------------Statics------------------------------------*/
0062 /*---------------------------Prototypes---------------------------------*/
0063 exprivate int request_info(char *qname);
0064 
0065 /**
0066  * Do actions required for restart.
0067  */
0068 expublic int do_restart_actions(void)
0069 {
0070     int ret=EXSUCCEED;
0071     string_list_t* qlist = NULL;
0072     string_list_t* elt = NULL;
0073     static char    server_prefix[NDRX_MAX_Q_SIZE+1];
0074     static int     server_prefix_len;
0075     
0076     /* Load app config */
0077     /*
0078     if (EXSUCCEED!=(ret = load_active_config(&G_app_config, &G_process_model,
0079             &G_process_model_hash, &G_process_model_pid_hash)))
0080      */
0081     if (EXSUCCEED!=(ret = load_active_config_live()))
0082     {
0083         NDRX_LOG(log_error, "Failed to load active configuration - "
0084                 "cannot restart!");
0085         goto out;
0086     }
0087 
0088     snprintf(server_prefix, sizeof(server_prefix), NDRX_ADMIN_FMT_PFX, G_sys_config.qprefix);
0089     server_prefix_len=strlen(server_prefix);
0090     NDRX_LOG(log_debug, "server_prefix=[%s]/%d", server_prefix, 
0091                         server_prefix_len);
0092 
0093     NDRX_LOG(log_warn, "Scanning process queues for info gathering");
0094 
0095     /* Do the directory listing here... and perform the check! */
0096     
0097     qlist = ndrx_sys_mqueue_list_make(G_sys_config.qpath, &ret);
0098 
0099     if (EXSUCCEED!=ret)
0100     {
0101         NDRX_LOG(log_error, "posix queue listing failed!");
0102         EXFAIL_OUT(ret);
0103     }
0104 
0105     LL_FOREACH(qlist,elt)
0106     {
0107         if (0==strncmp(elt->qname, server_prefix, server_prefix_len)) 
0108         {
0109             NDRX_LOG(log_warn, "Requesting info from: [%s]", elt->qname);
0110             ret=request_info(elt->qname);
0111         }
0112         
0113         /* Check the status of above run */
0114         if (EXSUCCEED!=ret)
0115             goto out;
0116     }
0117 
0118     /* Reset wait timer for learning */
0119     ndrx_stopwatch_reset(&(G_sys_config.time_from_restart));
0120 
0121 out:
0122 
0123     if (NULL!=qlist)
0124     {
0125         ndrx_string_list_free(qlist);
0126     }
0127 
0128     return ret;
0129 }
0130 
0131 /**
0132  * Send info request to server.
0133  */
0134 exprivate int request_info(char *qname)
0135 {
0136     int ret=EXSUCCEED;
0137     command_call_t call;
0138     memset(&call, 0, sizeof(call));
0139     
0140     if (EXSUCCEED!=(cmd_generic_call(NDRXD_COM_SRVINFO_RQ, NDRXD_SRC_ADMIN,
0141                 NDRXD_CALL_TYPE_GENERIC,
0142                 &call, sizeof(call),
0143                 G_command_state.listenq_str,
0144                 G_command_state.listenq,
0145                 (mqd_t)EXFAIL,
0146                 qname,
0147                 0, NULL,
0148                 NULL,
0149                 NULL,
0150                 NULL,
0151                 EXFALSE)))
0152     {
0153         /* Will ignore any error */
0154         NDRX_LOG(log_error, "Failed to call: [%s]", qname);
0155     }
0156     
0157 out:
0158     return ret;
0159 }
0160 /**
0161  * Do checking about shall we switch to normal mode.
0162  * @return 
0163  */
0164 expublic int do_restart_chk(void)
0165 {
0166     int ret=EXSUCCEED;
0167     int delta;
0168     
0169     if ((delta=ndrx_stopwatch_get_delta_sec(&(G_sys_config.time_from_restart))) > G_app_config->restart_to_check)
0170     {
0171         NDRX_LOG(log_warn, "Restart learning time spent over... "
0172                 "switching to normal state!");
0173         G_sys_config.restarting = EXFALSE;
0174     }
0175     else
0176     {
0177         NDRX_LOG(log_warn, "Still learning for %d secs, limit: %d", 
0178                 delta, G_app_config->restart_to_check);
0179     }
0180     
0181 out:
0182     return ret;    
0183 }
0184 
0185 
0186 /* vim: set ts=4 sw=4 et smartindent: */