-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix recursive-protection
feature flag
#13887
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,11 @@ name = "datafusion_common" | |
path = "src/lib.rs" | ||
|
||
[features] | ||
default = ["recursive-protection"] | ||
avro = ["apache-avro"] | ||
backtrace = [] | ||
pyarrow = ["pyo3", "arrow/pyarrow", "parquet"] | ||
force_hash_collisions = [] | ||
recursive-protection = ["dep:recursive"] | ||
recursive_protection = ["dep:recursive"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also renamed the feature to use an underscore ( |
||
|
||
[dependencies] | ||
ahash = { workspace = true } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ use std::sync::Arc; | |
|
||
use crate::planner::{ContextProvider, PlannerContext, SqlToRel}; | ||
|
||
use crate::stack::StackGuard; | ||
use datafusion_common::{not_impl_err, Constraints, DFSchema, Result}; | ||
use datafusion_expr::expr::Sort; | ||
use datafusion_expr::{ | ||
|
@@ -62,10 +63,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> { | |
// The functions called from `set_expr_to_plan()` need more than 128KB | ||
// stack in debug builds as investigated in: | ||
// https://github.com/apache/datafusion/pull/13310#discussion_r1836813902 | ||
let min_stack_size = recursive::get_minimum_stack_size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is pretty good evidence that the feature flag is not working as expected, as this code requires There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Late LGTM. |
||
recursive::set_minimum_stack_size(256 * 1024); | ||
let plan = self.set_expr_to_plan(other, planner_context)?; | ||
recursive::set_minimum_stack_size(min_stack_size); | ||
let plan = { | ||
// scope for dropping _guard | ||
let _guard = StackGuard::new(256 * 1024); | ||
self.set_expr_to_plan(other, planner_context) | ||
}?; | ||
let oby_exprs = to_order_by_exprs(query.order_by)?; | ||
let order_by_rex = self.order_by_to_sort_expr( | ||
oby_exprs, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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. | ||
|
||
pub use inner::StackGuard; | ||
|
||
/// A guard that sets the minimum stack size for the current thread to `min_stack_size` bytes. | ||
#[cfg(feature = "recursive_protection")] | ||
mod inner { | ||
/// Sets the stack size to `min_stack_size` bytes on call to `new()` and | ||
/// resets to the previous value when this structure is dropped. | ||
pub struct StackGuard { | ||
previous_stack_size: usize, | ||
} | ||
|
||
impl StackGuard { | ||
/// Sets the stack size to `min_stack_size` bytes on call to `new()` and | ||
/// resets to the previous value when this structure is dropped. | ||
pub fn new(min_stack_size: usize) -> Self { | ||
let previous_stack_size = recursive::get_minimum_stack_size(); | ||
recursive::set_minimum_stack_size(min_stack_size); | ||
Self { | ||
previous_stack_size, | ||
} | ||
} | ||
} | ||
|
||
impl Drop for StackGuard { | ||
fn drop(&mut self) { | ||
recursive::set_minimum_stack_size(self.previous_stack_size); | ||
} | ||
} | ||
} | ||
|
||
/// A stub implementation of the stack guard when the recursive protection | ||
/// feature is not enabled | ||
#[cfg(not(feature = "recursive_protection"))] | ||
mod inner { | ||
/// A stub implementation of the stack guard when the recursive protection | ||
/// feature is not enabled that does nothing | ||
pub struct StackGuard; | ||
|
||
impl StackGuard { | ||
/// A stub implementation of the stack guard when the recursive protection | ||
/// feature is not enabled | ||
pub fn new(_min_stack_size: usize) -> Self { | ||
Self | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having the feature enabled by default in subcrates meant I think it basically was not possible to disable when using datafusion core crate