Skip to content

Commit 826fdac

Browse files
committed
Introduce a stale readers clearing Env method
1 parent 560136b commit 826fdac

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

heed/src/env.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,17 @@ impl Env {
473473
}
474474
}
475475
}
476+
477+
/// Check for stale entries in the reader lock table and clear them.
478+
///
479+
/// Returns the number of stale readers cleared.
480+
pub fn clear_stale_readers(&self) -> Result<usize> {
481+
let mut dead: i32 = 0;
482+
unsafe { mdb_result(ffi::mdb_reader_check(self.0.env, &mut dead))? }
483+
// safety: The reader_check function asks for an i32, initialize it to zero
484+
// and never decrements it. It is safe to use either an u32 or u64 (usize).
485+
Ok(dead as usize)
486+
}
476487
}
477488

478489
#[derive(Clone)]

heed/src/mdb/lmdb_ffi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ pub use ffi::{
22
mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put,
33
mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd,
44
mdb_env_create, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, mdb_env_set_maxreaders,
5-
mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_stat, mdb_txn_abort,
6-
mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env, MDB_stat as MDB_Stat, MDB_txn,
7-
MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY,
5+
mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_reader_check, mdb_stat,
6+
mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env,
7+
MDB_stat as MDB_Stat, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY,
88
};
99
use lmdb_master3_sys as ffi;
1010

0 commit comments

Comments
 (0)