Skip to content

Commit 2756398

Browse files
kariyclaude
andcommitted
fix: use existing page size when opening pre-built database snapshots
The database fixtures are generated on macOS (Apple Silicon, 16KB pages) but CI runs on Linux (x86_64, 4KB pages). DbEnvBuilder was always forcing the OS default page size via set_geometry, causing MDBX to report MDBX_CORRUPTED when the forced page size didn't match the existing database's page size. Add `existing_page_size()` to DbEnvBuilder that sets page_size to None, letting MDBX read the page size from the existing data file. Use it in Db::open_no_sync which is specifically for opening pre-built snapshots. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e7ee134 commit 2756398

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

crates/storage/db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl Db {
165165
.max_size(GIGABYTE * 10)
166166
.growth_step((GIGABYTE / 2) as isize)
167167
.sync(SyncMode::UtterlyNoSync)
168+
.existing_page_size()
168169
.build(path)?;
169170

170171
env.create_default_tables()?;

crates/storage/db/src/mdbx/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct DbEnvBuilder {
3333
max_readers: u64,
3434
max_size: usize,
3535
growth_step: isize,
36+
page_size: Option<PageSize>,
3637
}
3738

3839
impl DbEnvBuilder {
@@ -43,6 +44,7 @@ impl DbEnvBuilder {
4344
max_readers: DEFAULT_MAX_READERS,
4445
max_size: DEFAULT_MAX_SIZE,
4546
growth_step: DEFAULT_GROWTH_STEP,
47+
page_size: Some(PageSize::Set(utils::default_page_size())),
4648
}
4749
}
4850

@@ -72,6 +74,15 @@ impl DbEnvBuilder {
7274
self
7375
}
7476

77+
/// Uses the page size from an existing database instead of forcing the OS default.
78+
///
79+
/// This is required when opening databases created on a platform with a different
80+
/// page size (e.g., macOS Apple Silicon uses 16KB pages vs Linux x86_64 4KB pages).
81+
pub fn existing_page_size(mut self) -> Self {
82+
self.page_size = None;
83+
self
84+
}
85+
7586
/// Builds the database environment at the specified path.
7687
pub fn build(self, path: impl AsRef<Path>) -> Result<DbEnv, DatabaseError> {
7788
let mut builder = libmdbx::Environment::builder();
@@ -85,7 +96,7 @@ impl DbEnvBuilder {
8596
growth_step: Some(self.growth_step),
8697
// The database never shrinks
8798
shrink_threshold: None,
88-
page_size: Some(PageSize::Set(utils::default_page_size())),
99+
page_size: self.page_size,
89100
})
90101
.set_flags(EnvironmentFlags {
91102
mode: self.mode,

0 commit comments

Comments
 (0)