Commit 6c5c1f0b authored by Eugene Kosov's avatar Eugene Kosov Committed by Marko Mäkelä

MDEV-19231 make DB_SUCCESS equal to 0

It's a micro optimization. On most platforms CPUs has instructions to
compare with 0 fast. DB_SUCCESS is the most popular outcome of functions
and this patch optimized code like (err == DB_SUCCESS)

BtrBulk::finish(): bogus assertion fixed

fil_node_t::read_page0(): corrected usage of os_file_read()

que_eval_sql(): bugus assertion removed. Apparently it checked that
the field was assigned after having been zero-initialized at
object creation.

It turns out that the return type of os_file_read_func() was changed
in mysql/mysql-server@98909cefbc37e54efc6452c7e95bccbf64ac9213 (MySQL 5.7)
from ibool to dberr_t. The reviewer (if there was any) failed to
point out that because of future merges, it could be a bad idea to
change the return type of a function without changing the function name.

This change was applied to MariaDB 10.2.2 in
commit 2e814d47 but the
MariaDB-specific code was not fully adjusted accordingly,
e.g. in fil_node_open_file(). Essentially, code like
!os_file_read(...) became dead code in MariaDB and later
in Mariabackup 10.2, and we could be dealing with an uninitialized
buffer after a failed page read.
parent bc145193
...@@ -559,9 +559,9 @@ datafile_read(datafile_cur_t *cursor) ...@@ -559,9 +559,9 @@ datafile_read(datafile_cur_t *cursor)
return(XB_FIL_CUR_EOF); return(XB_FIL_CUR_EOF);
} }
if (!os_file_read(IORequestRead, if (os_file_read(IORequestRead,
cursor->file, cursor->buf, cursor->buf_offset, cursor->file, cursor->buf, cursor->buf_offset,
to_read)) { to_read) != DB_SUCCESS) {
return(XB_FIL_CUR_ERROR); return(XB_FIL_CUR_ERROR);
} }
......
...@@ -195,7 +195,7 @@ log_online_read_bitmap_page( ...@@ -195,7 +195,7 @@ log_online_read_bitmap_page(
ut_a(bitmap_file->offset % MODIFIED_PAGE_BLOCK_SIZE == 0); ut_a(bitmap_file->offset % MODIFIED_PAGE_BLOCK_SIZE == 0);
success = os_file_read(IORequestRead, success = os_file_read(IORequestRead,
bitmap_file->file, page, bitmap_file->offset, bitmap_file->file, page, bitmap_file->offset,
MODIFIED_PAGE_BLOCK_SIZE); MODIFIED_PAGE_BLOCK_SIZE) == DB_SUCCESS;
if (UNIV_UNLIKELY(!success)) { if (UNIV_UNLIKELY(!success)) {
......
...@@ -253,7 +253,7 @@ xb_fil_cur_open( ...@@ -253,7 +253,7 @@ xb_fil_cur_open(
if (!node->space->crypt_data if (!node->space->crypt_data
&& os_file_read(IORequestRead, && os_file_read(IORequestRead,
node->handle, cursor->buf, 0, node->handle, cursor->buf, 0,
page_size.physical())) { page_size.physical()) == DB_SUCCESS) {
mutex_enter(&fil_system->mutex); mutex_enter(&fil_system->mutex);
if (!node->space->crypt_data) { if (!node->space->crypt_data) {
node->space->crypt_data node->space->crypt_data
...@@ -442,8 +442,8 @@ xb_fil_cur_read( ...@@ -442,8 +442,8 @@ xb_fil_cur_read(
cursor->buf_offset = offset; cursor->buf_offset = offset;
cursor->buf_page_no = (ulint)(offset / page_size); cursor->buf_page_no = (ulint)(offset / page_size);
if (!os_file_read(IORequestRead, cursor->file, cursor->buf, offset, if (os_file_read(IORequestRead, cursor->file, cursor->buf, offset,
(ulint) to_read)) { (ulint) to_read) != DB_SUCCESS) {
ret = XB_FIL_CUR_ERROR; ret = XB_FIL_CUR_ERROR;
goto func_exit; goto func_exit;
} }
......
...@@ -3302,8 +3302,8 @@ static dberr_t xb_assign_undo_space_start() ...@@ -3302,8 +3302,8 @@ static dberr_t xb_assign_undo_space_start()
page = static_cast<byte*>(ut_align(buf, UNIV_PAGE_SIZE)); page = static_cast<byte*>(ut_align(buf, UNIV_PAGE_SIZE));
retry: retry:
if (!os_file_read(IORequestRead, file, page, TRX_SYS_PAGE_NO * UNIV_PAGE_SIZE, if (os_file_read(IORequestRead, file, page, TRX_SYS_PAGE_NO * UNIV_PAGE_SIZE,
UNIV_PAGE_SIZE)) { UNIV_PAGE_SIZE) != DB_SUCCESS) {
msg("Reading TRX_SYS page failed."); msg("Reading TRX_SYS page failed.");
error = DB_ERROR; error = DB_ERROR;
goto func_exit; goto func_exit;
...@@ -4655,7 +4655,7 @@ xb_space_create_file( ...@@ -4655,7 +4655,7 @@ xb_space_create_file(
free(buf); free(buf);
if (!ret) { if (ret != DB_SUCCESS) {
msg("mariabackup: could not write the first page to %s", msg("mariabackup: could not write the first page to %s",
path); path);
os_file_close(*file); os_file_close(*file);
...@@ -4947,7 +4947,7 @@ xtrabackup_apply_delta( ...@@ -4947,7 +4947,7 @@ xtrabackup_apply_delta(
<< page_size_shift); << page_size_shift);
success = os_file_read(IORequestRead, src_file, success = os_file_read(IORequestRead, src_file,
incremental_buffer, offset, page_size); incremental_buffer, offset, page_size);
if (!success) { if (success != DB_SUCCESS) {
goto error; goto error;
} }
...@@ -4980,7 +4980,7 @@ xtrabackup_apply_delta( ...@@ -4980,7 +4980,7 @@ xtrabackup_apply_delta(
success = os_file_read(IORequestRead, src_file, success = os_file_read(IORequestRead, src_file,
incremental_buffer, incremental_buffer,
offset, page_in_buffer * page_size); offset, page_in_buffer * page_size);
if (!success) { if (success != DB_SUCCESS) {
goto error; goto error;
} }
...@@ -5029,7 +5029,7 @@ xtrabackup_apply_delta( ...@@ -5029,7 +5029,7 @@ xtrabackup_apply_delta(
success = os_file_write(IORequestWrite, success = os_file_write(IORequestWrite,
dst_path, dst_file, buf, off, page_size); dst_path, dst_file, buf, off, page_size);
if (!success) { if (success != DB_SUCCESS) {
goto error; goto error;
} }
} }
......
...@@ -1050,6 +1050,7 @@ BtrBulk::finish(dberr_t err) ...@@ -1050,6 +1050,7 @@ BtrBulk::finish(dberr_t err)
ut_ad(!sync_check_iterate(dict_sync_check())); ut_ad(!sync_check_iterate(dict_sync_check()));
ut_ad(err != DB_SUCCESS || btr_validate_index(m_index, NULL, false)); ut_ad(err == DB_SUCCESS
|| btr_validate_index(m_index, NULL, false) == DB_SUCCESS);
return(err); return(err);
} }
...@@ -539,7 +539,7 @@ bool fil_node_t::read_page0(bool first) ...@@ -539,7 +539,7 @@ bool fil_node_t::read_page0(bool first)
/* Align the memory for file i/o if we might have O_DIRECT set */ /* Align the memory for file i/o if we might have O_DIRECT set */
byte* page = static_cast<byte*>(ut_align(buf2, psize)); byte* page = static_cast<byte*>(ut_align(buf2, psize));
IORequest request(IORequest::READ); IORequest request(IORequest::READ);
if (!os_file_read(request, handle, page, 0, psize)) { if (os_file_read(request, handle, page, 0, psize) != DB_SUCCESS) {
ib::error() << "Unable to read first page of file " << name; ib::error() << "Unable to read first page of file " << name;
ut_free(buf2); ut_free(buf2);
return false; return false;
......
...@@ -30,12 +30,13 @@ Created 5/24/1996 Heikki Tuuri ...@@ -30,12 +30,13 @@ Created 5/24/1996 Heikki Tuuri
/* Do not include univ.i because univ.i includes this. */ /* Do not include univ.i because univ.i includes this. */
enum dberr_t { enum dberr_t {
DB_SUCCESS,
DB_SUCCESS_LOCKED_REC = 9, /*!< like DB_SUCCESS, but a new DB_SUCCESS_LOCKED_REC = 9, /*!< like DB_SUCCESS, but a new
explicit record lock was created */ explicit record lock was created */
DB_SUCCESS = 10,
/* The following are error codes */ /* The following are error codes */
DB_ERROR, DB_ERROR = 11,
DB_INTERRUPTED, DB_INTERRUPTED,
DB_OUT_OF_MEMORY, DB_OUT_OF_MEMORY,
DB_OUT_OF_FILE_SPACE, DB_OUT_OF_FILE_SPACE,
......
...@@ -1233,7 +1233,5 @@ que_eval_sql( ...@@ -1233,7 +1233,5 @@ que_eval_sql(
mutex_exit(&dict_sys->mutex); mutex_exit(&dict_sys->mutex);
} }
ut_a(trx->error_state != 0);
DBUG_RETURN(trx->error_state); DBUG_RETURN(trx->error_state);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment