Updating db handlers for orphan insertions and batched queries by Sansh2356 · Pull Request #478 · braidpool/braidpool · GitHub
Skip to content

Updating db handlers for orphan insertions and batched queries #478

Open
Sansh2356 wants to merge 3 commits into
braidpool:devfrom
Sansh2356:ibd/db-persist-decoupling
Open

Updating db handlers for orphan insertions and batched queries #478
Sansh2356 wants to merge 3 commits into
braidpool:devfrom
Sansh2356:ibd/db-persist-decoupling

Conversation

@Sansh2356

@Sansh2356 Sansh2356 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

This is a continuation of PR #309 and PR #474 having scope :-

  • Updating db_handler with Batched query insertion and removing SequentialQueryInsertion.
  • Removing the tests associated with sequential insertion method and updating the existent method wrt to orphan handling.
  • Persisting orphan beads via db command handlers and adding helpers to Braid for constructing parents set and passing into BeadInsertData containing parent_bead_idx and timestamp as per schema for insertion,to be passed onto the db_handler .
  • Adding appropriate error types for handling consensus failures.

@Sansh2356 Sansh2356 marked this pull request as ready for review June 14, 2026 08:26
@Sansh2356 Sansh2356 requested a review from zaidmstrr as a code owner June 14, 2026 08:26
Copilot AI review requested due to automatic review settings June 14, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates node-side persistence to use batched DB insert commands (including persistence of newly-adopted orphans) and removes the legacy sequential insertion path, while adding helper types/logic to resolve parent references for DB writes and introducing new consensus/persistence error variants.

Changes:

  • Replaces sequential DB insertion with a batched InsertBeadsBatch command using BeadInsertData (bead + id + resolved parent refs/timestamps).
  • Adds Braid::resolve_parents() and new BraidError variants to surface missing-parent / missing-index invariants during persistence resolution.
  • Updates startup DB loading and multiple persistence call sites to use the new batch API, plus updates DB tests to exercise the production batch insertion path.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
node/src/rpc_server.rs Minor refactor to avoid extra deref when reading bead indices.
node/src/main.rs Switches persistence calls to InsertBeadsBatch with BeadInsertData resolution; updates DB pool usage (no mutex lock on shutdown).
node/src/lib.rs Switches swarm-side persistence to InsertBeadsBatch with resolved bead + promoted orphan insert data.
node/src/error.rs Adds BraidError variants for missing parent/index invariants and display messages.
node/src/db/mod.rs Introduces BeadInsertData and replaces sequential insert enum variant with batched insert variant.
node/src/db/db_handlers.rs Implements bulk insert SQL + chunking, removes sequential insert logic, updates DB fetch APIs, and rewrites tests for batch insertion.
node/src/braid/mod.rs Adds resolve_parents() helper and adjusts some index mapping access patterns.
Comments suppressed due to low confidence (1)

node/src/db/db_handlers.rs:745

  • This use crate::{ ... } block imports braid and emit_bead, but neither is used by the current test module. Consider collapsing the import to only what is needed.
    use crate::{
        braid,
        utils::test_utils::test_utility_functions::{
            emit_bead, loading_braid_from_file, BRAIDTESTDIRECTORY,
        },

pub struct DBHandler {
//Query receiver inherit to handler only
receiver: Receiver<BraidpoolDBTypes>,
//Shared across tasks for accessing DB after contention using `Mutex`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

"parent": *parent_id,
"timestamp": *parent_timestamp,
}));
debug!("Parent found with id - {:?}", parent_id);
Comment on lines +695 to +700
let parent_ts = MedianTimePast::from_u32(parent_timestamp as u32).map_err(|e| {
DBErrors::TupleAttributeParsingError {
error: format!("Invalid parent timestamp value {}: {}", parent_timestamp, e),
attribute: "parent_bead_timestamps".to_string(),
}
})?;
Comment on lines 735 to 739
use super::*;
use serde_json::json;
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
use std::collections::HashSet;
use std::{fs, path::Path, str::FromStr};
Comment on lines +792 to +795
Comment thread node/src/db/db_handlers.rs
Comment thread node/src/lib.rs
@Sansh2356 Sansh2356 force-pushed the ibd/db-persist-decoupling branch 2 times, most recently from 47a2021 to e774ae6 Compare June 19, 2026 16:16
Updating the test_batch_insertion for changed orphan handling
with test orphan bead, adding error for ParentsNotFound and
BeadIndexNotExists for additional error management.

Updating the rollback error logging in db_handler.
@Sansh2356 Sansh2356 force-pushed the ibd/db-persist-decoupling branch from e774ae6 to 7c00c64 Compare June 30, 2026 15:47
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.

2 participants