Skip to content

chore: implement configurable deduplication mirror mode - #6224

Merged
mihir20 merged 8 commits into
masterfrom
mihir/pipe-2289
Aug 14, 2025
Merged

mihir20 merged 8 commits into
masterfrom
mihir/pipe-2289

Conversation

@mihir20

@mihir20 mihir20 commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor

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

// 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

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

- Add mirrorMode type and constants for different mirror modes
- Update New function to support mirrorBadger and mirrorKeyDB modes
- Add error handling for KeyDB initialization
- Update tests to cover new mirror modes
- Modify mirror.go to dynamically set dedup mirror mode
@codecov

codecov Bot commented Aug 11, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.29293% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.83%. Comparing base (8be54bf) to head (efe3ec5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
services/dedup/db.go 60.46% 12 Missing and 5 partials ⚠️
services/dedup/badger/badger.go 63.88% 9 Missing and 4 partials ⚠️
services/dedup/dedup.go 90.16% 4 Missing and 2 partials ⚠️
services/dedup/mirror.go 90.38% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6224      +/-   ##
==========================================
+ Coverage   76.66%   76.83%   +0.16%     
==========================================
  Files         520      521       +1     
  Lines       70762    70779      +17     
==========================================
+ Hits        54248    54380     +132     
+ Misses      13636    13532     -104     
+ Partials     2878     2867      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mihir20
mihir20 marked this pull request as draft August 12, 2025 07:23
@mihir20
mihir20 marked this pull request as ready for review August 12, 2025 12:14
@mihir20
mihir20 marked this pull request as draft August 12, 2025 12:15
@mihir20
mihir20 marked this pull request as ready for review August 12, 2025 12:52
Comment thread services/dedup/mirror.go Resolved
@mihir20
mihir20 requested a review from ktgowtham August 14, 2025 06:50

@atzoum atzoum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, looks lean and clean!

Comment thread services/dedup/types/types.go Resolved
Comment thread processor/processor.go Resolved
Comment thread services/dedup/dedup.go Resolved
Comment thread services/dedup/db.go Resolved
Comment thread services/dedup/badger/badger.go Resolved
Comment thread services/dedup/db.go Resolved
Comment thread services/dedup/mirror.go Resolved
Comment thread services/dedup/badger/badger.go Resolved
Comment thread services/dedup/keydb/keydb.go Resolved
Comment thread services/dedup/mirror.go Resolved
@mihir20
mihir20 requested a review from atzoum August 14, 2025 10:27
Comment thread services/dedup/badger/badger.go Resolved
Comment thread services/dedup/db.go Resolved
Comment thread services/dedup/keydb/keydb.go Resolved
- Rename interfaces and structs to follow Go naming conventions
- Enhance error handling in dedup and mirror packages
- Update mock generation command and adjust import paths
- Refactor DB initialization and error handling in badger and keydb packages
- Improve logging and error reporting in mirror package
- Update MirrorLabel function to return correct database label for each mode
- Add default return value for unknown modes
Comment thread services/dedup/db.go Resolved
- Add error logging for KeyDB mirror creation failure
- Implement fallback mechanism to use Badger only database when KeyDB connection fails
- Improve error handling and prevent panic when KeyDB mirror creation is not possible
…instead

- Removed MirrorLabel method from the mode type
- Updated mirror.go to use string conversion of mode instead of MirrorLabel()
@mihir20
mihir20 requested a review from atzoum August 14, 2025 12:33
@mihir20
mihir20 enabled auto-merge (squash) August 14, 2025 12:36
@mihir20
mihir20 merged commit c97ad7a into master Aug 14, 2025
@mihir20
mihir20 deleted the mihir/pipe-2289 branch August 14, 2025 13:04
This was referenced Aug 18, 2025
mihir20 pushed a commit that referenced this pull request Aug 18, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.57.0-rc.1](v1.56.0...v1.57.0-rc.1)
(2025-08-18)


### Features

