Skip to content

Implement parallel CRUD with experimental endpoints #453

Closed

Description

@malibio

Implement Parallel CRUD with Experimental Endpoints

Parent Epic: #451

Dependencies

Overview

Implement complete CRUD (Create, Read, Update, Delete) operations for LanceDB with experimental Tauri command endpoints. These endpoints run in parallel with existing Turso operations, enabling side-by-side validation without disrupting production functionality.

Self-Contained Scope

  • Implement all CRUD operations in LanceDB datastore layer
  • Create experimental Tauri commands with _lance_experimental suffix
  • Implement backend batch coordinator for atomic operations
  • Add comparison command for side-by-side validation
  • Zero changes to existing Turso command endpoints

Implementation Approach

Phase 1: LanceDB CRUD Operations

  • Implement create_node() with automatic version creation
  • Implement read_node() and query_nodes() with filtering
  • Implement update_node() using delete+insert pattern
  • Implement delete_node() with tombstone records
  • Implement structural operations (indent, outdent, move)

Phase 2: Backend Batch Coordinator

  • Create batch operation builder for atomic writes
  • Implement RecordBatch construction from multiple nodes
  • Ensure single version created per structural operation
  • Handle sibling chain updates atomically

Phase 3: Experimental Tauri Commands

  • Create create_node_lance_experimental()
  • Create read_node_lance_experimental()
  • Create update_node_lance_experimental()
  • Create delete_node_lance_experimental()
  • Create compare_backends() for validation

Phase 4: Testing & Validation

  • Test each CRUD operation independently
  • Verify atomic batch operations create single version
  • Test comparison command with identical operations
  • Document any behavioral differences vs Turso

Acceptance Criteria

  • All CRUD operations implemented in LanceDB layer
  • Backend batch coordinator ensures atomic operations
  • Structural operations (indent/outdent/move) create single version
  • Experimental Tauri commands callable from frontend
  • compare_backends() command works for all operations
  • No modifications to existing Turso commands
  • Comprehensive error handling for LanceDB operations
  • Operations documented with code examples

Technical Specifications

LanceDB CRUD Interface:

impl LanceDataStore {
    pub async fn create_node(&self, node: Node) -> Result<String>;
    pub async fn read_node(&self, id: &str) -> Result<Option<Node>>;
    pub async fn query_nodes(&self, filter: &str) -> Result<Vec<Node>>;
    pub async fn update_node(&self, node: Node) -> Result<()>;
    pub async fn delete_node(&self, id: &str) -> Result<()>;
    
    // Atomic batch operations
    pub async fn add_batch(&self, batch: RecordBatch) -> Result<()>;
}

Backend Batch Coordinator Pattern:

pub async fn insert_node_atomic(
    datastore: &LanceDataStore,
    node_to_insert: Node,
    after_node_id: NodeId,
) -> Result<(), Error> {
    // 1. Collect all affected nodes
    let mut batch_nodes = Vec::new();
    batch_nodes.push(node_to_insert.clone());
    
    // 2. Update next sibling
    if let Some(next_sibling) = datastore.get_next_sibling(&after_node_id).await? {
        let mut updated_sibling = next_sibling;
        updated_sibling.before_sibling = Some(node_to_insert.id.clone());
        batch_nodes.push(updated_sibling);
    }
    
    // 3. Single atomic write - creates single LanceDB version
    let record_batch = create_record_batch_from_nodes(&batch_nodes, schema)?;
    datastore.add_batch(record_batch).await?;
}

Experimental Tauri Commands:

#[tauri::command]
async fn create_node_lance_experimental(
    state: State<'_, AppState>,
    node: Node,
) -> Result<String, String> {
    let service = state.node_service.lock().await;
    if let Some(lance_db) = &service.lance_db {
        lance_db.create_node(node).await
            .map_err(|e| e.to_string())
    } else {
        Err("LanceDB not enabled".to_string())
    }
}

#[tauri::command]
async fn compare_backends(
    state: State<'_, AppState>,
    operation: String,
    data: Value,
) -> Result<ComparisonResult, String> {
    // Execute same operation on both backends
    // Return timing and result comparison
}

Comparison Result Structure:

#[derive(Serialize)]
pub struct ComparisonResult {
    turso_time_ms: f64,
    lance_time_ms: f64,
    results_match: bool,
    turso_result: Value,
    lance_result: Value,
    differences: Vec<String>,
}

Resources & References

Architecture Documents:

  • /Users/malibio/Downloads/nodespace-persistence-architecture.md - Atomicity analysis
  • Batch coordinator pattern for atomic operations

Existing Patterns:

  • packages/desktop-app/src-tauri/src/commands/nodes.rs - Existing Turso commands
  • packages/desktop-app/src-tauri/src/services/node_service.rs - Service layer pattern

LanceDB PoC:

  • nodespace-data-store/src/lance_data_store_simple.rs - Reference implementation

Dependencies:

Epic Context:

Definition of Done

  • All CRUD operations work correctly in LanceDB
  • Batch coordinator creates single version per structural operation
  • Experimental commands accessible from frontend
  • Comparison command validates identical behavior
  • Error handling comprehensive and informative
  • Code passes cargo fmt and cargo clippy
  • Unit tests for batch coordinator logic
  • Integration tests for experimental commands

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions