laskoviymishka commented on code in PR #2689:
URL: https://github.com/apache/iceberg-go/pull/2689#discussion_r4692064853
##########
table/maintenance/orphan_cleanup_stale_plan_test.go:
##########
@@ -115,6 +115,57 @@ func
TestExecuteOrphanCleanupRejectsStalePlanWhenFileBecomesLive(t *testing.T) {
require.Empty(t, result.DeletedFiles)
}
+func TestOrphanCleanupRejectsRefsOnlyHistoryAfterRefresh(t *testing.T) {
+ ctx := t.Context()
+ fs := iceio.NewMemFS()
+ const location = "mem://stale-plan/refs-only"
+ const metadataLocation = location + "/metadata/v1.metadata.json"
+ const orphanPath = location + "/data/orphan.parquet"
+ meta, err := table.NewMetadata(iceberg.NewSchema(0),
iceberg.UnpartitionedSpec,
+ table.UnsortedSortOrder, location, nil)
+ require.NoError(t, err)
+ fsF := testFSF(fs)
+ catalog := &orphanCleanupTestCatalog{metadata: meta, location:
metadataLocation, fsF: fsF}
+ tbl := table.New(table.Identifier{"db", "refs_only_refresh"}, meta,
metadataLocation, fsF, catalog)
+ require.NoError(t, fs.WriteFile(ctx, orphanPath, []byte("orphan")))
+ plan, err := PlanOrphanFiles(ctx, tbl, WithCleanupFilesOlderThan(0))
+ require.NoError(t, err)
+ require.Equal(t, []string{orphanPath}, plan.Files())
+
+ for _, name := range []string{"saved plan", "before planning", "after
planning"} {
+ t.Run(name, func(t *testing.T) {
+ catalog.refsOnly = false
+ switchCatalogToRefs := func() error {
+ // The metadata location stays the same when
only the load mode changes.
+ catalog.refsOnly = true
+
+ return nil
+ }
+ catalog.beforeLoad = switchCatalogToRefs
+ if name == "after planning" {
Review Comment:
Could the test catalog count `LoadTable` calls so this case asserts the
switch lands after planning? With a second refresh added before planning in
`DeleteOrphanFiles`, all three subtests still pass, so `after planning` quietly
becomes a copy of `before planning`.
##########
table/maintenance/orphan_cleanup.go:
##########
@@ -443,17 +448,22 @@ func refreshOrphanCleanupTable(ctx context.Context, tbl
*table.Table) (*table.Ta
if err := refreshed.Refresh(ctx); err != nil {
return nil, fmt.Errorf("failed to refresh table before orphan
cleanup: %w", err)
}
- if err := validateOrphanCleanupGC(&refreshed); err != nil {
+ if err := validateOrphanCleanupTable(&refreshed); err != nil {
Review Comment:
Should this refresh go through `FullSnapshotHistoryLoader` when the caller
loaded the table with full history? `Refresh` reloads via `cat.LoadTable` in
the catalog's mode and copies the refs-only flag
([table.go#L287-L313](https://github.com/apache/iceberg-go/blob/5fb0a5dce8a2bdcd9ac8692dcf099759f004c165/table/table.go#L287-L313)).
With a refs-configured catalog and a `LoadTableWithFullSnapshotHistory` load,
plan and dry run pass, but execute and delete return `ErrInvalidOperation`
(requested modes `[all refs refs]`).
So a CLI flag alone won't unblock cleanup, and "reload with
snapshot-loading-mode=all" in the error only helps after reconfiguring the
catalog.
##########
table/table.go:
##########
@@ -215,6 +215,12 @@ func (t Table) Location() string {
return t.metadata.Locatio
func (t Table) CurrentSnapshot() *Snapshot { return
t.metadata.CurrentSnapshot() }
func (t Table) SnapshotByID(id int64) *Snapshot { return
t.metadata.SnapshotByID(id) }
func (t Table) SnapshotByName(name string) *Snapshot { return
t.metadata.SnapshotByName(name) }
+
+// SnapshotHistoryLimitedToRefs reports whether this table was loaded with only
+// snapshots directly referenced by branches and tags. Operations that depend
+// on complete snapshot history must not use a table when this returns true.
Review Comment:
This is new public API, and `PurgeFiles` in this same PR deliberately runs
on such tables, so the "must not use" rule reads stricter than the code. Could
the doc just say what the flag means?
```suggestion
// SnapshotHistoryLimitedToRefs reports whether this table was loaded with
only
// snapshots directly referenced by branches and tags, so older snapshots
may be
// missing from its metadata.
```
--
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]