From a5dbdb96ea86d3c087387586fd57dea8b0468d0c Mon Sep 17 00:00:00 2001 From: theshy <228933550@qq.com> Date: Tue, 28 May 2024 08:43:35 -0400 Subject: [PATCH] add state --- README.md | 32 +++++++++++++++---------- src/execution/executor_delete.h | 1 + src/execution/executor_index_scan.h | 2 +- src/execution/executor_insert.h | 2 +- src/execution/executor_update.h | 2 +- src/transaction/transaction_manager.cpp | 3 --- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index dfa903d6..aeea84a1 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,19 @@ -create table student (id int, name char(8), score float); -insert into student values (1, 'xiaohong', 90.0); -create index student(id); -insert into student values (2, 'xiaoming', 99.0); -begin; -delete from student where id>0; -select * from student where id>0; -abort; -select * from student; - -期待输出: -| id | name | score | -| 1 | xiaohong | 90.000000 | \ No newline at end of file +测试示例: +本测试判æ–系统是å¦ä¼šå‡ºçŽ°äº”ç§æ•°æ®å¼‚常,包括è„写(dirty write)ã€è„读(dirty read)ã€ä¸¢å¤±æ›´æ–°(lost update)ã€ä¸å¯é‡å¤è¯»(unrepeatable read)ã€å¹»è¯»(phantom)。 +例如,对è„读数æ®å¼‚常进行如下测试: +create table concurrency_test (id int, name char(8), score float); +insert into concurrency_test values (1, 'xiaohong', 90.0); +insert into concurrency_test values (2, 'xiaoming', 95.0); +insert into concurrency_test values (3, 'zhanghua', 88.5); +事务1: +t1a begin; +t1b update concurrency_test set score = 100.0 where id = 2; +t1c abort; +事务2: +t2a begin; +t2b select * from concurrency_test where id = 2; +t2c commit; +事务3: +t3a select * from concurrency_test where id = 2; +输入顺åºï¼št2a t1a t1b t2b t1c t2c t3a +注æ„:为ä¿è¯æ“作åºåˆ—按照指定顺åºè°ƒåº¦ï¼Œå‚赛队ä¼éœ€è¦ä¿è¯æ¯æ¡SQL(é™¤å› wait-dieç–ç•¥ç‰å¾…之外)的执行时间å°äºŽ300ms. \ No newline at end of file diff --git a/src/execution/executor_delete.h b/src/execution/executor_delete.h index 46b017ac..8d626ffd 100644 --- a/src/execution/executor_delete.h +++ b/src/execution/executor_delete.h @@ -60,6 +60,7 @@ class DeleteExecutor : public AbstractExecutor { } fh_->delete_record(rid, context_); + //by jinx 20240528 context_->txn_->append_write_record(new WriteRecord(WType::DELETE_TUPLE, tab_name_, rid, *rec.get())); // åˆ é™¤è®°å½•æ–‡ä»¶ä¸çš„记录 } diff --git a/src/execution/executor_index_scan.h b/src/execution/executor_index_scan.h index 8aa39081..fd339de3 100644 --- a/src/execution/executor_index_scan.h +++ b/src/execution/executor_index_scan.h @@ -39,7 +39,7 @@ class IndexScanExecutor : public AbstractExecutor { public: IndexScanExecutor(SmManager *sm_manager, std::string tab_name, std::vector<Condition> conds, std::vector<std::string> index_col_names, Context *context,IndexMeta idx_meta) { - std::cout<<"qunimade1"<<std::endl; + std::cout<<"intoindexscan"<<std::endl; sm_manager_ = sm_manager; context_ = context; tab_name_ = std::move(tab_name); diff --git a/src/execution/executor_insert.h b/src/execution/executor_insert.h index e436051c..ef9d07ba 100644 --- a/src/execution/executor_insert.h +++ b/src/execution/executor_insert.h @@ -82,7 +82,7 @@ class InsertExecutor : public AbstractExecutor { ih->insert_entry(key, rid_, context_->txn_); delete[] key; } - + //by jinx 20240528 context_->txn_->append_write_record(new WriteRecord(WType::INSERT_TUPLE, tab_name_, rid_)); return nullptr; diff --git a/src/execution/executor_update.h b/src/execution/executor_update.h index 9951837f..dc2c9c3d 100644 --- a/src/execution/executor_update.h +++ b/src/execution/executor_update.h @@ -130,7 +130,7 @@ std::unique_ptr<RmRecord> Next() override { // 更新记录文件ä¸çš„记录 fh_->update_record(rid, update_record.data, context_); - + //by jinx 20240528 RmRecord originrecord{ rec->size }; memcpy(originrecord.data, rec->data, rec->size); context_->txn_->append_write_record(new WriteRecord(WType::UPDATE_TUPLE, tab_name_, rid, originrecord)); diff --git a/src/transaction/transaction_manager.cpp b/src/transaction/transaction_manager.cpp index 7a4bec79..819b0ea4 100644 --- a/src/transaction/transaction_manager.cpp +++ b/src/transaction/transaction_manager.cpp @@ -86,9 +86,6 @@ void TransactionManager::abort(Transaction * txn, LogManager *log_manager) { auto& wrecord = write_set->back(); auto type = wrecord->GetWriteType(); sm_manager_->dealwithrollback(type,wrecord,context); - //sm_manager_->insert_rollback(item->GetTableName(),item->GetRid(), context); - //sm_manager_->update_rollback(item->GetTableName(), item->GetRid(), item->GetRecord(), context); - //sm_manager_->delete_rollback(item->GetTableName(),item->GetRecord(), context); write_set->pop_back(); } write_set->clear(); -- GitLab