You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by at...@apache.org on 2026/07/10 15:21:00 UTC
(iceberg-go) branch main updated: fix(metadata): validate v3 snapshot sequence numbers (#1394)
This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 90c310dd fix(metadata): validate v3 snapshot sequence numbers (#1394)
90c310dd is described below
commit 90c310ddbb05e6c11b8921101bb831f14dd227f8
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Fri Jul 10 17:20:54 2026 +0200
fix(metadata): validate v3 snapshot sequence numbers (#1394)
## Summary
- In `MetadataBuilder.addSnapshotInternal`, sequence-number monotonicity
validation now applies for format versions **>= 2** (not only `== 2`).
- This closes the v3 gap where a later snapshot with a non-increasing
sequence number could be accepted.
- Adds regression coverage with `TestV3SequenceNumberCannotDecrease`.
## Testing
- `go test ./table -run
'TestV2SequenceNumberCannotDecrease|TestV3SequenceNumberCannotDecrease'
-count=1`
- `go test ./table -run 'Test.*Snapshot' -count=1`
- `go test ./table -count=1`
---
table/metadata.go | 2 +-
table/metadata_builder_internal_test.go | 41 +++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/table/metadata.go b/table/metadata.go
index 1dac37cb..dee1259b 100644
--- a/table/metadata.go
+++ b/table/metadata.go
@@ -507,7 +507,7 @@ func (b *MetadataBuilder) addSnapshotInternal(snapshot *Snapshot, preserveUpdate
return errors.New("can't add snapshot with no added partition specs")
} else if s, _ := b.SnapshotByID(snapshot.SnapshotID); s != nil {
return fmt.Errorf("can't add snapshot with id %d, already exists", snapshot.SnapshotID)
- } else if b.formatVersion == 2 &&
+ } else if b.formatVersion >= 2 &&
snapshot.ParentSnapshotID != nil &&
snapshot.SequenceNumber <= *b.lastSequenceNumber {
return fmt.Errorf("can't add snapshot with sequence number %d, must be > than last sequence number %d",
diff --git a/table/metadata_builder_internal_test.go b/table/metadata_builder_internal_test.go
index 81400ac3..6cf54628 100644
--- a/table/metadata_builder_internal_test.go
+++ b/table/metadata_builder_internal_test.go
@@ -923,6 +923,47 @@ func TestV2SequenceNumberCannotDecrease(t *testing.T) {
require.ErrorContains(t, err, "can't add snapshot with sequence number 0, must be > than last sequence number 1")
}
+func TestV3SequenceNumberCannotDecrease(t *testing.T) {
+ builder := builderWithoutChanges(3)
+ schemaID := 0
+ firstRowID1 := int64(0)
+ addedRows := int64(10)
+
+ snapshot1 := Snapshot{
+ SnapshotID: 1,
+ ParentSnapshotID: nil,
+ SequenceNumber: 0,
+ TimestampMs: builder.base.LastUpdatedMillis() + 1,
+ ManifestList: "/snap-1.avro",
+ Summary: &Summary{Operation: OpAppend},
+ SchemaID: &schemaID,
+ FirstRowID: &firstRowID1,
+ AddedRows: &addedRows,
+ }
+
+ require.NoError(t, builder.AddSnapshot(&snapshot1))
+
+ firstRowID2 := int64(10)
+ parentSnapshotID := int64(1)
+ snapshot2 := Snapshot{
+ SnapshotID: 2,
+ ParentSnapshotID: &parentSnapshotID,
+ SequenceNumber: 0,
+ TimestampMs: builder.lastUpdatedMS + 1,
+ ManifestList: "/snap-0.avro",
+ Summary: &Summary{
+ Operation: OpAppend,
+ Properties: map[string]string{},
+ },
+ SchemaID: &schemaID,
+ FirstRowID: &firstRowID2,
+ AddedRows: &addedRows,
+ }
+
+ err := builder.AddSnapshot(&snapshot2)
+ require.ErrorContains(t, err, "can't add snapshot with sequence number 0, must be > than last sequence number 0")
+}
+
func TestCannotAddDuplicateSnapshotID(t *testing.T) {
builder := builderWithoutChanges(2)
schemaID := 0