3
3
#include " columnshard_schema.h"
4
4
#include < ydb/library/yql/dq/actors/compute/dq_compute_actor.h>
5
5
#include < ydb/library/yql/dq/actors/dq.h>
6
+ #include < ydb/core/tx/columnshard/transactions/propose_transaction_base.h>
6
7
7
8
namespace NKikimr ::NColumnShard {
8
9
9
10
using namespace NTabletFlatExecutor ;
10
11
11
- class TTxProposeTransaction : public NTabletFlatExecutor ::TTransactionBase<TColumnShard> {
12
+ class TTxProposeTransaction : public TProposeTransactionBase {
12
13
public:
13
14
TTxProposeTransaction (TColumnShard* self, TEvColumnShard::TEvProposeTransaction::TPtr& ev)
14
- : TBase (self)
15
+ : TProposeTransactionBase (self)
15
16
, Ev(ev)
16
- , TabletTxNo(++Self->TabletTxCounter)
17
17
{}
18
18
19
19
bool Execute (TTransactionContext& txc, const TActorContext& ctx) override ;
@@ -22,35 +22,26 @@ class TTxProposeTransaction : public NTabletFlatExecutor::TTransactionBase<TColu
22
22
23
23
private:
24
24
TEvColumnShard::TEvProposeTransaction::TPtr Ev;
25
- const ui32 TabletTxNo;
26
25
std::unique_ptr<TEvColumnShard::TEvProposeTransactionResult> Result;
27
26
28
- TStringBuilder TxPrefix () const {
29
- return TStringBuilder () << " TxProposeTransaction[" << ToString (TabletTxNo) << " ] " ;
30
- }
31
-
32
- TString TxSuffix () const {
33
- return TStringBuilder () << " at tablet " << Self->TabletID ();
34
- }
35
-
36
- void ConstructResult (TTxController::TProposeResult& proposeResult, const TTxController::TBasicTxInfo& txInfo);
27
+ void OnProposeResult (TTxController::TProposeResult& proposeResult, const TTxController::TTxInfo& txInfo) override ;
28
+ void OnProposeError (TTxController::TProposeResult& proposeResult, const TTxController::TBasicTxInfo& txInfo) override ;
37
29
TTxController::TProposeResult ProposeTtlDeprecated (const TString& txBody);
38
30
};
39
31
40
32
41
33
bool TTxProposeTransaction::Execute (TTransactionContext& txc, const TActorContext& /* ctx*/ ) {
42
34
Y_ABORT_UNLESS (Ev);
43
- LOG_S_DEBUG (TxPrefix () << " execute" << TxSuffix ());
44
35
45
36
txc.DB .NoMoreReadsForTx ();
46
37
NIceDb::TNiceDb db (txc.DB );
47
38
48
39
Self->IncCounter (COUNTER_PREPARE_REQUEST);
49
40
50
41
auto & record = Proto (Ev->Get ());
51
- auto txKind = record.GetTxKind ();
52
- ui64 txId = record.GetTxId ();
53
- auto & txBody = record.GetTxBody ();
42
+ const auto txKind = record.GetTxKind ();
43
+ const ui64 txId = record.GetTxId ();
44
+ const auto & txBody = record.GetTxBody ();
54
45
55
46
if (txKind == NKikimrTxColumnShard::TX_KIND_TTL) {
56
47
auto proposeResult = ProposeTtlDeprecated (txBody);
@@ -71,39 +62,7 @@ bool TTxProposeTransaction::Execute(TTransactionContext& txc, const TActorContex
71
62
Y_ABORT_UNLESS (Self->CurrentSchemeShardId == record.GetSchemeShardId ());
72
63
}
73
64
}
74
-
75
- TTxController::TBasicTxInfo fakeTxInfo;
76
- fakeTxInfo.TxId = txId;
77
- fakeTxInfo.TxKind = txKind;
78
-
79
- auto txOperator = TTxController::ITransactionOperatior::TFactory::MakeHolder (txKind, fakeTxInfo);
80
- if (!txOperator || !txOperator->Parse (txBody)) {
81
- TTxController::TProposeResult proposeResult (NKikimrTxColumnShard::EResultStatus::ERROR, TStringBuilder () << " Error processing commit TxId# " << txId
82
- << (txOperator ? " . Parsing error " : " . Unknown operator for txKind" ));
83
- ConstructResult (proposeResult, fakeTxInfo);
84
- return true ;
85
- }
86
-
87
- auto txInfoPtr = Self->ProgressTxController ->GetTxInfo (txId);
88
- if (!!txInfoPtr) {
89
- if (txInfoPtr->Source != Ev->Get ()->GetSource () || txInfoPtr->Cookie != Ev->Cookie ) {
90
- TTxController::TProposeResult proposeResult (NKikimrTxColumnShard::EResultStatus::ERROR, TStringBuilder () << " Another commit TxId# " << txId << " has already been proposed" );
91
- ConstructResult (proposeResult, fakeTxInfo);
92
- }
93
- TTxController::TProposeResult proposeResult;
94
- ConstructResult (proposeResult, *txInfoPtr);
95
- } else {
96
- auto proposeResult = txOperator->Propose (*Self, txc, false );
97
- if (!!proposeResult) {
98
- const auto & txInfo = txOperator->TxWithDeadline () ? Self->ProgressTxController ->RegisterTxWithDeadline (txId, txKind, txBody, Ev->Get ()->GetSource (), Ev->Cookie , txc)
99
- : Self->ProgressTxController ->RegisterTx (txId, txKind, txBody, Ev->Get ()->GetSource (), Ev->Cookie , txc);
100
-
101
- ConstructResult (proposeResult, txInfo);
102
- } else {
103
- ConstructResult (proposeResult, fakeTxInfo);
104
- }
105
- }
106
- AFL_VERIFY (!!Result);
65
+ ProposeTransaction (TTxController::TBasicTxInfo (txKind, txId), txBody, Ev->Get ()->GetSource (), Ev->Cookie , txc);
107
66
return true ;
108
67
}
109
68
@@ -154,21 +113,21 @@ TTxController::TProposeResult TTxProposeTransaction::ProposeTtlDeprecated(const
154
113
return TTxController::TProposeResult ();
155
114
}
156
115
157
- void TTxProposeTransaction::ConstructResult (TTxController::TProposeResult& proposeResult, const TTxController::TBasicTxInfo& txInfo) {
116
+ void TTxProposeTransaction::OnProposeError (TTxController::TProposeResult& proposeResult, const TTxController::TBasicTxInfo& txInfo) {
158
117
Result = std::make_unique<TEvColumnShard::TEvProposeTransactionResult>(Self->TabletID (), txInfo.TxKind , txInfo.TxId , proposeResult.GetStatus (), proposeResult.GetStatusMessage ());
159
- if (proposeResult.GetStatus () == NKikimrTxColumnShard::EResultStatus::PREPARED) {
160
- Self->IncCounter (COUNTER_PREPARE_SUCCESS);
161
- Result->Record .SetMinStep (txInfo.MinStep );
162
- Result->Record .SetMaxStep (txInfo.MaxStep );
163
- if (Self->ProcessingParams ) {
164
- Result->Record .MutableDomainCoordinators ()->CopyFrom (Self->ProcessingParams ->GetCoordinators ());
165
- }
166
- } else if (proposeResult.GetStatus () == NKikimrTxColumnShard::EResultStatus::SUCCESS) {
167
- Self->IncCounter (COUNTER_PREPARE_SUCCESS);
168
- } else {
169
- Self->IncCounter (COUNTER_PREPARE_ERROR);
170
- LOG_S_INFO (TxPrefix () << " error txId " << txInfo.TxId << " " << proposeResult.GetStatusMessage () << TxSuffix ());
118
+ Self->IncCounter (COUNTER_PREPARE_ERROR);
119
+ AFL_ERROR (NKikimrServices::TX_COLUMNSHARD)(" message" , proposeResult.GetStatusMessage ())(" tablet_id" , Self->TabletID ())(" tx_id" , txInfo.TxId );
120
+ }
121
+
122
+ void TTxProposeTransaction::OnProposeResult (TTxController::TProposeResult& proposeResult, const TTxController::TTxInfo& txInfo) {
123
+ AFL_VERIFY (proposeResult.GetStatus () == NKikimrTxColumnShard::EResultStatus::PREPARED)(" tx_id" , txInfo.TxId )(" details" , proposeResult.DebugString ());
124
+ Result = std::make_unique<TEvColumnShard::TEvProposeTransactionResult>(Self->TabletID (), txInfo.TxKind , txInfo.TxId , proposeResult.GetStatus (), proposeResult.GetStatusMessage ());
125
+ Result->Record .SetMinStep (txInfo.MinStep );
126
+ Result->Record .SetMaxStep (txInfo.MaxStep );
127
+ if (Self->ProcessingParams ) {
128
+ Result->Record .MutableDomainCoordinators ()->CopyFrom (Self->ProcessingParams ->GetCoordinators ());
171
129
}
130
+ Self->IncCounter (COUNTER_PREPARE_SUCCESS);
172
131
}
173
132
174
133
void TTxProposeTransaction::Complete (const TActorContext& ctx) {
@@ -180,12 +139,6 @@ void TTxProposeTransaction::Complete(const TActorContext& ctx) {
180
139
181
140
182
141
void TColumnShard::Handle (TEvColumnShard::TEvProposeTransaction::TPtr& ev, const TActorContext& ctx) {
183
- auto & record = Proto (ev->Get ());
184
- auto txKind = record.GetTxKind ();
185
- ui64 txId = record.GetTxId ();
186
- LOG_S_DEBUG (" ProposeTransaction " << NKikimrTxColumnShard::ETransactionKind_Name (txKind)
187
- << " txId " << txId << " at tablet " << TabletID ());
188
-
189
142
Execute (new TTxProposeTransaction (this , ev), ctx);
190
143
}
191
144
0 commit comments