add lock to protect slog writer's cursor_

This commit is contained in:
obdev
2023-05-04 04:11:55 +00:00
committed by ob-robot
parent 8094743d24
commit f99116654a
2 changed files with 10 additions and 2 deletions

View File

@ -151,6 +151,12 @@ void ObStorageLogWriter::destroy()
is_inited_ = false;
}
ObLogCursor ObStorageLogWriter::get_cur_cursor()
{
ObSpinLockGuard guard(cursor_lock_);
return cursor_;
}
int ObStorageLogWriter::start_log(const ObLogCursor &start_cursor)
{
int ret = OB_SUCCESS;
@ -555,6 +561,7 @@ int ObStorageLogWriter::advance_file_id()
{
int ret = OB_SUCCESS;
ObSpinLockGuard guard(cursor_lock_);
if (file_handler_.is_opened() && OB_FAIL(file_handler_.close())) {
STORAGE_REDO_LOG(WARN, "Fail to close file", K(ret), K(cursor_.file_id_));
} else if (OB_FAIL(file_handler_.open(cursor_.file_id_ + 1))) {
@ -609,6 +616,7 @@ int ObStorageLogWriter::update_log_item_cursor(
ret = OB_INVALID_ARGUMENT;
LOG_ERROR("Invalid argument", K(ret), KP(log_item));
} else {
ObSpinLockGuard guard(cursor_lock_);
log_item->start_cursor_.file_id_ = cursor_.file_id_;
log_item->start_cursor_.log_id_ = log_item->get_seq();
log_item->start_cursor_.offset_ = begin_offset;

View File

@ -47,7 +47,7 @@ public:
virtual int start() override;
virtual void wait() override;
void destroy();
common::ObLogCursor get_cur_cursor() const { return cursor_; }
common::ObLogCursor get_cur_cursor();
int delete_log_file(const int64_t file_id);
int get_using_disk_space(int64_t &using_space) const;
@ -136,7 +136,7 @@ private:
// because it won't count the offset on the write buffer
int64_t write_offset_;
common::ObLogCursor cursor_;
common::ObSpinLock cursor_lock_;
common::ObLogRetryWritePolicy retry_write_policy_;
common::ObLogWritePolicy log_write_policy_;