You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/12/20 19:00:17 UTC

[GitHub] [arrow] pitrou opened a new pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

pitrou opened a new pull request #12001:
URL: https://github.com/apache/arrow/pull/12001


   Manage a readhead queue of ready-to-use Minio servers to avoid waiting for process launch at the start of each test.
   
   Before (time for arrow-s3fs-test):
   ```
   real	0m59,841s
   user	0m13,669s
   sys	0m2,851s
   ```
   
   After:
   ```
   real	0m6,415s
   user	0m17,433s
   sys	0m3,470s
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] lidavidm commented on a change in pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
lidavidm commented on a change in pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#discussion_r776419557



##########
File path: cpp/src/arrow/filesystem/s3_test_util.cc
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <algorithm>  // Missing include in boost/process
+#include <sstream>
+
+// This boost/asio/io_context.hpp include is needless for no MinGW
+// build.
+//
+// This is for including boost/asio/detail/socket_types.hpp before any
+// "#include <windows.h>". boost/asio/detail/socket_types.hpp doesn't
+// work if windows.h is already included. boost/process.h ->
+// boost/process/args.hpp -> boost/process/detail/basic_cmd.hpp
+// includes windows.h. boost/process/args.hpp is included before
+// boost/process/async.h that includes
+// boost/asio/detail/socket_types.hpp implicitly is included.
+#include <boost/asio/io_context.hpp>
+// We need BOOST_USE_WINDOWS_H definition with MinGW when we use
+// boost/process.hpp. See ARROW_BOOST_PROCESS_COMPILE_DEFINITIONS in
+// cpp/cmake_modules/BuildUtils.cmake for details.
+#include <boost/process.hpp>
+
+#include "arrow/filesystem/s3_test_util.h"
+#include "arrow/filesystem/s3fs.h"
+#include "arrow/util/async_generator.h"
+#include "arrow/util/future.h"
+#include "arrow/util/io_util.h"
+#include "arrow/util/thread_pool.h"
+
+namespace arrow {
+namespace fs {
+
+using ::arrow::internal::TemporaryDir;
+
+namespace bp = boost::process;
+
+namespace {
+
+const char* kMinioExecutableName = "minio";
+const char* kMinioAccessKey = "minio";
+const char* kMinioSecretKey = "miniopass";
+
+// Environment variables to configure another S3-compatible service
+const char* kEnvConnectString = "ARROW_TEST_S3_CONNECT_STRING";
+const char* kEnvAccessKey = "ARROW_TEST_S3_ACCESS_KEY";
+const char* kEnvSecretKey = "ARROW_TEST_S3_SECRET_KEY";
+
+std::string GenerateConnectString() {
+  std::stringstream ss;
+  ss << "127.0.0.1:" << GetListenPort();
+  return ss.str();
+}
+
+}  // namespace
+
+struct MinioTestServer::Impl {
+  std::unique_ptr<TemporaryDir> temp_dir_;
+  std::string connect_string_;
+  std::string access_key_ = kMinioAccessKey;
+  std::string secret_key_ = kMinioSecretKey;
+  std::shared_ptr<::boost::process::child> server_process_;
+};
+
+MinioTestServer::MinioTestServer() : impl_(new Impl) {}
+
+MinioTestServer::~MinioTestServer() {
+  auto st = Stop();
+  ARROW_UNUSED(st);
+}
+
+std::string MinioTestServer::connect_string() const { return impl_->connect_string_; }
+
+std::string MinioTestServer::access_key() const { return impl_->access_key_; }
+
+std::string MinioTestServer::secret_key() const { return impl_->secret_key_; }
+
+Status MinioTestServer::Start() {
+  const char* connect_str = std::getenv(kEnvConnectString);
+  const char* access_key = std::getenv(kEnvAccessKey);
+  const char* secret_key = std::getenv(kEnvSecretKey);
+  if (connect_str && access_key && secret_key) {
+    // Use external instance
+    impl_->connect_string_ = connect_str;
+    impl_->access_key_ = access_key;
+    impl_->secret_key_ = secret_key;
+    return Status::OK();
+  }
+
+  ARROW_ASSIGN_OR_RAISE(impl_->temp_dir_, TemporaryDir::Make("s3fs-test-"));
+
+  // Get a copy of the current environment.
+  // (NOTE: using "auto" would return a native_environment that mutates
+  //  the current environment)
+  bp::environment env = boost::this_process::environment();
+  env["MINIO_ACCESS_KEY"] = kMinioAccessKey;
+  env["MINIO_SECRET_KEY"] = kMinioSecretKey;
+
+  impl_->connect_string_ = GenerateConnectString();
+
+  auto exe_path = bp::search_path(kMinioExecutableName);
+  if (exe_path.empty()) {
+    return Status::IOError("Failed to find minio executable ('", kMinioExecutableName,
+                           "') in PATH");
+  }
+
+  try {
+    // NOTE: --quiet makes startup faster by suppressing remote version check
+    impl_->server_process_ = std::make_shared<bp::child>(
+        env, exe_path, "server", "--quiet", "--compat", "--address",
+        impl_->connect_string_, impl_->temp_dir_->path().ToString());
+  } catch (const std::exception& e) {
+    return Status::IOError("Failed to launch Minio server: ", e.what());
+  }
+  return Status::OK();
+}
+
+Status MinioTestServer::Stop() {
+  if (impl_->server_process_ && impl_->server_process_->valid()) {
+    // Brutal shutdown
+    impl_->server_process_->terminate();
+    impl_->server_process_->wait();
+  }
+  return Status::OK();
+}
+
+struct MinioTestEnvironment::Impl {
+  std::function<Future<std::shared_ptr<MinioTestServer>>()> server_generator_;
+
+  Result<std::shared_ptr<MinioTestServer>> LaunchOneServer() {
+    auto server = std::make_shared<MinioTestServer>();
+    RETURN_NOT_OK(server->Start());
+    return server;
+  }
+};
+
+MinioTestEnvironment::MinioTestEnvironment() : impl_(new Impl) {}
+
+MinioTestEnvironment::~MinioTestEnvironment() = default;
+
+void MinioTestEnvironment::SetUp() {
+  auto pool = ::arrow::internal::GetCpuThreadPool();
+
+  auto launch_one_server = []() -> Result<std::shared_ptr<MinioTestServer>> {
+    auto server = std::make_shared<MinioTestServer>();
+    RETURN_NOT_OK(server->Start());
+    return server;
+  };
+  impl_->server_generator_ = [pool, launch_one_server]() {
+    return DeferNotOk(pool->Submit(launch_one_server));
+  };
+  impl_->server_generator_ =
+      MakeReadaheadGenerator(std::move(impl_->server_generator_), pool->GetCapacity());

Review comment:
       Would a fixed readahead level be better? On my system for instance I think this would instantly spawn 18 minio instances…Though maybe that's fine since we need an instance per test.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#issuecomment-998189914


   https://issues.apache.org/jira/browse/ARROW-15136


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot commented on pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
ursabot commented on pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#issuecomment-1002733635


   Benchmark runs are scheduled for baseline = bf7636e1cbd35fdf4c638776366e113cf82f9081 and contender = f5ab8833867cb456190d656300cbbb2f7724563e. f5ab8833867cb456190d656300cbbb2f7724563e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Scheduled] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/c33b656f038344828efb0aceceee5209...c08618e598874d00998fe6d9a8c30279/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/d8d159b81ba1498aa6e7c84c2148e5d9...309f2f3bd55e486f81ef67c191b6b8e3/)
   [Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/ec66f356df61461b801dba6872cd6d70...73a82fc54583447d8c5f325e6b87d3b6/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#issuecomment-1002733635


   Benchmark runs are scheduled for baseline = bf7636e1cbd35fdf4c638776366e113cf82f9081 and contender = f5ab8833867cb456190d656300cbbb2f7724563e. f5ab8833867cb456190d656300cbbb2f7724563e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/c33b656f038344828efb0aceceee5209...c08618e598874d00998fe6d9a8c30279/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/d8d159b81ba1498aa6e7c84c2148e5d9...309f2f3bd55e486f81ef67c191b6b8e3/)
   [Failed :arrow_down:0.22% :arrow_up:0.04%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/ec66f356df61461b801dba6872cd6d70...73a82fc54583447d8c5f325e6b87d3b6/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] lidavidm closed pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
lidavidm closed pull request #12001:
URL: https://github.com/apache/arrow/pull/12001


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#issuecomment-1002733635


   Benchmark runs are scheduled for baseline = bf7636e1cbd35fdf4c638776366e113cf82f9081 and contender = f5ab8833867cb456190d656300cbbb2f7724563e. f5ab8833867cb456190d656300cbbb2f7724563e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/c33b656f038344828efb0aceceee5209...c08618e598874d00998fe6d9a8c30279/)
   [Failed :arrow_down:0.0% :arrow_up:0.0%] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/d8d159b81ba1498aa6e7c84c2148e5d9...309f2f3bd55e486f81ef67c191b6b8e3/)
   [Failed :arrow_down:0.22% :arrow_up:0.04%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/ec66f356df61461b801dba6872cd6d70...73a82fc54583447d8c5f325e6b87d3b6/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou commented on a change in pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#discussion_r776426805



##########
File path: cpp/src/arrow/filesystem/s3_test_util.cc
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <algorithm>  // Missing include in boost/process
+#include <sstream>
+
+// This boost/asio/io_context.hpp include is needless for no MinGW
+// build.
+//
+// This is for including boost/asio/detail/socket_types.hpp before any
+// "#include <windows.h>". boost/asio/detail/socket_types.hpp doesn't
+// work if windows.h is already included. boost/process.h ->
+// boost/process/args.hpp -> boost/process/detail/basic_cmd.hpp
+// includes windows.h. boost/process/args.hpp is included before
+// boost/process/async.h that includes
+// boost/asio/detail/socket_types.hpp implicitly is included.
+#include <boost/asio/io_context.hpp>
+// We need BOOST_USE_WINDOWS_H definition with MinGW when we use
+// boost/process.hpp. See ARROW_BOOST_PROCESS_COMPILE_DEFINITIONS in
+// cpp/cmake_modules/BuildUtils.cmake for details.
+#include <boost/process.hpp>
+
+#include "arrow/filesystem/s3_test_util.h"
+#include "arrow/filesystem/s3fs.h"
+#include "arrow/util/async_generator.h"
+#include "arrow/util/future.h"
+#include "arrow/util/io_util.h"
+#include "arrow/util/thread_pool.h"
+
+namespace arrow {
+namespace fs {
+
+using ::arrow::internal::TemporaryDir;
+
+namespace bp = boost::process;
+
+namespace {
+
+const char* kMinioExecutableName = "minio";
+const char* kMinioAccessKey = "minio";
+const char* kMinioSecretKey = "miniopass";
+
+// Environment variables to configure another S3-compatible service
+const char* kEnvConnectString = "ARROW_TEST_S3_CONNECT_STRING";
+const char* kEnvAccessKey = "ARROW_TEST_S3_ACCESS_KEY";
+const char* kEnvSecretKey = "ARROW_TEST_S3_SECRET_KEY";
+
+std::string GenerateConnectString() {
+  std::stringstream ss;
+  ss << "127.0.0.1:" << GetListenPort();
+  return ss.str();
+}
+
+}  // namespace
+
+struct MinioTestServer::Impl {
+  std::unique_ptr<TemporaryDir> temp_dir_;
+  std::string connect_string_;
+  std::string access_key_ = kMinioAccessKey;
+  std::string secret_key_ = kMinioSecretKey;
+  std::shared_ptr<::boost::process::child> server_process_;
+};
+
+MinioTestServer::MinioTestServer() : impl_(new Impl) {}
+
+MinioTestServer::~MinioTestServer() {
+  auto st = Stop();
+  ARROW_UNUSED(st);
+}
+
+std::string MinioTestServer::connect_string() const { return impl_->connect_string_; }
+
+std::string MinioTestServer::access_key() const { return impl_->access_key_; }
+
+std::string MinioTestServer::secret_key() const { return impl_->secret_key_; }
+
+Status MinioTestServer::Start() {
+  const char* connect_str = std::getenv(kEnvConnectString);
+  const char* access_key = std::getenv(kEnvAccessKey);
+  const char* secret_key = std::getenv(kEnvSecretKey);
+  if (connect_str && access_key && secret_key) {
+    // Use external instance
+    impl_->connect_string_ = connect_str;
+    impl_->access_key_ = access_key;
+    impl_->secret_key_ = secret_key;
+    return Status::OK();
+  }
+
+  ARROW_ASSIGN_OR_RAISE(impl_->temp_dir_, TemporaryDir::Make("s3fs-test-"));
+
+  // Get a copy of the current environment.
+  // (NOTE: using "auto" would return a native_environment that mutates
+  //  the current environment)
+  bp::environment env = boost::this_process::environment();
+  env["MINIO_ACCESS_KEY"] = kMinioAccessKey;
+  env["MINIO_SECRET_KEY"] = kMinioSecretKey;
+
+  impl_->connect_string_ = GenerateConnectString();
+
+  auto exe_path = bp::search_path(kMinioExecutableName);
+  if (exe_path.empty()) {
+    return Status::IOError("Failed to find minio executable ('", kMinioExecutableName,
+                           "') in PATH");
+  }
+
+  try {
+    // NOTE: --quiet makes startup faster by suppressing remote version check
+    impl_->server_process_ = std::make_shared<bp::child>(
+        env, exe_path, "server", "--quiet", "--compat", "--address",
+        impl_->connect_string_, impl_->temp_dir_->path().ToString());
+  } catch (const std::exception& e) {
+    return Status::IOError("Failed to launch Minio server: ", e.what());
+  }
+  return Status::OK();
+}
+
+Status MinioTestServer::Stop() {
+  if (impl_->server_process_ && impl_->server_process_->valid()) {
+    // Brutal shutdown
+    impl_->server_process_->terminate();
+    impl_->server_process_->wait();
+  }
+  return Status::OK();
+}
+
+struct MinioTestEnvironment::Impl {
+  std::function<Future<std::shared_ptr<MinioTestServer>>()> server_generator_;
+
+  Result<std::shared_ptr<MinioTestServer>> LaunchOneServer() {
+    auto server = std::make_shared<MinioTestServer>();
+    RETURN_NOT_OK(server->Start());
+    return server;
+  }
+};
+
+MinioTestEnvironment::MinioTestEnvironment() : impl_(new Impl) {}
+
+MinioTestEnvironment::~MinioTestEnvironment() = default;
+
+void MinioTestEnvironment::SetUp() {
+  auto pool = ::arrow::internal::GetCpuThreadPool();
+
+  auto launch_one_server = []() -> Result<std::shared_ptr<MinioTestServer>> {
+    auto server = std::make_shared<MinioTestServer>();
+    RETURN_NOT_OK(server->Start());
+    return server;
+  };
+  impl_->server_generator_ = [pool, launch_one_server]() {
+    return DeferNotOk(pool->Submit(launch_one_server));
+  };
+  impl_->server_generator_ =
+      MakeReadaheadGenerator(std::move(impl_->server_generator_), pool->GetCapacity());

Review comment:
       On my system it spawns 24 of them :-)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#issuecomment-1002733635


   Benchmark runs are scheduled for baseline = bf7636e1cbd35fdf4c638776366e113cf82f9081 and contender = f5ab8833867cb456190d656300cbbb2f7724563e. f5ab8833867cb456190d656300cbbb2f7724563e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/c33b656f038344828efb0aceceee5209...c08618e598874d00998fe6d9a8c30279/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/d8d159b81ba1498aa6e7c84c2148e5d9...309f2f3bd55e486f81ef67c191b6b8e3/)
   [Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/ec66f356df61461b801dba6872cd6d70...73a82fc54583447d8c5f325e6b87d3b6/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou commented on a change in pull request #12001: ARROW-15136: [C++] Make S3FS tests faster

Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #12001:
URL: https://github.com/apache/arrow/pull/12001#discussion_r776427143



##########
File path: cpp/src/arrow/filesystem/s3_test_util.cc
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <algorithm>  // Missing include in boost/process
+#include <sstream>
+
+// This boost/asio/io_context.hpp include is needless for no MinGW
+// build.
+//
+// This is for including boost/asio/detail/socket_types.hpp before any
+// "#include <windows.h>". boost/asio/detail/socket_types.hpp doesn't
+// work if windows.h is already included. boost/process.h ->
+// boost/process/args.hpp -> boost/process/detail/basic_cmd.hpp
+// includes windows.h. boost/process/args.hpp is included before
+// boost/process/async.h that includes
+// boost/asio/detail/socket_types.hpp implicitly is included.
+#include <boost/asio/io_context.hpp>
+// We need BOOST_USE_WINDOWS_H definition with MinGW when we use
+// boost/process.hpp. See ARROW_BOOST_PROCESS_COMPILE_DEFINITIONS in
+// cpp/cmake_modules/BuildUtils.cmake for details.
+#include <boost/process.hpp>
+
+#include "arrow/filesystem/s3_test_util.h"
+#include "arrow/filesystem/s3fs.h"
+#include "arrow/util/async_generator.h"
+#include "arrow/util/future.h"
+#include "arrow/util/io_util.h"
+#include "arrow/util/thread_pool.h"
+
+namespace arrow {
+namespace fs {
+
+using ::arrow::internal::TemporaryDir;
+
+namespace bp = boost::process;
+
+namespace {
+
+const char* kMinioExecutableName = "minio";
+const char* kMinioAccessKey = "minio";
+const char* kMinioSecretKey = "miniopass";
+
+// Environment variables to configure another S3-compatible service
+const char* kEnvConnectString = "ARROW_TEST_S3_CONNECT_STRING";
+const char* kEnvAccessKey = "ARROW_TEST_S3_ACCESS_KEY";
+const char* kEnvSecretKey = "ARROW_TEST_S3_SECRET_KEY";
+
+std::string GenerateConnectString() {
+  std::stringstream ss;
+  ss << "127.0.0.1:" << GetListenPort();
+  return ss.str();
+}
+
+}  // namespace
+
+struct MinioTestServer::Impl {
+  std::unique_ptr<TemporaryDir> temp_dir_;
+  std::string connect_string_;
+  std::string access_key_ = kMinioAccessKey;
+  std::string secret_key_ = kMinioSecretKey;
+  std::shared_ptr<::boost::process::child> server_process_;
+};
+
+MinioTestServer::MinioTestServer() : impl_(new Impl) {}
+
+MinioTestServer::~MinioTestServer() {
+  auto st = Stop();
+  ARROW_UNUSED(st);
+}
+
+std::string MinioTestServer::connect_string() const { return impl_->connect_string_; }
+
+std::string MinioTestServer::access_key() const { return impl_->access_key_; }
+
+std::string MinioTestServer::secret_key() const { return impl_->secret_key_; }
+
+Status MinioTestServer::Start() {
+  const char* connect_str = std::getenv(kEnvConnectString);
+  const char* access_key = std::getenv(kEnvAccessKey);
+  const char* secret_key = std::getenv(kEnvSecretKey);
+  if (connect_str && access_key && secret_key) {
+    // Use external instance
+    impl_->connect_string_ = connect_str;
+    impl_->access_key_ = access_key;
+    impl_->secret_key_ = secret_key;
+    return Status::OK();
+  }
+
+  ARROW_ASSIGN_OR_RAISE(impl_->temp_dir_, TemporaryDir::Make("s3fs-test-"));
+
+  // Get a copy of the current environment.
+  // (NOTE: using "auto" would return a native_environment that mutates
+  //  the current environment)
+  bp::environment env = boost::this_process::environment();
+  env["MINIO_ACCESS_KEY"] = kMinioAccessKey;
+  env["MINIO_SECRET_KEY"] = kMinioSecretKey;
+
+  impl_->connect_string_ = GenerateConnectString();
+
+  auto exe_path = bp::search_path(kMinioExecutableName);
+  if (exe_path.empty()) {
+    return Status::IOError("Failed to find minio executable ('", kMinioExecutableName,
+                           "') in PATH");
+  }
+
+  try {
+    // NOTE: --quiet makes startup faster by suppressing remote version check
+    impl_->server_process_ = std::make_shared<bp::child>(
+        env, exe_path, "server", "--quiet", "--compat", "--address",
+        impl_->connect_string_, impl_->temp_dir_->path().ToString());
+  } catch (const std::exception& e) {
+    return Status::IOError("Failed to launch Minio server: ", e.what());
+  }
+  return Status::OK();
+}
+
+Status MinioTestServer::Stop() {
+  if (impl_->server_process_ && impl_->server_process_->valid()) {
+    // Brutal shutdown
+    impl_->server_process_->terminate();
+    impl_->server_process_->wait();
+  }
+  return Status::OK();
+}
+
+struct MinioTestEnvironment::Impl {
+  std::function<Future<std::shared_ptr<MinioTestServer>>()> server_generator_;
+
+  Result<std::shared_ptr<MinioTestServer>> LaunchOneServer() {
+    auto server = std::make_shared<MinioTestServer>();
+    RETURN_NOT_OK(server->Start());
+    return server;
+  }
+};
+
+MinioTestEnvironment::MinioTestEnvironment() : impl_(new Impl) {}
+
+MinioTestEnvironment::~MinioTestEnvironment() = default;
+
+void MinioTestEnvironment::SetUp() {
+  auto pool = ::arrow::internal::GetCpuThreadPool();
+
+  auto launch_one_server = []() -> Result<std::shared_ptr<MinioTestServer>> {
+    auto server = std::make_shared<MinioTestServer>();
+    RETURN_NOT_OK(server->Start());
+    return server;
+  };
+  impl_->server_generator_ = [pool, launch_one_server]() {
+    return DeferNotOk(pool->Submit(launch_one_server));
+  };
+  impl_->server_generator_ =
+      MakeReadaheadGenerator(std::move(impl_->server_generator_), pool->GetCapacity());

Review comment:
       So, yes, it's fine IMHO. They'll just sit waiting for requests.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org