diff options
author | bbiff <bbiff@yandex-team.com> | 2022-08-31 17:23:49 +0300 |
---|---|---|
committer | bbiff <bbiff@yandex-team.com> | 2022-08-31 17:23:49 +0300 |
commit | bc36654b8c3d511ea51c097d69ea9b1775a5b37e (patch) | |
tree | ecc2a6ea208f589a78a9391bb065927aa49ac3e7 | |
parent | 79a5c4b63f6732d9ba5358a7480feabf6b3c0916 (diff) | |
download | ydb-bc36654b8c3d511ea51c097d69ea9b1775a5b37e.tar.gz |
Revert commit rXXXXXX
-rw-r--r-- | ydb/library/yql/providers/common/http_gateway/yql_http_gateway.cpp | 4 | ||||
-rw-r--r-- | ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp | 76 |
2 files changed, 27 insertions, 53 deletions
diff --git a/ydb/library/yql/providers/common/http_gateway/yql_http_gateway.cpp b/ydb/library/yql/providers/common/http_gateway/yql_http_gateway.cpp index 6e230f8591..e31a8d9686 100644 --- a/ydb/library/yql/providers/common/http_gateway/yql_http_gateway.cpp +++ b/ydb/library/yql/providers/common/http_gateway/yql_http_gateway.cpp @@ -113,8 +113,8 @@ public: byteRange << Offset + expectedSize - 1; } curl_easy_setopt(Handle, CURLOPT_RANGE, byteRange.c_str()); - curl_easy_setopt(Handle, CURLOPT_WRITEFUNCTION, &WriteMemoryCallback); - curl_easy_setopt(Handle, CURLOPT_WRITEDATA, static_cast<void*>(this)); + curl_easy_setopt(Handle, EMethod::PUT == method ? CURLOPT_HEADERFUNCTION : CURLOPT_WRITEFUNCTION, &WriteMemoryCallback); + curl_easy_setopt(Handle, EMethod::PUT == method ? CURLOPT_HEADERDATA :CURLOPT_WRITEDATA, static_cast<void*>(this)); if (method == EMethod::POST) { curl_easy_setopt(Handle, CURLOPT_POSTFIELDSIZE, bodySize); } diff --git a/ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp b/ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp index 4db191fa85..641a7c4f6b 100644 --- a/ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp +++ b/ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp @@ -137,46 +137,24 @@ private: hFunc(TEvPrivate::TEvUploadPartFinished, Handle); ) - static std::optional<NXml::TConstNode> TryParseXmlResponse(const TString& response, TActorId parentId, TActorId selfId, TActorSystem* actorSystem, const TString& errorAvantMessage = "") { - try { - const NXml::TDocument xml(response, NXml::TDocument::String); - const auto& root = xml.Root(); - if (root.Name() == "Error") { - auto errorCode = root.Node("Code", true).Value<TString>(); - auto errorText = root.Node("Message", true).Value<TString>(); - actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << errorAvantMessage << "Error code: '" << errorCode << ". Description: " << errorText)}))); - } - return root; - } catch(const std::exception& ex) { - actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << errorAvantMessage << "Error while parsing xml: '" << ex.what())}))); - } - return std::nullopt; - } - - static std::optional<NXml::TConstNode> TryParseXmlResponse(IHTTPGateway::TResult response, TActorId parentId, TActorId selfId, TActorSystem* actorSystem, const TString& errorAvantMessage = "") { - return TryParseXmlResponse(std::get<IHTTPGateway::TContent>(response).Extract(), parentId, selfId, actorSystem, errorAvantMessage); - } - static void OnUploadsCreated(TActorSystem* actorSystem, TActorId selfId, TActorId parentId, IHTTPGateway::TResult&& result) { switch (result.index()) { - case 0U: { - auto maybeRoot = TryParseXmlResponse(std::move(result), parentId, selfId, actorSystem, "create upload error: "); - if (!maybeRoot || maybeRoot->Name() == "Error") { - break; - } - auto root = *maybeRoot; - if (root.Name() != "InitiateMultipartUploadResult") + case 0U: try { + const NXml::TDocument xml(std::get<IHTTPGateway::TContent>(std::move(result)).Extract(), NXml::TDocument::String); + if (const auto& root = xml.Root(); root.Name() == "Error") { + const auto& code = root.Node("Code", true).Value<TString>(); + const auto& message = root.Node("Message", true).Value<TString>(); + actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << message << ", error: code: " << code)}))); + } else if (root.Name() != "InitiateMultipartUploadResult") actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Unexpected response '" << root.Name() << "' on create upload.")}))); else { const NXml::TNamespacesForXPath nss(1U, {"s3", "http://s3.amazonaws.com/doc/2006-03-01/"}); - try { - actorSystem->Send(new IEventHandle(selfId, selfId, new TEvPrivate::TEvUploadStarted(root.Node("s3:UploadId", false, nss).Value<TString>()))); - } catch (const std::exception& ex) { - actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Error '" << ex.what() << "' on parse create upload response.")}))); - break; - } + actorSystem->Send(new IEventHandle(selfId, selfId, new TEvPrivate::TEvUploadStarted(root.Node("s3:UploadId", false, nss).Value<TString>()))); } break; + } catch (const std::exception& ex) { + actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Error '" << ex.what() << "' on parse create upload response.")}))); + break; } case 1U: actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError(std::get<TIssues>(std::move(result))))); @@ -198,11 +176,7 @@ private: break; } } - - if (!TryParseXmlResponse(str, parentId, selfId, actorSystem, "upload part error: ")) { - actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Unexpected response: " << str)}))); - } - + actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Unexpected response:" << Endl << str)}))); break; } case 1U: @@ -213,18 +187,19 @@ private: static void OnMultipartUploadFinish(TActorSystem* actorSystem, TActorId selfId, TActorId parentId, const TString& key, const TString& url, IHTTPGateway::TResult&& result) { switch (result.index()) { - case 0U: { - - auto maybeRoot = TryParseXmlResponse(std::move(result), parentId, selfId, actorSystem, "upload error: "); - if (!maybeRoot || maybeRoot->Name() == "Error") { - break; - } - auto root = *maybeRoot; - if (root.Name() != "CompleteMultipartUploadResult") { + case 0U: try { + const NXml::TDocument xml(std::get<IHTTPGateway::TContent>(std::move(result)).Extract(), NXml::TDocument::String); + if (const auto& root = xml.Root(); root.Name() == "Error") { + const auto& code = root.Node("Code", true).Value<TString>(); + const auto& message = root.Node("Message", true).Value<TString>(); + actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << message << ", error: code: " << code)}))); + } else if (root.Name() != "CompleteMultipartUploadResult") actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Unexpected response '" << root.Name() << "' on finish upload.")}))); - } else { + else actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadFinished(key, url))); - } + break; + } catch (const std::exception& ex) { + actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "Error '" << ex.what() << "' on parse finish upload response.")}))); break; } case 1U: @@ -242,9 +217,7 @@ private: { auto content = std::get<IHTTPGateway::TContent>(std::move(result)); if (content.HttpResponseCode >= 300) { - if (!TryParseXmlResponse(content.Extract(), parentId, selfId, actorSystem, "upload error: ")) { - actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "HTTP error code: " << content.HttpResponseCode << ". Response: " << content.data())}))); - } + actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadError({TIssue(TStringBuilder() << "HTTP error code: " << content.HttpResponseCode)}))); } else { actorSystem->Send(new IEventHandle(parentId, selfId, new TEvPrivate::TEvUploadFinished(key, url))); } @@ -402,6 +375,7 @@ private: ins.first->second.emplace_back(fileWrite.get()); RegisterWithSameMailbox(fileWrite.release()); } + ins.first->second.back()->SendData(TString((Keys.empty() ? v : *v.GetElements()).AsStringRef())); } |