Skip to content

Commit 322a985

Browse files
authored
Merge ac2677f into 1c39afc
2 parents 1c39afc + ac2677f commit 322a985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+422
-289
lines changed

ydb/core/client/locks_ut.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <ydb/core/engine/mkql_engine_flat_impl.h>
33
#include <ydb/core/testlib/test_client.h>
44
#include <ydb/core/tx/tx_proxy/proxy.h>
5-
#include <ydb/core/tx/datashard/datashard_locks.h>
5+
#include <ydb/core/tx/locks/locks.h>
66
#include <ydb/public/lib/deprecated/kicli/kicli.h>
77

88
#include <library/cpp/testing/unittest/tests_data.h>

ydb/core/engine/minikql/minikql_engine_host.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <ydb/library/yql/minikql/computation/mkql_custom_list.h>
77
#include <ydb/library/yql/minikql/mkql_string_util.h>
88
#include <ydb/library/yql/parser/pg_wrapper/interface/codec.h>
9-
#include <ydb/core/tx/datashard/sys_tables.h>
9+
#include <ydb/core/tx/locks/sys_tables.h>
1010

1111
#include <library/cpp/containers/stack_vector/stack_vec.h>
1212

ydb/core/kqp/runtime/kqp_stream_lookup_worker.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <ydb/library/yql/minikql/mkql_node.h>
55
#include <ydb/library/yql/minikql/computation/mkql_computation_node_holders.h>
66
#include <ydb/core/scheme/scheme_tabledefs.h>
7-
#include <ydb/core/tx/datashard/sys_tables.h>
7+
#include <ydb/core/tx/locks/sys_tables.h>
88
#include <ydb/core/tx/datashard/datashard.h>
99

1010
namespace NKikimr {

ydb/core/sys_view/common/schema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "path.h"
44

55
#include <ydb/core/tablet_flat/flat_cxx_database.h>
6-
#include <ydb/core/tx/datashard/sys_tables.h>
6+
#include <ydb/core/tx/locks/sys_tables.h>
77

88
namespace NKikimr {
99
namespace NSysView {

ydb/core/tx/columnshard/columnshard__init.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "columnshard_schema.h"
55
#include "hooks/abstract/abstract.h"
66
#include <ydb/core/tx/columnshard/blobs_action/blob_manager_db.h>
7+
#include <ydb/core/tx/columnshard/transactions/locks_db.h>
78

89
#include <ydb/core/tablet/tablet_exception.h>
910
#include <ydb/core/tx/columnshard/operations/write.h>
@@ -177,6 +178,15 @@ bool TTxInit::ReadEverything(TTransactionContext& txc, const TActorContext& ctx)
177178
}
178179
}
179180
}
181+
{
182+
TMemoryProfileGuard g("TTxInit/LocksDB");
183+
if (txc.DB.GetScheme().GetTableInfo(Schema::Locks::TableId)) {
184+
TColumnShardLocksDb locksDb(*Self, txc);
185+
if (!Self->SysLocks.Load(locksDb)) {
186+
return false;
187+
}
188+
}
189+
}
180190

181191
Self->UpdateInsertTableCounters();
182192
Self->UpdateIndexCounters();

