xref: /spdk/test/blobfs/rocksdb/rocksdb.sh (revision ba23cec1820104cc710ad776f0127e1cf82033aa)
1#!/usr/bin/env bash
2
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5source $rootdir/test/common/autotest_common.sh
6
7dump_db_bench_on_err() {
8	# Fetch std dump of the last run_step that might have failed
9	[[ -e $db_bench ]] || return 0
10
11	# Dump entire *.txt to stderr to clearly see what might have failed
12	xtrace_disable
13	mapfile -t step_map < "$db_bench"
14	printf '%s\n' "${step_map[@]/#/* $step (FAILED)}" >&2
15	xtrace_restore
16}
17
18run_step() {
19	if [ -z "$1" ]; then
20		echo run_step called with no parameter
21		exit 1
22	fi
23
24	cat <<- EOL >> "$1"_flags.txt
25		--spdk=$ROCKSDB_CONF
26		--spdk_bdev=Nvme0n1
27		--spdk_cache_size=$CACHE_SIZE
28	EOL
29
30	db_bench=$1_db_bench.txt
31	echo -n Start $1 test phase...
32	time taskset 0xFF $DB_BENCH --flagfile="$1"_flags.txt &> "$db_bench"
33	DB_BENCH_FILE=$(grep -o '/dev/shm/\(\w\|\.\|\d\|/\)*' "$db_bench")
34	gzip $DB_BENCH_FILE
35	mv $DB_BENCH_FILE.gz "$1"_trace.gz
36	chmod 644 "$1"_trace.gz
37	echo done.
38}
39
40run_bsdump() {
41	$rootdir/examples/blob/cli/blobcli -c $ROCKSDB_CONF -b Nvme0n1 -D &> bsdump.txt
42}
43
44# In the autotest job, we copy the rocksdb source to just outside the spdk directory.
45DB_BENCH_DIR="$rootdir/../rocksdb"
46DB_BENCH=$DB_BENCH_DIR/db_bench
47ROCKSDB_CONF=$testdir/rocksdb.conf
48
49if [ ! -e $DB_BENCH_DIR ]; then
50	echo $DB_BENCH_DIR does not exist
51	false
52fi
53
54timing_enter db_bench_build
55
56pushd $DB_BENCH_DIR
57if [ -z "$SKIP_GIT_CLEAN" ]; then
58	git clean -x -f -d
59fi
60
61EXTRA_CXXFLAGS=""
62GCC_VERSION=$(cc -dumpversion | cut -d. -f1)
63if ((GCC_VERSION >= 9)); then
64	EXTRA_CXXFLAGS+="-Wno-deprecated-copy -Wno-pessimizing-move -Wno-error=stringop-truncation"
65fi
66
67$MAKE db_bench $MAKEFLAGS $MAKECONFIG DEBUG_LEVEL=0 SPDK_DIR=$rootdir EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS"
68popd
69
70timing_exit db_bench_build
71
72$rootdir/scripts/gen_nvme.sh > $ROCKSDB_CONF
73# 0x80 is the bit mask for BlobFS tracepoints
74echo "[Global]" >> $ROCKSDB_CONF
75echo "TpointGroupMask 0x80" >> $ROCKSDB_CONF
76
77trap 'dump_db_bench_on_err; run_bsdump || :; rm -f $ROCKSDB_CONF; exit 1' SIGINT SIGTERM EXIT
78
79if [ -z "$SKIP_MKFS" ]; then
80	run_test "blobfs_mkfs" $rootdir/test/blobfs/mkfs/mkfs $ROCKSDB_CONF Nvme0n1
81fi
82
83mkdir -p $output_dir/rocksdb
84RESULTS_DIR=$output_dir/rocksdb
85if [ $RUN_NIGHTLY -eq 1 ]; then
86	CACHE_SIZE=4096
87	DURATION=60
88	NUM_KEYS=100000000
89else
90	CACHE_SIZE=2048
91	DURATION=20
92	NUM_KEYS=20000000
93fi
94
95cd $RESULTS_DIR
96cp $testdir/common_flags.txt insert_flags.txt
97cat << EOL >> insert_flags.txt
98--benchmarks=fillseq
99--threads=1
100--disable_wal=1
101--use_existing_db=0
102--num=$NUM_KEYS
103EOL
104
105cp $testdir/common_flags.txt randread_flags.txt
106cat << EOL >> randread_flags.txt
107--benchmarks=readrandom
108--threads=16
109--duration=$DURATION
110--disable_wal=1
111--use_existing_db=1
112--num=$NUM_KEYS
113EOL
114
115cp $testdir/common_flags.txt overwrite_flags.txt
116cat << EOL >> overwrite_flags.txt
117--benchmarks=overwrite
118--threads=1
119--duration=$DURATION
120--disable_wal=1
121--use_existing_db=1
122--num=$NUM_KEYS
123EOL
124
125cp $testdir/common_flags.txt readwrite_flags.txt
126cat << EOL >> readwrite_flags.txt
127--benchmarks=readwhilewriting
128--threads=4
129--duration=$DURATION
130--disable_wal=1
131--use_existing_db=1
132--num=$NUM_KEYS
133EOL
134
135cp $testdir/common_flags.txt writesync_flags.txt
136cat << EOL >> writesync_flags.txt
137--benchmarks=overwrite
138--threads=1
139--duration=$DURATION
140--disable_wal=0
141--use_existing_db=1
142--sync=1
143--num=$NUM_KEYS
144EOL
145
146run_test "rocksdb_insert" run_step insert
147run_test "rocksdb_overwrite" run_step overwrite
148run_test "rocksdb_readwrite" run_step readwrite
149run_test "rocksdb_writesync" run_step writesync
150run_test "rocksdb_randread" run_step randread
151
152trap - SIGINT SIGTERM EXIT
153
154run_bsdump
155rm -f $ROCKSDB_CONF
156