* add support for manual sync mode in warehouse
([#6199](#6199))
([6f87119](6f87119))
* **router:** support different throttler per event type
([#6181](#6181))
([12254bb](12254bb))
* warehouse grpc API to get namespace mappings of a destination
([#6200](#6200))
([9613236](9613236))


### Bug Fixes

* adaptive throttling not applying dynamic throttling limits
consistently
([#6219](#6219))
([478b2e1](478b2e1))
* error extractor to handle nested JSON responses
([#6209](#6209))
([ffc0d7a](ffc0d7a))
* getting occasional unauthenticated errors from googlepubsub
([#6228](#6228))
([cc39306](cc39306))
* handle snowpipe service restarts in destination polling logic
([#6236](#6236))
([b76bc7f](b76bc7f))
* handling empty schema for table level schemas
([#6233](#6233))
([cc39306](cc39306))
* histogram buckets for schema snapshots
([#6234](#6234))
([cc39306](cc39306))
* warehouse source empty jobs
([#6204](#6204))
([42f5ae4](42f5ae4))


### Miscellaneous

* bump the go-dependencies group with 12 updates
([#6189](#6189))
([e6e2bcd](e6e2bcd))
* enforcing non-sugared logger
([#6066](#6066))
([b24ded8](b24ded8))
* force new MTU metrics from 1st September 2025 onwards
([#6227](#6227))
([154d2c3](154d2c3))
* implement configurable deduplication mirror mode
([#6224](#6224))
([c97ad7a](c97ad7a))
* refactor Google Pub/Sub to add retry logic for auth errors
([#6229](#6229))
([cc39306](cc39306))
* remove enableV2NotifierJob flag support
([#6196](#6196))
([8be54bf](8be54bf))
* remove event blocking flag
([#6240](#6240))
([e668e14](e668e14))
* remove queryWithUploadId flag support for load files
([#6192](#6192))
([e6e2bcd](e6e2bcd))
* revert "fix: snowpipe events getting duplicated if status API fails"
([#6211](#6211))
([777b08e](777b08e))
* skip warehouse destinations from version deprecation error extraction
([#6226](#6226))
([87c3320](87c3320))
* stop collecting errors in proc_error jobsdb
([#6232](#6232))
([c600968](c600968))
* throttler should emit no warning if not enabled
([#6223](#6223))
([0773168](0773168))
* update keydb dependency
([#6222](#6222))
([d1d64bc](d1d64bc))
* use harbor to pull docker images
([#6210](#6210))
([6c324cf](6c324cf))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
ItsSudip pushed a commit that referenced this pull request Aug 19, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.57.0-rc.2](v1.56.0...v1.57.0-rc.2)
(2025-08-19)


### Features

* add support for manual sync mode in warehouse
([#6199](#6199))
([6f87119](6f87119))
* enable oauthV2 by removing oauthV2enabled variable
([#6175](#6175))
([caad8f0](caad8f0))
* **router:** support different throttler per event type
([#6181](#6181))
([12254bb](12254bb))
* warehouse grpc API to get namespace mappings of a destination
([#6200](#6200))
([9613236](9613236))


### Bug Fixes

* adaptive throttling not applying dynamic throttling limits
consistently
([#6219](#6219))
([478b2e1](478b2e1))
* error extractor to handle nested JSON responses
([#6209](#6209))
([ffc0d7a](ffc0d7a))
* getting occasional unauthenticated errors from googlepubsub
([#6228](#6228))
([cc39306](cc39306))
* handle snowpipe service restarts in destination polling logic
([#6236](#6236))
([b76bc7f](b76bc7f))
* handling empty schema for table level schemas
([#6233](#6233))
([cc39306](cc39306))
* histogram buckets for schema snapshots
([#6234](#6234))
([cc39306](cc39306))
* warehouse source empty jobs
([#6204](#6204))
([42f5ae4](42f5ae4))


### Miscellaneous

* bump the go-dependencies group with 12 updates
([#6189](#6189))
([e6e2bcd](e6e2bcd))
* enforcing non-sugared logger
([#6066](#6066))
([b24ded8](b24ded8))
* force new MTU metrics from 1st September 2025 onwards
([#6227](#6227))
([154d2c3](154d2c3))
* implement configurable deduplication mirror mode
([#6224](#6224))
([c97ad7a](c97ad7a))
* refactor Google Pub/Sub to add retry logic for auth errors
([#6229](#6229))
([cc39306](cc39306))
* remove enableV2NotifierJob flag support
([#6196](#6196))
([8be54bf](8be54bf))
* remove event blocking flag
([#6240](#6240))
([e668e14](e668e14))
* remove queryWithUploadId flag support for load files
([#6192](#6192))
([e6e2bcd](e6e2bcd))
* revert "fix: snowpipe events getting duplicated if status API fails"
([#6211](#6211))
([777b08e](777b08e))
* skip warehouse destinations from version deprecation error extraction
([#6226](#6226))
([87c3320](87c3320))
* stop collecting errors in proc_error jobsdb
([#6232](#6232))
([c600968](c600968))
* throttler should emit no warning if not enabled
([#6223](#6223))
([0773168](0773168))
* update keydb dependency
([#6222](#6222))
([d1d64bc](d1d64bc))
* use harbor to pull docker images
([#6210](#6210))
([6c324cf](6c324cf))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
mihir20 pushed a commit that referenced this pull request Aug 19, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.57.0](v1.56.0...v1.57.0)
(2025-08-19)


### Features

* add support for manual sync mode in warehouse
([#6199](#6199))
([6f87119](6f87119))
* enable oauthV2 by removing oauthV2enabled variable
([#6175](#6175))
([caad8f0](caad8f0))
* **router:** support different throttler per event type
([#6181](#6181))
([12254bb](12254bb))
* warehouse grpc API to get namespace mappings of a destination
([#6200](#6200))
([9613236](9613236))


### Bug Fixes

* adaptive throttling not applying dynamic throttling limits
consistently
([#6219](#6219))
([478b2e1](478b2e1))
* error extractor to handle nested JSON responses
([#6209](#6209))
([ffc0d7a](ffc0d7a))
* getting occasional unauthenticated errors from googlepubsub
([#6228](#6228))
([cc39306](cc39306))
* handle snowpipe service restarts in destination polling logic
([#6236](#6236))
([b76bc7f](b76bc7f))
* handling empty schema for table level schemas
([#6233](#6233))
([cc39306](cc39306))
* histogram buckets for schema snapshots
([#6234](#6234))
([cc39306](cc39306))
* warehouse source empty jobs
([#6204](#6204))
([42f5ae4](42f5ae4))


### Miscellaneous

* bump the go-dependencies group with 12 updates
([#6189](#6189))
([e6e2bcd](e6e2bcd))
* enforcing non-sugared logger
([#6066](#6066))
([b24ded8](b24ded8))
* force new MTU metrics from 1st September 2025 onwards
([#6227](#6227))
([154d2c3](154d2c3))
* implement configurable deduplication mirror mode
([#6224](#6224))
([c97ad7a](c97ad7a))
* refactor Google Pub/Sub to add retry logic for auth errors
([#6229](#6229))
([cc39306](cc39306))
* remove enableV2NotifierJob flag support
([#6196](#6196))
([8be54bf](8be54bf))
* remove event blocking flag
([#6240](#6240))
([e668e14](e668e14))
* remove queryWithUploadId flag support for load files
([#6192](#6192))
([e6e2bcd](e6e2bcd))
* revert "fix: snowpipe events getting duplicated if status API fails"
([#6211](#6211))
([777b08e](777b08e))
* skip warehouse destinations from version deprecation error extraction
([#6226](#6226))
([87c3320](87c3320))
* stop collecting errors in proc_error jobsdb
([#6232](#6232))
([c600968](c600968))
* throttler should emit no warning if not enabled
([#6223](#6223))
([0773168](0773168))
* update keydb dependency
([#6222](#6222))
([d1d64bc](d1d64bc))
* use harbor to pull docker images
([#6210](#6210))
([6c324cf](6c324cf))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants