Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Print singleton groups
0003  *
0004  * @file cmd_psg.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 <memory.h>
0038 #include <sys/param.h>
0039 
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 
0043 #include <ndrx.h>
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <errno.h>
0048 #include <lcf.h>
0049 #include <linenoise.h>
0050 
0051 #include "nclopt.h"
0052 
0053 #include <exhash.h>
0054 #include <utlist.h>
0055 #include <userlog.h>
0056 #include <singlegrp.h>
0057 #include <lcfint.h>
0058 
0059 
0060 /*---------------------------Externs------------------------------------*/
0061 /*---------------------------Macros-------------------------------------*/
0062 /*---------------------------Enums--------------------------------------*/
0063 /*---------------------------Typedefs-----------------------------------*/
0064 /*---------------------------Globals------------------------------------*/
0065 /*---------------------------Statics------------------------------------*/
0066 
0067 /**
0068  * Decode flags
0069  */
0070 exprivate char *decode_flags(unsigned short flags)
0071 {
0072     static char buf[10];
0073 
0074     buf[0] = EXEOS;
0075 
0076     if (flags & NDRX_SG_NO_ORDER)
0077     {
0078         strcat(buf, "n");
0079     }
0080 
0081     /* group is in use... as defined as singleton */
0082     if (flags & NDRX_SG_SINGLETON)
0083     {
0084         strcat(buf, "i");
0085     }
0086 
0087     if (flags & NDRX_SG_VERIFY)
0088     {
0089         strcat(buf, "v");
0090     }
0091 
0092     return buf;
0093 }
0094 
0095 /**
0096  * Print singleton groups
0097  * @param p_cmd_map
0098  * @param argc
0099  * @param argv
0100  * @return SUCCEED
0101  */
0102 expublic int cmd_psg(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0103 {
0104     int ret = EXSUCCEED;
0105     int i;
0106     struct timespec ts;
0107     long long refresh;
0108     int print_all = EXFALSE;
0109     int print_page_2 = EXFALSE;
0110 
0111     ncloptmap_t clopt[] =
0112     {
0113         {'a', BFLD_INT, (void *)&print_all, 0, 
0114                             NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print all groups"},
0115         {'2', BFLD_INT, (void *)&print_page_2, 0, 
0116                             NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print page 2 (nodes)"},
0117         {0}
0118     };
0119 
0120     /* parse command line */
0121     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0122     {
0123         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0124         EXFAIL_OUT(ret);
0125     }
0126 
0127     if (print_page_2)
0128     {
0129         /* print header: */
0130         fprintf(stderr, "SGID                           CNODES   SEQUENCE\n");
0131         fprintf(stderr, "---- -------------------------------- ----------\n");
0132     }
0133     else
0134     {
0135         /* print header: */
0136         fprintf(stderr, "SGID LCKD MMON SBOOT CBOOT LPSRVID    LPPID LPPROCNM          REFRESH RSN FLAGS\n");
0137         fprintf(stderr, "---- ---- ---- ----- ----- ------- -------- ---------------- -------- --- -----\n");
0138     }
0139 
0140     /* process groups: */
0141     for (i=1; i<=ndrx_G_libnstd_cfg.pgmax; i++)
0142     {
0143         ndrx_sg_shm_t *p_shm=ndrx_sg_get(i);
0144         ndrx_sg_shm_t local;
0145         ndrx_sg_load(&local, p_shm);
0146 
0147         /* print only used groups by default
0148          * groups with NDRX_SG_SINGLETON are pushed to psg
0149          */
0150         if (!( local.is_locked || (local.flags & NDRX_SG_SINGLETON)) && !print_all )
0151         {
0152             continue;
0153         }
0154 
0155         if (local.is_locked)
0156         {
0157             ndrx_realtime_get(&ts);
0158             refresh = ((long long)ts.tv_sec-(long long)local.last_refresh)*1000;
0159         }
0160         else
0161         {
0162             refresh=-1;
0163         }
0164 
0165         if (print_page_2)
0166         {
0167             char node_buf[CONF_NDRX_NODEID_COUNT+1];
0168             int j;
0169             char *p;
0170             memset(node_buf, '0', sizeof(node_buf));
0171             node_buf[CONF_NDRX_NODEID_COUNT] = EXEOS;
0172 
0173             for (j=0; j<CONF_NDRX_NODEID_COUNT; j++)
0174             {
0175                 if (local.sg_nodes[j])
0176                 {
0177                     /* node used */
0178                     node_buf[local.sg_nodes[j]-1] = 'Y';
0179                 }
0180                 else
0181                 {
0182                     /* array is sorted of used nodes */
0183                     break;
0184                 }
0185             }
0186 
0187             fprintf(stdout, "%4d %s %10ld\n",
0188                     i, node_buf, local.sequence);
0189         }
0190         else
0191         {
0192             fprintf(stdout, "%4d %-4.4s %-4.4s %-5.5s %-5.5s %7d %8d %-16.16s %8.8s %3d %-5.5s\n",
0193                     i, 
0194                     local.is_locked?"Y":"N",
0195                     local.is_mmon?"Y":"N",
0196                     local.is_srv_booted?"Y":"N",
0197                     local.is_clt_booted?"Y":"N",
0198                     local.lockprov_srvid,
0199                     (int)local.lockprov_pid,
0200                     local.lockprov_procname,
0201                     ndrx_decode_msec((long)refresh, 0, 0, 2),
0202                     local.reason,
0203                     decode_flags(local.flags)
0204                     );
0205         }
0206     }
0207 
0208 out:
0209     return ret;
0210 }
0211 
0212 /**
0213  * Put in maintenance mode
0214  * @param p_cmd_map
0215  * @param argc
0216  * @param argv
0217  * @return SUCCEED
0218  */
0219 expublic int cmd_mmon(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0220 {
0221     int ret=EXSUCCEED;
0222 
0223     if (NULL!=ndrx_G_shmcfg)
0224     {
0225         ndrx_G_shmcfg->is_mmon=1;
0226         __sync_synchronize();
0227         printf("OK\n");
0228     }
0229     else
0230     {
0231         ret = EXFAIL;
0232     }
0233 
0234     return ret;
0235 }
0236 
0237 /**
0238  * Disbale maintenace mode
0239  */
0240 expublic int cmd_mmoff(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0241 {
0242     int ret=EXSUCCEED;
0243 
0244     if (NULL!=ndrx_G_shmcfg)
0245     {
0246         ndrx_G_shmcfg->is_mmon=0;
0247         __sync_synchronize();
0248         printf("OK\n");
0249     }
0250     else
0251     {
0252         ret = EXFAIL;
0253     }
0254 
0255     return ret;
0256 }
0257 
0258 /* vim: set ts=4 sw=4 et smartindent: */