Skip to content

Commit 7857771

Browse files
authored
ut for deleting absent rows (#13172)
1 parent 9740792 commit 7857771

File tree

7 files changed

+59
-5
lines changed

7 files changed

+59
-5
lines changed

.github/config/muted_ya.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ydb/core/keyvalue/ut_trace TKeyValueTracingTest.WriteSmall
2525
ydb/core/kqp/ut/cost KqpCost.OlapWriteRow
2626
ydb/core/kqp/ut/data_integrity KqpDataIntegrityTrails.Select
2727
ydb/core/kqp/ut/data_integrity KqpDataIntegrityTrails.UpsertEvWrite
28+
ydb/core/kqp/ut/olap KqpOlap.DeleteAbsent+Reboot
2829
ydb/core/kqp/ut/olap KqpDecimalColumnShard.TestAggregation
2930
ydb/core/kqp/ut/olap KqpDecimalColumnShard.TestFilterCompare
3031
ydb/core/kqp/ut/olap KqpOlap.ManyColumnShardsWithRestarts

ydb/core/kqp/ut/olap/kqp_olap_ut.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,36 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
29912991
.GetValueSync();
29922992
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
29932993
}
2994+
2995+
Y_UNIT_TEST_TWIN(DeleteAbsent, Reboot) {
2996+
//This test tries to DELETE from a table with WHERE condition that matches no rows
2997+
//It corresponds to a SCAN, then NO write then COMMIT
2998+
auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NYDBTest::NColumnShard::TController>();
2999+
3000+
NKikimrConfig::TAppConfig appConfig;
3001+
auto settings = TKikimrSettings().SetAppConfig(appConfig).SetWithSampleTables(false);
3002+
TTestHelper testHelper(settings);
3003+
3004+
TVector<TTestHelper::TColumnSchema> schema = {
3005+
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int64).SetNullable(false),
3006+
TTestHelper::TColumnSchema().SetName("value").SetType(NScheme::NTypeIds::Int32).SetNullable(true),
3007+
};
3008+
TTestHelper::TColumnTable testTable;
3009+
testTable.SetName("/Root/ttt").SetPrimaryKey({ "id" }).SetSharding({ "id" }).SetSchema(schema);
3010+
testHelper.CreateTable(testTable);
3011+
3012+
if (Reboot) {
3013+
csController->SetRestartOnLocalTxCommitted("TProposeWriteTransaction");
3014+
}
3015+
auto client = testHelper.GetKikimr().GetQueryClient();
3016+
const auto resultDelete =
3017+
client
3018+
.ExecuteQuery(
3019+
"DELETE from `/Root/ttt` WHERE value % 2 == 1;",
3020+
NYdb::NQuery::TTxControl::BeginTx().CommitTx())
3021+
.GetValueSync();
3022+
UNIT_ASSERT_C(resultDelete.IsSuccess(), resultDelete.GetIssues().ToString());
3023+
}
29943024
}
29953025

29963026
}

ydb/core/tx/columnshard/columnshard__write.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,19 @@ class TCommitOperation {
376376
ui64 ArbiterColumnShard = 0;
377377
};
378378

