Skip to content

Commit

Permalink
Review update
Browse files Browse the repository at this point in the history
  • Loading branch information
lordgamez committed Oct 14, 2024
1 parent 25a84f8 commit b7278a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ CouchbaseErrorType CouchbaseClient::getErrorType(const std::error_code& error_co
}

nonstd::expected<::couchbase::collection, CouchbaseErrorType> CouchbaseClient::getCollection(const CouchbaseCollection& collection) {
if (auto error_type = establishConnection()) {
return nonstd::make_unexpected(*error_type);
auto connection_result = establishConnection();
if (!connection_result) {
return nonstd::make_unexpected(connection_result.error());
}
return cluster_->bucket(collection.bucket_name).scope(collection.scope_name).collection(collection.collection_name);
}
Expand Down Expand Up @@ -88,19 +89,19 @@ void CouchbaseClient::close() {
}
}

std::optional<CouchbaseErrorType> CouchbaseClient::establishConnection() {
nonstd::expected<void, CouchbaseErrorType> CouchbaseClient::establishConnection() {
if (cluster_) {
return std::nullopt;
return {};
}

auto options = ::couchbase::cluster_options(username_, password_);
auto [connect_err, cluster] = ::couchbase::cluster::connect(connection_string_, options).get();
if (connect_err.ec()) {
logger_->log_error("Failed to connect to Couchbase cluster with error code: '{}' and message: '{}'", connect_err.ec(), connect_err.message());
return getErrorType(connect_err.ec());
return nonstd::make_unexpected(getErrorType(connect_err.ec()));
}
cluster_ = std::move(cluster);
return std::nullopt;
return {};
}

namespace controllers {
Expand All @@ -121,8 +122,9 @@ void CouchbaseClusterService::onEnable() {
}

client_ = std::make_unique<CouchbaseClient>(connection_string, username, password, logger_);
if (auto result = client_->establishConnection()) {
if (result == CouchbaseErrorType::FATAL) {
auto result = client_->establishConnection();
if (!result) {
if (result.error() == CouchbaseErrorType::FATAL) {
throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Failed to connect to Couchbase cluster with fatal error");
}
logger_->log_warn("Failed to connect to Couchbase cluster with temporary error, will retry connection when a Couchbase processor is triggered");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CouchbaseClient {

nonstd::expected<CouchbaseUpsertResult, CouchbaseErrorType> upsert(const CouchbaseCollection& collection, CouchbaseValueType document_type, const std::string& document_id,
const std::vector<std::byte>& buffer, const ::couchbase::upsert_options& options);
std::optional<CouchbaseErrorType> establishConnection();
nonstd::expected<void, CouchbaseErrorType> establishConnection();
void close();

private:
Expand Down

0 comments on commit b7278a9

Please sign in to comment.