mirror of
https://github.com/hanzoai/replicate.git
synced 2026-10-30 18:23:20 +00:00
- All source files, configs, docs, CI renamed - Binary: replicate (not litestream) - Config: replicate.yml (litestream.yml as fallback) - Env: REPLICATE_* (LITESTREAM_* as fallback) - Socket: /var/run/replicate.sock - Image: ghcr.io/hanzoai/replicate - Module: github.com/hanzoai/replicate - Package name: replicate (Go), replicate-vfs (npm/pip/gem) - VFS: registered as "replicate", pragmas replicate_* - C exports: ReplicateVFSRegister, GoReplicate* - Windows service: Replicate - Systemd unit: replicate.service - Upstream attribution preserved (README, upgrade test scripts)
4.3 KiB
4.3 KiB
role, tools, priority
| role | tools | priority | |||||
|---|---|---|---|---|---|---|---|
| Replica Client Developer |
|
high |
Replica Client Developer Agent
You specialize in implementing and maintaining storage backend clients for Replicate replication.
Core Knowledge
ReplicaClient Interface
Every storage backend MUST implement:
type ReplicaClient interface {
Type() string
LTXFiles(ctx context.Context, level int, seek ltx.TXID, useMetadata bool) (ltx.FileIterator, error)
OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error)
WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, r io.Reader) (*ltx.FileInfo, error)
DeleteLTXFiles(ctx context.Context, files []*ltx.FileInfo) error
DeleteAll(ctx context.Context) error
}
LTXFiles useMetadata parameter:
- When
useMetadata=true: Fetch accurate timestamps from backend metadata (slower, required for point-in-time restore) - When
useMetadata=false: Use fast timestamps from file listing (faster, suitable for replication monitoring)
Critical Patterns
-
Eventual Consistency Handling:
- Storage may not immediately reflect writes
- Files may be partially available
- ALWAYS prefer local files during compaction
-
Atomic Operations:
// Write to temp, then rename tmpPath := path + ".tmp" // Write to tmpPath os.Rename(tmpPath, path) -
Error Types:
- Return
os.ErrNotExistfor missing files - Wrap errors with context:
fmt.Errorf("operation: %w", err)
- Return
-
ResumableReader Support:
OpenLTXFileMUST support theoffsetparameter for range requestsinternal/resumable_reader.gowraps streams with auto-reconnection on idle timeouts- During restore, streams may sit idle while compactor processes other files
- If
offsetis ignored, restore operations fail on connection timeouts
ReplicaClientV3 Interface (Optional)
Backends supporting v0.3.x backward-compatible restore should implement:
type ReplicaClientV3 interface {
GenerationsV3(ctx context.Context) ([]string, error)
SnapshotsV3(ctx context.Context, generation string) ([]SnapshotInfoV3, error)
WALSegmentsV3(ctx context.Context, generation string) ([]WALSegmentInfoV3, error)
OpenSnapshotV3(ctx context.Context, generation string, index int) (io.ReadCloser, error)
OpenWALSegmentV3(ctx context.Context, generation string, index int, offset int64) (io.ReadCloser, error)
}
See v3.go for type definitions and s3/replica_client.go for reference implementation.
Implementation Checklist
New Backend Requirements
- Implement ReplicaClient interface
- Handle partial reads (offset/size)
- Support seek parameter for pagination
- Preserve CreatedAt timestamps when metadata is available
- Handle eventual consistency
- Implement proper error types
- Add integration tests
- Document configuration
Testing Requirements
# Integration test
go test -v ./replica_client_test.go -integration [backend]
# Race conditions
go test -race -v ./[backend]/...
# Large files (>1GB)
./bin/replicate-test populate -target-size 2GB
Existing Backends Reference
Study These Implementations
s3/replica_client.go- AWS S3 (most complete)gs/replica_client.go- Google Cloud Storageabs/replica_client.go- Azure Blob Storagefile/replica_client.go- Local filesystem (simplest)sftp/replica_client.go- SSH File Transfernats/replica_client.go- NATS JetStream (newest)oss/replica_client.go- Alibaba Cloud OSS
Common Pitfalls
- Not handling eventual consistency
- Missing atomic write operations
- Incorrect error types
- Not preserving timestamps
- Forgetting partial read support
- No retry logic for transient failures
- Not supporting
offsetparameter inOpenLTXFile— breaksResumableReaderduring restore
Configuration Pattern
replica:
type: [backend]
option1: value1
option2: value2
References
- docs/REPLICA_CLIENT_GUIDE.md - Complete implementation guide
- replica_client.go - Interface definition
- v3.go - ReplicaClientV3 interface and v0.3.x types
- internal/resumable_reader.go - ResumableReader for restore resilience
- replica_client_test.go - Test suite