diff --git a/src/storage/blocksstable/slog/ob_storage_log_writer.cpp b/src/storage/blocksstable/slog/ob_storage_log_writer.cpp index 7e07a8ba3ffed99c96cac6f51dffc361effa7978..c0fc11443f3ba21f4bc0cb53484d90b4d2dea8af 100644 --- a/src/storage/blocksstable/slog/ob_storage_log_writer.cpp +++ b/src/storage/blocksstable/slog/ob_storage_log_writer.cpp @@ -517,8 +517,8 @@ int ObStorageLogWriter::get_log_item( const LogCommand cmd, const ObBaseStorageLogBuffer& data, ObStorageLogItem*& log_item) { int ret = OB_SUCCESS; - void* log_buffer = nullptr; - log_item = nullptr; + void *log_buffer = NULL; + ObStorageLogItem *item = NULL; if (IS_NOT_INIT) { ret = OB_NOT_INIT; LOG_WARN("not init", K(ret)); @@ -543,16 +543,16 @@ int ObStorageLogWriter::get_log_item( LOG_ERROR("log item too long", K(ret), K(total_item_size), LITERAL_K(LOG_ITEM_MAX_LENGTH)); } else if (!alloc_locally && OB_FAIL(log_buffers_.pop(log_buffer))) { LOG_WARN("pop failed", K(ret)); - } else if (OB_FAIL(slog_items_.pop(log_item))) { - LOG_WARN("pop log_item failed", K(ret)); - } else if (OB_FAIL(log_item->init(reinterpret_cast(log_buffer), total_item_size))) { - LOG_WARN("init log_item failed", K(ret)); + } else if (OB_FAIL(slog_items_.pop(item))) { + LOG_WARN("pop log item failed", K(ret)); + } else if (OB_FAIL(item->init(reinterpret_cast(log_buffer), total_item_size))) { + LOG_WARN("init log item failed", K(ret)); } else { - log_item->start_cursor_ = build_cursor_; - if (OB_FAIL(build_log_item(cmd, data, log_item))) { + item->start_cursor_ = build_cursor_; + if (OB_FAIL(build_log_item(cmd, data, item))) { LOG_WARN("build_log_item failed", K(ret), K(cmd), K(data)); } else { - log_item->end_cursor_ = build_cursor_; + item->end_cursor_ = build_cursor_; } } } @@ -564,12 +564,14 @@ int ObStorageLogWriter::get_log_item( LOG_ERROR("push log_buffer failed", K(temp_ret), KP(log_buffer)); } } - if (NULL != log_item) { - log_item->reset(); - if (OB_SUCCESS != (temp_ret = slog_items_.push(log_item))) { - LOG_ERROR("push log_item failed", K(temp_ret), KP(log_item)); + if (NULL != item) { + item->reset(); + if (OB_SUCCESS != (temp_ret = slog_items_.push(item))) { + LOG_ERROR("push log item failed", K(temp_ret), KP(item)); } } + } else { + log_item = item; } return ret; } diff --git a/unittest/storage/blocksstable/slog/test_storage_log_reader_writer.cpp b/unittest/storage/blocksstable/slog/test_storage_log_reader_writer.cpp index 4bdb213f40cfc3ba17f47d1c1a1e805a88d24d07..4702cceb3b78816c452fce63eb03ac9bfda015c0 100644 --- a/unittest/storage/blocksstable/slog/test_storage_log_reader_writer.cpp +++ b/unittest/storage/blocksstable/slog/test_storage_log_reader_writer.cpp @@ -12,6 +12,7 @@ #include #include + #include "lib/file/file_directory_utils.h" #include "lib/utility/ob_tracepoint.h" #include "storage/blocksstable/slog/ob_storage_log_reader.h" @@ -1094,6 +1095,8 @@ TEST_F(TestStorageLogReaderWriter, read_multiple_files) int main(int argc, char** argv) { + system("rm -f test_storage_log_reader_writer.log*"); + OB_LOGGER.set_file_name("test_storage_log_reader_writer.log", true); OB_LOGGER.set_log_level("INFO"); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();