Skip to content

Commit 6a697fe

Browse files
committed
Added try catch
1 parent 998409c commit 6a697fe

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
139139
const TString& token)
140140
: TxId(txId)
141141
, Gateway(std::move(gateway))
142-
, AuthInfo(crdentials.GetAuthInfo())
142+
, Credentials(std::move(crdentials))
143143
, RetryPolicy(retryPolicy)
144144
, ActorSystem(TActivationContext::ActorSystem())
145145
, Key(key)
@@ -155,6 +155,9 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
155155
void Bootstrap(const TActorId& parentId) {
156156
ParentId = parentId;
157157
LOG_D("TS3FileWriteActor", "Bootstrap by " << ParentId << " for Key: [" << Key << "], Url: [" << Url << "], request id: [" << RequestId << "]");
158+
if (!UpdateAuthInfo()) {
159+
return;
160+
}
158161
if (DirtyWrite && Parts->IsSealed() && Parts->Size() <= 1) {
159162
Become(&TS3FileWriteActor::SinglepartWorkingStateFunc);
160163
const size_t size = Max<size_t>(Parts->Volume(), 1);
@@ -359,13 +362,27 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
359362
}
360363
}
361364

365+
bool UpdateAuthInfo() {
366+
try {
367+
AuthInfo = Credentials.GetAuthInfo();
368+
return true;
369+
}
370+
catch (const yexception& ex) {
371+
Send(ParentId, new TEvPrivate::TEvUploadError(NYql::NDqProto::StatusIds::BAD_REQUEST, TStringBuilder() << "Failed to get auth info: " << ex.what()));
372+
return false;
373+
}
374+
}
375+
362376
void StartUploadParts() {
363377
while (auto part = Parts->Pop()) {
364378
const auto size = part.size();
365379
const auto index = Tags.size();
366380
Tags.emplace_back();
367381
InFlight += size;
368382
SentSize += size;
383+
if (!UpdateAuthInfo()) {
384+
return;
385+
}
369386
Gateway->Upload(Url + "?partNumber=" + std::to_string(index + 1) + "&uploadId=" + UploadId,
370387
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), {}, AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
371388
std::move(part),
@@ -393,6 +410,9 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
393410
for (const auto& tag : Tags)
394411
xml << "<Part><PartNumber>" << ++i << "</PartNumber><ETag>" << tag << "</ETag></Part>" << Endl;
395412
xml << "</CompleteMultipartUpload>" << Endl;
413+
if (!UpdateAuthInfo()) {
414+
return;
415+
}
396416
Gateway->Upload(Url + "?uploadId=" + UploadId,
397417
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), "application/xml", AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
398418
xml,
@@ -409,6 +429,9 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
409429
return;
410430
}
411431

432+
if (!UpdateAuthInfo()) {
433+
return;
434+
}
412435
Gateway->Delete(Url + "?uploadId=" + UploadId,
413436
IHTTPGateway::MakeYcHeaders(RequestId, AuthInfo.GetToken(), "application/xml", AuthInfo.GetAwsUserPwd(), AuthInfo.GetAwsSigV4()),
414437
std::bind(&TS3FileWriteActor::OnMultipartUploadAbort, ActorSystem, SelfId(), TxId, RequestId, std::placeholders::_1),
@@ -421,7 +444,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
421444

422445
const TTxId TxId;
423446
const IHTTPGateway::TPtr Gateway;
424-
const TS3Credentials::TAuthInfo AuthInfo;
447+
const TS3Credentials Credentials;
425448
const IHTTPGateway::TRetryPolicy::TPtr RetryPolicy;
426449

427450
TActorSystem* const ActorSystem;
@@ -437,6 +460,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
437460
TString UploadId;
438461
bool DirtyWrite;
439462
TString Token;
463+
TS3Credentials::TAuthInfo AuthInfo;
440464
};
441465

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

0 commit comments

Comments
 (0)