mdbx: mdbx: avoid log a warning about empty header during DB creation.

Resolve https://github.com/erthink/libmdbx/issues/205.
This commit is contained in:
Leonid Yuriev 2021-06-18 01:06:20 +03:00
parent 68a164da2b
commit b8e621cb2f

View File

@ -3624,7 +3624,8 @@ static int __must_check_result mdbx_page_split(MDBX_cursor *mc,
static int __must_check_result mdbx_read_header(MDBX_env *env, MDBX_meta *meta, static int __must_check_result mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
uint64_t *filesize, uint64_t *filesize,
const int lck_exclusive); const int lck_exclusive,
const mdbx_mode_t mode_bits);
static int __must_check_result mdbx_sync_locked(MDBX_env *env, unsigned flags, static int __must_check_result mdbx_sync_locked(MDBX_env *env, unsigned flags,
MDBX_meta *const pending); MDBX_meta *const pending);
static int mdbx_env_close0(MDBX_env *env); static int mdbx_env_close0(MDBX_env *env);
@ -10293,8 +10294,8 @@ mdbx_validate_meta(MDBX_env *env, MDBX_meta *const meta, uint64_t *filesize,
/* Read the environment parameters of a DB environment /* Read the environment parameters of a DB environment
* before mapping it into memory. */ * before mapping it into memory. */
static __cold int mdbx_read_header(MDBX_env *env, MDBX_meta *dest, static __cold int mdbx_read_header(MDBX_env *env, MDBX_meta *dest,
uint64_t *filesize, uint64_t *filesize, const int lck_exclusive,
const int lck_exclusive) { const mdbx_mode_t mode_bits) {
int rc = mdbx_filesize(env->me_lazy_fd, filesize); int rc = mdbx_filesize(env->me_lazy_fd, filesize);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;
@ -10324,8 +10325,8 @@ static __cold int mdbx_read_header(MDBX_env *env, MDBX_meta *dest,
int err = mdbx_pread(env->me_lazy_fd, buffer, MIN_PAGESIZE, offset); int err = mdbx_pread(env->me_lazy_fd, buffer, MIN_PAGESIZE, offset);
if (err != MDBX_SUCCESS) { if (err != MDBX_SUCCESS) {
if (err == MDBX_ENODATA && offset == 0 && loop_count == 0 && if (err == MDBX_ENODATA && offset == 0 && loop_count == 0 &&
*filesize == 0 && (env->me_flags & MDBX_RDONLY) == 0) *filesize == 0 && mode_bits /* non-zero for DB creation */ != 0)
mdbx_warning("read meta: empty file (%d, %s)", err, mdbx_notice("read meta: empty file (%d, %s)", err,
mdbx_strerror(err)); mdbx_strerror(err));
else else
mdbx_error("read meta[%u,%u]: %i, %s", offset, MIN_PAGESIZE, err, mdbx_error("read meta[%u,%u]: %i, %s", offset, MIN_PAGESIZE, err,
@ -11369,11 +11370,12 @@ __cold int mdbx_env_get_maxreaders(const MDBX_env *env, unsigned *readers) {
#endif /* LIBMDBX_NO_EXPORTS_LEGACY_API */ #endif /* LIBMDBX_NO_EXPORTS_LEGACY_API */
/* Further setup required for opening an MDBX environment */ /* Further setup required for opening an MDBX environment */
static __cold int mdbx_setup_dxb(MDBX_env *env, const int lck_rc) { static __cold int mdbx_setup_dxb(MDBX_env *env, const int lck_rc,
const mdbx_mode_t mode_bits) {
uint64_t filesize_before; uint64_t filesize_before;
MDBX_meta meta; MDBX_meta meta;
int rc = MDBX_RESULT_FALSE; int rc = MDBX_RESULT_FALSE;
int err = mdbx_read_header(env, &meta, &filesize_before, lck_rc); int err = mdbx_read_header(env, &meta, &filesize_before, lck_rc, mode_bits);
if (unlikely(err != MDBX_SUCCESS)) { if (unlikely(err != MDBX_SUCCESS)) {
if (lck_rc != /* lck exclusive */ MDBX_RESULT_TRUE || err != MDBX_ENODATA || if (lck_rc != /* lck exclusive */ MDBX_RESULT_TRUE || err != MDBX_ENODATA ||
(env->me_flags & MDBX_RDONLY) != 0 || (env->me_flags & MDBX_RDONLY) != 0 ||
@ -11405,7 +11407,7 @@ static __cold int mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
return err; return err;
#ifndef NDEBUG /* just for checking */ #ifndef NDEBUG /* just for checking */
err = mdbx_read_header(env, &meta, &filesize_before, lck_rc); err = mdbx_read_header(env, &meta, &filesize_before, lck_rc, mode_bits);
if (unlikely(err != MDBX_SUCCESS)) if (unlikely(err != MDBX_SUCCESS))
return err; return err;
#endif #endif
@ -12360,9 +12362,12 @@ __cold int mdbx_env_open(MDBX_env *env, const char *pathname,
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;
if (flags & ~ENV_USABLE_FLAGS) if (unlikely(flags & ~ENV_USABLE_FLAGS))
return MDBX_EINVAL; return MDBX_EINVAL;
if (flags & MDBX_RDONLY)
mode = 0;
if (env->me_lazy_fd != INVALID_HANDLE_VALUE || if (env->me_lazy_fd != INVALID_HANDLE_VALUE ||
(env->me_flags & MDBX_ENV_ACTIVE) != 0 || env->me_map) (env->me_flags & MDBX_ENV_ACTIVE) != 0 || env->me_map)
return MDBX_EPERM; return MDBX_EPERM;
@ -12510,7 +12515,7 @@ __cold int mdbx_env_open(MDBX_env *env, const char *pathname,
} }
} }
const int dxb_rc = mdbx_setup_dxb(env, lck_rc); const int dxb_rc = mdbx_setup_dxb(env, lck_rc, mode);
if (MDBX_IS_ERROR(dxb_rc)) { if (MDBX_IS_ERROR(dxb_rc)) {
rc = dxb_rc; rc = dxb_rc;
goto bailout; goto bailout;