timothyw553 commented on code in PR #1169:
URL: https://github.com/apache/iceberg-cpp/pull/1169#discussion_r4746291991
##########
src/iceberg/table_metadata.cc:
##########
@@ -1398,9 +1437,10 @@ Result<std::vector<SnapshotLogEntry>>
TableMetadataBuilder::Impl::UpdateSnapshot
}
Result<std::unique_ptr<TableMetadata>> TableMetadataBuilder::Impl::Build() {
- // 1. Validate the format version.
+ // 1. Validate the format version and metadata consistency.
ICEBERG_PRECHECK(TableMetadata::IsSupportedFormatVersion(metadata_.format_version),
"Unsupported table format version: {}",
metadata_.format_version);
+ ICEBERG_RETURN_UNEXPECTED(metadata_.Validate());
Review Comment:
to my understanding, `AddSnapshot()` skips the `RetryableValidationFailed`
check when `parent_snapshot_id` is absent and overwrites `last_sequence_number`
with `snapshot->sequence_number`. if another writer already advanced
`last_sequence_number`, won't `Build()` now fail permanently with
`kValidationFailed` instead of retrying (for example on `StageOnly()` or a new
branch)? should we check stale sequence numbers in `AddSnapshot()` for
parentless snapshots too, and clarify how `sequence == last` should behave for
the seq 0 init case?
##########
src/iceberg/test/metadata_serde_test.cc:
##########
@@ -499,6 +499,109 @@ TEST(MetadataSerdeTest, V3DefaultValuesRoundTrip) {
EXPECT_EQ(*reparsed, *metadata);
}
+TEST(MetadataSerdeTest, TableSequenceAndRowIdBoundsCoverRetainedSnapshots) {
+ for (const auto* resource :
+ {"TableMetadataV2ValidMinimal.json",
"TableMetadataV3ValidMinimal.json"}) {
+ SCOPED_TRACE(resource);
+ ICEBERG_UNWRAP_OR_FAIL(auto empty,
ReadTableMetadataFromResource(resource));
+ ICEBERG_UNWRAP_OR_FAIL(auto json, ToJson(*empty));
+ json["snapshots"] = nlohmann::json::parse(R"([{
+ "snapshot-id": 1, "sequence-number": 1, "timestamp-ms": 1000,
+ "manifest-list": "metadata/manifest-list.avro", "summary": {"operation":
"append"},
+ "schema-id": 0, "first-row-id": 1, "added-rows": 10
+ }])");
+ json["last-sequence-number"] = 1;
+ json["next-row-id"] = 11;
+ ICEBERG_UNWRAP_OR_FAIL(auto valid, TableMetadataFromJson(json));
+ for (const auto* field : {"last-sequence-number", "next-row-id"}) {
+ const bool is_next_row_id = std::string_view(field) == "next-row-id";
+ if (is_next_row_id && empty->format_version < 3) {
+ continue;
+ }
+ SCOPED_TRACE(field);
+ auto invalid = json;
+ invalid[field] = 0;
Review Comment:
setting this to `0` only hits the retained-snapshot comparison, not the
negative-counter checks. could we also test negative `last-sequence-number` and
`next-row-id` without snapshots (e.g. adding `int64_t{-1}` in
`TableSequenceAndRowIdBoundsRejectInvalidJsonIntegers`), plus directly
constructed snapshots with missing `added_rows` or negative row-lineage fields?
also, do we test the accepted boundaries like `first_row_id == next_row_id` and
`sequence_number == last_sequence_number` through `Build()`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]