Use this demo to showcase how YugabyteDB handles failures.
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
- Clone the app:
git clone https://github.com/YugabyteDB-Samples/market-orders-app.git
- Build the docker image:
mvn clean package
docker rmi market-orders-app
docker build -t market-orders-app .
- 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
- Stop the first node the app is connected to:
docker stop yugabytedb_node1
-
Show the app logs and the console UI. The app can't longer reach the database and there is no load on the cluster.
-
Bring the node back:
docker start yugabytedb_node1
- Start the app's container:
docker start market-orders-instance -a
- Stop the app instance:
docker stop market-orders-instance
docker container rm market-orders-instance
- 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
- Repeat the outage scenario. This time the application will continue working even when one of the nodes is down.
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