Skip to content

Commit

Permalink
Add LMDB driver for apr_dbm.
Browse files Browse the repository at this point in the history
* dbm/apr_dbm.c (apr_dbm_get_driver): Support LMDB.

* dbm/apr_dbm_lmdb.c: New file.

* Makefile.in, build/dbm.m4, build/dso.m4: Add LMDB buildsystem
  support.

* include/apr.h*: Define APU_HAVE_LMDB.

* test/testdbm.c: Test LMDB if present.

Github: closes #46
Submitted by: Lubos Uhliarik <uhliarik redhat.com>, jorton


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1912607 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Sep 29, 2023
1 parent 59341af commit 4e6f06b
Show file tree
Hide file tree
Showing 16 changed files with 431 additions and 7 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ jobs:
config: --enable-pool-debug --with-odbc=no
- name: UBsan
notest-cflags: -fsanitize=undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer -Werror -O2
- name: LMDB
packages: liblmdb-dev
notest-cflags: -Werror
config: --enable-maintainer-mode --with-lmdb --with-dbm=lmdb
- name: Berkeley DB v5.3
packages: libdb5.3-dev
notest-cflags: -Werror
config: --enable-maintainer-mode --with-berkeley-db --with-dbm=db5
fail-fast: false

runs-on: ubuntu-latest
Expand All @@ -50,7 +58,7 @@ jobs:
name: ${{ matrix.name }}
steps:
- name: Install prerequisites
run: sudo apt-get install libtool libtool-bin
run: sudo apt-get install libtool libtool-bin ${{ matrix.packages }}
- uses: actions/checkout@v3
- name: buildconf
run: ./buildconf
Expand Down
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-*- coding: utf-8 -*-
Changes for APR 2.0.0

*) dbm: Add LMDB driver. [Lubos Uhliarik <luhliari redhat.com>]

*) apr_memcache: Check sockets from connection pool before using them and try
to reconnect them if they are not usable any longer.[Ruediger Pluem]

Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ LDADD_dbd_odbc = @LDADD_dbd_odbc@
LDADD_dbm_db = @LDADD_dbm_db@
LDADD_dbm_gdbm = @LDADD_dbm_gdbm@
LDADD_dbm_ndbm = @LDADD_dbm_ndbm@
LDADD_dbm_lmdb = @LDADD_dbm_lmdb@
LDADD_crypto_openssl = @LDADD_crypto_openssl@
LDADD_crypto_nss = @LDADD_crypto_nss@
LDADD_crypto_commoncrypto = @LDADD_crypto_commoncrypto@
Expand Down
5 changes: 4 additions & 1 deletion build.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dsp = libapr.dsp
modules =
crypto_openssl crypto_nss crypto_commoncrypto dbd_pgsql
dbd_sqlite2 dbd_sqlite3 dbd_oracle dbd_mysql dbd_odbc
dbm_db dbm_gdbm dbm_ndbm
dbm_db dbm_gdbm dbm_ndbm dbm_lmdb

# gen_uri_delim.c

Expand Down Expand Up @@ -113,3 +113,6 @@ target = dbm/apr_dbm_gdbm.la
paths = dbm/apr_dbm_ndbm.c
target = dbm/apr_dbm_ndbm.la

