nssalian commented on code in PR #2599:
URL: https://github.com/apache/iceberg-go/pull/2599#discussion_r4604652058


##########
website/src/releases.md:
##########
@@ -42,8 +42,10 @@ Per-release notes (highlights, breaking changes, 
contributors) are published on
 
 ### Unreleased compatibility notes
 
+- **`RowDelta.Commit` can be called once per builder.** A second `Commit` on 
the same `RowDelta` now returns an error wrapping `table.ErrInvalidOperation` 
and stages nothing, even if the first call failed, as `RewriteFiles.Commit` 
does. Previously, calling `Commit` again after a failed first call could 
succeed, and calling it again after a successful one staged the builder's files 
a second time. Create a new builder with `Transaction.NewRowDelta` for each 
commit.
 - **Data-file replacements now reject concurrent deletes.** Commits staged 
through `ReplaceDataFiles`, `ReplaceDataFilesByPath`, `ReplaceFiles`, or 
rewrite operations can return `table.ErrConflictingDeleteFiles` when a 
concurrent position delete targets a replaced file or any concurrent equality 
delete is added. Compaction on tables with streaming equality deletes may see 
additional conflicts.
 - **Orphan cleanup now rejects `gc.enabled=false`.** `DeleteOrphanFiles`, 
`PlanOrphanFiles`, `ExecuteOrphanCleanup`, and dry runs now return an error 
before filesystem access. The `iceberg clean-orphan-files` command is also 
affected.
+- **Orphan cleanup requires complete snapshot history.** `DeleteOrphanFiles`, 
`PlanOrphanFiles`, and `ExecuteOrphanCleanup` now return an error when the 
table was loaded with REST `snapshot-loading-mode=refs`. Reload with 
`snapshot-loading-mode=all` before orphan cleanup. `maintenance.PurgeFiles` is 
unaffected.

Review Comment:
   the gc.enabled entry right above names dry runs and `iceberg 
clean-orphan-files`. Both hit this rejection too (the CLI calls 
`PlanOrphanFiles` before its dry-run branch in 
cmd/iceberg/clean_orphan_files.go:50), so worth naming them here as well.



##########
table/maintenance/orphan_cleanup_test.go:
##########
@@ -208,6 +213,94 @@ func TestOrphanCleanupPlanDoesNotExpandAfterPlanning(t 
*testing.T) {
        assert.NoError(t, file.Close())
 }
 
+func TestPlanOrphanFilesRejectsRefsOnlySnapshotHistory(t *testing.T) {
+       fs := iceio.NewMemFS()
+       location := "mem://refs-only/table"
+       metadataLocation := location + "/metadata/v1.metadata.json"
+
+       meta, err := table.NewMetadata(iceberg.NewSchema(0), nil, 
table.UnsortedSortOrder, location, nil)
+       require.NoError(t, err)
+       tbl := table.New(
+               []string{"db", "refs_only"},
+               meta,
+               metadataLocation,
+               func(context.Context) (iceio.IO, error) { return fs, nil },
+               nil,
+               table.WithSnapshotHistoryLimitedToRefs(true),
+       )
+
+       checks := map[string]func() error{
+               "plan": func() error {
+                       _, err := PlanOrphanFiles(context.Background(), tbl)
+
+                       return err
+               },
+               "delete": func() error {
+                       _, err := DeleteOrphanFiles(context.Background(), tbl)
+
+                       return err
+               },
+               "execute": func() error {
+                       _, err := ExecuteOrphanCleanup(context.Background(), 
tbl, OrphanCleanupPlan{})
+
+                       return err
+               },
+       }
+       for name, check := range checks {
+               t.Run(name, func(t *testing.T) {
+                       err := check()
+                       require.ErrorIs(t, err, table.ErrInvalidOperation)
+                       require.ErrorContains(t, err, 
"snapshot-loading-mode=refs")
+                       require.ErrorContains(t, err, 
"snapshot-loading-mode=all")
+               })
+       }
+}
+
+// PurgeFiles runs after catalogs have dropped a table. A refs-only load must
+// not block that cleanup: when GC is enabled the directory walk covers files
+// in the table location, while disabled GC still permits metadata removal.
+func TestPurgeFilesAllowsRefsOnlySnapshotHistory(t *testing.T) {
+       for _, tc := range []struct {
+               name       string
+               gcEnabled  string
+               removeData bool
+       }{
+               {name: "gc enabled", gcEnabled: "true", removeData: true},
+               {name: "gc disabled", gcEnabled: "false", removeData: false},
+       } {
+               t.Run(tc.name, func(t *testing.T) {
+                       ctx := t.Context()
+                       location := t.TempDir()
+                       metadataLocation := filepath.Join(location, "metadata", 
"v1.metadata.json")
+                       dataLocation := filepath.Join(location, "data", 
"part-0001.parquet")
+                       for _, filename := range []string{metadataLocation, 
dataLocation} {
+                               require.NoError(t, 
os.MkdirAll(filepath.Dir(filename), 0o755))
+                               require.NoError(t, os.WriteFile(filename, 
[]byte("test"), 0o644))
+                       }
+
+                       meta, err := table.NewMetadata(iceberg.NewSchema(0), 
nil,
+                               table.UnsortedSortOrder, location, 
iceberg.Properties{"gc.enabled": tc.gcEnabled})

Review Comment:
   `table.GCEnabledKey` instead of the "gc.enabled" literal, like the other 
tests in this package.



-- 
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]

Reply via email to