@@ -25,6 +25,12 @@ i32 GetDataChunkCodec(const NKikimrPQClient::TDataChunk& proto) {
25
25
return 0 ;
26
26
}
27
27
28
+ #define PQ_CPROXY_LOG_D (message ) LOG_DEBUG_S(ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder() << " Direct read cache: " << message);
29
+ #define PQ_CPROXY_LOG_I (message ) LOG_INFO_S(ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder() << " Direct read cache: " << message);
30
+ #define PQ_CPROXY_LOG_W (message ) LOG_WARN_S(ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder() << " Direct read cache: " << message);
31
+ #define PQ_CPROXY_LOG_E (message ) LOG_ERROR_S(ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder() << " Direct read cache: " << message);
32
+ #define PQ_CPROXY_LOG_A (message ) LOG_ALERT_S(ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder() << " Direct read cache: " << message);
33
+
28
34
29
35
class TPQDirectReadCacheService : public TActorBootstrapped <TPQDirectReadCacheService> {
30
36
public:
@@ -35,7 +41,7 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
35
41
}
36
42
37
43
void Bootstrap (const TActorContext& ctx) {
38
- LOG_DEBUG_S (ctx, NKikimrServices::PQ_READ_PROXY, " Direct read cache created " );
44
+ PQ_CPROXY_LOG_D ( " : Created " );
39
45
40
46
Become (&TThis::StateWork);
41
47
Y_UNUSED (ctx);
@@ -59,10 +65,10 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
59
65
void HandleCreateClientSession (TEvPQProxy::TEvDirectReadDataSessionConnected::TPtr& ev) {
60
66
const auto & ctx = ActorContext ();
61
67
auto key = MakeSessionKey (ev->Get ());
62
- LOG_DEBUG_S (ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder () << " Direct read cache: client session connected with id '" << key.SessionId << " '" );
68
+ PQ_CPROXY_LOG_D ( " client session connected with id '" << key.SessionId << " '" );
63
69
auto sessionIter = ServerSessions.find (key);
64
70
if (sessionIter.IsEnd ()) {
65
- LOG_DEBUG_S (ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder () << " Direct read cache: unknown session id '" << key.SessionId << " ', close session" );
71
+ PQ_CPROXY_LOG_D ( " unknown session id '" << key.SessionId << " ', close session" );
66
72
CloseSession (ev->Sender , Ydb::PersQueue::ErrorCode::ErrorCode::BAD_REQUEST, " Unknown session" );
67
73
return ;
68
74
}
@@ -112,16 +118,10 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
112
118
113
119
auto destroyDone = DestroyServerSession (ServerSessions.find (key), ev->Get ()->Generation );
114
120
if (destroyDone) {
115
- LOG_DEBUG_S (
116
- ctx, NKikimrServices::PQ_READ_PROXY,
117
- TStringBuilder () << " Direct read cache: server session deregistered: " << key.SessionId
118
- );
121
+ PQ_CPROXY_LOG_D (" server session deregistered: " << key.SessionId );
119
122
} else {
120
- LOG_WARN_S (
121
- ctx, NKikimrServices::PQ_READ_PROXY,
122
- TStringBuilder () << " Direct read cache: attempted to deregister unknown server session: " << key.SessionId
123
- << " :" << key.PartitionSessionId << " with generation " << ev->Get ()->Generation << " , ignored"
124
- );
123
+ PQ_CPROXY_LOG_W (" attempted to deregister unknown server session: " << key.SessionId
124
+ << " :" << key.PartitionSessionId << " with generation " << ev->Get ()->Generation << " , ignored" );
125
125
return ;
126
126
}
127
127
}
@@ -131,64 +131,47 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
131
131
auto sessionKey = MakeSessionKey (ev->Get ());
132
132
auto sessionIter = ServerSessions.find (sessionKey);
133
133
if (sessionIter.IsEnd ()) {
134
- LOG_ERROR_S (
135
- ctx, NKikimrServices::PQ_READ_PROXY,
136
- TStringBuilder () << " Direct read cache: tried to stage direct read for unregistered session: "
137
- << sessionKey.SessionId << " :" << sessionKey.PartitionSessionId
138
- );
134
+ PQ_CPROXY_LOG_E (" tried to stage direct read for unregistered session: "
135
+ << sessionKey.SessionId << " :" << sessionKey.PartitionSessionId );
139
136
return ;
140
137
}
141
138
if (sessionIter->second .Generation != ev->Get ()->TabletGeneration ) {
142
- LOG_ALERT_S (
143
- ctx, NKikimrServices::PQ_READ_PROXY,
144
- TStringBuilder () << " Direct read cache: tried to stage direct read for session " << sessionKey.SessionId
145
- << " with generation " << ev->Get ()->TabletGeneration << " , previously had this session with generation "
146
- << sessionIter->second .Generation << " . Data ignored"
147
- );
139
+ PQ_CPROXY_LOG_A (" tried to stage direct read for session " << sessionKey.SessionId
140
+ << " with generation " << ev->Get ()->TabletGeneration << " , previously had this session with generation "
141
+ << sessionIter->second .Generation << " . Data ignored" );
148
142
return ;
149
143
}
150
144
auto ins = sessionIter->second .StagedReads .insert (std::make_pair (ev->Get ()->ReadKey .ReadId , ev->Get ()->Response ));
151
145
if (!ins.second ) {
152
- LOG_WARN_S (
153
- ctx, NKikimrServices::PQ_READ_PROXY,
154
- TStringBuilder () << " Direct read cache: tried to stage duplicate direct read for session " << sessionKey.SessionId << " with id "
155
- << ev->Get ()->ReadKey .ReadId << " , new data ignored"
156
- );
146
+ PQ_CPROXY_LOG_W (" tried to stage duplicate direct read for session " << sessionKey.SessionId << " with id "
147
+ << ev->Get ()->ReadKey .ReadId << " , new data ignored" );
157
148
return ;
158
149
}
159
150
ChangeCounterValue (" StagedReadDataSize" , ins.first ->second ->ByteSize (), false );
160
151
ChangeCounterValue (" StagedReadsCount" , 1 , false );
161
- LOG_DEBUG_S (
162
- ctx, NKikimrServices::PQ_READ_PROXY,
163
- TStringBuilder () << " Direct read cache: staged direct read id " << ev->Get ()->ReadKey .ReadId << " for session: "
164
- << sessionKey.SessionId
165
- );
152
+ PQ_CPROXY_LOG_D (" staged direct read id " << ev->Get ()->ReadKey .ReadId << " for session: " << sessionKey.SessionId );
166
153
}
167
154
168
155
void HandlePublish (TEvPQ::TEvPublishDirectRead::TPtr& ev) {
169
156
const auto & ctx = ActorContext ();
170
157
auto key = MakeSessionKey (ev->Get ());
171
158
const auto readId = ev->Get ()->ReadKey .ReadId ;
172
- LOG_DEBUG_S (ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder () << " Direct read cache: publish read: " << readId << " for session " << key.SessionId );
159
+ const auto & generation = ev->Get ()->TabletGeneration ;
160
+ PQ_CPROXY_LOG_D (" publish read: " << readId << " for session " << key.SessionId << " , Generation: " << generation);
161
+
173
162
auto iter = ServerSessions.find (key);
174
163
if (iter.IsEnd ()) {
175
- LOG_ERROR_S (
176
- ctx, NKikimrServices::PQ_READ_PROXY,
177
- TStringBuilder () << " Direct read cache: attempt to publish read for unknow session " << key.SessionId << " ignored"
178
- );
164
+ PQ_CPROXY_LOG_E (" attempt to publish read for unknow session " << key.SessionId << " ignored" );
179
165
return ;
180
166
}
181
167
182
- const auto & generation = ev->Get ()->TabletGeneration ;
183
168
if (iter->second .Generation != generation)
184
169
return ;
185
170
186
171
auto stagedIter = iter->second .StagedReads .find (readId);
187
172
if (stagedIter == iter->second .StagedReads .end ()) {
188
- LOG_ERROR_S (
189
- ctx, NKikimrServices::PQ_READ_PROXY,
190
- TStringBuilder () << " Direct read cache: attempt to publish unknown read id " << readId << " from session: "
191
- << key.SessionId << " ignored" );
173
+ PQ_CPROXY_LOG_E (" attempt to publish unknown read id " << readId << " from session: "
174
+ << key.SessionId << " ignored" );
192
175
return ;
193
176
}
194
177
auto inserted = iter->second .Reads .insert (std::make_pair (ev->Get ()->ReadKey .ReadId , stagedIter->second )).second ;
@@ -209,18 +192,10 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
209
192
auto key = MakeSessionKey (ev->Get ());
210
193
auto iter = ServerSessions.find (key);
211
194
if (iter.IsEnd ()) {
212
- LOG_DEBUG_S (
213
- ctx, NKikimrServices::PQ_READ_PROXY,
214
- TStringBuilder () << " Direct read cache: attempt to forget read for unknown session: "
215
- << ev->Get ()->ReadKey .SessionId << " ignored"
216
- );
195
+ PQ_CPROXY_LOG_D (" attempt to forget read for unknown session: " << ev->Get ()->ReadKey .SessionId << " ignored" );
217
196
return ;
218
197
}
219
- LOG_DEBUG_S (
220
- ctx, NKikimrServices::PQ_READ_PROXY,
221
- TStringBuilder () << " Direct read cache: forget read: " << ev->Get ()->ReadKey .ReadId << " for session "
222
- << key.SessionId
223
- );
198
+ PQ_CPROXY_LOG_D (" forget read: " << ev->Get ()->ReadKey .ReadId << " for session " << key.SessionId );
224
199
225
200
const auto & generation = ev->Get ()->TabletGeneration ;
226
201
if (iter->second .Generation != generation) { // Stale generation in event, ignore it
@@ -265,6 +240,7 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
265
240
[[nodiscard]] bool DestroyServerSession (TSessionsMap::iterator sessionIter, ui64 generation) {
266
241
if (sessionIter.IsEnd () || sessionIter->second .Generation > generation)
267
242
return false ;
243
+ Cerr << " CahceProxy: DestroyServerSession with generation: " << generation << Endl;
268
244
DestroyPartitionSession (sessionIter, Ydb::PersQueue::ErrorCode::READ_ERROR_NO_SESSION, " Closed by server" );
269
245
ServerSessions.erase (sessionIter);
270
246
ChangeCounterValue (" ActiveServerSessions" , ServerSessions.size (), true );
@@ -275,32 +251,22 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
275
251
const auto & ctx = ActorContext ();
276
252
auto sessionsIter = ServerSessions.find (key);
277
253
if (sessionsIter.IsEnd ()) {
278
- LOG_DEBUG_S (
279
- ctx, NKikimrServices::PQ_READ_PROXY,
280
- TStringBuilder () << " Direct read cache: registered server session: " << key.SessionId
281
- << " :" << key.PartitionSessionId << " with generation " << generation
282
- );
254
+ PQ_CPROXY_LOG_D (" registered server session: " << key.SessionId
255
+ << " :" << key.PartitionSessionId << " with generation " << generation);
256
+
283
257
ServerSessions.insert (std::make_pair (key, TCacheServiceData{generation}));
284
258
} else if (sessionsIter->second .Generation == generation) {
285
- LOG_WARN_S (
286
- ctx, NKikimrServices::PQ_READ_PROXY,
287
- TStringBuilder () << " Direct read cache: attempted to register duplicate server session: " << key.SessionId
288
- << " :" << key.PartitionSessionId << " with same generation " << generation << " , ignored"
289
- );
259
+ PQ_CPROXY_LOG_W (" attempted to register duplicate server session: " << key.SessionId << " :"
260
+ << key.PartitionSessionId << " with same generation " << generation << " , ignored" );
261
+
290
262
} else if (DestroyServerSession (sessionsIter, generation)) {
291
- LOG_DEBUG_S (
292
- ctx, NKikimrServices::PQ_READ_PROXY,
293
- TStringBuilder () << " Direct read cache: registered server session: " << key.SessionId
294
- << " :" << key.PartitionSessionId << " with generation " << generation
295
- << " , killed existing session with older generation "
296
- );
263
+ PQ_CPROXY_LOG_D (" registered server session: " << key.SessionId
264
+ << " :" << key.PartitionSessionId << " with generation " << generation
265
+ << " , killed existing session with older generation " );
297
266
ServerSessions.insert (std::make_pair (key, TCacheServiceData{generation}));
298
267
} else {
299
- LOG_INFO_S (
300
- ctx, NKikimrServices::PQ_READ_PROXY,
301
- TStringBuilder () << " Direct read cache: attempted to register server session: " << key.SessionId
302
- << " :" << key.PartitionSessionId << " with stale generation " << generation << " , ignored"
303
- );
268
+ PQ_CPROXY_LOG_I (" attempted to register server session: " << key.SessionId
269
+ << " :" << key.PartitionSessionId << " with stale generation " << generation << " , ignored" );
304
270
}
305
271
ChangeCounterValue (" ActiveServerSessions" , ServerSessions.size (), true );
306
272
}
@@ -372,8 +338,7 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
372
338
partSessionId);
373
339
message->set_status (Ydb::StatusIds::SUCCESS);
374
340
375
- LOG_DEBUG_S (ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder () << " Direct read cache: send data to client. AssignId: "
376
- << partSessionId << " , readId: " << readId);
341
+ PQ_CPROXY_LOG_D (" send data to client. AssignId: " << partSessionId << " , readId: " << readId);
377
342
378
343
ctx.Send (proxyClient.ProxyId , new TEvPQProxy::TEvDirectReadSendClientData (std::move (message)));
379
344
return true ;
@@ -386,7 +351,7 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
386
351
) {
387
352
const auto & ctx = ActorContext ();
388
353
ctx.Send (proxyId, new TEvPQProxy::TEvDirectReadCloseSession (code, reason));
389
- LOG_DEBUG_S (ctx, NKikimrServices::PQ_READ_PROXY, TStringBuilder () << " Direct read cache: close session for proxy " << proxyId.ToString ());
354
+ PQ_CPROXY_LOG_D ( " close session for proxy " << proxyId.ToString ());
390
355
}
391
356
392
357
bool DestroyPartitionSession (
@@ -400,11 +365,7 @@ class TPQDirectReadCacheService : public TActorBootstrapped<TPQDirectReadCacheSe
400
365
ctx.Send (
401
366
sessionIter->second .Client ->ProxyId , new TEvPQProxy::TEvDirectReadDestroyPartitionSession (sessionIter->first , code, reason)
402
367
);
403
- LOG_DEBUG_S (
404
- ctx, NKikimrServices::PQ_READ_PROXY,
405
- TStringBuilder () << " Direct read cache: close session for proxy "
406
- << sessionIter->second .Client ->ProxyId .ToString ()
407
- );
368
+ PQ_CPROXY_LOG_D (" close session for proxy " << sessionIter->second .Client ->ProxyId .ToString ());
408
369
return true ;
409
370
}
410
371
0 commit comments