Skip to content

fix: use transactions for atomic database inserts#39

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-155
Open

fix: use transactions for atomic database inserts#39
echobt wants to merge 1 commit intomainfrom
fix/issue-155

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 20, 2026

Description

This PR addresses issue #155 where database operations for inserting files and chunks were not atomic. This could lead to orphan records if the process was interrupted between inserting a file and its chunks.

Changes

  • Added insert_file_with_chunks method to Database which wraps file and chunk insertion in a single transaction.
  • Updated Indexer, ServerIndexer, and FileWatcher to use this new method.
  • Ensuring that file and chunks are committed together or not at all.

Verification

  • Verified that the new method correctly inserts data into both tables.
  • Verified that the codebase compiles and existing tests pass.

Related Issue

Fixes #155

This change introduces atomic database operations for file and chunk insertions. Previously, files and chunks were inserted in separate operations, which could lead to inconsistent states (orphan files) if the process was interrupted. Now, insertions are wrapped in a transaction, ensuring that either all data is persisted or none of it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant