From a97021df02f644f23c876756c4c5f2940a310c5c Mon Sep 17 00:00:00 2001 From: Revendell <2312237896@qq.com> Date: Tue, 3 Sep 2024 14:25:59 +0000 Subject: [PATCH] modify OB_IO_ERROR to convert_sys_errno --- src/logservice/palf/log_define.cpp | 3 +++ src/share/ob_io_device_helper.cpp | 19 ++++++++++++++----- src/share/ob_io_device_helper.h | 1 + src/share/ob_local_device.cpp | 17 +++++++++++------ .../object_storage/ob_device_manifest.cpp | 19 ++++++++++--------- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/logservice/palf/log_define.cpp b/src/logservice/palf/log_define.cpp index e71cd8bc0..d1749697f 100644 --- a/src/logservice/palf/log_define.cpp +++ b/src/logservice/palf/log_define.cpp @@ -44,6 +44,9 @@ int convert_sys_errno() case ENOMEM: ret = OB_ALLOCATE_MEMORY_FAILED; break; + case EMFILE: + ret = OB_TOO_MANY_OPEN_FILES; + break; default: ret = OB_IO_ERROR; } diff --git a/src/share/ob_io_device_helper.cpp b/src/share/ob_io_device_helper.cpp index eb2509c84..aed7e88cf 100644 --- a/src/share/ob_io_device_helper.cpp +++ b/src/share/ob_io_device_helper.cpp @@ -646,7 +646,7 @@ int ObIODeviceLocalFileOp::pread_impl( if (EINTR == errno) { SHARE_LOG(INFO, "pread is interrupted before any data is read, just retry", K(errno), KERRMSG); } else { - ret = OB_IO_ERROR; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); SHARE_LOG(WARN, "failed to pread", K(ret), K(fd), K(read_sz), K(read_offset), K(errno), KERRMSG); } } else if (0 == sz) { @@ -684,7 +684,7 @@ int ObIODeviceLocalFileOp::pwrite_impl( if (EINTR == errno) { SHARE_LOG(INFO, "pwrite is interrupted before any data is written, just retry", K(errno), KERRMSG); } else { - ret = OB_IO_ERROR; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); SHARE_LOG(WARN, "failed to pwrite", K(ret), K(fd), K(write_sz), K(write_offset), K(errno), KERRMSG); } } else { @@ -698,10 +698,16 @@ int ObIODeviceLocalFileOp::pwrite_impl( } int ObIODeviceLocalFileOp::convert_sys_errno() +{ + return ObIODeviceLocalFileOp::convert_sys_errno(errno); +} + +// Notes: error_no is a positive value +int ObIODeviceLocalFileOp::convert_sys_errno(const int error_no) { int ret = OB_IO_ERROR; bool use_warn_log = false; - switch (errno) { + switch (error_no) { case EACCES: ret = OB_FILE_OR_DIRECTORY_PERMISSION_DENIED; break; @@ -721,14 +727,17 @@ int ObIODeviceLocalFileOp::convert_sys_errno() case ENOSPC: ret = OB_SERVER_OUTOF_DISK_SPACE; break; + case EMFILE: + ret = OB_TOO_MANY_OPEN_FILES; + break; default: use_warn_log = true; break; } if (use_warn_log) { - SHARE_LOG(WARN, "convert sys errno", K(ret), K(errno), KERRMSG); + SHARE_LOG(WARN, "convert sys errno", K(ret), K(error_no), KERRMSG); } else { - SHARE_LOG(INFO, "convert sys errno", K(ret), K(errno), KERRMSG); + SHARE_LOG(INFO, "convert sys errno", K(ret), K(error_no), KERRMSG); } return ret; } diff --git a/src/share/ob_io_device_helper.h b/src/share/ob_io_device_helper.h index fe6db5b67..5a3f365a5 100644 --- a/src/share/ob_io_device_helper.h +++ b/src/share/ob_io_device_helper.h @@ -185,6 +185,7 @@ public: const int64_t offset, int64_t &write_size); static int convert_sys_errno(); + static int convert_sys_errno(const int error_no); static int get_block_file_size(const char *sstable_dir, const int64_t reserved_size, diff --git a/src/share/ob_local_device.cpp b/src/share/ob_local_device.cpp index ee0100144..5a5faedcf 100644 --- a/src/share/ob_local_device.cpp +++ b/src/share/ob_local_device.cpp @@ -690,7 +690,7 @@ int ObLocalDevice::fsync_block() } else { int sys_ret = 0; if (0 != (sys_ret = ::fsync(block_fd_))) { - ret = OB_IO_ERROR; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); SHARE_LOG(WARN, "Fail to sync block file, ", K(ret), K(sys_ret), KERRMSG); } } @@ -918,7 +918,8 @@ int ObLocalDevice::io_setup( ObLocalIOContext *local_context = nullptr; local_context = new (buf) ObLocalIOContext(); if (0 != (sys_ret = ::io_setup(max_events, &(local_context->io_context_)))) { - ret = OB_IO_ERROR; + // libaio on error it returns a negated error number (the negative of one of the values listed in ERRORS) + ret = ObIODeviceLocalFileOp::convert_sys_errno(-sys_ret); SHARE_LOG(WARN, "Fail to setup io context, ", K(ret), K(sys_ret), KERRMSG); } else { io_context = local_context; @@ -952,7 +953,8 @@ int ObLocalDevice::io_destroy(common::ObIOContext *io_context) } else { int sys_ret = 0; if ((sys_ret = ::io_destroy(local_io_context->io_context_)) != 0) { - ret = OB_IO_ERROR; + // libaio on error it returns a negated error number (the negative of one of the values listed in ERRORS) + ret = ObIODeviceLocalFileOp::convert_sys_errno(-sys_ret); SHARE_LOG(WARN, "Fail to destroy io context, ", K(ret), K(sys_ret), KERRMSG); } else { allocator_.free(io_context); @@ -1068,7 +1070,8 @@ int ObLocalDevice::io_submit( int submit_ret = ::io_submit(local_io_context->io_context_, 1, &iocbp); time_guard.click("LocalDevice_submit"); if (1 != submit_ret) { - ret = OB_IO_ERROR; + // libaio on error it returns a negated error number (the negative of one of the values listed in ERRORS) + ret = ObIODeviceLocalFileOp::convert_sys_errno(-submit_ret); SHARE_LOG(WARN, "Fail to submit aio, ", K(ret), K(submit_ret), K(errno), KERRMSG); } } @@ -1104,7 +1107,8 @@ int ObLocalDevice::io_cancel( } else { int sys_ret = 0; if ((sys_ret = ::io_cancel(local_io_context->io_context_, &(local_iocb->iocb_), &local_event)) < 0) { - ret = OB_IO_ERROR; + // libaio on error it returns a negated error number (the negative of one of the values listed in ERRORS) + ret = ObIODeviceLocalFileOp::convert_sys_errno(-sys_ret); SHARE_LOG(DEBUG, "Fail to cancel aio, ", K(ret), K(sys_ret), KERRMSG); } } @@ -1150,7 +1154,8 @@ int ObLocalDevice::io_getevents( timeout)) < 0 && -EINTR == sys_ret); // ignore EINTR } if (sys_ret < 0) { - ret = OB_IO_ERROR; + // libaio on error it returns a negated error number (the negative of one of the values listed in ERRORS) + ret = ObIODeviceLocalFileOp::convert_sys_errno(-sys_ret); SHARE_LOG(WARN, "Fail to get io events, ", K(ret), K(sys_ret), KERRMSG); } else { local_io_events->complete_io_cnt_ = sys_ret; diff --git a/src/share/object_storage/ob_device_manifest.cpp b/src/share/object_storage/ob_device_manifest.cpp index 196199d7d..420171a0e 100644 --- a/src/share/object_storage/ob_device_manifest.cpp +++ b/src/share/object_storage/ob_device_manifest.cpp @@ -20,6 +20,7 @@ #include "share/object_storage/ob_device_config_parser.h" #include "share/object_storage/ob_object_storage_struct.h" #include "common/ob_smart_var.h" +#include "share/ob_io_device_helper.h" namespace oceanbase { @@ -266,11 +267,11 @@ int ObDeviceManifest::dump2file( LOG_WARN("fail to construct history manifest path", KR(ret)); } else if ((fd = ::open(tmp_manifest_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP)) < 0) { - ret = OB_IO_ERROR; - LOG_WARN("fail to create tmp manifest", K(tmp_manifest_path), K(errno), KR(ret)); + ret = ObIODeviceLocalFileOp::convert_sys_errno(); + LOG_WARN("fail to create tmp manifest", KR(ret), K(tmp_manifest_path), K(errno), KERRMSG); } else if (OB_ISNULL(fp = ::fdopen(fd, "w"))) { - ret = OB_IO_ERROR; - LOG_WARN("fail to fdopen", K(fd), K(errno), KR(ret)); + ret = ObIODeviceLocalFileOp::convert_sys_errno(); + LOG_WARN("fail to fdopen", KR(ret), K(fd), K(errno), KERRMSG); } else if (FALSE_IT(pret = fprintf(fp, "# THIS FILE IS AUTOMATICALLY GENERATED BY OBSERVER. PLEASE DO NOT MODIFY IT MANUALLY!!!\n"))) { } else if (pret <= 0 || pret > MAX_FILE_LINE_LEN) { @@ -281,22 +282,22 @@ int ObDeviceManifest::dump2file( } else if (OB_FAIL(write_device_config_(fp, configs))) { LOG_WARN("fail to write device config", KR(ret), K(configs)); } else if (0 != ::fflush(fp)) { - ret = OB_IO_ERROR; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); LOG_WARN("fail to fflush manifest", KR(ret), K(errno), KERRMSG); } else if (0 != fsync(fd)) { - ret = OB_IO_ERROR; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); LOG_WARN("fail to fsync", KR(ret), K(fd), K(errno), KERRMSG); } else if (0 != fclose(fp)) { - ret = OB_IO_ERROR; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); LOG_WARN("fail to fclose", KR(ret), K(fd), K(errno), KERRMSG); } else { LOG_INFO("write tmp device manifest successfully", K(tmp_manifest_path), K(configs)); if (0 != ::rename(manifest_path, his_manifest_path) && errno != ENOENT) { - ret = OB_ERR_SYS; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); LOG_WARN("fail to backup history device manifest", KR(ret), K(manifest_path), K(his_manifest_path), K(errno), KERRMSG); } else if (0 != ::rename(tmp_manifest_path, manifest_path)) { - ret = OB_ERR_SYS; + ret = ObIODeviceLocalFileOp::convert_sys_errno(); LOG_WARN("fail to rename device manifest", KR(ret), K(tmp_manifest_path), K(manifest_path), K(errno), KERRMSG); }