-
Notifications
You must be signed in to change notification settings - Fork 93
Write with parallel #772
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
Write with parallel #772
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,6 +163,30 @@ FORCE_INLINE uint8_t get_global_compression() { | |
| return static_cast<uint8_t>(g_config_value_.default_compression_type_); | ||
| } | ||
|
|
||
| FORCE_INLINE void set_parallel_write_enabled(bool enabled) { | ||
| g_config_value_.parallel_write_enabled_ = enabled; | ||
| } | ||
|
|
||
| FORCE_INLINE bool get_parallel_write_enabled() { | ||
| return g_config_value_.parallel_write_enabled_ && | ||
| g_config_value_.write_thread_count_ > 1; | ||
| } | ||
jt2594838 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Set the number of threads for parallel writes. Must be called before | ||
| // init_common() / libtsfile_init() — the global thread pool is created | ||
| // during initialization and is not resized at runtime. | ||
| FORCE_INLINE int set_write_thread_count(int32_t count) { | ||
| if (count < 1 || count > 64) return E_INVALID_ARG; | ||
| g_config_value_.write_thread_count_ = count; | ||
| return E_OK; | ||
| } | ||
|
Comment on lines
+178
to
+182
|
||
|
|
||
| #ifdef ENABLE_THREADS | ||
| class ThreadPool; | ||
| // Global write thread pool, created by init_common(). | ||
| extern ThreadPool* g_write_thread_pool_; | ||
| #endif | ||
|
|
||
| extern int init_common(); | ||
| extern bool is_timestamp_column_name(const char* time_col_name); | ||
| extern void cols_to_json(ByteStream* byte_stream, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,123 @@ | ||||||||
| /* | ||||||||
| * 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. | ||||||||
| */ | ||||||||
| #ifndef COMMON_THREAD_POOL_H | ||||||||
| #define COMMON_THREAD_POOL_H | ||||||||
|
|
||||||||
| #ifdef ENABLE_THREADS | ||||||||
|
|
||||||||
| #include <condition_variable> | ||||||||
| #include <functional> | ||||||||
| #include <future> | ||||||||
| #include <mutex> | ||||||||
| #include <queue> | ||||||||
| #include <thread> | ||||||||
|
||||||||
| #include <thread> | |
| #include <thread> | |
| #include <type_traits> |
Copilot
AI
Apr 10, 2026
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.
worker_loop() executes task() without any exception handling. If a task throws, the worker thread will terminate and active_ will never be decremented, causing wait_all() (and any code waiting on futures) to potentially block forever. Wrap task execution in a try/catch that ensures active_ is decremented and optionally stores/logs the exception.
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.
ENABLE_THREADSadds a compile definition, but the build does not link against the platform thread library (e.g.,-pthread/Threads::Threads). On many toolchains this will cause unresolved symbols when usingstd::thread. WhenENABLE_THREADSis ON,find_package(Threads REQUIRED)and linkThreads::Threadsto the relevant targets (at leasttsfileand any object libs that end up in it).