[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#8124) Patch "Context for compare functions"



Full_Name: James Rouzier
Version: LMDB mdb.master
OS: N/A
URL: https://github.com/rouzier/openldap/commit/33f1dc8be4a8503e78930f130ff9c8e5aa9bfa7b
Submission from: (NULL) (70.81.32.80)


New feature inclusion request: "Context for compare functions"

I am finishing up a new perl module which is a very thin wrapper for LMDB.
(The current perl LMDB module does not fit my needs as it does not support
NO_TLS really support).

When looking at mdb_set_compare and mdb_set_dupsort.

There were three choices.

* Not support mdb_set_compare, mdb_set_dupsort in the module.
* Capture each mdb_*(del|put|get) function to figure which dbi I am using.
* Add support for contexts in the compare functions.

So I decided on the latter.

I understand that passing a context for each compare can add some overhead.
So I made this feature optional it is only enabled if the macro MDB_CMP_CTX is
enabled.

This patch does the following.

* Adds context to the MDB_cmp_func

   typedef int  (MDB_cmp_func)(const MDB_val *a, const MDB_val *b ,void* ctx);

* And two new data members to the MDB_dbx struct
  * void        *md_cmpctx;     /**< user-provided context for md_cmp */
  * void        *md_dcmpctx;    /**< user-provided context for md_dcmp */

* Add functions for setting/getting the contexts 

  * int  mdb_set_cmpctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);

  * int  mdb_set_dcmpctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);

  * int  mdb_get_cmpctx(MDB_txn *txn, MDB_dbi dbi, void **ctx);

  * int  mdb_get_dcmpctx(MDB_txn *txn, MDB_dbi dbi, void **ctx);


I have no problem maintaining this as a separate patch if it does not fit in the
vision of LMDB.
I believe this can be useful for people who wants to add LMDB to a scripting
language.

New feature inclusion request: "Context for compare functions"

I am finishing up a new perl module which is a very thin wrapper for LMDB.
(The current perl LMDB module does not fit my needs as it does not support
NO_TLS really well).

When looking at mdb_set_compare and mdb_set_dupsort.

There were three choices.

* Not support mdb_set_compare, mdb_set_dupsort in the module.
* Capture each mdb_*(del|put|get) function to figure which dbi I am using.
* Add support for contexts in the compare functions.

So I decided on the latter.

I understand that passing a context for each compare can add some overhead.
So I made this feature optional it is only enabled if the macro MDB_CMP_CTX is
enabled.

This patch does the following.

* Adds context to the MDB_cmp_func

   typedef int  (MDB_cmp_func)(const MDB_val *a, const MDB_val *b ,void* ctx);

* And two new data members to the MDB_dbx struct
  * void        *md_cmpctx;     /**< user-provided context for md_cmp */
  * void        *md_dcmpctx;    /**< user-provided context for md_dcmp */

* Add functions for setting/getting the contexts 

  * int  mdb_set_cmpctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);

  * int  mdb_set_dcmpctx(MDB_txn *txn, MDdbi i dbi, void *ctx);

  * int  mdb_get_cmpctx(MDB_txn *txn, MDB_dbi dbi, void **ctx);

  * int  mdb_get_dcmpctx(MDB_txn *txn, MDB_dbi dbi, void **ctx);


I have no problem maintaining this as a separate patch if it does not fit in the
vision of LMDB.
I figured it might be very useful for others.

Thank You for creating and releasing LMDB

I, James Rouzier, hereby place the following modifications to OpenLDAP Software
(and only these modifications) into the public domain. Hence, these
modifications may be freely used and/or redistributed for any purpose with or
without attribution and/or other notice.