Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (18)
Tags (41)
master
clickhouse
clickhouse-new-tmp
clickhouse-old-2021年12月22日
suppress-msan-2
master-old-2021年12月22日
nm/fix-uninitialized-memory
cmake-3-19
clickhouse-patch-leshikus2
update
boringssl
2.15.3
clickhouse_old_2.11
ssl-default-verify-paths
CPP-747-experiment
gh-pages
2.0
1.0
2.15.2
2.15.1
2.15.0
2.14.1
2.14.0
2.13.0
2.12.0
2.11.0
2.10.0
2.10.0-beta1
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
master
Branches (18)
Tags (41)
master
clickhouse
clickhouse-new-tmp
clickhouse-old-2021年12月22日
suppress-msan-2
master-old-2021年12月22日
nm/fix-uninitialized-memory
cmake-3-19
clickhouse-patch-leshikus2
update
boringssl
2.15.3
clickhouse_old_2.11
ssl-default-verify-paths
CPP-747-experiment
gh-pages
2.0
1.0
2.15.2
2.15.1
2.15.0
2.14.1
2.14.0
2.13.0
2.12.0
2.11.0
2.10.0
2.10.0-beta1
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (18)
Tags (41)
master
clickhouse
clickhouse-new-tmp
clickhouse-old-2021年12月22日
suppress-msan-2
master-old-2021年12月22日
nm/fix-uninitialized-memory
cmake-3-19
clickhouse-patch-leshikus2
update
boringssl
2.15.3
clickhouse_old_2.11
ssl-default-verify-paths
CPP-747-experiment
gh-pages
2.0
1.0
2.15.2
2.15.1
2.15.0
2.14.1
2.14.0
2.13.0
2.12.0
2.11.0
2.10.0
2.10.0-beta1
2.9.0
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
cpp-driver
/
src
/
batch_request.cpp
cpp-driver
/
src
/
batch_request.cpp
batch_request.cpp 7.22 KB
Copy Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
/*
Copyright (c) DataStax, Inc.
Licensed 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 "batch_request.hpp"
#include "constants.hpp"
#include "execute_request.hpp"
#include "external.hpp"
#include "protocol.hpp"
#include "request_callback.hpp"
#include "serialization.hpp"
#include "statement.hpp"
using namespace datastax;
using namespace datastax::internal::core;
extern "C" {
CassBatch* cass_batch_new(CassBatchType type) {
BatchRequest* batch = new BatchRequest(type);
batch->inc_ref();
return CassBatch::to(batch);
}
void cass_batch_free(CassBatch* batch) { batch->dec_ref(); }
CassError cass_batch_set_keyspace(CassBatch* batch, const char* keyspace) {
return cass_batch_set_keyspace_n(batch, keyspace, SAFE_STRLEN(keyspace));
}
CassError cass_batch_set_keyspace_n(CassBatch* batch, const char* keyspace,
size_t keyspace_length) {
batch->set_keyspace(String(keyspace, keyspace_length));
return CASS_OK;
}
CassError cass_batch_set_consistency(CassBatch* batch, CassConsistency consistency) {
batch->set_consistency(consistency);
return CASS_OK;
}
CassError cass_batch_set_serial_consistency(CassBatch* batch, CassConsistency serial_consistency) {
batch->set_serial_consistency(serial_consistency);
return CASS_OK;
}
CassError cass_batch_set_timestamp(CassBatch* batch, cass_int64_t timestamp) {
batch->set_timestamp(timestamp);
return CASS_OK;
}
CassError cass_batch_set_request_timeout(CassBatch* batch, cass_uint64_t timeout_ms) {
batch->set_request_timeout_ms(timeout_ms);
return CASS_OK;
}
CassError cass_batch_set_is_idempotent(CassBatch* batch, cass_bool_t is_idempotent) {
batch->set_is_idempotent(is_idempotent == cass_true);
return CASS_OK;
}
CassError cass_batch_set_retry_policy(CassBatch* batch, CassRetryPolicy* retry_policy) {
batch->set_retry_policy(retry_policy);
return CASS_OK;
}
CassError cass_batch_set_custom_payload(CassBatch* batch, const CassCustomPayload* payload) {
batch->set_custom_payload(payload);
return CASS_OK;
}
CassError cass_batch_set_tracing(CassBatch* batch, cass_bool_t enabled) {
batch->set_tracing(enabled == cass_true);
return CASS_OK;
}
CassError cass_batch_add_statement(CassBatch* batch, CassStatement* statement) {
batch->add_statement(statement);
return CASS_OK;
}
CassError cass_batch_set_execution_profile(CassBatch* batch, const char* name) {
return cass_batch_set_execution_profile_n(batch, name, SAFE_STRLEN(name));
}
CassError cass_batch_set_execution_profile_n(CassBatch* batch, const char* name,
size_t name_length) {
if (name_length > 0) {
batch->set_execution_profile_name(String(name, name_length));
} else {
batch->set_execution_profile_name(String());
}
return CASS_OK;
}
} // extern "C"
// Format: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
// where:
// <type> is a [byte]
// <n> is a [short]
// <query> has the format <kind><string_or_id><n>[<name_1>]<value_1>...[<name_n>]<value_n>
// <consistency> is a [short]
// Only protocol v3 and higher for the following:
// <flags> is a [byte] (or [int] for protocol v5)
// <serial_consistency> is a [short]
// <timestamp> is a [long]
int BatchRequest::encode(ProtocolVersion version, RequestCallback* callback,
BufferVec* bufs) const {
int length = 0;
uint32_t flags = 0;
{
// <type> [byte] + <n> [short]
size_t buf_size = sizeof(uint8_t) + sizeof(uint16_t);
Buffer buf(buf_size);
size_t pos = buf.encode_byte(0, type_);
buf.encode_uint16(pos, static_cast<uint16_t>(statements().size()));
bufs->push_back(buf);
length += buf_size;
}
for (BatchRequest::StatementVec::const_iterator i = statements_.begin(), end = statements_.end();
i != end; ++i) {
const Statement::Ptr& statement(*i);
if (statement->has_names_for_values()) {
callback->on_error(CASS_ERROR_LIB_BAD_PARAMS,
"Batches cannot contain queries with named values");
return REQUEST_ERROR_BATCH_WITH_NAMED_VALUES;
}
int32_t result = statement->encode_batch(version, callback, bufs);
if (result < 0) {
return result;
}
length += result;
}
{
// <consistency> [short]
size_t buf_size = sizeof(uint16_t);
// <flags>[<serial_consistency><timestamp><keyspace>]
if (version >= CASS_PROTOCOL_VERSION_V5) {
buf_size += sizeof(int32_t); // [int]
} else {
buf_size += sizeof(uint8_t); // [byte]
}
if (callback->serial_consistency() != 0) {
buf_size += sizeof(uint16_t); // [short]
flags |= CASS_QUERY_FLAG_SERIAL_CONSISTENCY;
}
if (callback->timestamp() != CASS_INT64_MIN) {
buf_size += sizeof(int64_t); // [long]
flags |= CASS_QUERY_FLAG_DEFAULT_TIMESTAMP;
}
if (version.supports_set_keyspace() && !keyspace().empty()) {
buf_size += sizeof(uint16_t) + keyspace().size();
flags |= CASS_QUERY_FLAG_WITH_KEYSPACE;
}
Buffer buf(buf_size);
size_t pos = buf.encode_uint16(0, callback->consistency());
if (version >= CASS_PROTOCOL_VERSION_V5) {
pos = buf.encode_int32(pos, flags);
} else {
pos = buf.encode_byte(pos, static_cast<uint8_t>(flags));
}
if (callback->serial_consistency() != 0) {
pos = buf.encode_uint16(pos, callback->serial_consistency());
}
if (callback->timestamp() != CASS_INT64_MIN) {
pos = buf.encode_int64(pos, callback->timestamp());
}
if (version.supports_set_keyspace() && !keyspace().empty()) {
pos = buf.encode_string(pos, keyspace().data(), static_cast<uint16_t>(keyspace().size()));
}
bufs->push_back(buf);
length += buf_size;
}
return length;
}
void BatchRequest::add_statement(Statement* statement) {
// If the keyspace is not set then inherit the keyspace of the first
// statement with a non-empty keyspace.
if (keyspace().empty()) {
set_keyspace(statement->keyspace());
}
statements_.push_back(Statement::Ptr(statement));
}
bool BatchRequest::find_prepared_query(const String& id, String* query) const {
for (StatementVec::const_iterator it = statements_.begin(), end = statements_.end(); it != end;
++it) {
const Statement::Ptr& statement(*it);
if (statement->kind() == CASS_BATCH_KIND_PREPARED) {
ExecuteRequest* execute_request = static_cast<ExecuteRequest*>(statement.get());
if (execute_request->prepared()->id() == id) {
*query = execute_request->prepared()->query();
return true;
}
}
}
return false;
}
bool BatchRequest::get_routing_key(String* routing_key) const {
for (BatchRequest::StatementVec::const_iterator i = statements_.begin(); i != statements_.end();
++i) {
if ((*i)->get_routing_key(routing_key)) {
return true;
}
}
return false;
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

cpp-driver加速
No labels
Apache-2.0
Use Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cyys/cpp-driver.git
git@gitee.com:cyys/cpp-driver.git
cyys
cpp-driver
cpp-driver
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /