From a5fb5887f961c28a29e2f55d126e1bfd815b0028 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 21 Dec 2019 18:55:56 +0300 Subject: [PATCH] mdbx: minor refine/fix lock-related erro logging. Change-Id: Id507819b6b2b0c1a57ec71bd031c5068cb2098e1 --- src/elements/core.c | 2 +- src/elements/lck-posix.c | 19 +++++++++---------- src/elements/lck-windows.c | 34 +++++++++++++++------------------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index 96a31a09..ea9e8d63 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -9085,7 +9085,7 @@ int __cold mdbx_env_open(MDBX_env *env, const char *pathname, unsigned flags, } mode = st.st_mode; } -#endif +#endif /* !Windows */ const int lck_rc = mdbx_setup_lck(env, lck_pathname, mode); if (MDBX_IS_ERROR(lck_rc)) { diff --git a/src/elements/lck-posix.c b/src/elements/lck-posix.c index 931f4cc5..84652d7a 100644 --- a/src/elements/lck-posix.c +++ b/src/elements/lck-posix.c @@ -295,7 +295,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_seize(MDBX_env *env) { lck_op(env->me_lazy_fd, op_setlk, (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX); if (rc != MDBX_SUCCESS) { - mdbx_error("%s(%s) failed: errcode %u", __func__, "without-lck", rc); + mdbx_error("%s, err %u", "without-lck", rc); mdbx_assert(env, MDBX_IS_ERROR(rc)); return rc; } @@ -336,7 +336,7 @@ retry: /* the cause may be a collision with POSIX's file-lock recovery. */ if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK || rc == EDEADLK)) { - mdbx_error("%s(%s) failed: errcode %u", __func__, "dxb-exclusive", rc); + mdbx_error("%s, err %u", "dxb-exclusive", rc); mdbx_assert(env, MDBX_IS_ERROR(rc)); return rc; } @@ -361,7 +361,7 @@ retry: * competing process doesn't call lck_downgrade(). */ rc = lck_op(env->me_lfd, op_setlkw, F_RDLCK, 0, 1); if (rc != MDBX_SUCCESS) { - mdbx_error("%s(%s) failed: errcode %u", __func__, "try-shared", rc); + mdbx_error("%s, err %u", "try-shared", rc); mdbx_assert(env, MDBX_IS_ERROR(rc)); return rc; } @@ -381,7 +381,7 @@ retry: if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK || rc == EDEADLK)) { - mdbx_error("%s(%s) failed: errcode %u", __func__, "try-exclusive", rc); + mdbx_error("%s, err %u", "try-exclusive", rc); mdbx_assert(env, MDBX_IS_ERROR(rc)); return rc; } @@ -391,8 +391,7 @@ retry: lck_op(env->me_lazy_fd, op_setlk, (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, env->me_pid, 1); if (rc != MDBX_SUCCESS) { - mdbx_error("%s(%s) failed: errcode %u", __func__, - "lock-against-without-lck", rc); + mdbx_error("%s, err %u", "lock-against-without-lck", rc); mdbx_assert(env, MDBX_IS_ERROR(rc)); return rc; } @@ -416,7 +415,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) { if (rc == MDBX_SUCCESS) rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1); if (unlikely(rc != 0)) { - mdbx_error("%s(%s) failed: errcode %u", __func__, "lck", rc); + mdbx_error("%s, err %u", "lck", rc); assert(MDBX_IS_ERROR(rc)); } return rc; @@ -439,7 +438,7 @@ MDBX_INTERNAL_FUNC int __cold mdbx_lck_destroy(MDBX_env *env, (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX) == 0) { - mdbx_verbose("%s: got exclusive, drown locks", __func__); + mdbx_verbose("%p got exclusive, drown locks", (void *)env); #if MDBX_LOCKING == MDBX_LOCKING_SYSV if (env->me_sysv_ipc.semid != -1) rc = semctl(env->me_sysv_ipc.semid, 2, IPC_RMID) ? errno : 0; @@ -784,7 +783,7 @@ MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) { int rc = mdbx_ipclock_unlock(env, &env->me_lck->mti_rlock); mdbx_trace("<< rc %d", rc); if (unlikely(rc != MDBX_SUCCESS)) - mdbx_panic("%s() failed: errcode %d\n", __func__, rc); + mdbx_panic("%s() failed: err %d\n", __func__, rc); mdbx_jitter4testing(true); } @@ -801,6 +800,6 @@ void mdbx_txn_unlock(MDBX_env *env) { int rc = mdbx_ipclock_unlock(env, env->me_wlock); mdbx_trace("<< rc %d", rc); if (unlikely(rc != MDBX_SUCCESS)) - mdbx_panic("%s() failed: errcode %d\n", __func__, rc); + mdbx_panic("%s() failed: err %d\n", __func__, rc); mdbx_jitter4testing(true); } diff --git a/src/elements/lck-windows.c b/src/elements/lck-windows.c index 3bfae22f..56d77f5e 100644 --- a/src/elements/lck-windows.c +++ b/src/elements/lck-windows.c @@ -167,7 +167,7 @@ void mdbx_txn_unlock(MDBX_env *env) { : funlock(env->me_lazy_fd, LCK_BODY); LeaveCriticalSection(&env->me_windowsbug_lock); if (!rc) - mdbx_panic("%s failed: errcode %u", __func__, GetLastError()); + mdbx_panic("%s failed: err %u", __func__, GetLastError()); } /*----------------------------------------------------------------------------*/ @@ -201,7 +201,7 @@ MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) { /* transite from S-E (locked) to S-? (used), e.g. unlock upper-part */ if ((env->me_flags & MDBX_EXCLUSIVE) == 0 && !funlock(env->me_lfd, LCK_UPPER)) - mdbx_panic("%s failed: errcode %u", __func__, GetLastError()); + mdbx_panic("%s failed: err %u", __func__, GetLastError()); } mdbx_srwlock_ReleaseShared(&env->me_remap_guard); } @@ -447,8 +447,7 @@ static int internal_seize_lck(HANDLE lfd) { mdbx_jitter4testing(false); if (!flock(lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER)) { rc = GetLastError() /* 2) something went wrong, give up */; - mdbx_error("%s(%s) failed: errcode %u", __func__, - "?-?(free) >> ?-E(middle)", rc); + mdbx_error("%s, err %u", "?-?(free) >> ?-E(middle)", rc); return rc; } @@ -463,8 +462,8 @@ static int internal_seize_lck(HANDLE lfd) { if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) { /* 6) something went wrong, give up */ if (!funlock(lfd, LCK_UPPER)) - mdbx_panic("%s(%s) failed: errcode %u", __func__, - "?-E(middle) >> ?-?(free)", GetLastError()); + mdbx_panic("%s(%s) failed: err %u", __func__, "?-E(middle) >> ?-?(free)", + GetLastError()); return rc; } @@ -475,13 +474,12 @@ static int internal_seize_lck(HANDLE lfd) { mdbx_jitter4testing(false); if (rc != MDBX_RESULT_FALSE) - mdbx_error("%s(%s) failed: errcode %u", __func__, - "?-E(middle) >> S-E(locked)", rc); + mdbx_error("%s, err %u", "?-E(middle) >> S-E(locked)", rc); /* 8) now on S-E (locked) or still on ?-E (middle), * transite to S-? (used) or ?-? (free) */ if (!funlock(lfd, LCK_UPPER)) - mdbx_panic("%s(%s) failed: errcode %u", __func__, + mdbx_panic("%s(%s) failed: err %u", __func__, "X-E(locked/middle) >> X-?(used/free)", GetLastError()); /* 9) now on S-? (used, DONE) or ?-? (free, FAILURE) */ @@ -502,7 +500,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) { mdbx_jitter4testing(false); if (!flock(env->me_lazy_fd, LCK_SHARED | LCK_DONTWAIT, LCK_WHOLE)) { rc = GetLastError(); - mdbx_error("%s(%s) failed: errcode %u", __func__, "without-lck", rc); + mdbx_error("%s, err %u", "without-lck", rc); return rc; } return MDBX_RESULT_FALSE; @@ -519,14 +517,13 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) { * while opening db in valid (non-conflict) mode. */ if (!flock(env->me_lazy_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY)) { rc = GetLastError(); - mdbx_error("%s(%s) failed: errcode %u", __func__, - "lock-against-without-lck", rc); + mdbx_error("%s, err %u", "lock-against-without-lck", rc); mdbx_jitter4testing(false); lck_unlock(env); } else { mdbx_jitter4testing(false); if (!funlock(env->me_lazy_fd, LCK_BODY)) - mdbx_panic("%s(%s) failed: errcode %u", __func__, + mdbx_panic("%s(%s) failed: err %u", __func__, "unlock-against-without-lck", GetLastError()); } } @@ -548,7 +545,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) { if (env->me_flags & MDBX_EXCLUSIVE) { /* transite from E-E to E_? (exclusive-read) */ if (!funlock(env->me_lfd, LCK_UPPER)) - mdbx_panic("%s(%s) failed: errcode %u", __func__, + mdbx_panic("%s(%s) failed: err %u", __func__, "E-E(exclusive-write) >> E-?(exclusive-read)", GetLastError()); return MDBX_SUCCESS /* 2) now at E-? (exclusive-read), done */; } @@ -556,21 +553,20 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) { /* 3) now at E-E (exclusive-write), transite to ?_E (middle) */ if (!funlock(env->me_lfd, LCK_LOWER)) - mdbx_panic("%s(%s) failed: errcode %u", __func__, + mdbx_panic("%s(%s) failed: err %u", __func__, "E-E(exclusive-write) >> ?-E(middle)", GetLastError()); /* 4) now at ?-E (middle), transite to S-E (locked) */ if (!flock(env->me_lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER)) { int rc = GetLastError() /* 5) something went wrong, give up */; - mdbx_error("%s(%s) failed: errcode %u", __func__, - "?-E(middle) >> S-E(locked)", rc); + mdbx_error("%s, err %u", "?-E(middle) >> S-E(locked)", rc); return rc; } /* 6) got S-E (locked), continue transition to S-? (used) */ if (!funlock(env->me_lfd, LCK_UPPER)) - mdbx_panic("%s(%s) failed: errcode %u", __func__, - "S-E(locked) >> S-?(used)", GetLastError()); + mdbx_panic("%s(%s) failed: err %u", __func__, "S-E(locked) >> S-?(used)", + GetLastError()); return MDBX_SUCCESS /* 7) now at S-? (used), done */; }