summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanilalexeev <[email protected]>2024-03-14 11:26:06 +0300
committerdanilalexeev <[email protected]>2024-03-14 11:39:01 +0300
commit678e296ea969fe485638b36b6a20122d6df2aa96 (patch)
treece26de8a1753985c33741f2fd88f2a703ff03d74
parentd4249a074243bb969bf8c144374e0441b673df2f (diff)
Handle error by value
d4e9ffb825d8eb6f92b164c5ee7f48db4b6bdcc2
-rw-r--r--yt/yt/core/rpc/bus/channel.cpp2
-rw-r--r--yt/yt/core/rpc/client.cpp21
-rw-r--r--yt/yt/core/rpc/client.h6
-rw-r--r--yt/yt/core/rpc/grpc/channel.cpp4
-rw-r--r--yt/yt/core/rpc/hedging_channel.cpp16
-rw-r--r--yt/yt/core/rpc/helpers.cpp31
-rw-r--r--yt/yt/core/rpc/helpers.h4
-rw-r--r--yt/yt/core/rpc/local_channel.cpp2
-rw-r--r--yt/yt/core/rpc/retrying_channel.cpp10
-rw-r--r--yt/yt/core/rpc/roaming_channel.cpp7
-rw-r--r--yt/yt/core/rpc/serialized_channel.cpp4
-rw-r--r--yt/yt/core/rpc/throttling_channel.cpp5
12 files changed, 48 insertions, 64 deletions
diff --git a/yt/yt/core/rpc/bus/channel.cpp b/yt/yt/core/rpc/bus/channel.cpp
index 7a2369c81f3..a43b5c8f3e0 100644
--- a/yt/yt/core/rpc/bus/channel.cpp
+++ b/yt/yt/core/rpc/bus/channel.cpp
@@ -1072,7 +1072,7 @@ private:
reason,
requestControl->GetRequestId());
- responseHandler->HandleError(detailedError);
+ responseHandler->HandleError(std::move(detailedError));
}
void NotifyAcknowledgement(
diff --git a/yt/yt/core/rpc/client.cpp b/yt/yt/core/rpc/client.cpp
index 085931e8479..162830c21f9 100644
--- a/yt/yt/core/rpc/client.cpp
+++ b/yt/yt/core/rpc/client.cpp
@@ -520,7 +520,7 @@ size_t TClientResponse::GetTotalSize() const
return ResponseMessage_.ByteSize();
}
-void TClientResponse::HandleError(const TError& error)
+void TClientResponse::HandleError(TError error)
{
auto prevState = State_.exchange(EState::Done);
if (prevState == EState::Done) {
@@ -529,22 +529,15 @@ void TClientResponse::HandleError(const TError& error)
return;
}
- auto invokeHandler = [&] (const TError& error) {
- GetInvoker()->Invoke(
- BIND(&TClientResponse::DoHandleError, MakeStrong(this), error));
- };
-
- auto optionalEnrichedError = TryEnrichClientRequestError(
- error,
+ EnrichClientRequestError(
+ &error,
ClientContext_->GetFeatureIdFormatter());
- if (optionalEnrichedError) {
- invokeHandler(*optionalEnrichedError);
- } else {
- invokeHandler(error);
- }
+
+ GetInvoker()->Invoke(
+ BIND(&TClientResponse::DoHandleError, MakeStrong(this), std::move(error)));
}
-void TClientResponse::DoHandleError(const TError& error)
+void TClientResponse::DoHandleError(TError error)
{
NProfiling::TWallTimer timer;
diff --git a/yt/yt/core/rpc/client.h b/yt/yt/core/rpc/client.h
index 5a04b9baca5..96e5c27db7e 100644
--- a/yt/yt/core/rpc/client.h
+++ b/yt/yt/core/rpc/client.h
@@ -295,7 +295,7 @@ struct IClientResponseHandler
/*!
* \param error An error that has occurred.
*/
- virtual void HandleError(const TError& error) = 0;
+ virtual void HandleError(TError error) = 0;
//! Enables passing streaming data from the service to clients.
virtual void HandleStreamingPayload(const TStreamingPayload& payload) = 0;
@@ -346,7 +346,7 @@ protected:
virtual bool TryDeserializeBody(TRef data, std::optional<NCompression::ECodec> codecId = {}) = 0;
// IClientResponseHandler implementation.
- void HandleError(const TError& error) override;
+ void HandleError(TError error) override;
void HandleAcknowledgement() override;
void HandleResponse(TSharedRefArray message, TString address) override;
void HandleStreamingPayload(const TStreamingPayload& payload) override;
@@ -364,7 +364,7 @@ private:
TSharedRefArray ResponseMessage_;
void TraceResponse();
- void DoHandleError(const TError& error);
+ void DoHandleError(TError error);
void DoHandleResponse(TSharedRefArray message, TString address);
void Deserialize(TSharedRefArray responseMessage);
diff --git a/yt/yt/core/rpc/grpc/channel.cpp b/yt/yt/core/rpc/grpc/channel.cpp
index c8ec39e9041..5fc956dd840 100644
--- a/yt/yt/core/rpc/grpc/channel.cpp
+++ b/yt/yt/core/rpc/grpc/channel.cpp
@@ -168,7 +168,7 @@ public:
if (!TerminationError_.IsOK()) {
auto error = TerminationError_;
guard.Release();
- responseHandler->HandleError(error);
+ responseHandler->HandleError(std::move(error));
return nullptr;
}
return New<TCallHandler>(
@@ -686,7 +686,7 @@ private:
reason,
Request_->GetRequestId());
- responseHandler->HandleError(detailedError);
+ responseHandler->HandleError(std::move(detailedError));
}
void NotifyResponse(TSharedRefArray message)
diff --git a/yt/yt/core/rpc/hedging_channel.cpp b/yt/yt/core/rpc/hedging_channel.cpp
index b97c089b49c..a75ed434d3c 100644
--- a/yt/yt/core/rpc/hedging_channel.cpp
+++ b/yt/yt/core/rpc/hedging_channel.cpp
@@ -45,7 +45,7 @@ public:
// IClientResponseHandler implementation.
void HandleAcknowledgement() override;
void HandleResponse(TSharedRefArray message, TString address) override;
- void HandleError(const TError& error) override;
+ void HandleError(TError error) override;
void HandleStreamingPayload(const TStreamingPayload& /*payload*/) override;
void HandleStreamingFeedback(const TStreamingFeedback& /*feedback*/) override;
@@ -149,7 +149,7 @@ public:
responseHandler->HandleResponse(std::move(message), std::move(address));
}
- void HandleError(const TError& error, bool backup)
+ void HandleError(TError error, bool backup)
{
IClientResponseHandlerPtr responseHandler;
{
@@ -168,10 +168,10 @@ public:
YT_LOG_DEBUG_IF(backup, "Request failed at backup (RequestId: %v)",
Request_->GetRequestId());
- responseHandler->HandleError(
- backup
- ? error << TErrorAttribute(BackupFailedKey, true)
- : error);
+ if (backup) {
+ error <<= TErrorAttribute(BackupFailedKey, true);
+ }
+ responseHandler->HandleError(std::move(error));
}
// IClientRequestControl implementation.
@@ -302,9 +302,9 @@ void THedgingResponseHandler::HandleAcknowledgement()
Session_->HandleAcknowledgement(Backup_);
}
-void THedgingResponseHandler::HandleError(const TError& error)
+void THedgingResponseHandler::HandleError(TError error)
{
- Session_->HandleError(error, Backup_);
+ Session_->HandleError(std::move(error), Backup_);
}
void THedgingResponseHandler::HandleResponse(TSharedRefArray message, TString address)
diff --git a/yt/yt/core/rpc/helpers.cpp b/yt/yt/core/rpc/helpers.cpp
index d23f2995ad1..27cc2c7af45 100644
--- a/yt/yt/core/rpc/helpers.cpp
+++ b/yt/yt/core/rpc/helpers.cpp
@@ -369,12 +369,12 @@ private:
UnderlyingHandler_->HandleResponse(std::move(message), std::move(address));
}
- void HandleError(const TError& error) override
+ void HandleError(TError error) override
{
if (IsError_(error)) {
OnFailure_.Run(Channel_, error);
}
- UnderlyingHandler_->HandleError(error);
+ UnderlyingHandler_->HandleError(std::move(error));
}
void HandleStreamingPayload(const TStreamingPayload& payload) override
@@ -597,34 +597,27 @@ std::vector<TSharedRef> DecompressAttachments(
////////////////////////////////////////////////////////////////////////////////
-std::optional<TError> TryEnrichClientRequestError(
- const TError& error,
+void EnrichClientRequestError(
+ TError* error,
TFeatureIdFormatter featureIdFormatter)
{
- std::optional<TError> result;
-
+ YT_VERIFY(error);
// Try to enrich error with feature name.
- if (error.GetCode() == NRpc::EErrorCode::UnsupportedServerFeature &&
- error.Attributes().Contains(FeatureIdAttributeKey) &&
- !error.Attributes().Contains(FeatureNameAttributeKey) &&
+ if (error->GetCode() == NRpc::EErrorCode::UnsupportedServerFeature &&
+ error->Attributes().Contains(FeatureIdAttributeKey) &&
+ !error->Attributes().Contains(FeatureNameAttributeKey) &&
featureIdFormatter)
{
- auto featureId = error.Attributes().Get<int>(FeatureIdAttributeKey);
+ auto featureId = error->Attributes().Get<int>(FeatureIdAttributeKey);
if (auto featureName = (*featureIdFormatter)(featureId)) {
- result = error;
- result->MutableAttributes()->Set(FeatureNameAttributeKey, featureName);
+ error->MutableAttributes()->Set(FeatureNameAttributeKey, featureName);
}
}
// Try to enrich error with handled channel failure label.
- if (IsChannelFailureError(error) && !IsChannelFailureErrorHandled(error)) {
- if (!result) {
- result = error;
- }
- LabelHandledChannelFailureError(&*result);
+ if (IsChannelFailureError(*error) && !IsChannelFailureErrorHandled(*error)) {
+ LabelHandledChannelFailureError(&*error);
}
-
- return result;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/rpc/helpers.h b/yt/yt/core/rpc/helpers.h
index 8b4bd12607c..438093c1ed5 100644
--- a/yt/yt/core/rpc/helpers.h
+++ b/yt/yt/core/rpc/helpers.h
@@ -117,8 +117,8 @@ std::vector<TSharedRef> DecompressAttachments(
template <class E>
int FeatureIdToInt(E featureId);
-std::optional<TError> TryEnrichClientRequestError(
- const TError& error,
+void EnrichClientRequestError(
+ TError* error,
TFeatureIdFormatter featureIdFormatter);
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/rpc/local_channel.cpp b/yt/yt/core/rpc/local_channel.cpp
index 948b3793a7b..3e2fe3cfea8 100644
--- a/yt/yt/core/rpc/local_channel.cpp
+++ b/yt/yt/core/rpc/local_channel.cpp
@@ -331,7 +331,7 @@ private:
YT_LOG_DEBUG(detailedError, "Local request failed (RequestId: %v)",
RequestId_);
- Handler_->HandleError(detailedError);
+ Handler_->HandleError(std::move(detailedError));
}
};
diff --git a/yt/yt/core/rpc/retrying_channel.cpp b/yt/yt/core/rpc/retrying_channel.cpp
index b8481f2acb1..b9fd70a8cd4 100644
--- a/yt/yt/core/rpc/retrying_channel.cpp
+++ b/yt/yt/core/rpc/retrying_channel.cpp
@@ -208,7 +208,7 @@ private:
// NB: The underlying handler is not notified.
}
- void HandleError(const TError& error) override
+ void HandleError(TError error) override
{
YT_LOG_DEBUG(error, "Request attempt failed (RequestId: %v, Attempt: %v of %v)",
Request_->GetRequestId(),
@@ -216,17 +216,17 @@ private:
Config_->RetryAttempts);
if (!RetryChecker_.Run(error)) {
- ResponseHandler_->HandleError(error);
+ ResponseHandler_->HandleError(std::move(error));
return;
}
if (!FirstError_) {
- FirstError_ = error;
+ FirstError_ = std::move(error);
} else {
if (LastError_) {
++OmittedInnerErrorCount_;
}
- LastError_ = error;
+ LastError_ = std::move(error);
}
Retry();
@@ -271,7 +271,7 @@ private:
if (LastError_) {
detailedError = detailedError << *LastError_;
}
- ResponseHandler_->HandleError(detailedError);
+ ResponseHandler_->HandleError(std::move(detailedError));
}
void Retry()
diff --git a/yt/yt/core/rpc/roaming_channel.cpp b/yt/yt/core/rpc/roaming_channel.cpp
index a1b531b586a..47c9767c8fc 100644
--- a/yt/yt/core/rpc/roaming_channel.cpp
+++ b/yt/yt/core/rpc/roaming_channel.cpp
@@ -40,12 +40,11 @@ public:
return;
}
- auto error = TError(NYT::EErrorCode::Canceled, "RPC request canceled")
+ ResponseHandler_->HandleError(TError(NYT::EErrorCode::Canceled, "RPC request canceled")
<< TErrorAttribute("request_id", Request_->GetRequestId())
<< TErrorAttribute("realm_id", Request_->GetRealmId())
<< TErrorAttribute("service", Request_->GetService())
- << TErrorAttribute("method", Request_->GetMethod());
- ResponseHandler_->HandleError(error);
+ << TErrorAttribute("method", Request_->GetMethod()));
Request_.Reset();
ResponseHandler_.Reset();
@@ -154,7 +153,7 @@ public:
options),
channel);
} else {
- responseHandler->HandleError(*channelOrError);
+ responseHandler->HandleError(std::move(*channelOrError));
return New<TClientRequestControlThunk>();
}
}
diff --git a/yt/yt/core/rpc/serialized_channel.cpp b/yt/yt/core/rpc/serialized_channel.cpp
index 8722d79737b..12c76ad100a 100644
--- a/yt/yt/core/rpc/serialized_channel.cpp
+++ b/yt/yt/core/rpc/serialized_channel.cpp
@@ -78,9 +78,9 @@ private:
Owner_->OnRequestCompleted();
}
- void HandleError(const TError& error) override
+ void HandleError(TError error) override
{
- UnderlyingHandler_->HandleError(error);
+ UnderlyingHandler_->HandleError(std::move(error));
Owner_->OnRequestCompleted();
}
diff --git a/yt/yt/core/rpc/throttling_channel.cpp b/yt/yt/core/rpc/throttling_channel.cpp
index faac72bd986..2c831f2b2b6 100644
--- a/yt/yt/core/rpc/throttling_channel.cpp
+++ b/yt/yt/core/rpc/throttling_channel.cpp
@@ -41,9 +41,8 @@ public:
.WithTimeout(timeout)
.Subscribe(BIND([=, this, this_ = MakeStrong(this)] (const TError& error) {
if (!error.IsOK()) {
- auto wrappedError = TError("Error throttling RPC request")
- << error;
- responseHandler->HandleError(wrappedError);
+ responseHandler->HandleError(TError("Error throttling RPC request")
+ << error);
return;
}