Skip to content

Commit 40bcf99

Browse files
authored
Fix ApplyReplicationChanges (#5683)
1 parent ed0f141 commit 40bcf99

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

ydb/core/tx/datashard/datashard_repl_apply.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ class TDataShard::TTxApplyReplicationChanges : public TTransactionBase<TDataShar
2424
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
2525
Y_UNUSED(ctx);
2626

27-
if (Self->State != TShardState::Ready && !Self->IsReplicated()) {
27+
if (Self->State != TShardState::Ready) {
2828
Result = MakeHolder<TEvDataShard::TEvApplyReplicationChangesResult>(
2929
NKikimrTxDataShard::TEvApplyReplicationChangesResult::STATUS_REJECTED,
3030
NKikimrTxDataShard::TEvApplyReplicationChangesResult::REASON_WRONG_STATE);
3131
return true;
3232
}
3333

34+
if (!Self->IsReplicated()) {
35+
Result = MakeHolder<TEvDataShard::TEvApplyReplicationChangesResult>(
36+
NKikimrTxDataShard::TEvApplyReplicationChangesResult::STATUS_REJECTED,
37+
NKikimrTxDataShard::TEvApplyReplicationChangesResult::REASON_BAD_REQUEST);
38+
return true;
39+
}
40+
3441
const auto& msg = Ev->Get()->Record;
3542

3643
const auto& tableId = msg.GetTableId();

ydb/core/tx/datashard/datashard_ut_replication.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,29 @@ Y_UNIT_TEST_SUITE(DataShardReplication) {
281281
);
282282
}
283283

284+
Y_UNIT_TEST(ApplyChangesToCommonTable) {
285+
TPortManager pm;
286+
TServerSettings serverSettings(pm.GetPort(2134));
287+
serverSettings.SetDomainName("Root")
288+
.SetUseRealThreads(false);
289+
290+
Tests::TServer::TPtr server = new TServer(serverSettings);
291+
auto &runtime = *server->GetRuntime();
292+
auto sender = runtime.AllocateEdgeActor();
293+
294+
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
295+
296+
InitRoot(server, sender);
297+
CreateShardedTable(server, sender, "/Root", "table-1", TShardedTableOptions());
298+
299+
auto shards = GetTableShards(server, sender, "/Root/table-1");
300+
auto tableId = ResolveTableId(server, sender, "/Root/table-1");
301+
302+
ApplyChanges(server, shards.at(0), tableId, "my-source", {
303+
TChange{ .Offset = 0, .WriteTxId = 0, .Key = 1, .Value = 11 },
304+
}, NKikimrTxDataShard::TEvApplyReplicationChangesResult::STATUS_REJECTED);
305+
}
306+
284307
}
285308

286309
} // namespace NKikimr

0 commit comments

Comments
 (0)