diff options
author | ilnaz <ilnaz@ydb.tech> | 2022-11-30 21:13:50 +0300 |
---|---|---|
committer | ilnaz <ilnaz@ydb.tech> | 2022-11-30 21:13:50 +0300 |
commit | 332b99e2173f0425444abb759eebcb2fafaa9209 (patch) | |
tree | cd63f9e6a6d54677d1dc84d43d9e2e0876dc7ce9 | |
parent | 3dfe99f4cc702156a58dce52df0cf2100c626241 (diff) | |
download | ydb-332b99e2173f0425444abb759eebcb2fafaa9209.tar.gz |
Move + TTL = <3
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp | 22 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_info_types.h | 11 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/ut_ttl.cpp | 24 |
3 files changed, 55 insertions, 2 deletions
diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp index dbd2a377da3..5452799d884 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp @@ -228,7 +228,7 @@ public: Y_VERIFY(!context.SS->Tables.contains(dstPath.Base()->PathId)); Y_VERIFY(context.SS->Tables.contains(srcPath.Base()->PathId)); - TTableInfo::TPtr tableInfo = new TTableInfo(*context.SS->Tables.at(srcPath.Base()->PathId)); + TTableInfo::TPtr tableInfo = TTableInfo::DeepCopy(*context.SS->Tables.at(srcPath.Base()->PathId)); tableInfo->ResetDescriptionCache(); tableInfo->AlterVersion += 1; @@ -400,15 +400,33 @@ public: TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); - TPath srcPath = TPath::Init(txState->SourcePathId, context.SS); + auto srcPath = TPath::Init(txState->SourcePathId, context.SS); + auto dstPath = TPath::Init(txState->TargetPathId, context.SS); Y_VERIFY(txState->PlanStep); MarkSrcDropped(db, context, OperationId, *txState, srcPath); + Y_VERIFY(context.SS->Tables.contains(dstPath.Base()->PathId)); + auto tableInfo = context.SS->Tables.at(dstPath.Base()->PathId); + + if (tableInfo->IsTTLEnabled() && !context.SS->TTLEnabledTables.contains(dstPath.Base()->PathId)) { + context.SS->TTLEnabledTables[dstPath.Base()->PathId] = tableInfo; + // MarkSrcDropped() removes srcPath from TTLEnabledTables & decrements the counters + context.SS->TabletCounters->Simple()[COUNTER_TTL_ENABLED_TABLE_COUNT].Add(1); + + const auto now = context.Ctx.Now(); + for (auto& shard : tableInfo->GetPartitions()) { + auto& lag = shard.LastCondEraseLag; + lag = now - shard.LastCondErase; + context.SS->TabletCounters->Percentile()[COUNTER_NUM_SHARDS_BY_TTL_LAG].IncrementFor(lag->Seconds()); + } + } + context.SS->ChangeTxState(db, OperationId, TTxState::ProposedWaitParts); return true; } + bool ProgressState(TOperationContext& context) override { TTabletId ssId = context.SS->SelfTabletId(); context.OnComplete.RouteByTabletsFromOperation(OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard_info_types.h b/ydb/core/tx/schemeshard/schemeshard_info_types.h index 0b3ff48a3c9..722518e3633 100644 --- a/ydb/core/tx/schemeshard/schemeshard_info_types.h +++ b/ydb/core/tx/schemeshard/schemeshard_info_types.h @@ -493,6 +493,17 @@ public: TableDescription.Swap(alterData.TableDescriptionFull.Get()); } + static TTableInfo::TPtr DeepCopy(const TTableInfo& other) { + TTableInfo::TPtr copy(new TTableInfo(other)); + // rebuild conditional erase schedule since it uses iterators + copy->CondEraseSchedule.clear(); + for (ui32 i = 0; i < copy->Partitions.size(); ++i) { + copy->CondEraseSchedule.push(copy->Partitions.begin() + i); + } + + return copy; + } + static TAlterDataPtr CreateAlterData( TPtr source, NKikimrSchemeOp::TTableDescription& descr, diff --git a/ydb/core/tx/schemeshard/ut_ttl.cpp b/ydb/core/tx/schemeshard/ut_ttl.cpp index 7dc846f2605..aa12857a154 100644 --- a/ydb/core/tx/schemeshard/ut_ttl.cpp +++ b/ydb/core/tx/schemeshard/ut_ttl.cpp @@ -995,6 +995,30 @@ Y_UNIT_TEST_SUITE(TSchemeShardTTLTests) { WaitForCondErase(runtime); WaitForStats(runtime, 2); CheckPercentileCounter(runtime, "SchemeShard/NumShardsByTtlLag", {{"900", 2}, {"1800", 0}, {"inf", 0}}); + + // move table + TestMoveTable(runtime, ++txId, "/MyRoot/TTLEnabledTable", "/MyRoot/TTLEnabledTableMoved"); + env.TestWaitNotification(runtime, txId); + + // just after move + CheckSimpleCounter(runtime, "SchemeShard/TTLEnabledTables", 1); + CheckPercentileCounter(runtime, "SchemeShard/NumShardsByTtlLag", {{"900", 2}, {"1800", 0}, {"inf", 0}}); + + // after a while + runtime.AdvanceCurrentTime(TDuration::Minutes(20)); + WaitForStats(runtime, 2); + CheckPercentileCounter(runtime, "SchemeShard/NumShardsByTtlLag", {{"900", 0}, {"1800", 2}, {"inf", 0}}); + + // after erase + runtime.AdvanceCurrentTime(TDuration::Minutes(40)); + WaitForCondErase(runtime); + WaitForStats(runtime, 2); + CheckPercentileCounter(runtime, "SchemeShard/NumShardsByTtlLag", {{"0", 2}, {"900", 0}, {"1800", 0}, {"inf", 0}}); + + // after a while + runtime.AdvanceCurrentTime(TDuration::Minutes(10)); + WaitForStats(runtime, 2); + CheckPercentileCounter(runtime, "SchemeShard/NumShardsByTtlLag", {{"900", 2}, {"1800", 0}, {"inf", 0}}); } } |