Repository navigation
Conversation
…td/Win32 Remove the PThreads4W (pthreads-win32) devdep from the Windows build of the engine and adapt every internal pthread usage point to C++ standard library / Win32 primitives instead of vendoring a pthread shim. Platform branches only (_WIN32); POSIX compile paths are unchanged. - lib/thread: Thread uses _beginthreadex (UCRT) with pthread_create-style error codes; thread handle (pth_) is private, wait/try_wait/destroy use WaitForSingleObject/CloseHandle; dead get_pthread()/ob_pthread_get_pth removed. - obutil Mutex/Cond: std::mutex / std::condition_variable on Windows (pthreads4w ENOSPC fast-fail branches disappear with it); wait keeps the pthread 'still locked on return' contract via adopt_lock+release. - ob_rwlock: std::shared_mutex (SRWLOCK) on Windows; recursive-read-free usage verified. - ob_thread_cond: std::mutex/std::condition_variable members, init/ destroy only flip lifecycle flags. - ob_hashutils: Locker/Initer/Waiter/BroadCaster and all DefendModes get Windows std-type variants; MutexWaiter converts the absolute epoch-us timespec to a relative wait_for. - ob_platform_utils: ob_pthread_spinlock_t on Windows is a true spinlock (std::atomic<bool> TATAS); the ob_pthread_spin_* helpers stay uniform across the three platforms; QoS helpers hidden on Windows. - ob_common_utility: startup stack probe thread uses _beginthreadex. - ob_thread_hook/ob_define: ob_pthread_cond_timedwait_us gets a Windows overload on std types (steady_clock wait_for), same call-site name. - ob_tsi_utils: pthread_key -> FlsAlloc (thread-exit callback preserved). - ob_signal_handle: pthread_t thread_id_ limited to __APPLE__. - ob_queue_thread/ob_dedup_queue/ob_print_utils/utility: std-based or native thread ids on Windows. - cleanup: leftover #include <pthread.h> guarded for !_WIN32; unused ObMutex0/proxy mutex helpers hidden on Windows. - deps: drop devdeps-pthreads-20260506.tar.gz from oceanbase.windows deps. Verified: clang -fsyntax-only over all changed headers/TUs on POSIX plus forced instantiation of hash containers for every DefendMode; Windows compile to be validated by CI.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
任务描述
Windows 构建目前依赖第三方包
devdeps-pthreads(PThreads4W / pthreads-win32)为 oblib 提供 pthread API。该包在服务进程里引入了独立的 pthread 实现层:其内部对象基于内核句柄(CreateEvent 等),在内核对象配额耗尽时pthread_mutex_init/pthread_cond_init返回 ENOSPC,若未处理会在pthreadVC3.dll内部空指针解引用形成 AccessViolation(此前的快速失败补丁只是把崩溃点提前)。本 PR 把 seekdb 引擎 Windows 构建对devdeps-pthreads的依赖整个移除:先把所有内部 pthread 使用点适配为 C++ 标准库 / Windows 原生 API(不引入仓库内 pthread shim),最后删除deps/init/oceanbase.windows.x86_64.deps中的devdeps-pthreads-20260506.tar.gz行。关联工单:暂无 SEEK 编号(draft 阶段,如需挂工单请补充)。不关联 issue。
解决方案
全部改动位于
_WIN32/__APPLE__平台分支,POSIX 编译路径不动。不采用"把 pthread 移植进来"的 shim 方案(用户明确否决),理由:shim 会继续引入第二套同步语义与 pthreads4w 的内核对象消耗,而 std/Win32 原语覆盖了全部实际使用点。逐项对应:
lib/thread/thread.cpp/.h、ob_common_utility.cpp启动栈探测线程):Windows 用_beginthreadex(UCRT 接口,微软推荐),配unsigned __stdcall桩th_start_win,保持pthread_create的错误码语义(不用会抛异常的std::thread构造)。线程句柄pth_完全私有化,不外露;wait()/try_wait()/destroy()改WaitForSingleObject+CloseHandle,join 失败ob_abort()语义保留。删除无调用者的死代码get_pthread()(threads.h)与ob_pthread_get_pth(ob_pthread.cpp)。SMART_CALL 栈检查不受影响(GetCurrentThreadStackLimits查询真实栈界)。QoS 仅 macOS 需要(ob_pthread_attr_set_qos包#ifndef _WIN32)。obutil::ObUtilMutex、obutil::Cond、ObThreadCond、ob_queue_threadObCond、ob_multi_version_schema_serviceObSchemaConstructTask):Windows 成员改std::mutex/std::condition_variable。关键语义:pthread 的"返回时仍持锁"通过std::unique_lock(adopt_lock)+(void)ul.release()保持(ObUtilMutex::unlock(LockState&)只记录指针不解锁)。pthreads4w 的 ENOSPC fast-fail 分支随 std 类型自然消失(std::mutex::lock 无错误路径)。ObThreadCond::init/destroy只翻生命周期标志位,复用语义保留。ob_rwlock.h/.cpp):Windows 用std::shared_mutex(MSVC 上即 SRWLOCK)。此前已核查全部 ObRWLock 使用者无递归读锁、读写不重叠,shared_mutex语义安全;pthreads4wrwlock 死锁/EINVAL 问题的绕行注释随之收束。ob_platform_utils.h):Windows 上ob_pthread_spinlock_t定义为std::atomic<bool>TATAS 真自旋类(不用atomic_flag::test,它要求 C++20;atomic<bool>兼容 C++17 且在 x64 上 lock-free)。ob_pthread_spin_*helper 接口三平台统一,现有别名ob_pthread_spinlock_t保留不改名。ob_hashutils.h):MutexLocker/MutexIniter/MutexWaiter/MutexBroadCaster、ReadLocker/WriteLocker/RWLockIniter及全部 DefendMode 策略结构体补 Windows std 类型分支;MutexWaiter把调用方传入的绝对 epoch-µstimespec转回相对wait_for(steady_clock),调用点(ob_hashtable 超时 get)不变;init_hash_sync/destroy_hash_sync的 pthread 重载包#if !defined(_WIN32),std 类型走泛型 fallback。ob_thread_hook.cpp+ob_define.h):ob_pthread_cond_timedwait_us提供双签名——Windows 重载为std::condition_variable*/std::mutex*(steady_clock 相对等待),POSIX 保持extern "C"pthread 签名;调用点(cond.h timed_wait、schema service)名字不变。ob_tsi_utils.cpp):pthread_key_t→ WindowsFlsAlloc(带线程退出回调;TlsAlloc无回调),itid 回收语义保留。ob_signal_handle.h/.cpp):pthread_t thread_id_成员与pthread_self()赋值限__APPLE__(仅为 macOS sigwait 唤醒)。ob_dedup_queueThreadMeta 的pthread_t pthread_id_仅用于 to_string 打印,Windows 改存GetCurrentThreadId();ob_print_utils.h的is_pthread_like在 Windows 恒 false;utility.cpphexdump 的线程号 Windows 用GetCurrentThreadId();Windows 存根的pthread_sigmask(ob_signal_handle.h 内)与新结构无冲突。#include <pthread.h>包#ifndef _WIN32(hash 三件套、fifo_allocator、spin_lock/spin_rwlock、reentrant_thread、list、warning_buffer、trace_id、timer_service、clock_generator、ob_th_worker、ob_mysql_global 等,逐文件核实过体内确无其他 pthread 符号);ob_mutex.h里全仓零调用的ObMutex0/proxy mutex helper 段在 Windows 隐藏(保留 POSIX 原样)。deps/init/oceanbase.windows.x86_64.deps中devdeps-pthreads-20260506.tar.gz一行(BOM 保留,diff 仅 1 deletion)。考虑过并否决的替代方案:pthread shim(见上);
std::thread(抛异常构造 + 无法保持错误码返回语义);自旋锁映射为 mutex(用户确认 Windows 用 std::atomic 更忠实,macOS libc 无 pthread_spin 的问题由既有 mutex 别名分支处理,不属于本 PR)。验证
验证范围与结果,如实区分:
clang++ -std=gnu++17 -fsyntax-only(含ob_hashutils.h、mutex/cond/rwlock/thread_cond、thread.h/threads.h/thread.cpp、ob_queue_thread、ob_tsi_utils、ob_dedup_queue、ob_print_utils、ob_platform_utils、ob_common_utility等)。缺 cbindgen 生成头(rust/logger.h等)的文件用最小桩头补齐后通过——桩只声明符号、不参与被检代码,被检区域不涉及桩实现。ObHashMap/ObHashSet并执行 create/set/get/erase/destroy,类型检查通过。这覆盖了本次改动最容易错的 Locker/Waiter/BroadCaster 管线(过程中抓出并修复了 2 个真实错误:ob_define.h悬空#else、WriteLocker类头缺失)。ob_thread_hook.cpp、utility.cpp在 macOS 单文件编译报缺符号(生成头依赖),用未修改的 master 基线同样编译失败逐字对照确认,属既有失败。ob_multi_version_schema_service.h及 observer 侧文件因缺生成头无法本地全量编译(改动块做了片段级检查);Windows 分支完全未编译——本机无 MSVC/clang-cl/SDK,本 PR 以 draft 状态主要就是为了跑 Windows CI 把关。0a0f9d0e…,因本地 git push 传输失败,远端提交经 GitHub Git Data API 按 blob→tree→commit 逐字节重建);本地 macOS 检查结论对 PR head 成立。展开详细复现与验证记录
4031d847([SEEK-1513]),40 个待改文件与 HEAD 逐字节校验一致后开始编辑。-std=gnu++17);rust/*.h与share/inner_table/ob_inner_table_schema.h为构建期生成件不在工作树,语法检查用最小桩头(.cache-stubs/rust/*.h,仅声明 ob_log.h/ob_string.h 链路用到的logger::、compression::Code、crypto::certificate_expiry符号,签名从调用点反推)。ob_define.h悬空#else、WriteLocker类头缺失两个错误由该检查暴露并修复后全绿。.cache-stubs/hash_instantiate.cpp):include ob_hashmap/hashset/hashtable,实例化五种 DefendMode 容器并调用 create/set_refactored/get_refactored/erase_refactored/destroy,clang++ -fsyntax-only通过。git show HEAD:…导出 ob_thread_hook.cpp、utility.cpp 原文件同参数编译,报错与改动后一致(pthread_cond_timedwait_relative_np/errno未声明、ObPlatformDir未声明),判定既有失败。dumpbin /dependents检查。seekdb_test验证:待验证。原因:本机无 Windows 工具链,无法构建可运行 seekdb_test 的 Windows 产物;且本次改动不触碰 POSIX 行为,Linux/macOS 下游用例的既有断言不因本 PR 改变(POSIX 分支零改动)。剩余验证项:Windows CI 编译 + Windows 侧 seekdb_test;用例本身预计无需更新(接口名与调用点均未变),如 Windows CI 暴露行为差异再补充用例。影响范围
pthreadVC3.dll尚未核查——CI 通过后建议跑dumpbin /dependents seekdb.exe确认;若有隐式依赖需另行处理(与本 PR 的源码改动无关)。4031d847;无版本迁移/兼容面(纯构建依赖与内部实现替换,外部 ABI 接口名不变)。合入理由
_WIN32/__APPLE__分支,POSIX 路径零改动,接口名与调用点不变(ob_pthread_cond_timedwait_us双签名、ob_pthread_spin_*三平台统一),回归面集中在 Windows 构建本身。std::condition_variable相对等待替代 pthreads4w 绝对时间等待的时钟语义差异(wall-clock → steady_clock)在源码层推导为更安全(免墙上时钟跳变),但无 Windows 实测证据;hash 桶MutexWaiter的绝对→相对换算在调用方循环外层本就有get_cur_microseconds_time() > abs_timeout_us的墙钟超时判断,行为边界保持。其他信息
find_package(Threads)/Threads::ThreadsWindows 移除已在本 PR 之前单独完成,不在本 PR 范围。.cache-stubs/下 rust 头桩、hash 实例化 harness、API 推送脚本。[SEEK-xxx]。