[dbm_lmdb]
paths = dbm/apr_dbm_lmdb.c
target = dbm/apr_dbm_lmdb.la
40 changes: 37 additions & 3 deletions build/dbm.m4
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,13 @@ dnl APU_CHECK_DBM: see what kind of DBM backend to use for apr_dbm.
dnl
AC_DEFUN([APU_CHECK_DBM], [
apu_use_sdbm=0
apu_use_lmdb=0
apu_use_ndbm=0
apu_use_gdbm=0
apu_use_db=0
dnl it's in our codebase
apu_have_sdbm=1
apu_have_lmdb=0
apu_have_gdbm=0
apu_have_ndbm=0
apu_have_db=0
Expand All @@ -514,7 +516,7 @@ AC_DEFUN([APU_CHECK_DBM], [
# Although we search for all versions up to 6.9,
# we should only include existing versions in our
# help string.
dbm_list="sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4"
dbm_list="sdbm, lmdb, gdbm, ndbm, db, db1, db185, db2, db3, db4"
db_max_version=48
db_min_version=41
db_version="$db_min_version"
Expand All @@ -541,7 +543,7 @@ AC_DEFUN([APU_CHECK_DBM], [
done
AC_ARG_WITH(dbm, [APR_HELP_STRING([--with-dbm=DBM], [choose the DBM type to use.
DBM={sdbm,gdbm,ndbm,db,db1,db185,db2,db3,db4,db4X,db5X,db6X} for some X=0,...,9])],
DBM={sdbm,lmdb,gdbm,ndbm,db,db1,db185,db2,db3,db4,db4X,db5X,db6X} for some X=0,...,9])],
[
if test "$withval" = "yes"; then
AC_MSG_ERROR([--with-dbm needs to specify a DBM type to use.
Expand All @@ -552,6 +554,31 @@ AC_DEFUN([APU_CHECK_DBM], [
requested=default
])
AC_ARG_WITH([lmdb], [APR_HELP_STRING([--with-lmdb=DIR], [enable LMDB support])],
[
apu_have_lmdb=0
if test "$withval" = "yes"; then
AC_CHECK_HEADER(lmdb.h, AC_CHECK_LIB(lmdb, mdb_dbi_open, [apu_have_lmdb=1]))
elif test "$withval" = "no"; then
apu_have_lmdb=0
else
saved_cppflags="$CPPFLAGS"
saved_ldflags="$LDFLAGS"
CPPFLAGS="$CPPFLAGS -I$withval/include"
LDFLAGS="$LDFLAGS -L$withval/lib "
AC_MSG_CHECKING(checking for lmdb in $withval)
AC_CHECK_HEADER(lmdb.h, AC_CHECK_LIB(lmdb, mdb_dbi_open, [apu_have_lmdb=1]))
if test "$apu_have_lmdb" != "0"; then
APR_ADDTO(LDFLAGS, [-L$withval/lib])
APR_ADDTO(INCLUDES, [-I$withval/include])
fi
CPPFLAGS="$saved_cppflags"
LDFLAGS="$saved_ldflags"
fi
])
dnl We don't pull in GDBM unless the user asks for it, since it's GPL
AC_ARG_WITH([gdbm], [APR_HELP_STRING([--with-gdbm=DIR], [enable GDBM support])],
[
Expand Down Expand Up @@ -680,7 +707,7 @@ AC_DEFUN([APU_CHECK_DBM], [
fi
case "$requested" in
sdbm | gdbm | ndbm | db)
lmdb | sdbm | gdbm | ndbm | db)
eval "apu_use_$requested=1"
apu_default_dbm=$requested
;;
Expand Down Expand Up @@ -709,11 +736,13 @@ AC_DEFUN([APU_CHECK_DBM], [
AC_MSG_CHECKING(for default DBM)
AC_MSG_RESULT($apu_default_dbm)
AC_SUBST(apu_use_lmdb)
AC_SUBST(apu_use_sdbm)
AC_SUBST(apu_use_gdbm)
AC_SUBST(apu_use_ndbm)
AC_SUBST(apu_use_db)
AC_SUBST(apu_have_lmdb)
AC_SUBST(apu_have_sdbm)
AC_SUBST(apu_have_gdbm)
AC_SUBST(apu_have_ndbm)
Expand All @@ -738,8 +767,13 @@ AC_DEFUN([APU_CHECK_DBM], [
APR_ADDTO(LDADD_dbm_ndbm, [-l$apu_ndbm_lib])
fi
if test "$apu_have_lmdb" = "1"; then
APR_ADDTO(LDADD_dbm_lmdb, [-llmdb])
fi
AC_SUBST(LDADD_dbm_db)
AC_SUBST(LDADD_dbm_gdbm)
AC_SUBST(LDADD_dbm_ndbm)
AC_SUBST(LDADD_dbm_lmdb)
])

6 changes: 4 additions & 2 deletions build/dso.m4
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ AC_DEFUN([APR_MODULAR_DSO], [
test $apu_have_db = 1 && objs="$objs dbm/apr_dbm_berkeleydb.lo"
test $apu_have_gdbm = 1 && objs="$objs dbm/apr_dbm_gdbm.lo"
test $apu_have_ndbm = 1 && objs="$objs dbm/apr_dbm_ndbm.lo"
test $apu_have_lmdb = 1 && objs="$objs dbm/apr_dbm_lmdb.lo"
EXTRA_OBJECTS="$EXTRA_OBJECTS $objs"
# Use libtool *.la for mysql if available
Expand All @@ -64,10 +65,10 @@ AC_DEFUN([APR_MODULAR_DSO], [
LIBS="$LIBS $LDADD_crypto_openssl $LDADD_crypto_nss $LDADD_crypto_commoncrypto"
LIBS="$LIBS $LDADD_dbd_pgsql $LDADD_dbd_sqlite2 $LDADD_dbd_sqlite3 $LDADD_dbd_oracle $LDADD_dbd_mysql $LDADD_dbd_odbc"
LIBS="$LIBS $LDADD_dbm_db $LDADD_dbm_gdbm $LDADD_dbm_ndbm"
LIBS="$LIBS $LDADD_dbm_db $LDADD_dbm_gdbm $LDADD_dbm_ndbm $LDADD_dbm_lmdb"
APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $LDADD_crypto_openssl $LDADD_crypto_nss $LDADD_crypto_commoncrypto"
APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $LDADD_dbd_pgsql $LDADD_dbd_sqlite2 $LDADD_dbd_sqlite3 $LDADD_dbd_oracle $LDADD_dbd_mysql $LDADD_dbd_odbc"
APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $LDADD_dbm_db $LDADD_dbm_gdbm $LDADD_dbm_ndbm"
APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $LDADD_dbm_db $LDADD_dbm_gdbm $LDADD_dbm_ndbm $LDADD_dbm_lmdb"
else
Expand All @@ -85,6 +86,7 @@ AC_DEFUN([APR_MODULAR_DSO], [
test $apu_have_db = 1 && dsos="$dsos dbm/apr_dbm_db.la"
test $apu_have_gdbm = 1 && dsos="$dsos dbm/apr_dbm_gdbm.la"
test $apu_have_ndbm = 1 && dsos="$dsos dbm/apr_dbm_ndbm.la"
test $apu_have_lmdb = 1 && dsos="$dsos dbm/apr_dbm_lmdb.la"
if test -n "$dsos"; then
APR_DSO_MODULES="$APR_DSO_MODULES $dsos"
Expand Down
7 changes: 7 additions & 0 deletions dbm/apr_dbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#elif APU_USE_SDBM
#define DBM_VTABLE apr_dbm_type_sdbm
#define DBM_NAME "sdbm"
#elif APU_USE_LMDB
#define DBM_VTABLE apr_dbm_type_lmdb
#define DBM_NAME "lmdb"
#else /* Not in the USE_xDBM list above */
#error a DBM implementation was not specified
#endif
Expand Down Expand Up @@ -94,6 +97,9 @@ APR_DECLARE(apr_status_t) apr_dbm_get_driver(const apr_dbm_driver_t **vtable,
if (!strcasecmp(type, "default")) *vtable = &DBM_VTABLE;
#if APU_HAVE_DB
else if (!strcasecmp(type, "db")) *vtable = &apr_dbm_type_db;
#endif
#if APU_HAVE_LMDB
else if (!strcasecmp(type, "lmdb")) *vtable = &apr_dbm_type_lmdb;
#endif
else if (*type && !strcasecmp(type + 1, "dbm")) {
#if APU_HAVE_GDBM
Expand Down Expand Up @@ -142,6 +148,7 @@ APR_DECLARE(apr_status_t) apr_dbm_get_driver(const apr_dbm_driver_t **vtable,

if (!strcasecmp(type, "default")) type = DBM_NAME;
else if (!strcasecmp(type, "db")) type = "db";
else if (!strcasecmp(type, "lmdb")) type = "lmdb";
else if (*type && !strcasecmp(type + 1, "dbm")) {
if (*type == 'G' || *type == 'g') type = "gdbm";
else if (*type == 'N' || *type == 'n') type = "ndbm";
Expand Down
Loading

0 comments on commit 4e6f06b

Please sign in to comment.