mdbx: use mdbx_jitter4testing() for race detection.

This commit is contained in:
Leo Yuriev
2017-04-27 15:51:58 +03:00
parent 7204c46421
commit 4b2cb66453
3 changed files with 34 additions and 17 deletions

View File

@@ -193,7 +193,7 @@ static int internal_seize_lck(HANDLE lfd) {
assert(lfd != INVALID_HANDLE_VALUE);
/* 1) now on ?-? (free), get ?-E (middle) */
jitter4testing();
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", mdbx_func_,
@@ -202,13 +202,13 @@ static int internal_seize_lck(HANDLE lfd) {
}
/* 3) now on ?-E (middle), try E-E (exclusive) */
jitter4testing();
mdbx_jitter4testing(false);
if (flock(lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_LOWER))
return MDBX_RESULT_TRUE; /* 4) got E-E (exclusive), done */
/* 5) still on ?-E (middle) */
rc = GetLastError();
jitter4testing();
mdbx_jitter4testing(false);
if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) {
/* 6) something went wrong, give up */
if (!funlock(lfd, LCK_UPPER)) {
@@ -220,11 +220,11 @@ static int internal_seize_lck(HANDLE lfd) {
}
/* 7) still on ?-E (middle), try S-E (locked) */
jitter4testing();
mdbx_jitter4testing(false);
rc = flock(lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER) ? MDBX_RESULT_FALSE
: GetLastError();
jitter4testing();
mdbx_jitter4testing(false);
if (rc != MDBX_RESULT_FALSE)
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_,
"?-E(middle) >> S-E(locked)", rc);
@@ -247,7 +247,7 @@ int mdbx_lck_seize(MDB_env *env) {
assert(env->me_fd != INVALID_HANDLE_VALUE);
if (env->me_lfd == INVALID_HANDLE_VALUE) {
/* LY: without-lck mode (e.g. on read-only filesystem) */
jitter4testing();
mdbx_jitter4testing(false);
if (!flock(env->me_fd, LCK_SHARED | LCK_DONTWAIT, LCK_WHOLE)) {
rc = GetLastError();
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_, "without-lck", rc);
@@ -257,7 +257,7 @@ int mdbx_lck_seize(MDB_env *env) {
}
rc = internal_seize_lck(env->me_lfd);
jitter4testing();
mdbx_jitter4testing(false);
if (rc == MDBX_RESULT_TRUE && (env->me_flags & MDB_RDONLY) == 0) {
/* Check that another process don't operates in without-lck mode.
* Doing such check by exclusive locking the body-part of db. Should be
@@ -269,10 +269,10 @@ int mdbx_lck_seize(MDB_env *env) {
rc = GetLastError();
mdbx_error("%s(%s) failed: errcode %u", mdbx_func_,
"lock-against-without-lck", rc);
jitter4testing();
mdbx_jitter4testing(false);
mdbx_lck_destroy(env);
} else {
jitter4testing();
mdbx_jitter4testing(false);
if (!funlock(env->me_fd, LCK_BODY)) {
rc = GetLastError();
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_,