Skip to content

Commit 15dc51d

Browse files
committed
Cherry-pick GC fixes from cmu-db#1349, final part. Passes all tests.
1 parent 64c289c commit 15dc51d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/storage/data_table.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,19 @@ bool DataTable::InsertInIndexes(const AbstractTuple *tuple,
469469

470470
// Handle failure
471471
if (res == false) {
472-
// If some of the indexes have been inserted,
473-
// the pointer has a chance to be dereferenced by readers and it cannot be
474-
// deleted
472+
// if an index insert fails, undo all prior inserts on this index
473+
for (index_itr = index_itr + 1; index_itr < index_count; ++index_itr) {
474+
index = GetIndex(index_itr);
475+
if (index == nullptr) continue;
476+
index_schema = index->GetKeySchema();
477+
indexed_columns = index_schema->GetIndexedColumns();
478+
std::unique_ptr<storage::Tuple> delete_key(
479+
new storage::Tuple(index_schema, true));
480+
delete_key->SetFromTuple(tuple, indexed_columns, index->GetPool());
481+
UNUSED_ATTRIBUTE bool delete_res =
482+
index->DeleteEntry(delete_key.get(), *index_entry_ptr);
483+
PELOTON_ASSERT(delete_res == true);
484+
}
475485
*index_entry_ptr = nullptr;
476486
return false;
477487
} else {

0 commit comments

Comments
 (0)