diff options
| -rw-r--r-- | yt/yt/client/api/transaction.cpp | 55 | ||||
| -rw-r--r-- | yt/yt/client/table_client/schema-inl.h | 3 | ||||
| -rw-r--r-- | yt/yt/client/table_client/unversioned_row.cpp | 4 | ||||
| -rw-r--r-- | yt/yt/client/table_client/unversioned_row.h | 2 |
4 files changed, 38 insertions, 26 deletions
diff --git a/yt/yt/client/api/transaction.cpp b/yt/yt/client/api/transaction.cpp index c6e2698af35..8a2c421da8e 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); + 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 (int index = 0; index < static_cast<int>(row.GetCount()); ++index) { - auto lockIndex = columnIndexToLockIndex[row[index].Id]; - if (lockIndex != -1) { - lockMask.Set(lockIndex, lockType); + 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 364ff584c07..290b68a1d33 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 874c175d4d5..7a28b1333f6 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 ccbb73e03f4..0fc64203965 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); |
