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


##########
catalog/hadoop/options.go:
##########
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package hadoop
+
+import "github.com/apache/iceberg-go/io"
+
+type Option func(*catalogOptions)
+
+type catalogOptions struct {
+       ioRegistry *io.Registry
+}
+
+// WithIORegistry selects the FileIO factories used by this Hadoop catalog.
+// A nil registry preserves the package-level default.

Review Comment:
   Could the doc say the registry is shared, not copied? Catalogs keep the 
pointer and nothing on the option path calls `Clone()`, so a later `Register` 
or `Unregister` on a shared registry is visible to every catalog holding it 
([`io/registry.go`](https://github.com/apache/iceberg-go/blob/231bf491128479325cac50584274b9f7b29ec968/io/registry.go#L85-L118)).
 Same wording applies to the glue, hive and sql `WithIORegistry`.
   
   ```suggestion
   // A nil registry preserves the package-level default. The registry is not
   // copied, so later Register and Unregister calls are visible to this 
catalog.
   ```



##########
catalog/internal/utils.go:
##########
@@ -95,7 +95,20 @@ func UpdateTableMetadata(base table.Metadata, updates 
[]table.Update, metadataLo
 }
 
 func CreateStagedTable(ctx context.Context, catprops iceberg.Properties, 
nspropsFn GetNamespacePropsFn, ident table.Identifier, sc *iceberg.Schema, opts 
...catalog.CreateTableOpt) (table.StagedTable, error) {
-       return createStagedTable(ctx, catprops, nspropsFn, ident, "", sc, 
opts...)
+       return createStagedTable(ctx, catprops, nspropsFn, ident, "", sc, nil, 
opts...)
+}
+
+// CreateStagedTableWithRegistry creates a staged table with a catalog-scoped 
FileIO registry.
+func CreateStagedTableWithRegistry(

Review Comment:
   Could the registry be a parameter on `CreateStagedTable`, 
`CreateStagedTableWithNamespaceKey` and `UpdateAndStageTable` instead of three 
twins? After this PR the originals have no production callers ([`utils.go` 
lines 
97-142](https://github.com/apache/iceberg-go/blob/231bf491128479325cac50584274b9f7b29ec968/catalog/internal/utils.go#L97-L142),
 [lines 
313-322](https://github.com/apache/iceberg-go/blob/231bf491128479325cac50584274b9f7b29ec968/catalog/internal/utils.go#L313-L322)),
 and `UpdateAndStageTable` is only reached from `update_stage_test.go`. Since 
this is `catalog/internal` we can change the signatures freely, while twins 
double again with the next knob.



##########
catalog/sql/io_registry_test.go:
##########
@@ -0,0 +1,178 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package sql_test
+
+import (
+       "context"
+       "database/sql"
+       "net/url"
+       "path/filepath"
+       "testing"
+
+       "github.com/apache/iceberg-go"
+       sqlcat "github.com/apache/iceberg-go/catalog/sql"
+       iceio "github.com/apache/iceberg-go/io"
+       "github.com/apache/iceberg-go/table"
+       "github.com/apache/iceberg-go/view"
+       "github.com/google/uuid"
+       "github.com/stretchr/testify/require"
+       "github.com/uptrace/bun/driver/sqliteshim"
+)
+
+func TestSQLCatalogIORegistriesAreIsolated(t *testing.T) {

Review Comment:
   Could this become a table-driven helper that every catalog runs? SQL is the 
only catalog with a two-catalog, same-scheme check. The [Glue 
test](https://github.com/apache/iceberg-go/blob/231bf491128479325cac50584274b9f7b29ec968/catalog/glue/io_registry_test.go#L34-L59)
 uses one registry and only `LoadTable`, so Glue `CreateTable`, `CommitTable` 
and the S3Tables cleanup path have no registry coverage, and the hive and 
hadoop tests also use a single registry. A shared helper is what would catch a 
missed `...WithRegistry` call in the next catalog.



##########
catalog/internal/io_registry.go:
##########
@@ -0,0 +1,45 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package internal
+
+import (
+       "context"
+
+       icebergio "github.com/apache/iceberg-go/io"
+       "github.com/apache/iceberg-go/table"
+)
+
+// LoadFSWithRegistry uses the global FileIO registry when registry is nil.
+// A non-nil (including empty) registry is strictly isolated.
+func LoadFSWithRegistry(ctx context.Context, registry *icebergio.Registry, 
props map[string]string, location string) (icebergio.IO, error) {
+       if registry == nil {
+               return icebergio.LoadFS(ctx, props, location)

Review Comment:
   Should we add a guard so a new catalog path can't reach the global 
`io.LoadFS` by accident? Isolation holds today because every non-REST call site 
picks a `...WithRegistry` helper, but nothing enforces that, and 
[`.golangci.yml`](https://github.com/apache/iceberg-go/blob/231bf491128479325cac50584274b9f7b29ec968/.golangci.yml#L19-L31)
 has no forbidigo or depguard rule. A forbidigo rule on `io.LoadFS` and 
`io.LoadFSFunc` under `catalog/` that exempts this file (and REST until #2366 
lands), or a test that scans the packages, would both work.



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