389337 {
389338 MetaBlockPointer pointer;
389340 auto debug_verify_blocks = Settings::Get<DebugVerifyBlocksSetting>(GetDatabase());
389342
389343
389344
389346 vector<MetaBlockPointer> written_pointers;
389348
389349
389350 BinarySerializer stats_serializer(
table_data_writer, serializer.GetOptions());
389351 stats_serializer.Begin();
389352 global_stats.Serialize(stats_serializer);
389353 stats_serializer.End();
389354
389355
389357 total_rows = 0;
389359 auto row_group_count = row_group_pointer.row_start + row_group_pointer.tuple_count;
389360 if (row_group_count > total_rows) {
389361 total_rows = row_group_count;
389362 }
389363
389364
389365 BinarySerializer row_group_serializer(
table_data_writer, serializer.GetOptions());
389366 row_group_serializer.Begin();
389367 RowGroup::Serialize(row_group_pointer, row_group_serializer);
389368 row_group_serializer.End();
389369 }
389371 collection.FinalizeCheckpoint(pointer, written_pointers);
389372 } else {
389373
389375 total_rows = existing_rows.GetIndex();
389376
389377
389378 auto &metadata_manager = checkpoint_manager.GetMetadataManager();
389379 metadata_manager.ClearModifiedBlocks(existing_pointers);
389380
389381
389382 if (debug_verify_blocks) {
389383 vector<MetaBlockPointer> read_pointers;
389384 MetadataReader reader(metadata_manager, pointer, read_pointers);
389385 auto bound_info = Binder::BindCreateTableCheckpoint(table.GetInfo(), table.schema);
389386 TableDataReader data_reader(reader, *bound_info, pointer);
389387 data_reader.ReadTableData();
389388 for (
idx_t row_group = 0; row_group < bound_info->data->row_group_count; ++row_group) {
389389 BinaryDeserializer deserializer(reader);
389390 deserializer.Begin();
389391 auto row_group_pointer = RowGroup::Deserialize(deserializer);
389392 deserializer.End();
389393 }
389394 set<idx_t> existing_block_ids;
389395 for (auto &ptr : existing_pointers) {
389396 existing_block_ids.insert(ptr.block_pointer);
389397 }
389398 set<idx_t> all_read_block_ids;
389399 for (auto &ptr : read_pointers) {
389400 all_read_block_ids.insert(ptr.block_pointer);
389401 }
389402 if (existing_block_ids != all_read_block_ids) {
389403 std::stringstream oss;
389404 oss << "Existing: ";
389405 for (auto &block : existing_pointers) {
389406 oss << block << ", ";
389407 }
389408 oss << "\n";
389409 oss << "Read: ";
389410 for (auto &block : read_pointers) {
389411 oss << block << ", ";
389412 }
389413 oss << "\n";
389414 throw InternalException("Reading existing blocks does not yield same blocks: " + oss.str());
389415 }
389416 }
389417 }
389418
389419
389420
389421 serializer.WriteProperty(101, "table_pointer", pointer);
389422 serializer.WriteProperty(102, "total_rows", total_rows);
389423
389424 auto v1_0_0_storage = serializer.GetOptions().serialization_compatibility.serialization_version < 3;
389425 IndexSerializationInfo serialization_info;
389426 if (!v1_0_0_storage) {
389427 serialization_info.options.emplace("v1_0_0_storage", v1_0_0_storage);
389428 }
389429 serialization_info.checkpoint_id = GetCheckpointOptions().transaction_id;
389430
389431 auto index_storage_infos = info.GetIndexes().SerializeToDisk(context, serialization_info);
389432
389433 if (debug_verify_blocks) {
389434 for (auto &entry : index_storage_infos.ordered_infos) {
389435 for (auto &allocator : entry.get().allocator_infos) {
389436 for (auto &block : allocator.block_pointers) {
389437 checkpoint_manager.verify_block_usage_count[block.block_id]++;
389438 }
389439 }
389440 }
389441 }
389442
389443
389444 vector<BlockPointer> compat_block_pointers;
389445 serializer.WriteProperty(103, "index_pointers", compat_block_pointers);
389446 serializer.WriteList(
389447 104, "index_storage_infos", index_storage_infos.ordered_infos.size(),
389448 [&](Serializer::List &list,
idx_t i) { list.WriteElement(index_storage_infos.ordered_infos[i].get()); });
389449}
vector< RowGroupPointer > row_group_pointers
Pointers to the start of each row group.
Definition duckdb.cpp:389116
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237