diff --git a/cpp/include/gar/utils/filesystem.h b/cpp/include/gar/utils/filesystem.h index 5313a4dd2..a224c5f20 100644 --- a/cpp/include/gar/utils/filesystem.h +++ b/cpp/include/gar/utils/filesystem.h @@ -116,6 +116,11 @@ class FileSystem { Result GetFileNumOfDir(const std::string& dir_path, bool recursive = false) const noexcept; + /** + * Shutdown the S3 APIs if the FileSystem is for S3 job. + */ + static Status FinalizeS3(); + private: std::shared_ptr arrow_fs_; }; diff --git a/cpp/src/filesystem.cc b/cpp/src/filesystem.cc index 07b0c82ef..6240c3938 100644 --- a/cpp/src/filesystem.cc +++ b/cpp/src/filesystem.cc @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include + #include "arrow/adapters/orc/adapter.h" #include "arrow/api.h" #include "arrow/csv/api.h" @@ -296,6 +298,15 @@ Result> FileSystemFromUriOrPath( return std::make_shared(arrow_fs); } +// NB: bring by arrow 12.0.0 +// https://github.com/apache/arrow/blob/main/cpp/src/arrow/filesystem/s3fs.h#L340-L341 +Status FileSystem::FinalizeS3() { +#if defined(ARROW_VERSION) && ARROW_VERSION >= 12000000 + RETURN_NOT_ARROW_OK(arrow::fs::FinalizeS3()); +#endif + return Status::OK(); +} + /// template specialization for std::string template Result FileSystem::ReadFileToValue( const std::string&) const noexcept; diff --git a/cpp/test/test_info.cc b/cpp/test/test_info.cc index aebc31353..29cb776a0 100644 --- a/cpp/test/test_info.cc +++ b/cpp/test/test_info.cc @@ -380,4 +380,5 @@ TEST_CASE("test_graph_info_load_from_s3") { const auto& edge_infos = graph_info.GetEdgeInfos(); REQUIRE(vertex_infos.size() == 8); REQUIRE(edge_infos.size() == 23); + REQUIRE(GAR_NAMESPACE::FileSystem::FinalizeS3().ok()); }