From 32d46d4ea2aea296ce5884017173f5b2999fe219 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 17 Apr 2015 18:32:54 +0100 Subject: [PATCH 1/4] ITS#8106 retry writes on EINTR --- libraries/liblmdb/mdb.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 944b95f1cc..cc87f19def 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -3133,6 +3133,7 @@ mdb_page_flush(MDB_txn *txn, int keep) /* Write up to MDB_COMMIT_PAGES dirty pages at a time. */ if (pos!=next_pos || n==MDB_COMMIT_PAGES || wsize+size>MAX_WRITE) { if (n) { +retry_write: /* Write previous page(s) */ #ifdef MDB_USE_PWRITEV wres = pwritev(env->me_fd, iov, n, wpos); @@ -3140,8 +3141,11 @@ mdb_page_flush(MDB_txn *txn, int keep) if (n == 1) { wres = pwrite(env->me_fd, iov[0].iov_base, wsize, wpos); } else { +retry_seek: if (lseek(env->me_fd, wpos, SEEK_SET) == -1) { rc = ErrCode(); + if (rc == EINTR) + goto retry_seek; DPRINTF(("lseek: %s", strerror(rc))); return rc; } @@ -3151,6 +3155,8 @@ mdb_page_flush(MDB_txn *txn, int keep) if (wres != wsize) { if (wres < 0) { rc = ErrCode(); + if (rc == EINTR) + goto retry_write; DPRINTF(("Write error: %s", strerror(rc))); } else { rc = EIO; /* TODO: Use which error code? */ @@ -3520,7 +3526,8 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta) int len; #define DO_PWRITE(rc, fd, ptr, size, len, pos) do { \ len = pwrite(fd, ptr, size, pos); \ - rc = (len >= 0); } while(0) + if (len == -1 && ErrCode() == EINTR) continue; \ + rc = (len >= 0); break; } while(1) #endif DPUTS("writing new meta page"); @@ -3625,6 +3632,7 @@ mdb_env_write_meta(MDB_txn *txn) /* Write to the SYNC fd */ mfd = env->me_flags & (MDB_NOSYNC|MDB_NOMETASYNC) ? env->me_fd : env->me_mfd; +retry_write: #ifdef _WIN32 { memset(&ov, 0, sizeof(ov)); @@ -3637,6 +3645,8 @@ mdb_env_write_meta(MDB_txn *txn) #endif if (rc != len) { rc = rc < 0 ? ErrCode() : EIO; + if (rc == EINTR) + goto retry_write; DPUTS("write failed, disk error?"); /* On a failure, the pagecache still contains the new data. * Write some old data back, to prevent it from being used. From 8cf73291fbd8a5ac9744503cb791e20adfe60bb8 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 23 Apr 2015 03:27:33 +0100 Subject: [PATCH 2/4] ITS#8106 --- libraries/liblmdb/CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/liblmdb/CHANGES b/libraries/liblmdb/CHANGES index 1d60d7f511..e0295ba802 100644 --- a/libraries/liblmdb/CHANGES +++ b/libraries/liblmdb/CHANGES @@ -6,6 +6,7 @@ LMDB 0.9.15 Release Engineering Fix compact of empty env (ITS#7956) Fix mdb_rebalance collapsing root (ITS#8062) Fix mdb_load with large values (ITS#8066) + Fix to retry writes on EINTR (ITS#8106) Added workaround for fdatasync bug in ext3fs Build Don't use -fPIC for static lib From b7511480c50e3a6099e223a8940fea501f5b6d2c Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 23 Apr 2015 05:49:56 +0100 Subject: [PATCH 3/4] ITS#8109 fix mdb_cursor_del0 on empty DB --- libraries/liblmdb/mdb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index cc87f19def..fe651509f8 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -7845,6 +7845,13 @@ mdb_cursor_del0(MDB_cursor *mc) MDB_cursor *m2, *m3; MDB_dbi dbi = mc->mc_dbi; + /* DB is totally empty now, just bail out. + * Other cursors adjustments were already done + * by mdb_rebalance and aren't needed here. + */ + if (!mc->mc_snum) + return rc; + mp = mc->mc_pg[mc->mc_top]; nkeys = NUMKEYS(mp); From 5cdde0c5b76e2bc7378bf180263317966974bf13 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 23 Apr 2015 05:52:13 +0100 Subject: [PATCH 4/4] ITS#8109 --- libraries/liblmdb/CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/liblmdb/CHANGES b/libraries/liblmdb/CHANGES index e0295ba802..da4e5ce5f4 100644 --- a/libraries/liblmdb/CHANGES +++ b/libraries/liblmdb/CHANGES @@ -7,6 +7,7 @@ LMDB 0.9.15 Release Engineering Fix mdb_rebalance collapsing root (ITS#8062) Fix mdb_load with large values (ITS#8066) Fix to retry writes on EINTR (ITS#8106) + Fix mdb_cursor_del on empty DB (ITS#8109) Added workaround for fdatasync bug in ext3fs Build Don't use -fPIC for static lib