Skip to content

Instantly share code, notes, and snippets.

@dmagda
Last active December 20, 2022 16:01
Show Gist options
  • Save dmagda/d0749805a320f3623011de1722e5ae6a to your computer and use it in GitHub Desktop.
Save dmagda/d0749805a320f3623011de1722e5ae6a to your computer and use it in GitHub Desktop.
YugabyteDB Outage Demo

YugabyteDB Outage Demo

Use this demo to showcase how YugabyteDB handles failures.

Start Cluster

Create the custom network:

docker network create custom-network

Start a three-node YugabyteDB cluster:

rm -r ~/yb_docker_data
mkdir ~/yb_docker_data

docker run -d --name yugabytedb_node0 --net custom-network \
  -p 7001:7000 -p 9000:9000 -p 5433:5433 \
  -v ~/yb_docker_data/node0:/home/yugabyte/yb_data --restart unless-stopped \
  yugabytedb/yugabyte:2.15.1.0-b175 \
  bin/yugabyted start --listen=yugabytedb_node0 \
  --base_dir=/home/yugabyte/yb_data --daemon=false

docker run -d --name yugabytedb_node1 --net custom-network \
  -p 7002:7000 \
  -v ~/yb_docker_data/node1:/home/yugabyte/yb_data --restart unless-stopped \
  yugabytedb/yugabyte:2.15.1.0-b175 \
  bin/yugabyted start --join=yugabytedb_node0 --listen=yugabytedb_node1 \
  --base_dir=/home/yugabyte/yb_data --daemon=false

docker run -d --name yugabytedb_node2 --net custom-network \
  -p 7003:7000 \
  -v ~/yb_docker_data/node2:/home/yugabyte/yb_data --restart unless-stopped \
  yugabytedb/yugabyte:2.15.1.0-b175 \
  bin/yugabyted start --join=yugabytedb_node0 --listen=yugabytedb_node2 \
  --base_dir=/home/yugabyte/yb_data --daemon=false

Open the console UI by connecting to the first node: http://127.0.0.1:7001

Start App

  1. Clone the app:
git clone https://github.com/YugabyteDB-Samples/market-orders-app.git
  1. Build the docker image:
mvn clean package 
docker rmi market-orders-app
docker build -t market-orders-app .
  1. Start the app using the default Postgres driver:
  docker run --name market-orders-instance --net custom-network \
  market-orders-app:latest \
  java -jar /home/target/market-orders-app.jar \
  connectionProps=/home/yugabyte-docker-pg-driver.properties \
  loadScript=/home/schema_postgres.sql \
  refreshView=false tradeStatsInterval=5000

Simulate Outage

  1. Stop the first node the app is connected to:
docker stop yugabytedb_node1
  1. Show the app logs and the console UI. The app can't longer reach the database and there is no load on the cluster.

  2. Bring the node back:

docker start yugabytedb_node1
  1. Start the app's container:
docker start market-orders-instance -a

Switch to Cluster-Aware Driver

  1. Stop the app instance:
docker stop market-orders-instance
docker container rm market-orders-instance
  1. Start the app using the cluster-aware driver:
docker run --name market-orders-instance --net custom-network \
market-orders-app:latest \
java -jar /home/target/market-orders-app.jar \
connectionProps=/home/yugabyte-docker.properties \
loadScript=/home/schema_postgres.sql \
refreshView=false tradeStatsInterval=5000
  1. Repeat the outage scenario. This time the application will continue working even when one of the nodes is down.

Clear Demo Resources

  docker kill yugabytedb_node0
  docker container rm yugabytedb_node0
  
  docker kill yugabytedb_node1
  docker container rm yugabytedb_node1
  
  docker kill yugabytedb_node2
  docker container rm yugabytedb_node2
  
  docker kill market-orders-instance
  docker container rm market-orders-instance
  
  docker network rm custom-network
  
  rm -r ~/yb_docker_data
  mkdir ~/yb_docker_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment