check_format_compatible.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/usr/bin/env bash
  2. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. #
  4. # A shell script to load some pre generated data file to a DB using ldb tool
  5. # ./ldb needs to be avaible to be executed.
  6. #
  7. # Usage: <SCRIPT> [checkout]
  8. # `checkout` can be a tag, commit or branch name. Will build using it and check DBs generated by all previous branches (or tags for very old versions without branch) can be opened by it.
  9. # Return value 0 means all regression tests pass. 1 if not pass.
  10. scriptpath=`dirname $BASH_SOURCE`
  11. test_dir=${TEST_TMPDIR:-"/tmp"}"/format_compatible_check"
  12. script_copy_dir=$test_dir"/script_copy"
  13. input_data_path=$test_dir"/test_data_input/"
  14. mkdir $test_dir || true
  15. mkdir $input_data_path || true
  16. rm -rf $script_copy_dir
  17. cp $scriptpath $script_copy_dir -rf
  18. # Generate random files.
  19. for i in {1..6}
  20. do
  21. input_data[$i]=$input_data_path/data$i
  22. echo == Generating random input file ${input_data[$i]}
  23. python - <<EOF
  24. import random
  25. random.seed($i)
  26. 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']
  27. with open('${input_data[$i]}', 'w') as f:
  28. for i in range(1,1024):
  29. k = ""
  30. for j in range(1, random.randint(1,32)):
  31. k=k + symbols[random.randint(0, len(symbols) - 1)]
  32. vb = ""
  33. for j in range(1, random.randint(0,128)):
  34. vb = vb + symbols[random.randint(0, len(symbols) - 1)]
  35. v = ""
  36. for j in range(1, random.randint(1, 5)):
  37. v = v + vb
  38. print >> f, k + " ==> " + v
  39. EOF
  40. done
  41. # Generate file(s) with sorted keys.
  42. sorted_input_data=$input_data_path/sorted_data
  43. echo == Generating file with sorted keys ${sorted_input_data}
  44. python - <<EOF
  45. with open('${sorted_input_data}', 'w') as f:
  46. for i in range(0,10):
  47. k = str(i)
  48. v = "value" + k
  49. print >> f, k + " ==> " + v
  50. EOF
  51. declare -a backward_compatible_checkout_objs=("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")
  52. declare -a forward_compatible_checkout_objs=("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" "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")
  53. declare -a forward_compatible_with_options_checkout_objs=("5.11.fb" "5.12.fb" "5.13.fb" "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")
  54. declare -a checkout_objs=(${backward_compatible_checkout_objs[@]} ${forward_compatible_checkout_objs[@]} ${forward_compatible_with_options_checkout_objs[@]})
  55. declare -a extern_sst_ingestion_compatible_checkout_objs=("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")
  56. generate_db()
  57. {
  58. set +e
  59. $script_copy_dir/generate_random_db.sh $1 $2
  60. if [ $? -ne 0 ]; then
  61. echo ==== Error loading data from $2 to $1 ====
  62. exit 1
  63. fi
  64. set -e
  65. }
  66. compare_db()
  67. {
  68. set +e
  69. $script_copy_dir/verify_random_db.sh $1 $2 $3 $4 $5
  70. if [ $? -ne 0 ]; then
  71. echo ==== Read different content from $1 and $2 or error happened. ====
  72. exit 1
  73. fi
  74. set -e
  75. }
  76. write_external_sst()
  77. {
  78. set +e
  79. $script_copy_dir/write_external_sst.sh $1 $2 $3
  80. if [ $? -ne 0 ]; then
  81. echo ==== Error writing external SST file using data from $1 to $3 ====
  82. exit 1
  83. fi
  84. set -e
  85. }
  86. ingest_external_sst()
  87. {
  88. set +e
  89. $script_copy_dir/ingest_external_sst.sh $1 $2
  90. if [ $? -ne 0 ]; then
  91. echo ==== Error ingesting external SST in $2 to DB at $1 ====
  92. exit 1
  93. fi
  94. set -e
  95. }
  96. # Sandcastle sets us up with a remote that is just another directory on the same
  97. # machine and doesn't have our branches. Need to fetch them so checkout works.
  98. # Remote add may fail if added previously (we don't cleanup).
  99. git remote add github_origin "https://github.com/facebook/rocksdb.git"
  100. set -e
  101. https_proxy="fwdproxy:8080" git fetch github_origin
  102. # Compatibility test for external SST file ingestion
  103. for checkout_obj in "${extern_sst_ingestion_compatible_checkout_objs[@]}"
  104. do
  105. echo == Generating DB with extern SST file in "$checkout_obj" ...
  106. https_proxy="fwdproxy:8080" git checkout github_origin/$checkout_obj -b $checkout_obj
  107. make clean
  108. make ldb -j32
  109. write_external_sst $input_data_path $test_dir/$checkout_obj $test_dir/$checkout_obj
  110. ingest_external_sst $test_dir/$checkout_obj $test_dir/$checkout_obj
  111. done
  112. checkout_flag=${1:-"master"}
  113. echo == Building $checkout_flag debug
  114. https_proxy="fwdproxy:8080" git checkout github_origin/$checkout_flag -b tmp-$checkout_flag
  115. make clean
  116. make ldb -j32
  117. compare_base_db_dir=$test_dir"/base_db_dir"
  118. write_external_sst $input_data_path $compare_base_db_dir $compare_base_db_dir
  119. ingest_external_sst $compare_base_db_dir $compare_base_db_dir
  120. for checkout_obj in "${extern_sst_ingestion_compatible_checkout_objs[@]}"
  121. do
  122. echo == Build "$checkout_obj" and try to open DB generated using $checkout_flag
  123. git checkout $checkout_obj
  124. make clean
  125. make ldb -j32
  126. compare_db $test_dir/$checkout_obj $compare_base_db_dir db_dump.txt 1 1
  127. git checkout tmp-$checkout_flag
  128. # Clean up
  129. git branch -D $checkout_obj
  130. done
  131. echo == Finish compatibility test for SST ingestion.
  132. for checkout_obj in "${checkout_objs[@]}"
  133. do
  134. echo == Generating DB from "$checkout_obj" ...
  135. https_proxy="fwdproxy:8080" git checkout github_origin/$checkout_obj -b $checkout_obj
  136. make clean
  137. make ldb -j32
  138. generate_db $input_data_path $test_dir/$checkout_obj
  139. done
  140. checkout_flag=${1:-"master"}
  141. echo == Building $checkout_flag debug
  142. git checkout tmp-$checkout_flag
  143. make clean
  144. make ldb -j32
  145. compare_base_db_dir=$test_dir"/base_db_dir"
  146. echo == Generate compare base DB to $compare_base_db_dir
  147. generate_db $input_data_path $compare_base_db_dir
  148. for checkout_obj in "${checkout_objs[@]}"
  149. do
  150. echo == Opening DB from "$checkout_obj" using debug build of $checkout_flag ...
  151. compare_db $test_dir/$checkout_obj $compare_base_db_dir db_dump.txt 1 0
  152. done
  153. for checkout_obj in "${forward_compatible_checkout_objs[@]}"
  154. do
  155. echo == Build "$checkout_obj" and try to open DB generated using $checkout_flag...
  156. git checkout $checkout_obj
  157. make clean
  158. make ldb -j32
  159. compare_db $test_dir/$checkout_obj $compare_base_db_dir forward_${checkout_obj}_dump.txt 0
  160. done
  161. for checkout_obj in "${forward_compatible_with_options_checkout_objs[@]}"
  162. do
  163. echo == Build "$checkout_obj" and try to open DB generated using $checkout_flag with its options...
  164. git checkout $checkout_obj
  165. make clean
  166. make ldb -j32
  167. compare_db $test_dir/$checkout_obj $compare_base_db_dir forward_${checkout_obj}_dump.txt 1 1
  168. done
  169. echo ==== Compatibility Test PASSED ====