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 12:50:36 UTC

(iceberg-go) branch main updated: fix(conflict_validation): reject invalid isolation-level values (#1398)

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 c2a07d50 fix(conflict_validation): reject invalid isolation-level values (#1398)
c2a07d50 is described below

commit c2a07d50e725b564acd0a55ecfff317dc774a04f
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Fri Jul 10 14:50:31 2026 +0200

    fix(conflict_validation): reject invalid isolation-level values (#1398)
    
    ## Summary
    - reject malformed table conflict isolation-level properties at
    validation time
    - propagate errors from overwrite/row-delta conflict checks
    - add regression tests for helper and validator error behavior
    
    ## Testing
    - go test ./table -count=1
---
 table/conflict_validation.go      | 25 ++++++++----
 table/conflict_validation_test.go | 84 ++++++++++++++++++++++++---------------
 table/producer_validate_test.go   | 72 ++++++++++++++++++++++++++++++++-
 table/row_delta.go                | 22 +++++-----
 table/snapshot_producers.go       | 13 +++---
 5 files changed, 161 insertions(+), 55 deletions(-)

diff --git a/table/conflict_validation.go b/table/conflict_validation.go
index ce091643..df56828d 100644
--- a/table/conflict_validation.go
+++ b/table/conflict_validation.go
@@ -54,6 +54,7 @@ import (
 	"slices"
 	"sort"
 	"strconv"
+	"strings"
 
 	"github.com/apache/iceberg-go"
 	iceio "github.com/apache/iceberg-go/io"
@@ -97,23 +98,31 @@ const (
 	// Older Java releases and some pyiceberg codepaths used
 	// "snapshot"; set this property explicitly to snapshot if you are
 	// migrating from a pipeline that relied on that behavior.
+	// write.merge.isolation-level is not modeled separately here yet;
+	// merge-style producers continue to use write.update.isolation-level.
 	WriteUpdateIsolationLevelKey     = "write.update.isolation-level"
 	WriteUpdateIsolationLevelDefault = IsolationSerializable
 )
 
+// ErrInvalidIsolationLevel is returned when a configured isolation level
+// value is invalid. It is terminal for the current commit attempt and does
+// not wrap ErrCommitFailed, so config errors are not retried as conflicts.
+var ErrInvalidIsolationLevel = errors.New("invalid isolation level")
+
 // readIsolationLevel returns the isolation level for the given
-// property key, falling back to defVal for a missing or unrecognized
-// value.
-func readIsolationLevel(props iceberg.Properties, key string, defVal IsolationLevel) IsolationLevel {
+// property key, falling back to defVal when the key is absent.
+func readIsolationLevel(props iceberg.Properties, key string, defVal IsolationLevel) (IsolationLevel, error) {
 	v, ok := props[key]
-	if !ok {
-		return defVal
+	if !ok || v == "" {
+		return defVal, nil
 	}
-	switch IsolationLevel(v) {
+
+	lower := IsolationLevel(strings.ToLower(v))
+	switch lower {
 	case IsolationSerializable, IsolationSnapshot:
-		return IsolationLevel(v)
+		return lower, nil
 	default:
-		return defVal
+		return defVal, fmt.Errorf("%w: %q for property %q", ErrInvalidIsolationLevel, v, key)
 	}
 }
 
diff --git a/table/conflict_validation_test.go b/table/conflict_validation_test.go
index 6a3c0bc0..915162c2 100644
--- a/table/conflict_validation_test.go
+++ b/table/conflict_validation_test.go
@@ -128,52 +128,74 @@ func runPosDeleteConflictCheck(t *testing.T, rewrittenFiles []iceberg.DataFile,
 
 func TestReadIsolationLevel(t *testing.T) {
 	tests := []struct {
-		name   string
-		props  iceberg.Properties
-		key    string
-		defVal IsolationLevel
-		want   IsolationLevel
+		name    string
+		props   iceberg.Properties
+		key     string
+		defVal  IsolationLevel
+		want    IsolationLevel
+		wantErr bool
 	}{
 		{
-			name:   "missing key falls back to default",
-			props:  iceberg.Properties{},
-			key:    WriteDeleteIsolationLevelKey,
-			defVal: IsolationSerializable,
-			want:   IsolationSerializable,
+			name:    "missing key falls back to default",
+			props:   iceberg.Properties{},
+			key:     WriteDeleteIsolationLevelKey,
+			defVal:  IsolationSerializable,
+			want:    IsolationSerializable,
+			wantErr: false,
 		},
 		{
-			name:   "explicit serializable",
-			props:  iceberg.Properties{WriteDeleteIsolationLevelKey: "serializable"},
-			key:    WriteDeleteIsolationLevelKey,
-			defVal: IsolationSnapshot,
-			want:   IsolationSerializable,
+			name:    "explicit serializable",
+			props:   iceberg.Properties{WriteDeleteIsolationLevelKey: "serializable"},
+			key:     WriteDeleteIsolationLevelKey,
+			defVal:  IsolationSnapshot,
+			want:    IsolationSerializable,
+			wantErr: false,
 		},
 		{
-			name:   "explicit snapshot",
-			props:  iceberg.Properties{WriteDeleteIsolationLevelKey: "snapshot"},
-			key:    WriteDeleteIsolationLevelKey,
-			defVal: IsolationSerializable,
-			want:   IsolationSnapshot,
+			name:    "explicit snapshot",
+			props:   iceberg.Properties{WriteDeleteIsolationLevelKey: "snapshot"},
+			key:     WriteDeleteIsolationLevelKey,
+			defVal:  IsolationSerializable,
+			want:    IsolationSnapshot,
+			wantErr: false,
 		},
 		{
-			name:   "unrecognized value falls back to default",
-			props:  iceberg.Properties{WriteDeleteIsolationLevelKey: "repeatable-read"},
-			key:    WriteDeleteIsolationLevelKey,
-			defVal: IsolationSerializable,
-			want:   IsolationSerializable,
+			name:    "explicit snapshot (mixed case)",
+			props:   iceberg.Properties{WriteDeleteIsolationLevelKey: "Snapshot"},
+			key:     WriteDeleteIsolationLevelKey,
+			defVal:  IsolationSerializable,
+			want:    IsolationSnapshot,
+			wantErr: false,
 		},
 		{
-			name:   "empty string falls back to default",
-			props:  iceberg.Properties{WriteDeleteIsolationLevelKey: ""},
-			key:    WriteDeleteIsolationLevelKey,
-			defVal: IsolationSnapshot,
-			want:   IsolationSnapshot,
+			name:    "unrecognized value returns error",
+			props:   iceberg.Properties{WriteDeleteIsolationLevelKey: "repeatable-read"},
+			key:     WriteDeleteIsolationLevelKey,
+			defVal:  IsolationSerializable,
+			want:    IsolationSerializable,
+			wantErr: true,
+		},
+		{
+			name:    "empty string falls back to default",
+			props:   iceberg.Properties{WriteDeleteIsolationLevelKey: ""},
+			key:     WriteDeleteIsolationLevelKey,
+			defVal:  IsolationSnapshot,
+			want:    IsolationSnapshot,
+			wantErr: false,
 		},
 	}
 
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			got := readIsolationLevel(tt.props, tt.key, tt.defVal)
+			got, err := readIsolationLevel(tt.props, tt.key, tt.defVal)
+			if tt.wantErr {
+				assert.ErrorIs(t, err, ErrInvalidIsolationLevel)
+				assert.Equal(t, tt.want, got)
+
+				return
+			}
+
+			assert.NoError(t, err)
 			assert.Equal(t, tt.want, got)
 		})
 	}
diff --git a/table/producer_validate_test.go b/table/producer_validate_test.go
index 7f69e9de..2d87323d 100644
--- a/table/producer_validate_test.go
+++ b/table/producer_validate_test.go
@@ -165,18 +165,53 @@ func TestOverwriteFiles_IsolationKeySplitByOp(t *testing.T) {
 		WriteUpdateIsolationLevelKey: string(IsolationSerializable),
 	}
 
+	deleteLevel, err := readIsolationLevel(props, WriteDeleteIsolationLevelKey, WriteDeleteIsolationLevelDefault)
+	require.NoError(t, err)
 	// OpDelete must resolve to the delete key (snapshot).
 	assert.Equal(t, IsolationSnapshot,
-		readIsolationLevel(props, WriteDeleteIsolationLevelKey, WriteDeleteIsolationLevelDefault),
+		deleteLevel,
 		"OpDelete path must consult write.delete.isolation-level")
 
 	// Every other op (OpOverwrite, OpReplace) must resolve to the
 	// update key (serializable).
+	updateLevel, err := readIsolationLevel(props, WriteUpdateIsolationLevelKey, WriteUpdateIsolationLevelDefault)
+	require.NoError(t, err)
 	assert.Equal(t, IsolationSerializable,
-		readIsolationLevel(props, WriteUpdateIsolationLevelKey, WriteUpdateIsolationLevelDefault),
+		updateLevel,
 		"non-delete ops must consult write.update.isolation-level")
 }
 
+// TestOverwriteFiles_ValidateInvalidIsolationLevel verifies that malformed
+// isolation settings fail the validator before conflict scanning runs.
+func TestOverwriteFiles_ValidateInvalidIsolationLevel(t *testing.T) {
+	cc := newEmptyConflictContext(t)
+	txn := newValidateTestTxn(t, iceberg.Properties{
+		WriteUpdateIsolationLevelKey: "not-a-level",
+	})
+	of := &overwriteFiles{base: &snapshotProducer{txn: txn}}
+
+	assert.ErrorIs(t, of.validate(cc), ErrInvalidIsolationLevel)
+}
+
+func TestOverwriteFiles_ValidateInvalidDeleteIsolationLevel(t *testing.T) {
+	cc := newEmptyConflictContext(t)
+	txn := newValidateTestTxn(t, iceberg.Properties{
+		WriteDeleteIsolationLevelKey: "not-a-level",
+	})
+	of := &overwriteFiles{base: &snapshotProducer{txn: txn, op: OpDelete}}
+
+	assert.ErrorIs(t, of.validate(cc), ErrInvalidIsolationLevel)
+}
+
+func TestOverwriteFiles_ValidateInvalidIsolationLevelWithNilContext(t *testing.T) {
+	txn := newValidateTestTxn(t, iceberg.Properties{
+		WriteUpdateIsolationLevelKey: "not-a-level",
+	})
+	of := &overwriteFiles{base: &snapshotProducer{txn: txn}}
+
+	assert.ErrorIs(t, of.validate(nil), ErrInvalidIsolationLevel)
+}
+
 // TestOverwriteFiles_ValidateNilContext hardens validate against a
 // nil conflictContext — callers that cannot construct cc (branch
 // missing on both sides) should still see nil rather than a crash.
@@ -223,6 +258,39 @@ func TestRowDelta_ValidateEqDeleteIsolationGates(t *testing.T) {
 	}
 }
 
+// TestRowDelta_ValidateInvalidIsolationLevel verifies malformed isolation
+// settings fail before manifest or schema checks.
+func TestRowDelta_ValidateInvalidIsolationLevel(t *testing.T) {
+	cc := newEmptyConflictContext(t)
+	eqDelete := newTestEqDeleteFile(t, "eq-1.parquet", []int{1})
+	txn := newValidateTestTxn(t, iceberg.Properties{
+		WriteDeleteIsolationLevelKey: "not-a-level",
+	})
+	rd := &RowDelta{txn: txn, delFiles: []iceberg.DataFile{eqDelete}}
+
+	assert.ErrorIs(t, rd.validate(cc), ErrInvalidIsolationLevel)
+}
+
+func TestRowDelta_ValidateInvalidIsolationLevelWithPosDeletesOnly(t *testing.T) {
+	cc := newEmptyConflictContext(t)
+	posDelete := newTestPosDeleteFile(t, "pos-1.parquet", nil)
+	txn := newValidateTestTxn(t, iceberg.Properties{
+		WriteDeleteIsolationLevelKey: "not-a-level",
+	})
+	rd := &RowDelta{txn: txn, delFiles: []iceberg.DataFile{posDelete}}
+
+	assert.ErrorIs(t, rd.validate(cc), ErrInvalidIsolationLevel)
+}
+
+func TestRowDelta_ValidateInvalidIsolationLevelWithNilContext(t *testing.T) {
+	txn := newValidateTestTxn(t, iceberg.Properties{
+		WriteDeleteIsolationLevelKey: "not-a-level",
+	})
+	rd := &RowDelta{txn: txn}
+
+	assert.ErrorIs(t, rd.validate(nil), ErrInvalidIsolationLevel)
+}
+
 func TestRewriteValidator_Smokes(t *testing.T) {
 	cc := newEmptyConflictContext(t)
 
diff --git a/table/row_delta.go b/table/row_delta.go
index d8a9236e..a13efb3f 100644
--- a/table/row_delta.go
+++ b/table/row_delta.go
@@ -200,8 +200,10 @@ func (rd *RowDelta) Commit(ctx context.Context) error {
 // Fast appends alongside a RowDelta see no validators from RowDelta:
 // data-only commits are as safe as a fastAppend.
 func (rd *RowDelta) validate(cc *conflictContext) error {
-	if cc == nil {
-		return nil
+	level, err := readIsolationLevel(rd.txn.meta.props,
+		WriteDeleteIsolationLevelKey, WriteDeleteIsolationLevelDefault)
+	if err != nil {
+		return err
 	}
 
 	// Collect every data-file path the pos-deletes in this delta
@@ -224,6 +226,10 @@ func (rd *RowDelta) validate(cc *conflictContext) error {
 		}
 	}
 
+	if cc == nil {
+		return nil
+	}
+
 	if len(referenced) > 0 {
 		if err := validateDataFilesExist(cc, referenced); err != nil {
 			return err
@@ -231,8 +237,6 @@ func (rd *RowDelta) validate(cc *conflictContext) error {
 	}
 
 	if len(eqDeleteFiles) > 0 {
-		level := readIsolationLevel(rd.txn.meta.props,
-			WriteDeleteIsolationLevelKey, WriteDeleteIsolationLevelDefault)
 		// Route through the existing validateNoConflictingDataFiles path,
 		// which calls validateAddedDataFilesMatchingFilter internally.
 		// For unpartitioned tables, use AlwaysTrue conservatively — an
@@ -245,14 +249,14 @@ func (rd *RowDelta) validate(cc *conflictContext) error {
 			return fmt.Errorf("reading current partition spec: %w", specErr)
 		}
 
-		var err error
+		var conflictErr error
 		if currentSpec == nil || currentSpec.NumFields() == 0 {
-			err = validateNoConflictingDataFiles(cc, iceberg.AlwaysTrue{}, level)
+			conflictErr = validateNoConflictingDataFiles(cc, iceberg.AlwaysTrue{}, level)
 		} else {
-			err = validateNoConflictingDataFilesInPartitions(cc, eqDeleteFiles, level)
+			conflictErr = validateNoConflictingDataFilesInPartitions(cc, eqDeleteFiles, level)
 		}
-		if err != nil {
-			return err
+		if conflictErr != nil {
+			return conflictErr
 		}
 	}
 
diff --git a/table/snapshot_producers.go b/table/snapshot_producers.go
index 66c7a941..7ca96d3c 100644
--- a/table/snapshot_producers.go
+++ b/table/snapshot_producers.go
@@ -246,10 +246,6 @@ func (of *overwriteFiles) existingManifests(parent *Snapshot) ([]iceberg.Manifes
 // are allowed. SERIALIZABLE runs validateAddedDataFilesMatchingFilter
 // against the committer's filter (AlwaysTrue when no filter is set).
 func (of *overwriteFiles) validate(cc *conflictContext) error {
-	if cc == nil || of.skipDefaultValidator {
-		return nil
-	}
-
 	// Delete operations (copy-on-write / merge-on-read deletes that
 	// run through overwriteFiles) must read write.delete.isolation-
 	// level, not write.update.isolation-level. Java's BaseDeleteFiles
@@ -259,7 +255,14 @@ func (of *overwriteFiles) validate(cc *conflictContext) error {
 	if of.base.op == OpDelete {
 		key, defVal = WriteDeleteIsolationLevelKey, WriteDeleteIsolationLevelDefault
 	}
-	if readIsolationLevel(of.base.txn.meta.props, key, defVal) != IsolationSerializable {
+	level, err := readIsolationLevel(of.base.txn.meta.props, key, defVal)
+	if err != nil {
+		return err
+	}
+	if cc == nil || of.skipDefaultValidator {
+		return nil
+	}
+	if level != IsolationSerializable {
 		// SNAPSHOT isolation allows concurrent appends into the
 		// filter region. No further checks on this path.
 		return nil