You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Description
## Overview
Refactored the dedup package to use a single Dedup instance with
pluggable database backends instead of creating multiple instances.
## Key Changes
### 1. Core Architecture
- **Before**: Multiple Dedup instances (BadgerDB, KeyDB, Mirror)
- **After**: Single Dedup instance with pluggable DB backends
### 2. Interface Changes
- Added `DB` interface in `types` package for database operations
- Made BadgerDB and KeyDB implement the DB interface
- Created MirrorDB to handle mirroring logic internally
### 3. Main Dedup Structure
```go
// New simplified structure
type Dedup struct {
db DB
uncommittedMu sync.RWMutex
uncommitted map[string]struct{}
}
```
### 4. Database Implementations
#### BadgerDB (`services/dedup/badger/badger.go`)
- `NewBadgerDB` now returns `types.DB` instead of `*Dedup`
- Removed embedded Dedup struct
- Implements DB interface directly
#### KeyDB (`services/dedup/keydb/keydb.go`)
- `NewKeyDB` now returns `types.DB` instead of `*Dedup`
- Removed embedded Dedup struct
- Implements DB interface directly
#### MirrorDB (`services/dedup/mirror.go`)
- New implementation that wraps primary and mirror databases
- Handles asynchronous mirroring operations
- Implements both DB and DedupInterface interfaces
### 5. Configuration Modes
1. `badgerOnlyMode` - BadgerDB only
2. `keyDBOnlyMode` - KeyDB only
3. `mirrorBadgerMode` - BadgerDB primary, KeyDB mirror
4. `mirrorKeyDBMode` - KeyDB primary, BadgerDB mirror
### 6. Test Updates (`services/dedup/dedup_test.go`)
- Updated to use `types.DedupInterface` instead of `dedup.Dedup`
- Modified KeyDB test to use config to select backend
- Preserved all existing test logic and coverage
## Benefits
- Single Dedup instance management
- Cleaner separation of concerns
- Easier testing and maintenance
- Better extensibility for new database backends
- Preserved backward compatibility
## Linear Ticket
pipe-2289
## Security
- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
0 commit comments