Skip to content

My src .bashrc.local file

Jingyu Zhou edited this page Jan 9, 2023 · 6 revisions

Assuming in the okteto environment, src/.bashrc.local file is automatically sourced. Then we can easily do a few things:

  • cat the most recent trace file: cmr

  • Show more readable version of the most recent trace file: cmr | s | less

  • Show master recoveries:

$ cmr | grep --color=auto MasterRecoveryState | s
7.710926 MasterRecoveryState ID=daf5df154b8b4def StatusCode=0 Status=reading_coordinated_state
7.724563 MasterRecoveryState ID=daf5df154b8b4def StatusCode=1 Status=locking_coordinated_state TLogs=0 ActiveGenerations=1 MyRecoveryCount=2 ForceRecovery=0
8.394776 MasterRecoveryState ID=daf5df154b8b4def StatusCode=3 Status=reading_transaction_system_state
8.394776 MasterRecoveryState ID=daf5df154b8b4def StatusCode=5 Status=configuration_never_created
10.406976 MasterRecoveryState ID=daf5df154b8b4def StatusCode=7 Status=recruiting_transaction_servers Conf={backup_worker_enabled:1,commit_proxies:1,log_spill:2,log_version:6,logs:2,perpetual_storage_wiggle:1,perpetual_storage_wiggle_locality:data_hall:1,proxies:1,redundancy_mode:single,regions:[{datacenters:[{id:0,priority:2},{id:2,priority:1,satellite:1}]},{datacenters:[{id:1,priority:-1},{id:3,priority:1,satellite:1}]}],remote_redundancy_mode:remote_triple,storage_engine:ssd-redwood-experimental,storage_migration_type:disabled... RequiredCommitProxies=1 RequiredGrvProxies=1 RequiredResolvers=1
11.960971 MasterRecoveryState ID=5c7edea534e1b565 StatusCode=0 Status=reading_coordinated_state
11.964340 MasterRecoveryState ID=5c7edea534e1b565 StatusCode=1 Status=locking_coordinated_state TLogs=0 ActiveGenerations=1 MyRecoveryCount=3 ForceRecovery=0
11.977081 MasterRecoveryState ID=5c7edea534e1b565 StatusCode=3 Status=reading_transaction_system_state
11.977081 MasterRecoveryState ID=5c7edea534e1b565 StatusCode=5 Status=configuration_never_created
  • Customize searching: cmr | grep -E 'pattern1|pattern2|...' | s | less
  • Search Severity=40 events: cmr | s40
$ cmr | s40
<Event Severity="40" ErrorKind="Unset" Time="232.287646" DateTime="2021-11-12T02:15:16Z" Type="GetLatestCommitVersions" Machine="[abcd::3:4:3:5]:1" ID="0000000000000000" ReadVersion="524616678" Version vector="[{1:0,524605676}{0:0,524605676} maxversion: 524609182]" ThreadID="3524125355259437632" Backtrace="addr2line -e fdbserver.debug -p -C -f -i 0x354ef1d 0x354f199 0x354fb53 0x2ebb6f2 0x2f179aa 0x2f17724 0x2f173e8 0x2ed6ca0 0x2ede9cf 0x27a6a8d 0x27a713d 0x27a7648 0x2f23ad8 0x2f1709c 0x2f23648 0x2f233f3 0x2f22b98 0x2f19b0b 0x2f1d2e8 0x1322c88 0x13229cb 0x337a4d7 0x337a1d1 0x13224b8 0x34224b3 0x3422306 0x3421f71 0x3422352 0x34229fc 0x13224b8 0x34fcb66 0x34eea7d 0x33f191b 0x1a6acee 0x7ffff7105555" LogGroup="default" Roles="TS" />
<Event Severity="40" ErrorKind="BugDetected" Time="232.287646" DateTime="2021-11-12T02:15:16Z" Type="InternalError" Machine="[abcd::3:4:3:5]:1" ID="0000000000000000" Error="internal_error" ErrorDescription="An internal error occurred" ErrorCode="4100" FailedAssertion="false" File="/root/src/foundationdb/fdbclient/NativeAPI.actor.cpp" Line="217" ThreadID="3524125355259437632" Backtrace="addr2line -e fdbserver.debug -p -C -f -i 0x354ef1d 0x354f199 0x354fb53 0x34b561a 0x2ebbbe7 0x2f179aa 0x2f17724 0x2f173e8 0x2ed6ca0 0x2ede9cf 0x27a6a8d 0x27a713d 0x27a7648 0x2f23ad8 0x2f1709c 0x2f23648 0x2f233f3 0x2f22b98 0x2f19b0b 0x2f1d2e8 0x1322c88 0x13229cb 0x337a4d7 0x337a1d1 0x13224b8 0x34224b3 0x3422306 0x3421f71 0x3422352 0x34229fc 0x13224b8 0x34fcb66 0x34eea7d 0x33f191b 0x1a6acee 0x7ffff7105555" LogGroup="default" Roles="TS" />
<Event Severity="40" ErrorKind="Unset" Time="232.287646" DateTime="2021-11-12T02:15:16Z" Type="SystemError" Machine="[abcd::3:4:3:5]:1" ID="0000000000000000" Error="internal_error" ErrorDescription="An internal error occurred" ErrorCode="4100" ThreadID="3524125355259437632" Backtrace="addr2line -e fdbserver.debug -p -C -f -i 0x354ef1d 0x354f199 0x354fb53 0x34b59fe 0x34b562d 0x2ebbbe7 0x2f179aa 0x2f17724 0x2f173e8 0x2ed6ca0 0x2ede9cf 0x27a6a8d 0x27a713d 0x27a7648 0x2f23ad8 0x2f1709c 0x2f23648 0x2f233f3 0x2f22b98 0x2f19b0b 0x2f1d2e8 0x1322c88 0x13229cb 0x337a4d7 0x337a1d1 0x13224b8 0x34224b3 0x3422306 0x3421f71 0x3422352 0x34229fc 0x13224b8 0x34fcb66 0x34eea7d 0x33f191b 0x1a6acee 0x7ffff7105555" LogGroup="default" Roles="TS" />
  • Only compile fdbserver: ccmk fdbserver (clang) or cmk fdbserver (gcc)

  • Generate seeds from a Joshua xml output:

$ xt 20211111-193010-jzhou-ba16030593930175.xml
-r simulation --crash --logsize 1024MB -f ./foundationdb/tests/slow/SwizzledDdBalance.toml -s 524220244 -b off
-r simulation --crash --logsize 1024MB -f ./foundationdb/tests/slow/ConfigureStorageMigrationTest.toml -s 80026900 -b on

The src/.bashrc.local is:

alias vmr='cd ${HOME} && vim -u ~/.vimrc-syntax-off `ls *.xml -tr | tail -1`'
alias cmr='cat `ls *.xml -tr | tail -1`'
alias less='less -R'

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

## Rebundles Joshua correctness bundle with tests matching given
## pattern `tests_glob_pattern`. The new correctness bundle is
## created in current directory.
## Usage:
##   $ cbundle <correctness_bundle> <tests_glob_pattern>
## E.g.
##   Just bundle CycleTest
##     $ cbundle /path/to/correctnes.tar.gz tests/fast/CycleTest.toml
##   Bundle all tests in `fast` and all API tests
##     $ cbundle /path/to/correctness.tar.gz tests/fast tests/slow/Api*.toml
##   (Ex: cbundle correctness-7.0.0.tar.gz tests/fast tests/slow/Api*.toml)
function cbundle() {
    BUILD=~/build_output
    package=$1
    output_dir=$BUILD/rebundled_correctness/
    output=$output_dir/$(basename $package)
    echo "Bundle: $"
    echo "Selected Tests: $2"
    rm -rf $output_dir
    mkdir -p $output_dir
    tar xvf $1 -C $output_dir
    shift
    tar -C $output_dir -czf $output bin/ joshua_test joshua_timeout $@
    cp -f $output .
    rm -rf $output_dir
    echo "Output Package: $(pwd)/$(basename $output)"
}

function s40() {
  grep 'Severity="40"' "$@"
}

function s30() {
  grep 'Severity="30"' "$@"
}

# filter out unuseful stuff
function f() {
    grep -E -v 'Rolled|BuggifySection|Knob|PingLatency|(Transaction|Storage|Cache|LocalConfiguration|TLog|Proxy)Metrics|MachineLoadDetail|Sim2Connection|BusiestWriteTag|SlowSSLoopx100|SQLiteDBCreate|VFSAsync|KVThread|ConnectionKeeper|CoroStop|SQLiteDBDestroy|ConfigBroadcasterMetrics'
}

# simplify an XML output line
# For color/highlight, see https://misc.flogisoft.com/bash/tip_colors_and_formatting
# Use "less -R" to see formatted output.
function s() {
   grep -v Rolled | sed -e 's/ Machine="\([0-9:\.a-fA-F]\)*" / /' -e 's/LogGroup="default"//' -e 's/TrackLatestType="Original"//' -e 's|/>||' -e 's/&quot;/"/g' | sed -e 's/.*Time="\([0-9\.\]*\)".*" Type="\(.*\)" ID="\([a-f0-9]*\)"/\x1b[32m\1\x1b[0m \x1b[1m\2\x1b[0m ID=\x1b[91m\3\x1b[0m/' -e 's/  Roles="\([A-Z,]*\)"/ \x1b[34m\1\x1b[0m/' -e 's/ ThreadID="\([0-9]*\)"//' -e 's/"//g'
#  grep -v Rolled | sed  -e 's/.* Time="//' -e 's/LogGroup="default"//' -e 's|/>||' -e 's/&quot;/"/g' | sed -e 's/" Type="\(.*\)" Machine=".*" ID="\([a-f0-9]*\)"/ \x1b[1m\1\x1b[0m ID=\x1b[91m\2\x1b[0m/' -e 's/  Roles.*//' -e 's/ ThreadID="\([0-9]*\)"//' | cut -f 1,3- -d " " | sed -e 's/"//g'
}

# combine filter and simplify
function fs() {
   f | s
}

function sl() {
   s | less
}

# make some target, e.g., m fdbserver
function m() {
cmake -S ${HOME}/src/foundationdb -B ${HOME}/build_output -D USE_CCACHE=ON -D USE_WERROR=ON -D RocksDB_ROOT=/opt/rocksdb-6.27.3 -G Ninja && ninja -C ${HOME}/build_output -j 84 $@ && /usr/bin/cp -f ${HOME}/build_output/fdbclient/FDBOptions.g.h ${HOME}/src/foundationdb/fdbclient/
}

# Check master recovery state
function mr() {
  grep MasterRecoveryState "$@" | grep -v Rolled | grep -v ConfigurationMonitor | \
  sed -e 's/.* Time="//' -e 's/" Type="MasterRecoveryState" Machine/ m/' -e 's/Status="\([a-z_]*\)"/\1 /' -e 's/StatusCode="\([0-9]*\)"/\1/' -e 's/LogGroup="default" //' -e 's|TrackLatestType="Original" />||' -e 's/DateTime=".*Z m="//' -e 's/"//g' -e 's/ ThreadID=.*//' -e 's/&quot;/"/g'
}

# generate seeds for failed Joshua results
# You need to have pretty_xml.py in place and chmod +x to it
function xt() {
~/src/pretty_xml.py "$1" | grep RandomSeed | sed -e 's|.*BuggifyEnabled="\([0-1]*\)".*Determinism.*RandomSeed="\([0-9]*\)" .*TestFile=".*tests/\([a-z_A-Z/.0-9-]*\)" .*|-r simulation --crash --logsize 1024MB -f ./foundationdb/tests/\3 -s \2 \1|' | sed -e 's/\(.*\) 1$/\1 -b on/' -e 's/\(.*\) 0$/\1 -b off/' -e 's/-2.txt/-2.txt --restarting/' -e 's/-2.toml/-2.toml --restarting/'
}

function v() {
~/src/pretty_xml.py "$1" | less
}

function fdbver() {
cat ~/src/foundationdb/versions.target | grep '<Version>' | sed -e 's,^[^>]*>,,' -e 's,<.*,,'
}


############################################
## The following are not guaranteed to work
############################################

function bk() {
  grep -E 'BW|GotBackupProgress|BackupRecruitment|BackupWorker|ConsistencyCheck|QuietDatabase|TLogPop|LogRouterPop|TLogMetric|TLogRecover|PopVersion' "$@" | grep -v Rolled | s
}

function bkk() {
  # Output:
  #   339.707826" MaxTLogQueueSize="519" MaxTLogPoppedVersionLag="39311495" MaxStorageQueueSize="4690"
  bk "$@" | grep QuietDatabaseConsistencyCheckStart | awk '{print $1, $7, $9, $13}'
}
function bkt() {
  # Output:
  #  49.579523 184fc93b8504b51c PersistentDataDurableVersion 30538833 QueuePoppedVersion 1843736 Lag 28695097 TLogQ 6328
  bk "$@" | grep TLogMetrics | awk '{print $1, $4, $15, $17, $8, $11}' | sed -e 's/"//g' -e 's/=/ /g' | awk '{print $1, $3, $4, $5, $6, $7, "Lag", $5 - $7, "TLogQ", $8 - $9}' 
}

function dh() {
  # list data distributor events
  grep DataDistributor "$@" | grep -v Rolled | grep -E -v 'GotServerDBInfoChange|StorageServersRecruiting' | sed -e "s/<Event Severity=.* Time=\"//" -e "s| />||" -e 's/" Type="/ /' -e 's/" Machine/ m/' -e 's/&quot;/"/g' -e 's/ LogGroup.*//' -e 's/.*\.\([0-9]*\).xml:\(.*\)/\2 \1/' | sort -n
}

function dhh() {
  # list data distributor live/exit/rejoin events 
  dh "$@" | grep -E 'Recruit|DataDistributor(Died|_Error|_Running)|Transition="End"'
}

function dhhh() {
  # list data distributor live/exit/rejoin events 
  dh "$@" | grep --color=always -E 'DataDistributor_Running|Transition="End"'
}

function rk() {
  grep -i ratekeeper "$@" | s | grep -v -E 'Proxy_RatekeeperChanged|Rolled' | sort -n | grep -E 'Recruit|Halt|RKID=|"Begin"|"End"|CC_RateKeeperDied'
}

function cc() {
  # time increasing order of CC event
  grep CCWDB "$@" | grep -v Rolled | sed -e 's/.* Time="//' -e 's/" Type="CCWDB" Machine="/ m=/' -e 's/" ID="\([0-9a-f]*\)"/ \1/' -e 's| />||' -e 's/ LogGroup="default"//' | sort -n
}

# process plog file names and produce sorted version ranges
function plog() {
  awk '{print $9, $5}' | grep -v .part | grep -v .lnk | sed -e 's/,/ /g' | awk '{print $5, $2, $3, $4, $7}' | sort -n -k1 -k2 -k3
}

export ROCKS_ROOT=/opt/rocksdb-6.27.3
# valgrind build
function val() 
{ 
    cmake -S ${HOME}/src/foundationdb -B ${HOME}/build_output -D USE_VALGRIND=ON -D USE_CCACHE=ON -D USE_WERROR=ON -D RocksDB_ROOT=$ROCKS_ROOT -G Ninja && ninja -C ${HOME}/build_output -j 80 $@
}

# gcc build
function cmk() 
{ 
    cmake -S ${HOME}/src/foundationdb -B ${HOME}/build_output -D USE_CCACHE=ON -D USE_WERROR=ON -D RocksDB_ROOT=$ROCKS_ROOT -G Ninja && ninja -C ${HOME}/build_output -j 80 $@
}

# gperftool build
function cmkMem() 
{ 
    cmake -S ${HOME}/src/foundationdb -B ${HOME}/build_output -DUSE_GPERFTOOLS=1 -D USE_CCACHE=ON -D USE_WERROR=ON -D RocksDB_ROOT=$ROCKS_ROOT -G Ninja && ninja -C ${HOME}/build_output -j 80 $@
}

function ccmk() {
  CC=clang CXX=clang++ LD=lld cmake -S ${HOME}/src/foundationdb -B ${HOME}/cbuild_output -D USE_CCACHE=ON -D USE_LD=LLD -D USE_WERROR=ON -D RocksDB_ROOT=/opt/rocksdb-6.27.3 -D USE_LIBCXX=1 -G Ninja && ninja -C ${HOME}/cbuild_output -j 84 $@
}

function -r() {
	${HOME}/fdbserver -r $@
}

function -f() {
	${HOME}/fdbserver -r simulation --crash --logsize 1024MB -f $@
}

function c() {
  ccmk fdbserver
}

function b() {
  ccmk flowbench
}

One tool ~/src/pretty_xml.py for make Joshua result XML file more readable is:

#!/usr/bin/python2

import sys
import xml.dom.minidom

def main():
  if len(sys.argv) == 0:
    print 'Usage: python pretty_xml.py input.xml\n'
    return
  dom = xml.dom.minidom.parse(sys.argv[1])  # or xml.dom.minidom.parseString(xml_string)
  print dom.toprettyxml(indent="  ")

if __name__ == '__main__':
  main()

VS code shortcuts on Mac

  • Ctrl + `: show or hide the Terminal window
  • Cmd+Shift+]: Move to next terminal
  • Cmd+shift+[: Move to previous terminal