Skip to content

Commit

Permalink
Introduce a stale readers clearing Env method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Sep 15, 2022
1 parent 560136b commit 826fdac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions heed/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@ impl Env {
}
}
}

/// Check for stale entries in the reader lock table and clear them.
///
/// Returns the number of stale readers cleared.
pub fn clear_stale_readers(&self) -> Result<usize> {
let mut dead: i32 = 0;
unsafe { mdb_result(ffi::mdb_reader_check(self.0.env, &mut dead))? }
// safety: The reader_check function asks for an i32, initialize it to zero
// and never decrements it. It is safe to use either an u32 or u64 (usize).
Ok(dead as usize)
}
}

#[derive(Clone)]
Expand Down
6 changes: 3 additions & 3 deletions heed/src/mdb/lmdb_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub use ffi::{
mdb_cursor_close, mdb_cursor_del, mdb_cursor_get, mdb_cursor_open, mdb_cursor_put,
mdb_dbi_open, mdb_del, mdb_drop, mdb_env_close, mdb_env_copyfd2 as mdb_env_copy2fd,
mdb_env_create, mdb_env_open, mdb_env_set_mapsize, mdb_env_set_maxdbs, mdb_env_set_maxreaders,
mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_stat, mdb_txn_abort,
mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env, MDB_stat as MDB_Stat, MDB_txn,
MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY,
mdb_env_stat, mdb_env_sync, mdb_filehandle_t, mdb_get, mdb_put, mdb_reader_check, mdb_stat,
mdb_txn_abort, mdb_txn_begin, mdb_txn_commit, MDB_cursor, MDB_dbi, MDB_env,
MDB_stat as MDB_Stat, MDB_txn, MDB_APPEND, MDB_CP_COMPACT, MDB_CREATE, MDB_CURRENT, MDB_RDONLY,
};
use lmdb_master3_sys as ffi;

Expand Down

0 comments on commit 826fdac

Please sign in to comment.