Skip to content

Commit b61bbb3

Browse files
authored
Merge 7aade9f into 4002b4c
2 parents 4002b4c + 7aade9f commit b61bbb3

File tree

8 files changed

+87
-7
lines changed

8 files changed

+87
-7
lines changed

ydb/core/tx/datashard/datashard_repl_apply.cpp

Lines changed: 8 additions & 1 deletion
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

Lines changed: 23 additions & 0 deletions
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

ydb/core/tx/replication/controller/dst_creator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class TDstCreator: public TActorBootstrapped<TDstCreator> {
112112
if (bootstrap) {
113113
GetTableProfiles();
114114
} else {
115-
Send(YdbProxy, new TEvYdbProxy::TEvDescribeTableRequest(SrcPath, {}));
115+
Send(YdbProxy, new TEvYdbProxy::TEvDescribeTableRequest(SrcPath, NYdb::NTable::TDescribeTableSettings()
116+
.WithKeyShardBoundary(true)));
116117
}
117118
break;
118119
}

ydb/core/tx/replication/controller/dst_creator_ut.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Y_UNIT_TEST_SUITE(DstCreator) {
8080
},
8181
.ReplicationConfig = Nothing(),
8282
}));
83+
8384
env.GetRuntime().Register(CreateDstCreator(
8485
env.GetSender(), env.GetSchemeshardId("/Root/Table"), env.GetYdbProxy(), env.GetPathId("/Root"),
8586
1 /* rid */, 1 /* tid */, TReplication::ETargetKind::Table, "/Root/Table", "/Root/Replicated"
@@ -93,6 +94,38 @@ Y_UNIT_TEST_SUITE(DstCreator) {
9394
UNIT_ASSERT_VALUES_EQUAL(replicatedSelf.GetOwner(), "user@builtin");
9495
}
9596

97+
Y_UNIT_TEST(SamePartitionCount) {
98+
TEnv env;
99+
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE);
100+
101+
env.CreateTable("/Root", *MakeTableDescription({
102+
.Name = "Table",
103+
.KeyColumns = {"key"},
104+
.Columns = {
105+
{.Name = "key", .Type = "Uint32"},
106+
{.Name = "value", .Type = "Utf8"},
107+
},
108+
.ReplicationConfig = Nothing(),
109+
.UniformPartitions = 2,
110+
}));
111+
112+
env.GetRuntime().Register(CreateDstCreator(
113+
env.GetSender(), env.GetSchemeshardId("/Root/Table"), env.GetYdbProxy(), env.GetPathId("/Root"),
114+
1 /* rid */, 1 /* tid */, TReplication::ETargetKind::Table, "/Root/Table", "/Root/Replicated"
115+
));
116+
117+
auto ev = env.GetRuntime().GrabEdgeEvent<TEvPrivate::TEvCreateDstResult>(env.GetSender());
118+
UNIT_ASSERT_VALUES_EQUAL(ev->Get()->Status, NKikimrScheme::StatusSuccess);
119+
120+
auto originalDesc = env.GetDescription("/Root/Table");
121+
const auto& originalTable = originalDesc.GetPathDescription();
122+
UNIT_ASSERT_VALUES_EQUAL(originalTable.TablePartitionsSize(), 2);
123+
124+
auto replicatedDesc = env.GetDescription("/Root/Replicated");
125+
const auto& replicatedTable = replicatedDesc.GetPathDescription();
126+
UNIT_ASSERT_VALUES_EQUAL(originalTable.TablePartitionsSize(), replicatedTable.TablePartitionsSize());
127+
}
128+
96129
Y_UNIT_TEST(NonExistentSrc) {
97130
TEnv env;
98131
env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE);

ydb/core/tx/replication/service/table_writer.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class TTablePartitionWriter: public TActorBootstrapped<TTablePartitionWriter> {
9393
event->Record.SetSource(source);
9494
}
9595

96-
Send(LeaderPipeCache, new TEvPipeCache::TEvForward(event.Release(), TabletId, false));
96+
Send(LeaderPipeCache, new TEvPipeCache::TEvForward(event.Release(), TabletId, true, ++SubscribeCookie));
9797
Become(&TThis::StateWaitingStatus);
9898
}
9999

