github.com/m3db/m3@v1.5.0/scripts/docker-integration-tests/repair/test.sh (about) 1 #!/usr/bin/env bash 2 3 set -xe 4 5 source "$M3_PATH"/scripts/docker-integration-tests/common.sh 6 REVISION=$(git rev-parse HEAD) 7 SCRIPT_PATH="$M3_PATH"/scripts/docker-integration-tests/repair 8 COMPOSE_FILE=$SCRIPT_PATH/docker-compose.yml 9 export REVISION 10 11 echo "Run m3dbnode and m3coordinator containers" 12 docker-compose -f ${COMPOSE_FILE} up -d --renew-anon-volumes dbnode01 13 docker-compose -f ${COMPOSE_FILE} up -d --renew-anon-volumes dbnode02 14 docker-compose -f ${COMPOSE_FILE} up -d --renew-anon-volumes coordinator01 15 16 # Think of this as a defer func() in golang 17 function defer { 18 docker-compose -f ${COMPOSE_FILE} down || echo "unable to shutdown containers" # CI fails to stop all containers sometimes 19 } 20 trap defer EXIT 21 22 setup_two_m3db_nodes 23 24 function write_data { 25 namespace=$1 26 id=$2 27 timestamp=$3 28 value=$4 29 port=$5 30 31 respCode=$(curl -s -o /dev/null -X POST -w "%{http_code}" 0.0.0.0:"$port"/write -d '{ 32 "namespace": "'"$namespace"'", 33 "id": "'"$id"'", 34 "datapoint": { 35 "timestamp":'"$timestamp"', 36 "value": '"$value"' 37 } 38 }') 39 40 41 if [[ $respCode -eq "200" ]]; then 42 return 0 43 else 44 return 1 45 fi 46 } 47 48 function read_all { 49 namespace=$1 50 id=$2 51 expected_datapoints=$3 52 port=$4 53 54 received_datapoints=$(curl -sSf -X POST 0.0.0.0:"$port"/fetch -d '{ 55 "namespace": "'"$namespace"'", 56 "id": "'"$id"'", 57 "rangeStart": 0, 58 "rangeEnd":'"$(date +"%s")"' 59 }' | jq '.datapoints | length') 60 61 if [[ $expected_datapoints -eq $received_datapoints ]]; then 62 return 0 63 else 64 return 1 65 fi 66 } 67 68 # Write 2 block sizes into the past to ensure it's a repairable block since the current mutable 69 # block will not be repaired. Use the node-specific port to ensure the write only goes to dbnode01 70 # and not the other two nodes. 71 echo "Write data for 'now - 2 * blockSize' to dbnode01" 72 write_data "coldWritesRepairAndNoIndex" "foo" "$(($(date +"%s") - 60 * 60 * 2))" 12.3456789 9012 73 74 # This should pass immediately since it was written to this node. 75 echo "Expect to read the data back from dbnode01" 76 read_all "coldWritesRepairAndNoIndex" "foo" 1 9012 77 78 # This should eventually succeed once a repair detects the mismatch. 79 echo "Wait for the data to become available (via repairs) from dbnode02" 80 ATTEMPTS=30 MAX_TIMEOUT=4 TIMEOUT=1 retry_with_backoff \ 81 read_all "coldWritesRepairAndNoIndex" "foo" 1 9022