aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorponasenko-rs <ponasenko-rs@yandex-team.com>2023-12-08 13:31:18 +0300
committerponasenko-rs <ponasenko-rs@yandex-team.com>2023-12-08 14:55:36 +0300
commitab9f19c8c2ce7ef36f054686c8a22d8c7e9133b3 (patch)
tree220a2cd0c80c869a4a53935cc6fccf0c249e06a6
parent55eb3c2eceed1b0fb22e925a16ddf159349aed62 (diff)
downloadydb-ab9f19c8c2ce7ef36f054686c8a22d8c7e9133b3.tar.gz
YT-19441: Shared write locks post-commit fixes.
-rw-r--r--yt/yt/client/api/transaction.cpp59
-rw-r--r--yt/yt/client/table_client/schema-inl.h3
-rw-r--r--yt/yt/client/table_client/unversioned_row.cpp4
-rw-r--r--yt/yt/client/table_client/unversioned_row.h2
4 files changed, 40 insertions, 28 deletions
diff --git a/yt/yt/client/api/transaction.cpp b/yt/yt/client/api/transaction.cpp
index c6e2698af3..8a2c421da8 100644
--- a/yt/yt/client/api/transaction.cpp
+++ b/yt/yt/client/api/transaction.cpp
@@ -24,40 +24,51 @@ void ITransaction::WriteRows(
const TModifyRowsOptions& options,
ELockType lockType)
{
- THROW_ERROR_EXCEPTION_IF(!IsWriteLock(lockType), "Inappropriate lock type %Qv given for write operation",
+ THROW_ERROR_EXCEPTION_UNLESS(IsWriteLock(lockType), "Inappropriate lock type %Qlv given for write modification",
lockType);
std::vector<TRowModification> modifications;
modifications.reserve(rows.Size());
- if (lockType == ELockType::Exclusive) {
- for (auto row : rows) {
- modifications.push_back({ERowModificationType::Write, row.ToTypeErasedRow(), TLockMask()});
+ switch (lockType) {
+ case ELockType::Exclusive: {
+ for (auto row : rows) {
+ modifications.push_back({ERowModificationType::Write, row.ToTypeErasedRow(), TLockMask()});
+ }
+
+ break;
}
- } else {
- // NB: This mount revision could differ from the one will be send to tablet node.
- // However locks correctness will be checked in native transaction.
- const auto& tableMountCache = GetClient()->GetTableMountCache();
- auto tableInfo = WaitFor(tableMountCache->GetTableInfo(path))
- .ValueOrThrow();
-
- std::vector<int> columnIndexToLockIndex;
- GetLocksMapping(
- *tableInfo->Schemas[ETableSchemaKind::Write],
- GetAtomicity() == NTransactionClient::EAtomicity::Full,
- &columnIndexToLockIndex);
-
- for (auto row : rows) {
- TLockMask lockMask;
- for (int index = 0; index < static_cast<int>(row.GetCount()); ++index) {
- auto lockIndex = columnIndexToLockIndex[row[index].Id];
- if (lockIndex != -1) {
- lockMask.Set(lockIndex, lockType);
+
+ case ELockType::SharedWrite: {
+ // NB: This mount revision could differ from the one will be sent to tablet node.
+ // However locks correctness will be checked in native transaction.
+ const auto& tableMountCache = GetClient()->GetTableMountCache();
+ auto tableInfo = WaitFor(tableMountCache->GetTableInfo(path))
+ .ValueOrThrow();
+
+ std::vector<int> columnIndexToLockIndex;
+ GetLocksMapping(
+ *tableInfo->Schemas[ETableSchemaKind::Write],
+ GetAtomicity() == NTransactionClient::EAtomicity::Full,
+ &columnIndexToLockIndex);
+
+ for (auto row : rows) {
+ TLockMask lockMask;
+ for (const auto& value : row) {
+ auto lockIndex = columnIndexToLockIndex[value.Id];
+ if (lockIndex != -1) {
+ lockMask.Set(lockIndex, lockType);
+ }
}
+
+ modifications.push_back({ERowModificationType::WriteAndLock, row.ToTypeErasedRow(), lockMask});
}
- modifications.push_back({ERowModificationType::WriteAndLock, row.ToTypeErasedRow(), lockMask});
+ break;
}
+
+ default:
+ YT_ABORT();
}
ModifyRows(
diff --git a/yt/yt/client/table_client/schema-inl.h b/yt/yt/client/table_client/schema-inl.h
index 364ff584c0..290b68a1d3 100644
--- a/yt/yt/client/table_client/schema-inl.h
+++ b/yt/yt/client/table_client/schema-inl.h
@@ -131,7 +131,8 @@ inline bool TLockMask::HasNewLocks() const
return false;
}
-inline bool TLockMask::IsNone() const {
+inline bool TLockMask::IsNone() const
+{
for (int index = 0; index < GetSize(); ++index) {
if (Get(index) != ELockType::None) {
return false;
diff --git a/yt/yt/client/table_client/unversioned_row.cpp b/yt/yt/client/table_client/unversioned_row.cpp
index 874c175d4d..7a28b1333f 100644
--- a/yt/yt/client/table_client/unversioned_row.cpp
+++ b/yt/yt/client/table_client/unversioned_row.cpp
@@ -1242,12 +1242,12 @@ bool ValidateNonKeyColumnsAgainstLock(
const TLockMask& locks,
const TTableSchema& schema,
const TNameTableToSchemaIdMapping& idMapping,
- const TNameTablePtr nameTable,
+ const TNameTablePtr& nameTable,
const std::vector<int>& columnIndexToLockIndex,
bool allowSharedWriteLocks)
{
bool hasNonKeyColumns = false;
- for (const auto value : row) {
+ for (const auto& value : row) {
int mappedId = ApplyIdMapping(value, &idMapping);
if (mappedId < 0 || mappedId >= std::ssize(schema.Columns())) {
int size = nameTable->GetSize();
diff --git a/yt/yt/client/table_client/unversioned_row.h b/yt/yt/client/table_client/unversioned_row.h
index ccbb73e03f..0fc6420396 100644
--- a/yt/yt/client/table_client/unversioned_row.h
+++ b/yt/yt/client/table_client/unversioned_row.h
@@ -450,7 +450,7 @@ bool ValidateNonKeyColumnsAgainstLock(
const TLockMask& locks,
const TTableSchema& schema,
const TNameTableToSchemaIdMapping& idMapping,
- const TNameTablePtr nameTable,
+ const TNameTablePtr& nameTable,
const std::vector<int>& columnIndexToLockIndex,
bool allowSharedWriteLocks);