-
-
Notifications
You must be signed in to change notification settings - Fork 200
Open
Description
Replace timestamp-based change tracking in Dotmim.Sync.Sqlite with a dirty-flag approach using [is_dirty] and [sync_session_id] columns to prevent issues from users changing system time on mobile devices.
Core Changes
- Add New DbCommandType Enums (DbCommandType.cs:152)
- Add MarkRowAsSyncing - Sets sync_session_id on tracking rows when changes are selected
- Add MarkRowAsSynced - Clears is_dirty and sync_session_id after successful sync
- Update Tracking Table Schema (SqliteTableBuilder.cs:178-234)
Already has the columns (lines 197-198):
- [is_dirty] - already exists with default(0)
- [sync_session_id] - already exists with COLLATE NOCASE
- Update index at line 230 to include is_dirty
- Update Triggers (SqliteTableBuilder.cs:359-519)
- Insert Trigger (line 359): Set [is_dirty]=1 and [sync_session_id]=NULL on insert
- Update Trigger (line 454): Set [is_dirty]=1 and [sync_session_id]=NULL on update
- Delete Trigger (line 407): Set [is_dirty]=1 and [sync_session_id]=NULL on delete
- Update SelectChanges Query (SQLiteObjectNames.cs:688)
- Replace timestamp check ([side].[timestamp] > @sync_min_timestamp...) (line 764)
- Use [is_dirty] = 1 instead
- Keep [update_scope_id] IS NULL check to avoid selecting rows from server-side sync
- Add MarkRowAsSyncing Command (SQLiteObjectNames.cs:109-133)
Create new command that:
- Updates tracking table rows with [is_dirty]=1
- Sets [sync_session_id] = @sync_session_id (context.SessionId)
- Executed before SelectChanges reads the data
- Add MarkRowAsSynced Command (SQLiteObjectNames.cs:109-133)
Create new command that:
- Updates tracking table where [sync_session_id] = @sync_session_id
- Sets [is_dirty]=0 and [sync_session_id]=NULL
- Executed after successful sync completion
- Orchestrator Integration
- BaseOrchestrator.GetChanges.cs: Call MarkRowAsSyncing before reading changes (around line 350)
- BaseOrchestrator.ApplyChanges.cs: Call MarkRowAsSynced after successful apply (end of sync flow)
- Pass context.SessionId to both commands
- Update SqliteSyncAdapter (SQLiteSyncAdapter.cs:48)
- Handle new DbCommandType cases in GetCommand method
- Return appropriate command text for MarkRowAsSyncing and MarkRowAsSynced
Key Benefits
- Race condition protection: If a row changes during sync (after MarkRowAsSyncing but before MarkRowAsSynced), its sync_session_id will be NULL, so it won't be marked as
synced - Time-independent: No reliance on system clock
- Backward compatible: Existing tracking table already has required columns
Files to Modify
- /Projects/Dotmim.Sync.Core/Builders/DbCommandType.cs
- /Projects/Dotmim.Sync.Sqlite/Builders/SqliteTableBuilder.cs
- /Projects/Dotmim.Sync.Sqlite/Builders/SQLiteObjectNames.cs
- /Projects/Dotmim.Sync.Sqlite/SQLiteSyncAdapter.cs
- /Projects/Dotmim.Sync.Core/Orchestrators/GetChanges/BaseOrchestrator.GetChanges.cs
- /Projects/Dotmim.Sync.Core/Orchestrators/ApplyChanges/BaseOrchestrator.ApplyChanges.cs (or LocalOrchestrator)
Metadata
Metadata
Assignees
Labels
No labels