Skip to content

Commit 8db2d76

Browse files
committed
Removed field AuthInfo
1 parent dad179d commit 8db2d76

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp

+44-32
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,37 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
148148
, Parts(MakeCompressorQueue(compression))
149149
, DirtyWrite(dirtyWrite)
150150
, Token(token)
151-
, AuthInfo(Credentials.GetAuthInfo())
152151
{
153152
YQL_ENSURE(Parts, "Compression '" << compression << "' is not supported.");
154153
}
155154

156155
void Bootstrap(const TActorId& parentId) {
157156
ParentId = parentId;
158157
LOG_D("TS3FileWriteActor", "Bootstrap by " << ParentId << " for Key: [" << Key << "], Url: [" << Url << "], request id: [" << RequestId << "]");
158+
try {
159+
BeginPartsUpload(Credentials.GetAuthInfo());
160+
}
161+
catch (const yexception& ex) {
162+
FailOnException();
163+
}
164+
}
165+
166+
void BeginPartsUpload(const TS3Credentials::TAuthInfo& authInfo) {
159167
if (DirtyWrite && Parts->IsSealed() && Parts->Size() <= 1) {
160-
Become(&TS3FileWriteActor::SinglepartWorkingStateFunc);
168+
Become(&TS3FileWriteActor::StateFuncWrapper<&TS3FileWriteActor::SinglepartWorkingStateFunc>);
161169
const size_t size = Max<size_t>(Parts->Volume(), 1);
162170
InFlight += size;
163171
SentSize += size;
164172
Gateway->Upload(Url,
165-
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), {}, AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
173+
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), {}, authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
166174
Parts->Pop(),
167175
std::bind(&TS3FileWriteActor::OnUploadFinish, ActorSystem, SelfId(), ParentId, Key, Url, RequestId, size, std::placeholders::_1),
168176
true,
169177
RetryPolicy);
170178
} else {
171-
Become(&TS3FileWriteActor::MultipartInitialStateFunc);
179+
Become(&TS3FileWriteActor::StateFuncWrapper<&TS3FileWriteActor::MultipartInitialStateFunc>);
172180
Gateway->Upload(Url + "?uploads",
173-
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), {}, AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
181+
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), {}, authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
174182
0,
175183
std::bind(&TS3FileWriteActor::OnUploadsCreated, ActorSystem, SelfId(), ParentId, RequestId, std::placeholders::_1),
176184
false,
@@ -186,7 +194,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
186194

187195
void PassAway() override {
188196
if (InFlight || !Parts->Empty()) {
189-
AbortMultipartUpload();
197+
SafeAbortMultipartUpload();
190198
LOG_W("TS3FileWriteActor", "PassAway: but NOT finished, InFlight: " << InFlight << ", Parts: " << Parts->Size() << ", Sealed: " << Parts->IsSealed() << ", request id: [" << RequestId << "]");
191199
} else {
192200
LOG_D("TS3FileWriteActor", "PassAway: request id: [" << RequestId << "]");
@@ -236,6 +244,15 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
236244
return InFlight + Parts->Volume();
237245
}
238246
private:
247+
template <void (TS3FileWriteActor::* DelegatedStateFunc)(STFUNC_SIG)>
248+
STFUNC(StateFuncWrapper) {
249+
try {
250+
(this->*DelegatedStateFunc)(ev);
251+
} catch (...) {
252+
FailOnException();
253+
}
254+
}
255+
239256
STRICT_STFUNC(MultipartInitialStateFunc,
240257
hFunc(TEvPrivate::TEvUploadStarted, Handle);
241258
)
@@ -347,7 +364,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
347364

348365
void Handle(TEvPrivate::TEvUploadStarted::TPtr& result) {
349366
UploadId = result->Get()->UploadId;
350-
Become(&TS3FileWriteActor::MultipartWorkingStateFunc);
367+
Become(&TS3FileWriteActor::StateFuncWrapper<&TS3FileWriteActor::MultipartWorkingStateFunc>);
351368
StartUploadParts();
352369
}
353370

@@ -360,29 +377,16 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
360377
}
361378
}
362379

