620 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
rajvarun77 7684356982 Add MySQL client protocol (text protocol, transactions, prepared statements) on clean-room auth (#3330)
* feat(mysql): clean-room MySQL authentication codec

Clean-room implementation of the MySQL connection-phase authentication handshake,
derived from the public MySQL protocol documentation with no GPL lineage:
mysql_native_password and caching_sha2_password scrambles, HandshakeV10/
HandshakeResponse41 codec, and length-encoded integer/string plus packet-header
wire helpers. Handles the lenenc NULL (0xFB) marker and rejects an oversize
auth_response.

* feat(mysql): full MySQL text protocol with transactions and prepared statements

Port the MySQL protocol client (issue #2093) onto the clean-room auth codec and
protobuf 3.21 (NonreflectableMessage): COM_QUERY text protocol, interactive
transactions via connection affinity, and prepared statements. Wire
caching_sha2_password (fast-auth, full-auth RSA, and secure-transport cleartext)
into the live client. Fix the lenenc 9-byte length marker in pack_encode_length
(0xFD -> 0xFE) per the MySQL protocol spec.

* test(mysql): clean-room integration tests + prepared-stmt error fix + Controller cleanup

- Add clean-room integration tests (transactions, prepared statements, pooled
  connection concurrency, connection-type) run against a self-spawned mysqld.
- Fix: a failed COM_STMT_PREPARE now returns the ERR packet to the caller and keeps
  the connection alive, instead of closing the socket.
- Warn when a prepared statement runs on a 'short' connection (re-prepares on every
  execute; prefer 'pooled').
- Replace Controller's mysql-specific _mysql_stmt with a generic opaque per-RPC slot
  so no protocol type leaks onto the shared Controller.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(mysql): consolidate sources under policy/mysql/; drop inherited images

Move all MySQL sources (mysql.*, mysql_command/reply/common/transaction/
statement*, mysql_protocol.*, mysql_authenticator.*) into src/brpc/policy/mysql/
alongside the clean-room auth codec; update all includes, build globs, and
install rules. Remove three benchmark images inherited from the #2093 port and
the doc section referencing them.

No behavior change: full build green; all 19 mysql unit/integration tests pass;
a 30-case standalone end-to-end run was independently verified against mysqld.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(mysql): address code-review findings (binary protocol, auth, edge cases) + ASF headers

- Binary DATETIME/TIME: gate the microsecond bytes on the packet length, not the
  column's declared decimals (over-read / result-set desync).
- COM_STMT_SEND_LONG_DATA: frame stmt_id/param_id inside the packet; fix chunk offset.
- COM_STMT_EXECUTE: emit the trailing 0-length packet for 16MiB-aligned payloads.
- OK/EOF status & warnings: decode via mysql_uint2korr (big-endian safe).
- Row NULL-bitmap: arena-allocate instead of a stack VLA; cap column_count.
- Auth: bounds-check the parsed auth string; size-bound StringPiece uses.
- Prepared stmt: prune stale per-socket stmt_id map entries; count only real '?'
  placeholders (skip quotes/comments).
- MysqlResponse::Clear and MysqlRequest copy/Swap: reset/copy all members.
- Controller::ResetPods: release _bind_sock on controller reuse.
- Standardize mysql file license headers to the ASF form; clarify auth comment.

All 19 unit/integration tests still pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(mysql): address review findings — license header, flag typo, header-global, doc/comment drift

- example/mysql_c++/mysql_go_press.go: add ASF Apache-2.0 license header
  (the last file failing the License Check; other 6 already had headers).
- mysql_common.{h,cpp}: move the MysqlCollations map definition out of the
  header into the .cpp behind an `extern` declaration, so each translation
  unit no longer gets its own copy (C++11-safe; avoids the header-defined
  global flagged in review).
- mysql_statement.{cpp,inl.h}: rename the misspelled gflag
  mysql_statment_map_size -> mysql_statement_map_size (user-facing name).
- docs/cn/mysql_client.md: prepared statements ARE supported now — drop the
  stale "不支持Prepared statement".
- brpc_mysql_connection_type_unittest.cpp: rewrite the stale header comment
  that described a removed "MustError" test; the prepared-statement path now
  transparently re-prepares under CONNECTION_TYPE_SHORT and succeeds, matching
  the actual PreparedStatementUnderShortRePreparesAndSucceeds test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(mysql): use the standard ASF license header on new example/test files

The new MySQL example sources and brpc_mysql_unittest.cpp carried the old
"Copyright (c) Baidu, Inc." Apache-2.0 header, which skywalking-eyes (the
repo's License Check, configured copyright-owner = Apache Software Foundation)
does not accept — so all 7 files failed the gate. Replace with the canonical
ASF header used by the other 549 sources in the tree, and drop the stale
Baidu copyright/date attribution lines. Verified locally with
`license-eye -c .licenserc.yaml header check`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(mysql): add diagnostic error logs on silent failure paths

Extend the failure-path logging from the auth codec to the full client
protocol. Parsers and request/response handlers returned false/0/nullptr
silently on malformed wire data, truncated packets, bad state, or missing
prepared statements, giving no clue why a query/connection failed. Add a
LOG(ERROR) at each silent failure path naming the function and the concrete
cause.

- mysql_auth_handshake/packet.cpp: handshake + lenenc codec failure paths
  (truncated <field>, pre-4.1 server, reserved 0xFF marker, length mismatch).
- mysql.cpp: request command/param guards.
- mysql_reply.cpp: result-set parse (column/row/error packet truncation,
  arena alloc failure, bad binary-row header).
- mysql_protocol.cpp: serialize/process type + serialization failures.
- mysql_statement.cpp: statement-id lookup misses (not-prepared / stale conn).

Logic unchanged — logs inserted only. Normal control-flow returns
(need-more-data, lenenc NULL 0xFB, short-connection no-cache) are not logged.
mysql_authenticator.cpp and mysql_transaction.cpp already logged every
failure path and were left unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore(mysql): demote non-fatal diagnostic logs to LOG(WARNING)

Tune the severity of the failure-path logs. LOG(ERROR) is reserved for
total failures — handshake/connection corruption, authentication failure,
out-of-memory, and fundamental request/response type or serialization
misuse. Operational and statement-data failures are demoted to
LOG(WARNING):

- mysql_auth_packet.cpp: lenenc int/string/header decode failures (these
  fire during normal resultset parsing).
- mysql.cpp: request command/param API guards.
- mysql_reply.cpp: column/row/field/ERR-packet truncation (statement data).
  The arena out-of-memory and Auth::Parse auth-plugin failures stay ERROR.
- mysql_statement.cpp: prepared-statement-id lookup misses (recoverable,
  trigger a re-prepare).

handshake parsing and the protocol serialize/process type checks remain
LOG(ERROR). Severity-only change; messages and logic unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(test): make AuthCase a C++11 aggregate so push_back{...} compiles

CI compiles unittests with -std=c++0x (C++11), where a class with a default
member initializer is not an aggregate, so g_auth_cases.push_back({...})
fails to compile. Drop the default member initializer on AuthCase::use_ssl;
all init sites pass it explicitly. Mirrors the same fix on the #3310 codec
branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(mysql,ci): run integration tests against a real CI-provisioned mysqld

The MySQL integration tests were not exercising a live server in CI:

- Merge master to pick up #3323, which installs mysql-server in the
  install-essential-dependencies action used by the unittest lanes, so the
  mysqld binary is present for the self-spawning test/mysql/* suites.
- Delete the legacy test/brpc_mysql_unittest.cpp: it hardcoded an external
  host (db4free.net) with embedded credentials and asserted on connect
  failure (no skip), so it timed out and hard-failed in CI. The
  test/mysql/*_integration suites supersede it, spawning a throwaway local
  mysqld and GTEST_SKIP-ing when none is available (the redis precedent).
- Build the test/mysql/* suites in the make lane: extend test/Makefile's
  source glob and add a mysql/-prefixed link rule; add the subdir to
  run_tests.sh with nullglob so it runs them.
- Bazel: build one cc_test per mysql test file via generate_unittests
  instead of globbing them all into a single brpc_mysql_test target, which
  duplicated main() and the FLAGS_mysql_* definitions (ld: duplicate
  symbol). Drop the per-file main()s so every suite relies on gtest_main,
  matching brpc_redis_unittest; tag the server-spawning suites
  external+local so bazel runs them unsandboxed with the real mysqld.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* address review comments: bind-sock flag, non-copyable response, naming

- Controller: store the mysql-transaction BindSockAction in two bits of
  _flags (FLAGS_BIND_SOCK_RESERVE / FLAGS_BIND_SOCK_USE) via
  set_bind_sock_action()/bind_sock_action(), instead of a dedicated member,
  per review. No behavior change.
- MysqlResponse: make it explicitly non-copyable (= delete copy ctor and
  assignment) and turn the previously no-op MergeFrom into a hard
  CHECK-failure, so an accidental copy/CopyFrom is caught instead of
  silently dropping parsed replies.
- MysqlRequest: rename the trivial getters get_tx()/get_stmt() to
  tx()/stmt() per review.
- ControllerPrivateAccessor: add set_mysql_statement_type() as a clearly
  named alias over the pipelined_count slot the mysql protocol reuses, and
  call it from the mysql protocol instead of set_pipelined_count() directly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(mysql): move unittests from mysql/ subdir into test/

Move all seven mysql unittests (auth handshake/packet/scramble,
connection_type, pool_concurrency, prepared/txn integration) and the
test-plan doc out of test/mysql/ into test/, per review on
apache/brpc#3310.

The existing brpc_*_unittest glob in the Makefile and CMakeLists.txt now
picks them up, so both revert to master with no mysql-specific lines. In
BUILD.bazel they likewise join the brpc_unittests glob; the five tests
that fork a real mysqld keep their ["external", "local"] tags by folding
those entries into that target's per_test_tags instead of a separate
mysql target.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(mysql): drop run_tests.sh mysql/ subdir entry after move

The mysql unittests now live in test/ and match the existing
brpc*unittest glob in run_tests.sh, so revert the script to master. The
removed mysql/brpc*unittest entry needed `shopt -s nullglob` to skip a
missing subdir, but CI runs the script under `sh` (dash), where shopt is
absent; nullglob stayed off and the now-empty glob was executed as a
literal path, exiting 127.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Fix backup/retry call hang: default-initialize bind_sock_action

The new bind_sock_action member of Controller::Call had no in-class default,
and the Call(Call*) copy constructor used for backup requests and retries did
not initialize it in its member-init list. The backup call therefore read an
indeterminate value in Controller::Call::OnComplete, which branches on it
before the normal pool-return / SetFailed path; when the garbage matched
BIND_SOCK_RESERVE/BIND_SOCK_USE the backup call's socket was diverted to
_bind_sock or held instead of returned, leaving the in-flight RPC unconcluded
and hanging ChannelTest.backup_request until the test timeout (nondeterministic,
hence flaky-looking).

Give the member an in-class default initializer (BIND_SOCK_NONE) so every Call
construction path inherits it; a backup/retry never inherits transaction
connection-affinity. This closes the whole class of "new init path forgets the
member" rather than the single copy-ctor instance.

* Initialize Call::bind_sock_action explicitly in every constructor

Per review: drop the in-class default initializer for Call::bind_sock_action
and set it explicitly in each Call constructor (the copy ctor used for
backup/retry) and Call::Reset(). Leaving it uninitialized was the cause of the
backup/retry-request hang; explicit per-constructor init keeps every path safe.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Address review: remove redundant comments and dead code, move _bind_sock.reset() to ResetNonPods()

* Remove commented-out code in mysql_stmt example

---------

Co-authored-by: rajvarun77 <287367605+rajvarun77@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 16:31:14 +08:00
Bright Chen cd3948ceac Refactor Bazel build with custom proto rules and build all test targets (#3313) 2026-05-31 10:48:30 +08:00
Bright Chen f97f23edba Hide libunwind's _Unwind_* symbols under Bazel to fix bthread_tracer crash (#3297)
libunwind ships its `src/unwind/*.c` (the GCC `_Unwind_*`
ABI compatibility layer) as exported symbols of `libexternal_S~libunwind.so`.
At runtime the dynamic loader resolves `_Unwind_*` lookups (from
`pthread_exit`, libstdc++'s `__gxx_personality_v0`, etc.) to libunwind's
DWARF-based implementation instead of `libgcc_s.so.1`, hitting an
uninitialized internal context and crashing on the no-return cleanup chain
triggered by pthread_exit / C++ exception unwinding -- e.g. it makes
BthreadTest.bthread_exit segfault deterministically when
`--define=with_bthread_tracer=true` is on.

This is purely an ELF runtime symbol-resolution-order issue and reproduces
identically on GCC and Clang, since both default to `libstdc++ + libgcc_s`
on Linux.
2026-05-27 10:56:43 +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
lh2debug 8380e6e0f6 Fix span lifecycle with smart pointers to prevent use-after-free in async RPC callbacks (#3140)
* Fix span lifecycle with smart pointers to prevent use-after-free in async RPC callbacks (#3068)

* Refactor bthread span lifecycle management and optimize span API with smart pointer reuse (#3068)

---------

Co-authored-by: lhh <lhh>
2026-03-31 11:36:02 +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
yanfeng bb081befc0 feat(auto_cl): add error rate threshold for punishment attenuation (#3219)
* feat(auto_cl): add error rate threshold for punishment attenuation

Add new GFlag `auto_cl_error_rate_punish_threshold` to enable
error-rate-based punishment attenuation in AutoConcurrencyLimiter.

Problem: Low error rates (e.g., 1.3% sporadic timeouts) cause
disproportionate avg_latency inflation (+31%), leading the limiter
to mistakenly shrink max_concurrency and trigger ELIMIT rejections.

Solution: Inspired by Alibaba Sentinel's threshold-based approach:
- threshold=0 (default): Original behavior preserved (backward compat)
- threshold>0 (e.g., 0.1): Error rates below threshold produce zero
  punishment; above it, punishment scales linearly from 0 to full

Example: With threshold=0.1, a 5% error rate produces no punishment,
while a 50% error rate produces 44% of the original punishment.

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-12 14:02:26 +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 ef82950d17 Support shared mbvar (#3129)
* Support shared mbvar

* Update document
2025-11-01 13:07:21 +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
mwish 575ae27039 Enhance doc for server.md (#3040)
Signed-off-by: mwish <maplewish117@gmail.com>
2025-08-02 16:18:22 +08:00
Bright Chen 1ff5f3fc5a Support generics for MultiDimension APIs (#3026)
* Support generics for MVariable api

* Update document
2025-07-23 10:14:05 +08:00
Bright Chen bea48d75fe Bugfix: SignalTrace mode has memory and deadlock issues (#3019)
* Bugfix: SignalTrace mode has memory and deadlock issues

* Bugfix: Memory leak of SignalSync and wrong status of global priority bthread
2025-07-18 23:35:00 +08:00
Bright Chen d95ede52bd Bugfix: Butex returned to ObjectPool triggers use-after-poison (#3012) 2025-07-15 14:05:42 +08:00
Yang,Liming 67057f8fe6 rdma support polling mode (#2920) 2025-06-20 14:11:36 +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
zhoukangsheng 84071ed058 feat: change members to a single HealthCheckOption member && update ComputeChannelSignature 2025-05-10 14:39:10 +08:00
zhoukangsheng 4a0f411b01 feat: 支持channel维度设置rpc级别健康检查参数 2025-05-09 22:51:54 +08:00
LorinLee 985569728a Merge pull request #2929 from GreateCode/jemalloc_objects
jemalloc profiler support objects
2025-04-03 22:36:59 +08:00
Bright Chen f44f803a96 Fix asan switch fiber with error stack info (#2931)
* Fix __sanitizer_start_switch_fiber with error stack info

* Enable detect_stack_use_after_return in UT

* Fix reuse thread stack with asan
2025-04-02 20:27:41 +08:00
GreateCode b38ffa42ed jemalloc profiler support objects 2025-03-29 23:49:07 +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
Zhe Zhang b82f2b87de Fix build instructions in getting_started.md (#2832) 2024-11-30 10:59:34 +08:00
Jade e1bf467b20 set tags workers unlimitedly (#2801)
* set tags workers unlimitedly

* fix set concurrency test

---------

Co-authored-by: jiazheng.jia <jiazheng.jia@antgroup.com>
2024-10-31 10:13:43 +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 bb284cf1a2 Support backup request policy (#2734)
* Support backup request policy

* Support Controller::set_backup_request_policy

* Pass Controller to GetBackupRequestMs and update cn/client.md

* Feedback call info

* Avoid to block the timer thread in HandleSocketFailed
2024-09-26 10:46:01 +08:00