@@ -618,9 +618,7 @@ class TableMetadataBuilder::Impl {
618618 Status SetBranchSnapshot (std::shared_ptr<Snapshot> snapshot, const std::string& branch);
619619 Status SetRef (const std::string& name, std::shared_ptr<SnapshotRef> ref);
620620
621- Status SetRef (const std::string& name, std::shared_ptr<SnapshotRef> ref);
622621 Status RemoveRef (const std::string& name);
623- Status AddSnapshot (std::shared_ptr<Snapshot> snapshot);
624622 Status RemoveSnapshots (const std::vector<int64_t >& snapshot_ids);
625623 Status RemovePartitionSpecs (const std::vector<int32_t >& spec_ids);
626624
@@ -1340,68 +1338,6 @@ int32_t TableMetadataBuilder::Impl::ReuseOrCreateNewSchemaId(
13401338 return new_schema_id;
13411339}
13421340
1343- Status TableMetadataBuilder::Impl::SetRef (const std::string& name,
1344- std::shared_ptr<SnapshotRef> ref) {
1345- // Check if the ref already exists and is equal to the new ref
1346- auto existing_ref_it = metadata_.refs .find (name);
1347- if (existing_ref_it != metadata_.refs .end () && *existing_ref_it->second == *ref) {
1348- // No change needed
1349- return {};
1350- }
1351-
1352- // Validate that the snapshot exists
1353- int64_t snapshot_id = ref->snapshot_id ;
1354- auto snapshot_it =
1355- std::ranges::find_if (metadata_.snapshots , [snapshot_id](const auto & snapshot) {
1356- return snapshot != nullptr && snapshot->snapshot_id == snapshot_id;
1357- });
1358- ICEBERG_PRECHECK (snapshot_it != metadata_.snapshots .end (),
1359- " Cannot set {} to unknown snapshot: {}" , name, snapshot_id);
1360-
1361- // Check if this is an added snapshot (in the current set of changes)
1362- bool is_added_snapshot =
1363- std::ranges::any_of (changes_, [snapshot_id](const auto & change) {
1364- return change->kind () == TableUpdate::Kind::kAddSnapshot &&
1365- internal::checked_cast<const table::AddSnapshot&>(*change)
1366- .snapshot ()
1367- ->snapshot_id == snapshot_id;
1368- });
1369-
1370- if (is_added_snapshot) {
1371- metadata_.last_updated_ms = (*snapshot_it)->timestamp_ms ;
1372- }
1373-
1374- // Handle main branch specially
1375- if (name == SnapshotRef::kMainBranch ) {
1376- metadata_.current_snapshot_id = ref->snapshot_id ;
1377- if (metadata_.last_updated_ms == kInvalidLastUpdatedMs ) {
1378- metadata_.last_updated_ms =
1379- TimePointMs{std::chrono::duration_cast<std::chrono::milliseconds>(
1380- std::chrono::system_clock::now ().time_since_epoch ())};
1381- }
1382-
1383- metadata_.snapshot_log .emplace_back (metadata_.last_updated_ms , ref->snapshot_id );
1384- }
1385-
1386- // Update the refs map
1387- metadata_.refs [name] = ref;
1388-
1389- // Record the change
1390- if (ref->type () == SnapshotRefType::kBranch ) {
1391- auto retention = std::get<SnapshotRef::Branch>(ref->retention );
1392- changes_.push_back (std::make_unique<table::SetSnapshotRef>(
1393- name, ref->snapshot_id , ref->type (), retention.min_snapshots_to_keep ,
1394- retention.max_snapshot_age_ms , retention.max_ref_age_ms ));
1395- } else {
1396- auto retention = std::get<SnapshotRef::Tag>(ref->retention );
1397- changes_.push_back (std::make_unique<table::SetSnapshotRef>(
1398- name, ref->snapshot_id , ref->type (), std::nullopt , std::nullopt ,
1399- retention.max_ref_age_ms ));
1400- }
1401-
1402- return {};
1403- }
1404-
14051341Status TableMetadataBuilder::Impl::RemoveRef (const std::string& name) {
14061342 // Handle main branch specially
14071343 if (name == SnapshotRef::kMainBranch ) {
@@ -1418,47 +1354,6 @@ Status TableMetadataBuilder::Impl::RemoveRef(const std::string& name) {
14181354 return {};
14191355}
14201356
1421- Status TableMetadataBuilder::Impl::AddSnapshot (std::shared_ptr<Snapshot> snapshot) {
1422- if (snapshot == nullptr ) {
1423- // No-op
1424- return {};
1425- }
1426-
1427- // Validate preconditions
1428- ICEBERG_PRECHECK (!metadata_.schemas .empty (),
1429- " Attempting to add a snapshot before a schema is added" );
1430- ICEBERG_PRECHECK (!metadata_.partition_specs .empty (),
1431- " Attempting to add a snapshot before a partition spec is added" );
1432- ICEBERG_PRECHECK (!metadata_.sort_orders .empty (),
1433- " Attempting to add a snapshot before a sort order is added" );
1434-
1435- // Check if snapshot already exists
1436- int64_t snapshot_id = snapshot->snapshot_id ;
1437- auto existing_snapshot =
1438- std::ranges::find_if (metadata_.snapshots , [snapshot_id](const auto & s) {
1439- return s != nullptr && s->snapshot_id == snapshot_id;
1440- });
1441- ICEBERG_PRECHECK (existing_snapshot == metadata_.snapshots .end (),
1442- " Snapshot already exists for id: {}" , snapshot_id);
1443-
1444- // Validate sequence number
1445- ICEBERG_PRECHECK (
1446- metadata_.format_version == 1 ||
1447- snapshot->sequence_number > metadata_.last_sequence_number ||
1448- !snapshot->parent_snapshot_id .has_value (),
1449- " Cannot add snapshot with sequence number {} older than last sequence number {}" ,
1450- snapshot->sequence_number , metadata_.last_sequence_number );
1451-
1452- // Update metadata
1453- metadata_.last_updated_ms = snapshot->timestamp_ms ;
1454- metadata_.last_sequence_number = snapshot->sequence_number ;
1455- metadata_.snapshots .push_back (snapshot);
1456- changes_.push_back (std::make_unique<table::AddSnapshot>(snapshot));
1457-
1458- // TODO(xiao.dong) Handle row lineage for format version >= 3
1459- return {};
1460- }
1461-
14621357Status TableMetadataBuilder::Impl::RemoveSnapshots (
14631358 const std::vector<int64_t >& snapshot_ids) {
14641359 if (snapshot_ids.empty ()) {
0 commit comments