laskoviymishka commented on code in PR #2611:
URL: https://github.com/apache/iceberg-go/pull/2611#discussion_r4580414382


##########
catalog/hadoop/hadoop_context_test.go:
##########
@@ -143,11 +167,6 @@ func TestNewCatalogFilesystemContextLifetime(t *testing.T) 
{
                        require.ErrorIs(t, err, context.Canceled)
                        _, err = cat.ListNamespaces(canceledOperationCtx, 
table.Identifier{"ns"})
                        require.ErrorIs(t, err, context.Canceled)

Review Comment:
   Could we keep the cancelled `CreateNamespace` check that was here? It's the 
only test that a cancelled `CreateNamespace` returns `context.Canceled` and 
creates nothing ([base 
L146-150](https://github.com/apache/iceberg-go/blob/dc09cf00fcdd59caca9d98421693423608d17111/catalog/hadoop/hadoop_context_test.go#L146-L150)).
 As I read it, it still passes at head, since `checkedMkdirAll` hits the fake's 
`Stat` first and that returns `ctx.Err()` ([namespaces.go 
L227-247](https://github.com/apache/iceberg-go/blob/f3d317c48b5bb7fc5a36ce5e2ee740057291a9a2/catalog/hadoop/namespaces.go#L227-L247)).



##########
catalog/hadoop/hadoop_context_test.go:
##########
@@ -160,6 +179,43 @@ func TestNewCatalogFilesystemContextLifetime(t *testing.T) 
{
        }
 }
 
+func TestHadoopCatalogDirectoryOperationsUseOperationContext(t *testing.T) {
+       cat, err := NewCatalog(context.Background(), "test", 
filepath.Join(t.TempDir(), "warehouse"), nil)
+       require.NoError(t, err)
+
+       filesystem := &directoryContextHadoopFS{HadoopCatalogFS: cat.filesystem}
+       cat.filesystem = filesystem
+       operationContext := func(value string) context.Context {
+               return context.WithValue(context.Background(), 
hadoopContextKey{}, value)
+       }
+
+       require.NoError(t, 
cat.CreateNamespace(operationContext("CreateNamespace"), 
table.Identifier{"ns"}, nil))
+       requireLastDirectoryContextValue(t, filesystem.mkdirAllValues, 
"CreateNamespace")
+
+       schema := iceberg.NewSchema(1, iceberg.NestedField{
+               ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int32, 
Required: true,
+       })
+       dropIdent := table.Identifier{"ns", "drop"}
+       dropTable, err := cat.CreateTable(operationContext("CreateTable"), 
dropIdent, schema)
+       require.NoError(t, err)
+       requireLastDirectoryContextValue(t, filesystem.mkdirAllValues, 
"CreateTable")
+
+       _, _, err = cat.CommitTable(operationContext("CommitTable"), dropIdent,
+               
[]table.Requirement{table.AssertTableUUID(dropTable.Metadata().TableUUID())},
+               
[]table.Update{table.NewSetPropertiesUpdate(iceberg.Properties{"context-test": 
"committed"})})
+       require.NoError(t, err)
+       requireLastDirectoryContextValue(t, filesystem.mkdirAllValues, 
"CommitTable")
+
+       require.NoError(t, cat.DropTable(operationContext("DropTable"), 
dropIdent))
+       requireLastDirectoryContextValue(t, filesystem.removeAllValues, 
"DropTable")
+
+       purgeIdent := table.Identifier{"ns", "purge"}
+       _, err = cat.CreateTable(operationContext("CreateTable for 
PurgeTable"), purgeIdent, schema)
+       require.NoError(t, err)
+       require.NoError(t, cat.PurgeTable(operationContext("PurgeTable"), 
purgeIdent))
+       requireLastDirectoryContextValue(t, filesystem.removeAllValues, 
"PurgeTable")

Review Comment:
   Could this also cover a table with `gc.enabled=false`? That branch calls 
`RemoveAll(ctx, c.metadataDir(identifier))` ([tables.go 
L459-463](https://github.com/apache/iceberg-go/blob/f3d317c48b5bb7fc5a36ce5e2ee740057291a9a2/catalog/hadoop/tables.go#L459-L463)),
 and its only test, `TestPurgeTableGCDisabledPreservesData`, passes 
`context.Background()`, so dropping `ctx` there wouldn't fail anything.



##########
io/io.go:
##########
@@ -223,7 +223,9 @@ type RenameNoReplaceIO interface {
 type RemoveAllIO interface {
        IO
 
-       RemoveAll(name string) error
+       // RemoveAll removes the named path and any children recursively. The 
context
+       // controls the operation where the implementation supports 
cancellation.

Review Comment:
   Should the contract say what a cancelled `RemoveAll` leaves behind? blobfs 
deletes the key and then checks ctx per child, so cancelling mid-walk returns 
with part of the tree gone ([blob.go 
L815-856](https://github.com/apache/iceberg-go/blob/f3d317c48b5bb7fc5a36ce5e2ee740057291a9a2/io/gocloud/blobfs/blob.go#L815-L856)).
 `LocalFS` returns a bare `ctx.Err()` and blobfs wraps it in `*fs.PathError`, 
so `errors.Is` is the safe check:
   
   ```suggestion
        // controls the operation where the implementation supports 
cancellation.
        // A canceled RemoveAll may leave the tree partially removed. The 
returned
        // error is or wraps ctx.Err(), so check it with errors.Is.
   ```



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