mdbx: fix check-for-unique for the case when more than one new database are opening (i.e. with creation of LCK-files).

Change-Id: If712e1ead2e0cdfd72a115bd442d613a8d730839
This commit is contained in:
Leonid Yuriev 2019-10-25 21:00:07 +03:00
parent 42f8154c39
commit a0ec89e468

View File

@ -1160,6 +1160,15 @@ __cold static int uniq_check(const mdbx_mmap_t *pending, MDBX_env **found) {
int err = scan->me_lck_mmap.lck->mti_bait_uniqueness
? uniq_peek(pending, &scan->me_lck_mmap)
: uniq_poke(pending, &scan->me_lck_mmap, &salt);
if (err == MDBX_ENODATA) {
uint64_t length;
if (likely(mdbx_filesize(pending->fd, &length) == MDBX_SUCCESS &&
length == 0)) {
/* LY: skip checking since LCK-file is empty, i.e. just created. */
mdbx_debug("uniq-probe: unique (new/empty lck)");
return MDBX_RESULT_TRUE;
}
}
if (err == MDBX_RESULT_TRUE)
err = uniq_poke(pending, &scan->me_lck_mmap, &salt);
if (err == MDBX_RESULT_TRUE) {
@ -1169,16 +1178,16 @@ __cold static int uniq_check(const mdbx_mmap_t *pending, MDBX_env **found) {
if (err == MDBX_RESULT_TRUE) {
err = uniq_poke(pending, &scan->me_lck_mmap, &salt);
*found = scan;
mdbx_verbose("<< uniq-probe: found %p", *found);
mdbx_debug("uniq-probe: found %p", *found);
return MDBX_RESULT_FALSE;
}
if (unlikely(err != MDBX_SUCCESS)) {
mdbx_verbose("<< uniq-probe: failed rc %d", err);
mdbx_debug("uniq-probe: failed rc %d", err);
return err;
}
}
mdbx_verbose("<< uniq-probe: unique");
mdbx_debug("uniq-probe: unique");
return MDBX_RESULT_TRUE;
}