Skip to content

Commit 63236ec

Browse files
Merge pull request #7309 from francesco-stacks/fix/sortdb-detect-external-blobs
feat: sortdb detect external blobs
2 parents 87ef5b4 + 64163d2 commit 63236ec

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The sortition MARF index now auto-detects external-blob storage (a sibling `marf.sqlite.blobs` file) instead of assuming internal SQLite blobs.

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use crate::chainstate::nakamoto::NakamotoChainState;
5252
use crate::chainstate::stacks::address::PoxAddress;
5353
use crate::chainstate::stacks::boot::PoxStartCycleInfo;
5454
use crate::chainstate::stacks::db::{StacksBlockHeaderTypes, StacksChainState};
55+
use crate::chainstate::stacks::index::file::TrieFile;
5556
use crate::chainstate::stacks::index::marf::{
5657
test_override_marf_compression, MARFOpenOpts, MarfConnection, MARF,
5758
};
@@ -2706,28 +2707,30 @@ impl SortitionDB {
27062707
self.marf.sqlite_conn()
27072708
}
27082709

2709-
/// Open or create the sortition MARF index database with internal blobs.
2710+
/// Open or create the sortition MARF index database.
27102711
///
27112712
/// This function opens the SQLite-based MARF index at `marf_path`.
27122713
/// If the index database does not exist, it will be created.
2713-
/// This index stores all blobs internally within the SQLite database
2714-
/// (i.e., no separate `.blobs` file).
2714+
/// Archival sortition DBs store blobs internally. Squashed sortition DBs
2715+
/// are expected to store blobs externally in `marf.sqlite.blobs`.
27152716
///
27162717
/// # Arguments
27172718
/// * `marf_path` - Path to the MARF SQLite index database.
27182719
/// * `marf_opts` - Configuration options for opening the MARF.
27192720
///
27202721
/// # Behavior
2721-
/// Given a `marf_path` such as `burnchain/sortition/marf.sqlite`,
2722-
/// the MARF blobs are stored internally within the SQLite database.
2722+
/// The blob layout is detected from disk (external iff `marf.sqlite.blobs`
2723+
/// exists), not from `marf_opts.external_blobs`, which is ignored.
2724+
/// Creating a new DB via this function always forces internal blobs,
2725+
/// since the blobs file cannot exist yet.
27232726
/// This function also enables SQLite foreign key enforcement.
27242727
fn open_index(
27252728
marf_path: &str,
27262729
marf_opts: Option<MARFOpenOpts>,
27272730
) -> Result<MARF<SortitionId>, db_error> {
27282731
test_debug!("Open MARF index at {}", marf_path);
27292732
let mut open_opts = marf_opts.unwrap_or(MARFOpenOpts::default());
2730-
open_opts.external_blobs = false;
2733+
open_opts.external_blobs = TrieFile::exists(marf_path)?;
27312734
test_override_marf_compression(&mut open_opts);
27322735
let marf = MARF::from_path(marf_path, open_opts).map_err(|_e| db_error::Corruption)?;
27332736
sql_pragma(marf.sqlite_conn(), "foreign_keys", &true)?;

0 commit comments

Comments
 (0)