Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit c40cd60

Browse files
(I think) this fixes the Halloween problem
1 parent bc297d0 commit c40cd60

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/codegen/updater.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ char *Updater::GetDataPtr(uint32_t tile_group_id, uint32_t tuple_offset) {
5353

5454
char *Updater::Prepare(uint32_t tile_group_id, uint32_t tuple_offset) {
5555
PELOTON_ASSERT(table_ != nullptr && executor_context_ != nullptr);
56+
57+
if (IsInStatementWriteSet(ItemPointer(tile_group_id, tuple_offset))) {
58+
return nullptr;
59+
}
60+
5661
auto *txn = executor_context_->GetTransaction();
5762
auto tile_group = table_->GetTileGroupById(tile_group_id).get();
5863
auto *tile_group_header = tile_group->GetHeader();
@@ -79,7 +84,7 @@ char *Updater::PreparePK(uint32_t tile_group_id, uint32_t tuple_offset) {
7984

8085
PELOTON_ASSERT(table_ != nullptr && executor_context_ != nullptr);
8186

82-
if (statement_write_set_->find(ItemPointer(tile_group_id, tuple_offset)) != statement_write_set_->end()) {
87+
if (IsInStatementWriteSet(ItemPointer(tile_group_id, tuple_offset))) {
8388
return nullptr;
8489
}
8590

@@ -130,7 +135,6 @@ void Updater::Update() {
130135
auto tile_group = table_->GetTileGroupById(old_location_.block).get();
131136
auto *tile_group_header = tile_group->GetHeader();
132137
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
133-
134138
// Either update in-place
135139
if (is_owner_ == true) {
136140
txn_manager.PerformUpdate(txn, old_location_);
@@ -151,6 +155,7 @@ void Updater::Update() {
151155
return;
152156
}
153157
txn_manager.PerformUpdate(txn, old_location_, new_location_);
158+
AddToStatementWriteSet(new_location_);
154159
executor_context_->num_processed++;
155160
}
156161

@@ -174,7 +179,7 @@ void Updater::UpdatePK() {
174179
return;
175180
}
176181
txn_manager.PerformInsert(txn, new_location_, index_entry_ptr);
177-
statement_write_set_->insert(new_location_);
182+
AddToStatementWriteSet(new_location_);
178183
executor_context_->num_processed++;
179184
}
180185

src/executor/update_executor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ bool UpdateExecutor::PerformUpdatePrimaryKey(
6262
bool is_owner, storage::TileGroup *tile_group,
6363
storage::TileGroupHeader *tile_group_header, oid_t physical_tuple_id,
6464
ItemPointer &old_location) {
65-
66-
if (statement_write_set_.find(old_location) != statement_write_set_.end()) {
65+
66+
/* if (statement_write_set_.find(old_location) != statement_write_set_.end()) {
6767
return true;
68-
}
68+
} */
6969

7070
auto &transaction_manager =
7171
concurrency::TransactionManagerFactory::GetInstance();
@@ -195,6 +195,9 @@ bool UpdateExecutor::DExecute() {
195195
oid_t physical_tuple_id = pos_lists[0][visible_tuple_id];
196196

197197
ItemPointer old_location(tile_group->GetTileGroupId(), physical_tuple_id);
198+
if (IsInStatementWriteSet(old_location)) {
199+
continue;
200+
}
198201

199202
LOG_TRACE("Visible Tuple id : %u, Physical Tuple id : %u ",
200203
visible_tuple_id, physical_tuple_id);
@@ -269,6 +272,7 @@ bool UpdateExecutor::DExecute() {
269272
executor_context_);
270273

271274
transaction_manager.PerformUpdate(current_txn, old_location);
275+
statement_write_set_.insert(old_location);
272276
}
273277
}
274278
// if we have already obtained the ownership
@@ -366,6 +370,7 @@ bool UpdateExecutor::DExecute() {
366370
new_location.offset);
367371
transaction_manager.PerformUpdate(current_txn, old_location,
368372
new_location);
373+
statement_write_set_.insert(new_location);
369374

370375
// TODO: Why don't we also do this in the if branch above?
371376
executor_context_->num_processed += 1; // updated one

src/include/codegen/updater.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ class Updater {
6767

6868
char *GetDataPtr(uint32_t tile_group_id, uint32_t tuple_offset);
6969

70+
// Check if the tuple is in the statement write set
71+
inline bool IsInStatementWriteSet(ItemPointer location) {
72+
return statement_write_set_->find(location) !=
73+
statement_write_set_->end();
74+
}
75+
76+
// Add the updated location to the statement write set
77+
inline void AddToStatementWriteSet(ItemPointer& location) {
78+
statement_write_set_->insert(location);
79+
}
80+
7081
private:
7182
// Table and executor context from the update translator
7283
storage::DataTable *table_;

src/include/executor/update_executor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class UpdateExecutor : public AbstractExecutor {
4949

5050
bool DExecute();
5151

52+
inline bool IsInStatementWriteSet(ItemPointer &location) {
53+
return (statement_write_set_.find(location) != statement_write_set_.end());
54+
}
55+
5256
private:
5357
storage::DataTable *target_table_ = nullptr;
5458
const planner::ProjectInfo *project_info_ = nullptr;

0 commit comments

Comments
 (0)