Skip to content

Instantly share code, notes, and snippets.

@thieman
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thieman/e28d426d3415c30caf38 to your computer and use it in GitHub Desktop.
Save thieman/e28d426d3415c30caf38 to your computer and use it in GitHub Desktop.
MongoDB 3.0.4 critical section cascading failure repro
rs1n1:
image: mongo:3.0.4
command: mongod --replSet rs1 --storageEngine wiredTiger
rs1n2:
image: mongo:3.0.4
command: mongod --replSet rs1 --storageEngine wiredTiger
rs1n3:
image: mongo:3.0.4
command: mongod --replSet rs1 --storageEngine wiredTiger
rs2n1:
image: mongo:3.0.4
command: mongod --replSet rs2 --storageEngine wiredTiger
rs2n2:
image: mongo:3.0.4
command: mongod --replSet rs2 --storageEngine wiredTiger
rs2n3:
image: mongo:3.0.4
command: mongod --replSet rs2 --storageEngine wiredTiger
config1:
image: mongo:3.0.4
command: mongod --configsvr --storageEngine wiredTiger --dbpath /data/db
config2:
image: mongo:3.0.4
command: mongod --configsvr --storageEngine wiredTiger --dbpath /data/db
config3:
image: mongo:3.0.4
command: mongod --configsvr --storageEngine wiredTiger --dbpath /data/db
mongos:
image: mongo:3.0.4
command: sleep infinity
#!/usr/bin/env bash
set -e
echo "Spinning up containers with Docker Compose..."
docker-compose -p mongo -f mongo-cluster.yml up -d
RS1N1=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_rs1n1_1`
RS1N2=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_rs1n2_1`
RS1N3=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_rs1n3_1`
RS2N1=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_rs2n1_1`
RS2N2=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_rs2n2_1`
RS2N3=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_rs2n3_1`
CONFIG1=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_config1_1`
CONFIG2=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_config2_1`
CONFIG3=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo_config3_1`
echo "Initializing rs1..."
docker exec mongo_rs1n1_1 mongo --eval "printjson(rs.initiate({_id: 'rs1', members: [{_id: 0, host: '$RS1N1'}]}))"
docker exec mongo_rs1n1_1 mongo --eval "printjson(rs.add('$RS1N2'))"
docker exec mongo_rs1n1_1 mongo --eval "printjson(rs.add({_id: 2, host: '$RS1N3', priority: 0}))"
echo "Initializing rs2..."
docker exec mongo_rs2n1_1 mongo --eval "printjson(rs.initiate({_id: 'rs2', members: [{_id: 0, host: '$RS2N1'}]}))"
docker exec mongo_rs2n1_1 mongo --eval "printjson(rs.add('$RS2N2'))"
docker exec mongo_rs2n1_1 mongo --eval "printjson(rs.add({_id: 2, host: '$RS2N3', priority: 0}))"
echo "Starting mongos..."
docker exec -d mongo_mongos_1 mongos --configdb $CONFIG1,$CONFIG2,$CONFIG3
echo "Giving replica sets a few seconds to get synchronized..."
sleep 5
echo "Disabling balancer..."
docker exec mongo_mongos_1 mongo --eval "printjson(sh.stopBalancer())"
echo "Adding first replicaset to cluster through mongos..."
docker exec mongo_mongos_1 mongo --eval "printjson(sh.addShard('rs1/$RS1N1'))"
echo "Enabling sharding on data database..."
docker exec mongo_mongos_1 mongo --eval "printjson(sh.enableSharding('data'))"
echo "Making two collections with 100 initial chunks"
docker exec mongo_mongos_1 mongo --eval "printjson(db.getSiblingDB('admin').runCommand({shardCollection: 'data.test1', key: {_id: 'hashed'}, numInitialChunks: 100}))"
docker exec mongo_mongos_1 mongo --eval "printjson(db.getSiblingDB('admin').runCommand({shardCollection: 'data.test2', key: {_id: 'hashed'}, numInitialChunks: 100}))"
echo "Adding second replicaset to cluster through mongos..."
docker exec mongo_mongos_1 mongo --eval "printjson(sh.addShard('rs2/$RS2N1'))"
echo "Enabling balancer..."
docker exec mongo_mongos_1 mongo --eval "printjson(sh.startBalancer())"
echo "Balancing is underway."
echo "Use the following iptables incantation to make the balancer crash rs1n1, then crash rs1n2."
echo "WARNING: This is gonna screw with your system iptables, you probably want to do this in a VM or something."
echo ""
cat <<EOF
sudo iptables -F FORWARD
echo "About to spring the trap on rs1n1..."
docker logs -f mongo_rs1n1_1 | grep -m 5 'migrate commit accepted by TO-shard' && sudo iptables -A FORWARD -s $RS1N1 -d $CONFIG1 -j DROP
echo "Waiting 20 seconds for rs1n1 to die..."
sleep 20
sudo iptables -F FORWARD
echo "About to spring the trap on rs1n2, which should be primary now..."
docker logs -f mongo_rs1n2_1 | grep -m 5 'migrate commit accepted by TO-shard' && sudo iptables -A FORWARD -s $RS1N2 -d $CONFIG1 -j DROP
echo "rs1n2 should die in about 15 seconds"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment