-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CXXCBC-328: fix restarting MCBP sessions (#406)
Fix socket reconnection during rebalance process. There are several improvements has been implemented to make the library resilient to rapid topology changes (in particular in Cloud environment) when both DNS-SRV bootstrap is being used along with alternative addresses. The changes include: * take into account alternative hostname and ports during detection of added/removed nodes on configuration update * replace node index tracking with hostname/port matching to when restarting the connections, this way we will be sure that no duplicate connections will be left, or live connections replaced by restarted session. * improved logging of critial events during rebalance: restarting, preservation and removing connections. Tools ----- * Added `--verbose` switch to `cbc-get` and `cbc-pillowfight` that will report error contexts of every failed operation to standard error stream in JSON format. It might be useful to collect/diagnose errors of the long running workloads. * Added batching switches `--batch-size` and `--batch-wait` to `cbc-pillowfight`. `--batch-size` allows to change number of operations to be scheduled at once before waiting for completion. `--batch-wait` allows to insert delays between batches in the workload thread. * Added `--number-of-keys-to-populate` switch, which allow to preload set of keys before running the workload. The switch sets number of the keys per thread.
- Loading branch information
Showing
23 changed files
with
692 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Copyright 2020-Present Couchbase, 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 <couchbase/key_value_error_context.hxx> | ||
|
||
#include <couchbase/fmt/cas.hxx> | ||
#include <couchbase/fmt/key_value_error_map_attribute.hxx> | ||
#include <couchbase/fmt/key_value_status_code.hxx> | ||
#include <couchbase/fmt/retry_reason.hxx> | ||
|
||
#include <tao/json/to_string.hpp> | ||
|
||
namespace couchbase | ||
{ | ||
auto | ||
key_value_error_context::to_json() const -> std::string | ||
{ | ||
tao::json::value json = { | ||
{ | ||
"ec", | ||
tao::json::value{ | ||
{ "value", ec().value() }, | ||
{ "message", ec().message() }, | ||
}, | ||
}, | ||
{ "operation_id", operation_id() }, | ||
{ "id", id_ }, | ||
{ "bucket", bucket_ }, | ||
{ "scope", scope_ }, | ||
{ "collection", collection_ }, | ||
}; | ||
|
||
if (auto val = retry_attempts(); val > 0) { | ||
json["retry_attempts"] = val; | ||
} | ||
if (opaque_ > 0) { | ||
json["opaque"] = opaque_; | ||
} | ||
|
||
if (!cas_.empty()) { | ||
json["cas"] = fmt::format("{}", cas_); | ||
} | ||
|
||
if (const auto& reasons = retry_reasons(); !reasons.empty()) { | ||
tao::json::value reasons_json = tao::json::empty_array; | ||
for (const auto& reason : reasons) { | ||
reasons_json.emplace_back(fmt::format("{}", reason)); | ||
} | ||
json["retry_reasons"] = reasons_json; | ||
} | ||
if (const auto& val = last_dispatched_from(); val.has_value()) { | ||
json["last_dispatched_from"] = val.value(); | ||
} | ||
if (const auto& val = last_dispatched_to(); val.has_value()) { | ||
json["last_dispatched_to"] = val.value(); | ||
} | ||
if (const auto& val = status_code_; val.has_value()) { | ||
json["status_code"] = fmt::format("{}", val.value()); | ||
} | ||
if (const auto& val = extended_error_info_; val.has_value()) { | ||
json["extended_error_info"] = tao::json::value{ | ||
{ "context", val->context() }, | ||
{ "reference", val->reference() }, | ||
}; | ||
} | ||
if (const auto& val = error_map_info_; val.has_value()) { | ||
tao::json::value info{ | ||
{ "code", val->code() }, | ||
{ "name", val->name() }, | ||
{ "description", val->description() }, | ||
}; | ||
if (const auto& attributes = val->attributes(); !attributes.empty()) { | ||
tao::json::value attrs_json = tao::json::empty_array; | ||
for (const auto& attr : attributes) { | ||
attrs_json.emplace_back(fmt::format("{}", attr)); | ||
} | ||
info["attributes"] = attrs_json; | ||
} | ||
json["error_map_info"] = info; | ||
} | ||
|
||
return tao::json::to_string(json, 2); | ||
} | ||
} // namespace couchbase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Copyright 2020-Present Couchbase, 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 <couchbase/query_error_context.hxx> | ||
|
||
#include <couchbase/fmt/retry_reason.hxx> | ||
|
||
#include <tao/json/to_string.hpp> | ||
|
||
namespace couchbase | ||
{ | ||
auto | ||
query_error_context::to_json() const -> std::string | ||
{ | ||
tao::json::value json = { | ||
{ | ||
"ec", | ||
tao::json::value{ | ||
{ "value", ec().value() }, | ||
{ "message", ec().message() }, | ||
}, | ||
}, | ||
{ "operation_id", operation_id() }, | ||
{ "retry_attempts", retry_attempts() }, | ||
{ "client_context_id", client_context_id_ }, | ||
{ "statement", statement_ }, | ||
{ "method", statement_ }, | ||
{ "path", statement_ }, | ||
{ "http_status", http_status_ }, | ||
{ "http_body", http_body_ }, | ||
{ "hostname", hostname_ }, | ||
{ "port", port_ }, | ||
}; | ||
|
||
if (const auto& val = parameters_; val.has_value()) { | ||
json["parameters"] = val.value(); | ||
} | ||
if (first_error_code_ > 0) { | ||
json["first_error_code"] = first_error_code_; | ||
} | ||
if (!first_error_message_.empty()) { | ||
json["first_error_message"] = first_error_message_; | ||
} | ||
|
||
if (const auto& reasons = retry_reasons(); !reasons.empty()) { | ||
tao::json::value reasons_json = tao::json::empty_array; | ||
for (const auto& reason : reasons) { | ||
reasons_json.emplace_back(fmt::format("{}", reason)); | ||
} | ||
json["retry_reasons"] = reasons_json; | ||
} | ||
if (const auto& val = last_dispatched_from(); val.has_value()) { | ||
json["last_dispatched_from"] = val.value(); | ||
} | ||
if (const auto& val = last_dispatched_to(); val.has_value()) { | ||
json["last_dispatched_to"] = val.value(); | ||
} | ||
|
||
return tao::json::to_string(json, 2); | ||
} | ||
} // namespace couchbase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.