GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

GH-38309: [C++] build filesystems as separate modules - #39067

Merged
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules
Mar 14, 2024
Merged

GH-38309: [C++] build filesystems as separate modules#39067
bkietz merged 1 commit into
apache:mainfrom
bkietz:38309-filesystem-modules

Conversation

@bkietz

@bkietzbkietz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Rationale for this change

Each filesystem implementation carries unique and potentially heavy dependencies, so it'd be useful to build them separately. Furthermore, one typically doesn't need all of them at the same time and building separate modules would allow them to be dynamically loaded as necessary. Finally, defining this interface allows custom filesystem implementations to be supported seamlessly.

What changes are included in this PR?

An initial sketch of a registry, with documentation as if the registry were complete to illustrate intended usage.

Are these changes tested?

A toy module is added and a single unit test too.

Are there any user-facing changes?

Users would be able to add their own filesystem implementations to the registry

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Dec 5, 2023
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/util/uri.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@pitrou

Copy link
Copy Markdown
Member

Ok, so I think we should provide the building blocks for lazy loading of filesystem libraries when a given URI scheme is requested. Something like:

// filesystem.{h,cc}using FileSystemFactory = std::function<
Result<std::shared_ptr<FileSystem>>(
const Uri& uri, const io::IOContext& io_context, std::string* out_path)>;
using FileSystemLoader = std::function<Status(const std::string& scheme)>;
Status RegisterFileSystemFactory(std::vector<std::string> schemes,
FileSystemFactory factory);
Status RegisterFileSystemLoader(std::vector<std::string> schemes,
FileSystemLoader loader);
Result<FileSystemLoader> MakeSharedLibraryFileSystemLoader(
std::string library_path, std::string init_function) {
using InitFuncType = Status(*)();
auto loader = [=](const std::string& scheme) -> Status {
ARROW_ASSIGN_OR_RAISE(void* ptr, SharedLibrary::LookupSymbol(library_path, init_symbol));
returnreinterpret_cast<InitFuncType>(ptr)();
};
}
Status RegisterSharedLibraryFileSystemLoader(
std::vector<std::string> schemes,
std::string library_path, std::string init_function) {
ARROW_ASSIGN_OR_RAISE(auto loader,
MakeSharedLibraryFileSystemLoader(std::move(library_path), std::move(init_function)));
returnRegisterFileSystemLoader(std::move(schemes), std::move(loader));
}
// io_util.hclassSharedLibrary {
public:static Result<SharedLibrary> Open(const std::string& path);
Result<void*> LookupSymbol(const std::string& symbol);
static Result<void*> LookupSymbol(const std::string& path, const std::string& symbol) {
ARROW_ASSIGN_OR_RAISE(auto lib, Open(path));
return lib.LookupSymbol(symbol);
}
};

And then you can use it such as:

// libarrow_s3.so
Status RegisterS3FileSystem() {
returnRegisterFileSystemFactory({"s3"}, &MakeS3FileSystem);
}
// some init code somewhere
Status InitLoadableFileSystems() {
RETURN_NOT_OK(RegisterSharedLibraryFileSystemLoader(
{"s3"}, "libarrow_s3.so", "RegisterS3FileSystem");
// other filesystems here...returnStatus::OK();
}

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

I think we should provide the building blocks for lazy loading of filesystem libraries

I don't think this presents much improvement over using direct factories. The main advantage I see with a FileSystemLoader approach is that initialization code can be run as part of loading the filesystem, including calls to EnsureS3Initialized() and dynamic loading of the library.

However EnsureS3Initialized() could equally be called by the factory, or triggered by dynamic loading at the same time as the factory is registered. As for dynamic loading itself: either the library contains one of the built-in filesystems or it is a custom implementation. For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered. For a custom filesystem libarrow.so is unaware of the name of a library containing support for custom:// uris, and can only automatically load if

  • some naming convention is adopted so that we can load libarrow_fs_custom.so
  • the name is passed explicitly to libarrow.so with SetLibraryNameForScheme(uri, libname) which is slightly more complicated than passing the name to LoadLibrary(libname)

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from fb82438 to 8bff100CompareFebruary 1, 2024 19:38
@pitrou

Copy link
Copy Markdown
Member

For the builtin S3 filesystem, it's reasonable that libarrow.so could include the string "libarrow_fs_s3.so" in order to automatically load when an s3:// uri is encountered.

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

@bkietz

bkietz commented Feb 1, 2024

Copy link
Copy Markdown
MemberAuthor

This depends on how libarrow_fs_s3.so is distributed, and which directory it is installed. It is certainly a reasonable default setting, but it can be useful to make it customizable.

I agree, but again: customization will not be resident in libarrow.so, and will require instructions like "ensure X before calling FileSystemFromUri". That being the case, I don't think any instructions could be simpler than "ensure the library is loaded before calling FileSystemFromUri".

In the specific case of a python package which renames or moves libarrow_fs_s3.so, we disable autoloading and have pyarrow/__init__.py call cffi.FFI.dlopen() with the correct path.

@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Feb 2, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

In light of the lack of an obvious approach, I think I'll defer support for autoloading for the moment. The main feature of interest is the registry anyway, and adding autoloading will not be more difficult after the registry is defined.

@kou

kou commented Feb 4, 2024

Copy link
Copy Markdown
Member

It makes sense.

@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 8bff100 to abaed2eCompareFebruary 7, 2024 19:24
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Feb 7, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from abaed2e to f95dc66CompareFebruary 8, 2024 03:01
@bkietz
bkietz marked this pull request as ready for review February 8, 2024 03:02
@github-actionsgithub-actionsBot added the awaiting changes Awaiting changes label Mar 4, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 7f9b201 to 13dfd98CompareMarch 4, 2024 22:05
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 4, 2024
kou
kou approved these changes Mar 5, 2024

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

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated

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.

Do we need std::move() here?

Suggested change
std::move(scheme), factory, std::move(finalizer),
std::move(scheme), std::move(factory), std::move(finalizer),

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We do not since the factory is currently a function pointer instead of a std::function. I guess that could be changed as well for consistency with finalizer

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, OK. I missed the FileSystemFactory definition. (I thought that it's a normal class.)
Then should we remove std::move() for factory here https://github.com/apache/arrow/pull/39067/files#diff-e487db128ea7075182ace948c56f2992b370a10b40d0bceef696becab1c9dabfR808 ?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I have changed factory to also be a std::function for consistency with finalizer, so the std::move is warranted

Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.h Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Mar 5, 2024
@bkietz
bkietzforce-pushed the 38309-filesystem-modules branch from 13dfd98 to f515a7aCompareMarch 5, 2024 15:12
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Mar 5, 2024
@bkietz

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g cpp -g r -g python -g wheel

@github-actions

Copy link
Copy Markdown

Revision: 4925905ea42d9571f65237603b0acc7547c9730f

Submitted crossbow builds: ursacomputing/crossbow @ actions-348ec81e98

TaskStatus
r-binary-packagesGitHub Actions
test-alpine-linux-cppGitHub Actions
test-build-cpp-fuzzGitHub Actions
test-conda-cppGitHub Actions
test-conda-cpp-valgrindAzure
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-cppGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-cpp-amd64GitHub Actions
test-debian-11-cpp-i386GitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-cppGitHub Actions
test-fedora-39-python-3Azure
test-fedora-r-clang-sanitizerAzure
test-r-arrow-backwards-compatibilityGitHub Actions
test-r-depsource-bundledAzure
test-r-depsource-systemGitHub Actions
test-r-dev-duckdbGitHub Actions
test-r-devdocsGitHub Actions
test-r-gcc-11GitHub Actions
test-r-gcc-12GitHub Actions
test-r-install-localGitHub Actions
test-r-install-local-minsizerelGitHub Actions
test-r-linux-as-cranGitHub Actions
test-r-linux-rchkGitHub Actions
test-r-linux-valgrindAzure
test-r-minimal-buildAzure
test-r-offline-maximalGitHub Actions
test-r-offline-minimalAzure
test-r-rhub-debian-gcc-devel-lto-latestAzure
test-r-rhub-debian-gcc-release-custom-ccacheAzure
test-r-rhub-ubuntu-gcc-release-latestAzure
test-r-rocker-r-ver-latestAzure
test-r-rstudio-r-base-4.1-opensuse153Azure
test-r-rstudio-r-base-4.2-centos7-devtoolset-8Azure
test-r-rstudio-r-base-4.2-focalAzure
test-r-ubuntu-22.04GitHub Actions
test-r-versionsGitHub Actions
test-ubuntu-20.04-cppGitHub Actions
test-ubuntu-20.04-cpp-bundledGitHub Actions
test-ubuntu-20.04-cpp-minimal-with-formatsGitHub Actions
test-ubuntu-20.04-cpp-thread-sanitizerGitHub Actions
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-cppGitHub Actions
test-ubuntu-22.04-cpp-20GitHub Actions
test-ubuntu-22.04-cpp-no-threadingGitHub Actions
test-ubuntu-22.04-python-3GitHub Actions
test-ubuntu-24.04-cppGitHub Actions
test-ubuntu-24.04-cpp-gcc-14GitHub Actions
test-ubuntu-r-sanitizerAzure
wheel-macos-big-sur-cp310-arm64GitHub Actions
wheel-macos-big-sur-cp311-arm64GitHub Actions
wheel-macos-big-sur-cp312-arm64GitHub Actions
wheel-macos-big-sur-cp38-arm64GitHub Actions
wheel-macos-big-sur-cp39-arm64GitHub Actions
wheel-macos-catalina-cp310-amd64GitHub Actions
wheel-macos-catalina-cp311-amd64GitHub Actions
wheel-macos-catalina-cp312-amd64GitHub Actions
wheel-macos-catalina-cp38-amd64GitHub Actions
wheel-macos-catalina-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp310-amd64GitHub Actions
wheel-manylinux-2-28-cp310-arm64GitHub Actions
wheel-manylinux-2-28-cp311-amd64GitHub Actions
wheel-manylinux-2-28-cp311-arm64GitHub Actions
wheel-manylinux-2-28-cp312-amd64GitHub Actions
wheel-manylinux-2-28-cp312-arm64GitHub Actions
wheel-manylinux-2-28-cp38-amd64GitHub Actions
wheel-manylinux-2-28-cp38-arm64GitHub Actions
wheel-manylinux-2-28-cp39-amd64GitHub Actions
wheel-manylinux-2-28-cp39-arm64GitHub Actions
wheel-manylinux-2014-cp310-amd64GitHub Actions
wheel-manylinux-2014-cp310-arm64GitHub Actions
wheel-manylinux-2014-cp311-amd64GitHub Actions
wheel-manylinux-2014-cp311-arm64GitHub Actions
wheel-manylinux-2014-cp312-amd64GitHub Actions
wheel-manylinux-2014-cp312-arm64GitHub Actions
wheel-manylinux-2014-cp38-amd64GitHub Actions
wheel-manylinux-2014-cp38-arm64GitHub Actions
wheel-manylinux-2014-cp39-amd64GitHub Actions
wheel-manylinux-2014-cp39-arm64GitHub Actions
wheel-windows-cp310-amd64GitHub Actions
wheel-windows-cp311-amd64GitHub Actions
wheel-windows-cp312-amd64GitHub Actions
wheel-windows-cp38-amd64GitHub Actions
wheel-windows-cp39-amd64GitHub Actions

@pitrou

Copy link
Copy Markdown
Member

The test-ubuntu-22.04-cpp-20 build failure seems unexpected. Can you perhaps try it locally and look through the build logs?

@bkietz

Copy link
Copy Markdown
MemberAuthor

The failure is in the orc external project. Since orc doesn't depend on arrow I think this must be spurious, and the retry has succeeded.

@pitroupitrou 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.

Starting to look very neat. The remaining comments are minor. Thank you!

Comment threadcpp/src/arrow/util/visibility.h Outdated
Comment threadcpp/src/arrow/testing/examplefs.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/localfs_test.cc Outdated
Comment threadcpp/src/arrow/filesystem/filesystem.cc Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
Comment threaddocs/source/cpp/io.rst Outdated
@bkietz

Copy link
Copy Markdown
MemberAuthor

Appveyor and macos failures seem unrelated.

@jorisvandenbossche

Copy link
Copy Markdown
Member

Seems this caused some nightly failures in the minimal C++ builds, see

/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::LoadDynamicLibrary(char const*) [clone .localalias]':
io_util.cc:(.text+0x56e0): undefined reference to `dlopen'
/usr/bin/ld: io_util.cc:(.text+0x5721): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libarrow.a(io_util.cc.o): in function `arrow::internal::GetSymbol(void*, char const*)':
io_util.cc:(.text+0x58c3): undefined reference to `dlsym'
/usr/bin/ld: io_util.cc:(.text+0x59c1): undefined reference to `dlerror'
collect2: error: ld returned 1 exit status

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit b235f83.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 9 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto 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.

[C++] Allow filesystems to be implemented in separate library (+ move remote filesystems out of libarrow into their own shared libraries)

5 participants

@bkietz@pitrou@kou@jorisvandenbossche@felipecrv