1+ #include " schemeshard__operation_alter_cdc_stream.h"
2+
13#include " schemeshard__operation_part.h"
24#include " schemeshard__operation_common.h"
35#include " schemeshard_impl.h"
810
911namespace NKikimr::NSchemeShard {
1012
13+ namespace NCdc {
14+
1115namespace {
1216
1317class TPropose : public TSubOperationState {
@@ -471,35 +475,12 @@ class TAlterCdcStreamAtTable: public TSubOperation {
471475
472476} // anonymous
473477
474- ISubOperation::TPtr CreateAlterCdcStreamImpl (TOperationId id, const TTxTransaction& tx) {
475- return MakeSubOperation<TAlterCdcStream>(id, tx);
476- }
477-
478- ISubOperation::TPtr CreateAlterCdcStreamImpl (TOperationId id, TTxState::ETxState state) {
479- return MakeSubOperation<TAlterCdcStream>(id, state);
480- }
481-
482- ISubOperation::TPtr CreateAlterCdcStreamAtTable (TOperationId id, const TTxTransaction& tx, bool dropSnapshot) {
483- return MakeSubOperation<TAlterCdcStreamAtTable>(id, tx, dropSnapshot);
484- }
485-
486- ISubOperation::TPtr CreateAlterCdcStreamAtTable (TOperationId id, TTxState::ETxState state, bool dropSnapshot) {
487- return MakeSubOperation<TAlterCdcStreamAtTable>(id, state, dropSnapshot);
488- }
489-
490- TVector<ISubOperation::TPtr> CreateAlterCdcStream (TOperationId opId, const TTxTransaction& tx, TOperationContext& context) {
491- Y_ABORT_UNLESS (tx.GetOperationType () == NKikimrSchemeOp::EOperationType::ESchemeOpAlterCdcStream);
492-
493- LOG_D (" CreateAlterCdcStream"
494- << " : opId# " << opId
495- << " , tx# " << tx.ShortDebugString ());
496-
497- const auto & op = tx.GetAlterCdcStream ();
498- const auto & tableName = op.GetTableName ();
499- const auto & streamName = op.GetStreamName ();
500-
501- const auto workingDirPath = TPath::Resolve (tx.GetWorkingDir (), context.SS );
502-
478+ std::variant<TStreamPaths, ISubOperation::TPtr> DoAlterStreamPathChecks (
479+ const TOperationId& opId,
480+ const TPath& workingDirPath,
481+ const TString& tableName,
482+ const TString& streamName)
483+ {
503484 const auto tablePath = workingDirPath.Child (tableName);
504485 {
505486 const auto checks = tablePath.Check ();
@@ -515,7 +496,7 @@ TVector<ISubOperation::TPtr> CreateAlterCdcStream(TOperationId opId, const TTxTr
515496 .NotUnderOperation ();
516497
517498 if (!checks) {
518- return { CreateReject (opId, checks.GetStatus (), checks.GetError ())} ;
499+ return CreateReject (opId, checks.GetStatus (), checks.GetError ());
519500 }
520501 }
521502
@@ -532,21 +513,20 @@ TVector<ISubOperation::TPtr> CreateAlterCdcStream(TOperationId opId, const TTxTr
532513 .NotUnderOperation ();
533514
534515 if (!checks) {
535- return { CreateReject (opId, checks.GetStatus (), checks.GetError ())} ;
516+ return CreateReject (opId, checks.GetStatus (), checks.GetError ());
536517 }
537518 }
538519
539- TString errStr;
540- if (!context.SS ->CheckApplyIf (tx, errStr)) {
541- return {CreateReject (opId, NKikimrScheme::StatusPreconditionFailed, errStr)};
542- }
543-
544- if (!context.SS ->CheckLocks (tablePath.Base ()->PathId , tx, errStr)) {
545- return {CreateReject (opId, NKikimrScheme::StatusMultipleModifications, errStr)};
546- }
547-
548- TVector<ISubOperation::TPtr> result;
520+ return TStreamPaths{tablePath, streamPath};
521+ }
549522
523+ void DoAlterStream (
524+ const NKikimrSchemeOp::TAlterCdcStream& op,
525+ const TOperationId& opId,
526+ const TPath& workingDirPath,
527+ const TPath& tablePath,
528+ TVector<ISubOperation::TPtr>& result)
529+ {
550530 {
551531 auto outTx = TransactionTemplate (tablePath.PathString (), NKikimrSchemeOp::EOperationType::ESchemeOpAlterCdcStreamImpl);
552532 outTx.MutableAlterCdcStream ()->CopyFrom (op);
@@ -568,6 +548,60 @@ TVector<ISubOperation::TPtr> CreateAlterCdcStream(TOperationId opId, const TTxTr
568548
569549 result.push_back (CreateAlterCdcStreamAtTable (NextPartId (opId, result), outTx, op.HasGetReady ()));
570550 }
551+ }
552+
553+ } // namespace NCdc
554+
555+ using namespace NCdc ;
556+
557+ ISubOperation::TPtr CreateAlterCdcStreamImpl (TOperationId id, const TTxTransaction& tx) {
558+ return MakeSubOperation<TAlterCdcStream>(id, tx);
559+ }
560+
561+ ISubOperation::TPtr CreateAlterCdcStreamImpl (TOperationId id, TTxState::ETxState state) {
562+ return MakeSubOperation<TAlterCdcStream>(id, state);
563+ }
564+
565+ ISubOperation::TPtr CreateAlterCdcStreamAtTable (TOperationId id, const TTxTransaction& tx, bool dropSnapshot) {
566+ return MakeSubOperation<TAlterCdcStreamAtTable>(id, tx, dropSnapshot);
567+ }
568+
569+ ISubOperation::TPtr CreateAlterCdcStreamAtTable (TOperationId id, TTxState::ETxState state, bool dropSnapshot) {
570+ return MakeSubOperation<TAlterCdcStreamAtTable>(id, state, dropSnapshot);
571+ }
572+
573+ TVector<ISubOperation::TPtr> CreateAlterCdcStream (TOperationId opId, const TTxTransaction& tx, TOperationContext& context) {
574+ Y_ABORT_UNLESS (tx.GetOperationType () == NKikimrSchemeOp::EOperationType::ESchemeOpAlterCdcStream);
575+
576+ LOG_D (" CreateAlterCdcStream"
577+ << " : opId# " << opId
578+ << " , tx# " << tx.ShortDebugString ());
579+
580+ const auto & op = tx.GetAlterCdcStream ();
581+ const auto & tableName = op.GetTableName ();
582+ const auto & streamName = op.GetStreamName ();
583+
584+ const auto workingDirPath = TPath::Resolve (tx.GetWorkingDir (), context.SS );
585+
586+ const auto checksResult = DoAlterStreamPathChecks (opId, workingDirPath, tableName, streamName);
587+ if (std::holds_alternative<ISubOperation::TPtr>(checksResult)) {
588+ return {std::get<ISubOperation::TPtr>(checksResult)};
589+ }
590+
591+ const auto [tablePath, streamPath] = std::get<TStreamPaths>(checksResult);
592+
593+ TString errStr;
594+ if (!context.SS ->CheckApplyIf (tx, errStr)) {
595+ return {CreateReject (opId, NKikimrScheme::StatusPreconditionFailed, errStr)};
596+ }
597+
598+ if (!context.SS ->CheckLocks (tablePath.Base ()->PathId , tx, errStr)) {
599+ return {CreateReject (opId, NKikimrScheme::StatusMultipleModifications, errStr)};
600+ }
601+
602+ TVector<ISubOperation::TPtr> result;
603+
604+ DoAlterStream (op, opId, workingDirPath, tablePath, result);
571605
572606 if (op.HasGetReady ()) {
573607 auto outTx = TransactionTemplate (workingDirPath.PathString (), NKikimrSchemeOp::EOperationType::ESchemeOpDropLock);
0 commit comments