Skip to content

Commit

Permalink
PMM-12510 correctly recognize arbiter nodes (#755)
Browse files Browse the repository at this point in the history
* add networks

* accept exit code

* use replica set status for node states

* drop external links

* fix formatting

* convert to table tests

* fix topology tests

* include hello command for arbiter nodes

* use parallel tests

* add tests for hello metrics

* attempt to satisfy golint

* use single command for replica setup

* improve naming

* reduce external calls

* add method comments

* use isMaster for compatibility

* PMM-12712 Shards collector. (#762)

* PMM-12712 Shard ID and count.

* PMM-12712 Name and count.

* PMM-12712 Sharded collector.

* PMM-12712 Remove missed print.

* PMM-12712 Revert test changes.

* PMM-12712 Revert old not related changes.

* PMM-12712 Another changes.

* PMM-12712 Missed print.

* PMM-12712 Align naming with task description.

* PMM-12712 Add mongos test client.

* PMM-12712 Lint.

* PMM-12712 Lint.

* PMM-12712 Typo.

* PMM-12712 Lint.

* PMM-12712 Test higher sleep.

* Revert "PMM-12712 Test higher sleep."

This reverts commit 88451ba.

* PMM-12712 Test of pipeline.

* PMM-12712 Change.

* PMM-12712 Test.

* PMM-12712 Test.

* PMM-12712 Test.

* PMM-12712 Correct aggregation to get chunks info.

* PMM-12712 Another progress.

* PMM-12702 Small refactor.

* PMM-12712 Test.

* PMM-12712 Fix, tests.

* PMM-12712 Temp.

* PMM-12712 Improve sharded test.

* PMM-12712 Change in workflow.

* PMM-12712 Remove print.

* PMM-12712 Init script changes.

* PMM-12712 Remove print.

* PMM-12712 Bigger sleep.

* PMM-12712 Refactor.

* PMM-12712 Small refactor.

* PMM-12712 Another refactor.

* PMM-12712 Fix after refactor.

* PMM-12712 Alias.

* PMM-12712 Alias for shell in older versions.

* PMM-12712 Static test shard.

* PMM-12712 Fix another tests, mongo 4 shell script.

* PMM-12712 Big sleep test.

* PMM-12712 Michael's fix.

* PMM-12712 Sleep.

* PMM-12712 Env.

* PMM-12712 Test.

* PMM-12712 Fix test.

* PMM-12712 Bigger sleep after changes.

* PMM-12712 Remove duplicate lines.

* PMM-12712 Renaming from sharded to shards.

* PMM-12712 Better script to detect proper mongo client.

* PMM-12712 Init script refactor.

* PMM-12712 Fix.

* PMM-12712 Small refactor.

* Update main.go

Co-authored-by: Michael Okoko <[email protected]>

* Update exporter/shards_collector.go

Co-authored-by: Michael Okoko <[email protected]>

* PMM-12712 Remove mongo 6 for now, skip test for shards.

* PMM-12712 Revert sleep length.

* PMM-12712 Mongo client based on vendor.

---------

Co-authored-by: Michael Okoko <[email protected]>

* add wait to docker compose command

* remove wait from docker compose command

---------

Co-authored-by: Jiří Čtvrtka <[email protected]>
  • Loading branch information
idoqo and JiriCtvrtka authored Jan 17, 2024
1 parent d67f79d commit b173af7
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 162 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test-race: env ## Run all tests with race flag.
go test -race -v -timeout 30s ./...

test-cluster: env ## Starts MongoDB test cluster. Use env var TEST_MONGODB_IMAGE to set flavor and version. Example: TEST_MONGODB_IMAGE=mongo:3.6 make test-cluster
docker compose up -d --wait
docker compose up -d

test-cluster-clean: env ## Stops MongoDB test cluster.
docker compose down --remove-orphans
91 changes: 55 additions & 36 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,39 @@ services:
ports:
- "${TEST_MONGODB_S1_PRIMARY_PORT:-17001}:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
links:
- mongo-1-2:mongo-1-2
- mongo-1-3:mongo-1-3
networks:
- rs1
depends_on:
- "mongo-1-2"
- "mongo-1-3"
- "mongo-1-arbiter"

mongo-1-2:
container_name: "mongo-1-2"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S1_SECONDARY1_PORT:-17002}:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
networks:
- rs1

mongo-1-3:
container_name: "mongo-1-3"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S1_SECONDARY2_PORT:-17003}:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
networks:
- rs1

mongo-1-arbiter:
container_name: "mongo-1-arbiter"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S1_ARBITER:-17011}:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
networks:
- rs1

