ItemPointer DataTable::InsertVersion(const storage::Tuple *tuple) { // First, do integrity checks and claim a slot ItemPointer location = GetEmptyTupleSlot(tuple, true); if (location.block == INVALID_OID) { LOG_TRACE("Failed to get tuple slot."); return INVALID_ITEMPOINTER; } // Index checks and updates if (InsertInSecondaryIndexes(tuple, location) == false) { LOG_TRACE("Index constraint violated"); return INVALID_ITEMPOINTER; } // ForeignKey checks if (CheckForeignKeyConstraints(tuple) == false) { LOG_TRACE("ForeignKey constraint violated"); return INVALID_ITEMPOINTER; } LOG_TRACE("Location: %u, %u", location.block, location.offset); IncreaseNumberOfTuplesBy(1); return location; }
ItemPointer DataTable::InsertTuple(const storage::Tuple *tuple) { // First, do integrity checks and claim a slot ItemPointer location = GetEmptyTupleSlot(tuple); if (location.block == INVALID_OID) { LOG_TRACE("Failed to get tuple slot."); return INVALID_ITEMPOINTER; } LOG_TRACE("Location: %u, %u", location.block, location.offset); // Index checks and updates if (InsertInIndexes(tuple, location) == false) { LOG_TRACE("Index constraint violated"); return INVALID_ITEMPOINTER; } // ForeignKey checks if (CheckForeignKeyConstraints(tuple) == false) { LOG_TRACE("ForeignKey constraint violated"); return INVALID_ITEMPOINTER; } // Increase the table's number of tuples by 1 IncreaseNumberOfTuplesBy(1); // Increase the indexes' number of tuples by 1 as well for (auto index : indexes_) index->IncreaseNumberOfTuplesBy(1); return location; }
/** * @brief read tuple record from log file and add them tuples to recovery txn * @param recovery txn */ void AriesFrontendLogger::InsertTuple(concurrency::Transaction *recovery_txn) { TupleRecord tuple_record(LOGRECORD_TYPE_ARIES_TUPLE_INSERT); // Check for torn log write if (ReadTupleRecordHeader(tuple_record, log_file, log_file_size) == false) { LOG_ERROR("Could not read tuple record header."); return; } auto txn_id = tuple_record.GetTransactionId(); if (recovery_txn_table.find(txn_id) == recovery_txn_table.end()) { LOG_ERROR("Insert txd id %d not found in recovery txn table", (int)txn_id); return; } auto table = GetTable(tuple_record); // Read off the tuple record body from the log auto tuple = ReadTupleRecordBody(table->GetSchema(), recovery_pool, log_file, log_file_size); // Check for torn log write if (tuple == nullptr) { return; } auto target_location = tuple_record.GetInsertLocation(); auto tile_group_id = target_location.block; auto tuple_slot = target_location.offset; auto &manager = catalog::Manager::GetInstance(); auto tile_group = manager.GetTileGroup(tile_group_id); auto txn = recovery_txn_table.at(txn_id); // Create new tile group if table doesn't already have that tile group if (tile_group == nullptr) { table->AddTileGroupWithOid(tile_group_id); tile_group = manager.GetTileGroup(tile_group_id); if (max_oid < tile_group_id) { max_oid = tile_group_id; } } // Do the insert ! auto inserted_tuple_slot = tile_group->InsertTuple( recovery_txn->GetTransactionId(), tuple_slot, tuple); if (inserted_tuple_slot == INVALID_OID) { // TODO: We need to abort on failure ! recovery_txn->SetResult(Result::RESULT_FAILURE); } else { txn->RecordInsert(target_location); table->IncreaseNumberOfTuplesBy(1); } delete tuple; }