diff options
author | snaury <snaury@ydb.tech> | 2023-04-05 15:53:57 +0300 |
---|---|---|
committer | snaury <snaury@ydb.tech> | 2023-04-05 15:53:57 +0300 |
commit | e4bb8963cf5d91898a2aa4534a719d7bf0f96b1a (patch) | |
tree | e6ee84455a147c7b9dac1ab5a2f5dcbcce696b62 | |
parent | 6dc558eee9997353e681325476197c57216ca0d9 (diff) | |
download | ydb-e4bb8963cf5d91898a2aa4534a719d7bf0f96b1a.tar.gz |
Fix compatibility with persisted tx artifacts
-rw-r--r-- | ydb/core/tx/datashard/datashard_active_transaction.cpp | 2 | ||||
-rw-r--r-- | ydb/core/tx/datashard/datashard_impl.h | 2 | ||||
-rw-r--r-- | ydb/core/tx/datashard/datashard_trans_queue.cpp | 7 | ||||
-rw-r--r-- | ydb/core/tx/datashard/sys_tables.h | 35 |
4 files changed, 34 insertions, 12 deletions
diff --git a/ydb/core/tx/datashard/datashard_active_transaction.cpp b/ydb/core/tx/datashard/datashard_active_transaction.cpp index 33d8c6f3086..8f334f8b1ff 100644 --- a/ydb/core/tx/datashard/datashard_active_transaction.cpp +++ b/ydb/core/tx/datashard/datashard_active_transaction.cpp @@ -582,7 +582,7 @@ void TActiveTransaction::DbStoreLocksAccessLog(TDataShard * self, using Schema = TDataShard::Schema; NIceDb::TNiceDb db(txc.DB); - TVector<TSysTables::TLocksTable::TLock> vec; + TVector<TSysTables::TLocksTable::TPersistentLock> vec; vec.reserve(LocksAccessLog().Locks.size()); for (auto &pr : LocksAccessLog().Locks) vec.emplace_back(pr.second); diff --git a/ydb/core/tx/datashard/datashard_impl.h b/ydb/core/tx/datashard/datashard_impl.h index 1cf51f6fd2e..39a24478c6c 100644 --- a/ydb/core/tx/datashard/datashard_impl.h +++ b/ydb/core/tx/datashard/datashard_impl.h @@ -642,7 +642,7 @@ class TDataShard // Specify which tx artifacts have been stored to local DB and can be // reused on tx replay. See TActiveTransaction::EArtifactFlags. struct Flags : Column<2, NScheme::NTypeIds::Uint64> {}; - struct Locks : Column<3, NScheme::NTypeIds::String> { using Type = TVector<TSysTables::TLocksTable::TLock>; }; + struct Locks : Column<3, NScheme::NTypeIds::String> { using Type = TVector<TSysTables::TLocksTable::TPersistentLock>; }; using TKey = TableKey<TxId>; using TColumns = TableColumns<TxId, Flags, Locks>; diff --git a/ydb/core/tx/datashard/datashard_trans_queue.cpp b/ydb/core/tx/datashard/datashard_trans_queue.cpp index 3c1f4633574..4e529eb25d7 100644 --- a/ydb/core/tx/datashard/datashard_trans_queue.cpp +++ b/ydb/core/tx/datashard/datashard_trans_queue.cpp @@ -360,7 +360,12 @@ bool TTransQueue::LoadTxDetails(NIceDb::TNiceDb &db, artifactFlags = 0; if (!artifactsRow.EndOfSet()) { artifactFlags = artifactsRow.GetValue<Schema::TxArtifacts::Flags>(); - locks = artifactsRow.GetValueOrDefault<Schema::TxArtifacts::Locks>({}); + auto persistentLocks = artifactsRow.GetValueOrDefault<Schema::TxArtifacts::Locks>({}); + locks.clear(); + locks.reserve(persistentLocks.size()); + for (const auto& persistentLock : persistentLocks) { + locks.push_back(TSysTables::TLocksTable::TLock::FromPersistent(persistentLock)); + } } return true; diff --git a/ydb/core/tx/datashard/sys_tables.h b/ydb/core/tx/datashard/sys_tables.h index c424b604782..811af55bfee 100644 --- a/ydb/core/tx/datashard/sys_tables.h +++ b/ydb/core/tx/datashard/sys_tables.h @@ -48,15 +48,8 @@ struct TSysTables { PathId, }; - struct TLock { - enum ESetErrors : ui64 { - ErrorMin = Max<ui64>() - 255, - ErrorAlreadyBroken = Max<ui64>() - 3, - ErrorNotSet = Max<ui64>() - 2, - ErrorTooMuch = Max<ui64>() - 1, - ErrorBroken = Max<ui64>() - }; - + // WARNING: this struct is persisted in datashard db, do not change size or layout + struct TPersistentLock { ui64 LockId = 0; ui64 DataShard = 0; ui32 Generation = 0; @@ -65,6 +58,19 @@ struct TSysTables { ui64 Counter = 0; ui64 SchemeShard = 0; ui64 PathId = 0; + }; + + static_assert(sizeof(TPersistentLock) == 48, "Unexpected change in TPersistentLock size"); + + struct TLock : public TPersistentLock { + enum ESetErrors : ui64 { + ErrorMin = Max<ui64>() - 255, + ErrorAlreadyBroken = Max<ui64>() - 3, + ErrorNotSet = Max<ui64>() - 2, + ErrorTooMuch = Max<ui64>() - 1, + ErrorBroken = Max<ui64>() + }; + bool HasWrites = false; // Not exposed as a column bool IsEmpty() const { return (LockId == 0); } @@ -95,6 +101,17 @@ struct TSysTables { } } } + + static TLock FromPersistent(const TPersistentLock& lock) { + TLock result; + result.LockId = lock.LockId; + result.DataShard = lock.DataShard; + result.Generation = lock.Generation; + result.Counter = lock.Counter; + result.SchemeShard = lock.SchemeShard; + result.PathId = lock.PathId; + return result; + } }; static const char * GetColName(EColumns colId) { |