ydb/core/tx/columnshard/columnshard_impl.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ TColumnShard::TColumnShard(TTabletStorageInfo* info, const TActorId& tablet)
9393
, ScanCounters("Scan")
9494
, WritesMonitor(*this)
9595
, NormalizerController(StoragesManager, SubscribeCounters)
96+
, SysLocks(this)
9697
{
9798
TabletCountersPtr.reset(new TProtobufTabletCounters<
9899
ESimpleCounters_descriptor,

ydb/core/tx/columnshard/columnshard_impl.h

+44-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
#include <ydb/core/tx/tiering/manager.h>
2626
#include <ydb/core/tx/time_cast/time_cast.h>
2727
#include <ydb/core/tx/tx_processing.h>
28+
#include <ydb/core/tx/locks/locks.h>
2829
#include <ydb/services/metadata/service.h>
2930

31+
#include <ydb/core/tx/datashard/datashard_user_table.h>
32+
3033
namespace NKikimr::NOlap {
3134
class TCleanupColumnEngineChanges;
3235
class TTTLColumnEngineChanges;
@@ -206,10 +209,6 @@ class TColumnShard
206209
TabletCounters->Cumulative()[counter].Increment(num);
207210
}
208211

209-
void IncCounter(NColumnShard::EPercentileCounters counter, const TDuration& latency) const {
210-
TabletCounters->Percentile()[counter].IncrementFor(latency.MicroSeconds());
211-
}
212-
213212
void ActivateTiering(const ui64 pathId, const TString& useTiering, const bool onTabletInit = false);
214213
void OnTieringModified();
215214
public:
@@ -220,6 +219,41 @@ class TColumnShard
220219
None /* "none" */
221220
};
222221

222+
void IncCounter(NColumnShard::EPercentileCounters counter, const TDuration& latency) const {
223+
TabletCounters->Percentile()[counter].IncrementFor(latency.MicroSeconds());
224+
}
225+
226+
void IncCounter(NDataShard::ESimpleCounters counter, ui64 num = 1) const {
227+
TabletCounters->Simple()[counter].Add(num);
228+
}
229+
230+
// For systable
231+
void IncCounter(NDataShard::ECumulativeCounters counter, ui64 num = 1) const {
232+
TabletCounters->Cumulative()[counter].Increment(num);
233+
}
234+
235+
void IncCounter(NDataShard::EPercentileCounters counter, ui64 num) const {
236+
TabletCounters->Percentile()[counter].IncrementFor(num);
237+
}
238+
239+
void IncCounter(NDataShard::EPercentileCounters counter, const TDuration& latency) const {
240+
TabletCounters->Percentile()[counter].IncrementFor(latency.MilliSeconds());
241+
}
242+
243+
inline TRowVersion LastCompleteTxVersion() const {
244+
return TRowVersion(LastCompletedStep, LastCompletedTxId);
245+
}
246+
247+
ui32 Generation() const { return Executor()->Generation(); }
248+
249+
bool IsUserTable(const TTableId&) const {
250+
return false;
251+
}
252+
253+
const THashMap<ui64, NDataShard::TUserTable::TCPtr> &GetUserTables() const {
254+
return Default<THashMap<ui64, NDataShard::TUserTable::TCPtr>>();
255+
}
256+
223257
private:
224258
void OverloadWriteFail(const EOverloadStatus overloadReason, const NEvWrite::TWriteData& writeData, std::unique_ptr<NActors::IEventBase>&& event, const TActorContext& ctx);
225259
EOverloadStatus CheckOverloaded(const ui64 tableId) const;
@@ -281,6 +315,9 @@ class TColumnShard
281315
}
282316
}
283317

318+
public:
319+
TTabletCountersBase* TabletCounters;
320+
284321
private:
285322
std::unique_ptr<TTxController> ProgressTxController;
286323
std::unique_ptr<TOperationsManager> OperationsManager;
@@ -360,6 +397,8 @@ class TColumnShard
360397
TWriteId LastWriteId = TWriteId{0};
361398
ui64 LastPlannedStep = 0;
362399
ui64 LastPlannedTxId = 0;
400+
ui64 LastCompletedStep = 0;
401+
ui64 LastCompletedTxId = 0;
363402
ui64 LastExportNo = 0;
364403

365404
ui64 OwnerPathId = 0;
@@ -386,7 +425,6 @@ class TColumnShard
386425
TTablesManager TablesManager;
387426
std::shared_ptr<TTiersManager> Tiers;
388427
std::unique_ptr<TTabletCountersBase> TabletCountersPtr;
389-
TTabletCountersBase* TabletCounters;
390428
std::unique_ptr<NTabletPipe::IClientCache> PipeClientCache;
391429
std::unique_ptr<NOlap::TInsertTable> InsertTable;
392430
std::shared_ptr<NOlap::NResourceBroker::NSubscribe::TSubscriberCounters> SubscribeCounters;
@@ -412,6 +450,7 @@ class TColumnShard
412450
TLimits Limits;
413451
TCompactionLimits CompactionLimits;
414452
NOlap::TNormalizationController NormalizerController;
453+
NDataShard::TSysLocks SysLocks;
415454

416455
void TryRegisterMediatorTimeCast();
417456
void UnregisterMediatorTimeCast();

ydb/core/tx/columnshard/columnshard_schema.h

