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 #31

Open
wants to merge 3 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
36 changes: 1 addition & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1 @@
# pymongo-api

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

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

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

Заполняем mongodb данными

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

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

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

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

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

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

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

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

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

Список доступных эндпоинтов, swagger http://<ip виртуальной машины>:8080/docs
см [последний вариант](./sharding-repl-cache/README.md)
1 change: 1 addition & 0 deletions mongo-sharding-repl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
168 changes: 168 additions & 0 deletions mongo-sharding-repl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Задание 1

# Задание 2

## Шардирование

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

```bash
docker-compose exec -it configSrv mongosh --port 27017
```

```bash
rs.initiate(
{
_id : "config_server",
configsvr: true,
members: [
{ _id : 0, host : "configSrv:27017" }
]
}
);
```

### Инициализаци реплик

#### Шард 1

```bash
docker-compose exec -it shard1 mongosh --port 27018
```

```bash
rs.initiate({_id: "shard1", members: [
{_id: 0, host: "shard1:27018"},
{_id: 1, host: "shard1_2:27021"},
{_id: 2, host: "shard1_3:27022"}
]})
```

#### Шард 2

```bash
docker-compose exec -it shard2 mongosh --port 27019
```

```bash
rs.initiate({_id: "shard2", members: [
{_id: 0, host: "shard2:27019"},
{_id: 1, host: "shard2_2:27023"},
{_id: 2, host: "shard2_3:27024"}
]})
```


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

```bash
docker-compose exec -it mongos_router mongosh --port 27020
```

```bash
sh.addShard( "shard1/shard1:27018");
```

```bash
sh.addShard( "shard2/shard2:27019");
```

```bash
sh.enableSharding("somedb");
```

```bash
sh.shardCollection("somedb.helloDoc", { "name" : "hashed" } )
```

```bash
use somedb
```

```bash
for(var i = 0; i < 1000; i++) db.helloDoc.insert({age:i, name:"ly"+i})
```

```bash
db.helloDoc.countDocuments()
```

### Проверка в шардах

#### Шард 1

```bash
docker-compose exec -it shard1 mongosh --port 27018
```

```bash
use somedb;
db.helloDoc.countDocuments();
```

##### Реплика 2

```bash
docker-compose exec -it shard1 mongosh --port 27021
```

```bash
use somedb;
db.helloDoc.countDocuments();
```

##### Реплика 3

```bash
docker-compose exec -it shard1 mongosh --port 27022
```

```bash
use somedb;
db.helloDoc.countDocuments();
```

#### Шард 2

```bash
docker-compose exec -it shard2 mongosh --port 27019
```

```bash
use somedb;
db.helloDoc.countDocuments();
```

##### Реплика 2

```bash
docker-compose exec -it shard2 mongosh --port 27023
```

```bash
use somedb;
db.helloDoc.countDocuments();
```

##### Реплика 3

```bash
docker-compose exec -it shard2 mongosh --port 27024
```

```bash
use somedb;
db.helloDoc.countDocuments();
```

### Запуск приложения

```bash
docker-compose up -d pymongo_api
```

Проверка [http://localhost:8080/](http://localhost:8080/)


# Задание 3

10 changes: 10 additions & 0 deletions mongo-sharding-repl/api_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.12.1-slim
WORKDIR /app
EXPOSE 8080
COPY requirements.txt ./
# Устанавливаем зависимости python не пересобирая их
RUN pip install --no-cache --no-cache-dir -r requirements.txt
# Копирование кода приложения
COPY app.py /app/
ENTRYPOINT ["uvicorn"]
CMD ["app:app", "--host", "0.0.0.0", "--port", "8080"]
Loading