From 32a3674dc892942ded442c86106bf187b4846901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Thu, 22 Sep 2022 19:48:44 +0300 Subject: [PATCH] mdbx: return `MDBX_PROBLEM` insted of `MDBX_CORRUPTED` on coherence troubles. --- src/core.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/core.c b/src/core.c index ea3e7331..5f3fde43 100644 --- a/src/core.c +++ b/src/core.c @@ -3116,6 +3116,7 @@ static int __must_check_result page_split(MDBX_cursor *mc, MDBX_val *const newdata, pgno_t newpgno, const unsigned naf); +static int coherency_timeout(uint64_t *timestamp, pgno_t pgno); static bool coherency_check_meta(const MDBX_env *env, const volatile MDBX_meta *meta, bool report); static int __must_check_result validate_meta_copy(MDBX_env *env, @@ -4389,25 +4390,13 @@ static int iov_write(MDBX_txn *const txn, struct iov_ctx *ctx) { while (likely(rc == MDBX_SUCCESS) && unlikely(memcmp(wp, rp, ctx->iov[i].iov_len) != 0)) { if (!timestamp) { - timestamp = osal_monotime(); iov_done(txn, ctx); WARNING( "catch delayed/non-arrived page %" PRIaPGNO " %s", wp->mp_pgno, "(workaround for incoherent flaw of unified page/buffer cache)"); - } else if (unlikely(osal_monotime() - timestamp > 65536 / 10)) { - ERROR("bailout waiting for %" PRIaPGNO " page arrival %s", wp->mp_pgno, - "(workaround for incoherent flaw of unified page/buffer cache)"); - rc = MDBX_CORRUPTED; } -#if defined(_WIN32) || defined(_WIN64) - SwitchToThread(); -#elif defined(__linux__) || defined(__gnu_linux__) || defined(_UNIX03_SOURCE) - sched_yield(); -#elif (defined(_GNU_SOURCE) && __GLIBC_PREREQ(2, 1)) || defined(_OPEN_THREADS) - pthread_yield(); -#else - usleep(42); -#endif + if (coherency_timeout(×tamp, wp->mp_pgno) != MDBX_RESULT_TRUE) + rc = MDBX_PROBLEM; } dpage_free(env, wp, bytes2pgno(env, ctx->iov[i].iov_len)); } @@ -7629,13 +7618,17 @@ static bool coherency_check(const MDBX_env *env, const txnid_t txnid, return ok; } -__cold static int coherency_timeout(uint64_t *timestamp) { +__cold static int coherency_timeout(uint64_t *timestamp, pgno_t pgno) { if (likely(timestamp && *timestamp == 0)) *timestamp = osal_monotime(); else if (unlikely(!timestamp || osal_monotime() - *timestamp > 65536 / 10)) { - ERROR("bailout waiting for valid snapshot (%s)", - "workaround for incoherent flaw of unified page/buffer cache"); - return MDBX_CORRUPTED; + if (pgno) + ERROR("bailout waiting for %" PRIaPGNO " page arrival %s", pgno, + "(workaround for incoherent flaw of unified page/buffer cache)"); + else + ERROR("bailout waiting for valid snapshot (%s)", + "workaround for incoherent flaw of unified page/buffer cache"); + return MDBX_PROBLEM; } osal_memory_fence(mo_AcquireRelease, true); @@ -7660,7 +7653,7 @@ __hot static int coherency_check_readed(const MDBX_env *env, uint64_t *timestamp) { const bool report = !(timestamp && *timestamp); if (unlikely(!coherency_check(env, txnid, dbs, meta, report))) - return coherency_timeout(timestamp); + return coherency_timeout(timestamp, 0); return MDBX_SUCCESS; } @@ -7675,7 +7668,7 @@ static int coherency_check_written(const MDBX_env *env, const txnid_t txnid, (head_txnid < MIN_TXNID) ? "invalid" : "unexpected", head_txnid, bytes2pgno(env, (const uint8_t *)meta - env->me_dxb_mmap.dxb), "(workaround for incoherent flaw of unified page/buffer cache)"); - return coherency_timeout(timestamp); + return coherency_timeout(timestamp, 0); } return coherency_check_readed(env, head_txnid, meta->mm_dbs, meta, timestamp); }