delete some legacy code and fix several file description leak.
This commit is contained in:
parent
05d3a935cc
commit
55b78ca715
@ -410,7 +410,7 @@ int FileDirectoryUtils::get_disk_space(
|
||||
int FileDirectoryUtils::delete_directory_rec(const char *path)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
DIR *dir;
|
||||
DIR *dir = NULL;
|
||||
struct dirent *entry;
|
||||
if (NULL == (dir = opendir(path))) {
|
||||
ret = OB_ERR_SYS;
|
||||
@ -450,9 +450,8 @@ int FileDirectoryUtils::delete_directory_rec(const char *path)
|
||||
int FileDirectoryUtils::delete_tmp_file_or_directory_at(const char *path)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
DIR *dir;
|
||||
DIR *dir = NULL;
|
||||
struct dirent *entry;
|
||||
dir = opendir(path);
|
||||
if (NULL == (dir = opendir(path))) {
|
||||
ret = OB_ERR_SYS;
|
||||
LIB_LOG(WARN, "opendir failed", K(path));
|
||||
|
@ -211,7 +211,7 @@ TEST_F(TestObSimpleLogClusterBasicFunc, restart_and_clear_tmp_files)
|
||||
int64_t leader_idx1 = 0;
|
||||
EXPECT_EQ(OB_SUCCESS, get_leader(id, leader1, leader_idx1));
|
||||
std::string palf_log_dir = leader1.palf_handle_impl_->log_engine_.log_storage_.block_mgr_.log_dir_;
|
||||
ObISimpleLogServer *i_server = get_cluster()[0];
|
||||
ObISimpleLogServer *i_server = get_cluster()[leader_idx1];
|
||||
ObSimpleLogServer *server = dynamic_cast<ObSimpleLogServer*>(i_server);
|
||||
std::string log_pool = server->log_block_pool_.log_pool_path_;
|
||||
const block_id_t min_block_id = server->log_block_pool_.min_block_id_;
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "share/ob_errno.h" // errno
|
||||
#include "share/rc/ob_tenant_base.h" // mtl_malloc
|
||||
#include "log_writer_utils.h" // LogWriteBuf
|
||||
|
||||
#include "log_io_uitls.h" // close_with_ret
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
@ -188,7 +188,10 @@ void LogBlockHandler::destroy()
|
||||
if (IS_INIT) {
|
||||
is_inited_ = false;
|
||||
dir_fd_ = -1;
|
||||
io_fd_ = -1;
|
||||
if (-1 != io_fd_) {
|
||||
close_with_ret(io_fd_);
|
||||
io_fd_ = -1;
|
||||
}
|
||||
log_block_size_ = 0;
|
||||
dio_aligned_buf_.destroy();
|
||||
PALF_LOG(INFO, "LogFileHandler destroy success");
|
||||
@ -444,7 +447,7 @@ int LogBlockHandler::inner_write_impl_(const int fd, const char *buf, const int6
|
||||
if (count != (write_size = ob_pwrite(fd, buf, count, offset))) {
|
||||
if (palf_reach_time_interval(1000 * 1000, time_interval)) {
|
||||
ret = convert_sys_errno();
|
||||
PALF_LOG(ERROR, "ob_pwrite failed", K(ret), K(fd), K(offset), K(count));
|
||||
PALF_LOG(ERROR, "ob_pwrite failed", K(ret), K(fd), K(offset), K(count), K(errno));
|
||||
}
|
||||
ob_usleep(RETRY_INTERVAL);
|
||||
} else {
|
||||
|
@ -101,7 +101,10 @@ void LogBlockMgr::destroy()
|
||||
is_inited_ = false;
|
||||
align_size_ = -1;
|
||||
align_buf_size_ = -1;
|
||||
dir_fd_ = -1;
|
||||
if (-1 != dir_fd_) {
|
||||
close_with_ret(dir_fd_);
|
||||
dir_fd_ = -1;
|
||||
}
|
||||
log_block_pool_ = NULL;
|
||||
curr_writable_handler_.destroy();
|
||||
curr_writable_block_id_ = LOG_INVALID_BLOCK_ID;
|
||||
@ -404,8 +407,8 @@ int LogBlockMgr::check_after_truncate_(const char *block_path, const offset_t of
|
||||
PALF_LOG(INFO, "check_after_truncate_ success", KPC(this), K(block_path), K(offset));
|
||||
}
|
||||
|
||||
if (-1 != fd && OB_FAIL(close_with_retry(fd))) {
|
||||
PALF_LOG(ERROR, "close_with_retry failed", KPC(this), K(block_path));
|
||||
if (-1 != fd && OB_FAIL(close_with_ret(fd))) {
|
||||
PALF_LOG(ERROR, "close_with_ret failed", KPC(this), K(block_path));
|
||||
}
|
||||
if (NULL != buf) {
|
||||
ob_free_align(buf);
|
||||
|
@ -22,7 +22,7 @@ int openat_with_retry(const int dir_fd,
|
||||
const int flag,
|
||||
const int mode,
|
||||
int &fd);
|
||||
int close_with_retry(const int fd);
|
||||
int close_with_ret(const int fd);
|
||||
|
||||
} // end namespace palf
|
||||
} // end namespace oceanbase
|
||||
|
@ -41,23 +41,16 @@ int openat_with_retry(const int dir_fd,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int close_with_retry(const int fd)
|
||||
int close_with_ret(const int fd)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (-1 == fd) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
PALF_LOG(ERROR, "invalid argument", K(fd));
|
||||
} else if (-1 == (::close(fd))) {
|
||||
ret = convert_sys_errno();
|
||||
PALF_LOG(ERROR, "close block failed", K(ret), K(errno), K(fd));
|
||||
} else {
|
||||
do {
|
||||
if (-1 == (::close(fd))) {
|
||||
ret = convert_sys_errno();
|
||||
PALF_LOG(ERROR, "open block failed", K(ret), K(errno), K(fd));
|
||||
ob_usleep(RETRY_INTERVAL);
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
break;
|
||||
}
|
||||
} while (OB_FAIL(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ IteratorStorage::IteratorStorage() :
|
||||
read_buf_(),
|
||||
block_size_(0),
|
||||
log_storage_(NULL),
|
||||
read_buf_has_log_block_header_(false),
|
||||
is_inited_(false) {}
|
||||
|
||||
IteratorStorage::~IteratorStorage()
|
||||
@ -61,7 +60,6 @@ int IteratorStorage::init(
|
||||
void IteratorStorage::destroy()
|
||||
{
|
||||
is_inited_ = false;
|
||||
read_buf_has_log_block_header_ = false;
|
||||
start_lsn_.reset();
|
||||
end_lsn_.reset();
|
||||
read_buf_.reset();
|
||||
@ -235,8 +233,6 @@ int DiskIteratorStorage::read_data_from_storage_(
|
||||
if (OB_FAIL(ensure_memory_layout_correct_(pos, in_read_size, remain_valid_data_size))) {
|
||||
PALF_LOG(WARN, "ensure_memory_layout_correct_ failed", K(ret), K(pos), K(in_read_size), KPC(this));
|
||||
} else {
|
||||
// NB: LogBlockHeader not consider by LSN, ignore it when no need to read('pos' need decrease MAX_INFO_BLOCK_SIZE).
|
||||
pos = (true == read_buf_has_log_block_header_ ? pos - MAX_INFO_BLOCK_SIZE : pos);
|
||||
// avoid read repeated data from disk
|
||||
const LSN curr_round_read_lsn = start_lsn_ + pos + remain_valid_data_size;
|
||||
const int64_t real_in_read_size = in_read_size - remain_valid_data_size;
|
||||
@ -254,9 +250,6 @@ int DiskIteratorStorage::read_data_from_storage_(
|
||||
buf = read_buf_.buf_;
|
||||
out_read_size += remain_valid_data_size;
|
||||
// check the 'read_buf_' whether has LogBlockHeader, if has, the return LSN need decrese MAX_INFO_BLOCK_SIZE
|
||||
read_buf_has_log_block_header_ = false;
|
||||
//read_buf_has_log_block_header_ =
|
||||
// (lsn_2_offset(curr_round_read_lsn, block_size_) == 0 ? true : false);
|
||||
PALF_LOG(TRACE, "read_data_from_storage_ success", K(ret), KPC(this), K(pos), K(in_read_size),
|
||||
K(curr_round_read_lsn), K(remain_valid_data_size), K(real_in_read_size), K(out_read_size));
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ public:
|
||||
void destroy();
|
||||
void reuse(const LSN &start_lsn);
|
||||
inline const LSN get_lsn(const offset_t pos) const
|
||||
{ return start_lsn_ + pos - (read_buf_has_log_block_header_ == true ? MAX_INFO_BLOCK_SIZE : 0); }
|
||||
{ return start_lsn_ + pos; }
|
||||
inline bool check_iterate_end(const offset_t pos) const
|
||||
{ return start_lsn_ + pos > get_file_end_lsn_(); }
|
||||
int pread(const int64_t pos,
|
||||
const int64_t in_read_size,
|
||||
char *&buf,
|
||||
int64_t &out_read_size);
|
||||
VIRTUAL_TO_STRING_KV(K_(start_lsn), K_(end_lsn), K_(read_buf), K_(block_size), KP(log_storage_), K_(read_buf_has_log_block_header));
|
||||
VIRTUAL_TO_STRING_KV(K_(start_lsn), K_(end_lsn), K_(read_buf), K_(block_size), KP(log_storage_));
|
||||
protected:
|
||||
inline int64_t get_valid_data_len_()
|
||||
{ return end_lsn_ - start_lsn_; }
|
||||
@ -62,7 +62,6 @@ protected:
|
||||
int64_t block_size_;
|
||||
ILogStorage *log_storage_;
|
||||
GetFileEndLSN get_file_end_lsn_;
|
||||
bool read_buf_has_log_block_header_;
|
||||
bool is_inited_;
|
||||
};
|
||||
|
||||
|
@ -87,7 +87,7 @@ int LogReader::pread(const block_id_t block_id,
|
||||
K(remained_read_size), K(block_path));
|
||||
} else {
|
||||
out_read_size += curr_out_read_size;
|
||||
remained_read_size -= step;
|
||||
remained_read_size -= curr_out_read_size;
|
||||
PALF_LOG(TRACE, "inner_pread_ success", K(ret), K(read_io_fd), K(block_id), K(offset), K(in_read_size),
|
||||
K(out_read_size), K(read_buf), K(curr_in_read_size), K(curr_read_lsn), K(curr_out_read_size),
|
||||
K(remained_read_size), K(block_path));
|
||||
@ -96,7 +96,7 @@ int LogReader::pread(const block_id_t block_id,
|
||||
}
|
||||
|
||||
if (-1 != read_io_fd && -1 == ::close(read_io_fd)) {
|
||||
ret = OB_IO_ERROR;
|
||||
ret = convert_sys_errno();
|
||||
PALF_LOG(ERROR, "close read_io_fd failed", K(ret), K(read_io_fd));
|
||||
}
|
||||
return ret;
|
||||
@ -113,6 +113,7 @@ int LogReader::inner_pread_(const int read_io_fd,
|
||||
offset_t backoff = start_offset - aligned_start_offset;
|
||||
int64_t aligned_in_read_size = upper_align(in_read_size + backoff, LOG_DIO_ALIGN_SIZE);
|
||||
int64_t limited_and_aligned_in_read_size = 0;
|
||||
ReadBufGuard read_buf_guard("LogReader", aligned_in_read_size);
|
||||
if (MAX_LOG_BUFFER_SIZE + LOG_DIO_ALIGN_SIZE < aligned_in_read_size) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
PALF_LOG(ERROR, "aligned_in_read_size is greater than MAX BUFFER LEN",
|
||||
|
@ -38,11 +38,6 @@ public:
|
||||
int64_t in_read_size,
|
||||
ReadBuf &read_buf,
|
||||
int64_t &out_read_size) const;
|
||||
int pread(const char *block_name,
|
||||
const offset_t read_lsn,
|
||||
int64_t in_read_size,
|
||||
ReadBuf &read_buf,
|
||||
int64_t &out_read_size) const;
|
||||
private:
|
||||
int limit_and_align_in_read_size_by_block_size_(
|
||||
offset_t aligned_start_offset,
|
||||
|
@ -757,7 +757,7 @@ int LogStorage::read_block_header_(const block_id_t block_id,
|
||||
PALF_LOG(WARN, "this block has been deleted", K(ret), K(block_id));
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
PALF_LOG(ERROR, "unexpected error, maybe deleted by human!!!", K(ret), K(block_id));
|
||||
PALF_LOG(WARN, "unexpected error, maybe deleted by human or flashabck!!!", K(ret), K(block_id), KPC(this));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user