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

Re: (ITS#7969) LMDB: Globally shared fields of meta-data are not 'volatile'.



The attached files is derived from OpenLDAP Software. All of the modifications
to OpenLDAP Software represented in the following patch(es) were developed by
Peter-Service LLC, Moscow, Russia. Peter-Service LLC has not assigned rights
and/or interest in this work to any party. I, Leonid Yuriev am authorized by
Peter-Service LLC, my employer, to release this work under the following terms.

Peter-Service LLC hereby places 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.


commit 5e83ea8a76f81dac8d5a9dcd74d5b10a01330102
Author: Leo Yuriev <leo@yuriev.ru>
Date:   2014-09-12 01:32:13 +0400

    ITS#7969 for LMDB: volatile & __synchronize().

diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 6cc3433..3286ffb 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -580,11 +580,11 @@ typedef struct MDB_rxbody {
  * started from so we can avoid overwriting any data used in that
  * particular version.
  */
- txnid_t mrb_txnid;
+ volatile txnid_t mrb_txnid;
  /** The process ID of the process owning this reader txn. */
- MDB_PID_T mrb_pid;
+ volatile MDB_PID_T mrb_pid;
  /** The thread ID of the thread owning this txn. */
- MDB_THR_T mrb_tid;
+ volatile MDB_THR_T mrb_tid;
 } MDB_rxbody;

  /** The actual reader record, with cacheline padding. */
@@ -632,12 +632,12 @@ typedef struct MDB_txbody {
  * This is recorded here only for convenience; the value can always
  * be determined by reading the main database meta pages.
  */
- txnid_t mtb_txnid;
+ volatile txnid_t mtb_txnid;
  /** The number of slots that have been used in the reader table.
  * This always records the maximum count, it is not decremented
  * when readers release their slots.
  */
- unsigned mtb_numreaders;
+ volatile unsigned mtb_numreaders;
 } MDB_txbody;

  /** The actual reader table definition. */
@@ -908,7 +908,7 @@ typedef struct MDB_meta {
  /** Any persistent environment flags. @ref mdb_env */
 #define mm_flags mm_dbs[0].md_flags
  pgno_t mm_last_pg; /**< last used page in file */
- txnid_t mm_txnid; /**< txnid that committed this page */
+ volatile txnid_t mm_txnid; /**< txnid that committed this page */
 } MDB_meta;

  /** Buffer for a stack-allocated meta page.
@@ -3559,6 +3559,10 @@ mdb_env_write_meta(MDB_txn *txn)
  mp->mm_dbs[0] = txn->mt_dbs[0];
  mp->mm_dbs[1] = txn->mt_dbs[1];
  mp->mm_last_pg = txn->mt_next_pgno - 1;
+#if !(defined(_MSC_VER) || defined(__i386__) || defined(__x86_64__))
+ /* LY: issue a memory barrier, if not x86. */
+ __sync_synchronize();
+#endif
  mp->mm_txnid = txn->mt_txnid;
  if (!(env->me_flags & (MDB_NOMETASYNC|MDB_NOSYNC))) {
  unsigned meta_size = env->me_psize;