Skip to content

Commit 0cd4902

Browse files
authored
Setup sys locks in TTxApplyReplicationChanges (#9723)
1 parent 5807f62 commit 0cd4902

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

ydb/core/tx/datashard/datashard_repl_apply.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "datashard_impl.h"
2+
#include "datashard_locks_db.h"
3+
#include "setup_sys_locks.h"
24

35
#include <util/string/escape.h>
46

@@ -24,6 +26,9 @@ class TDataShard::TTxApplyReplicationChanges : public TTransactionBase<TDataShar
2426
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
2527
Y_UNUSED(ctx);
2628

29+
TDataShardLocksDb locksDb(*Self, txc);
30+
TSetupSysLocks guardLocks(*Self, &locksDb);
31+
2732
if (Self->State != TShardState::Ready) {
2833
Result = MakeHolder<TEvDataShard::TEvApplyReplicationChangesResult>(
2934
NKikimrTxDataShard::TEvApplyReplicationChangesResult::STATUS_REJECTED,
@@ -84,6 +89,7 @@ class TDataShard::TTxApplyReplicationChanges : public TTransactionBase<TDataShar
8489
}
8590

8691
if (MvccReadWriteVersion) {
92+
Self->PromoteImmediatePostExecuteEdges(*MvccReadWriteVersion, TDataShard::EPromotePostExecuteEdges::ReadWrite, txc);
8793
Pipeline.AddCommittingOp(*MvccReadWriteVersion);
8894
}
8995

@@ -92,6 +98,7 @@ class TDataShard::TTxApplyReplicationChanges : public TTransactionBase<TDataShar
9298
NKikimrTxDataShard::TEvApplyReplicationChangesResult::STATUS_OK);
9399
}
94100

101+
Self->SysLocksTable().ApplyLocks();
95102
return true;
96103
}
97104

ydb/core/tx/datashard/datashard_ut_replication.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <ydb/core/tx/datashard/ut_common/datashard_ut_common.h>
22
#include "datashard_active_transaction.h"
3+
#include "datashard_ut_common_kqp.h"
34

45
#include <ydb/core/tx/tx_proxy/proxy.h>
56

67
namespace NKikimr {
78

89
using namespace NKikimr::NDataShard;
10+
using namespace NKikimr::NDataShard::NKqpHelpers;
911
using namespace NSchemeShard;
1012
using namespace Tests;
1113

@@ -307,6 +309,46 @@ Y_UNIT_TEST_SUITE(DataShardReplication) {
307309
}, NKikimrTxDataShard::TEvApplyReplicationChangesResult::STATUS_REJECTED);
308310
}
309311

312+
Y_UNIT_TEST(ApplyChangesWithConcurrentTx) {
313+
TPortManager pm;
314+
TServerSettings serverSettings(pm.GetPort(2134));
315+
serverSettings.SetDomainName("Root")
316+
.SetUseRealThreads(false);
317+
318+
Tests::TServer::TPtr server = new TServer(serverSettings);
319+
auto &runtime = *server->GetRuntime();
320+
auto sender = runtime.AllocateEdgeActor();
321+
322+
runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_TRACE);
323+
324+
InitRoot(server, sender);
325+
CreateShardedTable(server, sender, "/Root", "table-1", TShardedTableOptions()
326+
.Replicated(true)
327+
.ReplicationConsistency(EReplicationConsistency::Weak)
328+
);
329+
330+
auto shards = GetTableShards(server, sender, "/Root/table-1");
331+
auto tableId = ResolveTableId(server, sender, "/Root/table-1");
332+
333+
ApplyChanges(server, shards.at(0), tableId, "my-source", {
334+
TChange{ .Offset = 0, .WriteTxId = 0, .Key = 1, .Value = 11 },
335+
});
336+
337+
TString sessionId;
338+
TString txId;
339+
UNIT_ASSERT_VALUES_EQUAL(
340+
KqpSimpleBegin(runtime, sessionId, txId, "SELECT key, value FROM `/Root/table-1`;"),
341+
"{ items { uint32_value: 1 } items { uint32_value: 11 } }");
342+
343+
ApplyChanges(server, shards.at(0), tableId, "my-source", {
344+
TChange{ .Offset = 1, .WriteTxId = 0, .Key = 1, .Value = 21 },
345+
});
346+
347+
UNIT_ASSERT_VALUES_EQUAL(
348+
KqpSimpleCommit(runtime, sessionId, txId, "SELECT key, value FROM `/Root/table-1`;"),
349+
"{ items { uint32_value: 1 } items { uint32_value: 11 } }");
350+
}
351+
310352
}
311353

312354
} // namespace NKikimr

0 commit comments

Comments
 (0)