Back to home page

Enduro/X

 
 

    


0001 #!/bin/bash
0002 ##
0003 ## @brief Test the failover of TMSRV+TMQ with the singleton groups between two domains - test launcher
0004 ##  Testing strategy would be following:
0005 ##    - Have two domains, both use the same data folder for tmq/srv and virtual node id (-n2)
0006 ##    - tmsrv+tmq in both domains are in "GRP1" lock group, whith shared locks.
0007 ##    - tmsrv+tmq has the same SRVIDs
0008 ##    - Two automatic queues are configured: Q1 and Q2, when QFWD1 and QFWD2 servers to send msgs between the
0009 ##     the queues.
0010 ##  During the test, client keeps loading the Q1 with messages, periodically (at random points)
0011 ##  for active domain the exsinglesv is shutdown + sleep (of other node exsinglesv try to lock) + and started back
0012 ##  the client waits for "locked wait" and for Q bring up... and the enqueues again.
0013 ##  when all this run for some 5 minutes. queues are re-configured to manual, and full number of enqueued messages
0014 ##  is read.
0015 ##  Additionally, the exsinglesv lock scripts removes transactinos logs which are not prepared i.e.
0016 ##  If not having this “:S:50:” In transaction, then transaction log is removed, the tmrecoversv shall scan
0017 ##  for prepared lost transactions and shall recover them.
0018 ##
0019 ## @file run.sh
0020 ##
0021 ## -----------------------------------------------------------------------------
0022 ## Enduro/X Middleware Platform for Distributed Transaction Processing
0023 ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0024 ## Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0025 ## This software is released under one of the following licenses:
0026 ## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0027 ## See LICENSE file for full text.
0028 ## -----------------------------------------------------------------------------
0029 ## AGPL license:
0030 ## 
0031 ## This program is free software; you can redistribute it and/or modify it under
0032 ## the terms of the GNU Affero General Public License, version 3 as published
0033 ## by the Free Software Foundation;
0034 ##
0035 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY
0036 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0037 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0038 ## for more details.
0039 ##
0040 ## You should have received a copy of the GNU Affero General Public License along 
0041 ## with this program; if not, write to the Free Software Foundation, Inc., 
0042 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0043 ##
0044 ## -----------------------------------------------------------------------------
0045 ## A commercial use license is available from Mavimax, Ltd
0046 ## contact@mavimax.com
0047 ## -----------------------------------------------------------------------------
0048 ##
0049 
0050 export TESTNAME="test104_tmqfailover"
0051 
0052 PWD=`pwd`
0053 if [ `echo $PWD | grep $TESTNAME ` ]; then
0054     # Do nothing 
0055     echo > /dev/null
0056 else
0057     # started from parent folder
0058     pushd .
0059     echo "Doing cd"
0060     cd $TESTNAME
0061 fi;
0062 
0063 . ../testenv.sh
0064 
0065 export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
0066 export PATH=$PATH:$TESTDIR
0067 export NDRX_ULOG=$TESTDIR
0068 export NDRX_TOUT=25
0069 export NDRX_SILENT=Y
0070 
0071 ################################################################################
0072 # 6 gives:
0073 # lock expire if not refreshed in 6 seconds
0074 # lock take over by other node if file unlocked: 12 sec
0075 # exsinglesv periodic scans / locks 2 sec
0076 export NDRX_SGREFRESH=6
0077 ################################################################################
0078 
0079 if [ "$(uname)" == "Darwin" ]; then
0080     export NDRX_LIBEXT="dylib"
0081 else
0082     export NDRX_LIBEXT="so"
0083 fi
0084 
0085 UNAME=`uname`
0086 
0087 #
0088 # Get the crash lib...
0089 #
0090 case $UNAME in
0091 
0092   Darwin)
0093     export NDRX_PLUGINS=libt86_lcf.dylib
0094     export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$TESTDIR/../test086_tmqlimit
0095     ;;
0096 
0097   AIX)
0098     export NDRX_PLUGINS=libt86_lcf.so
0099     export LIBPATH=$LIBPATH:$TESTDIR/../test086_tmqlimit
0100     ;;
0101 
0102   *)
0103     export NDRX_PLUGINS=libt86_lcf.so
0104     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TESTDIR/../test086_tmqlimit
0105     ;;
0106 esac
0107 
0108 #
0109 # Common configuration between the domains
0110 #
0111 export NDRX_CCONFIG1=$TESTDIR/app-common.ini
0112 
0113 # Check if the /etc/os-release file exists
0114 if [ -e /etc/os-release ]; then
0115     if grep -q "Raspbian" /etc/os-release; then
0116         echo "Raspbian detected - no fsync"
0117         export NDRX_CCONFIG1=$TESTDIR/app-common-no-fsync.ini
0118     fi
0119 fi
0120 
0121 #
0122 # Domain 1 - here client will live
0123 #
0124 set_dom1() {
0125     echo "Setting domain 1"
0126     . ../dom1.sh
0127     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1.xml
0128     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
0129     export NDRX_LOG=$TESTDIR/ndrx-dom1.log
0130     export NDRX_CCONFIG=$TESTDIR/app-dom1.ini
0131     #export NDRX_DEBUG_CONF=$TESTDIR/debug-dom1.conf
0132 }
0133 
0134 #
0135 # Domain 2 - here server will live
0136 #
0137 set_dom2() {
0138     echo "Setting domain 2"
0139     . ../dom2.sh    
0140     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom2.xml
0141     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom2.log
0142     export NDRX_LOG=$TESTDIR/ndrx-dom2.log
0143     export NDRX_CCONFIG=$TESTDIR/app-dom2.ini
0144     #export NDRX_DEBUG_CONF=$TESTDIR/debug-dom2.conf
0145 }
0146 
0147 #
0148 # Generic exit function
0149 #
0150 function go_out {
0151     echo "Test exiting with: $1"
0152     
0153     set_dom1;
0154     xadmin stop -y
0155     xadmin down -y
0156 
0157     set_dom2;
0158     xadmin stop -y
0159     xadmin down -y
0160 
0161     # If some alive stuff left...
0162     xadmin killall atmiclt104
0163 
0164     popd 2>/dev/null
0165     exit $1
0166 }
0167 
0168 # clean up some old stuff
0169 rm *.log 2>/dev/null
0170 rm lock_* 2>/dev/null
0171 rm ULOG* 2>/dev/null
0172 rm -rf RM1 RM2 qdata 2>/dev/null
0173 
0174 # where to store the data
0175 mkdir RM1 RM2 qdata
0176 
0177 # Any bridges that are live must be killed!
0178 xadmin killall tpbridge
0179 
0180 set_dom1;
0181 xadmin down -y
0182 xadmin start -y || go_out 1
0183 
0184 set_dom2;
0185 xadmin down -y
0186 xadmin start -y || go_out 2
0187 
0188 echo "Sleep 15 for link"
0189 sleep 15
0190 
0191 set_dom1;
0192 xadmin psg
0193 xadmin psc
0194 
0195 ################################################################################
0196 echo ">>> Loop enqueue + crash"
0197 ################################################################################
0198 NUM=60
0199 
0200 counter=0
0201 while [ $counter -lt $NUM ]
0202 do
0203     echo "Loop [$counter]"
0204 
0205     # enq single msg...
0206     ./atmiclt104 enq $counter
0207     RET=$?
0208 
0209     if [[ "X$RET" != "X0" ]]; then
0210         echo "./atmiclt104 enq $counter failed"
0211         go_out $RET
0212     fi
0213 
0214     if [ "$(($counter % 5))" == "0" ]; then
0215         echo "Doing failover..."
0216         # failover the groups...
0217         # whoever will first get the lock that will win...
0218         xadmin killall exsinglesv
0219         
0220         # let ndrxd to collect, otherwise we might remove some msg where
0221         # some TM already writes the message to disk...
0222         # remove transaction logs which are not
0223         sleep 5
0224         xadmin ps -a tmsrv
0225         # prepared...
0226         if [ "$(($counter % 3))" == "0" ]; then
0227             grep -L ":S:50" $TESTDIR/RM1/* | xargs rm
0228             grep -L ":S:50" $TESTDIR/RM2/* | xargs rm
0229         fi
0230 
0231         echo "Sleep 15... to bring processes back... (with some buffer for msg read)"
0232         sleep 15
0233 
0234         set_dom1;
0235         xadmin psg
0236         xadmin mqlq
0237         xadmin ppm
0238 
0239         set_dom2;
0240         xadmin psg
0241         xadmin mqlq
0242         xadmin ppm
0243     else
0244         echo "Echo let processes to run for 1 sec"
0245         sleep 1
0246     fi
0247 
0248     # swap the domains of attempts...
0249     if [ "$(($counter % 2))" == "0" ]; then
0250         set_dom1;
0251         xadmin psg
0252         xadmin ppm
0253         xadmin mqlq
0254     else
0255         set_dom2;
0256         xadmin psg
0257         xadmin ppm
0258         xadmin mqlq
0259     fi
0260 
0261     ((counter++))
0262 
0263 done
0264 
0265 ################################################################################
0266 echo ">>> Validate $NUM messages"
0267 ################################################################################
0268 
0269 # disable auto from Qs....
0270 xadmin mqch -n2 -i 200 -qQ1,autoq=n
0271 xadmin mqch -n2 -i 200 -qQ2,autoq=n
0272 sleep 5
0273 # lets Q to complete...
0274 xadmin mqlc
0275 xadmin mqlq
0276 
0277 # validate that all messages are in place
0278 # enq single msg...
0279 ./atmiclt104 deq $NUM
0280 RET=$?
0281 
0282 if [[ "X$RET" != "X0" ]]; then
0283     echo "./atmiclt104 deq $counter failed"
0284     go_out $RET
0285 fi
0286 
0287 RET=$?
0288 
0289 if [[ "X$RET" != "X0" ]]; then
0290     go_out $RET
0291 fi
0292 
0293 # Catch is there is test error!!!
0294 if [ "X`grep TESTERROR *.log`" != "X" ]; then
0295     echo "Test error detected!"
0296     RET=-2
0297 fi
0298 
0299 go_out $RET
0300 
0301 
0302 # vim: set ts=4 sw=4 et smartindent:
0303