363-
bool UpdateAuthInfo() {
364-
try {
365-
AuthInfo = Credentials.GetAuthInfo();
366-
return true;
367-
}
368-
catch (const yexception& ex) {
369-
Send(ParentId, new TEvPrivate::TEvUploadError(NYql::NDqProto::StatusIds::BAD_REQUEST, TStringBuilder() << "Failed to get auth info: " << ex.what()));
370-
return false;
371-
}
372-
}
373-
374380
void StartUploadParts() {
375381
while (auto part = Parts->Pop()) {
376382
const auto size = part.size();
377383
const auto index = Tags.size();
378384
Tags.emplace_back();
379385
InFlight += size;
380386
SentSize += size;
381-
if (!UpdateAuthInfo()) {
382-
return;
383-
}
387+
auto authInfo = Credentials.GetAuthInfo();
384388
Gateway->Upload(Url + "?partNumber=" + std::to_string(index + 1) + "&uploadId=" + UploadId,
385-
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), {}, AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
389+
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), {}, authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
386390
std::move(part),
387391
std::bind(&TS3FileWriteActor::OnPartUploadFinish, ActorSystem, SelfId(), ParentId, size, index, RequestId, std::placeholders::_1),
388392
true,
@@ -408,35 +412,44 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
408412
for (const auto& tag : Tags)
409413
xml << "<Part><PartNumber>" << ++i << "</PartNumber><ETag>" << tag << "</ETag></Part>" << Endl;
410414
xml << "</CompleteMultipartUpload>" << Endl;
411-
if (!UpdateAuthInfo()) {
412-
return;
413-
}
415+
auto authInfo = Credentials.GetAuthInfo();
414416
Gateway->Upload(Url + "?uploadId=" + UploadId,
415-
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), "application/xml", AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
417+
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), "application/xml", authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
416418
xml,
417419
std::bind(&TS3FileWriteActor::OnMultipartUploadFinish, ActorSystem, SelfId(), ParentId, Key, Url, RequestId, SentSize, std::placeholders::_1),
418420
false,
419421
RetryPolicy);
420422
}
421423

422-
void AbortMultipartUpload() {
424+
void SafeAbortMultipartUpload() {
425+
try {
426+
AbortMultipartUpload(Credentials.GetAuthInfo());
427+
}
428+
catch (const yexception& ex) {
429+
LOG_W("TS3FileWriteActor", "Failed to abort multipart upload, error: " << CurrentExceptionMessage());
430+
}
431+
}
432+
433+
void AbortMultipartUpload(const TS3Credentials::TAuthInfo& authInfo) {
423434
// Try to abort multipart upload in case of unexpected termination.
424435
// In case of error just logs warning.
425436

426437
if (!UploadId) {
427438
return;
428439
}
429440

430-
if (!UpdateAuthInfo()) {
431-
return;
432-
}
433441
Gateway->Delete(Url + "?uploadId=" + UploadId,
434-
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), "application/xml", AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
442+
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), "application/xml", authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
435443
std::bind(&TS3FileWriteActor::OnMultipartUploadAbort, ActorSystem, SelfId(), TxId, RequestId, std::placeholders::_1),
436444
RetryPolicy);
437445
UploadId.clear();
438446
}
439447

448+
void FailOnException() {
449+
Send(ParentId, new TEvPrivate::TEvUploadError(NYql::NDqProto::StatusIds::BAD_REQUEST, CurrentExceptionMessage()));
450+
SafeAbortMultipartUpload();
451+
}
452+
440453
size_t InFlight = 0ULL;
441454
size_t SentSize = 0ULL;
442455

@@ -458,7 +471,6 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
458471
TString UploadId;
459472
bool DirtyWrite;
460473
TString Token;
461-
TS3Credentials::TAuthInfo AuthInfo;
462474
};
463475

464476
class TS3WriteActor : public TActorBootstrapped<TS3WriteActor>, public IDqComputeActorAsyncOutput {

0 commit comments

Comments
 (0)