felipecrv commented on code in PR #41335:
URL: https://github.com/apache/arrow/pull/41335#discussion_r1576629308
##########
cpp/src/arrow/acero/query_context.cc:
##########
@@ -23,6 +23,36 @@ namespace arrow {
using arrow::internal::CpuInfo;
namespace acero {
+namespace internal {
+
+int64_t GetTempStackSizeFromEnvVar() {
+ auto maybe_env_value = arrow::internal::GetEnvVar(kTempStackSizeEnvVar);
+ if (!maybe_env_value.ok()) {
+ return kDefaultTempStackSize;
+ }
+ auto env_value = *std::move(maybe_env_value);
Review Comment:
Being explicit about the type here would be helpful:
```cpp
std::string env_value = std::move(maybe_env_value).ValueUnsafe();
```
##########
cpp/src/arrow/acero/query_context.cc:
##########
@@ -23,6 +23,36 @@ namespace arrow {
using arrow::internal::CpuInfo;
namespace acero {
+namespace internal {
+
+int64_t GetTempStackSizeFromEnvVar() {
+ auto maybe_env_value = arrow::internal::GetEnvVar(kTempStackSizeEnvVar);
+ if (!maybe_env_value.ok()) {
+ return kDefaultTempStackSize;
+ }
+ auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return kDefaultTempStackSize;
+ }
+
+ int64_t temp_stack_size = 0;
+ size_t length = 0;
+ bool exception = false;
+ try {
+ temp_stack_size = std::stoll(env_value.c_str(), &length);
+ } catch (const std::exception&) {
+ exception = true;
+ }
+ if (length != env_value.length() || exception || temp_stack_size <= 0) {
Review Comment:
The minimum valid `temp_stack_size` should be greater than `0` to prevent
someone that can control env vars from forcing a very small temp stack size.
##########
cpp/src/arrow/acero/query_context.cc:
##########
@@ -51,9 +81,9 @@ size_t QueryContext::GetThreadIndex() { return
thread_indexer_(); }
size_t QueryContext::max_concurrency() const { return
thread_indexer_.Capacity(); }
Result<util::TempVectorStack*> QueryContext::GetTempStack(size_t thread_index)
{
+ static const int64_t temp_stack_size =
internal::GetTempStackSizeFromEnvVar();
if (!tld_[thread_index].is_init) {
Review Comment:
Please move the `static` to the `if (...) {` block so that code doesn't have
to always atomically call `GetTempStackSizeFromEnvVar`.
And use `ARROW_PREDIC_FALSE` on the `if` so that the compiler doesn't inline
`GetTempStackSizeFromEnvVar` (cold code) keeping this function small in the
binary.
##########
cpp/src/arrow/acero/query_context.cc:
##########
@@ -23,6 +23,36 @@ namespace arrow {
using arrow::internal::CpuInfo;
namespace acero {
+namespace internal {
+
+int64_t GetTempStackSizeFromEnvVar() {
+ auto maybe_env_value = arrow::internal::GetEnvVar(kTempStackSizeEnvVar);
+ if (!maybe_env_value.ok()) {
+ return kDefaultTempStackSize;
+ }
+ auto env_value = *std::move(maybe_env_value);
+ if (env_value.empty()) {
+ return kDefaultTempStackSize;
+ }
+
+ int64_t temp_stack_size = 0;
+ size_t length = 0;
+ bool exception = false;
+ try {
+ temp_stack_size = std::stoll(env_value.c_str(), &length);
+ } catch (const std::exception&) {
+ exception = true;
+ }
+ if (length != env_value.length() || exception || temp_stack_size <= 0) {
+ ARROW_LOG(WARNING) << "Invalid temp stack size provided in " <<
kTempStackSizeEnvVar
+ << ". Using default temp stack size: " <<
kDefaultTempStackSize;
+ return kDefaultTempStackSize;
+ }
+ return temp_stack_size;
Review Comment:
You probably want to limit it to some safe upper-bound here
`return std::min(temp_stack_size, kMaxTempStackSize);`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]