284 Commits

Author SHA1 Message Date
Chuang Zhang f90ab52b64 docs: add Bazel build guide and bzlmod example (#3468)
* docs: add Bazel build guide for bRPC (#13)

* docs: fix build_with_bazel_module echo example

* docs: explain why the bzlmod example repeats the root overrides (#24)

---------

Co-authored-by: Winchell <cw20050111@gmail.com>
2026-08-24 18:14:07 +08:00
Bright Chen e24461e353 Refactor NULL with nullptr in docs (#3467) 2026-08-19 23:11:50 +08:00
Regal 58ad9048b9 build: complete UBRING Bazel and CI support (#3445)
Add the missing BRPC_WITH_UBRING Bazel configuration, wire it through
the library and example targets, and document the supported build
commands.

Enable RDMA and UBRING in CI jobs whose all-options configurations did
not exercise those features. Run both feature suites in the existing
Bazel unit-test jobs and enable RDMA in the Make unit-test job.

Use unsigned literals for UBRING atomic counter operations to match the
counter type and avoid template deduction failures on stricter
compilers.

Signed-off-by: Zhengwei Zhu <141622927+ZhengweiZhu@users.noreply.github.com>
2026-08-15 09:54:19 +08:00
darion-yaphet 0313102276 build(cxx): align all builds on a C++14 baseline (#3419)
* build(cxx): align all builds on a C++14 baseline

CMake, Make, tests, tools, and examples now require C++14 so every supported build path shares the same minimum language level. The compiler checks and user-facing documentation reflect that baseline.

* fix(test): keep cores scoped to the failing test

Clear prior cores before each test binary. A passing death test can leave a core that would otherwise be used to diagnose an unrelated later failure.

* revert src/butil/type_traits.h
2026-08-06 17:34:49 +08:00
Chuang Zhang 72bf13a395 Interconnecting with the UBShmTransport Based on the LD/ST Shared Memory Semantics. (#3290)
* add ubring transport

* fix the  bug for ub ring transport

* fix the  bug for ub ring transport and other

* add the license for ub transport

* Modifying the variable naming style

* optimize the log message and some field name

* fix some bug for ubring

* add some log ubring endpoint

* add todo

* fix the bug for handshake for ub endpoint

* fix the bug for client ub endpoint

* optimize the iobuf file code

* modify the log level

* fix the declare_shm_ubs define not found bug

* add the timer_mgr support for macos and format code style

* fix the bug for macos epoll

* fix the timespece bug

* adaptor the itimerspec for macos platform

* optimize the cmakelist config

* add the ubring docs for ubring transport

* modify some file name and directory structure

* modify some code style and optimize code logical

* add the cmake ubshm transport ci/testing

* add the dependency header

* bug fix the code

* Fix UB shm allocation cleanup crashes (#11)

Co-authored-by: 郭业昌 <lvpengfei@MacBook-Air.local>

* remove the brpc_ubshm_unittest

* Found and fixed two stability issues (#13)

* 修复ubring server端关闭连接coredump问题

* 修复PollIn/PollOut解引用已释放Socket指针的问题

PollIn/PollOut通过ep->_socket(裸指针)读取data socket,当data socket
被销毁时该指针悬空,导致Socket::Address读到垃圾id触发SIGSEGV。
改为存储_socket_id(SocketId),用Address获取引用计数的Socket,
并在整个回调期间持有该引用,避免解引用悬空指针。

* 修复client非正常退出导致UBRING shm残留的问题

client被强杀(SIGTERM/崩溃/OOM)时teardown没跑完,localShm(_C)的
shm_unlink未执行,导致/dev/shm残留_C文件。server的remoteShm只munmap
不unlink(正确),无法清理client的名字。

在握手ESTABLISHED时(client/server都确认对方已mmap自己的localShm)
立即unlink localShm名字。此时对端已持有mmap引用,unlink只删名字不
影响通信;进程任意时刻退出都不会残留文件名。

* Address chenBright's review: use English comments and BAIDU_CACHELINE_ALIGNMENT

- Convert all Chinese comments in ubshm to English (per chenBright's
  'Please use English' on ub_endpoint.cpp:723, ub_ring.cpp:337,
  shm_ubs.cpp:316, and similar)
- Replace __attribute__((aligned(64))) with BAIDU_CACHELINE_ALIGNMENT
  in ubr_msg.h (per chenBright's comment on ubr_msg.h:41)
- Remove unnecessary TODO comment in ub_ring.cpp:551 (per chenBright's
  'Unnecessary comments, please delete')

* Remove unused lock macros in thread_lock.h

Per chenBright's review, the functions and macros defined in
thread_lock.h are largely unused. Verified usage across ubshm:
- LOCK_GUARD / UnlockMutex: 8 call sites in shm_ubs.cpp and
  ub_ring_manager.cpp, kept.
- SPIN_LOCK_GUARD, R_LOCK_GUARD, W_LOCK_GUARD, SEMAPHORE_WAIT_GUARD,
  SEMAPHORE_WAIT_GUARD_WITH_CLOSE and their helper functions
  (UnlockSpinLock, UnlockRWLock, PostSem, PostSemWithClose): 0 call
  sites, removed.

* Apply chenBright's review on timer_mgr globals

Per chenBright's review on timer_mgr.cpp:32-37:
- Add explicit default values to uninitialized globals
  (g_total_timer_num=0, g_max_system_fd=0, g_epoll_execute_thread=0,
  g_timer_module_initialized=0)
- Rename globals to snake_case (g_epollFd -> g_epoll_fd,
  g_totalTimerNum -> g_total_timer_num, g_timerFdCtxMap ->
  g_timer_fd_ctx_map, maxSystemFd -> g_max_system_fd,
  g_epollExecuteThread -> g_epoll_execute_thread,
  g_timerModuleInitialized -> g_timer_module_initialized)
- maxSystemFd also gains the g_ prefix to match global naming style

Also fix the missing std:: qualifier on atomic_fetch_sub/add/load
(per chenBright's earlier comment on timer_mgr.cpp:80).

* Change CloseTimerFd fd type from uint32_t to int

Per chenBright's review on timer_mgr.cpp:399 (uint32_t -> int).
fd is a system file descriptor; POSIX APIs use int and -1 denotes an
invalid fd, which uint32_t cannot represent. Changed the CloseTimerFd
signature (header + definition) and removed the now-unnecessary
(uint32_t) casts at the two call sites.

* Use BAIDU_LIKELY/BAIDU_UNLIKELY instead of custom __builtin_expect

Per chenBright's review on common.h:27. Rather than redefine the
macros with __builtin_expect directly, forward LIKELY/UNLIKELY to
brpc's standard BAIDU_LIKELY/BAIDU_UNLIKELY (from butil/compiler_specific.h).
The 122 call sites keep using LIKELY()/UNLIKELY() unchanged; only the
macro bodies change, preserving semantics.

* Add unit tests for UBShmEndpoint

Per chenBright's request to add unit tests for UBShmTransport in this
PR (rather than a follow-up).

Adds test/brpc_ubring_unittest.cpp with tests covering the public
interface of UBShmEndpoint under the g_skip_ub_init=true mode (which
skips real shared-memory/poller setup):
- construct_and_destruct: lifecycle safety
- is_writable_false_when_skip_init: skip-mode behavior
- reset_is_idempotent: Reset() is safe to call repeatedly

The file follows the brpc_*_unittest.cpp naming convention so it is
auto-collected by test/CMakeLists.txt's file(GLOB). Verified: compiles,
links, and all 3 tests pass (g++ 15.2, C++17, gtest, BRPC_WITH_UBRING=ON).

* Rewrite UBShmEndpoint unit tests with real coverage

Per chenBright's feedback that the previous tests were too simple and
did not cover the main methods.

Source changes to enable testing:
- Move HelloMessage struct declaration from ub_endpoint.cpp to
  ub_endpoint.h so tests can access it
- Expose private members under #ifdef UNIT_TEST (precedent:
  butil/containers/stack_container.h) so tests can call
  AllocateClientResources without -Dprivate=public (which breaks
  GCC 15 + new libstdc++ <any>/<sstream>)

Tests (9, all passing on Ubuntu 26.04 g++ 15.2 C++17 gtest):
HelloMessageTest (5): serialize/deserialize roundtrip, network byte
order verification, uint64 max boundary, full shm_name, toString
UBShmEndpointTest (4): construct, real IPC shm
AllocateClientResources (g_skip_ub_init=false), reset cleanup, reset
idempotency

* rename the variable to snake_case style

---------

Co-authored-by: YeChang Guo <52730608+YChange01@users.noreply.github.com>
Co-authored-by: 郭业昌 <lvpengfei@MacBook-Air.local>
Co-authored-by: gure <740684863@qq.com>
2026-07-19 13:02:08 +08:00
rajvarun77 32c95225e8 Add Power-of-Two-Choices Peak-EWMA load balancer (p2c) (#3367)
* Add Power-of-Two-Choices Peak-EWMA load balancer (p2c)

Implements the p2c load balancing policy proposed in #3340: each
selection samples two random servers (configurable via choices=N) and
routes to the lower peak-EWMA latency * (inflight+1) / weight score.
Upward latency spikes take effect immediately while recovery decays
over tau_ms (default 10s), so a degraded server is shed within one
observation at O(1) selection cost.

Uses only existing LoadBalancer hooks (SelectServer/Feedback,
need_feedback) with DoublyBufferedData membership like rr/la; per-node
stats are shared_ptr-owned by both buffers. Registered as "p2c" in
global.cpp. Includes unit tests (functional, weighted, exclusion,
error punishment, concurrency churn) and docs in cn/en client.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Reuse SelectIn.begin_time_us to avoid extra clock read per selection

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Address review: gflags for tunables, cap error punishment, drop FlatMap init

- p2c_default_choices/p2c_default_tau_ms gflags as channel-overridable defaults
- p2c_max_punish_ms(default 30s) caps the doubled-EWMA error punishment so a
  persistently failing server recovers in bounded time after turning healthy
- Servers::server_map relies on FlatMap small-map auto-init
- tests: error_punish_is_capped + feedback_lock_overhead benchmark

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: rajvarun77 <287367605+rajvarun77@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 22:41:54 +08:00
darion-yaphet be01d1047c docs(readme): update READMEs and add English doc placeholders (#3263)
- Fix outdated Travis CI badge in README_cn.md to GitHub Actions
- Unify all doc links in README.md to point to docs/en/ directory
- Add references for bthread tracer, coroutine, circuit breaker, RDMA, Bazel support
- Create 39 English placeholder docs pointing to Chinese versions
- Create Chinese placeholder for couchbase_example
2026-04-08 20:01:58 +08:00
Jenrry You a103b4b6f5 Prevent indefinite defer-close by checking last_active_time (#3216)
Co-authored-by: youzhiyuan <youzhiyuan@bytedance.com>
2026-03-10 16:00:23 +08:00
Yang,Liming a363887fb6 Merge pull request #3238 from MalikHou/master
[feature][bug] Add tcp transport event dispatcher unsched flag & fix RDMA event dispatcher unsched flag
2026-03-09 13:57:46 +08:00
MalikHou b65c90e80b fix md 2026-03-09 12:29:50 +08:00
MalikHou 9218d96c27 fix 2026-03-09 11:50:30 +08:00
HU 0ec948ba1a Merge pull request #3222 from wayslog/feat/redis-cluster-channel
feat(redis): add native Redis Cluster channel support
2026-03-08 22:32:25 +08:00
MalikHou d3317cced4 fix 2026-03-07 13:37:11 +08:00
MalikHou 6b73ee9915 add tcp transport event dispatcher unsched flag & fix RDMA event dispatcher unsched flag 2026-03-06 20:26:15 +08:00
yanfeng 2e0f0b0521 feat(backup_request): add rate-limited backup request policy (#3228) (#3229)
* feat(backup_request): add rate-limited backup request policy (#3228)

* docs(backup_request): restructure rate-limiting section, add lifecycle guidance

- Promote built-in factory function to its own subsection (before custom interface)
- Add unique_ptr usage example for policy lifetime management
- Add RateLimitedBackupPolicyOptions parameter table with defaults/constraints
- Document NULL return on invalid params
- Keep cn/en docs in sync

* fix(backup_request): address review issues — sentinel fallback, comments, tests

- controller.cpp: When policy returns -1 (inherit sentinel), fall back
  to _backup_request_ms set from ChannelOptions, so backup timer is
  actually armed when using a policy with backup_request_ms=-1.
- backup_request_policy.cpp: Clarify OnRPCEnd comment to say 'RPC legs'
  (both original and backup completions counted as denominator).
- backup_request_policy.cpp: Warn when update_interval_seconds exceeds
  window_size_seconds (window would rarely refresh within its period).
- backup_request_policy.h: Fix comment typo ('Called when an RPC ends').
- brpc_channel_unittest.cpp: Replace nullptr with NULL to match codebase
  convention; use ASSERT_TRUE(p != NULL) for unique_ptr null checks.
- brpc_channel_unittest.cpp: Add ValidMaxRatioAtBoundary behavioral assert
  and AfterColdStartBackupSuppressedUntilRpcCompletes test.

* fix(backup_request): correct docs table defaults and add suppression test

- docs: fix backup_request_ms default (0→-1) and constraint (>=0→>=-1);
  add note that -1 inherit only works via ChannelOptions injection path,
  not Controller::set_backup_request_policy().
- test: replace no-op AfterColdStart test with a real behavioral assertion:
  after cold-start backup fires, wait 1.2s for ratio refresh, verify
  DoBackup() returns false (conservative ratio=1.0 path triggers).

* fix(backup_request): clarify comments — negative defer semantics and burst caveat

* fix(backup_request): address Copilot review — sentinel contract, OnRPCEnd comment, re-allow test, docs

- controller.cpp: treat -1 specifically (not all negatives) as the inherit
  sentinel; other negatives still disable backup, preserving old behavior
  for custom policies that return negative values to disable backup
- backup_request_policy.h: document the -1 sentinel contract on
  GetBackupRequestMs() so custom implementors know the new interface
- backup_request_policy.cpp: fix OnRPCEnd comment — called once per
  user-level RPC, not once per leg (total_count tracks user RPCs)
- test: add OnRPCEndDrivesRatioDownAndReAllows — fires 20 backups to
  suppress, then completes 50 RPCs via OnRPCEnd, verifies DoBackup
  re-allows once ratio refreshes below max_backup_ratio
- docs (EN+CN): rephrase backup_request_ms=-1 note to clarify the
  channel-level fallback only applies when set via ChannelOptions

* fix(backup_request): explain why std::nothrow is intentionally omitted

Plain new follows brpc's project-wide OOM convention (abort rather than
return NULL). The factory's NULL return already exclusively signals invalid
parameters, not allocation failure — adding std::nothrow would conflate
the two. Comment added to suppress future linter/AI suggestions.

* docs(backup_request): clarify policy lifetime — channel must be destroyed before policy

The unique_ptr comment was ambiguous: 'released when goes out of scope,
as long as it outlives the channel' can be read as contradictory. Reword
to make the ordering explicit: destroy channel first, then policy.

* test(backup_request): fix inaccurate cold-start comment in ValidMaxRatioAtBoundary

ratio=1.0 conservative path only applies when backup>0 && total==0.
True cold start (both zero) sets ratio=0.0 and allows freely.
2026-03-02 21:17:57 +08:00
Bright Chen c32ddee06e Support custom modification of sub controllers (#3213)
* Copy http headers from main controller to sub controller

* Support custom modification of sub controllers
2026-03-01 16:04:06 +08:00
wayslog 11a71050d2 feat(redis): add native Redis Cluster channel, tests and docs 2026-03-01 15:54:11 +08:00
Bright Chen c7ae57aa31 Bugfix: SQ overflow (#3145)
* Bugfix: The failure of ibv_post_send is caused by polling send CQE before recv CQE

* Split send and recv comp channel

* Use wr_id to update _sq_window_size

* Send CQ and recv CQ share comp channel

* Add IMM window

* Deallocate polling cq

* Update RDMA documents
2025-12-22 19:00:47 +08:00
Giriraj Singh d2ea819af0 Added support to connect and perform CRUD operations with couchbase (#3138)
* Implemented Couchbase binary protocol support

* added support for single connection type for couchbase

* removed unnecessary cout statements

* added protocol code for helo packet

* fixed vbucketID code for identification, fixed add and get functions

* Added test cases for threaded get and add functions

* Added Error Handling code and made upsert and delete examples

* added makefile for example/couchbase_c++

* fixed bugs in couchbase header files

* Added License and formatted to google c++ norms

* fixed bugs, added support for collections and added couchbase_client.md

* fixed license issue

* added custom logic for caching collectionIDs

* added caching of collection manifests

* Added example code for multithreaded demonstration

* updated CMake

* Abstracted CRUD operations

* Added pipeline/batching support

* commented unused variables

* Updated support for C++17

* fixed some issue.

* Using Mutex instead of shared lock to support c++11

* Formatted code to google c++ format

* Introduced local cache per-instance of CouchbaseOperations and added functionality to handle server side manifest updates.

* Delete MODULE.bazel.lock

Unnecessary file

* Fixed bugs in local collection cache and collection refresh logic

* remove recurring statements

* Fixed bugs/repetitive calls to refreshing manifest on server

* Formatted function/variable naming scheme and formatted code in c++ google format

* removed unnecessary code

* updated comments

* updated comments

* updated documentation

* updated documentation

* updated documentation

* updated documentation

* Updated documentation

* Updated documentation

* Update documentation

* Added features and fixed bugs in multithreaded environment

Using connection_groups to differentiate between connections across CouchbaseOperations instances to different buckets.

Renamed CollectionManifestTracker class to CollectionManifestManager and all the related functionality inside it as before refreshing method was outside this class

Added two different authenticate method authenticate(not secure) and authenticateSSL(secure)

* Updated multithreaded and single threaded code.

Added an example where a single instance is being shared across the threads when operating on single bucket.

* updated documentation

updated the documentation on thread safe operations and fixed small small discrepancies.

* removed commented code and updated readme to have links for cluster download certificate

* removed unused code.

* Added traditional bRPC coding approach

Traditional bRPC coding approach doesn't uses high level functions but provides more control to the user

fixed formatting issues.

fixed the bug in couchbase.cpp where logic to check the cache is empty was inverted

* updated couchbase_example.md

* added unit test cases

* removed using namespace std from couchbase.h

* restored original CMakeLists.txt
2025-11-25 16:56:37 +08:00
Bright Chen 1d3bded92a Support higher performance bvar with babylon counter (#3116)
* Support higher performance bvar with babylon counter

* Update documents
2025-10-26 15:22:43 +08:00
wwbmmm 9049685d0b improve server and redis docs 2025-08-02 16:43:47 +08:00
Bright Chen 66e9635e91 Fix invalid url of thrift (#2975) 2025-05-27 22:21:24 +08:00
tongke 6ef8b9ddeb Fix libunwind linked by default on x86_64 cpu when building via bazel (#2973)
* Fix libunwind linked by default on x86_64 cpu when build with bazel

* fix errors in getting_started.md english version

* add link libunwind instruction for bazel
2025-05-24 20:07:54 +08:00
Bright Chen 7a7d1c83e5 Support AddressSanitizer (#2890)
* Support AddressSanitizer

* Add gperftools helper header
2025-03-26 20:07:45 +08:00
Jenrry You 923d4137fe Support segment large stream messages automatically (#2889) 2025-02-17 12:58:13 +08:00
Bright Chen 4c33f88675 Support success limit of ParallelChannel (#2842)
* Support success limit of ParallelChannel

* Update document of ParallelChannel
2025-01-06 14:44:41 +08:00
Bright Chen a18463f6c3 Support task tracer (#2851)
* Support task tracer

* Opt signal trace

* Rename BRPC_VALIDATE_GFLAG to BUTIL_VALIDATE_GFLAG

* Update picture of document
2025-01-06 14:43:55 +08:00
Xiaofeng Wang 6c0195f71d docs: update build requirements (#2837) 2024-12-08 17:15:44 +08:00
Alan Muhammad f187d2ca43 Method level option to ignore server eovercrowded (#2820)
* method level option to ignore server eovercrowded

* explain method-level option

* [fix] add _failed_to_set_ignore_eovercrowded

* [fix] update docs

* fix indent and add service level option in baidu_master_service

* refactor constructor and update docs

* update server.md

* rm useless methods and refactor getter/setter

* fix build

---------

Co-authored-by: lianxuechao <lianxuechao@bytedance.com>
2024-12-04 11:39:32 +08:00
mwish dae4b4df23 Fix bad link in document and code (#2799) 2024-10-29 11:56:08 +08:00
Jenrry You 7e5ec4fe8d Batch create and accept stream (#2754)
* feat: batch create and accept stream

* fix protobuf 22.5 compilation error related to thread_local in MacOS

* refine style

* modify code based on the code review feedback and add more tests

modify code based on the code review feedback  and add more tests
2024-10-09 10:39:42 +08:00
Bright Chen 9643150b8f Support arena rpc pb message factory (#2751)
* Support arena rpc pb message factory

* Update server document

* Fix comment
2024-09-08 18:03:00 +02:00
Bright Chen 0128bb11d6 Update protobuf version in doc (#2618) 2024-04-29 10:13:11 +08:00
YinZheng-Sun 3f13b43987 fix typo 2024-03-29 23:03:32 +08:00
omahs 85e7ea7bd9 fix typos 2024-02-16 15:45:01 +01:00
Didier Raboud f19ae4f253 Fix english typos (#2496)
* Fix ploting -> plotting typo
* Fix is not enable -> is not enabled typo
* Fix allowd -> allowed typo
* Fix paramters -> parameters typo
* Fix reponse -> response typo
* Fix seperated -> separated typo
2024-01-05 13:59:22 +08:00
wwbmmm 64bd858dbc Update mac install document 2023-12-25 21:48:23 +08:00
Menci 4b14951862 Add client ALPN support (#2251)
* Add client ALPN support

* Fix build error

* Remove ALPN code from mesalink_ssl_helper

* Add alpn_protocol.size() to error message

* Add docs
2023-12-25 11:52:48 +08:00
Khalid Abdullah 6fce5d2be8 [Typo fixed in server.md] (#2432) 2023-10-30 10:08:54 +08:00
Xiaofeng Wang 12d072862e Add wireshark dissector for baidu_std protocol (#2408) 2023-10-18 03:28:37 +08:00
thorneliu 283ac46212 add HTTP server-sent-events(SSE) example in brpc http server 2023-09-07 23:21:44 +08:00
Ran Miller 09acd32715 Server support ALPN with OpenSSL (#2102)
* Server support ALPN with OpenSSL

* Fix SSL unittest compile error

* Add ALPN protocol unittest

* Add ALPN protocol doc
2023-08-30 11:14:03 +08:00
Ran Miller 9b102f0c52 Replace invisible U+00a0 characters with spaces in doc (#2320) 2023-07-24 17:14:46 +08:00
clundro 28b5322feb update thrift_doc
use `-Wno-error` to ignore the diagnose info.

Signed-off-by: clundro <859287553@qq.com>
2023-04-30 03:30:04 +08:00
Bright Chen a0a79378d9 Add http error code doc (#2224) 2023-04-28 09:48:13 +08:00
Xiaofeng Wang 0eb6a79f28 update project links (#2200)
- brpc/brpc -> apache/brpc
2023-04-11 09:48:46 +08:00
zuyu 2ec8f469f8 fix gtest build cmd in doc (#2154) 2023-03-07 18:32:27 +08:00
freemandealer 518d216da2 typo fix for bthread introduction
As term 'M:N' starts with a vowel sound [e], so it should be 'an' instead of
'a' grammatically.

Signed-off-by: freemandealer <freeman.zhang1992@gmail.com>
2023-01-11 21:44:32 +08:00
Weibing Wang 6b563554f2 Remove incubator (#2056) 2023-01-10 10:33:14 +08:00
caidj 70d702f1c7 Optimize reference docs (#2065)
* optimize parallel channel request map method

* optimize

* optimze request map function

* optimize doc
2022-12-29 09:49:19 +08:00