Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 2 #17

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions compose.yaml

This file was deleted.

600 changes: 600 additions & 0 deletions diagrams.drawio

Large diffs are not rendered by default.

File renamed without changes.
18 changes: 15 additions & 3 deletions README.md → mongo-sharding-repl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
docker compose up -d
```

Заполняем mongodb данными
Инициализируем шарды mongodb и заполняем тестовыми данными:

```shell
./scripts/mongo-init.sh
./scripts/mongo-init-configSrv.sh
```

```shell
./scripts/mongo-init-shards.sh
```

```shell
./scripts/mongo-init-router.sh
```

```shell
./scripts/mongo-init-fixtures.sh
```

## Как проверить
Expand All @@ -32,4 +44,4 @@ curl --silent http://ifconfig.me

## Доступные эндпоинты

Список доступных эндпоинтов, swagger http://<ip виртуальной машины>:8080/docs
Список доступных эндпоинтов, swagger http://<ip виртуальной машины>:8080/docs
File renamed without changes.
File renamed without changes.
File renamed without changes.
193 changes: 193 additions & 0 deletions mongo-sharding-repl/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
name: mongo-sharding-repl

services:
# сервер конфигурации
configSrv:
image: mongo:latest
container_name: configSrv
restart: always
ports:
- "27019:27019"
volumes:
- config-data:/data/db
command:
[
"--configsvr",
"--replSet",
"config_server",
"--bind_ip_all",
"--port",
"27019"
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

shard1-1:
image: mongo:latest
container_name: shard1-1
restart: always
ports:
- "28011:27018"
volumes:
- shard1-1-data:/data/db
command:
[
"--shardsvr",
"--replSet",
"shard1",
"--bind_ip_all",
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

shard1-2:
image: mongo:latest
container_name: shard1-2
restart: always
ports:
- "28012:27018"
volumes:
- shard1-2-data:/data/db
command:
[
"--shardsvr",
"--replSet",
"shard1",
"--bind_ip_all",
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

shard1-3:
image: mongo:latest
container_name: shard1-3
restart: always
ports:
- "28013:27018"
volumes:
- shard1-3-data:/data/db
command:
[
"--shardsvr",
"--replSet",
"shard1",
"--bind_ip_all",
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

shard2-1:
image: mongo:latest
container_name: shard2-1
restart: always
ports:
- "28021:27018"
volumes:
- shard2-1-data:/data/db
command:
[
"--shardsvr",
"--replSet",
"shard2",
"--bind_ip_all",
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

shard2-2:
image: mongo:latest
container_name: shard2-2
restart: always
ports:
- "28022:27018"
volumes:
- shard2-2-data:/data/db
command:
[
"--shardsvr",
"--replSet",
"shard2",
"--bind_ip_all",
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

shard2-3:
image: mongo:latest
container_name: shard2-3
restart: always
ports:
- "28023:27018"
volumes:
- shard2-3-data:/data/db
command:
[
"--shardsvr",
"--replSet",
"shard2",
"--bind_ip_all",
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

mongos_router:
image: mongo:latest
container_name: mongos_router
restart: always
ports:
- "27021:27021"
command:
[
"mongos",
"--configdb",
"config_server/configSrv:27019",
"--bind_ip_all",
"--port",
"27021"
]
healthcheck:
test: [ "CMD", "mongo", "--eval", "db.adminCommand('ping')" ]
interval: 5s
start_period: 10s

pymongo_api:
container_name: pymongo_api
build:
context: api_app
dockerfile: Dockerfile
image: kazhem/pymongo_api:1.0.0
depends_on:
- mongos_router
ports:
- 8080:8080
environment:
MONGODB_URL: "mongodb://mongos_router:27021"
MONGODB_DATABASE_NAME: "somedb"

networks:
default:
driver: bridge

volumes:
mongodb1_data_container:
config-data:
shard1-1-data:
shard1-2-data:
shard1-3-data:
shard2-1-data:
shard2-2-data:
shard2-3-data:
8 changes: 8 additions & 0 deletions mongo-sharding-repl/scripts/mongo-init-configSrv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

### Инициализация сервера конфигурации

docker compose exec -T configSrv mongosh --port 27019 --quiet <<EOF
rs.initiate({_id:"config_server", configsvr:true, members:[{ _id:0, host:"configSrv:27019"}] });
exit();
EOF
10 changes: 10 additions & 0 deletions mongo-sharding-repl/scripts/mongo-init-fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

### Заполняем тестовыми данными

docker compose exec -T mongos_router mongosh --port 27021 --quiet <<EOF
use somedb
for(var i = 0; i < 10000; i++) db.helloDoc.insertOne({age:i, name:"ly"+i, id:"test-id-"+i})
db.helloDoc.countDocuments()
exit();
EOF
11 changes: 11 additions & 0 deletions mongo-sharding-repl/scripts/mongo-init-router.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

### Инициализация роутера шардирования

docker compose exec -T mongos_router mongosh --port 27021 --quiet <<EOF
sh.addShard( "shard1/shard1-1:27018");
sh.addShard( "shard2/shard2-1:27018");

sh.enableSharding("somedb");
sh.shardCollection("somedb.helloDoc", { "name" : "hashed" } )
EOF
21 changes: 21 additions & 0 deletions mongo-sharding-repl/scripts/mongo-init-shards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

### Инициализация шардов

docker compose exec -T shard1-1 mongosh --port 27018 --quiet <<EOF
rs.initiate({_id:"shard1", members:[
{ _id:0, host:"shard1-1:27018"},
{ _id:1, host:"shard1-2:27018"},
{ _id:2, host:"shard1-3:27018"}
] });
exit();
EOF

docker compose exec -T shard2-2 mongosh --port 27018 --quiet <<EOF
rs.initiate({_id:"shard2", members:[
{ _id:0, host:"shard2-1:27018"},
{ _id:1, host:"shard2-2:27018"},
{ _id:2, host:"shard2-3:27018"}
] })
exit();
EOF
32 changes: 32 additions & 0 deletions mongo-sharding-repl/tests/task3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

docker compose exec -T shard1-1 mongosh --port 27018 --quiet <<EOF
use somedb
db.helloDoc.countDocuments()
EOF

docker compose exec -T shard1-2 mongosh --port 27018 --quiet <<EOF
use somedb
db.helloDoc.countDocuments()
EOF

docker compose exec -T shard1-3 mongosh --port 27018 --quiet <<EOF
use somedb
db.helloDoc.countDocuments()
EOF


docker compose exec -T shard2-1 mongosh --port 27018 --quiet <<EOF
use somedb
db.helloDoc.countDocuments()
EOF

docker compose exec -T shard2-2 mongosh --port 27018 --quiet <<EOF
use somedb
db.helloDoc.countDocuments()
EOF

docker compose exec -T shard2-3 mongosh --port 27018 --quiet <<EOF
use somedb
db.helloDoc.countDocuments()
EOF
1 change: 1 addition & 0 deletions mongo-sharding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
47 changes: 47 additions & 0 deletions mongo-sharding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# pymongo-api

## Как запустить

Запускаем mongodb и приложение

```shell
docker compose up -d
```

Инициализируем шарды mongodb и заполняем тестовыми данными:

```shell
./scripts/mongo-init-configSrv.sh
```

```shell
./scripts/mongo-init-shards.sh
```

```shell
./scripts/mongo-init-router.sh
```

```shell
./scripts/mongo-init-fixtures.sh
```

## Как проверить

### Если вы запускаете проект на локальной машине

Откройте в браузере http://localhost:8080

### Если вы запускаете проект на предоставленной виртуальной машине

Узнать белый ip виртуальной машины

```shell
curl --silent http://ifconfig.me
```

Откройте в браузере http://<ip виртуальной машины>:8080

## Доступные эндпоинты

Список доступных эндпоинтов, swagger http://<ip виртуальной машины>:8080/docs
Loading