Skip to content

Commit 713e5bb

Browse files
correction (#3958)
1 parent 23734ba commit 713e5bb

File tree

10 files changed

+66
-62
lines changed

10 files changed

+66
-62
lines changed

ydb/core/tx/schemeshard/olap/manager/manager.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void TTablesStorage::OnAddObject(const TPathId& pathId, TColumnTableInfo::TPtr o
77
if (!!tieringId) {
88
PathsByTieringId[tieringId].emplace(pathId);
99
}
10-
for (auto&& s : object->ColumnShards) {
10+
for (auto&& s : object->GetColumnShards()) {
1111
TablesByShard[s].AddId(pathId);
1212
}
1313
}
@@ -24,7 +24,7 @@ void TTablesStorage::OnRemoveObject(const TPathId& pathId, TColumnTableInfo::TPt
2424
PathsByTieringId.erase(it);
2525
}
2626
}
27-
for (auto&& s : object->ColumnShards) {
27+
for (auto&& s : object->GetColumnShards()) {
2828
TablesByShard[s].RemoveId(pathId);
2929
}
3030
}
@@ -112,21 +112,6 @@ void TTablesStorage::TTableExtractedGuard::UseAlterDataVerified() {
112112
Object = alterInfo;
113113
}
114114

115-
bool TTablesStorage::TTableCreateOperator::InitShardingTablets(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, TOlapStoreInfo::ILayoutPolicy::TPtr layoutPolicy, bool& isNewGroup) const {
116-
if (!layoutPolicy->Layout(currentLayout, shardsCount, Object->ColumnShards, isNewGroup)) {
117-
ALS_ERROR(NKikimrServices::FLAT_TX_SCHEMESHARD) << "cannot layout new table with " << shardsCount << " shards";
118-
return false;
119-
}
120-
Object->Sharding.SetVersion(1);
121-
122-
Object->Sharding.MutableColumnShards()->Clear();
123-
Object->Sharding.MutableColumnShards()->Reserve(Object->ColumnShards.size());
124-
for (ui64 columnShard : Object->ColumnShards) {
125-
Object->Sharding.AddColumnShards(columnShard);
126-
}
127-
return true;
128-
}
129-
130115
std::unordered_set<TPathId> TTablesStorage::GetAllPathIds() const {
131116
std::unordered_set<TPathId> result;
132117
for (const auto& [pathId, _] : Tables) {

ydb/core/tx/schemeshard/olap/manager/manager.h

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class TTablesStorage {
4848
using TBase = TTableReadGuard;
4949
public:
5050
using TBase::TBase;
51-
bool InitShardingTablets(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, TOlapStoreInfo::ILayoutPolicy::TPtr layoutPolicy, bool& isNewGroup) const;
5251
};
5352

5453
class TTableCreatedGuard: public TTableCreateOperator, TMoveOnly {

ydb/core/tx/schemeshard/olap/operations/alter_table.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class TAlterColumnTable: public TSubOperation {
577577
txState.State = TTxState::ConfigureParts;
578578

579579
// TODO: we need to know all shards where this table is currently active
580-
for (ui64 columnShardId : tableInfo->ColumnShards) {
580+
for (ui64 columnShardId : tableInfo->GetColumnShards()) {
581581
auto tabletId = TTabletId(columnShardId);
582582
auto shardIdx = context.SS->TabletIdToShardIdx.at(tabletId);
583583

ydb/core/tx/schemeshard/olap/operations/create_table.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class TConfigureParts: public TSubOperationState {
270270

271271
txState->ClearShardsInProgress();
272272

273-
Y_ABORT_UNLESS(tableInfo->ColumnShards.empty() || tableInfo->OwnedColumnShards.empty());
273+
Y_ABORT_UNLESS(tableInfo->GetColumnShards().empty() || tableInfo->OwnedColumnShards.empty());
274274

275275
TString columnShardTxBody;
276276
auto seqNo = context.SS->StartRound(*txState);
@@ -280,7 +280,7 @@ class TConfigureParts: public TSubOperationState {
280280
{
281281
NKikimrTxColumnShard::TCreateTable* create{};
282282
if (tableInfo->IsStandalone()) {
283-
Y_ABORT_UNLESS(tableInfo->ColumnShards.empty());
283+
Y_ABORT_UNLESS(tableInfo->GetColumnShards().empty());
284284
Y_ABORT_UNLESS(tableInfo->Description.HasSchema());
285285

286286
auto* init = tx.MutableInitShard();
@@ -392,11 +392,7 @@ class TPropose: public TSubOperationState {
392392

393393
auto table = context.SS->ColumnTables.TakeAlterVerified(pathId);
394394
if (table->IsStandalone()) {
395-
Y_ABORT_UNLESS(table->ColumnShards.empty());
396-
auto currentLayout = TColumnTablesLayout::BuildTrivial(TColumnTablesLayout::ShardIdxToTabletId(table->OwnedColumnShards, *context.SS));
397-
auto layoutPolicy = std::make_shared<TOlapStoreInfo::TMinimalTablesCountLayout>();
398-
bool isNewGroup;
399-
Y_ABORT_UNLESS(table.InitShardingTablets(currentLayout, table->OwnedColumnShards.size(), layoutPolicy, isNewGroup));
395+
table->SetColumnShards(TColumnTablesLayout::ShardIdxToTabletId(table->OwnedColumnShards, *context.SS));
400396
}
401397

402398
context.SS->PersistColumnTableAlterRemove(db, pathId);
@@ -584,7 +580,7 @@ class TCreateColumnTable: public TSubOperation {
584580
const auto acceptExisted = !Transaction.GetFailOnExist();
585581
const TString& parentPathStr = Transaction.GetWorkingDir();
586582

587-
// Copy CreateColumnTable for changes. Update defaut sharding if not set.
583+
// Copy CreateColumnTable for changes. Update default sharding if not set.
588584
auto createDescription = Transaction.GetCreateColumnTable();
589585
if (!createDescription.HasColumnShardCount()) {
590586
createDescription.SetColumnShardCount(TTableConstructorBase::DEFAULT_SHARDS_COUNT);
@@ -705,12 +701,12 @@ class TCreateColumnTable: public TSubOperation {
705701
tableInfo = tableConstructor.BuildTableInfo(errors);
706702
if (tableInfo) {
707703
auto layoutPolicy = storeInfo->GetTablesLayoutPolicy();
708-
auto currentLayout = context.SS->ColumnTables.GetTablesLayout(
709-
TColumnTablesLayout::ShardIdxToTabletId(storeInfo->GetColumnShards(), *context.SS));
710-
TTablesStorage::TTableCreateOperator createOperator(tableInfo);
711-
if (!createOperator.InitShardingTablets(currentLayout, shardsCount, layoutPolicy, needUpdateObject)) {
712-
result->SetError(NKikimrScheme::StatusPreconditionFailed,
713-
"cannot layout table by shards");
704+
auto currentLayout = context.SS->ColumnTables.GetTablesLayout(TColumnTablesLayout::ShardIdxToTabletId(storeInfo->GetColumnShards(), *context.SS));
705+
auto layoutConclusion = layoutPolicy->Layout(currentLayout, shardsCount);
706+
needUpdateObject = layoutConclusion->GetIsNewGroup();
707+
tableInfo->SetColumnShards(std::move(layoutConclusion->MutableTabletIds()));
708+
if (layoutConclusion.IsFail()) {
709+
result->SetError(NKikimrScheme::StatusPreconditionFailed, layoutConclusion.GetErrorMessage());
714710
return result;
715711
}
716712
}
@@ -746,9 +742,9 @@ class TCreateColumnTable: public TSubOperation {
746742
auto olapStorePath = parentPath.FindOlapStore();
747743

748744
txState.State = TTxState::ConfigureParts;
749-
txState.Shards.reserve(tableInfo->ColumnShards.size());
745+
txState.Shards.reserve(tableInfo->GetColumnShards().size());
750746

751-
for (ui64 columnShardId : tableInfo->ColumnShards) {
747+
for (ui64 columnShardId : tableInfo->GetColumnShards()) {
752748
auto tabletId = TTabletId(columnShardId);
753749
auto shardIdx = context.SS->TabletIdToShardIdx.at(tabletId);
754750
TShardInfo& shardInfo = context.SS->ShardInfos.at(shardIdx);

ydb/core/tx/schemeshard/olap/operations/drop_table.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class TDropColumnTable: public TSubOperation {
452452
context.SS->PersistLastTxId(db, storePath.Base());
453453

454454
// TODO: we need to know all shards where this table has ever been created
455-
for (ui64 columnShardId : tableInfo->ColumnShards) {
455+
for (ui64 columnShardId : tableInfo->GetColumnShards()) {
456456
auto tabletId = TTabletId(columnShardId);
457457
auto shardIdx = context.SS->TabletIdToShardIdx.at(tabletId);
458458

ydb/core/tx/schemeshard/olap/store/store.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,30 @@
22

33
namespace NKikimr::NSchemeShard {
44

5-
bool TOlapStoreInfo::ILayoutPolicy::Layout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const {
6-
if (!DoLayout(currentLayout, shardsCount, result, isNewGroup)) {
7-
return false;
5+
TConclusion<TOlapStoreInfo::TLayoutInfo> TOlapStoreInfo::ILayoutPolicy::Layout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const {
6+
auto result = DoLayout(currentLayout, shardsCount);
7+
if (result.IsFail()) {
8+
return result;
89
}
9-
Y_ABORT_UNLESS(result.size() == shardsCount);
10-
return true;
10+
AFL_VERIFY(result->GetTabletIds().size() == shardsCount);
11+
return result;
1112
}
1213

13-
bool TOlapStoreInfo::TIdentityGroupsLayout::DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const {
14-
isNewGroup = false;
14+
TConclusion<TOlapStoreInfo::TLayoutInfo> TOlapStoreInfo::TIdentityGroupsLayout::DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const {
1515
for (auto&& i : currentLayout.GetGroups()) {
1616
if (i.GetTableIds().Size() == 0 && i.GetShardIds().Size() >= shardsCount) {
17-
result = i.GetShardIds().GetIdsVector(shardsCount);
18-
isNewGroup = true;
19-
return true;
17+
return TOlapStoreInfo::TLayoutInfo(i.GetShardIds().GetIdsVector(shardsCount), true);
2018
}
2119
if (i.GetShardIds().Size() != shardsCount) {
2220
continue;
2321
}
24-
result = i.GetShardIds().GetIdsVector();
25-
return true;
22+
return TOlapStoreInfo::TLayoutInfo(i.GetShardIds().GetIdsVector(), false);
2623
}
27-
return false;
24+
return TConclusionStatus::Fail("cannot find appropriate group for " + ::ToString(shardsCount) + " shards");
2825
}
2926

30-
bool TOlapStoreInfo::TMinimalTablesCountLayout::DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const {
31-
isNewGroup = true;
27+
TConclusion<TOlapStoreInfo::TLayoutInfo> TOlapStoreInfo::TMinimalTablesCountLayout::DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const {
28+
bool isNewGroup = true;
3229
std::vector<ui64> resultLocal;
3330
for (auto&& i : currentLayout.GetGroups()) {
3431
if (i.GetTableIds().Size() > 0) {
@@ -37,12 +34,11 @@ bool TOlapStoreInfo::TMinimalTablesCountLayout::DoLayout(const TColumnTablesLayo
3734
for (auto&& s : i.GetShardIds()) {
3835
resultLocal.emplace_back(s);
3936
if (resultLocal.size() == shardsCount) {
40-
std::swap(result, resultLocal);
41-
return true;
37+
return TOlapStoreInfo::TLayoutInfo(std::move(resultLocal), isNewGroup);
4238
}
4339
}
4440
}
45-
return false;
41+
return TConclusionStatus::Fail("cannot find appropriate group for " + ::ToString(shardsCount) + " shards");
4642
}
4743

4844
TOlapStoreInfo::TOlapStoreInfo(

ydb/core/tx/schemeshard/olap/store/store.h

+17-4
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,36 @@ struct TOlapStoreInfo {
1919
public:
2020
using TPtr = std::shared_ptr<TOlapStoreInfo>;
2121

22+
class TLayoutInfo {
23+
private:
24+
YDB_ACCESSOR_DEF(std::vector<ui64>, TabletIds);
25+
YDB_READONLY(bool, IsNewGroup, false);
26+
public:
27+
TLayoutInfo(std::vector<ui64>&& ids, const bool isNewGroup)
28+
: TabletIds(std::move(ids))
29+
, IsNewGroup(isNewGroup)
30+
{
31+
32+
}
33+
};
34+
2235
class ILayoutPolicy {
2336
protected:
24-
virtual bool DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const = 0;
37+
virtual TConclusion<TLayoutInfo> DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const = 0;
2538
public:
2639
using TPtr = std::shared_ptr<ILayoutPolicy>;
2740
virtual ~ILayoutPolicy() = default;
28-
bool Layout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const;
41+
TConclusion<TLayoutInfo> Layout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const;
2942
};
3043

3144
class TMinimalTablesCountLayout: public ILayoutPolicy {
3245
protected:
33-
virtual bool DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const override;
46+
virtual TConclusion<TLayoutInfo> DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const override;
3447
};
3548

3649
class TIdentityGroupsLayout: public ILayoutPolicy {
3750
protected:
38-
virtual bool DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount, std::vector<ui64>& result, bool& isNewGroup) const override;
51+
virtual TConclusion<TLayoutInfo> DoLayout(const TColumnTablesLayout& currentLayout, const ui32 shardsCount) const override;
3952
};
4053

4154
TPtr AlterData;

ydb/core/tx/schemeshard/olap/table/table.h

+17-2
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,35 @@
66
namespace NKikimr::NSchemeShard {
77

88
struct TColumnTableInfo {
9+
private:
10+
YDB_READONLY_DEF(std::vector<ui64>, ColumnShards);
11+
public:
912
using TPtr = std::shared_ptr<TColumnTableInfo>;
1013

1114
ui64 AlterVersion = 0;
1215
TPtr AlterData;
1316

17+
void SetColumnShards(std::vector<ui64>&& columnShards) {
18+
AFL_VERIFY(ColumnShards.empty());
19+
ColumnShards = std::move(columnShards);
20+
21+
Sharding.SetVersion(1);
22+
23+
Sharding.MutableColumnShards()->Clear();
24+
Sharding.MutableColumnShards()->Reserve(ColumnShards.size());
25+
for (ui64 columnShard : ColumnShards) {
26+
Sharding.AddColumnShards(columnShard);
27+
}
28+
}
29+
1430
NKikimrSchemeOp::TColumnTableDescription Description;
1531
NKikimrSchemeOp::TColumnTableSharding Sharding;
1632
TMaybe<NKikimrSchemeOp::TColumnStoreSharding> StandaloneSharding;
1733
TMaybe<NKikimrSchemeOp::TAlterColumnTable> AlterBody;
1834

1935
TMaybe<TPathId> OlapStorePathId; // PathId of the table store
2036

21-
TVector<ui64> ColumnShards; // Current list of column shards
22-
TVector<TShardIdx> OwnedColumnShards;
37+
std::vector<TShardIdx> OwnedColumnShards;
2338
TAggregatedStats Stats;
2439

2540
TColumnTableInfo() = default;

ydb/core/tx/schemeshard/schemeshard_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6682,7 +6682,7 @@ bool TSchemeShard::FillUniformPartitioning(TVector<TString>& rangeEnds, ui32 key
66826682
return true;
66836683
}
66846684

6685-
void TSchemeShard::SetPartitioning(TPathId pathId, const TVector<TShardIdx>& partitioning) {
6685+
void TSchemeShard::SetPartitioning(TPathId pathId, const std::vector<TShardIdx>& partitioning) {
66866686
if (AppData()->FeatureFlags.GetEnableSystemViews()) {
66876687
TVector<std::pair<ui64, ui64>> shardIndices;
66886688
shardIndices.reserve(partitioning.size());

ydb/core/tx/schemeshard/schemeshard_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class TSchemeShard
597597

598598
void DoShardsDeletion(const THashSet<TShardIdx>& shardIdx, const TActorContext& ctx);
599599

600-
void SetPartitioning(TPathId pathId, const TVector<TShardIdx>& partitioning);
600+
void SetPartitioning(TPathId pathId, const std::vector<TShardIdx>& partitioning);
601601
void SetPartitioning(TPathId pathId, TOlapStoreInfo::TPtr storeInfo);
602602
void SetPartitioning(TPathId pathId, TColumnTableInfo::TPtr tableInfo);
603603
void SetPartitioning(TPathId pathId, TTableInfo::TPtr tableInfo, TVector<TTableShardInfo>&& newPartitioning);

0 commit comments

Comments
 (0)