Added support to connect and perform CRUD operations with couchbase #3138
Conversation
Merging from source
…ouchbaselabs/cb_brpc into couchbase_binary_protocol_brpc t :wq
…functionality to handle server side manifest updates.
Unnecessary file
updated the documentation on thread safe operations and fixed small small discrepancies.
…ownload certificate
Added support to connect and perform CRUD operations with couchbase
There was a problem hiding this comment.
Pull Request Overview
This pull request adds comprehensive support for Couchbase Binary Protocol to bRPC, enabling communication with Couchbase Server clusters using the native binary protocol. The implementation provides both high-level and low-level APIs for key-value operations with support for collections, pipelining, SSL/TLS, and multithreading.
Key Changes:
- Complete Couchbase Binary Protocol implementation with request/response parsing and serialization
- High-level
CouchbaseOperationsAPI with simple CRUD operations and pipeline support - SSL/TLS support for secure connections to Couchbase Capella (cloud)
- Collection-scoped operations with automatic manifest caching and refresh
- Multithreading support with both shared and separate instance patterns
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/brpc/proto_base.proto | Adds base message types for Couchbase request/response |
| src/brpc/policy/couchbase_protocol.h | Defines protocol structures, enums, and function declarations for Couchbase Binary Protocol |
| src/brpc/policy/couchbase_protocol.cpp | Implements message parsing, serialization, and protocol handling |
| src/brpc/couchbase.h | Defines high-level CouchbaseOperations API with request/response classes and manifest management |
| src/brpc/couchbase.cpp | Implements CRUD operations, authentication, collection management, and pipeline functionality |
| src/brpc/options.proto | Adds PROTOCOL_COUCHBASE enum value for protocol registration |
| src/brpc/global.cpp | Registers Couchbase protocol with bRPC framework |
| example/couchbase_c++/couchbase_client.cpp | Single-threaded example demonstrating all features |
| example/couchbase_c++/multithreaded_couchbase_client.cpp | Multithreaded example with shared and separate instance patterns |
| example/couchbase_c++/Makefile | Build configuration for examples |
| example/couchbase_c++/CMakeLists.txt | CMake build configuration for examples |
| docs/en/couchbase_example.md | Comprehensive documentation with usage patterns and examples |
| CMakeLists.txt | Updates C++ standard to C++17 for modern features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@giriraj-singh-couchbase Thank you for your contribution! This is quite a complicated job. Your code looks very good! I have add some comments. |
|
A small advice: you can add an unit test for the couchbase protocol, just base on the code in |
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
|
Hi @wwbmmm, I have added the unit test cases, traditional approach example and updated the documentation regarding it. |
Most look good, can you remove the |
Removed. |
|
LGTM |
Can you re-run the checks? |
I have fixed the unittest in this PR: #3153 . You can merge this PR and then re-run the checks. |
|
Hi @wwbmmm & @chenBright, can I get further feedback on this PR? |
…pache#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
This pull request introduces Couchbase Binary Protocol support to bRPC, enabling communication with Couchbase Server and Capella deployments. It adds a new protocol handler, request/response builders, comprehensive example clients, performance benchmarking tools, and detailed documentation. The changes are grouped below by theme:
Couchbase Binary Protocol Integration
Protocol Layer (
src/brpc/policy/):couchbase_protocol.handcouchbase_protocol.cppimplementing the complete binary protocol framing, parsing, with support for all standard Couchbase commands (GET, SET, ADD, REPLACE, DELETE, etc.)High-Level API (
src/brpc/):Implemented
CouchbaseOperationsclass insrc/brpc/couchbase.handsrc/brpc/couchbase.cpp(~3,500 lines), providing simplified APIs for:authenticate()andauthenticateSSL()for both non-SSL and SSL connections (required for Couchbase Capella)selectBucket()for bucket selectionget(),upsert(),add(),replace(),append(),prepend(),delete_()withResultstruct for clean error handlingbeginPipeline(),pipelineRequest(),executePipeline(),clearPipeline()for batching multiple operations in a single network call.Implemented
CouchbaseRequestandCouchbaseResponseclasses (inherit fromNonreflectableMessage) providing low-level request construction and response parsingImplemented
CouchbaseManifestManagersingleton for thread-safe collection manifest management with automatic caching and refreshExample Clients
Basic Client (
example/couchbase_c++/couchbase_client.cpp- 462 lines):Multithreaded Client (
example/couchbase_c++/multithreaded_couchbase_client.cpp- 375 lines):CouchbaseOperationsinstance (same bucket, shared connection)CouchbaseOperationsinstances (different buckets, isolated connections)Documentation
Comprehensive Guide (
docs/en/couchbase_example.md):Key Features
Resultstruct with success flag, error messages, status codes, and valuesWhat problem does this PR solve?
Added native support to interact with Couchbase servers using the binary protocol, enabling efficient CRUD operations, SSL/TLS encrypted connections and collection management.
Side effects:
Performance effects: None
Breaking backward compatibility: NO
Check List: