This is an automated email from the ASF dual-hosted git repository.

zeroshade 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 609bb66da refactor(registry): return sorted registered names (#2279)
609bb66da is described below

commit 609bb66da468cfd2664ba9e15f3ba8b7eafdbe21
Author: Minh Vu <[email protected]>
AuthorDate: Fri Oct 23 19:02:08 2026 +0200

    refactor(registry): return sorted registered names (#2279)
    
    * refactor(registry): return sorted registered names
    
    Signed-off-by: Minh Vu <[email protected]>
    
    * perf(catalog): allow concurrent registry name and factory reads
    
    ---------
    
    Signed-off-by: Minh Vu <[email protected]>
---
 catalog/registry.go      | 15 +++++++--------
 catalog/registry_test.go | 20 ++++++++++----------
 io/registry.go           |  4 ++--
 io/registry_test.go      | 44 ++++++++++++++++++++++----------------------
 4 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/catalog/registry.go b/catalog/registry.go
index e36f67b9e..1500e6516 100644
--- a/catalog/registry.go
+++ b/catalog/registry.go
@@ -33,10 +33,10 @@ import (
 type registry map[string]Registrar
 
 func (r registry) getKeys() []string {
-       regMutex.Lock()
-       defer regMutex.Unlock()
+       regMutex.RLock()
+       defer regMutex.RUnlock()
 
-       return slices.Collect(maps.Keys(r))
+       return slices.Sorted(maps.Keys(r))
 }
 
 func (r registry) set(catalogType string, reg Registrar) {
@@ -46,8 +46,8 @@ func (r registry) set(catalogType string, reg Registrar) {
 }
 
 func (r registry) get(catalogType string) (Registrar, bool) {
-       regMutex.Lock()
-       defer regMutex.Unlock()
+       regMutex.RLock()
+       defer regMutex.RUnlock()
        reg, ok := r[catalogType]
 
        return reg, ok
@@ -60,7 +60,7 @@ func (r registry) remove(catalogType string) {
 }
 
 var (
-       regMutex        sync.Mutex
+       regMutex        sync.RWMutex
        defaultRegistry = registry{}
 )
 
@@ -89,8 +89,7 @@ func Unregister(catalogType string) {
        defaultRegistry.remove(strings.ToLower(catalogType))
 }
 
-// GetRegisteredCatalogs returns the list of registered catalog names that can
-// be looked up via LoadCatalog.
+// GetRegisteredCatalogs returns the registered catalog types in sorted order.
 func GetRegisteredCatalogs() []string {
        return defaultRegistry.getKeys()
 }
diff --git a/catalog/registry_test.go b/catalog/registry_test.go
index a166e85c4..2d4b37756 100644
--- a/catalog/registry_test.go
+++ b/catalog/registry_test.go
@@ -54,11 +54,11 @@ func TestCatalogLoadTypeIsCaseInsensitive(t *testing.T) {
 
 func TestCatalogRegistry(t *testing.T) {
        ctx := context.Background()
-       assert.ElementsMatch(t, []string{
-               "rest",
+       assert.Equal(t, []string{
+               "glue",
                "http",
                "https",
-               "glue",
+               "rest",
        }, catalog.GetRegisteredCatalogs())
 
        catalog.Register("foobar", catalog.RegistrarFunc(func(ctx 
context.Context, s string, p iceberg.Properties) (catalog.Catalog, error) {
@@ -68,12 +68,12 @@ func TestCatalogRegistry(t *testing.T) {
                return nil, nil
        }))
 
-       assert.ElementsMatch(t, []string{
-               "rest",
-               "http",
+       assert.Equal(t, []string{
                "foobar",
-               "https",
                "glue",
+               "http",
+               "https",
+               "rest",
        }, catalog.GetRegisteredCatalogs())
 
        c, err := catalog.Load(ctx, "foobar", iceberg.Properties{"foo": "baz"})
@@ -107,11 +107,11 @@ func TestCatalogRegistry(t *testing.T) {
        assert.NoError(t, err)
 
        catalog.Unregister("foobar")
-       assert.ElementsMatch(t, []string{
-               "rest",
+       assert.Equal(t, []string{
+               "glue",
                "http",
                "https",
-               "glue",
+               "rest",
        }, catalog.GetRegisteredCatalogs())
 }
 
diff --git a/io/registry.go b/io/registry.go
index 465352e43..8bebcd2a2 100644
--- a/io/registry.go
+++ b/io/registry.go
@@ -60,12 +60,12 @@ func Unregister(scheme string) {
        delete(defaultRegistry, scheme)
 }
 
-// GetRegisteredSchemes returns the list of registered scheme names.
+// GetRegisteredSchemes returns registered scheme names in sorted order.
 func GetRegisteredSchemes() []string {
        regMutex.RLock()
        defer regMutex.RUnlock()
 
-       return slices.Collect(maps.Keys(defaultRegistry))
+       return slices.Sorted(maps.Keys(defaultRegistry))
 }
 
 func init() {
diff --git a/io/registry_test.go b/io/registry_test.go
index dda9aebe5..47a27c200 100644
--- a/io/registry_test.go
+++ b/io/registry_test.go
@@ -31,19 +31,19 @@ import (
 func TestIORegistry(t *testing.T) {
        ctx := context.Background()
 
-       assert.ElementsMatch(t, []string{
-               "file",
+       assert.Equal(t, []string{
                "",
+               "abfs",
+               "abfss",
+               "file",
+               "gs",
+               "mem",
+               "oss",
                "s3",
                "s3a",
                "s3n",
-               "gs",
-               "mem",
-               "abfs",
-               "abfss",
                "wasb",
                "wasbs",
-               "oss",
        }, io.GetRegisteredSchemes())
 
        customFactoryCalled := false
@@ -55,20 +55,20 @@ func TestIORegistry(t *testing.T) {
                return io.LocalFS{}, nil
        })
 
-       assert.ElementsMatch(t, []string{
-               "file",
+       assert.Equal(t, []string{
                "",
+               "abfs",
+               "abfss",
+               "custom",
+               "file",
+               "gs",
+               "mem",
+               "oss",
                "s3",
                "s3a",
                "s3n",
-               "gs",
-               "mem",
-               "abfs",
-               "abfss",
                "wasb",
                "wasbs",
-               "custom",
-               "oss",
        }, io.GetRegisteredSchemes())
 
        customIO, err := io.LoadFS(ctx, map[string]string{}, 
"custom://bucket/path")
@@ -77,19 +77,19 @@ func TestIORegistry(t *testing.T) {
        assert.True(t, customFactoryCalled)
 
        io.Unregister("custom")
-       assert.ElementsMatch(t, []string{
-               "file",
+       assert.Equal(t, []string{
                "",
+               "abfs",
+               "abfss",
+               "file",
+               "gs",
+               "mem",
+               "oss",
                "s3",
                "s3a",
                "s3n",
-               "gs",
-               "mem",
-               "abfs",
-               "abfss",
                "wasb",
                "wasbs",
-               "oss",
        }, io.GetRegisteredSchemes())
 
        _, err = io.LoadFS(ctx, map[string]string{}, "custom://bucket/path")

Reply via email to