|
1 | | -### Delta replications job container |
| 1 | +# OSM Replication Job Container |
2 | 2 |
|
3 | | -This contain is responsible for creating the delta replication files it may be set up by minute, hour, etc. Those replications files will be uploaded to a repository in AWS or Google Storage, depends on what you are using. |
| 3 | +This container is responsible for creating OSM delta replication files using [osmdbt](https://github.com/openstreetmap/osmdbt) tools. It generates replication files every minute and uploads them to S3 with integrity verification. |
4 | 4 |
|
5 | | -### Configuration |
| 5 | +## What it does |
6 | 6 |
|
7 | | -In order to run this container we need environment variables, these can be found in the following files👇: |
| 7 | +The container runs a continuous replication process that: |
8 | 8 |
|
9 | | -- [.env.db.example](./../../envs/.env.db.example) |
10 | | -- [.env.db-utils.example](./../../envs/.env.db-utils.example) |
11 | | -- [.env.cloudprovider.example](./../../envs/.env.cloudprovider.example) |
| 9 | +1. **Executes replication cycle every minute**: |
| 10 | + - Runs `osmdbt-get-log` to fetch changes from PostgreSQL logical replication |
| 11 | + - Runs `osmdbt-create-diff` to generate `.osc.gz` files and `state.txt` files |
| 12 | + |
| 13 | +2. **Uploads files to S3**: |
| 14 | + - Uploads `.osc.gz` files (e.g., `870.osc.gz`) |
| 15 | + - Uploads general `state.txt` (controls replication sequence) |
| 16 | + - Uploads specific `state.txt` files (e.g., `870.state.txt` for `870.osc.gz`) |
| 17 | + - All files are verified for integrity before upload |
| 18 | + |
| 19 | +3. **Manages replication state**: |
| 20 | + - Uses local `state.txt` to control replication sequence |
| 21 | + - Recovers `state.txt` from S3 on container restart |
| 22 | + - Continues from the last known sequence automatically |
| 23 | + |
| 24 | +4. **Error handling and monitoring**: |
| 25 | + - Verifies file integrity (gzip test, size checks) |
| 26 | + - Sends Slack notifications for errors and corruption |
| 27 | + - Automatically cleans up incomplete/orphaned files (`.lock`, `.log`, corrupted files) |
| 28 | + - Removes orphaned state files without matching `.osc.gz` files |
| 29 | + |
| 30 | +5. **Self-healing**: |
| 31 | + - Detects and removes corrupted files |
| 32 | + - Regenerates files if corruption is detected |
| 33 | + - Maintains sequence continuity |
| 34 | + |
| 35 | +## Technology Stack |
| 36 | + |
| 37 | +- **osmdbt v0.9**: OSM Database Replication Tools from OpenStreetMap |
| 38 | +- **Base Image**: Debian Bookworm (for library version consistency) |
| 39 | +- **PostgreSQL**: Uses logical replication slot for change tracking |
| 40 | +- **AWS S3**: For storing replication files |
| 41 | +- **Slack**: Optional notifications for errors |
| 42 | + |
| 43 | +## Configuration |
| 44 | + |
| 45 | +### Required Environment Variables |
| 46 | + |
| 47 | +The container requires environment variables from these files: |
| 48 | + |
| 49 | +- [.env.db.example](../../envs/.env.db.example) - Database connection |
| 50 | +- [.env.db-utils.example](../../envs/.env.db-utils.example) - Database utilities |
| 51 | +- [.env.cloudprovider.example](../../envs/.env.cloudprovider.example) - Cloud storage configuration |
12 | 52 |
|
13 | 53 | **Note**: Rename the above files as `.env.db`, `.env.db-utils` and `.env.cloudprovider` |
14 | 54 |
|
15 | | -#### Running replication-job container |
| 55 | +### Key Environment Variables |
| 56 | + |
| 57 | +#### Database Configuration |
| 58 | +- `POSTGRES_HOST` - PostgreSQL hostname |
| 59 | +- `POSTGRES_PORT` - PostgreSQL port (default: 5432) |
| 60 | +- `POSTGRES_DB` - Database name |
| 61 | +- `POSTGRES_USER` - Database user |
| 62 | +- `POSTGRES_PASSWORD` - Database password |
| 63 | +- `REPLICATION_SLOT` - Logical replication slot name (default: `osm_repl`) |
| 64 | + |
| 65 | +#### S3 Configuration |
| 66 | +- `CLOUDPROVIDER` - Cloud provider (default: `aws`) |
| 67 | +- `AWS_S3_BUCKET` - S3 bucket name for replication files |
| 68 | +- `REPLICATION_FOLDER` - Folder path in S3 bucket (default: `replication`) |
| 69 | + |
| 70 | +#### Slack Notifications (Optional) |
| 71 | +- `ENABLE_SEND_SLACK_MESSAGE` - Enable Slack notifications (default: `false`) |
| 72 | +- `SLACK_WEBHOOK_URL` - Slack webhook URL for notifications |
| 73 | +- `ENVIROMENT` - Environment name for notifications (e.g., `production`, `staging`) |
| 74 | + |
| 75 | +#### Working Directory |
| 76 | +- `WORKING_DIRECTORY` - Working directory path (default: `/mnt/data`) |
| 77 | + |
| 78 | +## Running the Container |
| 79 | + |
| 80 | +### Using Docker Compose |
| 81 | + |
| 82 | +```sh |
| 83 | +docker-compose run replication-job |
| 84 | +``` |
| 85 | + |
| 86 | +### Using Docker |
16 | 87 |
|
17 | 88 | ```sh |
18 | | - # Docker compose |
19 | | - docker-compose run replication-job |
20 | | - |
21 | | - # Docker |
22 | | - docker run \ |
23 | | - --env-file ./envs/.env.db \ |
24 | | - --env-file ./envs/.env.replication-job \ |
25 | | - --env-file ./envs/.env.cloudprovider \ |
26 | | - -v ${PWD}/data/replication-job-data:/mnt/data \ |
27 | | - --network osm-seed_default \ |
28 | | - -it osmseed-replication-job:v1 |
| 89 | +docker run \ |
| 90 | + --env-file ./envs/.env.db \ |
| 91 | + --env-file ./envs/.env.replication-job \ |
| 92 | + --env-file ./envs/.env.cloudprovider \ |
| 93 | + -v ${PWD}/data/replication-job-data:/mnt/data \ |
| 94 | + --network osm-seed_default \ |
| 95 | + -it osmseed-replication-job:v1 |
29 | 96 | ``` |
0 commit comments