Skip to content

feat(sync): --refresh-destination-state-before-apply flag#618

Merged
riyazsh merged 2 commits into
mainfrom
riyaz/HAMR-392-phase-state-load-race
Jul 9, 2026
Merged

feat(sync): --refresh-destination-state-before-apply flag#618
riyazsh merged 2 commits into
mainfrom
riyaz/HAMR-392-phase-state-load-race

Conversation

@riyazsh

@riyazsh riyazsh commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

New opt-in flag on sync and migrate:

  • --refresh-destination-state-before-apply (default False)

When set, apply_resources re-reads the destination side of the storage backend for the resource types in scope, right before workers dispatch. Insert-if-absent — in-flight writes from the current process are preserved.

Why

When an orchestrator runs sync-cli once per resource type as separate processes against a shared storage backend, an earlier process can write destination blobs AFTER a later process loaded state at startup. The later process's dependency lookups (connect_resources) then miss ids that are on disk but not in memory.

The refresh picks up those late-arriving blobs. Failure to refresh logs a warning and proceeds with the pre-refresh state; apply never aborts.

Off by default

Single-process users don't have this race and shouldn't pay the refresh cost.

Test plan

  • pytest tests/unit/ — 816 passing (6 new).
  • ruff clean.

@riyazsh
riyazsh requested a review from a team as a code owner July 9, 2026 15:25
Opt-in destination-state refresh from storage before apply_resources
dispatches workers. Insert-if-absent semantics; in-flight writes are
preserved. Off by default. For orchestrators running sync-cli once
per resource type against shared state.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@riyazsh
riyazsh force-pushed the riyaz/HAMR-392-phase-state-load-race branch from f850d1f to 64530da Compare July 9, 2026 15:44
nathantournant
nathantournant previously approved these changes Jul 9, 2026
heyronhay
heyronhay previously approved these changes Jul 9, 2026
# Conflicts:
#	datadog_sync/utils/resources_handler.py
@riyazsh
riyazsh dismissed stale reviews from heyronhay and nathantournant via 1ee7aac July 9, 2026 20:04
@riyazsh
riyazsh merged commit 71daf89 into main Jul 9, 2026
10 checks passed
@riyazsh
riyazsh deleted the riyaz/HAMR-392-phase-state-load-race branch July 9, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants