Skip to content

GH-51816: [GLib] Add filesystem GType registration mechanism - #55464

Merged
kou merged 7 commits into
apache:mainfrom
alytantawyy:fix-glib-filesystem-gtype-registration
Nov 24, 2026
Merged

kou merged 7 commits into
apache:mainfrom
alytantawyy:fix-glib-filesystem-gtype-registration

Conversation

@alytantawyy

@alytantawyy alytantawyy commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Provide filesystem wrapper registration so separately packaged bindings can supply their own GLib types. This prepares for the S3 GLib bindings split in #51608.

Closes #51816.

What changes are included in this PR?

  • Add garrow_file_system_register_type() backed by GIO's arrow-file-system extension point.
  • Select registered filesystem wrappers through GIO while preserving the built-in mappings.
  • Validate names and concrete wrapper types, and reject duplicate names and wrapper aliases.
  • Document initialization-only registration, including direct GIO registration and registrations triggered by module loading.
  • Add Ruby regression tests for registration and validation.

Are these changes tested?

Verified locally on macOS arm64:

  • 84 Ruby filesystem tests passed; 12 optional Dataset tests were omitted because Arrow Dataset was unavailable.
  • Build, formatting, and all applicable pre-commit checks passed.

These are local results for commit a75348d944. GitHub CI results are reported separately in the PR checks.

Are there any user-facing changes?

Adds a filesystem type-registration API. Each wrapper type has one registration name within the extension point. GArrowFileSystem remains abstract; changes to unknown-filesystem handling are deferred.

Registration must finish sequentially during initialization, before concurrent filesystem wrapper lookups begin. This requirement also applies to direct GIO registration and registrations triggered by GIO module loading. Concurrent registration is not supported.

Moving the S3 bindings into a separate library is outside this PR's scope.

Was AI used for this PR?

Codex generated the implementation and tests and helped draft this description.

I personally reviewed the full implementation and tests.

Comment thread c_glib/arrow-glib/file-system.cpp Outdated
Comment on lines +552 to +563
struct GArrowFileSystemTypeRegistry
{
std::mutex mutex;
std::unordered_map<std::string, GType> types = {
{"local", GARROW_TYPE_LOCAL_FILE_SYSTEM},
{"hdfs", GARROW_TYPE_HDFS_FILE_SYSTEM},
{"s3", GARROW_TYPE_S3_FILE_SYSTEM},
{"gcs", GARROW_TYPE_GCS_FILE_SYSTEM},
{"abfs", GARROW_TYPE_AZURE_FILE_SYSTEM},
{"mock", GARROW_TYPE_MOCK_FILE_SYSTEM},
};
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using GIOExtensionPoint instead?
https://docs.gtk.org/gio/struct.IOExtensionPoint.html

If you aren't familiar with GIOExtensionPoint, I can push some commits to this branch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kou Addressed. Please check

@kou

kou commented Nov 13, 2026

Copy link
Copy Markdown
Member

BTW, we don't need no human reviewed PR.
Read https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code carefully.

If you use only AI, I'll open a separated PR for the issue.

@alytantawyy

Copy link
Copy Markdown
Contributor Author

separated

@kou the code was fully reviewed and design was implemented by me - just the wording in the PR description and code syntax was by AI - I updated the description apologies for the confusion

@kou

kou commented Nov 15, 2026

Copy link
Copy Markdown
Member

OK. Could you explain the following?

  1. Why don't we need a mutex for garrow_file_system_get_extension_point()?
  2. Why do we need GRecMutex instead of GMutex for garrow_file_system_register_type()?
  3. Is this still thread-safe with "registration directly through GIO"?

@alytantawyy

Copy link
Copy Markdown
Contributor Author

OK. Could you explain the following?

  1. Why don't we need a mutex for garrow_file_system_get_extension_point()?
  2. Why do we need GRecMutex instead of GMutex for garrow_file_system_register_type()?
  3. Is this still thread-safe with "registration directly through GIO"?

Thanks for your questions @kou , I looked into GIO's implementation and here's what I found:

1- garrow_file_system_get_extension_point() uses a function local static variable where its initialization is thread safe in C++11 and later - this ensures that the initialization lambda runs only once even when multiple threads call it concurrently. That's why a mutex isn't needed.

2- I used GRecMutex to account for potential reentrant registration during GIO's lazy module loading - g_io_extension_point_get_extension_by_name() can trigger lazy module loading which may execute initialization code that calls garrow_file_system_register_type() again on the same thread - GMutex would cause a deadlock in this situation whereas GRecMutex allows recursive locking. I chose GRecMutex defensively in case of a possible callback.

3- For direct registration through GIO, the current implementation cannot guarantee thread safety when another module callsg_io_extension_point_implement()directly while Arrow GLib is performing a lookup - from my inspection of GIO's source code, I saw that registration modifies the extension list and lookup traverses it without shared synchronization around those operations. One thing we could do here is clarify the intended registration contract: require external file system modules to register through garrow_file_system_register_type() where thread safety is guaranteed through the mutexes we implemented. Another approach here could be to require filesystem modules to complete registration during initialization before concurrent lookups begin - this could also be documented and clarified as the intended registration contract.

Please let me know what you think the best approach is whenever you get the chance, thanks!

@alytantawyy

Copy link
Copy Markdown
Contributor Author

@kou following up

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Another approach here could be to require filesystem modules to complete registration during initialization before concurrent lookups begin - this could also be documented and clarified as the intended registration contract" is better but I want to keep garrow_file_system_register_type() for the API that is used by the initialization phase.

Comment thread c_glib/test/test-file-system.cpp Resolved
Comment thread c_glib/arrow-glib/file-system.cpp Outdated
};

G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GArrowFileSystem, garrow_file_system, G_TYPE_OBJECT)
G_DEFINE_TYPE_WITH_PRIVATE(GArrowFileSystem, garrow_file_system, G_TYPE_OBJECT)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables the generic fallback which was requested. When garrow_file_system_new_raw() encounters a fs that is not registered, it falls back to GARROW_TYPE_FILE_SYSTEM. Since GArrowFileSystem was previously abstract, I changed it to a concrete type so g_object_new() can instantiate it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. I wrote "fall back to GArrowFileSystem when none is registered" in #51608. I want to reconsider it. Reporting an error for unknown file system may be better. Could you keep "abstract" for now? We can revisit this later.

Comment thread c_glib/test/test-file-system.rb Resolved
Comment thread c_glib/test/test-file-system.rb Resolved
@alytantawyy

Copy link
Copy Markdown
Contributor Author

"Another approach here could be to require filesystem modules to complete registration during initialization before concurrent lookups begin - this could also be documented and clarified as the intended registration contract" is better but I want to keep garrow_file_system_register_type() for the API that is used by the initialization phase.

@kou I kept garrow_file_system_register_type() and documented that registration must finish sequentially during initialization, before concurrent lookups begin. This also covers direct GIO registration and module-triggered registration.

I removed the private mutex because direct GIO calls bypassed it. The function-local static still provides one-time initialization of the extension point and built-in registrations.

@alytantawyy

Copy link
Copy Markdown
Contributor Author

@kou Could you please rerun the failed Windows MinGW job? The GLib tests passed, but two Ruby Parquet tests errored with Permission denied while deleting temporary files. This looks transient and unrelated to my code changes.

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@kou

kou commented Nov 23, 2026

Copy link
Copy Markdown
Member

The failure will be fixed by #55703 .

Comment thread c_glib/test/test-file-system.rb Resolved
@alytantawyy

Copy link
Copy Markdown
Contributor Author

@kou I addressed everything - I think this is good to merge

@kou
kou merged commit bc553c3 into apache:main Nov 24, 2026
33 of 34 checks passed
@kou

kou commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GLib] Add filesystem GType registration mechanism

2 participants