From 9ae9dabed629b6f3bc3ce765cc03da6b8b913cee Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Fri, 22 Mar 2024 15:56:10 +0300 Subject: [PATCH 01/10] Fixes --- ydb/core/protos/flat_scheme_op.proto | 1 + ydb/core/protos/tx_sequenceshard.proto | 1 + ...hard__operation_consistent_copy_tables.cpp | 12 +- .../schemeshard__operation_copy_sequence.cpp | 59 ++++++- ...schemeshard__operation_create_sequence.cpp | 1 + .../schemeshard_export_flow_proposals.cpp | 7 +- .../schemeshard_import_flow_proposals.cpp | 1 + .../tx/schemeshard/ut_helpers/helpers.cpp | 9 +- ydb/core/tx/schemeshard/ut_helpers/helpers.h | 8 +- ydb/core/tx/schemeshard/ut_helpers/ya.make | 1 + .../tx/schemeshard/ut_restore/ut_restore.cpp | 150 ++++++++++++++++++ ydb/core/tx/schemeshard/ut_restore/ya.make | 2 +- ydb/core/tx/sequenceshard/public/events.h | 5 + .../tx/sequenceshard/tx_create_sequence.cpp | 7 +- ydb/core/ydb_convert/table_description.cpp | 4 + ydb/public/api/protos/ydb_table.proto | 1 + 16 files changed, 250 insertions(+), 19 deletions(-) diff --git a/ydb/core/protos/flat_scheme_op.proto b/ydb/core/protos/flat_scheme_op.proto index 165b66347f7d..b4acbeb30f67 100644 --- a/ydb/core/protos/flat_scheme_op.proto +++ b/ydb/core/protos/flat_scheme_op.proto @@ -1305,6 +1305,7 @@ message TSequenceDescription { optional uint64 Cache = 8; // number of items to cache, defaults to 1 optional sint64 Increment = 9; // increment at each call, defaults to 1 optional bool Cycle = 10; // true when cycle on overflow is allowed + optional bool Overflowed = 11; // true when sequence is overflowed } message TSequenceSharding { diff --git a/ydb/core/protos/tx_sequenceshard.proto b/ydb/core/protos/tx_sequenceshard.proto index 0f13af504618..9d66eb35e3c7 100644 --- a/ydb/core/protos/tx_sequenceshard.proto +++ b/ydb/core/protos/tx_sequenceshard.proto @@ -40,6 +40,7 @@ message TEvCreateSequence { bool Cycle = 9; } bool Frozen = 10; // defaults to false + bool Overflowed = 11; // defaults to false } message TEvCreateSequenceResult { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_consistent_copy_tables.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_consistent_copy_tables.cpp index 88034eec52fb..c9b3a1ab0ca4 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_consistent_copy_tables.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_consistent_copy_tables.cpp @@ -137,10 +137,6 @@ TVector CreateConsistentCopyTables(TOperationId nextId, con result.push_back(CreateCopyTable(NextPartId(nextId, result), CopyTableTask(srcPath, dstPath, descr.GetOmitFollowers(), descr.GetIsBackup()), sequences)); - if (descr.GetOmitIndexes()) { - continue; - } - TVector sequenceDescriptions; for (const auto& child: srcPath.Base()->GetChildren()) { const auto& name = child.first; @@ -160,6 +156,10 @@ TVector CreateConsistentCopyTables(TOperationId nextId, con continue; } + if (descr.GetOmitIndexes()) { + continue; + } + if (!srcIndexPath.IsTableIndex()) { continue; } @@ -185,9 +185,11 @@ TVector CreateConsistentCopyTables(TOperationId nextId, con NKikimrSchemeOp::EOperationType::ESchemeOpCreateSequence); scheme.SetFailOnExist(true); + auto* copySequence = scheme.MutableCopySequence(); + copySequence->SetCopyFrom(srcPath.PathString() + "/" + sequenceDescription.GetName()); *scheme.MutableSequence() = std::move(sequenceDescription); - result.push_back(CreateNewSequence(NextPartId(nextId, result), scheme)); + result.push_back(CreateCopySequence(NextPartId(nextId, result), scheme)); } } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp index f1f408817e99..0013d9412b02 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp @@ -115,7 +115,7 @@ class TConfigureParts : public TSubOperationState { event->Record.SetFrozen(true); LOG_DEBUG_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, - "TCoptSequence TConfigureParts ProgressState" + "TCopySequence TConfigureParts ProgressState" << " sending TEvCreateSequence to tablet " << tabletId << " operationId# " << OperationId << " at tablet " << ssId); @@ -274,6 +274,50 @@ class TProposedCopySequence : public TSubOperationState { << " operationId#" << OperationId; } + void UpdateSequenceDescription(NKikimrSchemeOp::TSequenceDescription& descr) { + descr.SetStartValue(GetSequenceResult.GetNextValue()); + descr.SetMinValue(GetSequenceResult.GetMinValue()); + descr.SetMaxValue(GetSequenceResult.GetMaxValue()); + descr.SetCache(GetSequenceResult.GetCache()); + descr.SetIncrement(GetSequenceResult.GetIncrement()); + descr.SetCycle(GetSequenceResult.GetCycle()); + + i64 nextValue = GetSequenceResult.GetNextValue(); + i64 minValue = GetSequenceResult.GetMinValue(); + i64 maxValue = GetSequenceResult.GetMaxValue(); + bool cycle = GetSequenceResult.GetCycle(); + bool overflowed = false; + + if (GetSequenceResult.GetNextUsed()) { + i64 increment = GetSequenceResult.GetIncrement(); + if (increment > 0) { + ui64 delta = increment; + + if (nextValue < maxValue && ui64(maxValue) - ui64(nextValue) >= delta) { + nextValue += delta; + } else { + if (cycle) { + nextValue = minValue; + } + overflowed = true; + } + } else { + ui64 delta = -increment; + + if (nextValue > minValue && ui64(nextValue) - ui64(minValue) >= delta) { + nextValue -= delta; + } else { + if (cycle) { + nextValue = maxValue; + } + overflowed = true; + } + } + } + descr.SetStartValue(nextValue); + descr.SetOverflowed(overflowed); + } + public: TProposedCopySequence(TOperationId id) : OperationId(id) @@ -333,7 +377,15 @@ class TProposedCopySequence : public TSubOperationState { return false; } + TPathId pathId = txState->TargetPathId; + NIceDb::TNiceDb db(context.GetDB()); + + auto sequenceInfo = context.SS->Sequences.at(pathId); + UpdateSequenceDescription(sequenceInfo->Description); + + context.SS->PersistSequence(db, pathId, *sequenceInfo); + context.SS->ChangeTxState(db, OperationId, TTxState::Done); context.OnComplete.ActivateTx(OperationId); return true; @@ -387,7 +439,7 @@ class TProposedCopySequence : public TSubOperationState { return false; } - auto getSequenceResult = ev->Get()->Record; + GetSequenceResult = ev->Get()->Record; Y_ABORT_UNLESS(txState->Shards.size() == 1); for (auto shard : txState->Shards) { @@ -397,7 +449,8 @@ class TProposedCopySequence : public TSubOperationState { Y_ABORT_UNLESS(currentTabletId != InvalidTabletId); auto event = MakeHolder( - txState->TargetPathId, getSequenceResult); + txState->TargetPathId, GetSequenceResult); + event->Record.SetTxId(ui64(OperationId.GetTxId())); event->Record.SetTxPartId(OperationId.GetSubTxId()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp index 6c2a700a8a7f..144af06acb63 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp @@ -142,6 +142,7 @@ class TConfigureParts : public TSubOperationState { if (alterData->Description.HasCycle()) { event->Record.SetCycle(alterData->Description.GetCycle()); } + event->Record.SetOverflowed(alterData->Description.GetOverflowed()); LOG_DEBUG_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, "TCreateSequence TConfigureParts ProgressState" diff --git a/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp b/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp index e80f3b09f958..11ebc0fa4436 100644 --- a/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp @@ -106,8 +106,11 @@ THolder BackupPropose( task.SetNeedToBill(!exportInfo->UserSID || !ss->SystemBackupSIDs.contains(*exportInfo->UserSID)); const TPath sourcePath = TPath::Init(exportInfo->Items[itemIdx].SourcePathId, ss); - if (sourcePath.IsResolved()) { - task.MutableTable()->CopyFrom(GetTableDescription(ss, sourcePath.Base()->PathId)); + const TPath exportPathItem = exportPath.Child(ToString(itemIdx)); + if (sourcePath.IsResolved() && exportPathItem.IsResolved()) { + auto exportDescription = GetTableDescription(ss, exportPathItem.Base()->PathId); + exportDescription.MutableTable()->SetName(sourcePath.LeafName()); + task.MutableTable()->CopyFrom(exportDescription); } task.SetSnapshotStep(exportInfo->SnapshotStep); diff --git a/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp b/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp index 9b4f9ad1d573..7ab3804ed8c0 100644 --- a/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp @@ -72,6 +72,7 @@ THolder CreateTablePropose( if (fromSequence.has_cycle()) { seqDesc->SetCycle(fromSequence.cycle()); } + seqDesc->SetOverflowed(fromSequence.overflowed()); break; } diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp index c3e0c5a65ae9..4f8832022eb8 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp @@ -2362,16 +2362,17 @@ namespace NSchemeShardUT_Private { runtime.Send(new IEventHandle(NSequenceProxy::MakeSequenceProxyServiceID(), sender, request.Release())); } - i64 WaitNextValResult(TTestActorRuntime& runtime, const TActorId& sender) { + i64 WaitNextValResult( + TTestActorRuntime& runtime, const TActorId& sender, Ydb::StatusIds::StatusCode expectedStatus) { auto ev = runtime.GrabEdgeEventRethrow(sender); auto* msg = ev->Get(); - UNIT_ASSERT_VALUES_EQUAL(msg->Status, Ydb::StatusIds::SUCCESS); + UNIT_ASSERT_VALUES_EQUAL(msg->Status, expectedStatus); return msg->Value; } - i64 DoNextVal(TTestActorRuntime& runtime, const TString& path) { + i64 DoNextVal(TTestActorRuntime& runtime, const TString& path, Ydb::StatusIds::StatusCode expectedStatus) { auto sender = runtime.AllocateEdgeActor(0); SendNextValRequest(runtime, sender, path); - return WaitNextValResult(runtime, sender); + return WaitNextValResult(runtime, sender, expectedStatus); } } diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.h b/ydb/core/tx/schemeshard/ut_helpers/helpers.h index 1c2e5df68d4b..d3c79c0e6946 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.h +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.h @@ -553,7 +553,11 @@ namespace NSchemeShardUT_Private { void WriteRow(TTestActorRuntime& runtime, const ui64 txId, const TString& tablePath, int partitionIdx, const ui32 key, const TString& value, bool successIsExpected = true); void SendNextValRequest(TTestActorRuntime& runtime, const TActorId& sender, const TString& path); - i64 WaitNextValResult(TTestActorRuntime& runtime, const TActorId& sender); - i64 DoNextVal(TTestActorRuntime& runtime, const TString& path); + i64 WaitNextValResult( + TTestActorRuntime& runtime, const TActorId& sender, + Ydb::StatusIds::StatusCode expectedStatus = Ydb::StatusIds::SUCCESS); + i64 DoNextVal( + TTestActorRuntime& runtime, const TString& path, + Ydb::StatusIds::StatusCode expectedStatus = Ydb::StatusIds::SUCCESS); } //NSchemeShardUT_Private diff --git a/ydb/core/tx/schemeshard/ut_helpers/ya.make b/ydb/core/tx/schemeshard/ut_helpers/ya.make index 89f867d6c154..2ecbccf6990f 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/ya.make +++ b/ydb/core/tx/schemeshard/ut_helpers/ya.make @@ -17,6 +17,7 @@ PEERDIR( ydb/core/tx ydb/core/tx/datashard ydb/core/tx/schemeshard + ydb/core/tx/sequenceproxy ydb/core/tx/tx_allocator ydb/core/tx/tx_proxy ydb/public/lib/scheme_types diff --git a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp index f4658249fb8f..fdc6eaf41fca 100644 --- a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp +++ b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp @@ -955,6 +955,156 @@ value { UNIT_ASSERT_C(CheckDefaultFromSequence(table), "Invalid default value"); } + Y_UNIT_TEST(ShouldRestoreSequence) { + TPortManager portManager; + const ui16 port = portManager.GetPort(); + + TS3Mock s3Mock({}, TS3Mock::TSettings(port)); + UNIT_ASSERT(s3Mock.Start()); + + TTestBasicRuntime runtime; + TTestEnv env(runtime); + + ui64 txId = 100; + + runtime.SetLogPriority(NKikimrServices::DATASHARD_BACKUP, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::DATASHARD_RESTORE, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::IMPORT, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::SEQUENCEPROXY, NActors::NLog::PRI_TRACE); + + TestCreateIndexedTable(runtime, ++txId, "/MyRoot", R"( + TableDescription { + Name: "Original" + Columns { Name: "key" Type: "Uint64" DefaultFromSequence: "myseq" } + Columns { Name: "value" Type: "Uint64" } + KeyColumnNames: ["key"] + } + SequenceDescription { + Name: "myseq" + } + )"); + env.TestWaitNotification(runtime, txId); + + i64 value = DoNextVal(runtime, "/MyRoot/Original/myseq"); + UNIT_ASSERT_VALUES_EQUAL(value, 1); + + TestExport(runtime, ++txId, "/MyRoot", Sprintf(R"( + ExportToS3Settings { + endpoint: "localhost:%d" + scheme: HTTP + items { + source_path: "/MyRoot/Original" + destination_prefix: "" + } + } + )", port)); + env.TestWaitNotification(runtime, txId); + TestGetExport(runtime, txId, "/MyRoot"); + + TestImport(runtime, ++txId, "/MyRoot", Sprintf(R"( + ImportFromS3Settings { + endpoint: "localhost:%d" + scheme: HTTP + items { + source_prefix: "" + destination_path: "/MyRoot/Restored" + } + } + )", port)); + env.TestWaitNotification(runtime, txId); + TestGetImport(runtime, txId, "/MyRoot"); + + const auto desc = DescribePath(runtime, "/MyRoot/Restored", true, true); + UNIT_ASSERT_VALUES_EQUAL(desc.GetStatus(), NKikimrScheme::StatusSuccess); + + const auto& table = desc.GetPathDescription().GetTable(); + + value = DoNextVal(runtime, "/MyRoot/Restored/myseq", Ydb::StatusIds::SCHEME_ERROR); + UNIT_ASSERT_VALUES_EQUAL(value, 2); + + UNIT_ASSERT_C(CheckDefaultFromSequence(table), "Invalid default value"); + } + + Y_UNIT_TEST(ShouldRestoreSequenceWithOverflow) { + TPortManager portManager; + const ui16 port = portManager.GetPort(); + + TS3Mock s3Mock({}, TS3Mock::TSettings(port)); + UNIT_ASSERT(s3Mock.Start()); + + TTestBasicRuntime runtime; + TTestEnv env(runtime); + + ui64 txId = 100; + + runtime.SetLogPriority(NKikimrServices::DATASHARD_BACKUP, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::DATASHARD_RESTORE, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::EXPORT, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::IMPORT, NActors::NLog::PRI_TRACE); + runtime.SetLogPriority(NKikimrServices::SEQUENCEPROXY, NActors::NLog::PRI_TRACE); + + TestCreateIndexedTable(runtime, ++txId, "/MyRoot", R"( + TableDescription { + Name: "Original" + Columns { Name: "key" Type: "Uint64" DefaultFromSequence: "myseq" } + Columns { Name: "value" Type: "Uint64" } + KeyColumnNames: ["key"] + } + SequenceDescription { + Name: "myseq" + MinValue: 1 + MaxValue: 2 + } + )"); + env.TestWaitNotification(runtime, txId); + + i64 value = DoNextVal(runtime, "/MyRoot/Original/myseq"); + UNIT_ASSERT_VALUES_EQUAL(value, 1); + + value = DoNextVal(runtime, "/MyRoot/Original/myseq"); + UNIT_ASSERT_VALUES_EQUAL(value, 2); + + TestExport(runtime, ++txId, "/MyRoot", Sprintf(R"( + ExportToS3Settings { + endpoint: "localhost:%d" + scheme: HTTP + items { + source_path: "/MyRoot/Original" + destination_prefix: "" + } + } + )", port)); + env.TestWaitNotification(runtime, txId); + TestGetExport(runtime, txId, "/MyRoot"); + + TestImport(runtime, ++txId, "/MyRoot", Sprintf(R"( + ImportFromS3Settings { + endpoint: "localhost:%d" + scheme: HTTP + items { + source_prefix: "" + destination_path: "/MyRoot/Restored" + } + } + )", port)); + env.TestWaitNotification(runtime, txId); + TestGetImport(runtime, txId, "/MyRoot"); + + const auto desc = DescribePath(runtime, "/MyRoot/Restored", true, true); + UNIT_ASSERT_VALUES_EQUAL(desc.GetStatus(), NKikimrScheme::StatusSuccess); + + const auto& table = desc.GetPathDescription().GetTable(); + + value = DoNextVal(runtime, "/MyRoot/Restored/myseq"); + UNIT_ASSERT_VALUES_EQUAL(value, 2); + + value = DoNextVal(runtime, "/MyRoot/Restored/myseq"); + UNIT_ASSERT_VALUES_EQUAL(value, 2); + + UNIT_ASSERT_C(CheckDefaultFromSequence(table), "Invalid default value"); + } + Y_UNIT_TEST(ExportImportPg) { TTestBasicRuntime runtime; TTestEnv env(runtime, TTestEnvOptions().EnableTablePgTypes(true)); diff --git a/ydb/core/tx/schemeshard/ut_restore/ya.make b/ydb/core/tx/schemeshard/ut_restore/ya.make index 308dd73133fa..7044d4283b5e 100644 --- a/ydb/core/tx/schemeshard/ut_restore/ya.make +++ b/ydb/core/tx/schemeshard/ut_restore/ya.make @@ -21,7 +21,7 @@ PEERDIR( ydb/core/wrappers/ut_helpers ydb/core/ydb_convert ydb/library/yql/sql/pg - ydb/library/yql/parser/pg_wrapper + ydb/library/yql/parser/pg_wrapper ) SRCS( diff --git a/ydb/core/tx/sequenceshard/public/events.h b/ydb/core/tx/sequenceshard/public/events.h index 62187515d291..eb0dd1792e4c 100644 --- a/ydb/core/tx/sequenceshard/public/events.h +++ b/ydb/core/tx/sequenceshard/public/events.h @@ -104,6 +104,11 @@ namespace NSequenceShard { return std::move(*this); } + TBuilder&& SetOverflowed(bool overflowed) && { + Msg->Record.SetOverflowed(overflowed); + return std::move(*this); + } + THolder Done() && { return std::move(Msg); } diff --git a/ydb/core/tx/sequenceshard/tx_create_sequence.cpp b/ydb/core/tx/sequenceshard/tx_create_sequence.cpp index 38822c47c10e..c5c1dc6b5385 100644 --- a/ydb/core/tx/sequenceshard/tx_create_sequence.cpp +++ b/ydb/core/tx/sequenceshard/tx_create_sequence.cpp @@ -75,7 +75,9 @@ namespace NSequenceShard { } sequence.NextValue = sequence.StartValue; - sequence.NextUsed = false; + bool overflowed = msg->Record.GetOverflowed(); + sequence.NextUsed = overflowed; + if (msg->Record.OptionalCache_case() == NKikimrTxSequenceShard::TEvCreateSequence::kCache) { sequence.Cache = msg->Record.GetCache(); if (sequence.Cache < 1) { @@ -103,7 +105,8 @@ namespace NSequenceShard { << " Cache# " << sequence.Cache << " Increment# " << sequence.Increment << " Cycle# " << (sequence.Cycle ? "true" : "false") - << " State# " << (frozen ? "Frozen" : "Active")); + << " State# " << (frozen ? "Frozen" : "Active") + << " Overflowed# " << (overflowed ? "true" : "false")); return true; } diff --git a/ydb/core/ydb_convert/table_description.cpp b/ydb/core/ydb_convert/table_description.cpp index b60ccd52e64a..aee5f33cbe5a 100644 --- a/ydb/core/ydb_convert/table_description.cpp +++ b/ydb/core/ydb_convert/table_description.cpp @@ -1416,6 +1416,10 @@ void FillSequenceDescription(Ydb::Table::CreateTableRequest& out, const NKikimrS if (sequenceDescription.HasIncrement()) { fromSequence->set_increment(sequenceDescription.GetIncrement()); } + if (sequenceDescription.HasCycle()) { + fromSequence->set_cycle(sequenceDescription.GetCycle()); + } + fromSequence->set_overflowed(sequenceDescription.GetOverflowed()); break; } case Ydb::Table::ColumnMeta::kFromLiteral: { diff --git a/ydb/public/api/protos/ydb_table.proto b/ydb/public/api/protos/ydb_table.proto index 295b67c12777..cfcbc2d55b42 100644 --- a/ydb/public/api/protos/ydb_table.proto +++ b/ydb/public/api/protos/ydb_table.proto @@ -341,6 +341,7 @@ message SequenceDescription { optional uint64 cache = 5; // number of items to cache, defaults to 1 optional sint64 increment = 6; // increment at each call, defaults to 1 optional bool cycle = 7; // true when cycle on overflow is allowed + optional bool overflowed = 8; // true when sequence is overflowed } message ColumnMeta { From da7e50a88f0d01176c91bca732824dfe8bff0d26 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Fri, 22 Mar 2024 20:29:30 +0300 Subject: [PATCH 02/10] Fixes --- ydb/core/protos/flat_scheme_op.proto | 7 ++++++- ydb/public/api/protos/ydb_table.proto | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ydb/core/protos/flat_scheme_op.proto b/ydb/core/protos/flat_scheme_op.proto index b4acbeb30f67..8011f707481b 100644 --- a/ydb/core/protos/flat_scheme_op.proto +++ b/ydb/core/protos/flat_scheme_op.proto @@ -1293,6 +1293,11 @@ message TMoveIndex { optional bool AllowOverwrite = 4; } +message TSetVal { + optional sint64 NextValue = 1; + optional bool NextUsed = 2; +} + message TSequenceDescription { optional string Name = 1; // mandatory optional NKikimrProto.TPathID PathId = 2; // sequence path id, assigned by schemeshard @@ -1305,7 +1310,7 @@ message TSequenceDescription { optional uint64 Cache = 8; // number of items to cache, defaults to 1 optional sint64 Increment = 9; // increment at each call, defaults to 1 optional bool Cycle = 10; // true when cycle on overflow is allowed - optional bool Overflowed = 11; // true when sequence is overflowed + optional TSetVal SetVal = 11; // SetVal(NextValue, NextUsed) is executed atomically when creating } message TSequenceSharding { diff --git a/ydb/public/api/protos/ydb_table.proto b/ydb/public/api/protos/ydb_table.proto index cfcbc2d55b42..e81d10e66ae3 100644 --- a/ydb/public/api/protos/ydb_table.proto +++ b/ydb/public/api/protos/ydb_table.proto @@ -333,6 +333,11 @@ message TableProfile { CachingPolicy caching_policy = 7; } +message SetVal { + optional sint64 next_value = 1; + optional bool next_used = 2; +} + message SequenceDescription { optional string name = 1; // mandatorys optional sint64 min_value = 2; // minimum value, defaults to 1 or Min @@ -341,7 +346,7 @@ message SequenceDescription { optional uint64 cache = 5; // number of items to cache, defaults to 1 optional sint64 increment = 6; // increment at each call, defaults to 1 optional bool cycle = 7; // true when cycle on overflow is allowed - optional bool overflowed = 8; // true when sequence is overflowed + optional SetVal set_val = 8; // set_val(next_value, next_used) is executed atomically when creating } message ColumnMeta { From bc90b900c78c3db554cc302f8a618d01dfcf5fb4 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Mon, 25 Mar 2024 11:13:20 +0300 Subject: [PATCH 03/10] Fixes --- ydb/core/protos/tx_sequenceshard.proto | 9 ++++- .../schemeshard__operation_copy_sequence.cpp | 40 ++----------------- ...schemeshard__operation_create_sequence.cpp | 5 ++- .../schemeshard_import_flow_proposals.cpp | 6 ++- ydb/core/tx/sequenceshard/public/events.h | 5 --- .../tx/sequenceshard/tx_create_sequence.cpp | 14 ++++--- ydb/core/ydb_convert/table_description.cpp | 6 ++- 7 files changed, 35 insertions(+), 50 deletions(-) diff --git a/ydb/core/protos/tx_sequenceshard.proto b/ydb/core/protos/tx_sequenceshard.proto index 9d66eb35e3c7..ecad295a16eb 100644 --- a/ydb/core/protos/tx_sequenceshard.proto +++ b/ydb/core/protos/tx_sequenceshard.proto @@ -17,6 +17,11 @@ message TEvMarkSchemeShardPipe { uint64 Round = 3; } +message TSetVal { + sint64 NextValue = 1; + bool NextUsed = 2; +} + message TEvCreateSequence { NKikimrProto.TPathID PathId = 1; uint64 TxId = 2; @@ -40,7 +45,9 @@ message TEvCreateSequence { bool Cycle = 9; } bool Frozen = 10; // defaults to false - bool Overflowed = 11; // defaults to false + oneof OptionalSetVal { + TSetVal SetVal = 11; + } } message TEvCreateSequenceResult { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp index 0013d9412b02..b1232aa0d6a8 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp @@ -275,47 +275,15 @@ class TProposedCopySequence : public TSubOperationState { } void UpdateSequenceDescription(NKikimrSchemeOp::TSequenceDescription& descr) { - descr.SetStartValue(GetSequenceResult.GetNextValue()); + descr.SetStartValue(GetSequenceResult.GetStartValue()); descr.SetMinValue(GetSequenceResult.GetMinValue()); descr.SetMaxValue(GetSequenceResult.GetMaxValue()); descr.SetCache(GetSequenceResult.GetCache()); descr.SetIncrement(GetSequenceResult.GetIncrement()); descr.SetCycle(GetSequenceResult.GetCycle()); - - i64 nextValue = GetSequenceResult.GetNextValue(); - i64 minValue = GetSequenceResult.GetMinValue(); - i64 maxValue = GetSequenceResult.GetMaxValue(); - bool cycle = GetSequenceResult.GetCycle(); - bool overflowed = false; - - if (GetSequenceResult.GetNextUsed()) { - i64 increment = GetSequenceResult.GetIncrement(); - if (increment > 0) { - ui64 delta = increment; - - if (nextValue < maxValue && ui64(maxValue) - ui64(nextValue) >= delta) { - nextValue += delta; - } else { - if (cycle) { - nextValue = minValue; - } - overflowed = true; - } - } else { - ui64 delta = -increment; - - if (nextValue > minValue && ui64(nextValue) - ui64(minValue) >= delta) { - nextValue -= delta; - } else { - if (cycle) { - nextValue = maxValue; - } - overflowed = true; - } - } - } - descr.SetStartValue(nextValue); - descr.SetOverflowed(overflowed); + auto* setValMsg = descr.MutableSetVal(); + setValMsg->SetNextValue(GetSequenceResult.GetNextValue()); + setValMsg->SetNextUsed(GetSequenceResult.GetNextUsed()); } public: diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp index 144af06acb63..8745837bd96a 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp @@ -142,7 +142,10 @@ class TConfigureParts : public TSubOperationState { if (alterData->Description.HasCycle()) { event->Record.SetCycle(alterData->Description.GetCycle()); } - event->Record.SetOverflowed(alterData->Description.GetOverflowed()); + if (alterData->Description.HasSetVal()) { + event->Record.MutableSetVal()->SetNextValue(alterData->Description.GetSetVal().GetNextValue()); + event->Record.MutableSetVal()->SetNextUsed(alterData->Description.GetSetVal().GetNextUsed()); + } LOG_DEBUG_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, "TCreateSequence TConfigureParts ProgressState" diff --git a/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp b/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp index 7ab3804ed8c0..bed9631994bb 100644 --- a/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_import_flow_proposals.cpp @@ -72,7 +72,11 @@ THolder CreateTablePropose( if (fromSequence.has_cycle()) { seqDesc->SetCycle(fromSequence.cycle()); } - seqDesc->SetOverflowed(fromSequence.overflowed()); + if (fromSequence.has_set_val()) { + auto* setVal = seqDesc->MutableSetVal(); + setVal->SetNextUsed(fromSequence.set_val().next_used()); + setVal->SetNextValue(fromSequence.set_val().next_value()); + } break; } diff --git a/ydb/core/tx/sequenceshard/public/events.h b/ydb/core/tx/sequenceshard/public/events.h index eb0dd1792e4c..62187515d291 100644 --- a/ydb/core/tx/sequenceshard/public/events.h +++ b/ydb/core/tx/sequenceshard/public/events.h @@ -104,11 +104,6 @@ namespace NSequenceShard { return std::move(*this); } - TBuilder&& SetOverflowed(bool overflowed) && { - Msg->Record.SetOverflowed(overflowed); - return std::move(*this); - } - THolder Done() && { return std::move(Msg); } diff --git a/ydb/core/tx/sequenceshard/tx_create_sequence.cpp b/ydb/core/tx/sequenceshard/tx_create_sequence.cpp index c5c1dc6b5385..9b62968361ce 100644 --- a/ydb/core/tx/sequenceshard/tx_create_sequence.cpp +++ b/ydb/core/tx/sequenceshard/tx_create_sequence.cpp @@ -74,9 +74,14 @@ namespace NSequenceShard { sequence.Cycle = msg->Record.GetCycle(); } - sequence.NextValue = sequence.StartValue; - bool overflowed = msg->Record.GetOverflowed(); - sequence.NextUsed = overflowed; + + if (msg->Record.OptionalSetVal_case() == NKikimrTxSequenceShard::TEvCreateSequence::kSetVal) { + sequence.NextValue = msg->Record.GetSetVal().GetNextValue(); + sequence.NextUsed = msg->Record.GetSetVal().GetNextUsed(); + } else { + sequence.NextUsed = false; + sequence.NextValue = sequence.StartValue; + } if (msg->Record.OptionalCache_case() == NKikimrTxSequenceShard::TEvCreateSequence::kCache) { sequence.Cache = msg->Record.GetCache(); @@ -105,8 +110,7 @@ namespace NSequenceShard { << " Cache# " << sequence.Cache << " Increment# " << sequence.Increment << " Cycle# " << (sequence.Cycle ? "true" : "false") - << " State# " << (frozen ? "Frozen" : "Active") - << " Overflowed# " << (overflowed ? "true" : "false")); + << " State# " << (frozen ? "Frozen" : "Active")); return true; } diff --git a/ydb/core/ydb_convert/table_description.cpp b/ydb/core/ydb_convert/table_description.cpp index aee5f33cbe5a..fc8a40a8e8ad 100644 --- a/ydb/core/ydb_convert/table_description.cpp +++ b/ydb/core/ydb_convert/table_description.cpp @@ -1419,7 +1419,11 @@ void FillSequenceDescription(Ydb::Table::CreateTableRequest& out, const NKikimrS if (sequenceDescription.HasCycle()) { fromSequence->set_cycle(sequenceDescription.GetCycle()); } - fromSequence->set_overflowed(sequenceDescription.GetOverflowed()); + if (sequenceDescription.HasSetVal()) { + auto* setVal = fromSequence->mutable_set_val(); + setVal->set_next_used(sequenceDescription.GetSetVal().GetNextUsed()); + setVal->set_next_value(sequenceDescription.GetSetVal().GetNextValue()); + } break; } case Ydb::Table::ColumnMeta::kFromLiteral: { From 82d5b85eb1ff4ddf6bcc4825a338de5f8e566b85 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Mon, 25 Mar 2024 12:42:44 +0300 Subject: [PATCH 04/10] Fixes --- ydb/core/tx/schemeshard/ut_helpers/ya.make | 1 - ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ydb/core/tx/schemeshard/ut_helpers/ya.make b/ydb/core/tx/schemeshard/ut_helpers/ya.make index 2ecbccf6990f..89f867d6c154 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/ya.make +++ b/ydb/core/tx/schemeshard/ut_helpers/ya.make @@ -17,7 +17,6 @@ PEERDIR( ydb/core/tx ydb/core/tx/datashard ydb/core/tx/schemeshard - ydb/core/tx/sequenceproxy ydb/core/tx/tx_allocator ydb/core/tx/tx_proxy ydb/public/lib/scheme_types diff --git a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp index fdc6eaf41fca..19a41dd3e3c4 100644 --- a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp +++ b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp @@ -1020,7 +1020,7 @@ value { const auto& table = desc.GetPathDescription().GetTable(); - value = DoNextVal(runtime, "/MyRoot/Restored/myseq", Ydb::StatusIds::SCHEME_ERROR); + value = DoNextVal(runtime, "/MyRoot/Restored/myseq"); UNIT_ASSERT_VALUES_EQUAL(value, 2); UNIT_ASSERT_C(CheckDefaultFromSequence(table), "Invalid default value"); @@ -1096,10 +1096,7 @@ value { const auto& table = desc.GetPathDescription().GetTable(); - value = DoNextVal(runtime, "/MyRoot/Restored/myseq"); - UNIT_ASSERT_VALUES_EQUAL(value, 2); - - value = DoNextVal(runtime, "/MyRoot/Restored/myseq"); + value = DoNextVal(runtime, "/MyRoot/Restored/myseq", Ydb::StatusIds::SCHEME_ERROR); UNIT_ASSERT_VALUES_EQUAL(value, 2); UNIT_ASSERT_C(CheckDefaultFromSequence(table), "Invalid default value"); From 4bfdd14264bd1f77ee8a9a812e2d0b90f4e1d37f Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Mon, 25 Mar 2024 13:36:52 +0300 Subject: [PATCH 05/10] Fixes --- ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp index 19a41dd3e3c4..c46eadac26ae 100644 --- a/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp +++ b/ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp @@ -1097,7 +1097,6 @@ value { const auto& table = desc.GetPathDescription().GetTable(); value = DoNextVal(runtime, "/MyRoot/Restored/myseq", Ydb::StatusIds::SCHEME_ERROR); - UNIT_ASSERT_VALUES_EQUAL(value, 2); UNIT_ASSERT_C(CheckDefaultFromSequence(table), "Invalid default value"); } From 111632b6a8f5a2afd71dbbc47fb97b686c078292 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Tue, 26 Mar 2024 15:21:29 +0300 Subject: [PATCH 06/10] Fixes --- ydb/core/protos/flat_scheme_op.proto | 10 +++++----- ydb/core/protos/tx_sequenceshard.proto | 14 ++++++-------- .../schemeshard_export_flow_proposals.cpp | 1 + ydb/core/tx/schemeshard/schemeshard_impl.h | 6 ++++-- .../tx/schemeshard/schemeshard_path_describer.cpp | 13 +++++++++---- ydb/public/api/protos/ydb_table.proto | 9 ++++----- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ydb/core/protos/flat_scheme_op.proto b/ydb/core/protos/flat_scheme_op.proto index 8011f707481b..7d8065c27278 100644 --- a/ydb/core/protos/flat_scheme_op.proto +++ b/ydb/core/protos/flat_scheme_op.proto @@ -1293,12 +1293,11 @@ message TMoveIndex { optional bool AllowOverwrite = 4; } -message TSetVal { - optional sint64 NextValue = 1; - optional bool NextUsed = 2; -} - message TSequenceDescription { + message TSetVal { + optional sint64 NextValue = 1; + optional bool NextUsed = 2; + } optional string Name = 1; // mandatory optional NKikimrProto.TPathID PathId = 2; // sequence path id, assigned by schemeshard optional uint64 Version = 3; // incremented every time sequence is altered @@ -1619,6 +1618,7 @@ message TDescribeOptions { optional bool ShowPrivateTable = 7 [default = false]; optional bool ReturnChannelsBinding = 8 [default = false]; optional bool ReturnRangeKey = 9 [default = true]; + optional bool ReturnSetVal = 10 [default = false]; } // Request to read scheme for a specific path diff --git a/ydb/core/protos/tx_sequenceshard.proto b/ydb/core/protos/tx_sequenceshard.proto index ecad295a16eb..e092dc447bd7 100644 --- a/ydb/core/protos/tx_sequenceshard.proto +++ b/ydb/core/protos/tx_sequenceshard.proto @@ -17,12 +17,12 @@ message TEvMarkSchemeShardPipe { uint64 Round = 3; } -message TSetVal { - sint64 NextValue = 1; - bool NextUsed = 2; -} - message TEvCreateSequence { + message TSetVal { + sint64 NextValue = 1; + bool NextUsed = 2; + } + NKikimrProto.TPathID PathId = 1; uint64 TxId = 2; uint64 TxPartId = 3; @@ -45,9 +45,7 @@ message TEvCreateSequence { bool Cycle = 9; } bool Frozen = 10; // defaults to false - oneof OptionalSetVal { - TSetVal SetVal = 11; - } + TSetVal SetVal = 11; } message TEvCreateSequenceResult { diff --git a/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp b/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp index 11ebc0fa4436..1f17e652ed16 100644 --- a/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp @@ -76,6 +76,7 @@ static NKikimrSchemeOp::TPathDescription GetTableDescription(TSchemeShard* ss, c opts.SetReturnPartitioningInfo(false); opts.SetReturnPartitionConfig(true); opts.SetReturnBoundaries(true); + opts.SetReturnSetVal(true); auto desc = DescribePath(ss, TlsActivationContext->AsActorContext(), pathId, opts); auto record = desc->GetRecord(); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.h b/ydb/core/tx/schemeshard/schemeshard_impl.h index 2b560c12f506..40c8c427996f 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.h +++ b/ydb/core/tx/schemeshard/schemeshard_impl.h @@ -992,8 +992,10 @@ class TSchemeShard void DescribeTableIndex(const TPathId& pathId, const TString& name, TTableIndexInfo::TPtr indexInfo, NKikimrSchemeOp::TIndexDescription& entry); void DescribeCdcStream(const TPathId& pathId, const TString& name, NKikimrSchemeOp::TCdcStreamDescription& desc); void DescribeCdcStream(const TPathId& pathId, const TString& name, TCdcStreamInfo::TPtr info, NKikimrSchemeOp::TCdcStreamDescription& desc); - void DescribeSequence(const TPathId& pathId, const TString& name, NKikimrSchemeOp::TSequenceDescription& desc); - void DescribeSequence(const TPathId& pathId, const TString& name, TSequenceInfo::TPtr info, NKikimrSchemeOp::TSequenceDescription& desc); + void DescribeSequence(const TPathId& pathId, const TString& name, + NKikimrSchemeOp::TSequenceDescription& desc, bool fillSetVal = false); + void DescribeSequence(const TPathId& pathId, const TString& name, TSequenceInfo::TPtr info, + NKikimrSchemeOp::TSequenceDescription& desc, bool fillSetVal = false); void DescribeReplication(const TPathId& pathId, const TString& name, NKikimrSchemeOp::TReplicationDescription& desc); void DescribeReplication(const TPathId& pathId, const TString& name, TReplicationInfo::TPtr info, NKikimrSchemeOp::TReplicationDescription& desc); void DescribeBlobDepot(const TPathId& pathId, const TString& name, NKikimrSchemeOp::TBlobDepotDescription& desc); diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp index e24a1f59f8dd..15998faa8aac 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp @@ -211,6 +211,7 @@ void TPathDescriber::DescribeTable(const TActorContext& ctx, TPathId pathId, TPa bool returnBackupInfo = Params.GetBackupInfo(); bool returnBoundaries = false; bool returnRangeKey = true; + bool returnSetVal = Params.GetReturnSetVal(); if (Params.HasOptions()) { returnConfig = Params.GetOptions().GetReturnPartitionConfig(); returnPartitioning = Params.GetOptions().GetReturnPartitioningInfo(); @@ -361,7 +362,7 @@ void TPathDescriber::DescribeTable(const TActorContext& ctx, TPathId pathId, TPa Self->DescribeCdcStream(childPathId, childName, *entry->AddCdcStreams()); break; case NKikimrSchemeOp::EPathTypeSequence: - Self->DescribeSequence(childPathId, childName, *entry->AddSequences()); + Self->DescribeSequence(childPathId, childName, *entry->AddSequences(), returnSetVal); break; default: Y_FAIL_S("Unexpected table's child" @@ -1241,17 +1242,17 @@ void TSchemeShard::DescribeCdcStream(const TPathId& pathId, const TString& name, } void TSchemeShard::DescribeSequence(const TPathId& pathId, const TString& name, - NKikimrSchemeOp::TSequenceDescription& desc) + NKikimrSchemeOp::TSequenceDescription& desc, bool fillSetVal) { auto it = Sequences.find(pathId); Y_VERIFY_S(it != Sequences.end(), "Sequence not found" << " pathId# " << pathId << " name# " << name); - DescribeSequence(pathId, name, it->second, desc); + DescribeSequence(pathId, name, it->second, desc, fillSetVal); } void TSchemeShard::DescribeSequence(const TPathId& pathId, const TString& name, TSequenceInfo::TPtr info, - NKikimrSchemeOp::TSequenceDescription& desc) + NKikimrSchemeOp::TSequenceDescription& desc, bool fillSetVal) { Y_VERIFY_S(info, "Empty sequence info" << " pathId# " << pathId @@ -1259,6 +1260,10 @@ void TSchemeShard::DescribeSequence(const TPathId& pathId, const TString& name, desc = info->Description; + if (!fillSetVal) { + desc.ClearSetVal(); + } + desc.SetName(name); PathIdFromPathId(pathId, desc.MutablePathId()); desc.SetVersion(info->AlterVersion); diff --git a/ydb/public/api/protos/ydb_table.proto b/ydb/public/api/protos/ydb_table.proto index e81d10e66ae3..50887aadf3d2 100644 --- a/ydb/public/api/protos/ydb_table.proto +++ b/ydb/public/api/protos/ydb_table.proto @@ -333,12 +333,11 @@ message TableProfile { CachingPolicy caching_policy = 7; } -message SetVal { - optional sint64 next_value = 1; - optional bool next_used = 2; -} - message SequenceDescription { + message SetVal { + optional sint64 next_value = 1; + optional bool next_used = 2; + } optional string name = 1; // mandatorys optional sint64 min_value = 2; // minimum value, defaults to 1 or Min optional sint64 max_value = 3; // maximum value, defaults to Max or -1 From 1ed48a85ad6787a4178915e42f16054339918b08 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Tue, 26 Mar 2024 15:23:17 +0300 Subject: [PATCH 07/10] Fixes --- ydb/core/tx/sequenceshard/tx_create_sequence.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ydb/core/tx/sequenceshard/tx_create_sequence.cpp b/ydb/core/tx/sequenceshard/tx_create_sequence.cpp index 9b62968361ce..8df1e6092ed3 100644 --- a/ydb/core/tx/sequenceshard/tx_create_sequence.cpp +++ b/ydb/core/tx/sequenceshard/tx_create_sequence.cpp @@ -75,7 +75,7 @@ namespace NSequenceShard { } - if (msg->Record.OptionalSetVal_case() == NKikimrTxSequenceShard::TEvCreateSequence::kSetVal) { + if (msg->Record.HasSetVal()) { sequence.NextValue = msg->Record.GetSetVal().GetNextValue(); sequence.NextUsed = msg->Record.GetSetVal().GetNextUsed(); } else { From 46e1e9cc949b9acc797a87b45fee702a92e82c13 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Tue, 26 Mar 2024 16:57:32 +0300 Subject: [PATCH 08/10] Fixes --- ydb/core/tx/schemeshard/schemeshard_path_describer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp index 15998faa8aac..d53f6b62d416 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp @@ -211,7 +211,7 @@ void TPathDescriber::DescribeTable(const TActorContext& ctx, TPathId pathId, TPa bool returnBackupInfo = Params.GetBackupInfo(); bool returnBoundaries = false; bool returnRangeKey = true; - bool returnSetVal = Params.GetReturnSetVal(); + bool returnSetVal = Params.GetOptions().GetReturnSetVal(); if (Params.HasOptions()) { returnConfig = Params.GetOptions().GetReturnPartitionConfig(); returnPartitioning = Params.GetOptions().GetReturnPartitioningInfo(); From a74befa6bc32b54cbe9db713a269ffb72b84491f Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Wed, 27 Mar 2024 03:58:19 +0300 Subject: [PATCH 09/10] Fixes --- .../schemeshard_export_flow_proposals.cpp | 38 ++++++++++++++++--- ydb/core/tx/schemeshard/schemeshard_impl.cpp | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp b/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp index 1f17e652ed16..4af5a86d53ea 100644 --- a/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_export_flow_proposals.cpp @@ -76,7 +76,6 @@ static NKikimrSchemeOp::TPathDescription GetTableDescription(TSchemeShard* ss, c opts.SetReturnPartitioningInfo(false); opts.SetReturnPartitionConfig(true); opts.SetReturnBoundaries(true); - opts.SetReturnSetVal(true); auto desc = DescribePath(ss, TlsActivationContext->AsActorContext(), pathId, opts); auto record = desc->GetRecord(); @@ -84,6 +83,30 @@ static NKikimrSchemeOp::TPathDescription GetTableDescription(TSchemeShard* ss, c return record.GetPathDescription(); } +void FillSetValForSequences(TSchemeShard* ss, NKikimrSchemeOp::TTableDescription& description, + const TPathId& exportItemPathId) { + NKikimrSchemeOp::TDescribeOptions opts; + opts.SetReturnSetVal(true); + + auto pathDescription = DescribePath(ss, TlsActivationContext->AsActorContext(), exportItemPathId, opts); + auto tableDescription = pathDescription->GetRecord().GetPathDescription().GetTable(); + + THashMap setValForSequences; + + for (const auto& sequenceDescription : tableDescription.GetSequences()) { + if (sequenceDescription.HasSetVal()) { + setValForSequences[sequenceDescription.GetName()] = sequenceDescription.GetSetVal(); + } + } + + for (auto& sequenceDescription : *description.MutableSequences()) { + auto it = setValForSequences.find(sequenceDescription.GetName()); + if (it != setValForSequences.end()) { + *sequenceDescription.MutableSetVal() = it->second; + } + } +} + THolder BackupPropose( TSchemeShard* ss, TTxId txId, @@ -107,11 +130,14 @@ THolder BackupPropose( task.SetNeedToBill(!exportInfo->UserSID || !ss->SystemBackupSIDs.contains(*exportInfo->UserSID)); const TPath sourcePath = TPath::Init(exportInfo->Items[itemIdx].SourcePathId, ss); - const TPath exportPathItem = exportPath.Child(ToString(itemIdx)); - if (sourcePath.IsResolved() && exportPathItem.IsResolved()) { - auto exportDescription = GetTableDescription(ss, exportPathItem.Base()->PathId); - exportDescription.MutableTable()->SetName(sourcePath.LeafName()); - task.MutableTable()->CopyFrom(exportDescription); + const TPath exportItemPath = exportPath.Child(ToString(itemIdx)); + if (sourcePath.IsResolved() && exportItemPath.IsResolved()) { + auto sourceDescription = GetTableDescription(ss, sourcePath.Base()->PathId); + if (sourceDescription.HasTable()) { + FillSetValForSequences( + ss, *sourceDescription.MutableTable(), exportItemPath.Base()->PathId); + } + task.MutableTable()->CopyFrom(sourceDescription); } task.SetSnapshotStep(exportInfo->SnapshotStep); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index bf604eb8767c..68a6f65715d5 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -6566,7 +6566,7 @@ void TSchemeShard::FillTableDescriptionForShardIdx( << ": path#d# " << childPathId << ", name# " << childName); auto info = Sequences.at(childPathId); - DescribeSequence(childPathId, childName, info, *tableDescr->MutableSequences()->Add()); + DescribeSequence(childPathId, childName, info, *tableDescr->MutableSequences()->Add(), false); break; } From aea5bd06cf746b06fc24201fb5f6abb556e53573 Mon Sep 17 00:00:00 2001 From: Nikolay Shumkov Date: Wed, 27 Mar 2024 04:09:42 +0300 Subject: [PATCH 10/10] Fixes --- ydb/core/tx/schemeshard/schemeshard_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index 68a6f65715d5..bf604eb8767c 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -6566,7 +6566,7 @@ void TSchemeShard::FillTableDescriptionForShardIdx( << ": path#d# " << childPathId << ", name# " << childName); auto info = Sequences.at(childPathId); - DescribeSequence(childPathId, childName, info, *tableDescr->MutableSequences()->Add(), false); + DescribeSequence(childPathId, childName, info, *tableDescr->MutableSequences()->Add()); break; }