-
Notifications
You must be signed in to change notification settings - Fork 1
Added support to connect and perform CRUD operations with couchbase #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support to connect and perform CRUD operations with couchbase #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license-eye has totally checked 1732 files.
| Valid | Invalid | Ignored | Fixed |
|---|---|---|---|
| 869 | 3 | 860 | 0 |
Click to see the invalid file list
- example/couchbase_c++/couchbase_client.cpp
- src/brpc/couchbase.h
- src/brpc/policy/couchbase_protocol.h
| @@ -0,0 +1,718 @@ | |||
| #include <gflags/gflags.h> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #include <gflags/gflags.h> | |
| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| */ | |
| #include <gflags/gflags.h> |
| @@ -0,0 +1,229 @@ | |||
| #ifndef BRPC_COUCHBASE_H | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #ifndef BRPC_COUCHBASE_H | |
| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| */ | |
| #ifndef BRPC_COUCHBASE_H |
| @@ -0,0 +1,167 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| */ | |
ingenthr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a few comments on the docs are most important, but there are some questions around the scope/collection management. If you want to proceed with those as is and let the user manage it or improve it in the future, I'd be fine with that too.
Merging from source
…ouchbaselabs/cb_brpc into couchbase_binary_protocol_brpc t :wq
| // the status codes are from Couchbase Binary Protocol documentation, | ||
| // for original reference of status codes visit | ||
| // https://github.com/couchbase/kv_engine/blob/master/include/mcbp/protocol/status.h | ||
| enum Status { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error_status code has been referenced.
|
|
||
| // collectionID fetching either from the metadata cache or if doesn't exist then | ||
| // fetch from the server. | ||
| bool CouchbaseOperations::CouchbaseRequest::getCachedOrFetchCollectionId( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method checks the global cache, and upon a miss the manifest is fetched from server using refreshCollectionManifest(). It shall be noted that upon a hit in global cache, local cache is also updated.
|
|
||
| brpc::CouchbaseMetadataTracking::CollectionManifest manifest; | ||
| // check if the server/bucket exists in the cached collection manifest | ||
| if (!metadata_tracking->getBucketToCollectionManifest(server, selected_bucket, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probes server->bucket if a miss then the manifest for that bucket is fetched.
src/brpc/couchbase.cpp
Outdated
| << selected_bucket << " on server " << server | ||
| << ", fetching from server"); | ||
| // No cached manifest found, fetch from server | ||
| if (!refreshCollectionManifest(channel, server, selected_bucket)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshCollectionManifest for the server using which channel/connection is established, and the bucket which is currently selected.
src/brpc/couchbase.cpp
Outdated
| return true; | ||
| } | ||
|
|
||
| bool CouchbaseOperations::CouchbaseRequest::refreshCollectionManifest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method refreshes the manifest for a particular sever/bucket and updates the caches.
| return result; | ||
| } | ||
|
|
||
| CouchbaseOperations::Result CouchbaseOperations::selectBucket( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method selects a bucket for the connection and can be used to select different buckets.
As a bucket is selected the collection manifest is fetched for that bucket.
In case of failure of fetching the collection manifest, it will be retried later when a collection operation is operated on this bucket.
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)
…ouchbaselabs/cb_brpc into couchbase_binary_protocol_brpc merging as the branch is not synced with the local-code base.
| msg->pi = pi; | ||
| return MakeMessage(msg); | ||
| } else { | ||
| // if (header->command == CB_BINARY_SASL_AUTH) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed the logic where authentication throws an error during parsing itself if the credentials are wrong.
src/brpc/couchbase.cpp
Outdated
|
|
||
| #include <zlib.h> //for crc32 Vbucket_id | ||
|
|
||
| #define CB_ADD(a,b) (a+b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed anywhere.
|
|
||
| // Debug flag for enabling debug statements | ||
| static bool DBUG = true; // Set to true to enable debug logs | ||
| static bool DBUG = false; // Set to true to enable debug logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a debug flag which can be set as true/false and is intended to be used for debugging purposes.
Added an example where a single instance is being shared across the threads when operating on single bucket.
updated the documentation on thread safe operations and fixed small small discrepancies.
ingenthr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments that you can use to improve this if you'd like, but otherwise offering approval. I'm sure you want to wrap this one up.
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: