2.0 KiB
2.0 KiB
Implement Missing Phase 2 Features
I will implement the remaining features for Phase 2: Advanced Replication (Realtime) and Resumable Uploads (Storage).
1. Advanced Realtime Replication (pgoutput)
Goal: Replace the LISTEN/NOTIFY fallback with robust logical replication using the pgoutput protocol.
- Dependencies: Add
pgoutputcrate and enablereplicationfeature fortokio-postgres. - Implementation:
- Update
realtime/src/replication.rsto connect to Postgres in replication mode. - Create a replication slot (
madbase_slot) and start streaming from publication (madbase_pub). - Use
pgoutput::Decoderto parse binary replication messages (Relation,Insert,Update,Delete). - Maintain an in-memory cache of
Relationmetadata (schema, table, columns) to map relation IDs to names. - Construct
PostgresPayloadfrom change events and broadcast to WebSocket clients.
- Update
2. Resumable Uploads (TUS Protocol)
Goal: Implement the TUS protocol for reliable large file uploads in the Storage service.
- Dependencies: Add
base64tostorage/Cargo.toml. - New Module: Create
storage/src/tus.rs. - Endpoints:
POST /storage/v1/upload/resumable: Initialize upload. Creates a local tracking file.PATCH /storage/v1/upload/resumable/:id: Append data chunk to the local file.HEAD /storage/v1/upload/resumable/:id: Return current upload offset.
- Completion Logic:
- When
offset == size, stream the complete file to S3. - Insert metadata into
storage.objects. - Clean up local temporary files.
- When
Execution Steps
- Update Dependencies: Modify
realtime/Cargo.tomlandstorage/Cargo.toml. - Implement Realtime Replication: Rewrite
realtime/src/replication.rswithpgoutputlogic. - Implement TUS Handlers: Create
storage/src/tus.rsand register routes instorage/src/lib.rs. - Verify: Ensure compilation and check for basic logic correctness.