mongo-rs1-setup:
container_name: "mongo-rs1-setup"
Expand All @@ -39,11 +48,6 @@ services:
- "mongo-1-2"
- "mongo-1-3"
- "mongo-1-arbiter"
links:
- mongo-1-1:mongo-1-1
- mongo-1-2:mongo-1-2
- mongo-1-3:mongo-1-3
- mongo-1-arbiter:mongo-1-arbiter
volumes:
- ./docker/scripts:/scripts
environment:
Expand All @@ -52,38 +56,46 @@ services:
- MONGO3=mongo-1-3
- ARBITER=mongo-1-arbiter
- RS=rs1
- VERSION=${TEST_MONGODB_IMAGE}
entrypoint: [ "/scripts/setup.sh" ]
networks:
- rs1

mongo-2-2:
container_name: "mongo-2-2"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S2_PRIMARY_PORT:-17004}:27017"
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
networks:
- rs2

mongo-2-3:
container_name: "mongo-2-3"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S2_SECONDARY1_PORT:-17005}:27017"
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
networks:
- rs2

mongo-2-1:
container_name: "mongo-2-1"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S2_SECONDARY2_PORT:-17006}:27017"
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
links:
- mongo-2-2:mongo-2-2
- mongo-2-3:mongo-2-3
networks:
- rs2

mongo-2-arbiter:
container_name: "mongo-2-arbiter"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_S2_ARBITER:-17012}:27017"
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
networks:
- rs2

mongo-rs2-setup:
container_name: "mongo-rs2-setup"
Expand All @@ -93,19 +105,18 @@ services:
- "mongo-2-2"
- "mongo-2-3"
- "mongo-2-arbiter"
links:
- mongo-2-1:mongo-2-1
- mongo-2-2:mongo-2-2
- mongo-2-3:mongo-2-3
volumes:
- ./docker/scripts:/scripts
environment:
- MONGO1=mongo-2-1
- MONGO2=mongo-2-2
- MONGO1=mongo-2-2
- MONGO2=mongo-2-1
- MONGO3=mongo-2-3
- ARBITER=mongo-2-arbiter
- RS=rs2
- VERSION=${TEST_MONGODB_IMAGE}
entrypoint: [ "/scripts/setup.sh" ]
networks:
- rs2

# Config servers
mongo-cnf-2:
Expand All @@ -114,23 +125,29 @@ services:
ports:
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
networks:
- cnf-serv

mongo-cnf-3:
container_name: "mongo-cnf-3"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
networks:
- cnf-serv

mongo-cnf-1:
container_name: "mongo-cnf-1"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
links:
- mongo-cnf-2:mongo-cnf-2
- mongo-cnf-3:mongo-cnf-3
networks:
- cnf-serv
depends_on:
- mongo-cnf-2
- mongo-cnf-3

mongo-cnf-setup:
container_name: "mongo-cnf-setup"
Expand All @@ -139,10 +156,6 @@ services:
- "mongo-cnf-1"
- "mongo-cnf-2"
- "mongo-cnf-3"
links:
- mongo-cnf-1:mongo-cnf-1
- mongo-cnf-2:mongo-cnf-2
- mongo-cnf-3:mongo-cnf-3
volumes:
- ./docker/scripts:/scripts
environment:
Expand All @@ -151,36 +164,34 @@ services:
- MONGO3=mongo-cnf-3
- RS=cnf-serv
- PORT=27017
- VERSION=${TEST_MONGODB_IMAGE}
entrypoint: [ "/scripts/setup.sh","cnf_servers" ]
networks:
- cnf-serv

mongos:
container_name: "mongos"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
ports:
- "${TEST_MONGODB_MONGOS_PORT:-17000}:27017"
networks:
- mongo-shard
- rs1
- rs2
- cnf-serv
depends_on:
- "mongo-rs1-setup"
- "mongo-rs2-setup"
- "mongo-cnf-setup"
external_links:
- mongo-cnf-1:mongo-cnf-1
- mongo-cnf-2:mongo-cnf-2
- mongo-cnf-3:mongo-cnf-3
- mongo-1-1:mongo-1-1
- mongo-1-2:mongo-1-2
- mongo-1-3:mongo-1-3
- mongo-2-1:mongo-2-1
- mongo-2-2:mongo-2-2
- mongo-2-3:mongo-2-3
command: mongos --configdb cnf-serv/mongo-cnf-1:27017,mongo-cnf-2:27017,mongo-cnf-3:27017 --port 27017 --bind_ip 0.0.0.0

mongo-shard-setup:
container_name: "mongo-shard-setup"
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
depends_on:
- "mongos"
links:
- mongos:mongos
networks:
- mongo-shard
volumes:
- ./docker/scripts:/scripts
environment:
Expand All @@ -197,6 +208,7 @@ services:
- PORT1=27017
- PORT2=27017
- PORT3=27017
- VERSION=${TEST_MONGODB_IMAGE}
entrypoint: [ "/scripts/init-shard.sh" ]
restart: on-failure:20

Expand All @@ -208,6 +220,7 @@ services:
command: mongod --port 27017 --oplogSize 16

