Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ if(EXISTS "${STDC_SHARED_LIB_SYMLINK}")
message(STATUS "STDC_SHARED_LIB: ${STDC_SHARED_LIB}")
endif()

option(OB_USE_WEPOLL "Windows: use wepoll (AFD/IOCP) instead of the legacy WSAPoll-based epoll shim" ON)
if(WIN32)
add_subdirectory(deps/oblib/src/lib/wepoll)
if(OB_USE_WEPOLL)
add_compile_definitions(OB_USE_WEPOLL=1)
endif()
endif()

add_subdirectory(deps/oblib)
add_subdirectory(src/objit)
add_subdirectory(src)
Expand Down
31 changes: 31 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,34 @@ All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory

==============================wepoll==============================

wepoll - epoll for Windows
https://github.com/piscisaureus/wepoll

Copyright 2012-2020, Bert Belder <bertbelder@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 changes: 4 additions & 3 deletions deps/oblib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ target_include_directories(
$<$<PLATFORM_ID:Windows>:${VCPKG_INCLUDE_DIR}/mysql/mysql>
$<$<PLATFORM_ID:Windows>:${SQLITE_COMPAT_DIR}>
$<$<PLATFORM_ID:Windows>:${OB_VSAG_DIR}/include>
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${OB_USE_WEPOLL}>>:${CMAKE_SOURCE_DIR}/deps/oblib/src/lib/wepoll>
${DEVTOOLS_DIR}
${DEVTOOLS_DIR}/include
${DEP_DIR}/include/apr-1/
Expand Down Expand Up @@ -100,7 +101,7 @@ if (OB_USE_CLANG)
-Wno-ambiguous-reversed-operator -Wno-invalid-partial-specialization
-Wno-string-concatenation
/EHsc -Wno-missing-noreturn -Wno-undefined-func-template
-Wno-undef -Wno-sign-conversion -Wno-strict-prototypes -Wno-switch-default -Wno-language-extension-token
-Wno-undef -Wno-sign-conversion -Wno-strict-prototypes -Wno-switch-default -Wno-language-extension-token
-Wno-missing-prototypes -Wno-extra-semi-stmt -Wno-unused-macros -Wno-unsafe-buffer-usage -Wno-c++98-compat -Wno-c++98-compat-pedantic
-Wno-reserved-identifier -Wno-padded -Wno-variadic-macros -Wno-global-constructors -Wno-undefined-reinterpret-cast
-Wno-tautological-unsigned-zero-compare -Wno-integer-overflow -Wno-shift-count-overflow -Wno-cast-function-type -Wno-cast-function-type-strict
Expand All @@ -110,8 +111,8 @@ if (OB_USE_CLANG)
-Wno-exit-time-destructors -Wno-inconsistent-missing-destructor-override -Wno-shadow -Wno-unreachable-code
-Wno-switch-enum -Wno-atomic-implicit-seq-cst -Wno-documentation-unknown-command
-Wno-implicit-int-conversion -Wno-gnu-conditional-omitted-operand -Wno-cast-align -Wno-comma -Wno-tautological-type-limit-compare
-Wno-disabled-macro-expansion -Wno-unreachable-code-break -Wno-missing-variable-declarations
-Wno-nonportable-system-include-path -Wno-c99-extensions -Wno-flexible-array-extensions
-Wno-disabled-macro-expansion -Wno-unreachable-code-break -Wno-missing-variable-declarations
-Wno-nonportable-system-include-path -Wno-c99-extensions -Wno-flexible-array-extensions
-Wno-compound-token-split-by-space -Wno-newline-eof -Wno-shadow-field -Wno-microsoft-unqualified-friend -Wno-float-equal
-Wno-used-but-marked-unused -Wno-unreachable-code-return -Wno-float-conversion -Wno-conditional-uninitialized
-Wno-signed-enum-bitfield -Wno-bitfield-enum-conversion -Wno-redundant-parens -Wno-gnu-statement-expression
Expand Down
139 changes: 139 additions & 0 deletions deps/oblib/src/lib/net/ob_epoll_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Copyright (c) 2024 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the
* Mulan PubL v2. You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/

#ifndef OCEANBASE_LIB_NET_OB_EPOLL_COMPAT_H_
#define OCEANBASE_LIB_NET_OB_EPOLL_COMPAT_H_

// Cross-platform thin epoll surface used by ob_sql_nio.cpp.
//
// Linux: forwards to <sys/epoll.h>.
// Windows + OB_USE_WEPOLL: forwards to wepoll (AFD/IOCP-backed real epoll).
// Windows without OB_USE_WEPOLL: this header MUST NOT be included; callers
// fall back to the legacy WSAPoll-based shim defined inline in ob_sql_nio.cpp.
//
// Why a side table on Windows:
// - wepoll's HANDLE is wepoll's own port_state_t* (heap pointer), 8 bytes on
// x64. OB stores epfd as `int epfd_` in many places. We map int<->HANDLE
// through a small registry so callers do not change.

#if defined(_WIN32) && defined(OB_USE_WEPOLL)

#include <stdint.h>
#include <mutex>
#include <unordered_map>
#include "wepoll.h"

// wepoll already provides: struct epoll_event, epoll_data_t, EPOLLIN,
// EPOLLPRI, EPOLLOUT, EPOLLERR, EPOLLHUP, EPOLLRDHUP, EPOLLONESHOT,
// EPOLL_CTL_ADD/DEL/MOD. It does NOT define:
//
// - EPOLLET: wepoll only supports level-triggered mode. Callers that pass
// EPOLLET expect edge-triggered, but they'd already silently get LT under
// the legacy WSAPoll shim. We define EPOLLET as 0 so call sites compile
// and behave identically to the WSAPoll path. If true ET semantics are
// ever required on Windows, that needs a separate effort.
// - EPOLL_CLOEXEC: irrelevant on Windows (handles do not inherit by default).

#ifndef EPOLLET
#define EPOLLET 0
#endif
#ifndef EPOLL_CLOEXEC
#define EPOLL_CLOEXEC 0
#endif

namespace oceanbase {
namespace lib {

class ObWepollRegistry
{
public:
static ObWepollRegistry &instance()
{
static ObWepollRegistry inst;
return inst;
}
int add(HANDLE h)
{
std::lock_guard<std::mutex> lg(mu_);
int id = next_id_++;
map_[id] = h;
return id;
}
HANDLE get(int id) const
{
std::lock_guard<std::mutex> lg(mu_);
auto it = map_.find(id);
return it == map_.end() ? NULL : it->second;
}
HANDLE pop(int id)
{
std::lock_guard<std::mutex> lg(mu_);
auto it = map_.find(id);
if (it == map_.end()) return NULL;
HANDLE h = it->second;
map_.erase(it);
return h;
}
private:
ObWepollRegistry() : next_id_(0x60000001) {}
mutable std::mutex mu_;
std::unordered_map<int, HANDLE> map_;
int next_id_;
};

} // namespace lib
} // namespace oceanbase

static inline int ob_wepoll_create1(int flags)
{
HANDLE h = epoll_create1(flags);
if (h == NULL) return -1;
return ::oceanbase::lib::ObWepollRegistry::instance().add(h);
}

static inline int ob_wepoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
{
HANDLE h = ::oceanbase::lib::ObWepollRegistry::instance().get(epfd);
if (h == NULL) return -1;
return epoll_ctl(h, op, (SOCKET)fd, ev);
}

static inline int ob_wepoll_wait(int epfd, struct epoll_event *events,
int maxevents, int timeout)
{
HANDLE h = ::oceanbase::lib::ObWepollRegistry::instance().get(epfd);
if (h == NULL) return -1;
return epoll_wait(h, events, maxevents, timeout);
}

static inline int ob_wepoll_close(int epfd)
{
HANDLE h = ::oceanbase::lib::ObWepollRegistry::instance().pop(epfd);
if (h == NULL) return -1;
return epoll_close(h);
}

// Override the libc names within this translation unit's Windows branch so
// existing call sites compile unchanged. epoll_close is intentionally NOT
// macro-redefined: closesocket()-style cleanup is done via ob_wepoll_close
// from explicit teardown paths.
#define epoll_create1 ob_wepoll_create1
#define epoll_ctl ob_wepoll_ctl
#define epoll_wait ob_wepoll_wait

#elif !defined(_WIN32)

#include <sys/epoll.h>

#endif // _WIN32 + OB_USE_WEPOLL

#endif // OCEANBASE_LIB_NET_OB_EPOLL_COMPAT_H_
24 changes: 24 additions & 0 deletions deps/oblib/src/lib/wepoll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if(NOT WIN32)
return()
endif()

set(_wepoll_src "${CMAKE_CURRENT_SOURCE_DIR}/wepoll.c")
set(_wepoll_hdr "${CMAKE_CURRENT_SOURCE_DIR}/wepoll.h")
if(NOT EXISTS "${_wepoll_src}" OR NOT EXISTS "${_wepoll_hdr}")
message(FATAL_ERROR
"wepoll source not found.\n"
" Drop wepoll.h and wepoll.c (BSD-2-Clause) from\n"
" https://github.com/piscisaureus/wepoll into ${CMAKE_CURRENT_SOURCE_DIR}/\n"
" See deps/oblib/src/lib/wepoll/README.md.")
endif()

add_library(wepoll STATIC "${_wepoll_src}")
target_include_directories(wepoll PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
# wepoll resolves AFD ioctls at runtime via ntdll
target_link_libraries(wepoll PUBLIC ws2_32 ntdll)
# wepoll.c is third-party; do not let project -Werror flags fail its build
if(MSVC)
target_compile_options(wepoll PRIVATE /w)
else()
target_compile_options(wepoll PRIVATE -w)
endif()
34 changes: 34 additions & 0 deletions deps/oblib/src/lib/wepoll/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# wepoll

Windows-only epoll implementation backed by AFD/IOCP. Used by OceanBase on
Windows to provide the `epoll_*` API surface that `ob_sql_nio.cpp` and friends
rely on.

## Vendoring

Two files are expected here:

- `wepoll.h`
- `wepoll.c`

Drop the latest tagged release from
<https://github.com/piscisaureus/wepoll> (BSD-2-Clause) into this directory.
Do not modify; treat as upstream.

## Build

`CMakeLists.txt` in this directory builds a static `wepoll` library on Windows
only. It fails fast at configure time if the sources are missing so we do not
silently link an empty stub.

Enable use of wepoll across the tree by passing `-DOB_USE_WEPOLL=ON` to CMake.
When unset, the legacy `WSAPoll`-based shim in `ob_sql_nio.cpp` remains the
default so we can A/B compare.

## License

BSD-2-Clause. Record the version drop here when updating:

| Version | Date | Notes |
|---------|------|-------|
| | | |
Loading
Loading