Skip to content

Commit

Permalink
lmdb: fix map size for 32-bit arch
Browse files Browse the repository at this point in the history
Closes #707

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jan 4, 2025
1 parent 26e9a7c commit ddacb06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

### Fixed

* lmdb: fix map size for 32-bit arch ([Yuki Kishimoto])

### Removed

### Deprecated
Expand Down
18 changes: 9 additions & 9 deletions crates/nostr-lmdb/src/store/lmdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ use super::types::{DatabaseEvent, DatabaseFilter};
const EVENT_ID_ALL_ZEROS: [u8; 32] = [0; 32];
const EVENT_ID_ALL_255: [u8; 32] = [255; 32];

// 64-bit
#[cfg(target_pointer_width = "64")]
const MAP_SIZE: usize = 1024 * 1024 * 1024 * 32; // 32GB

// 32-bit
#[cfg(target_pointer_width = "32")]
const MAP_SIZE: usize = 0xFFFFF000; // 4GB (2^32-4096)

#[derive(Debug, Clone)]
pub(crate) struct Lmdb {
/// LMDB env
Expand Down Expand Up @@ -52,20 +60,12 @@ impl Lmdb {
where
P: AsRef<Path>,
{
// 64-bit
#[cfg(target_pointer_width = "64")]
let map_size: usize = 1024 * 1024 * 1024 * 32; // 32 GB

// 32-bit
#[cfg(target_pointer_width = "32")]
let map_size: usize = u32::MAX as usize; // 4 GB

// Construct LMDB env
let env: Env = unsafe {
EnvOpenOptions::new()
.flags(EnvFlags::NO_TLS)
.max_dbs(9)
.map_size(map_size)
.map_size(MAP_SIZE)
.open(path)?
};

Expand Down

0 comments on commit ddacb06

Please sign in to comment.