From 4a2b2145a7182488b227b583476bc55b00300b0f Mon Sep 17 00:00:00 2001 From: hiddenbomb Date: Mon, 27 Sep 2021 21:29:42 +0800 Subject: [PATCH] fix race condition when slog write failed --- .../slog/ob_storage_log_writer.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/storage/blocksstable/slog/ob_storage_log_writer.cpp b/src/storage/blocksstable/slog/ob_storage_log_writer.cpp index 81f0135912..7e07a8ba3f 100644 --- a/src/storage/blocksstable/slog/ob_storage_log_writer.cpp +++ b/src/storage/blocksstable/slog/ob_storage_log_writer.cpp @@ -738,22 +738,24 @@ int ObStorageLogWriter::process_logs_in_batch( } } - if (OB_FAIL(ret)) { // wake up logs not sync + if (OB_FAIL(ret)) { + // wake up logs not sync for (int64_t i = sync_index + 1; i < item_cnt; ++i) { - if (NULL == items[i]) { + if (OB_ISNULL(items[i])) { LOG_ERROR("log_item in items is null", K(ret), KP(items[i])); } else { - ObStorageLogItem* log_item = reinterpret_cast(items[i]); + ObStorageLogItem *log_item = reinterpret_cast(items[i]); + if (i == sync_index + 1) { + // set build cursor and write cursor with the specified log item in queue + ObMutexGuard guard(build_log_mutex_); + build_cursor_ = log_item->start_cursor_; + write_cursor_ = log_item->start_cursor_; + } // aggregate_logs_to_buffer may fail for invalid cursor arguments, // we just finish flush and let upper layer retry log_item->finish_flush(ret); } } - - ObMutexGuard guard(build_log_mutex_); - ObStorageLogItem* log_item = reinterpret_cast(items[sync_index + 1]); - build_cursor_ = log_item->start_cursor_; - write_cursor_ = log_item->start_cursor_; LOG_ERROR("slog write failed, record cursor", K(ret), K_(build_cursor), K_(write_cursor)); } finish_cnt = item_cnt; @@ -775,7 +777,7 @@ int ObStorageLogWriter::prepare_fd(const int64_t file_id) // close last log file opened if (-1 != cur_file_id_ && OB_FAIL(file_store_->close())) { ret = OB_IO_ERROR; - LOG_ERROR("close error", K_(cur_file_id), KERRMSG); + LOG_ERROR("close error", K_(cur_file_id), K(file_id), KERRMSG); } if (OB_SUCC(ret)) { -- GitLab