379-
class TProposeWriteTransaction: public NTabletFlatExecutor::TTransactionBase<TColumnShard> {
379+
class TProposeWriteTransaction: public TExtendedTransactionBase {
380380
private:
381-
using TBase = NTabletFlatExecutor::TTransactionBase<TColumnShard>;
381+
using TBase = TExtendedTransactionBase;
382382

383383
public:
384384
TProposeWriteTransaction(TColumnShard* self, TCommitOperation::TPtr op, const TActorId source, const ui64 cookie)
385-
: TBase(self)
385+
: TBase(self, "TProposeWriteTransaction")
386386
, WriteCommit(op)
387387
, Source(source)
388388
, Cookie(cookie) {
389389
}
390390

391-
virtual bool Execute(TTransactionContext& txc, const TActorContext&) override {
391+
virtual bool DoExecute(TTransactionContext& txc, const TActorContext&) override {
392392
NKikimrTxColumnShard::TCommitWriteTxBody proto;
393393
NKikimrTxColumnShard::ETransactionKind kind;
394394
if (WriteCommit->NeedSyncLocks()) {
@@ -407,7 +407,7 @@ class TProposeWriteTransaction: public NTabletFlatExecutor::TTransactionBase<TCo
407407
return true;
408408
}
409409

410-
virtual void Complete(const TActorContext& ctx) override {
410+
virtual void DoComplete(const TActorContext& ctx) override {
411411
Self->GetProgressTxController().FinishProposeOnComplete(WriteCommit->GetTxId(), ctx);
412412
}
413413
TTxType GetTxType() const override {

ydb/core/tx/columnshard/hooks/abstract/abstract.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ class ICSController {
322322
virtual void OnCleanupActors(const ui64 tabletId) {
323323
Y_UNUSED(tabletId);
324324
}
325+
326+
virtual void OnAfterLocalTxCommitted(const NActors::TActorContext& ctx, const NColumnShard::TColumnShard& shard, const TString& txInfo) {
327+
Y_UNUSED(ctx);
328+
Y_UNUSED(shard);
329+
Y_UNUSED(txInfo);
330+
}
331+
325332
};
326333

327334
class TControllers {

ydb/core/tx/columnshard/hooks/testing/controller.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,10 @@ ::NKikimr::NColumnShard::TBlobPutResult::TPtr TController::OverrideBlobPutResult
145145
return result;
146146
}
147147

148+
void TController::OnAfterLocalTxCommitted(const NActors::TActorContext& ctx, const ::NKikimr::NColumnShard::TColumnShard& shard, const TString& txInfo) {
149+
if (RestartOnLocalDbTxCommitted == txInfo) {
150+
ctx.Send(shard.SelfId(), new TEvents::TEvPoisonPill{});
151+
}
152+
}
153+
148154
} // namespace NKikimr::NYDBTest::NColumnShard

ydb/core/tx/columnshard/hooks/testing/controller.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class TController: public TReadOnlyController {
132132
void CheckInvariants(const ::NKikimr::NColumnShard::TColumnShard& shard, TCheckContext& context) const;
133133

134134
THashSet<TString> SharingIds;
135+
136+
std::optional<TString> RestartOnLocalDbTxCommitted;
135137
protected:
136138
virtual const NOlap::NSplitter::TSplitSettings& DoGetBlobSplitSettings(const NOlap::NSplitter::TSplitSettings& defaultValue) const override {
137139
if (OverrideBlobSplitSettings) {
@@ -281,6 +283,13 @@ class TController: public TReadOnlyController {
281283
TGuard<TMutex> g(ActiveTabletsMutex);
282284
return ActiveTablets.contains(tabletId);
283285
}
286+
287+
void SetRestartOnLocalTxCommitted(std::optional<TString> txInfo) {
288+
RestartOnLocalDbTxCommitted = std::move(txInfo);
289+
}
290+
291+
virtual void OnAfterLocalTxCommitted(const NActors::TActorContext& ctx, const ::NKikimr::NColumnShard::TColumnShard& shard, const TString& txInfo) override;
292+
284293
};
285294

286295
}

ydb/core/tx/columnshard/tablet/ext_tx_base.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bool TExtendedTransactionBase::Execute(NTabletFlatExecutor::TTransactionContext&
1111
void TExtendedTransactionBase::Complete(const NActors::TActorContext& ctx) {
1212
NActors::TLogContextGuard logGuard = NActors::TLogContextBuilder::Build()("tablet_id", Self->TabletID())("local_tx_no", TabletTxNo)("method", "complete")("tx_info", TxInfo);
1313
DoComplete(ctx);
14+
NYDBTest::TControllers::GetColumnShardController()->OnAfterLocalTxCommitted(ctx, *Self, TxInfo);
1415
}
1516

1617
TExtendedTransactionBase::TExtendedTransactionBase(TColumnShard* self, const TString& txInfo)

0 commit comments

Comments
 (0)