forked from ssinger/slony1-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_test.sh
executable file
·807 lines (719 loc) · 21.2 KB
/
run_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#!/bin/sh
#
pgbindir=${PGBINDIR:-"/usr/local/pgsql/bin"}
numerrors=0
testname=$1
if [ -z "$testname" ]; then
echo "usage $0 testname"
exit 1;
fi
if [ ! -d "$testname" ]; then
echo "No such test $testname"
exit 1;
fi
if [ -z "$2" ]; then
case `uname` in
SunOS*)
bash $0 $1 1
retcode=$?
if [ $retcode -eq 127 ]; then
echo "Under SunOS (Solaris) we require you have bash installed, and in your path $testname"
fi
exit $retcode
;;
AIX*)
bash $0 $1 1
retcode=$?
if [ $retcode -eq 127 ]; then
echo "Under AIX we require you have bash installed, and in your path to run $testname"
fi
exit $retcode
;;
*)
;;
esac
fi
TESTSTARTTIME=`date +"%Y-%m-%d %H:%M:%S %Z"`
if [ ! -x "$pgbindir/psql" ]; then
echo "please set the PGBINDIR environment variable to the directory containing psql, createdb, ..."
exit 1;
fi
# Display the test documentation
echo "test: $testname"
echo "----------------------------------------------------"
cat $testname/README
echo "----------------------------------------------------"
#load settings
. settings.ik
. $testname/settings.ik
. support_funcs.sh
echo "Test by ${SLONYTESTER} to be summarized in ${SLONYTESTFILE}"
trap '
echo ""
echo "**** user abort"
stop_processes
exit 1
' 2 15
stop_processes()
{
node=1
while : ; do
eval workerpid=\$worker${node}_pid
if [ ! -z $workerpid ]; then
echo "**** killing worker $node"
kill -15 $workerpid
fi
if [ ${node} -ge ${WORKERS} ]; then
break;
else
node=`expr ${node} + 1`
fi
done
stop_poll
stop_slons
}
stop_poll()
{
if [ ! -z ${poll_pid} ]; then
case `uname` in
MINGW32*)
foo=`ps |awk '{ print $1 }'| grep ${poll_pid}`
if [ ! -z "$foo" ]; then
echo "***** killing poll_cluster"
kill -15 ${poll_pid}
fi
;;
*)
ps -p ${poll_pid} >/dev/null
if [ $? -eq 0 ]; then
echo "***** killing poll_cluster"
kill -15 ${poll_pid}
fi
;;
esac
fi
}
stop_slons()
{
node=1
while : ; do
SLON_BUILD=$PGBINDIR SLON_CONF=${mktmp}/slon-conf.${node} $SLTOOLDIR/start_slon.sh stop
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=`expr ${node} + 1`
fi
done
}
init_preamble() {
node=1
while : ; do
eval cluster=\$CLUSTER${node}
if [ -n "${cluster}" ]; then
echo "CLUSTER NAME = ${cluster};" > $mktmp/slonik.preamble
if [ ${node} -ge ${NUMCLUSTERS} ]; then
break;
else
node=expr ${node} + 1
fi
else
break;
fi
done
node=1
while : ; do
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval port=\$PORT${node}
echo "define node${node} ${node};" >> $mktmp/slonik.preamble
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
conninfo="dbname=${db} host=${host} user=${user} port=${port}"
echo "NODE ${node} ADMIN CONNINFO = '${conninfo}';" >> $mktmp/slonik.preamble
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=`expr ${node} + 1`
fi
else
break;
fi
done
echo "include <${mktmp}/slonik.preamble>;" > $mktmp/slonik.script
}
store_node()
{
originnode=${ORIGINNODE:-"1"}
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval oport=\$PORT${originnode}
if [ -n "${odb}" -a "${ohost}" -a "${ouser}" -a "${oport}" ]; then
node=1
while : ; do
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval port=\$PORT${node}
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
if [ ${node} -ne ${originnode} ]; then
echo "STORE NODE (id=@node${node}, comment='node ${node}', event node=${originnode});" >> $mktmp/slonik.script
fi
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
else
break;
fi
done
else
err 3 "No origin in ${odb} ${ohost} ${ouser}"
fi
}
store_path()
{
i=1
while : ; do
eval db=\$DB${i}
eval host=\$HOST${i}
eval user=\$USER${i}
eval port=\$PORT${i}
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
j=1
while : ; do
if [ ${i} -ne ${j} ]; then
eval bdb=\$DB${j}
eval bhost=\$HOST${j}
eval buser=\$WEAKUSER${j}
eval bport=\$PORT${j}
if [ -n "${bdb}" -a "${bhost}" -a "${buser}" -a "${bport}" ]; then
echo "STORE PATH (SERVER=@node${i}, CLIENT=@node${j}, CONNINFO='dbname=${db} host=${host} user=${buser} port=${port}');" >> $mktmp/slonik.script
else
err 3 "No conninfo"
fi
fi
if [ ${j} -ge ${NUMNODES} ]; then
break;
else
j=$((${j} + 1))
fi
done
if [ ${i} -ge ${NUMNODES} ]; then
break;
else
i=$((${i} +1))
fi
else
err 3 "no DB"
fi
done
}
init_origin_rdbms()
{
originnode=${ORIGINNODE:-"1"}
eval db=\$DB${originnode}
eval host=\$HOST${originnode}
eval user=\$USER${originnode}
eval weakuser=\$WEAKUSER${originnode}
eval pgbindir=\$PGBINDIR${originnode}
eval port=\$PORT${originnode}
if [ -n "${db}" -a "${host}" -a "${user}" ]; then
status "creating origin DB: $user -h $host -U $user -p $port $db"
$pgbindir/createdb -O $user -h $host -U $user -p $port --encoding $ENCODING -T template0 $db 1> ${mktmp}/createdb.${originnode} 2> ${mktmp}/createdb.${originnode}
if [ $? -ne 0 ]; then
err 3 "An error occurred trying to $pgbindir/createdb -O $user -h $host -U $user -p $port --encoding $ENCODING -T template0 $db, ${mktmp}/createdb.${originnode} for details"
fi
else
err 3 "No db '${db}' or host '${host}' or user '${user}' or port '${port}' specified"
fi
status "add plpgsql to Origin"
$pgbindir/createlang -h $host -U $user -p $port plpgsql $db
status "loading origin DB with $testname/init_schema.sql"
$pgbindir/psql -h $host -p $port $db $user < $testname/init_schema.sql 1> ${mktmp}/init_schema.sql.${originnode} 2>${mktmp}/init_schema.sql.${originnode}
status "setting up user ${weakuser} to have weak access to data"
$SHELL ${testname}/gen_weak_user.sh ${weakuser} > ${mktmp}/grant_weak_access.sql
$pgbindir/psql -h $host -p $port -d $db -U $user < ${mktmp}/grant_weak_access.sql > ${mktmp}/genweakuser.sql.${originnode} 2> ${mktmp}/genweakuser.sql.${originnode}
status "done"
}
create_subscribers()
{
originnode=${ORIGINNODE:-"1"}
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval oweakuser=\$WEAKUSER${originnode}
eval opgbindir=\$PGBINDIR${originnode}
eval oport=\$PORT${originnode}
if [ -n "${odb}" -a "${ohost}" -a "${ouser}" ]; then
node=1
while : ; do
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval weakuser=\$WEAKUSER${node}
eval pgbindir=\$PGBINDIR${node}
eval port=\$PORT${node}
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
if [ ${node} -ne ${originnode} ]; then
status "creating subscriber ${node} DB: $user -h $host -U $user -p $port $db"
$pgbindir/createdb -O $user -h $host -U $user -p $port --encoding $ENCODING -T template0 $db 1> ${mktmp}/createdb.${node} 2> ${mktmp}/createdb.${node}
status "add plpgsql to subscriber"
$pgbindir/createlang -h $host -U $user -p $port plpgsql $db
status "loading subscriber ${node} DB from $odb"
$opgbindir/pg_dump -h $ohost -U $ouser -p $oport $odb | $pgbindir/psql -h $host -p $port $db $user 1> ${mktmp}/init_schema.sql.${node} 2> ${mktmp}/init_schema.sql.${node}
status "done"
fi
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
else
break;
fi
done
else
err 3 "No ORIGINNODE defined"
fi
}
generate_weak_slony_grants ()
{
node=1
ROTBLS="sl_action_seq sl_config_lock sl_confirm sl_event
sl_event_seq sl_listen sl_local_node_id sl_log_1 sl_log_2
sl_log_status sl_node sl_path sl_registry
sl_seqlastvalue sl_seqlog sl_sequence sl_set sl_setsync
sl_status sl_subscribe sl_table"
RWTBLS="sl_nodelock sl_nodelock_nl_conncnt_seq"
while : ; do
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval weakuser=\$WEAKUSER${node}
eval pgbindir=\$PGBINDIR${node}
eval port=\$PORT${node}
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
$pgbindir/psql -h $host -p $port -U $user -d $db -c "grant usage on schema \"_${CLUSTER1}\" to ${weakuser};" > /dev/null 2> /dev/null
for table in `echo $ROTBLS`; do
$pgbindir/psql -h $host -p $port -U $user -d $db -c "grant select on \"_${CLUSTER1}\".${table} to ${weakuser};" > /dev/null 2> /dev/null
done
for table in `echo $RWTBLS`; do
$pgbindir/psql -h $host -p $port -U $user -d $db -c "grant all on \"_${CLUSTER1}\".${table} to ${weakuser};" > /dev/null 2> /dev/null
done
fi
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
done
}
drop_databases()
{
node=1
status "dropping database"
while : ; do
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval pgbindir=\$PGBINDIR${node}
eval port=\$PORT${node}
status "${db}"
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
$pgbindir/dropdb -U $user -h $host -p $port $db 1> ${mktmp}/dropdb.${node} 2> ${mktmp}/dropdb.${node}
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
else
break;
fi
done
status "done"
}
cleanup()
{
if [ ${numerrors} -eq 0 ]; then
rm -rf $mktmp
echo "***************************"
echo "test ${testname} completed successfully"
echo "***************************"
else
echo "there were ${numerrors} warnings during the run of $testname, check the files in $mktmp for more details"
fi
}
create_set()
{
if [ -f $testname/init_create_set.ik ]; then
cat $testname/init_create_set.ik >> $mktmp/slonik.script
fi
}
add_tables()
{ if [ -f $testname/init_add_tables.ik ]; then
cat $testname/init_add_tables.ik >> $mktmp/slonik.script
fi
}
init_cluster()
{
if [ -f $testname/init_cluster.ik ]; then
cat $testname/init_cluster.ik >> $mktmp/slonik.script
fi
}
subscribe_set()
{
if [ -f $testname/init_subscribe_set.ik ]; then
cat $testname/init_subscribe_set.ik >> $mktmp/slonik.script
fi
}
load_data()
{
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval opgbindir=\$PGBINDIR${originnode}
eval oport=\$PORT${originnode}
if [ -n "${odb}" -a "${ohost}" -a "${ouser}" ]; then
if [ -f $testname/init_data.sql ]; then
$opgbindir/psql -h $ohost -p $oport $odb $ouser < $testname/init_data.sql 1> $mktmp/init_data.sql.log 2> $mktmp/init_data.sql.log
if [ $? -ne 0 ]; then
warn 3 "$testname/init_data.sql generated an error see $mktmp/init_data.sql.log for details"
fi
fi
else
err 3 "No origin found in ${odb} ${ohost} ${ouser} ${oport}"
fi
}
do_ik()
{
if [ -f $mktmp/slonik.script ]; then
# cat $mktmp/slonik.script >`tty`
$pgbindir/slonik < $mktmp/slonik.script > $mktmp/slonik.log 2>&1
if [ $? -ne 0 ]; then
err 3 "Slonik error see $mktmp/slonik.log for details"
cat $mktmp/slonik.log
fi
fi
}
launch_poll()
{
originnode=${ORIGINNODE:-"1"}
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval opgbindir=\$PGBINDIR${originnode}
eval oport=\$PORT${originnode}
eval cluster=\$CLUSTER1
conninfo="-h ${ohost} -p ${oport} -d ${odb} -U ${ouser}"
status "launching polling script"
case `uname` in
MINGW32*)
./poll_cluster.sh "$mktmp" "${cluster}" "${conninfo}" "${opgbindir}" /dev/tty &
poll_pid=$!
;;
*)
if [ "x$SHLVL" != "x" ]; then
./poll_cluster.sh "$mktmp" "${cluster}" "${conninfo}" "${opgbindir}" `tty` &
else
./poll_cluster.sh "$mktmp" "${cluster}" "${conninfo}" "${opgbindir}" /dev/null &
fi
tmppid=$!
tmpppid=$$
sleep 1
foo=$(_check_pid poll_cluster ${tmppid} ${tmpppid})
poll_pid=${foo}
if [ -z "${foo}" -o "${tmppid}" != "${foo}" ]; then
warn 3 "Failed to launch poll_cluster check $mktmp/poll.log for details"
fi
;;
esac
}
build_slonconf()
{
node=$1
conninfo=$2
eval archive=\$ARCHIVE${node}
CONFFILE=$mktmp/slon-conf.${node}
echo "log_level=2" > ${CONFFILE}
echo "vac_frequency=2" >> ${CONFFILE}
echo "cleanup_interval=\"30 seconds\"" >> ${CONFFILE}
echo "sync_interval=2010" >> ${CONFFILE}
echo "sync_interval_timeout=15000" >> ${CONFFILE}
echo "sync_group_maxsize=8" >> ${CONFFILE}
echo "syslog=1" >> ${CONFFILE}
echo "log_timestamp=true" >> ${CONFFILE}
echo "log_timestamp_format='%Y-%m-%d %H:%M:%S %Z'" >> ${CONFFILE}
echo "pid_file='${mktmp}/slon-pid.${node}'" >> ${CONFFILE}
echo "syslog_facility=LOCAL0" >> ${CONFFILE}
echo "syslog_ident=slon-${cluster}-${node}" >> ${CONFFILE}
echo "cluster_name='${cluster}'" >> ${CONFFILE}
echo "conn_info='${conninfo}'" >> ${CONFFILE}
echo "desired_sync_time=60000" >> ${CONFFILE}
echo "sql_on_connection=\"SET log_min_duration_statement to '1000';\"" >> ${CONFFILE}
echo "lag_interval=\"2 seconds\"" >> ${CONFFILE}
if [ "x${archive}" = "xtrue" ]; then
status "slonconf configures archive logging for node ${node}"
echo "archive_dir='${mktmp}/archive_logs_${node}'" >> ${CONFFILE}
eval pgbindir=\$PGBINDIR${node}
fi
}
launch_slon()
{
node=1
originnode=${ORIGINNODE:-"1"}
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval opgbindir=\$PGBINDIR${originnode}
eval oport=\$PORT${originnode}
eval cluster=\$CLUSTER1
conninfo="dbname=${odb} host=${ohost} user=${ouser} port=${oport}"
build_slonconf ${originnode} "${conninfo}"
slonparms=" -f ${mktmp}/slon-conf.${originnode} "
status "launching originnode - PGBINDIR=${PGBINDIR}"
SLON_BUILD=${PGBINDIR} SLON_CONF=${mktmp}/slon-conf.${originnode} SLON_LOG=$mktmp/slon_log.${originnode} $SLTOOLDIR/start_slon.sh start
sleep 1
SLPID=`SLON_BUILD=$PGBINDIR SLON_CONF=${mktmp}/slon-conf.${originnode} $SLTOOLDIR/start_slon.sh status | grep "Slon running as PID:"`
if [ -z "${SLPID}" ]; then
echo "SLPID: ${SLPID}"
warn 3 "Failed to launch slon on node ${originnode} check $mktmp/slon_log.${originnode} for details"
fi
sleep 10
node=1
while : ; do
eval archive=\$ARCHIVE${node}
if [ "x${archive}" = "xtrue" ]; then
ARCHIVENODE=${node}
fi
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
done
status "Archive node: ${ARCHIVENODE}"
node=1
while : ; do
if [ ${node} -ne ${originnode} ]; then
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval pgbindir=\$PGBINDIR${node}
eval port=\$PORT${node}
eval cluster=\$CLUSTER1
eval archive=\$ARCHIVE${node}
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
unset conninfo
unset tmppid
unset tmpppid
eval slon${node}_pid=
status "Considering node ${node}"
if [ "x${archive}" = "xtrue" ]; then
status "Creating log shipping directory - $mktmp/archive_logs_${node}"
mkdir -p $mktmp/archive_logs_${node}
archiveparm="-a ${mktmp}/archive_logs_${node}"
else
archiveparm=""
fi
conninfo="dbname=${db} host=${host} user=${user} port=${port}"
build_slonconf ${node} "${conninfo}"
status "launching slon"
SLON_BUILD=$PGBINDIR SLON_CONF=${CONFFILE} SLON_LOG=$mktmp/slon_log.${node} $SLTOOLDIR/start_slon.sh start
sleep 1
SLPID=`SLON_BUILD=${PGBINDIR} SLON_CONF=${mktmp}/slon-conf.${node} $SLTOOLDIR/start_slon.sh status | grep "Slon running as PID:"`
if [ -z "${SLPID}" ]; then
echo "SLPID: ${SLPID}"
warn 3 "Failed to launch slon on node ${node} check $mktmp/slon_log.${node} for details"
fi
fi
fi
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
done
}
poll_cluster()
{
originnode=${ORIGINNODE:-"1"}
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval opgbindir=\$PGBINDIR${originnode}
eval oport=\$PORT${originnode}
node=1
while : ; do
eval cluster=\$CLUSTER${node}
if [ -n "${cluster}" ]; then
SQL="SELECT * FROM \"_${cluster}\".sl_status"
${opgbindir}/psql -c "${SQL}" -h ${ohost} -p ${oport} ${odb} ${ouser}
if [ ${node} -ge ${NUMCLUSTERS} ]; then
break;
else
node=`expr ${node} + 1`
fi
else
break;
fi
done
}
# wait_for_catchup()
# {
# node=1
# status "waiting for nodes to catch up"
# poll_cluster
# sleep 20
# poll_cluster
# status "done"
# }
wait_for_catchup ()
{
eval onode=${ORIGINNODE:-"1"}
status "submit SYNC to node ${onode}, wait for event to propagate to all nodes..."
echo "include <${mktmp}/slonik.preamble>;" > $mktmp/wait-for-propagation.slonik
echo "sync (ID=${onode});" >> $mktmp/wait-for-propagation.slonik
echo "wait for event (origin=${onode},confirmed=ALL,wait on=${onode});" >> $mktmp/wait-for-propagation.slonik
$pgbindir/slonik < $mktmp/wait-for-propagation.slonik > $mktmp/wait-for-propagation.log 2>&1
status "...event propagated to all nodes"
}
diff_db()
{
originnode=${ORIGINNODE:-"1"}
eval odb=\$DB${originnode}
eval ohost=\$HOST${originnode}
eval ouser=\$USER${originnode}
eval opgbindir=\$PGBINDIR${originnode}
eval oport=\$PORT${originnode}
if [ -f ${mktmp}/db_${originnode}.dmp ]; then
err 3 "${mktmp}/db_${originnode}.dmp exists but should not"
fi
status "getting data from origin DB for diffing"
cat ${testname}/schema.diff | while read SQL; do
${opgbindir}/psql -c "${SQL}" -h ${ohost} -p ${oport} ${odb} ${ouser} >> ${mktmp}/db_${originnode}.dmp
done
status "done"
node=1
while : ; do
eval db=\$DB${node}
eval host=\$HOST${node}
eval user=\$USER${node}
eval port=\$PORT${node}
eval pgbindir=\$PGBINDIR${node}
if [ -n "${db}" -a "${host}" -a "${user}" -a "${port}" ]; then
if [ ${node} -ne ${originnode} ]; then
if [ -f ${mktmp}/db_${node}.dmp ]; then
err 3 "${mktmp}/db_${node}.dmp exists but should not"
fi
status "getting data from node ${node} for diffing against origin"
cat ${testname}/schema.diff | while read SQL; do
${pgbindir}/psql -h ${host} -c "${SQL}" -p ${port} ${db} ${user} >> ${mktmp}/db_${node}.dmp
done
status "comparing"
diff ${mktmp}/db_${originnode}.dmp ${mktmp}/db_${node}.dmp > ${mktmp}/db_diff.${node}
if [ $? -ne 0 ]; then
warn 3 "${mktmp}/db_${originnode}.dmp ${mktmp}/db_${node}.dmp differ, see ${mktmp}/db_diff.${node} for details"
else
echo "subscriber node ${node} is the same as origin node ${originnode}"
fi
status "done"
fi
else
err 3 "Not Found ${db} -a ${host} ${user}"
fi
if [ ${node} -ge ${NUMNODES} ]; then
break;
else
node=$((${node} + 1))
fi
done
}
TMPDIR=${TMPDIR:-"/tmp"} # Consider either a default value, or /tmp
if [ -d ${TMPDIR} ]; then
T_TMPDIR=${TMPDIR}
else
for i in /tmp /usr/tmp /var/tmp; do
if [ -d ${i} ]; then
TMPDIR=$i
break
fi
done
fi
case `uname` in
SunOS|AIX|MINGW32*)
if [ -z $TMPDIR ]; then
err 3 "unable to create temp dir"
exit
fi
# do this 10 times else fail
rstring=$(random_az 8)
rstring=slony-regress.$rstring
mkdir ${TMPDIR}/$rstring
retcode=$?
if [ $retcode -ne 0 ]; then
err $retcode "unable to create temp dir"
else
mktmp=${TMPDIR}/$rstring
fi
;;
Linux)
mktmp=`mktemp -d -t slony-regress.XXXXXX`
if [ $MY_MKTEMP_IS_DECREPIT ] ; then
mktmp=`mktemp -d ${TMPDIR}/slony-regress.XXXXXX`
fi
if [ ! -d $mktmp ]; then
err 3 "mktemp failed"
fi
;;
*)
mktmp=`mktemp -d -t slony-regress`
if [ ! -d $mktmp ]; then
err 3 "mktemp failed"
fi
;;
esac
echo ${testname} > ${mktmp}/TestName
. $testname/generate_dml.sh
init_origin_rdbms
load_data
create_subscribers
init_preamble
init_cluster
create_set
add_tables
status "creating cluster"
do_ik
status "done"
status "storing nodes"
init_preamble
store_node
do_ik
status "done"
status "Granting weak access on Slony-I schema"
generate_weak_slony_grants
status "done"
status "storing paths"
init_preamble
store_path
do_ik
status "done"
launch_slon
status "subscribing"
init_preamble
subscribe_set
do_ik
status "done"
do_initdata
if [ ! -z ${poll_pid} ]; then
wait ${poll_pid}
fi
diff_db
stop_processes
status "waiting for slons to die"
sleep 5
status "done"
gen_testinfo
drop_databases
cleanup