11pub mod ctx_observability;
2+ mod runner_config;
23
3- use std:: fs;
4- use std:: path:: { Path , PathBuf } ;
54use std:: sync:: {
65 Arc , Mutex , RwLock ,
76 atomic:: { AtomicU32 , Ordering } ,
87} ;
98
109use datafusion:: { common:: HashMap , prelude:: SessionContext } ;
11- use serde:: { Deserialize , Serialize } ;
1210
11+ use crate :: common:: LogicalTable ;
1312use crate :: common:: value_generator:: ValueGenerationConfig ;
14- use crate :: common:: { LogicalTable , Result , fuzzer_err} ;
1513use crate :: fuzz_runner:: FuzzerStats ;
1614
15+ pub use runner_config:: RunnerConfig ;
16+
1717/// Create a default DataFusion SessionContext with standard configuration
1818/// This ensures consistency between initial creation and reset operations
1919fn default_df_session_context ( ) -> Arc < SessionContext > {
@@ -53,8 +53,6 @@ impl GlobalContext {
5353 /// Reset the DataFusion context to drop all registered tables
5454 /// This creates a fresh SessionContext and clears all table registrations
5555 pub fn reset_datafusion_context ( & self ) {
56- use std:: sync:: atomic:: Ordering ;
57-
5856 // Create a new SessionContext to completely reset the DataFusion state
5957 let new_session_context = default_df_session_context ( ) ;
6058
@@ -77,171 +75,6 @@ impl GlobalContext {
7775 }
7876}
7977
80- /// Unified configuration for the DataFusion fuzzer.
81- ///
82- /// This configuration controls both:
83- /// 1. The overall fuzzing process (rounds, queries, timeout)
84- /// 2. The table and query generation parameters
85- /// 3. UI and display parameters
86- #[ derive( Debug , Serialize , Deserialize , Clone ) ]
87- pub struct RunnerConfig {
88- // General fuzzing parameters
89- pub seed : u64 ,
90- pub rounds : u32 ,
91- pub queries_per_round : u32 ,
92- pub timeout_seconds : u64 ,
93- pub log_path : Option < PathBuf > ,
94-
95- // UI and display parameters
96- pub display_logs : bool ,
97- pub enable_tui : bool ,
98- pub sample_interval_secs : u64 ,
99-
100- // Table and query generation parameters
101- pub max_column_count : u64 ,
102- pub max_row_count : u64 ,
103- pub max_expr_level : u32 ,
104- pub max_table_count : u32 ,
105- pub max_insert_per_table : u32 ,
106- }
107-
108- impl RunnerConfig {
109- pub fn new ( ) -> Self {
110- Self :: default ( )
111- }
112-
113- pub fn with_seed ( mut self , seed : u64 ) -> Self {
114- self . seed = seed;
115- self
116- }
117-
118- pub fn with_rounds ( mut self , rounds : u32 ) -> Self {
119- self . rounds = rounds;
120- self
121- }
122-
123- pub fn with_queries_per_round ( mut self , queries_per_round : u32 ) -> Self {
124- self . queries_per_round = queries_per_round;
125- self
126- }
127-
128- pub fn with_timeout_seconds ( mut self , timeout_seconds : u64 ) -> Self {
129- self . timeout_seconds = timeout_seconds;
130- self
131- }
132-
133- pub fn with_log_path ( mut self , log_path : Option < PathBuf > ) -> Self {
134- self . log_path = log_path;
135- self
136- }
137-
138- pub fn with_display_logs ( mut self , display_logs : bool ) -> Self {
139- self . display_logs = display_logs;
140- self
141- }
142-
143- pub fn with_enable_tui ( mut self , enable_tui : bool ) -> Self {
144- self . enable_tui = enable_tui;
145- self
146- }
147-
148- pub fn with_sample_interval_secs ( mut self , sample_interval_secs : u64 ) -> Self {
149- self . sample_interval_secs = sample_interval_secs;
150- self
151- }
152-
153- pub fn with_max_column_count ( mut self , max_column_count : u64 ) -> Self {
154- self . max_column_count = max_column_count;
155- self
156- }
157-
158- pub fn with_max_row_count ( mut self , max_row_count : u64 ) -> Self {
159- self . max_row_count = max_row_count;
160- self
161- }
162-
163- pub fn with_max_expr_level ( mut self , max_expr_level : u32 ) -> Self {
164- self . max_expr_level = max_expr_level;
165- self
166- }
167-
168- pub fn with_max_table_count ( mut self , max_table_count : u32 ) -> Self {
169- self . max_table_count = max_table_count;
170- self
171- }
172-
173- pub fn with_max_insert_per_table ( mut self , max_insert_per_table : u32 ) -> Self {
174- self . max_insert_per_table = max_insert_per_table;
175- self
176- }
177-
178- pub fn from_file ( path : & Path ) -> Result < Self > {
179- let content = fs:: read_to_string ( path)
180- . map_err ( |e| fuzzer_err ( & format ! ( "Failed to read config file: {}" , e) ) ) ?;
181-
182- let config: Self = toml:: from_str ( & content)
183- . map_err ( |e| fuzzer_err ( & format ! ( "Failed to parse config file: {}" , e) ) ) ?;
184-
185- Ok ( config)
186- }
187-
188- pub fn from_cli ( cli : & crate :: cli:: Cli ) -> Result < Self > {
189- // Start with default or config file if provided
190- let mut config = if let Some ( config_path) = & cli. config {
191- Self :: from_file ( config_path) ?
192- } else {
193- Self :: default ( )
194- } ;
195-
196- // Override with CLI arguments if provided
197- if cli. seed != 42 {
198- config. seed = cli. seed ;
199- }
200-
201- if let Some ( rounds) = cli. rounds {
202- config. rounds = rounds;
203- }
204-
205- if let Some ( queries) = cli. queries_per_round {
206- config. queries_per_round = queries;
207- }
208-
209- if let Some ( timeout) = cli. timeout {
210- config. timeout_seconds = timeout;
211- }
212-
213- if let Some ( log_path) = & cli. log_path {
214- config. log_path = Some ( log_path. clone ( ) ) ;
215- }
216-
217- // Set display_logs from CLI argument
218- config. display_logs = cli. display_logs ;
219-
220- // Set enable_tui from CLI argument
221- config. enable_tui = cli. enable_tui ;
222-
223- Ok ( config)
224- }
225-
226- pub fn default ( ) -> Self {
227- Self {
228- seed : 42 ,
229- rounds : 3 ,
230- queries_per_round : 10 ,
231- timeout_seconds : 2 ,
232- log_path : Some ( PathBuf :: from ( "logs" ) ) ,
233- display_logs : false ,
234- enable_tui : true ,
235- sample_interval_secs : 5 ,
236- max_column_count : 5 ,
237- max_row_count : 100 ,
238- max_expr_level : 3 ,
239- max_table_count : 3 ,
240- max_insert_per_table : 20 ,
241- }
242- }
243- }
244-
24578pub struct RuntimeContext {
24679 pub df_ctx : Arc < RwLock < Arc < SessionContext > > > ,
24780 pub registered_tables : Arc < RwLock < HashMap < String , Arc < LogicalTable > > > > ,
0 commit comments