Module UpdateState

Module UpdateState 

Source
Expand description

§UpdateState

§File: Indexing/State/UpdateState.rs

§Role in Air Architecture

Provides state update operations for the File Indexer service, handling modification of index structures including adding, removing, and updating entries in the file index.

§Primary Responsibility

Update file index state by adding/removing files, symbols, and content entries in a thread-safe manner.

§Secondary Responsibilities

  • Remove deleted files from all indexes
  • Update symbol index with new symbol locations
  • Update content index with new file paths
  • Maintain index version and checksum on updates

§Dependencies

External Crates:

  • tokio - Async runtime for update operations

Internal Modules:

  • crate::Result - Error handling type
  • crate::AirError - Error types
  • super::CreateState - State structure definitions

§Dependents

  • Indexing::Scan::ScanDirectory - Updates index after directory scan
  • Indexing::Scan::ScanFile - Updates index after file scan
  • Indexing::Store::UpdateIndex - Incremental index updates
  • Indexing::Watch::WatchFile - Updates index on file changes

§VSCode Pattern Reference

Inspired by VSCode’s index update operations in src/vs/workbench/services/search/common/

§Security Considerations

  • Thread-safe updates prevent race conditions
  • Path validation before state updates
  • Size limits enforced on all update operations

§Performance Considerations

  • Incremental updates minimize reindexing
  • Batch updates for multiple files
  • Efficient hash lookups for O(1) updates

§Error Handling Strategy

Update operations silently fail on missing keys (idempotent) and propagate errors for I/O failures or invalid state transitions.

§Thread Safety

All update operations are designed to work within RwLock write guards and should be called while holding appropriate locks.

Functions§

AddFileToIndex
Add a file to the index with its metadata and symbols
CleanupOrphanedEntries
Clean up orphaned entries (files with no matching content/symbols)
GetIndexSizeEstimate
Get index size estimate in bytes
MergeIndexes
Merge another index into this one
NeedsUpdate
Check if periodic update is needed based on age
RemoveFileFromIndex
Remove a file from all indexes (content, symbols, files)
RemoveFilesFromIndex
Remove multiple files from the index in a batch operation
UpdateContentIndex
Update content index for a file
UpdateFileMetadata
Update file metadata for an existing file
UpdateFileSymbols
Update symbols for a file
UpdateIndexMetadata
Update index metadata (version, timestamp, checksum)
ValidateIndexConsistency
Validate that index is in a consistent state