analyze_txn_stress_test.sh 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. # Usage:
  4. # 1. Enable ROCKS_LOG_DETAILS in util/logging.h
  5. # 2. Run ./transaction_test --gtest_filter="MySQLStyleTransactionTest/MySQLStyleTransactionTest.TransactionStressTest/*" --gtest_break_on_failure
  6. # 3. SET=1 # 2 or 3
  7. # 4. LOG=/dev/shm/transaction_testdb_8600601584148590297/LOG
  8. # 5. grep RandomTransactionVerify $LOG | cut -d' ' -f 12 | sort -n # to find verify snapshots
  9. # 5. vn=1345
  10. # 6. vn_1=1340
  11. # 4. . tools/tools/analyze_txn_stress_test.sh
  12. echo Input params:
  13. # The rocksdb LOG path
  14. echo $LOG
  15. # Snapshot at which we got RandomTransactionVerify failure
  16. echo $vn
  17. # The snapshot before that where RandomTransactionVerify passed
  18. echo $vn_1
  19. # The stress tests use 3 sets, one or more might have shown inconsistent results.
  20. SET=${SET-1} # 1 or 2 or 3
  21. echo Checking set number $SET
  22. # Find the txns that committed between the two snapshots, and gather their changes made by them in /tmp/changes.txt
  23. # 2019/02/28-15:25:51.655477 7fffec9ff700 [DEBUG] [ilities/transactions/write_prepared_txn_db.cc:416] Txn 68497 Committing with 68498
  24. grep Committing $LOG | awk '{if ($9 <= vn && $9 > vn_1) print $0}' vn=$vn vn_1=${vn_1} > /tmp/txn.txt
  25. # 2019/02/28-15:25:49.046464 7fffe81f5700 [DEBUG] [il/transaction_test_util.cc:216] Commit of 65541 OK (txn12936193128775589751-9089)
  26. for i in `cat /tmp/txn.txt | awk '{print $6}'`; do grep "Commit of $i " $LOG; done > /tmp/names.txt
  27. for n in `cat /tmp/names.txt | awk '{print $9}'`; do grep $n $LOG; done > /tmp/changes.txt
  28. echo "Sum of the changes:"
  29. cat /tmp/changes.txt | grep Insert | awk '{print $12}' | cut -d= -f1 | cut -d+ -f2 | awk '{sum+=$1} END{print sum}'
  30. # Gather read values at each snapshot
  31. # 2019/02/28-15:25:51.655926 7fffebbff700 [DEBUG] [il/transaction_test_util.cc:347] VerifyRead at 67972 (67693): 000230 value: 15983
  32. grep "VerifyRead at ${vn_1} (.*): 000${SET}" $LOG | cut -d' ' -f 9- > /tmp/va.txt
  33. grep "VerifyRead at ${vn} (.*): 000${SET}" $LOG | cut -d' ' -f 9- > /tmp/vb.txt
  34. # For each key in the 2nd snapshot, find the value read by 1st, do the adds, and see if the results match.
  35. IFS=$'\n'
  36. for l in `cat /tmp/vb.txt`;
  37. do
  38. grep $l /tmp/va.txt > /dev/null ;
  39. if [[ $? -ne 0 ]]; then
  40. #echo $l
  41. k=`echo $l | awk '{print $1}'`;
  42. v=`echo $l | awk '{print $3}'`;
  43. # 2019/02/28-15:25:19.350111 7fffe81f5700 [DEBUG] [il/transaction_test_util.cc:194] Insert (txn12936193128775589751-2298) OK snap: 16289 key:000219 value: 3772+95=3867
  44. exp=`grep "\<$k\>" /tmp/changes.txt | tail -1 | cut -d= -f2`;
  45. if [[ $v -ne $exp ]]; then echo $l; fi
  46. else
  47. k=`echo $l | awk '{print $1}'`;
  48. grep "\<$k\>" /tmp/changes.txt
  49. fi;
  50. done
  51. # Check that all the keys read in the 1st snapshot are still visible in the 2nd
  52. for l in `cat /tmp/va.txt`;
  53. do
  54. k=`echo $l | awk '{print $1}'`;
  55. grep "\<$k\>" /tmp/vb.txt > /dev/null
  56. if [[ $? -ne 0 ]]; then
  57. echo missing key $k
  58. fi
  59. done
  60. # The following found a bug in ValidateSnapshot. It checks if the adds on each key match up.
  61. grep Insert /tmp/changes.txt | cut -d' ' -f 10 | sort | uniq > /tmp/keys.txt
  62. for k in `cat /tmp/keys.txt`;
  63. do
  64. grep "\<$k\>" /tmp/changes.txt > /tmp/adds.txt;
  65. # 2019/02/28-15:25:19.350111 7fffe81f5700 [DEBUG] [il/transaction_test_util.cc:194] Insert (txn12936193128775589751-2298) OK snap: 16289 key:000219 value: 3772+95=3867
  66. START=`head -1 /tmp/adds.txt | cut -d' ' -f 12 | cut -d+ -f1`
  67. END=`tail -1 /tmp/adds.txt | cut -d' ' -f 12 | cut -d= -f2`
  68. ADDS=`cat /tmp/adds.txt | grep Insert | awk '{print $12}' | cut -d= -f1 | cut -d+ -f2 | awk '{sum+=$1} END{print sum}'`
  69. EXP=$((START+ADDS))
  70. # If first + all the adds != last then there was an issue with ValidateSnapshot.
  71. if [[ $END -ne $EXP ]]; then echo inconsistent txn: $k $START+$ADDS=$END; cat /tmp/adds.txt; return 1; fi
  72. done