@@ -6,14 +6,6 @@ namespace NKafka {
6
6
using namespace NKikimr ;
7
7
using namespace NKikimr ::NGRpcProxy::V1;
8
8
9
- static EKafkaErrors KqpStatusToKafkaError (Ydb::StatusIds::StatusCode status) {
10
- // savnik finish it
11
- if (status == Ydb::StatusIds::SUCCESS) {
12
- return EKafkaErrors::NONE_ERROR;
13
- }
14
- return EKafkaErrors::UNKNOWN_SERVER_ERROR;
15
- }
16
-
17
9
static constexpr ui8 MASTER_WAIT_JOINS_DELAY_SECONDS = 5 ;
18
10
static constexpr ui8 WAIT_FOR_MASTER_DELAY_SECONDS = 2 ;
19
11
static constexpr ui8 WAIT_MASTER_MAX_RETRY_COUNT = 5 ;
@@ -29,6 +21,20 @@ void TKafkaBalancerActor::Bootstrap(const NActors::TActorContext& ctx) {
29
21
}
30
22
}
31
23
24
+ static EKafkaErrors KqpStatusToKafkaError (Ydb::StatusIds::StatusCode status) {
25
+ // savnik finish it
26
+ if (status == Ydb::StatusIds::SUCCESS) {
27
+ return EKafkaErrors::NONE_ERROR;
28
+ }
29
+ return EKafkaErrors::UNKNOWN_SERVER_ERROR;
30
+ }
31
+
32
+ TString TKafkaBalancerActor::LogPrefix () {
33
+ TStringBuilder sb;
34
+ sb << " TKafkaBalancerActor: " ;
35
+ return sb;
36
+ }
37
+
32
38
void TKafkaBalancerActor::Handle (NMetadata::NProvider::TEvManagerPrepared::TPtr&, const TActorContext& ctx) {
33
39
TablesInited++;
34
40
if (TablesInited == TABLES_TO_INIT_COUNT) {
@@ -37,68 +43,28 @@ void TKafkaBalancerActor::Handle(NMetadata::NProvider::TEvManagerPrepared::TPtr&
37
43
}
38
44
39
45
void TKafkaBalancerActor::Handle (NKqp::TEvKqp::TEvCreateSessionResponse::TPtr& ev, const TActorContext& ctx) {
40
- Cookie = 0 ;
41
- const TString createSessionError = " Failed to create KQP session " ;
46
+ Cookie = 0 ; // savnik
47
+
42
48
if (!Kqp->HandleCreateSessionResponse (ev, ctx)) {
43
- switch (RequestType) {
44
- case JOIN_GROUP:
45
- SendJoinGroupResponseFail (ctx, CorrelationId,
46
- EKafkaErrors::UNKNOWN_SERVER_ERROR,
47
- createSessionError);
48
- break ;
49
- case SYNC_GROUP:
50
- SendSyncGroupResponseFail (ctx, CorrelationId,
51
- EKafkaErrors::UNKNOWN_SERVER_ERROR,
52
- createSessionError);
53
- break ;
54
- case LEAVE_GROUP:
55
- SendLeaveGroupResponseFail (ctx, CorrelationId,
56
- EKafkaErrors::UNKNOWN_SERVER_ERROR,
57
- createSessionError);
58
- break ;
59
- case HEARTBEAT:
60
- SendHeartbeatResponseFail (ctx, CorrelationId,
61
- EKafkaErrors::UNKNOWN_SERVER_ERROR,
62
- createSessionError);
63
- break ;
64
- default :
65
- break ;
66
- }
49
+ SendResponseFail (ctx, EKafkaErrors::UNKNOWN_SERVER_ERROR, " Failed to create KQP session" );
67
50
PassAway ();
68
51
return ;
69
52
}
70
53
71
- switch (RequestType) {
72
- case JOIN_GROUP:
73
- HandleJoinGroupResponse (nullptr , ctx);
74
- break ;
75
- case SYNC_GROUP:
76
- HandleSyncGroupResponse (nullptr , ctx);
77
- break ;
78
- case LEAVE_GROUP:
79
- HandleLeaveGroupResponse (nullptr , ctx);
80
- break ;
81
- case HEARTBEAT:
82
- HandleHeartbeatResponse (nullptr , ctx);
83
- break ;
84
- default :
85
- KAFKA_LOG_CRIT (" Unknown RequestType in TEvCreateSessionResponse" );
86
- PassAway ();
87
- break ;
88
- }
54
+ HandleResponse (nullptr , ctx);
89
55
}
90
56
91
57
void TKafkaBalancerActor::Handle (NKqp::TEvKqp::TEvQueryResponse::TPtr& ev, const TActorContext& ctx) {
92
- const TString kqpQueryError = " KQP query error" ;
93
58
if (ev->Cookie != KqpReqCookie) {
94
- KAFKA_LOG_CRIT (" Unexpected cookie in TEvQueryResponse" );
59
+ KAFKA_LOG_ERROR (" Unexpected cookie in TEvQueryResponse" );
95
60
return ;
96
61
}
97
62
98
63
const auto & record = ev->Get ()->Record ;
99
64
auto status = record.GetYdbStatus ();
100
65
if (status == ::Ydb::StatusIds_StatusCode::StatusIds_StatusCode_ABORTED && CurrentRetryNumber < TX_ABORT_MAX_RETRY_COUNT) {
101
66
CurrentRetryNumber++;
67
+ KAFKA_LOG_I (TStringBuilder () << " Retry after tx aborted. Num of retry# " << CurrentRetryNumber);
102
68
switch (RequestType) {
103
69
case JOIN_GROUP:
104
70
Register (new TKafkaBalancerActor (Context, Cookie, CorrelationId, JoinGroupRequestData, CurrentRetryNumber));
@@ -123,26 +89,21 @@ void TKafkaBalancerActor::Handle(NKqp::TEvKqp::TEvQueryResponse::TPtr& ev, const
123
89
auto kafkaErr = KqpStatusToKafkaError (status);
124
90
125
91
if (kafkaErr != EKafkaErrors::NONE_ERROR) {
126
- switch (RequestType) {
127
- case JOIN_GROUP:
128
- SendJoinGroupResponseFail (ctx, CorrelationId, kafkaErr, kqpQueryError);
129
- break ;
130
- case SYNC_GROUP:
131
- SendSyncGroupResponseFail (ctx, CorrelationId, kafkaErr, kqpQueryError);
132
- break ;
133
- case LEAVE_GROUP:
134
- SendLeaveGroupResponseFail (ctx, CorrelationId, kafkaErr, kqpQueryError);
135
- break ;
136
- case HEARTBEAT:
137
- SendHeartbeatResponseFail (ctx, CorrelationId, kafkaErr, kqpQueryError);
138
- break ;
139
- default :
140
- break ;
141
- }
142
- PassAway ();
143
- return ;
92
+ auto kqpQueryError = TStringBuilder () <<" Kqp error. " ;
93
+
94
+ NYql::TIssues issues;
95
+ NYql::IssuesFromMessage (record.GetResponse ().GetQueryIssues (), issues);
96
+ NYdb::TStatus status (NYdb::EStatus (record.GetYdbStatus ()), std::move (issues));
97
+ kqpQueryError << status;
98
+
99
+ SendResponseFail (ctx, kafkaErr, kqpQueryError);
144
100
}
145
101
102
+ HandleResponse (ev, ctx);
103
+ }
104
+
105
+ void TKafkaBalancerActor::HandleResponse (NKqp::TEvKqp::TEvQueryResponse::TPtr ev, const TActorContext& ctx) {
106
+ KAFKA_LOG_I (TStringBuilder () << " Handle kqp response. CurrentStep# " << (ui8)CurrentStep);
146
107
switch (RequestType) {
147
108
case JOIN_GROUP:
148
109
HandleJoinGroupResponse (ev, ctx);
@@ -157,12 +118,31 @@ void TKafkaBalancerActor::Handle(NKqp::TEvKqp::TEvQueryResponse::TPtr& ev, const
157
118
HandleHeartbeatResponse (ev, ctx);
158
119
break ;
159
120
default :
160
- KAFKA_LOG_CRIT (" Unknown RequestType in TEvCreateSessionResponse" );
121
+ KAFKA_LOG_ERROR (" Unknown RequestType in TEvCreateSessionResponse" );
161
122
PassAway ();
162
123
break ;
163
124
}
164
125
}
165
126
127
+ void TKafkaBalancerActor::SendResponseFail (const TActorContext& ctx, EKafkaErrors error, const TString& message) {
128
+ switch (RequestType) {
129
+ case JOIN_GROUP:
130
+ SendJoinGroupResponseFail (ctx, CorrelationId, error, message);
131
+ break ;
132
+ case SYNC_GROUP:
133
+ SendSyncGroupResponseFail (ctx, CorrelationId, error, message);
134
+ break ;
135
+ case LEAVE_GROUP:
136
+ SendLeaveGroupResponseFail (ctx, CorrelationId, error, message);
137
+ break ;
138
+ case HEARTBEAT:
139
+ SendHeartbeatResponseFail (ctx, CorrelationId, error, message);
140
+ break ;
141
+ default :
142
+ break ;
143
+ }
144
+ }
145
+
166
146
std::optional<TGroupStatus> TKafkaBalancerActor::ParseCheckStateAndGeneration (
167
147
NKqp::TEvKqp::TEvQueryResponse::TPtr ev
168
148
) {
@@ -302,8 +282,8 @@ bool TKafkaBalancerActor::ParseWorkerStatesAndChooseProtocol(
302
282
}
303
283
304
284
for (const auto & st : states) {
305
- const auto & protos = st.WorkerState .protocols ();
306
- for (const auto & pr : protos ) {
285
+ const auto & protocols = st.WorkerState .protocols ();
286
+ for (const auto & pr : protocols ) {
307
287
if (pr.protocol_name () == chosenProtocol) {
308
288
workerStates[st.MemberId ] = pr.metadata ();
309
289
break ;
@@ -342,7 +322,7 @@ bool TKafkaBalancerActor::ParseDeadCount(
342
322
}
343
323
344
324
void TKafkaBalancerActor::Die (const TActorContext& ctx) {
345
- KAFKA_LOG_D (" TKafkaBalancerActor pass away" );
325
+ KAFKA_LOG_D (" Pass away" );
346
326
TBase::Die (ctx);
347
327
}
348
328
@@ -400,6 +380,8 @@ NYdb::TParamsBuilder TKafkaBalancerActor::BuildAssignmentsParams() {
400
380
401
381
auto & assignmentList = params.AddParam (" $Assignments" ).BeginList ();
402
382
383
+ KAFKA_LOG_D (TStringBuilder () << " Assignments count: " << SyncGroupRequestData->Assignments .size ());
384
+
403
385
for (auto & assignment: SyncGroupRequestData->Assignments ) {
404
386
assignmentList.AddListItem ()
405
387
.BeginStruct ()
@@ -1117,7 +1099,7 @@ void TKafkaBalancerActor::SendJoinGroupResponseFail(const TActorContext&,
1117
1099
EKafkaErrors error,
1118
1100
TString message) {
1119
1101
1120
- KAFKA_LOG_CRIT (" JOIN_GROUP failed. reason# " << message);
1102
+ KAFKA_LOG_ERROR (" JOIN_GROUP failed. reason# " << message);
1121
1103
auto response = std::make_shared<TJoinGroupResponseData>();
1122
1104
response->ErrorCode = error;
1123
1105
Send (Context->ConnectionId , new TEvKafka::TEvResponse (corellationId, response, error));
@@ -1127,7 +1109,7 @@ void TKafkaBalancerActor::SendSyncGroupResponseFail(const TActorContext&,
1127
1109
ui64 corellationId,
1128
1110
EKafkaErrors error,
1129
1111
TString message) {
1130
- KAFKA_LOG_CRIT (" SYNC_GROUP failed. reason# " << message);
1112
+ KAFKA_LOG_ERROR (" SYNC_GROUP failed. reason# " << message);
1131
1113
auto response = std::make_shared<TSyncGroupResponseData>();
1132
1114
response->ErrorCode = error;
1133
1115
response->Assignment = " " ;
@@ -1138,7 +1120,7 @@ void TKafkaBalancerActor::SendLeaveGroupResponseFail(const TActorContext&,
1138
1120
ui64 corellationId,
1139
1121
EKafkaErrors error,
1140
1122
TString message) {
1141
- KAFKA_LOG_CRIT (" LEAVE_GROUP failed. reason# " << message);
1123
+ KAFKA_LOG_ERROR (" LEAVE_GROUP failed. reason# " << message);
1142
1124
auto response = std::make_shared<TLeaveGroupResponseData>();
1143
1125
response->ErrorCode = error;
1144
1126
Send (Context->ConnectionId , new TEvKafka::TEvResponse (corellationId, response, error));
@@ -1148,7 +1130,7 @@ void TKafkaBalancerActor::SendHeartbeatResponseFail(const TActorContext&,
1148
1130
ui64 corellationId,
1149
1131
EKafkaErrors error,
1150
1132
TString message) {
1151
- KAFKA_LOG_CRIT (" HEARTBEAT failed. reason# " << message);
1133
+ KAFKA_LOG_ERROR (" HEARTBEAT failed. reason# " << message);
1152
1134
auto response = std::make_shared<THeartbeatResponseData>();
1153
1135
response->ErrorCode = error;
1154
1136
Send (Context->ConnectionId , new TEvKafka::TEvResponse (corellationId, response, error));
0 commit comments