@@ -62,7 +62,7 @@ ui64 CalculateValueBytes(const TArrayRef<const NIceDb::TUpdateOp> ops) {
6262 return bytes;
6363};
6464
65- void TDataShardUserDb::UpdateRow (
65+ void TDataShardUserDb::UpsertRow (
6666 const TTableId& tableId,
6767 const TArrayRef<const TRawTypeValue> key,
6868 const TArrayRef<const NIceDb::TUpdateOp> ops)
@@ -108,11 +108,11 @@ void TDataShardUserDb::UpdateRow(
108108 if (specUpdates.ColIdUpdateNo != Max<ui32>()) {
109109 addExtendedOp (specUpdates.ColIdUpdateNo , specUpdates.UpdateNo );
110110 }
111- UpdateRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, extendedOps);
111+ UpsertRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, extendedOps);
112112
113113 IncreaseUpdateCounters (key, extendedOps);
114114 } else {
115- UpdateRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, ops);
115+ UpsertRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, ops);
116116
117117 IncreaseUpdateCounters (key, ops);
118118 }
@@ -126,7 +126,7 @@ void TDataShardUserDb::ReplaceRow(
126126 auto localTableId = Self.GetLocalTableId (tableId);
127127 Y_ABORT_UNLESS (localTableId != 0 , " Unexpected ReplaceRow for an unknown table" );
128128
129- UpdateRowInt (NTable::ERowOp::Reset, tableId, localTableId, key, ops);
129+ UpsertRowInt (NTable::ERowOp::Reset, tableId, localTableId, key, ops);
130130
131131 IncreaseUpdateCounters (key, ops);
132132}
@@ -139,9 +139,26 @@ void TDataShardUserDb::InsertRow(
139139 auto localTableId = Self.GetLocalTableId (tableId);
140140 Y_ABORT_UNLESS (localTableId != 0 , " Unexpected InsertRow for an unknown table" );
141141
142- EnsureMissingRow (tableId, key);
142+ if (RowExists (tableId, key))
143+ throw TUniqueConstrainException ();
144+
145+ UpsertRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, ops);
146+
147+ IncreaseUpdateCounters (key, ops);
148+ }
149+
150+ void TDataShardUserDb::UpdateRow (
151+ const TTableId& tableId,
152+ const TArrayRef<const TRawTypeValue> key,
153+ const TArrayRef<const NIceDb::TUpdateOp> ops)
154+ {
155+ auto localTableId = Self.GetLocalTableId (tableId);
156+ Y_ABORT_UNLESS (localTableId != 0 , " Unexpected UpdateRow for an unknown table" );
157+
158+ if (!RowExists (tableId, key))
159+ return ;
143160
144- UpdateRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, ops);
161+ UpsertRowInt (NTable::ERowOp::Upsert, tableId, localTableId, key, ops);
145162
146163 IncreaseUpdateCounters (key, ops);
147164}
@@ -153,7 +170,7 @@ void TDataShardUserDb::EraseRow(
153170 auto localTableId = Self.GetLocalTableId (tableId);
154171 Y_ABORT_UNLESS (localTableId != 0 , " Unexpected UpdateRow for an unknown table" );
155172
156- UpdateRowInt (NTable::ERowOp::Erase, tableId, localTableId, key, {});
173+ UpsertRowInt (NTable::ERowOp::Erase, tableId, localTableId, key, {});
157174
158175 ui64 keyBytes = CalculateKeyBytes (key);
159176
@@ -172,7 +189,7 @@ void TDataShardUserDb::IncreaseUpdateCounters(
172189 Counters.UpdateRowBytes += keyBytes + valueBytes;
173190}
174191
175- void TDataShardUserDb::UpdateRowInt (
192+ void TDataShardUserDb::UpsertRowInt (
176193 NTable::ERowOp rowOp,
177194 const TTableId& tableId,
178195 ui64 localTableId,
@@ -216,7 +233,7 @@ void TDataShardUserDb::UpdateRowInt(
216233 Self.GetKeyAccessSampler ()->AddSample (tableId, keyCells);
217234}
218235
219- void TDataShardUserDb::EnsureMissingRow (
236+ bool TDataShardUserDb::RowExists (
220237 const TTableId& tableId,
221238 const TArrayRef<const TRawTypeValue> key)
222239{
@@ -227,12 +244,10 @@ void TDataShardUserDb::EnsureMissingRow (
227244 throw TNotReadyTabletException ();
228245 }
229246 case NTable::EReady::Data: {
230- if (rowState == NTable::ERowOp::Upsert)
231- throw TUniqueConstrainException ();
232- break ;
247+ return true ;
233248 }
234249 case NTable::EReady::Gone: {
235- break ;
250+ return false ;
236251 }
237252 }
238253}
0 commit comments