Hey Guys, I am working on a proof of concept of a simple key value store service using lmdb as the back end. I am using sendfile to avoid an extra copy. I accomplished this by creating function to extract get the mmap ptr from the env so I can calculate the offset of data.
I figured that function might be useful to the bigger community. If it does not fit in the bigger vision of lmdb it is fine not to include it. You will find the diff attached. Thank you James
diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h index 736d190..f71df3c 100644 --- a/libraries/liblmdb/lmdb.h +++ b/libraries/liblmdb/lmdb.h @@ -819,6 +819,18 @@ int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd); */ int mdb_env_set_mapsize(MDB_env *env, size_t size); + /** @brief Get the current mmap pointer + * + * @param[in] env An environment handle returned by #mdb_env_create() + * @param[out] The address of the pointer to store mmap prt + * @return A non-zero error value on failure and 0 on success. Some possible + * errors are: + * <ul> + * <li>EINVAL - an invalid parameter was specified. + * </ul> + */ +int mdb_env_get_mmap_ptr(MDB_env *env, char **mmap_ptr); + /** @brief Set the maximum number of threads/reader slots for the environment. * * This defines the number of slots in the lock table that is used to track readers in the diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 213842a..33c05c5 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -3932,6 +3932,16 @@ mdb_env_set_mapsize(MDB_env *env, size_t size) } int ESECT +mdb_env_get_mmap_ptr(MDB_env *env, char **arg) +{ + if (!env || !arg) + return EINVAL; + + *arg = env->me_map; + return MDB_SUCCESS; +} + +int ESECT mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs) { if (env->me_map)