OxiGDAL Offline - Offline-First Data Management
Comprehensive offline-first data management for OxiGDAL with local storage, sync queue management, conflict resolution, and optimistic updates.
Features
- Offline-First Architecture: Local-first data layer with background synchronization
- Multi-Platform Storage:
- SQLite for native platforms (desktop, server)
- IndexedDB for WASM/browser environments
- Sync Queue Management: Persistent queue with automatic retry and exponential backoff
- Conflict Detection: Automatic detection of concurrent modifications
- Merge Strategies:
- Last-Write-Wins
- Local-Wins / Remote-Wins
- Three-Way-Merge
- Larger-Wins
- Custom merge strategies
- Background Sync: Automatic synchronization when connectivity is restored
- Optimistic Updates: Immediate UI updates with eventual consistency
- Retry Mechanisms: Exponential backoff with configurable jitter
- Pure Rust: No C/C++ dependencies (COOLJAPAN policy compliant)
- WASM-Compatible: Runs in browsers using IndexedDB
Installation
Add to your Cargo.toml:
[]
= "0.1"
# For native platforms
[]
= ["native"]
= ["oxigdal-offline/native"]
# For WASM platforms
= ["oxigdal-offline/wasm"]
Quick Start
Basic Usage
use ;
async
With Remote Backend
use ;
use RemoteBackend;
// Implement your remote backend
async
WASM Usage
use ;
use spawn_local;
pub async
Architecture
Storage Layer
The storage layer provides an abstraction over platform-specific storage backends:
- SQLite (native): High-performance embedded database
- IndexedDB (WASM): Browser-native storage with async API
Sync Queue
Operations are queued for synchronization:
┌─────────────┐
│ Write │
│ Update │──▶ Local Storage ──▶ Sync Queue ──▶ Remote Sync
│ Delete │ ▲ │
└─────────────┘ │ │
└────────── Conflict ────────────┘
Resolution
Conflict Resolution
The system detects and resolves conflicts using configurable strategies:
- Version-based: Compare version numbers
- Timestamp-based: Use modification timestamps
- Content-based: Compare actual data
Optimistic Updates
UI updates happen immediately while sync occurs in the background:
User Action ──▶ Optimistic Update ──▶ UI Update
│
▼
Sync Queue ──▶ Remote Sync
│ │
▼ ▼
[Success] [Conflict]
│ │
▼ ▼
Confirm Rollback
Configuration
Config Options
builder
// Queue settings
.max_queue_size
.sync_batch_size
// Retry settings
.retry_max_attempts
.retry_initial_delay_ms
.retry_max_delay_ms
.retry_backoff_multiplier
.retry_jitter_factor
// Sync settings
.auto_sync_interval_secs
.max_operation_age_secs // 24 hours
// Merge strategy
.merge_strategy
// Optimistic updates
.enable_optimistic_updates
// Storage settings
.storage_path
.database_name
// Compression
.enable_compression
.compression_threshold
.build?
Merge Strategies
Last-Write-Wins (Default)
The record with the most recent timestamp wins:
builder
.merge_strategy
.build?
Local-Wins / Remote-Wins
Always prefer local or remote version:
// Always use local version
builder
.merge_strategy
.build?
// Always use remote version
builder
.merge_strategy
.build?
Three-Way-Merge
Merge changes using common ancestor:
builder
.merge_strategy
.build?
Custom Strategy
Implement your own merge logic:
use ;
let merger = new;
let engine = new
.with_custom_merger;
Advanced Features
Manual Maintenance
// Run maintenance tasks
let report = manager.maintenance.await?;
println!;
// Compact storage
manager.compact.await?;
// Get statistics
let stats = manager.statistics.await?;
println!;
Monitoring Queue
// Check queue size
let size = manager.queue_size.await?;
println!;
// Check if online
if manager.is_online.await
Performance
- Write throughput: ~10,000 ops/sec (SQLite)
- Read throughput: ~50,000 ops/sec (SQLite)
- Sync throughput: Configurable batch size (default: 100 ops/batch)
- Memory usage: Minimal (streaming operations)
COOLJAPAN Policy Compliance
- ✅ Pure Rust (no C/C++/Fortran dependencies)
- ✅ No unwrap() usage
- ✅ Workspace-based dependency management
- ✅ Latest crates from crates.io
- ✅ WASM-compatible
Examples
See the examples/ directory for more examples:
basic.rs: Basic offline operationssync.rs: Synchronization with remoteconflict.rs: Conflict resolutionwasm.rs: WASM/browser usage
License
Apache-2.0
Author
COOLJAPAN OU (Team Kitasan)