2017-08-03 22:43:05 +00:00
#!/usr/bin/env bash
2019-04-18 17:51:19 +00:00
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2015-04-07 23:54:39 +00:00
#
2021-03-02 19:40:36 +00:00
# A shell script to build and run different versions of ldb to check for
# expected forward and backward compatibility with "current" version. The
# working copy must have no uncommitted changes.
#
# Usage: <SCRIPT> [ref_for_current]
# `ref_for_current` can be a revision, tag, commit or branch name. Default is HEAD.
2015-04-07 23:54:39 +00:00
#
# Return value 0 means all regression tests pass. 1 if not pass.
2021-03-02 19:40:36 +00:00
#
# Environment options:
# SHORT_TEST=1 - Test only the oldest branch for each kind of test. This is
# a good choice for PR validation as it is relatively fast and will find
# most issues.
# USE_SSH=1 - Connect to GitHub with ssh instead of https
if ! git diff-index --quiet HEAD; then
echo "You have uncommitted changes. Aborting."
exit 1
fi
current_checkout_name = ${ 1 :- HEAD }
# This allows the script to work even if with transient refs like "HEAD"
current_checkout_hash = " $( git rev-parse --quiet --verify $current_checkout_name ) "
if [ " $current_checkout_hash " = = "" ] ; then
echo " Not a recognized ref: $current_checkout_name "
exit 1
fi
# To restore to prior branch at the end
orig_branch = " $( git rev-parse --abbrev-ref HEAD) "
tmp_branch = _tmp_format_compatible
tmp_origin = _tmp_origin
# Don't depend on what current "origin" might be
set -e
git remote remove $tmp_origin 2>/dev/null || true
if [ " $USE_SSH " ] ; then
git remote add $tmp_origin "git@github.com:facebook/rocksdb.git"
else
git remote add $tmp_origin "https://github.com/facebook/rocksdb.git"
fi
git fetch $tmp_origin
2015-04-07 23:54:39 +00:00
2022-02-08 03:34:39 +00:00
# Used in building some ancient RocksDB versions where by default it tries to
# use a precompiled libsnappy.a checked in to the repo.
export SNAPPY_LDFLAGS = -lsnappy
2021-03-02 19:40:36 +00:00
cleanup( ) {
echo "== Cleaning up"
2021-08-11 23:01:27 +00:00
git reset --hard || true
2021-03-02 19:40:36 +00:00
git checkout " $orig_branch " || true
git branch -D $tmp_branch || true
git remote remove $tmp_origin || true
}
trap cleanup EXIT # Always clean up, even on failure or Ctrl+C
scriptpath = ` dirname ${ BASH_SOURCE [0] } `
test_dir = ${ TEST_TMPDIR :- "/tmp" } " /rocksdb_format_compatible_ $USER "
rm -rf ${ test_dir : ? }
2022-05-09 20:38:46 +00:00
# Prevent 'make clean' etc. from wiping out test_dir
export TEST_TMPDIR = $test_dir "/misc"
2021-03-02 19:40:36 +00:00
# For saving current version of scripts as we checkout different versions to test
2015-04-07 23:54:39 +00:00
script_copy_dir = $test_dir "/script_copy"
2021-03-02 19:40:36 +00:00
mkdir -p $script_copy_dir
cp -f $scriptpath /*.sh $script_copy_dir
2015-04-07 23:54:39 +00:00
2021-03-02 19:40:36 +00:00
# For shared raw input data
input_data_path = $test_dir "/test_data_input"
mkdir -p $input_data_path
# For external sst ingestion test
ext_test_dir = $test_dir "/ext"
mkdir -p $ext_test_dir
# For DB dump test
db_test_dir = $test_dir "/db"
mkdir -p $db_test_dir
# For backup/restore test (uses DB test)
bak_test_dir = $test_dir "/bak"
mkdir -p $bak_test_dir
2020-06-30 23:35:59 +00:00
2021-03-02 19:40:36 +00:00
python_bin = $( which python3 || which python || echo python3)
2015-04-07 23:54:39 +00:00
2018-08-24 21:23:42 +00:00
# Generate random files.
2015-04-07 23:54:39 +00:00
for i in { 1..6}
do
input_data[ $i ] = $input_data_path /data$i
echo = = Generating random input file ${ input_data [ $i ] }
2020-06-30 23:35:59 +00:00
$python_bin - <<EOF
2015-04-07 23:54:39 +00:00
import random
random.seed( $i )
symbols = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' ]
with open( '${input_data[$i]}' , 'w' ) as f:
for i in range( 1,1024) :
k = ""
for j in range( 1, random.randint( 1,32) ) :
k = k + symbols[ random.randint( 0, len( symbols) - 1) ]
vb = ""
for j in range( 1, random.randint( 0,128) ) :
vb = vb + symbols[ random.randint( 0, len( symbols) - 1) ]
v = ""
for j in range( 1, random.randint( 1, 5) ) :
v = v + vb
2020-06-30 23:35:59 +00:00
print( k + " ==> " + v, file = f)
2015-04-07 23:54:39 +00:00
EOF
done
2018-08-24 21:23:42 +00:00
# Generate file(s) with sorted keys.
sorted_input_data = $input_data_path /sorted_data
echo = = Generating file with sorted keys ${ sorted_input_data }
2020-06-30 23:35:59 +00:00
$python_bin - <<EOF
2018-08-24 21:23:42 +00:00
with open( '${sorted_input_data}' , 'w' ) as f:
for i in range( 0,10) :
k = str( i)
v = "value" + k
2020-06-30 23:35:59 +00:00
print( k + " ==> " + v, file = f)
2018-08-24 21:23:42 +00:00
EOF
2021-03-02 19:40:36 +00:00
# db_backward_only_refs defined below the rest
# To check for DB forward compatibility with loading options (old version
# reading data from new), as well as backward compatibility
2023-04-24 20:37:56 +00:00
declare -a db_forward_with_options_refs = ( "6.27.fb" "6.28.fb" "6.29.fb" "7.0.fb" "7.1.fb" "7.2.fb" "7.3.fb" "7.4.fb" "7.5.fb" "7.6.fb" "7.7.fb" "7.8.fb" "7.9.fb" "7.10.fb" "8.0.fb" "8.1.fb" "8.2.fb" )
2021-03-02 19:40:36 +00:00
# To check for DB forward compatibility without loading options (in addition
# to the "with loading options" set), as well as backward compatibility
declare -a db_forward_no_options_refs = ( ) # N/A at the moment
# To check for SST ingestion backward compatibility (new version reading
# data from old) (ldb ingest_extern_sst added in 5.16.x, back-ported to
# 5.14.x, 5.15.x)
2022-10-22 01:09:12 +00:00
declare -a ext_backward_only_refs = ( "5.14.fb" "5.15.fb" "5.16.fb" "5.17.fb" "5.18.fb" "6.0.fb" "6.1.fb" "6.2.fb" "6.3.fb" "6.4.fb" "6.5.fb" "6.6.fb" "6.7.fb" "6.8.fb" "6.9.fb" "6.10.fb" "6.11.fb" "6.12.fb" "6.13.fb" "6.14.fb" "6.15.fb" "6.16.fb" "6.17.fb" "6.18.fb" "6.19.fb" "6.20.fb" "6.21.fb" "6.22.fb" "6.23.fb" "6.24.fb" "6.25.fb" "6.26.fb" )
2021-03-02 19:40:36 +00:00
# To check for SST ingestion forward compatibility (old version reading
# data from new) as well as backward compatibility
declare -a ext_forward_refs = ( " ${ db_forward_no_options_refs [@] } " " ${ db_forward_with_options_refs [@] } " )
# To check for backup backward compatibility (new version reading data
# from old) (ldb backup/restore added in 4.11.x)
declare -a bak_backward_only_refs = ( "4.11.fb" "4.12.fb" "4.13.fb" "5.0.fb" "5.1.fb" "5.2.fb" "5.3.fb" "5.4.fb" "5.5.fb" "5.6.fb" "5.7.fb" "5.8.fb" "5.9.fb" "5.10.fb" "5.11.fb" "5.12.fb" "5.13.fb" " ${ ext_backward_only_refs [@] } " )
# To check for backup forward compatibility (old version reading data
# from new) as well as backward compatibility
declare -a bak_forward_refs = ( " ${ db_forward_no_options_refs [@] } " " ${ db_forward_with_options_refs [@] } " )
# Branches (git refs) to check for DB backward compatibility (new version
# reading data from old) (in addition to the "forward compatible" list)
# NOTE: 2.7.fb.branch shows assertion violation in some configurations
declare -a db_backward_only_refs = ( "2.2.fb.branch" "2.3.fb.branch" "2.4.fb.branch" "2.5.fb.branch" "2.6.fb.branch" "2.7.fb.branch" "2.8.1.fb" "3.0.fb.branch" "3.1.fb" "3.2.fb" "3.3.fb" "3.4.fb" "3.5.fb" "3.6.fb" "3.7.fb" "3.8.fb" "3.9.fb" "4.2.fb" "4.3.fb" "4.4.fb" "4.5.fb" "4.6.fb" "4.7.fb" "4.8.fb" "4.9.fb" "4.10.fb" " ${ bak_backward_only_refs [@] } " )
if [ " $SHORT_TEST " ] ; then
# Use only the first (if exists) of each list
db_backward_only_refs = ( ${ db_backward_only_refs [0] } )
db_forward_no_options_refs = ( ${ db_forward_no_options_refs [0] } )
db_forward_with_options_refs = ( ${ db_forward_with_options_refs [0] } )
ext_backward_only_refs = ( ${ ext_backward_only_refs [0] } )
ext_forward_refs = ( ${ ext_forward_refs [0] } )
bak_backward_only_refs = ( ${ bak_backward_only_refs [0] } )
bak_forward_refs = ( ${ bak_forward_refs [0] } )
fi
# De-duplicate & accumulate
declare -a checkout_refs = ( )
for checkout_ref in " ${ db_backward_only_refs [@] } " " ${ db_forward_no_options_refs [@] } " " ${ db_forward_with_options_refs [@] } " " ${ ext_backward_only_refs [@] } " " ${ ext_forward_refs [@] } " " ${ bak_backward_only_refs [@] } " " ${ bak_forward_refs [@] } "
do
if [ ! -e $db_test_dir /$checkout_ref ] ; then
mkdir -p $db_test_dir /$checkout_ref
checkout_refs += ( $checkout_ref )
fi
done
2015-04-07 23:54:39 +00:00
generate_db( )
{
set +e
2022-08-11 20:33:06 +00:00
bash " $script_copy_dir " /generate_random_db.sh " $1 " " $2 "
2015-04-07 23:54:39 +00:00
if [ $? -ne 0 ] ; then
echo = = = = Error loading data from $2 to $1 = = = =
exit 1
fi
set -e
}
compare_db( )
{
set +e
2022-08-11 20:33:06 +00:00
bash " $script_copy_dir " /verify_random_db.sh " $1 " " $2 " " $3 " " $4 " " $5 "
2015-04-07 23:54:39 +00:00
if [ $? -ne 0 ] ; then
echo = = = = Read different content from $1 and $2 or error happened. = = = =
exit 1
fi
set -e
}
2018-08-24 21:23:42 +00:00
write_external_sst( )
{
set +e
2022-08-11 20:33:06 +00:00
bash " $script_copy_dir " /write_external_sst.sh " $1 " " $2 " " $3 "
2018-08-24 21:23:42 +00:00
if [ $? -ne 0 ] ; then
echo = = = = Error writing external SST file using data from $1 to $3 = = = =
exit 1
fi
set -e
}
ingest_external_sst( )
{
set +e
2022-08-11 20:33:06 +00:00
bash " $script_copy_dir " /ingest_external_sst.sh " $1 " " $2 "
2018-08-24 21:23:42 +00:00
if [ $? -ne 0 ] ; then
echo = = = = Error ingesting external SST in $2 to DB at $1 = = = =
exit 1
fi
set -e
}
2021-03-02 19:40:36 +00:00
backup_db( )
{
set +e
2022-08-11 20:33:06 +00:00
bash " $script_copy_dir " /backup_db.sh " $1 " " $2 "
2021-03-02 19:40:36 +00:00
if [ $? -ne 0 ] ; then
echo = = = = Error backing up DB $1 to $2 = = = =
exit 1
fi
set -e
}
2016-06-10 20:17:14 +00:00
2021-03-02 19:40:36 +00:00
restore_db( )
{
set +e
2022-08-11 20:33:06 +00:00
bash " $script_copy_dir " /restore_db.sh " $1 " " $2 "
2021-03-02 19:40:36 +00:00
if [ $? -ne 0 ] ; then
echo = = = = Error restoring from $1 to $2 = = = =
exit 1
fi
set -e
}
member_of_array( )
{
local e match = " $1 "
shift
for e; do [ [ " $e " = = " $match " ] ] && return 0; done
return 1
}
2021-08-11 23:01:27 +00:00
force_no_fbcode( )
{
# Not all branches recognize ROCKSDB_NO_FBCODE and we should not need
# to patch old branches for changes to available FB compilers.
sed -i -e 's|-d /mnt/gvfs/third-party|"$ROCKSDB_FORCE_FBCODE"|' build_tools/build_detect_platform
}
2021-03-02 19:40:36 +00:00
# General structure from here:
# * Check out, build, and do stuff with the "current" branch.
# * For each older branch under consideration,
# * Check out, build, and do stuff with it, potentially using data
# generated from "current" branch.
# * (Again) check out, build, and do (other) stuff with the "current"
# branch, potentially using data from older branches.
#
# This way, we only do at most n+1 checkout+build steps, without the
# need to stash away executables.
2018-08-24 21:23:42 +00:00
2021-03-02 19:40:36 +00:00
# Decorate name
current_checkout_name = " $current_checkout_name ( $current_checkout_hash ) "
2018-08-24 21:23:42 +00:00
2021-03-02 19:40:36 +00:00
echo " == Building $current_checkout_name debug "
git checkout -B $tmp_branch $current_checkout_hash
2021-08-11 23:01:27 +00:00
force_no_fbcode
2018-08-24 21:23:42 +00:00
make clean
2020-04-15 18:23:45 +00:00
DISABLE_WARNING_AS_ERROR = 1 make ldb -j32
2018-08-24 21:23:42 +00:00
2021-03-02 19:40:36 +00:00
echo " == Using $current_checkout_name , generate DB with extern SST and ingest "
current_ext_test_dir = $ext_test_dir "/current"
write_external_sst $input_data_path ${ current_ext_test_dir } _pointless $current_ext_test_dir
ingest_external_sst ${ current_ext_test_dir } _ingest $current_ext_test_dir
echo " == Generating DB from $current_checkout_name ... "
current_db_test_dir = $db_test_dir "/current"
generate_db $input_data_path $current_db_test_dir
echo " == Creating backup of DB from $current_checkout_name ... "
current_bak_test_dir = $bak_test_dir "/current"
backup_db $current_db_test_dir $current_bak_test_dir
for checkout_ref in " ${ checkout_refs [@] } "
2018-08-24 21:23:42 +00:00
do
2021-03-02 19:40:36 +00:00
echo " == Building $checkout_ref debug "
git reset --hard $tmp_origin /$checkout_ref
2021-08-11 23:01:27 +00:00
force_no_fbcode
2018-08-24 21:23:42 +00:00
make clean
2020-04-15 18:23:45 +00:00
DISABLE_WARNING_AS_ERROR = 1 make ldb -j32
2018-08-24 21:23:42 +00:00
2021-03-02 19:40:36 +00:00
# We currently assume DB backward compatibility for every branch listed
echo " == Use $checkout_ref to generate a DB ... "
generate_db $input_data_path $db_test_dir /$checkout_ref
2018-08-24 21:23:42 +00:00
2021-03-02 19:40:36 +00:00
if member_of_array " $checkout_ref " " ${ ext_backward_only_refs [@] } " ||
member_of_array " $checkout_ref " " ${ ext_forward_refs [@] } "
then
echo " == Use $checkout_ref to generate DB with extern SST file "
write_external_sst $input_data_path $ext_test_dir /${ checkout_ref } _pointless $ext_test_dir /$checkout_ref
fi
if member_of_array " $checkout_ref " " ${ ext_forward_refs [@] } "
then
echo " == Use $checkout_ref to ingest extern SST file and compare vs. $current_checkout_name "
ingest_external_sst $ext_test_dir /${ checkout_ref } _ingest $ext_test_dir /$checkout_ref
compare_db $ext_test_dir /${ checkout_ref } _ingest ${ current_ext_test_dir } _ingest db_dump.txt 1 1
rm -rf ${ ext_test_dir : ? } /${ checkout_ref } _ingest
echo " == Use $checkout_ref to ingest extern SST file from $current_checkout_name "
ingest_external_sst $ext_test_dir /${ checkout_ref } _ingest $current_ext_test_dir
compare_db $ext_test_dir /${ checkout_ref } _ingest ${ current_ext_test_dir } _ingest db_dump.txt 1 1
fi
if member_of_array " $checkout_ref " " ${ db_forward_no_options_refs [@] } " ||
member_of_array " $checkout_ref " " ${ db_forward_with_options_refs [@] } "
then
echo " == Use $checkout_ref to open DB generated using $current_checkout_name ... "
compare_db $db_test_dir /$checkout_ref $current_db_test_dir forward_${ checkout_ref } _dump.txt 0
fi
2015-04-07 23:54:39 +00:00
2021-03-02 19:40:36 +00:00
if member_of_array " $checkout_ref " " ${ db_forward_with_options_refs [@] } "
then
echo " == Use $checkout_ref to open DB generated using $current_checkout_name with its options... "
compare_db $db_test_dir /$checkout_ref $current_db_test_dir forward_${ checkout_ref } _dump.txt 1 1
fi
2015-04-07 23:54:39 +00:00
2021-03-02 19:40:36 +00:00
if member_of_array " $checkout_ref " " ${ bak_backward_only_refs [@] } " ||
member_of_array " $checkout_ref " " ${ bak_forward_refs [@] } "
then
echo " == Use $checkout_ref to backup DB "
backup_db $db_test_dir /$checkout_ref $bak_test_dir /$checkout_ref
fi
if member_of_array " $checkout_ref " " ${ bak_forward_refs [@] } "
then
echo " == Use $checkout_ref to restore DB from $current_checkout_name "
rm -rf ${ db_test_dir : ? } /$checkout_ref
restore_db $current_bak_test_dir $db_test_dir /$checkout_ref
compare_db $db_test_dir /$checkout_ref $current_db_test_dir forward_${ checkout_ref } _dump.txt 0
fi
done
echo " == Building $current_checkout_name debug (again, final) "
git reset --hard $current_checkout_hash
2021-08-11 23:01:27 +00:00
force_no_fbcode
2015-04-07 23:54:39 +00:00
make clean
2020-04-15 18:23:45 +00:00
DISABLE_WARNING_AS_ERROR = 1 make ldb -j32
2015-04-07 23:54:39 +00:00
2021-03-02 19:40:36 +00:00
for checkout_ref in " ${ checkout_refs [@] } "
2015-04-07 23:54:39 +00:00
do
2021-03-02 19:40:36 +00:00
# We currently assume DB backward compatibility for every branch listed
echo " == Use $current_checkout_name to open DB generated using $checkout_ref ... "
compare_db $db_test_dir /$checkout_ref $current_db_test_dir db_dump.txt 1 0
2015-04-07 23:54:39 +00:00
2021-03-02 19:40:36 +00:00
if member_of_array " $checkout_ref " " ${ ext_backward_only_refs [@] } " ||
member_of_array " $checkout_ref " " ${ ext_forward_refs [@] } "
then
rm -rf ${ ext_test_dir : ? } /${ checkout_ref } _ingest
echo " == Use $current_checkout_name to ingest extern SST file from $checkout_ref "
ingest_external_sst $ext_test_dir /${ checkout_ref } _ingest $current_ext_test_dir
compare_db $ext_test_dir /${ checkout_ref } _ingest ${ current_ext_test_dir } _ingest db_dump.txt 1 1
fi
2015-04-07 23:54:39 +00:00
2021-03-02 19:40:36 +00:00
if member_of_array " $checkout_ref " " ${ bak_backward_only_refs [@] } " ||
member_of_array " $checkout_ref " " ${ bak_forward_refs [@] } "
then
echo " == Use $current_checkout_name to restore DB from $checkout_ref "
rm -rf ${ db_test_dir : ? } /$checkout_ref
restore_db $bak_test_dir /$checkout_ref $db_test_dir /$checkout_ref
compare_db $db_test_dir /$checkout_ref $current_db_test_dir db_dump.txt 1 0
fi
2018-06-15 17:59:40 +00:00
done
2015-04-07 23:54:39 +00:00
echo = = = = Compatibility Test PASSED = = = =