void LogManager::LogUpdate(cid_t commit_id, const ItemPointer &old_version, const ItemPointer &new_version) { if (this->IsInLoggingMode()) { auto &manager = catalog::Manager::GetInstance(); auto new_tuple_tile_group = manager.GetTileGroup(new_version.block); auto logger = this->GetBackendLogger(); auto schema = manager.GetTableWithOid(new_tuple_tile_group->GetDatabaseId(), new_tuple_tile_group->GetTableId()) ->GetSchema(); // Can we avoid allocate tuple in head each time? std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(schema, true)); for (oid_t col = 0; col < schema->GetColumnCount(); col++) { tuple->SetValue(col, new_tuple_tile_group->GetValue(new_version.offset, col), logger->GetVarlenPool()); } std::unique_ptr<LogRecord> record( logger->GetTupleRecord(LOGRECORD_TYPE_TUPLE_UPDATE, commit_id, new_tuple_tile_group->GetTableId(), new_tuple_tile_group->GetDatabaseId(), new_version, old_version, tuple.get())); logger->Log(record.get()); } }
void LogManager::LogInsert(cid_t commit_id, const ItemPointer &new_location) { if (this->IsInLoggingMode()) { auto logger = this->GetBackendLogger(); auto &manager = catalog::Manager::GetInstance(); auto new_tuple_tile_group = manager.GetTileGroup(new_location.block); auto tile_group = manager.GetTileGroup(new_location.block); auto schema = manager.GetTableWithOid(tile_group->GetDatabaseId(), tile_group->GetTableId())->GetSchema(); std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(schema, true)); for (oid_t col = 0; col < schema->GetColumnCount(); col++) { tuple->SetValue(col, new_tuple_tile_group->GetValue(new_location.offset, col), logger->GetVarlenPool()); } std::unique_ptr<LogRecord> record(logger->GetTupleRecord( LOGRECORD_TYPE_TUPLE_INSERT, commit_id, tile_group->GetTableId(), new_tuple_tile_group->GetDatabaseId(), new_location, INVALID_ITEMPOINTER, tuple.get())); logger->Log(record.get()); } }
void LogManager::LogDelete(cid_t commit_id, const ItemPointer &delete_location) { if (this->IsInLoggingMode()) { auto logger = this->GetBackendLogger(); auto &manager = catalog::Manager::GetInstance(); auto tile_group = manager.GetTileGroup(delete_location.block); std::unique_ptr<LogRecord> record(logger->GetTupleRecord( LOGRECORD_TYPE_TUPLE_DELETE, commit_id, tile_group->GetTableId(), tile_group->GetDatabaseId(), INVALID_ITEMPOINTER, delete_location)); logger->Log(record.get()); } }
storage::TileGroup *DataTable::TransformTileGroup( const oid_t &tile_group_offset, const double &theta) { // First, check if the tile group is in this table if (tile_group_offset >= tile_groups_.GetSize()) { LOG_ERROR("Tile group offset not found in table : %u ", tile_group_offset); return nullptr; } auto tile_group_id = tile_groups_.FindValid(tile_group_offset, invalid_tile_group_id); // Get orig tile group from catalog auto &catalog_manager = catalog::Manager::GetInstance(); auto tile_group = catalog_manager.GetTileGroup(tile_group_id); auto diff = tile_group->GetSchemaDifference(default_partition_); // Check threshold for transformation if (diff < theta) { return nullptr; } LOG_TRACE("Transforming tile group : %u", tile_group_offset); // Get the schema for the new transformed tile group auto new_schema = TransformTileGroupSchema(tile_group.get(), default_partition_); // Allocate space for the transformed tile group std::shared_ptr<storage::TileGroup> new_tile_group( TileGroupFactory::GetTileGroup( tile_group->GetDatabaseId(), tile_group->GetTableId(), tile_group->GetTileGroupId(), tile_group->GetAbstractTable(), new_schema, default_partition_, tile_group->GetAllocatedTupleCount())); // Set the transformed tile group column-at-a-time SetTransformedTileGroup(tile_group.get(), new_tile_group.get()); // Set the location of the new tile group // and clean up the orig tile group catalog_manager.AddTileGroup(tile_group_id, new_tile_group); return new_tile_group.get(); }