From 3630066843b7ca6b2cd12911d3e2fe3314cd4549 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 26 Jul 2014 18:16:02 -0700 Subject: [PATCH 1/2] Fix MIPS cache coherency on Linux MIPS chips require manual control of on-chip caches. The cacheflush syscall being used here only exists on MIPS Linux, other OSs will require revisiting. --- libraries/liblmdb/mdb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 84477c4285..e1d774887b 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -70,6 +70,15 @@ #include #endif +#if defined(__mips) && defined(__linux) +/* MIPS has cache coherency issues, requires explicit cache control */ +#include +extern int cacheflush(char *addr, int nbytes, int cache); +#define CACHEFLUSH(addr, bytes, cache) cacheflush(addr, bytes, cache) +#else +#define CACHEFLUSH(addr, bytes, cache) +#endif + #include #include #include @@ -3581,6 +3590,11 @@ done: if (env->me_txns) env->me_txns->mti_txnid = txn->mt_txnid; + /* MIPS has cache coherency issues, this is a no-op everywhere else */ + if (!(env->me_flags & MDB_WRITEMAP)) { + CACHEFLUSH(env->me_map, txn->mt_next_pgno * env->me_psize, DCACHE); + } + return MDB_SUCCESS; } From 8498c6cba2d78de420e626245a49db4705e5a6f6 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 31 Jul 2014 09:59:52 -0700 Subject: [PATCH 2/2] ITS#7913 mdb_cursor_get(*_DUP) cleanup FIRST_DUP/LAST_DUP should succeed even on non-duplicate values PREV_DUP should reset cursor's EOF flag. --- libraries/liblmdb/mdb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index e1d774887b..96f5772903 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -5355,8 +5355,10 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op) if (op == MDB_PREV || op == MDB_PREV_DUP) { rc = mdb_cursor_prev(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_PREV); if (op != MDB_PREV || rc != MDB_NOTFOUND) { - if (rc == MDB_SUCCESS) + if (rc == MDB_SUCCESS) { MDB_GET_KEY(leaf, key); + mc->mc_flags &= ~C_EOF; + } return rc; } } else { @@ -5833,6 +5835,15 @@ fetchm: rc = MDB_INCOMPATIBLE; break; } + { + MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); + if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) { + MDB_GET_KEY(leaf, key); + if (data) + rc = mdb_node_read(mc->mc_txn, leaf, data); + break; + } + } if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) { rc = EINVAL; break;