Skip to content

Commit a1472b1

Browse files
committed
Update:更新有锁获取undologs
1 parent 2677383 commit a1472b1

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/execution/execution_sort.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SortExecutor : public AbstractExecutor {
7575
}
7676

7777
// 使用std::sort排序
78-
parallel::sort(
78+
std::sort(
7979
sorted_tuples_.begin(), sorted_tuples_.end(),
8080
[this](const std::unique_ptr<RmRecord>& a, const std::unique_ptr<RmRecord>& b) { return this->cmp(a, b); });
8181
}

src/transaction/transaction_manager.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,35 @@ void TransactionManager::add_delete_undo_log(Transaction* txn, const int& fd, Ri
523523
log.prev_version_ = DeleteUpdateVersionLink(fd, rid, txn);
524524
auto undo_link = txn->AppendUndoLog(log);
525525
UpdateUndoLink(fd, rid, undo_link);
526+
}
527+
528+
std::pair<std::vector<UndoLog>, bool> TransactionManager::get_undologs_with_lock(int fd, Rid rid, Transaction *txn) {
529+
std::shared_lock<std::shared_mutex> lock(version_info_mutex_);
530+
std::vector<UndoLog> undo_logs;
531+
auto pre_undo_link = GetUndoLink(fd, rid);
532+
533+
// 现在磁盘的是不是被标记删除
534+
bool is_deleted = false;
535+
if(pre_undo_link.has_value()) {
536+
auto undo_log = GetUndoLog(pre_undo_link.value());
537+
is_deleted = undo_log.is_deleted_;
538+
}
539+
540+
while (pre_undo_link.has_value()) {
541+
auto undo_log = GetUndoLog(pre_undo_link.value());
542+
// 如果是自己修改的直接返回
543+
if (pre_undo_link.value().prev_txn_ == txn->get_transaction_id()) {
544+
break;
545+
}
546+
// 如果是已提交事物
547+
if (undo_log.ts_ <= txn->get_read_ts()) {
548+
break;
549+
}
550+
undo_logs.push_back(undo_log);
551+
pre_undo_link = undo_log.prev_version_;
552+
if (!pre_undo_link->IsValid()) {
553+
break;
554+
}
555+
}
556+
return {undo_logs, is_deleted};
526557
}

src/transaction/transaction_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ class TransactionManager {
213213

214214
void do_delete(Transaction *txn);
215215

216+
std::pair<std::vector<UndoLog>, bool> get_undologs_with_lock(int fd, Rid rid, Transaction *txn);
217+
216218
private:
217219
/** @brief 检查事务是否可以被垃圾回收 */
218220
bool is_transaction_expired(Transaction *txn, timestamp_t watermark) const;

0 commit comments

Comments
 (0)