@@ -52,22 +52,40 @@ class TActorCoordinator : public TActorBootstrapped<TActorCoordinator> {
52
52
53
53
const ui64 PrintStatePeriodSec = 300 ;
54
54
55
- struct TPartitionKey {
55
+ struct TTopicKey {
56
56
TString Endpoint;
57
57
TString Database;
58
58
TString TopicName;
59
- ui64 PartitionId;
60
59
61
60
size_t Hash () const noexcept {
62
61
ui64 hash = std::hash<TString>()(Endpoint);
63
62
hash = CombineHashes<ui64>(hash, std::hash<TString>()(Database));
64
63
hash = CombineHashes<ui64>(hash, std::hash<TString>()(TopicName));
64
+ return hash;
65
+ }
66
+ bool operator ==(const TTopicKey& other) const {
67
+ return Endpoint == other.Endpoint && Database == other.Database
68
+ && TopicName == other.TopicName ;
69
+ }
70
+ };
71
+
72
+ struct TTopicKeyHash {
73
+ int operator ()(const TTopicKey& k) const {
74
+ return k.Hash ();
75
+ }
76
+ };
77
+
78
+ struct TPartitionKey {
79
+ TTopicKey Topic;
80
+ ui64 PartitionId;
81
+
82
+ size_t Hash () const noexcept {
83
+ ui64 hash = Topic.Hash ();
65
84
hash = CombineHashes<ui64>(hash, std::hash<ui64>()(PartitionId));
66
85
return hash;
67
86
}
68
87
bool operator ==(const TPartitionKey& other) const {
69
- return Endpoint == other.Endpoint && Database == other.Database
70
- && TopicName == other.TopicName && PartitionId == other.PartitionId ;
88
+ return Topic == other.Topic && PartitionId == other.PartitionId ;
71
89
}
72
90
};
73
91
@@ -156,7 +174,7 @@ class TActorCoordinator : public TActorBootstrapped<TActorCoordinator> {
156
174
const TString Tenant;
157
175
TMap<NActors::TActorId, RowDispatcherInfo> RowDispatchers;
158
176
THashMap<TPartitionKey, TActorId, TPartitionKeyHash> PartitionLocations;
159
- THashMap<TString , TTopicInfo> TopicsInfo;
177
+ THashMap<TTopicKey , TTopicInfo, TTopicKeyHash > TopicsInfo;
160
178
std::unordered_map<TActorId, TCoordinatorRequest> PendingReadActors;
161
179
TCoordinatorMetrics Metrics;
162
180
THashSet<TActorId> InterconnectSessions;
@@ -196,7 +214,7 @@ class TActorCoordinator : public TActorBootstrapped<TActorCoordinator> {
196
214
197
215
void AddRowDispatcher(NActors::TActorId actorId, bool isLocal);
198
216
void PrintInternalState ();
199
- TTopicInfo& GetOrCreateTopicInfo (const TString& topicName );
217
+ TTopicInfo& GetOrCreateTopicInfo (const TTopicKey& topic );
200
218
std::optional<TActorId> GetAndUpdateLocation (const TPartitionKey& key); // std::nullopt if TopicPartitionsLimitPerNode reached
201
219
bool ComputeCoordinatorRequest (TActorId readActorId, const TCoordinatorRequest& request);
202
220
void UpdatePendingReadActors ();
@@ -288,12 +306,12 @@ void TActorCoordinator::PrintInternalState() {
288
306
289
307
str << " \n Locations:\n " ;
290
308
for (auto & [key, actorId] : PartitionLocations) {
291
- str << " " << key.Endpoint << " / " << key.Database << " / " << key.TopicName << " , partId " << key.PartitionId << " , row dispatcher actor id: " << actorId << " \n " ;
309
+ str << " " << key.Topic . Endpoint << " / " << key.Topic . Database << " / " << key. Topic .TopicName << " , partId " << key.PartitionId << " , row dispatcher actor id: " << actorId << " \n " ;
292
310
}
293
311
294
312
str << " \n Pending partitions:\n " ;
295
- for (const auto & [topicName , topicInfo] : TopicsInfo) {
296
- str << " " << topicName << " , pending partitions: " << topicInfo.PendingPartitions .size () << " \n " ;
313
+ for (const auto & [topic , topicInfo] : TopicsInfo) {
314
+ str << " " << topic. TopicName << " ( " << topic. Endpoint << " ) , pending partitions: " << topicInfo.PendingPartitions .size () << " \n " ;
297
315
}
298
316
299
317
LOG_ROW_DISPATCHER_DEBUG (str.Str ());
@@ -337,18 +355,18 @@ void TActorCoordinator::Handle(NFq::TEvRowDispatcher::TEvCoordinatorChanged::TPt
337
355
Metrics.IsActive ->Set (isActive);
338
356
}
339
357
340
- TActorCoordinator::TTopicInfo& TActorCoordinator::GetOrCreateTopicInfo (const TString& topicName ) {
341
- const auto it = TopicsInfo.find (topicName );
358
+ TActorCoordinator::TTopicInfo& TActorCoordinator::GetOrCreateTopicInfo (const TTopicKey& topic ) {
359
+ const auto it = TopicsInfo.find (topic );
342
360
if (it != TopicsInfo.end ()) {
343
361
return it->second ;
344
362
}
345
- return TopicsInfo.insert ({topicName , TTopicInfo (Metrics, topicName )}).first ->second ;
363
+ return TopicsInfo.insert ({topic , TTopicInfo (Metrics, topic. TopicName )}).first ->second ;
346
364
}
347
365
348
366
std::optional<TActorId> TActorCoordinator::GetAndUpdateLocation (const TPartitionKey& key) {
349
367
Y_ENSURE (!PartitionLocations.contains (key));
350
368
351
- auto & topicInfo = GetOrCreateTopicInfo (key.TopicName );
369
+ auto & topicInfo = GetOrCreateTopicInfo (key.Topic );
352
370
353
371
TActorId bestLocation;
354
372
ui64 bestNumberPartitions = std::numeric_limits<ui64>::max ();
@@ -391,17 +409,14 @@ void TActorCoordinator::Handle(NFq::TEvRowDispatcher::TEvCoordinatorRequest::TPt
391
409
UpdateInterconnectSessions (ev->InterconnectSession );
392
410
393
411
TStringStream str;
394
- str << " TEvCoordinatorRequest from " << ev->Sender .ToString () << " , " << source.GetTopicPath () << " , partIds: " ;
395
- for (auto & partitionId : ev->Get ()->Record .GetPartitionId ()) {
396
- str << partitionId << " , " ;
397
- }
398
- LOG_ROW_DISPATCHER_DEBUG (str.Str ());
412
+ LOG_ROW_DISPATCHER_INFO (" TEvCoordinatorRequest from " << ev->Sender .ToString () << " , " << source.GetTopicPath () << " , partIds: " << JoinSeq (" , " , ev->Get ()->Record .GetPartitionId ()));
399
413
Metrics.IncomingRequests ->Inc ();
400
414
401
415
TCoordinatorRequest request = {.Cookie = ev->Cookie , .Record = ev->Get ()->Record };
402
416
if (ComputeCoordinatorRequest (ev->Sender , request)) {
403
417
PendingReadActors.erase (ev->Sender );
404
418
} else {
419
+ LOG_ROW_DISPATCHER_INFO (" All nodes are overloaded, add request into pending queue" );
405
420
// All nodes are overloaded, add request into pending queue
406
421
// We save only last request from each read actor
407
422
PendingReadActors[ev->Sender ] = request;
@@ -416,7 +431,8 @@ bool TActorCoordinator::ComputeCoordinatorRequest(TActorId readActorId, const TC
416
431
bool hasPendingPartitions = false ;
417
432
TMap<NActors::TActorId, TSet<ui64>> tmpResult;
418
433
for (auto & partitionId : request.Record .GetPartitionId ()) {
419
- TPartitionKey key{source.GetEndpoint (), source.GetDatabase (), source.GetTopicPath (), partitionId};
434
+ TTopicKey topicKey{source.GetEndpoint (), source.GetDatabase (), source.GetTopicPath ()};
435
+ TPartitionKey key {topicKey, partitionId};
420
436
auto locationIt = PartitionLocations.find (key);
421
437
NActors::TActorId rowDispatcherId;
422
438
if (locationIt != PartitionLocations.end ()) {
0 commit comments