mdbx: fix MDBX_CORRUPTED due open/shrink collision.

This commit is contained in:
Leo Yuriev 2018-09-13 19:21:57 +03:00
parent a150b791a4
commit 22e7630d53

View File

@ -4742,6 +4742,11 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
return MDBX_INVALID; return MDBX_INVALID;
} }
if (!retryleft) {
mdbx_error("meta[%u] is too volatile, skip it", meta_number);
continue;
}
/* LY: check pagesize */ /* LY: check pagesize */
if (!mdbx_is_power2(page.mp_meta.mm_psize) || if (!mdbx_is_power2(page.mp_meta.mm_psize) ||
page.mp_meta.mm_psize < MIN_PAGESIZE || page.mp_meta.mm_psize < MIN_PAGESIZE ||
@ -4759,11 +4764,6 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
page.mp_meta.mm_psize); page.mp_meta.mm_psize);
} }
if (!retryleft) {
mdbx_error("meta[%u] is too volatile, skip it", meta_number);
continue;
}
if (page.mp_meta.mm_txnid_a != page.mp_meta.mm_txnid_b) { if (page.mp_meta.mm_txnid_a != page.mp_meta.mm_txnid_b) {
mdbx_warning("meta[%u] not completely updated, skip it", meta_number); mdbx_warning("meta[%u] not completely updated, skip it", meta_number);
continue; continue;
@ -4830,12 +4830,17 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
const uint64_t used_bytes = const uint64_t used_bytes =
page.mp_meta.mm_geo.next * (uint64_t)page.mp_meta.mm_psize; page.mp_meta.mm_geo.next * (uint64_t)page.mp_meta.mm_psize;
if (used_bytes > *filesize) { if (used_bytes > *filesize) {
mdbx_notice("meta[%u] used-bytes (%" PRIu64 ") beyond filesize (%" PRIu64 rc = mdbx_filesize(env->me_fd, filesize);
"), skip it", if (unlikely(rc != MDBX_SUCCESS))
return rc;
if (used_bytes > *filesize) {
mdbx_notice("meta[%u] used-bytes (%" PRIu64
") beyond filesize (%" PRIu64 "), skip it",
meta_number, used_bytes, *filesize); meta_number, used_bytes, *filesize);
rc = MDBX_CORRUPTED; rc = MDBX_CORRUPTED;
continue; continue;
} }
}
/* LY: check mapsize limits */ /* LY: check mapsize limits */
const uint64_t mapsize_min = const uint64_t mapsize_min =