@@ -117,7 +117,11 @@ class TTablePartitionWriter: public TActorBootstrapped<TTablePartitionWriter> {
117117
<< ": status# " << static_cast<ui32>(record.GetStatus())
118118
<< ", reason# " << static_cast<ui32>(record.GetReason())
119119
<< ", error# " << record.GetErrorDescription());
120-
return Leave(IsHardError(record.GetReason()));
120+
if (IsHardError(record.GetReason())) {
121+
return Leave(true);
122+
} else {
123+
return DelayedLeave();
124+
}
121125
}
122126
}
123127

@@ -133,11 +137,16 @@ class TTablePartitionWriter: public TActorBootstrapped<TTablePartitionWriter> {
133137
}
134138

135139
void Handle(TEvPipeCache::TEvDeliveryProblem::TPtr& ev) {
136-
if (TabletId == ev->Get()->TabletId) {
137-
Leave();
140+
if (TabletId == ev->Get()->TabletId && ev->Cookie == SubscribeCookie) {
141+
DelayedLeave();
138142
}
139143
}
140144

145+
void DelayedLeave() {
146+
static constexpr TDuration delay = TDuration::MilliSeconds(50);
147+
this->Schedule(delay, new TEvents::TEvWakeup());
148+
}
149+
141150
void Leave(bool hardError = false) {
142151
LOG_I("Leave"
143152
<< ": hard error# " << hardError);
@@ -177,6 +186,7 @@ class TTablePartitionWriter: public TActorBootstrapped<TTablePartitionWriter> {
177186
STATEFN(StateBase) {
178187
switch (ev->GetTypeRewrite()) {
179188
hFunc(TEvPipeCache::TEvDeliveryProblem, Handle);
189+
sFunc(TEvents::TEvWakeup, Leave);
180190
sFunc(TEvents::TEvPoison, PassAway);
181191
}
182192
}
@@ -188,6 +198,7 @@ class TTablePartitionWriter: public TActorBootstrapped<TTablePartitionWriter> {
188198
mutable TMaybe<TString> LogPrefix;
189199

190200
TActorId LeaderPipeCache;
201+
ui64 SubscribeCookie = 0;
191202
TMemoryPool MemoryPool;
192203

193204
}; // TTablePartitionWriter

ydb/core/tx/replication/ut_helpers/test_table.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void TTestTableDescription::SerializeTo(NKikimrSchemeOp::TTableDescription& prot
5757
if (ReplicationConfig) {
5858
ReplicationConfig->SerializeTo(*proto.MutableReplicationConfig());
5959
}
60+
61+
if (UniformPartitions) {
62+
proto.SetUniformPartitionsCount(*UniformPartitions);
63+
}
6064
}
6165

6266
THolder<NKikimrSchemeOp::TTableDescription> MakeTableDescription(const TTestTableDescription& desc) {

ydb/core/tx/replication/ut_helpers/test_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct TTestTableDescription {
4444
TVector<TString> KeyColumns;
4545
TVector<TColumn> Columns;
4646
TMaybe<TReplicationConfig> ReplicationConfig = TReplicationConfig::Default();
47+
TMaybe<ui32> UniformPartitions = Nothing();
4748

4849
void SerializeTo(NKikimrSchemeOp::TTableDescription& proto) const;
4950
};

ydb/library/yql/sql/v1/sql_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,7 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
23952395

23962396
Y_UNIT_TEST(AlterTableAddIndexWithIsNotSupported) {
23972397
ExpectFailWithError("USE plato; ALTER TABLE table ADD INDEX idx LOCAL WITH (a=b, c=d, e=f) ON (col)",
2398-
"<main>:1:40: Error: local: alternative is not implemented yet: 714:7: local_index\n");
2398+
"<main>:1:40: Error: local: alternative is not implemented yet: 715:7: local_index\n");
23992399
}
24002400

24012401
Y_UNIT_TEST(OptionalAliases) {

0 commit comments

Comments
 (0)