Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TPropose: public TSubOperationState {
NIceDb::TNiceDb db(context.GetDB());

context.SS->PersistCdcStream(db, pathId);
context.SS->CdcStreams[pathId] = stream->AlterData;
context.SS->CdcStreams[pathId]->FinishAlter();

context.SS->ClearDescribePathCaches(path);
context.OnComplete.PublishToSchemeBoard(OperationId, pathId);
Expand Down
14 changes: 14 additions & 0 deletions ydb/core/tx/schemeshard/schemeshard_info_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,20 @@ struct TCdcStreamInfo : public TSimpleRefCount<TCdcStreamInfo> {
return result;
}

void FinishAlter() {
Y_ABORT_UNLESS(AlterData);

AlterVersion = AlterData->AlterVersion;
Mode = AlterData->Mode;
Format = AlterData->Format;
VirtualTimestamps = AlterData->VirtualTimestamps;
ResolvedTimestamps = AlterData->ResolvedTimestamps;
AwsRegion = AlterData->AwsRegion;
State = AlterData->State;

AlterData.Reset();
}

ui64 AlterVersion = 1;
EMode Mode;
EFormat Format;
Expand Down
76 changes: 76 additions & 0 deletions ydb/core/tx/schemeshard/ut_cdc_stream/ut_cdc_stream.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <ydb/core/metering/metering.h>
#include <ydb/core/testlib/actors/block_events.h>
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
#include <ydb/core/tx/schemeshard/schemeshard_impl.h>
#include <ydb/core/tx/schemeshard/schemeshard_private.h>

#include <library/cpp/json/json_reader.h>
#include <library/cpp/json/json_writer.h>
Expand Down Expand Up @@ -1754,6 +1756,80 @@ Y_UNIT_TEST_SUITE(TCdcStreamWithInitialScanTests) {
env.TestWaitNotification(runtime, txId);
}

Y_UNIT_TEST(RacyAlterStreamAndRestart) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions()
.EnableChangefeedInitialScan(true));
ui64 txId = 100;

TActorId schemeShardActorId;
auto findActorId = runtime.AddObserver<TEvSchemeShard::TEvModifySchemeTransactionResult>([&](auto& ev) {
if (!schemeShardActorId) {
schemeShardActorId = ev->Sender;
}
});

TestCreateTable(runtime, ++txId, "/MyRoot", R"(
Name: "Table"
Columns { Name: "key" Type: "Uint64" }
Columns { Name: "value" Type: "Uint64" }
KeyColumnNames: ["key"]
)");
env.TestWaitNotification(runtime, txId);

TBlockEvents<TEvSchemeShard::TEvModifySchemeTransaction> blockedAlterStream(runtime, [&](auto& ev) {
const auto& record = ev->Get()->Record;
if (record.GetTransaction(0).GetOperationType() == NKikimrSchemeOp::ESchemeOpAlterCdcStream) {
txId = record.GetTxId();
return true;
}
return false;
});

TestCreateCdcStream(runtime, ++txId, "/MyRoot", R"(
TableName: "Table"
StreamDescription {
Name: "Stream"
Mode: ECdcStreamModeKeysOnly
Format: ECdcStreamFormatProto
State: ECdcStreamStateScan
}
)");
env.TestWaitNotification(runtime, txId);

runtime.WaitFor("AlterCdcStream", [&]{ return blockedAlterStream.size(); });
blockedAlterStream.Stop();

UNIT_ASSERT(schemeShardActorId);

TBlockEvents<TEvPrivate::TEvProgressOperation> blockedProgress(runtime, [&](auto& ev) {
return schemeShardActorId == ev->Sender;
});

blockedAlterStream.Unblock();
runtime.WaitFor("Progress", [&]{ return blockedProgress.size(); });
blockedProgress.Stop();

RebootTablet(runtime, TTestTxConfig::SchemeShard, runtime.AllocateEdgeActor());
env.TestWaitNotification(runtime, txId);

TestDescribeResult(DescribePrivatePath(runtime, "/MyRoot/Table/Stream"), {
NLs::PathExist,
NLs::StreamState(NKikimrSchemeOp::ECdcStreamStateReady),
});

TestDropCdcStream(runtime, ++txId, "/MyRoot", R"(
TableName: "Table"
StreamName: "Stream"
)");
env.TestWaitNotification(runtime, txId);

RebootTablet(runtime, TTestTxConfig::SchemeShard, runtime.AllocateEdgeActor());
TestDescribeResult(DescribePrivatePath(runtime, "/MyRoot/Table/Stream"), {
NLs::PathNotExist,
});
}

void Metering(bool serverless) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions()
Expand Down