Skip to content

Commit 1b9117e

Browse files
authored
Handle unhandled exceptions during build index on SchemeShard (#19246)
1 parent ee494fe commit 1b9117e

9 files changed

+365
-134
lines changed

ydb/core/tx/schemeshard/schemeshard_build_index__cancel.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using namespace NTabletFlatExecutor;
1010
struct TSchemeShard::TIndexBuilder::TTxCancel: public TSchemeShard::TIndexBuilder::TTxSimple<TEvIndexBuilder::TEvCancelRequest, TEvIndexBuilder::TEvCancelResponse> {
1111
public:
1212
explicit TTxCancel(TSelf* self, TEvIndexBuilder::TEvCancelRequest::TPtr& ev)
13-
: TTxSimple(self, ev, TXTYPE_CANCEL_INDEX_BUILD)
13+
: TTxSimple(self, TIndexBuildId(ev->Get()->Record.GetIndexBuildId()), ev, TXTYPE_CANCEL_INDEX_BUILD)
1414
{}
1515

1616
bool DoExecute(TTransactionContext& txc, const TActorContext&) override {
@@ -27,40 +27,39 @@ struct TSchemeShard::TIndexBuilder::TTxCancel: public TSchemeShard::TIndexBuilde
2727
}
2828
const TPathId domainPathId = database.GetPathIdForDomain();
2929

30-
TIndexBuildId indexBuildId = TIndexBuildId(record.GetIndexBuildId());
31-
const auto* indexBuildInfoPtr = Self->IndexBuilds.FindPtr(indexBuildId);
30+
const auto* indexBuildInfoPtr = Self->IndexBuilds.FindPtr(BuildId);
3231
if (!indexBuildInfoPtr) {
3332
return Reply(
3433
Ydb::StatusIds::NOT_FOUND,
35-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> not found"
34+
TStringBuilder() << "Index build process with id <" << BuildId << "> not found"
3635
);
3736
}
3837
auto& indexBuildInfo = *indexBuildInfoPtr->Get();
3938
if (indexBuildInfo.DomainPathId != domainPathId) {
4039
return Reply(
4140
Ydb::StatusIds::NOT_FOUND,
42-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> not found in database <" << record.GetDatabaseName() << ">"
41+
TStringBuilder() << "Index build process with id <" << BuildId << "> not found in database <" << record.GetDatabaseName() << ">"
4342
);
4443
}
4544

4645
if (indexBuildInfo.IsFinished()) {
4746
return Reply(
4847
Ydb::StatusIds::PRECONDITION_FAILED,
49-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> has been finished already"
48+
TStringBuilder() << "Index build process with id <" << BuildId << "> has been finished already"
5049
);
5150
}
5251

5352
if (indexBuildInfo.IsCancellationRequested()) {
5453
return Reply(
5554
Ydb::StatusIds::PRECONDITION_FAILED,
56-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> canceling already"
55+
TStringBuilder() << "Index build process with id <" << BuildId << "> canceling already"
5756
);
5857
}
5958

6059
if (indexBuildInfo.State > TIndexBuildInfo::EState::Filling) {
6160
return Reply(
6261
Ydb::StatusIds::PRECONDITION_FAILED,
63-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> are almost done, cancellation has no sense"
62+
TStringBuilder() << "Index build process with id <" << BuildId << "> are almost done, cancellation has no sense"
6463
);
6564
}
6665

ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace NTabletFlatExecutor;
1414
class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder::TTxSimple<TEvIndexBuilder::TEvCreateRequest, TEvIndexBuilder::TEvCreateResponse> {
1515
public:
1616
explicit TTxCreate(TSelf* self, TEvIndexBuilder::TEvCreateRequest::TPtr& ev)
17-
: TTxSimple(self, ev, TXTYPE_CREATE_INDEX_BUILD)
17+
: TTxSimple(self, TIndexBuildId(ev->Get()->Record.GetTxId()), ev, TXTYPE_CREATE_INDEX_BUILD)
1818
{}
1919

2020
bool DoExecute(TTransactionContext& txc, const TActorContext& ctx) override {
@@ -24,10 +24,9 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
2424

2525
Response = MakeHolder<TEvIndexBuilder::TEvCreateResponse>(request.GetTxId());
2626

27-
const auto id = TIndexBuildId(request.GetTxId());
28-
if (Self->IndexBuilds.contains(id)) {
27+
if (Self->IndexBuilds.contains(BuildId)) {
2928
return Reply(Ydb::StatusIds::ALREADY_EXISTS, TStringBuilder()
30-
<< "Index build with id '" << id << "' already exists");
29+
<< "Index build with id '" << BuildId << "' already exists");
3130
}
3231

3332
const TString& uid = GetUid(request.GetOperationParams());
@@ -83,7 +82,7 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
8382
}
8483
}
8584

86-
TIndexBuildInfo::TPtr buildInfo = new TIndexBuildInfo(id, uid);
85+
TIndexBuildInfo::TPtr buildInfo = new TIndexBuildInfo(BuildId, uid);
8786
buildInfo->DomainPathId = domainPath.Base()->PathId;
8887
buildInfo->TablePathId = tablePath.Base()->PathId;
8988

@@ -198,14 +197,14 @@ class TSchemeShard::TIndexBuilder::TTxCreate: public TSchemeShard::TIndexBuilder
198197

199198
Self->PersistBuildIndexState(db, *buildInfo);
200199

201-
auto [it, emplaced] = Self->IndexBuilds.emplace(id, buildInfo);
200+
auto [it, emplaced] = Self->IndexBuilds.emplace(BuildId, buildInfo);
202201
Y_ASSERT(emplaced);
203202
if (uid) {
204203
std::tie(std::ignore, emplaced) = Self->IndexBuildsByUid.emplace(uid, buildInfo);
205204
Y_ASSERT(emplaced);
206205
}
207206

208-
Progress(id);
207+
Progress(BuildId);
209208

210209
return true;
211210
}

ydb/core/tx/schemeshard/schemeshard_build_index__forget.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using namespace NTabletFlatExecutor;
1010
struct TSchemeShard::TIndexBuilder::TTxForget: public TSchemeShard::TIndexBuilder::TTxSimple<TEvIndexBuilder::TEvForgetRequest, TEvIndexBuilder::TEvForgetResponse> {
1111
public:
1212
explicit TTxForget(TSelf* self, TEvIndexBuilder::TEvForgetRequest::TPtr& ev)
13-
: TTxSimple(self, ev, TXTYPE_FORGET_INDEX_BUILD)
13+
: TTxSimple(self, TIndexBuildId(ev->Get()->Record.GetIndexBuildId()), ev, TXTYPE_FORGET_INDEX_BUILD)
1414
{}
1515

1616
bool DoExecute(TTransactionContext& txc, const TActorContext&) override {
@@ -27,26 +27,25 @@ struct TSchemeShard::TIndexBuilder::TTxForget: public TSchemeShard::TIndexBuilde
2727
}
2828
const TPathId domainPathId = database.GetPathIdForDomain();
2929

30-
TIndexBuildId indexBuildId = TIndexBuildId(record.GetIndexBuildId());
31-
const auto* indexBuildInfoPtr = Self->IndexBuilds.FindPtr(indexBuildId);
30+
const auto* indexBuildInfoPtr = Self->IndexBuilds.FindPtr(BuildId);
3231
if (!indexBuildInfoPtr) {
3332
return Reply(
3433
Ydb::StatusIds::NOT_FOUND,
35-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> not found"
34+
TStringBuilder() << "Index build process with id <" << BuildId << "> not found"
3635
);
3736
}
3837
const auto& indexBuildInfo = *indexBuildInfoPtr->Get();
3938
if (indexBuildInfo.DomainPathId != domainPathId) {
4039
return Reply(
4140
Ydb::StatusIds::NOT_FOUND,
42-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> not found in database <" << record.GetDatabaseName() << ">"
41+
TStringBuilder() << "Index build process with id <" << BuildId << "> not found in database <" << record.GetDatabaseName() << ">"
4342
);
4443
}
4544

4645
if (!indexBuildInfo.IsFinished()) {
4746
return Reply(
4847
Ydb::StatusIds::PRECONDITION_FAILED,
49-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> hasn't been finished yet"
48+
TStringBuilder() << "Index build process with id <" << BuildId << "> hasn't been finished yet"
5049
);
5150
}
5251

ydb/core/tx/schemeshard/schemeshard_build_index__get.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using namespace NTabletFlatExecutor;
1111
struct TSchemeShard::TIndexBuilder::TTxGet: public TSchemeShard::TIndexBuilder::TTxSimple<TEvIndexBuilder::TEvGetRequest, TEvIndexBuilder::TEvGetResponse> {
1212
public:
1313
explicit TTxGet(TSelf* self, TEvIndexBuilder::TEvGetRequest::TPtr& ev)
14-
: TTxSimple(self, ev, TXTYPE_GET_INDEX_BUILD, false)
14+
: TTxSimple(self, TIndexBuildId(ev->Get()->Record.GetIndexBuildId()), ev, TXTYPE_GET_INDEX_BUILD, false)
1515
{}
1616

1717
bool DoExecute(TTransactionContext&, const TActorContext&) override {
@@ -28,20 +28,18 @@ struct TSchemeShard::TIndexBuilder::TTxGet: public TSchemeShard::TIndexBuilder::
2828
}
2929
const TPathId domainPathId = database.GetPathIdForDomain();
3030

31-
TIndexBuildId indexBuildId = TIndexBuildId(record.GetIndexBuildId());
32-
33-
const auto* indexBuildInfoPtr = Self->IndexBuilds.FindPtr(indexBuildId);
31+
const auto* indexBuildInfoPtr = Self->IndexBuilds.FindPtr(BuildId);
3432
if (!indexBuildInfoPtr) {
3533
return Reply(
3634
Ydb::StatusIds::PRECONDITION_FAILED,
37-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> not found"
35+
TStringBuilder() << "Index build process with id <" << BuildId << "> not found"
3836
);
3937
}
4038
const auto& indexBuildInfo = *indexBuildInfoPtr->Get();
4139
if (indexBuildInfo.DomainPathId != domainPathId) {
4240
return Reply(
4341
Ydb::StatusIds::BAD_REQUEST,
44-
TStringBuilder() << "Index build process with id <" << indexBuildId << "> not found in database <" << record.GetDatabaseName() << ">"
42+
TStringBuilder() << "Index build process with id <" << BuildId << "> not found in database <" << record.GetDatabaseName() << ">"
4543
);
4644
}
4745

ydb/core/tx/schemeshard/schemeshard_build_index__list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct TSchemeShard::TIndexBuilder::TTxList: public TSchemeShard::TIndexBuilder:
1515
static constexpr ui64 DefaultPage = 1;
1616
public:
1717
explicit TTxList(TSelf* self, TEvIndexBuilder::TEvListRequest::TPtr& ev)
18-
: TTxSimple(self, ev, TXTYPE_LIST_INDEX_BUILD, false)
18+
: TTxSimple(self, InvalidIndexBuildId, ev, TXTYPE_LIST_INDEX_BUILD, false)
1919
{}
2020

2121
bool DoExecute(TTransactionContext&, const TActorContext&) override {

0 commit comments

Comments
 (0)