-
Notifications
You must be signed in to change notification settings - Fork 312
/
run.sh
executable file
·2130 lines (2021 loc) · 67.4 KB
/
run.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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -e
LOCAL_HOSTNAME=$(hostname -f)
PID=$$
ROOT="$(cd "$(dirname "$0")" && pwd)"
export BUILD_ROOT_DIR=${ROOT}/build
export BUILD_LATEST_DIR=${BUILD_ROOT_DIR}/latest
export REPORT_DIR="$ROOT/test_report"
# It's possible to specify THIRDPARTY_ROOT by setting the environment variable PEGASUS_THIRDPARTY_ROOT.
export THIRDPARTY_ROOT=${PEGASUS_THIRDPARTY_ROOT:-"$ROOT/thirdparty"}
ARCH_TYPE=''
arch_output=$(arch)
if [ "$arch_output"x == "aarch64"x ]; then
ARCH_TYPE="aarch64"
else
if [ "$arch_output"x != "x86_64"x ]; then
echo "WARNING: unrecognized CPU architecture '$arch_output', use 'x86_64' as default"
fi
ARCH_TYPE="amd64"
fi
export LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/${ARCH_TYPE}:${JAVA_HOME}/jre/lib/${ARCH_TYPE}/server:${BUILD_LATEST_DIR}/output/lib:${THIRDPARTY_ROOT}/output/lib:${LD_LIBRARY_PATH}
# Disable AddressSanitizerOneDefinitionRuleViolation, see https://github.com/google/sanitizers/issues/1017 for details.
# Add parameters in order to be able to generate coredump file when run ASAN tests
export ASAN_OPTIONS=detect_odr_violation=0:abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1
# See https://github.com/gperftools/gperftools/wiki/gperftools'-stacktrace-capturing-methods-and-their-issues.
# Now we choose libgcc, because of https://github.com/apache/incubator-pegasus/issues/1685.
export TCMALLOC_STACKTRACE_METHOD=libgcc # Can be generic_fp, generic_fp_unsafe, libunwind or libgcc
export TCMALLOC_STACKTRACE_METHOD_VERBOSE=1
function usage()
{
echo "usage: run.sh <command> [<args>]"
echo
echo "Command list:"
echo " help print the help info"
echo " build build the system"
echo
echo " start_zk start local single zookeeper server"
echo " stop_zk stop local zookeeper server"
echo " clear_zk stop local zookeeper server and clear data"
echo
echo " start_onebox start pegasus onebox"
echo " stop_onebox stop pegasus onebox"
echo " list_onebox list pegasus onebox"
echo " clear_onebox clear pegasus onebox"
echo
echo " start_onebox_instance start pegasus onebox instance"
echo " stop_onebox_instance stop pegasus onebox instance"
echo " restart_onebox_instance restart pegasus onebox instance"
echo
echo " start_kill_test start pegasus kill test"
echo " stop_kill_test stop pegasus kill test"
echo " list_kill_test list pegasus kill test"
echo " clear_kill_test clear pegasus kill test"
echo
echo " bench run benchmark test"
echo " shell run pegasus shell"
echo " migrate_node migrate primary replicas out of specified node"
echo " downgrade_node downgrade replicas to inactive on specified node"
echo
echo " test run unit test"
echo
echo " pack_server generate pegasus server package for deploy with minos"
echo " pack_client generate pegasus client package"
echo " pack_tools generate pegasus tools package for shell and benchmark test"
echo
echo " bump_version change the version of the project"
echo "Command 'run.sh <command> -h' will print help for subcommands."
}
#####################
## build
#####################
function usage_build()
{
echo "Options for subcommand 'build':"
echo " -h|--help print the help info"
echo " -m|--modules specify modules to build, split by ',',"
echo " e.g., \"pegasus_unit_test,dsn_runtime_tests,dsn_meta_state_tests\","
echo " if not set, then build all objects"
echo " -t|--type build type: debug|release, default is release"
echo " -c|--clear clear pegasus before building, not clear thirdparty"
echo " --clear_thirdparty clear thirdparty/pegasus before building"
echo " --compiler specify c and cxx compiler, sperated by ','"
echo " e.g., \"gcc,g++\" or \"clang-3.9,clang++-3.9\""
echo " default is \"gcc,g++\""
echo " -j|--jobs <num> the number of jobs to run simultaneously, default 8"
echo " --enable_gcov generate gcov code coverage report, default no"
echo " -v|--verbose build in verbose mode, default no"
echo " --disable_gperf build without gperftools, this flag is mainly used"
echo " to enable valgrind memcheck, default no"
echo " --use_jemalloc build with jemalloc"
echo " --separate_servers whether to build pegasus_collector,pegasus_meta_server and pegasus_replica_server binaries separately, otherwise a combined pegasus_server binary will be built"
echo " --sanitizer <type> build with sanitizer to check potential problems,
type: address|leak|thread|undefined"
echo " --skip_thirdparty whether to skip building thirdparties, default no"
echo " --enable_rocksdb_portable build a portable rocksdb binary"
echo " --test whether to build test binaries"
echo " --iwyu specify the binary path of 'include-what-you-use' when build with IWYU"
echo " --cmake_only whether to run cmake only, default no"
}
function exit_if_fail() {
if [ $1 != 0 ]; then
exit $1
fi
}
function run_build()
{
# Note(jiashuo1): No "memory" check mode, because MemorySanitizer is only available in Clang for Linux x86_64 targets
# # https://www.jetbrains.com/help/clion/google-sanitizers.html
SANITIZERS=("address" "leak" "thread" "undefined")
C_COMPILER="gcc"
CXX_COMPILER="g++"
BUILD_TYPE="release"
# TODO(yingchun): some boolean variables are using YES/NO, some are using ON/OFF, should be unified.
CLEAR=NO
CLEAR_THIRDPARTY=NO
JOB_NUM=8
ENABLE_GCOV=NO
RUN_VERBOSE=NO
ENABLE_GPERF=ON
SKIP_THIRDPARTY=NO
SANITIZER=""
ROCKSDB_PORTABLE=0
USE_JEMALLOC=OFF
SEPARATE_SERVERS=OFF
BUILD_TEST=OFF
IWYU=""
BUILD_MODULES=""
CMAKE_ONLY=NO
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_build
exit 0
;;
-m|--modules)
BUILD_MODULES=$2
shift
;;
-t|--type)
BUILD_TYPE="$2"
shift
;;
-c|--clear)
CLEAR=YES
;;
--clear_thirdparty)
CLEAR_THIRDPARTY=YES
;;
--compiler)
C_COMPILER=`echo $2 | awk -F',' '{print $1}'`
CXX_COMPILER=`echo $2 | awk -F',' '{print $2}'`
if [ "x"$C_COMPILER == "x" -o "x"$CXX_COMPILER == "x" ]; then
echo "ERROR: invalid compiler option: $2"
echo
usage_build
exit 1
fi
shift
;;
-j|--jobs)
JOB_NUM="$2"
shift
;;
--enable_gcov)
ENABLE_GCOV=YES
;;
--sanitizer)
IS_SANITIZERS=`echo ${SANITIZERS[@]} | grep -w $2`
if [[ -z ${IS_SANITIZERS} ]]; then
echo "ERROR: unknown sanitizer type \"$2\""
usage_build
exit 1
fi
SANITIZER="$2"
shift
;;
-v|--verbose)
RUN_VERBOSE=YES
;;
--disable_gperf)
ENABLE_GPERF=OFF
;;
--skip_thirdparty)
SKIP_THIRDPARTY=YES
;;
--enable_rocksdb_portable)
ROCKSDB_PORTABLE=1
;;
--use_jemalloc)
ENABLE_GPERF=OFF
USE_JEMALLOC=ON
;;
--separate_servers)
SEPARATE_SERVERS=ON
;;
--test)
BUILD_TEST=ON
;;
--iwyu)
IWYU="$2"
shift
;;
--cmake_only)
CMAKE_ONLY=YES
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_build
exit 1
;;
esac
shift
done
if [ "$BUILD_TYPE" != "debug" -a "$BUILD_TYPE" != "release" ]; then
echo "ERROR: invalid build type \"$BUILD_TYPE\""
echo
usage_build
exit 1
fi
# Replace all ',' to ' ' in $BUILD_MODULES.
if [ "$BUILD_MODULES" != "" ]; then
BUILD_MODULES=${BUILD_MODULES//,/ }
fi
echo "build_modules=$BUILD_MODULES"
CMAKE_OPTIONS="-DCMAKE_C_COMPILER=${C_COMPILER}
-DCMAKE_CXX_COMPILER=${CXX_COMPILER}
-DUSE_JEMALLOC=${USE_JEMALLOC}
-DSEPARATE_SERVERS=${SEPARATE_SERVERS}"
echo "BUILD_TYPE=$BUILD_TYPE"
if [ "$BUILD_TYPE" == "debug" ]
then
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_BUILD_TYPE=Debug"
else
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_BUILD_TYPE=Release"
fi
if [ ! -z "${SANITIZER}" ]; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DSANITIZER=${SANITIZER}"
echo "ASAN_OPTIONS=$ASAN_OPTIONS"
fi
MAKE_OPTIONS="-j$JOB_NUM"
if [ "$RUN_VERBOSE" == "YES" ]; then
MAKE_OPTIONS="${MAKE_OPTIONS} VERBOSE=1"
fi
echo "Build start time: `date`"
start_time=`date +%s`
if [[ ${SKIP_THIRDPARTY} == "YES" ]]; then
echo "Skip building third-parties..."
else
cd ${THIRDPARTY_ROOT}
if [[ "$CLEAR_THIRDPARTY" == "YES" ]]; then
echo "Clear third-parties..."
rm -rf build
rm -rf output
fi
echo "Start building third-parties..."
mkdir -p build
pushd build
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DROCKSDB_PORTABLE=${ROCKSDB_PORTABLE}"
cmake .. ${CMAKE_OPTIONS}
make -j$JOB_NUM
exit_if_fail $?
popd
cd ..
fi
CMAKE_OPTIONS="${CMAKE_OPTIONS}
-DENABLE_GCOV=${ENABLE_GCOV}
-DENABLE_GPERF=${ENABLE_GPERF}
-DBoost_NO_BOOST_CMAKE=ON
-DBOOST_ROOT=${THIRDPARTY_ROOT}/output
-DBoost_NO_SYSTEM_PATHS=ON"
echo "INFO: start build Pegasus..."
BUILD_DIR="${BUILD_ROOT_DIR}/${BUILD_TYPE}_${SANITIZER}"
BUILD_DIR=${BUILD_DIR%_*}
if [ ! -z "${IWYU}" ]; then
BUILD_DIR="${BUILD_DIR}_iwyu"
fi
if [ "$CLEAR" == "YES" ]; then
echo "Clear $BUILD_DIR ..."
rm -rf $BUILD_DIR
rm -f ${ROOT}/src/base/rrdb_types.cpp
rm -f ${ROOT}/src/include/rrdb/rrdb_types.h
rm -f ${ROOT}/src/common/serialization_helper/dsn.layer2_types.h
rm -f ${ROOT}/src/runtime/dsn.layer2_types.cpp
rm -f ${ROOT}/src/include/pegasus/git_commit.h
fi
pushd ${ROOT}
if [ ! -f "${ROOT}/src/common/serialization_helper/dsn.layer2_types.h" ]; then
echo "Gen thrift"
# TODO(yingchun): should be optimized
python3 $ROOT/build_tools/compile_thrift.py
sh ${ROOT}/build_tools/recompile_thrift.sh
fi
if [ ! -d "$BUILD_DIR" ]; then
mkdir -p $BUILD_DIR
echo "Running cmake Pegasus..."
pushd $BUILD_DIR
if [ ! -z "${IWYU}" ]; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=${IWYU}"
fi
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DBUILD_TEST=${BUILD_TEST}"
cmake ${ROOT} -DCMAKE_INSTALL_PREFIX=$BUILD_DIR/output $CMAKE_OPTIONS
exit_if_fail $?
fi
GIT_COMMIT_FILE=$ROOT/src/include/pegasus/git_commit.h
if [ ! -f "${GIT_COMMIT_FILE}" ]; then
echo "Gen git_commit.h ..."
pushd "$ROOT/src"
PEGASUS_GIT_COMMIT="non-git-repo"
if git rev-parse HEAD; then # this is a git repo
PEGASUS_GIT_COMMIT=$(git rev-parse HEAD)
fi
echo "PEGASUS_GIT_COMMIT=${PEGASUS_GIT_COMMIT}"
echo "Generating $GIT_COMMIT_FILE..."
echo "#pragma once" >$GIT_COMMIT_FILE
echo "#define PEGASUS_GIT_COMMIT \"$PEGASUS_GIT_COMMIT\"" >>$GIT_COMMIT_FILE
fi
# rebuild link
rm -f ${BUILD_LATEST_DIR}
ln -s ${BUILD_DIR} ${BUILD_LATEST_DIR}
if [ "$CMAKE_ONLY" == "YES" ]; then
echo "CMake only, exit"
return
fi
echo "[$(date)] Building Pegasus ..."
pushd $BUILD_DIR
if [ ! -z "${IWYU}" ]; then
make $MAKE_OPTIONS 2> iwyu.out
elif [ "$BUILD_MODULES" != "" ]; then
make $BUILD_MODULES $MAKE_OPTIONS
else
make install $MAKE_OPTIONS
fi
exit_if_fail $?
echo "Build finish time: `date`"
finish_time=`date +%s`
used_time=$((finish_time-start_time))
echo "Build elapsed time: $((used_time/60))m $((used_time%60))s"
}
#####################
## test
#####################
function usage_test()
{
echo "Options for subcommand 'test':"
echo " -h|--help print the help info"
echo " -m|--modules specify modules to test, split by ',',"
echo " e.g., \"pegasus_unit_test,dsn_runtime_tests,dsn_meta_state_tests\","
echo " if not set, then run all tests"
echo " -k|--keep_onebox whether keep the onebox after the test[default false]"
echo " --onebox_opts update configs for onebox, e.g. key1=value1,key2=value2"
echo " --test_opts update configs for tests, e.g. key1=value1,key2=value2"
}
function run_test()
{
local test_modules=""
local clear_flags="1"
local enable_gcov="no"
local all_tests=(
backup_restore_test
base_api_test
base_test
bulk_load_test
# TODO(wangdan): Since the hotspot detection depends on the perf-counters system which
# is being replaced with the new metrics system, its test will fail. Temporarily disable
# the test and re-enable it after the hotspot detection is migrated to the new metrics
# system.
# detect_hotspot_test
dsn_aio_test
dsn_block_service_test
dsn_client_test
dsn.failure_detector.tests
dsn_http_test
dsn_meta_state_tests
dsn.meta.test
dsn_nfs_test
# TODO(wangdan): Since builtin_counters (memused.virt and memused.res) for perf-counters
# have been removed and dsn_perf_counter_test depends on them, disable it.
# dsn_perf_counter_test
dsn_replica_backup_test
dsn_replica_bulk_load_test
dsn_replica_dup_test
dsn_replica_split_test
dsn.replica.test
dsn_replication_common_test
dsn.replication.simple_kv
dsn.rep_tests.simple_kv
dsn_runtime_tests
dsn_utils_tests
dsn.zookeeper.tests
partition_split_test
pegasus_geo_test
pegasus_rproxy_test
pegasus_unit_test
recovery_test
restore_test
throttle_test
)
local onebox_opts=""
local test_opts=""
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_test
exit 0
;;
-m|--modules)
test_modules=$2
shift
;;
-k|--keep_onebox)
clear_flags=""
;;
--enable_gcov)
enable_gcov="yes"
;;
--onebox_opts)
onebox_opts=$2
shift
;;
--test_opts)
test_opts=$2
shift
;;
*)
echo "Error: unknown option \"$key\""
echo
usage_test
exit 1
;;
esac
shift
done
echo "Test start time: `date`"
start_time=`date +%s`
if [ ! -d "$REPORT_DIR" ]; then
mkdir -p $REPORT_DIR
fi
# Run all tests if none specified.
if [ "$test_modules" == "" ]; then
test_modules=$(IFS=,; echo "${all_tests[*]}")
fi
echo "test_modules=$test_modules"
for module in `echo $test_modules | sed 's/,/ /g'`; do
echo "====================== run $module =========================="
# The tests which need start onebox.
local need_onebox_tests=(
backup_restore_test
base_api_test
bulk_load_test
detect_hotspot_test
partition_split_test
pegasus_geo_test
pegasus_rproxy_test
recovery_test
restore_test
throttle_test
)
# Restart onebox if needed.
if [[ "${need_onebox_tests[@]}" =~ "${module}" ]]; then
# Clean up onebox at first.
run_clear_onebox
master_count=3
# Update options if needed, this should be done before starting onebox to make new options take effect.
if [ "${module}" == "recovery_test" ]; then
master_count=1
# all test case in recovery_test just run one meta_server, so we should change it
fqdn=`hostname -f`
opts="server_list=$fqdn:34601;meta_state_service_type=meta_state_service_simple;distributed_lock_service_type=distributed_lock_service_simple"
fi
if [ "${module}" == "backup_restore_test" ]; then
opts="cold_backup_disabled=false;cold_backup_checkpoint_reserve_minutes=0;cold_backup_root=onebox"
fi
if [ "${module}" == "restore_test" ]; then
opts="cold_backup_disabled=false;cold_backup_checkpoint_reserve_minutes=0;cold_backup_root=onebox"
fi
# Append onebox_opts if needed.
[ -z ${onebox_opts} ] || opts="${opts};${onebox_opts}"
# Start onebox.
if ! run_start_onebox -m ${master_count} -w -c --opts ${opts}; then
echo "ERROR: unable to continue on testing because starting onebox failed"
exit 1
fi
# TODO(yingchun): remove it?
sed -i "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g" ${BUILD_LATEST_DIR}/src/server/test/config.ini
else
# Restart ZK in what ever case.
run_stop_zk
run_start_zk
fi
# Run server test.
pushd ${BUILD_LATEST_DIR}/bin/${module}
local function_tests=(
backup_restore_test
recovery_test
restore_test
base_api_test
throttle_test
bulk_load_test
detect_hotspot_test
partition_split_test
)
# function_tests need client used meta_server_list to connect
if [[ "${function_tests[@]}" =~ "${module}" ]]; then
sed -i "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g" ./config.ini
fi
REPORT_DIR=${REPORT_DIR} TEST_BIN=${module} TEST_OPTS=${test_opts} ./run.sh
if [ $? != 0 ]; then
echo "run test \"$module\" in `pwd` failed"
exit 1
fi
# Clear onebox if needed.
if [[ "${need_onebox_tests[@]}" =~ "${test_modules}" ]]; then
if [ "$clear_flags" == "1" ]; then
run_clear_onebox
fi
fi
popd
done
echo "Test finish time: `date`"
finish_time=`date +%s`
used_time=$((finish_time-start_time))
echo "Test elapsed time: $((used_time/60))m $((used_time%60))s"
# TODO(yingchun): make sure if gcov can be ran normally.
if [ "$enable_gcov" == "yes" ]; then
echo "Generating gcov report..."
cd $ROOT
mkdir -p "$ROOT/gcov_report"
echo "Running gcovr to produce HTML code coverage report."
$BUILD_LATEST_DIR
gcovr --html --html-details -r $ROOT --object-directory=$BUILD_LATEST_DIR \
-o $GCOV_DIR/index.html
if [ $? -ne 0 ]; then
exit 1
fi
fi
}
#####################
## start_zk
#####################
function usage_start_zk()
{
echo "Options for subcommand 'start_zk':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " zookeeper install directory,"
echo " if not set, then default is './.zk_install'"
echo " -p|--port <port> listen port of zookeeper, default is 22181"
}
function run_start_zk()
{
# first we check the environment that zk need: java and nc command
# check java
type java >/dev/null 2>&1 || { echo >&2 "start zk failed, need install jre..."; exit 1;}
# check nc command
type nc >/dev/null 2>&1 || { echo >&2 "start zk failed, need install netcat command..."; exit 1;}
INSTALL_DIR=`pwd`/.zk_install
PORT=22181
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_start_zk
exit 0
;;
-d|--install_dir)
INSTALL_DIR=$2
shift
;;
-p|--port)
PORT=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_start_zk
exit 1
;;
esac
shift
done
if [ ! -d "${INSTALL_DIR}/zookeeper-bin" ]; then
echo "zookeeper-bin cannot be found under ${INSTALL_DIR}, thus try to find an existing one"
if [ -d "zookeeper-bin" ]; then
echo "zookeeper-bin is found under current work dir `pwd`, just use this one"
if ! mkdir -p "${INSTALL_DIR}"; then
echo "ERROR: mkdir ${INSTALL_DIR} failed"
exit 1
fi
# this zookeeper-bin must have been got from github action workflows, thus just
# move it to ${INSTALL_DIR} to prevent from downloading
mv zookeeper-bin ${INSTALL_DIR}/
fi
fi
INSTALL_DIR="$INSTALL_DIR" PORT="$PORT" $ROOT/admin_tools/start_zk.sh
}
#####################
## stop_zk
#####################
function usage_stop_zk()
{
echo "Options for subcommand 'stop_zk':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " zookeeper install directory,"
echo " if not set, then default is './.zk_install'"
}
function run_stop_zk()
{
INSTALL_DIR=`pwd`/.zk_install
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_stop_zk
exit 0
;;
-d|--install_dir)
INSTALL_DIR=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_stop_zk
exit 1
;;
esac
shift
done
INSTALL_DIR="$INSTALL_DIR" $ROOT/admin_tools/stop_zk.sh
}
#####################
## clear_zk
#####################
function usage_clear_zk()
{
echo "Options for subcommand 'clear_zk':"
echo " -h|--help print the help info"
echo " -d|--install_dir <dir>"
echo " zookeeper install directory,"
echo " if not set, then default is './.zk_install'"
}
function run_clear_zk()
{
INSTALL_DIR=`pwd`/.zk_install
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_clear_zk
exit 0
;;
-d|--install_dir)
INSTALL_DIR=$2
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_clear__zk
exit 1
;;
esac
shift
done
INSTALL_DIR="$INSTALL_DIR" $ROOT/admin_tools/clear_zk.sh
}
#####################
## start_onebox
#####################
function usage_start_onebox()
{
echo "Options for subcommand 'start_onebox':"
echo " -h|--help print the help info"
echo " -m|--meta_count <num>"
echo " meta server count, default is 3"
echo " -r|--replica_count <num>"
echo " replica server count, default is 3"
echo " -c|--collector"
echo " start the collector server, default not start"
echo " -a|--app_name <str>"
echo " default app name, default is temp"
echo " -p|--partition_count <num>"
echo " default app partition count, default is 8"
echo " -w|--wait_healthy"
echo " wait cluster to become healthy, default not wait"
echo " -s|--server_path <str>"
echo " server binary path, default is ${BUILD_LATEST_DIR}/output/bin/pegasus_server"
echo " --config_path"
echo " specify the config template path, default is ./src/server/config.min.ini in non-production env"
echo " ./src/server/config.ini in production env"
echo " --use_product_config"
echo " use the product config template"
echo " --hdfs_service_args"
echo " set the 'args' value of section '[block_service.hdfs_service]', it's a space separated HDFS namenode host:port and path string, for example: '127.0.0.1:8020 /pegasus'. Default is empty"
echo " --opts"
echo " update configs before start onebox, the configs are in the form of 'key1=value1,key2=value2'"
}
function run_start_onebox()
{
META_COUNT=3
REPLICA_COUNT=3
COLLECTOR_COUNT=0
APP_NAME=temp
PARTITION_COUNT=8
WAIT_HEALTHY=false
SERVER_PATH=${BUILD_LATEST_DIR}/output/bin/pegasus_server
CONFIG_FILE=""
USE_PRODUCT_CONFIG=false
HDFS_SERVICE_ARGS=""
OPTS=""
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_start_onebox
exit 0
;;
-m|--meta_count)
META_COUNT="$2"
shift
;;
-r|--replica_count)
REPLICA_COUNT="$2"
shift
;;
-c|--collector)
COLLECTOR_COUNT=1
;;
-a|--app_name)
APP_NAME="$2"
shift
;;
-p|--partition_count)
PARTITION_COUNT="$2"
shift
;;
-w|--wait_healthy)
WAIT_HEALTHY=true
;;
-s|--server_path)
SERVER_PATH="$2"
shift
;;
--config_path)
CONFIG_FILE="$2"
shift
;;
--use_product_config)
USE_PRODUCT_CONFIG=true
;;
--hdfs_service_args)
HDFS_SERVICE_ARGS="$2 $3"
shift
shift
;;
--opts)
OPTS="$2"
shift
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_start_onebox
exit 1
;;
esac
shift
done
if [ ! -f ${SERVER_PATH}/pegasus_server ]; then
echo "ERROR: file ${SERVER_PATH}/pegasus_server not exist"
exit 1
fi
if ps -ef | grep '/pegasus_server config.ini' | grep -E -q 'app_list meta|app_list replica|app_list collector'; then
echo "ERROR: some onebox processes are running, start failed"
exit 1
fi
ln -s -f "${SERVER_PATH}/pegasus_server" "${ROOT}"
if ! run_start_zk; then
echo "ERROR: unable to setup onebox because zookeeper can not be started"
exit 1
fi
source "${ROOT}"/admin_tools/config_hdfs.sh
if [ $USE_PRODUCT_CONFIG == "true" ]; then
[ -z "${CONFIG_FILE}" ] && CONFIG_FILE=${ROOT}/src/server/config.ini
[ ! -f "${CONFIG_FILE}" ] && { echo "${CONFIG_FILE} is not exist"; exit 1; }
cp -f ${CONFIG_FILE} ${ROOT}/config-server.ini
sed -i 's/\<34601\>/@META_PORT@/' ${ROOT}/config-server.ini
sed -i 's/\<34801\>/@REPLICA_PORT@/' ${ROOT}/config-server.ini
sed -i 's/%{cluster.name}/onebox/g' ${ROOT}/config-server.ini
sed -i 's/%{network.interface}/eth0/g' ${ROOT}/config-server.ini
sed -i 's/%{email.address}//g' ${ROOT}/config-server.ini
sed -i 's/%{app.dir}/.\/data/g' ${ROOT}/config-server.ini
sed -i 's/%{slog.dir}//g' ${ROOT}/config-server.ini
sed -i 's/%{data.dirs}//g' ${ROOT}/config-server.ini
sed -i 's@%{home.dir}@'"$HOME"'@g' ${ROOT}/config-server.ini
sed -i 's@%{hdfs_service_args}@'"${HDFS_SERVICE_ARGS}"'@g' ${ROOT}/config-server.ini
for i in $(seq ${META_COUNT})
do
meta_port=$((34600+i))
if [ $i -eq 1 ]; then
meta_list="${LOCAL_HOSTNAME}:$meta_port"
else
meta_list="$meta_list,${LOCAL_HOSTNAME}:$meta_port"
fi
done
sed -i 's/%{meta.server.list}/'"$meta_list"'/g' ${ROOT}/config-server.ini
sed -i 's/%{zk.server.list}/'"${LOCAL_HOSTNAME}"':22181/g' ${ROOT}/config-server.ini
sed -i 's/app_name = .*$/app_name = '"$APP_NAME"'/' ${ROOT}/config-server.ini
sed -i 's/partition_count = .*$/partition_count = '"$PARTITION_COUNT"'/' ${ROOT}/config-server.ini
else
[ -z "${CONFIG_FILE}" ] && CONFIG_FILE=${ROOT}/src/server/config.min.ini
[ ! -f "${CONFIG_FILE}" ] && { echo "${CONFIG_FILE} is not exist"; exit 1; }
sed "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g;s/@APP_NAME@/${APP_NAME}/g;s/@PARTITION_COUNT@/${PARTITION_COUNT}/g" \
${CONFIG_FILE} >${ROOT}/config-server.ini
fi
OPTS=`echo $OPTS | xargs`
config_kvs=(${OPTS//;/ })
for config_kv in ${config_kvs[@]}; do
config_kv=`echo $config_kv | xargs`
kv=(${config_kv//=/ })
if [ ! ${#kv[*]} -eq 2 ]; then
echo "Invalid --opts arguments!"
exit 1
fi
sed -i '/^\s*'"${kv[0]}"'/c '"${kv[0]}"' = '"${kv[1]}" ${ROOT}/config-server.ini
done
echo "starting server"
ld_library_path=${SERVER_PATH}:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$ld_library_path
mkdir -p onebox
cd onebox
for i in $(seq ${META_COUNT})
do
meta_port=$((34600+i))
prometheus_port=$((9091+i))
mkdir -p meta$i;
cd meta$i
ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server
sed "s/@META_PORT@/$meta_port/;s/@REPLICA_PORT@/34800/;s/@PROMETHEUS_PORT@/$prometheus_port/" ${ROOT}/config-server.ini >config.ini
$PWD/pegasus_server config.ini -app_list meta &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
done
for j in $(seq ${REPLICA_COUNT})
do
prometheus_port=$((9091+${META_COUNT}+j))
replica_port=$((34800+j))
mkdir -p replica$j
cd replica$j
ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server
sed "s/@META_PORT@/34600/;s/@REPLICA_PORT@/$replica_port/;s/@PROMETHEUS_PORT@/$prometheus_port/" ${ROOT}/config-server.ini >config.ini
$PWD/pegasus_server config.ini -app_list replica &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
done
if [ $COLLECTOR_COUNT -eq 1 ]
then
mkdir -p collector
cd collector
ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server
sed "s/@META_PORT@/34600/;s/@REPLICA_PORT@/34800/;s/@PROMETHEUS_PORT@/9091/" ${ROOT}/config-server.ini >config.ini
$PWD/pegasus_server config.ini -app_list collector &>result &
PID=$!
ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>"
cd ..
fi
if [ $WAIT_HEALTHY == "true" ]; then
cd $ROOT
echo "Wait cluster to become healthy..."
sleeped=0
while true; do
sleep 1
sleeped=$((sleeped+1))
echo "Sleeped for $sleeped seconds"
unhealthy_count=`echo "ls -d" | ./run.sh shell | awk 'f{ if(NF<7){f=0} else if($3!=$4){print} } / fully_healthy /{print;f=1}' | wc -l`
if [ $unhealthy_count -eq 1 ]; then
echo "Cluster becomes healthy."
break
fi
done
fi
}
#####################
## stop_onebox
#####################
function usage_stop_onebox()
{
echo "Options for subcommand 'stop_onebox':"
echo " -h|--help print the help info"
}
function run_stop_onebox()
{
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_stop_onebox
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_stop_onebox
exit 1
;;
esac
shift
done
ps -ef | grep '/pegasus_server config.ini' | grep -E 'app_list meta|app_list replica|app_list collector' | awk '{print $2}' | xargs kill &>/dev/null || true
}
#####################
## list_onebox
#####################
function usage_list_onebox()
{
echo "Options for subcommand 'list_onebox':"
echo " -h|--help print the help info"