github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ais/test/scripts/remais-prefetch-latest.sh (about)

     1  #!/bin/bash
     2  
     3  ## Prerequisites: #################################################################################
     4  # - aistore cluster
     5  # - remote aistore cluster (a.k.a. "remais")
     6  # - optionally, remais bucket (the bucket will be created if doesn't exist)
     7  # - ais (CLI)
     8  #
     9  ## Example:
    10  ## first, make sure remote ais cluster is attached:
    11  ##
    12  #  $ ais show remote-cluster -H
    13  #  $ JcHy3JUrL  http://127.0.0.1:11080  remais    v9  1  11m22.312048996s
    14  #
    15  ## and run:
    16  #  $ remais-prefetch-latest.sh --bucket ais://@remais/abc
    17  
    18  if ! [ -x "$(command -v ais)" ]; then
    19    echo "Error: ais (CLI) not installed" >&2
    20    exit 1
    21  fi
    22  
    23  lorem='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
    24  
    25  duis='Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Et harum quidem..'
    26  
    27  ## Command line options (and their respective defaults)
    28  bucket="ais://@remais/abc"
    29  
    30  ## constants
    31  sum1="xxhash[ad97df912d23103f]"
    32  sum2="xxhash[ecb5ed42299ea74d]"
    33  
    34  while (( "$#" )); do
    35    case "${1}" in
    36      --bucket) bucket=$2; shift; shift;;
    37      *) echo "fatal: unknown argument '${1}'"; exit 1;;
    38    esac
    39  done
    40  
    41  ## uncomment for verbose output
    42  ## set -x
    43  
    44  ## must be @remais
    45  [[ "$bucket" == *//@* ]] || { echo "Error: expecting remote ais bucket, got ${bucket}"; exit 1; }
    46  
    47  ## actual bucket inside remais:
    48  rbucket="ais://$(basename ${bucket})"
    49  
    50  ## remais must be attached
    51  rendpoint=$(ais show remote-cluster -H | awk '{print $2}')
    52  [[ ! -z "$rendpoint" ]] || { echo "Error: no remote ais clusters"; exit 1; }
    53  
    54  ## check remote bucket; create if doesn't exist
    55  exists=true
    56  AIS_ENDPOINT=$rendpoint ais show bucket $rbucket -c 1>/dev/null 2>&1 || exists=false
    57  [[ "$exists" == "true" ]] || AIS_ENDPOINT=$rendpoint ais create $rbucket || exit 1
    58  
    59  ## add it to _this_ cluster's BMD
    60  ais show bucket $bucket --add 1>/dev/null || exit 1
    61  
    62  ## remember existing bucket 'versioning' settings; disable synchronization if need be
    63  validate=$(ais bucket props show ${bucket} versioning.validate_warm_get -H | awk '{print $2}')
    64  [[ "$validate" == "false"  ]] || ais bucket props set $bucket versioning.validate_warm_get=false
    65  sync=$(ais bucket props show ${bucket} versioning.synchronize -H | awk '{print $2}')
    66  [[ "$sync" == "false"  ]] || ais bucket props set $bucket versioning.synchronize=false
    67  
    68  cleanup() {
    69    rc=$?
    70    ais object rm "$bucket/lorem-duis" 1>/dev/null 2>&1
    71    [[ "$validate" == "true"  ]] || ais bucket props set $bucket versioning.validate_warm_get=false 1>/dev/null 2>&1
    72    [[ "$sync" == "true"  ]] || ais bucket props set $bucket versioning.synchronize=false 1>/dev/null 2>&1
    73    [[ "$exists" == "true" ]] || ais rmb $bucket -y 1>/dev/null 2>&1
    74    exit $rc
    75  }
    76  
    77  trap cleanup EXIT INT TERM
    78  
    79  echo -e
    80  ais show performance counters --regex "(GET-COLD$|VERSION-CHANGE$|DELETE)"
    81  echo -e
    82  
    83  echo "1. out-of-band PUT: 1st version"
    84  echo $lorem | AIS_ENDPOINT=$rendpoint ais put - "$rbucket/lorem-duis" 1>/dev/null || exit $?
    85  
    86  echo "2. prefetch, and check"
    87  ais prefetch "$bucket/lorem-duis" --wait
    88  checksum=$(ais ls "$bucket/lorem-duis" --cached -H -props checksum | awk '{print $2}')
    89  [[ "$checksum" == "$sum1"  ]] || { echo "FAIL: $checksum != $sum1"; exit 1; }
    90  
    91  echo "3. out-of-band PUT: 2nd version (overwrite)"
    92  echo $duis | AIS_ENDPOINT=$rendpoint ais put - "$rbucket/lorem-duis" 1>/dev/null || exit $?
    93  
    94  echo "4. prefetch and check (expecting the first version's checksum)"
    95  ais prefetch "$bucket/lorem-duis" --wait
    96  checksum=$(ais ls "$bucket/lorem-duis" --cached -H -props checksum | awk '{print $2}')
    97  [[ "$checksum" != "$sum2"  ]] || { echo "FAIL: $checksum == $sum2"; exit 1; }
    98  
    99  echo "5. query cold-get count (statistics)"
   100  cnt1=$(ais show performance counters --regex GET-COLD -H | awk '{sum+=$2;}END{print sum;}')
   101  
   102  echo "6. prefetch latest: detect version change and update in-cluster copy"
   103  ais prefetch "$bucket/lorem-duis" --latest --wait
   104  checksum=$(ais ls "$bucket/lorem-duis" --cached -H -props checksum | awk '{print $2}')
   105  [[ "$checksum" == "$sum2"  ]] || { echo "FAIL: $checksum != $sum2"; exit 1; }
   106  
   107  echo "7. cold-get counter must increment"
   108  cnt2=$(ais show performance counters --regex GET-COLD -H | awk '{sum+=$2;}END{print sum;}')
   109  [[ $cnt2 == $(($cnt1+1)) ]] || { echo "FAIL: $cnt2 != $(($cnt1+1))"; exit 1; }
   110  
   111  echo "8. warm GET must remain \"warm\" and cold-get-count must not increment"
   112  ais get "$bucket/lorem-duis" /dev/null 1>/dev/null
   113  checksum=$(ais ls "$bucket/lorem-duis" --cached -H -props checksum | awk '{print $2}')
   114  [[ "$checksum" == "$sum2"  ]] || { echo "FAIL: $checksum != $sum2"; exit 1; }
   115  
   116  cnt3=$(ais show performance counters --regex GET-COLD -H | awk '{sum+=$2;}END{print sum;}')
   117  [[ $cnt3 == $cnt2 ]] || { echo "FAIL: $cnt3 != $cnt2"; exit 1; }
   118  
   119  echo "9. out-of-band DELETE"
   120  AIS_ENDPOINT=$rendpoint ais object rm "$rbucket/lorem-duis" 1>/dev/null || exit $?
   121  
   122  echo "10. prefetch without '--latest': expecting no changes"
   123  ais prefetch "$bucket/lorem-duis" --wait
   124  checksum=$(ais ls "$bucket/lorem-duis" --cached -H -props checksum | awk '{print $2}')
   125  [[ "$checksum" == "$sum2"  ]] || { echo "FAIL: $checksum != $sum2"; exit 1; }
   126  
   127  echo "11. remember 'remote-deleted' counter, enable version synchronization on the bucket"
   128  cnt4=$(ais show performance counters --regex REMOTE-DEL -H | awk '{sum+=$2;}END{print sum;}')
   129  ais bucket props set $bucket versioning.synchronize=true
   130  
   131  echo "12. run 'prefetch --latest' one last time, and make sure the object \"disappears\""
   132  ais prefetch "$bucket/lorem-duis" --latest --wait 2>/dev/null
   133  [[ $? == 0 ]] || { echo "FAIL: expecting 'prefetch --wait' to return Ok, got $?"; exit 1; }
   134  
   135  echo "13. 'remote-deleted' counter must increment"
   136  cnt5=$(ais show performance counters --regex REMOTE-DEL -H | awk '{sum+=$2;}END{print sum;}')
   137  [[ $cnt5 == $(($cnt4+1)) ]] || { echo "FAIL: $cnt5 != $(($cnt4+1))"; exit 1; }
   138