standalone-encrypted:
user: root
container_name: "standalone-encrypted"
image: percona/percona-server-mongodb:5.0.13-11
ports:
Expand All @@ -216,3 +229,9 @@ services:
- ./docker/secret/mongodb_secrets.txt:/secret/mongodb_secrets.txt
- ./docker/scripts:/scripts
command: /scripts/run-mongodb-encrypted.sh

networks:
rs1:
rs2:
cnf-serv:
mongo-shard:
20 changes: 18 additions & 2 deletions docker/scripts/init-shard.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/bin/bash
# `mongosh` is used starting from MongoDB 5.x
MONGODB_CLIENT="mongosh --quiet"
PARSED=(${VERSION//:/ })
MONGODB_VERSION=${PARSED[1]}
MONGODB_VENDOR=${PARSED[0]}
if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "4" ]; then
MONGODB_CLIENT="mongo"
fi
if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "5" ] && [ ${MONGODB_VENDOR} == "percona/percona-server-mongodb" ]; then
MONGODB_CLIENT="mongo"
fi
echo "MongoDB vendor, client and version: ${MONGODB_VENDOR} ${MONGODB_CLIENT} ${MONGODB_VERSION}"

mongodb1=`getent hosts ${MONGOS} | awk '{ print $1 }'`

Expand All @@ -17,16 +29,20 @@ mongodb33=`getent hosts ${MONGO33} | awk '{ print $1 }'`
port=${PORT:-27017}

echo "Waiting for startup.."
until mongo --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
until ${MONGODB_CLIENT} --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
printf '.'
sleep 1
done

echo "Started.."

echo init-shard.sh time now: `date +"%T" `
mongo --host ${mongodb1}:${port} <<EOF
${MONGODB_CLIENT} --host ${mongodb1}:${port} <<EOF
sh.addShard( "${RS1}/${mongodb11}:${PORT1},${mongodb12}:${PORT2},${mongodb13}:${PORT3}" );
sh.addShard( "${RS2}/${mongodb21}:${PORT1},${mongodb22}:${PORT2},${mongodb23}:${PORT3}" );
use test;
db.createCollection("shard");
sh.enableSharding("test");
sh.shardCollection( "test.shard", { id: "hashed" }, false, { numInitialChunks: 500, collation: { locale: "simple" }} );
sh.status();
EOF
42 changes: 29 additions & 13 deletions docker/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/bin/bash
# `mongosh` is used starting from MongoDB 5.x
MONGODB_CLIENT="mongosh --quiet"
PARSED=(${VERSION//:/ })
MONGODB_VERSION=${PARSED[1]}
MONGODB_VENDOR=${PARSED[0]}
if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "4" ]; then
MONGODB_CLIENT="mongo"
fi
if [ "`echo ${MONGODB_VERSION} | cut -c 1`" = "5" ] && [ ${MONGODB_VENDOR} == "percona/percona-server-mongodb" ]; then
MONGODB_CLIENT="mongo"
fi
echo "MongoDB vendor, client and version: ${MONGODB_VENDOR} ${MONGODB_CLIENT} ${MONGODB_VERSION}"

mongodb1=`getent hosts ${MONGO1} | awk '{ print $1 }'`
mongodb2=`getent hosts ${MONGO2} | awk '{ print $1 }'`
Expand All @@ -8,7 +20,7 @@ arbiter=`getent hosts ${ARBITER} | awk '{ print $1 }'`
port=${PORT:-27017}

echo "Waiting for startup.."
until mongo --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
until ${MONGODB_CLIENT} --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
printf '.'
sleep 1
done
Expand All @@ -19,10 +31,11 @@ echo setup.sh time now: `date +"%T" `


function cnf_servers() {
echo "setup cnf servers"
mongo --host ${mongodb1}:${port} <<EOF
echo "setup cnf servers on ${MONGO1}(${mongodb1}:${port})"
${MONGODB_CLIENT} --host ${mongodb1}:${port} <<EOF
var cfg = {
"_id": "${RS}",
"version": 1,
"protocolVersion": 1,
"configsvr": true,
"members": [
Expand All @@ -37,20 +50,21 @@ function cnf_servers() {
{
"_id": 2,
"host": "${mongodb3}:${port}"
}
},
]
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
rs.initiate(cfg);
EOF
}

function general_servers() {
echo "setup servers"
mongo --host ${mongodb1}:${port} <<EOF
echo "setup servers on ${MONGO1}(${mongodb1}:${port})"
${MONGODB_CLIENT} --host ${mongodb1}:${port} <<EOF
var cfg = {
"_id": "${RS}",
"protocolVersion": 1,
"version": 1,
"members": [
{
"_id": 0,
Expand All @@ -63,13 +77,15 @@ function general_servers() {
{
"_id": 2,
"host": "${mongodb3}:${port}"
}
},
{
"_id": 3,
"host": "${arbiter}:${port}",
"arbiterOnly": true
},
]
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
rs.addArb("${arbiter}:${port}")
rs.initiate(cfg);
EOF
}

Expand Down
Loading

0 comments on commit b173af7

Please sign in to comment.