+45-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ struct Schema : NIceDb::Schema {
3838
ColumnsTableId,
3939
CountersTableId,
4040
OperationsTableId,
41-
IndexesTableId
41+
IndexesTableId,
42+
LocksTableId,
43+
LockRangesTableId,
44+
LockConflictsTableId,
45+
LockVolatileDependenciesTableId
4246
};
4347

4448
enum class ETierTables: ui32 {
@@ -305,6 +309,46 @@ struct Schema : NIceDb::Schema {
305309
using TColumns = TableColumns<PathId, PortionId, IndexId, ChunkIdx, Blob, Offset, Size, RecordsCount, RawBytes>;
306310
};
307311

312+
struct Locks : Table<LocksTableId> {
313+
struct LockId : Column<1, NScheme::NTypeIds::Uint64> {};
314+
struct LockNodeId : Column<2, NScheme::NTypeIds::Uint32> {};
315+
struct Generation : Column<3, NScheme::NTypeIds::Uint32> {};
316+
struct Counter : Column<4, NScheme::NTypeIds::Uint64> {};
317+
struct CreateTimestamp : Column<5, NScheme::NTypeIds::Uint64> {};
318+
struct Flags : Column<6, NScheme::NTypeIds::Uint64> {};
319+
320+
using TKey = TableKey<LockId>;
321+
using TColumns = TableColumns<LockId, LockNodeId, Generation, Counter, CreateTimestamp, Flags>;
322+
};
323+
324+
struct LockRanges : Table<LockRangesTableId> {
325+
struct LockId : Column<1, NScheme::NTypeIds::Uint64> {};
326+
struct RangeId : Column<2, NScheme::NTypeIds::Uint64> {};
327+
struct PathOwnerId : Column<3, NScheme::NTypeIds::Uint64> {};
328+
struct LocalPathId : Column<4, NScheme::NTypeIds::Uint64> {};
329+
struct Flags : Column<5, NScheme::NTypeIds::Uint64> {};
330+
struct Data : Column<6, NScheme::NTypeIds::String> {};
331+
332+
using TKey = TableKey<LockId, RangeId>;
333+
using TColumns = TableColumns<LockId, RangeId, PathOwnerId, LocalPathId, Flags, Data>;
334+
};
335+
336+
struct LockConflicts : Table<LockConflictsTableId> {
337+
struct LockId : Column<1, NScheme::NTypeIds::Uint64> {};
338+
struct ConflictId : Column<2, NScheme::NTypeIds::Uint64> {};
339+
340+
using TKey = TableKey<LockId, ConflictId>;
341+
using TColumns = TableColumns<LockId, ConflictId>;
342+
};
343+
344+
struct LockVolatileDependencies : Table<LockVolatileDependenciesTableId> {
345+
struct LockId : Column<1, NScheme::NTypeIds::Uint64> {};
346+
struct TxId : Column<2, NScheme::NTypeIds::Uint64> {};
347+
348+
using TKey = TableKey<LockId, TxId>;
349+
using TColumns = TableColumns<LockId, TxId>;
350+
};
351+
308352
using TTables = SchemaTables<
309353
Value,
310354
TxInfo,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "locks_db.h"
2+
3+
namespace NKikimr::NColumnShard {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
#include <ydb/core/tx/locks/locks_db.h>
3+
#include <ydb/core/tx/columnshard/columnshard_impl.h>
4+
5+
6+
namespace NKikimr::NColumnShard {
7+
8+
class TColumnShardLocksDb : public NLocks::TShardLocksDb<TColumnShard, NColumnShard::Schema> {
9+
private:
10+
using TBase = NLocks::TShardLocksDb<TColumnShard, NColumnShard::Schema>;
11+
12+
public:
13+
using TBase::TBase;
14+
15+
void PersistRemoveLock(ui64 lockId) override {
16+
NIceDb::TNiceDb db(DB);
17+
db.Table<NColumnShard::Schema::Locks>().Key(lockId).Delete();
18+
HasChanges_ = true;
19+
}
20+
};
21+
22+
}

ydb/core/tx/columnshard/transactions/ya.make

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ LIBRARY()
22

33
SRCS(
44
tx_controller.cpp
5+
locks_db.cpp
56
)
67

78
PEERDIR(
89
ydb/core/tablet_flat
910
ydb/core/tx/data_events
1011
)
1112

12-
IF (OS_WINDOWS)
13-
CFLAGS(
14-
-DKIKIMR_DISABLE_S3_OPS
15-
)
16-
ENDIF()
17-
1813
YQL_LAST_ABI_VERSION()
1914

2015
END()

ydb/core/tx/datashard/build_and_wait_dependencies_unit.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "datashard_impl.h"
2-
#include "datashard_counters.h"
32
#include "datashard_pipeline.h"
43
#include "execution_unit_ctors.h"
54

5+
#include <ydb/core/tx/locks/time_counters.h>
6+
67
namespace NKikimr {
78
namespace NDataShard {
89

ydb/core/tx/datashard/datashard__engine_host.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "datashard_impl.h"
33
#include "datashard_user_db.h"
44
#include "datashard__engine_host.h"
5-
#include "sys_tables.h"
5+
#include <ydb/core/tx/locks/sys_tables.h>
66

77
#include <ydb/core/engine/minikql/minikql_engine_host.h>
88
#include <ydb/core/kqp/rm_service/kqp_rm_service.h>

ydb/core/tx/datashard/datashard_active_transaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
#include "datashard_active_transaction.h"
44
#include "datashard_kqp.h"
5-
#include "datashard_locks.h"
65
#include "datashard_impl.h"
76
#include "datashard_failpoints.h"
87
#include "key_conflicts.h"
98

9+
#include <ydb/core/tx/locks/locks.h>
1010
#include <ydb/library/actors/util/memory_track.h>
1111

1212
namespace NKikimr {

ydb/core/tx/datashard/datashard_active_transaction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "datashard.h"
4-
#include "datashard_locks.h"
4+
#include <ydb/core/tx/locks/locks.h>
55
#include "datashard__engine_host.h"
66
#include "operation.h"
77

ydb/core/tx/datashard/datashard_dep_tracker.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "datashard.h"
44
#include "datashard_user_table.h"
55
#include "datashard_active_transaction.h"
6-
#include "range_treap.h"
6+
#include <ydb/core/tx/locks/range_treap.h>
77

88
#include <library/cpp/containers/absl_flat_hash/flat_hash_map.h>
99

ydb/core/tx/datashard/datashard_direct_transaction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "datashard_impl.h"
4-
#include "datashard_locks.h"
4+
#include <ydb/core/tx/locks/locks.h>
55
#include "operation.h"
66

77
#include <ydb/core/engine/minikql/change_collector_iface.h>

ydb/core/tx/datashard/datashard_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "datashard.h"
4-
#include "datashard_locks.h"
54
#include "datashard_trans_queue.h"
65
#include "datashard_outreadset.h"
76
#include "datashard_pipeline.h"
@@ -29,6 +28,7 @@
2928
#include <ydb/core/tx/tx_processing.h>
3029
#include <ydb/core/tx/tx_proxy/proxy.h>
3130
#include <ydb/core/tx/schemeshard/schemeshard.h>
31+
#include <ydb/core/tx/locks/locks.h>
3232

3333
#include <ydb/core/base/appdata.h>
3434
#include <ydb/core/base/tablet_pipe.h>

ydb/core/tx/datashard/datashard_kqp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <ydb/core/kqp/runtime/kqp_tasks_runner.h>
77
#include <ydb/core/scheme/scheme_tablecell.h>
88
#include <ydb/core/scheme/scheme_types_proto.h>
9-
#include <ydb/core/tx/datashard/datashard_locks.h>
9+
#include <ydb/core/tx/locks/locks.h>
1010
#include <ydb/core/tx/datashard/datashard_user_table.h>
1111
#include <ydb/core/tx/datashard/range_ops.h>
1212

ydb/core/tx/datashard/datashard_kqp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#include "operation.h"
66
#include "key_validator.h"
7-
#include "datashard_locks.h"
87
#include "datashard_user_db.h"
98

109
#include <ydb/core/engine/minikql/minikql_engine_host.h>
1110
#include <ydb/core/kqp/runtime/kqp_tasks_runner.h>
11+
#include <ydb/core/tx/locks/locks_db.h>
1212

1313
#include <util/generic/ptr.h>
1414

0 commit comments

Comments
 (0)