@@ -19,14 +19,45 @@ NActors::IActor* CreateKafkaMetadataActor(const TContext::TPtr context,
19
19
20
20
void TKafkaMetadataActor::Bootstrap (const TActorContext& ctx) {
21
21
Response->Topics .resize (Message->Topics .size ());
22
+ Response->ClusterId = " ydb-cluster" ;
23
+ Response->ControllerId = 1 ;
22
24
25
+
26
+ if (WithProxy) {
27
+ AddProxyNodeToBrokers ();
28
+ }
29
+
30
+ if (Message->Topics .size () == 0 && !WithProxy) {
31
+ AddCurrentNodeToBrokers ();
32
+ }
33
+
34
+ if (Message->Topics .size () != 0 ) {
35
+ ProcessTopics ();
36
+ }
37
+
38
+ Become (&TKafkaMetadataActor::StateWork);
39
+ RespondIfRequired (ctx);
40
+ }
41
+
42
+ void TKafkaMetadataActor::AddCurrentNodeToBrokers () {
43
+ PendingResponses++;
44
+ Send (NKikimr::NIcNodeCache::CreateICNodesInfoCacheServiceId (), new NKikimr::NIcNodeCache::TEvICNodesInfoCache::TEvGetAllNodesInfoRequest ());
45
+ }
46
+
47
+ void TKafkaMetadataActor::AddProxyNodeToBrokers () {
48
+ auto broker = TMetadataResponseData::TMetadataResponseBroker{};
49
+ broker.NodeId = ProxyNodeId;
50
+ broker.Host = Context->Config .GetProxy ().GetHostname ();
51
+ broker.Port = Context->Config .GetProxy ().GetPort ();
52
+ Response->Brokers .emplace_back (std::move (broker));
53
+ }
54
+
55
+ void TKafkaMetadataActor::ProcessTopics () {
23
56
THashMap<TString, TActorId> partitionActors;
24
57
for (size_t i = 0 ; i < Message->Topics .size (); ++i) {
25
58
Response->Topics [i] = TMetadataResponseData::TMetadataResponseTopic{};
26
59
auto & reqTopic = Message->Topics [i];
27
60
Response->Topics [i].Name = reqTopic.Name .value_or (" " );
28
- Response->ClusterId = " ydb-cluster" ;
29
- Response->ControllerId = 1 ;
30
61
31
62
if (!reqTopic.Name .value_or (" " )) {
32
63
AddTopicError (Response->Topics [i], EKafkaErrors::INVALID_TOPIC_EXCEPTION);
@@ -43,8 +74,21 @@ void TKafkaMetadataActor::Bootstrap(const TActorContext& ctx) {
43
74
}
44
75
TopicIndexes[child].push_back (i);
45
76
}
46
- Become (&TKafkaMetadataActor::StateWork);
77
+ }
47
78
79
+ void TKafkaMetadataActor::HandleNodesResponse (NKikimr::NIcNodeCache::TEvICNodesInfoCache::TEvGetAllNodesInfoResponse::TPtr& ev, const NActors::TActorContext& ctx) {
80
+ auto iter = ev->Get ()->NodeIdsMapping ->find (ctx.SelfID .NodeId ());
81
+ Y_ABORT_UNLESS (!iter.IsEnd ());
82
+ auto host = (*ev->Get ()->Nodes )[iter->second ].Host ;
83
+ KAFKA_LOG_D (" Incoming TEvGetAllNodesInfoResponse. Host#: " << host);
84
+
85
+ auto broker = TMetadataResponseData::TMetadataResponseBroker{};
86
+ broker.NodeId = ctx.SelfID .NodeId ();
87
+ broker.Host = host;
88
+ broker.Port = Context->Config .GetListeningPort ();
89
+ Response->Brokers .emplace_back (std::move (broker));
90
+
91
+ --PendingResponses;
48
92
RespondIfRequired (ctx);
49
93
}
50
94
@@ -69,21 +113,11 @@ void TKafkaMetadataActor::AddTopicError(
69
113
}
70
114
71
115
void TKafkaMetadataActor::AddTopicResponse (TMetadataResponseData::TMetadataResponseTopic& topic, TEvLocationResponse* response) {
72
- bool withProxy = Context->Config .HasProxy () && !Context->Config .GetProxy ().GetHostname ().Empty ();
73
-
74
116
topic.ErrorCode = NONE_ERROR;
75
- // topic.TopicId = TKafkaUuid(response->SchemeShardId, response->PathId);
76
- if (withProxy) {
77
- auto broker = TMetadataResponseData::TMetadataResponseBroker{};
78
- broker.NodeId = ProxyNodeId;
79
- broker.Host = Context->Config .GetProxy ().GetHostname ();
80
- broker.Port = Context->Config .GetProxy ().GetPort ();
81
- Response->Brokers .emplace_back (std::move (broker));
82
- }
83
117
84
118
topic.Partitions .reserve (response->Partitions .size ());
85
119
for (const auto & part : response->Partitions ) {
86
- auto nodeId = withProxy ? ProxyNodeId : part.NodeId ;
120
+ auto nodeId = WithProxy ? ProxyNodeId : part.NodeId ;
87
121
88
122
TMetadataResponseData::TMetadataResponseTopic::PartitionsMeta::ItemType responsePartition;
89
123
responsePartition.PartitionIndex = part.PartitionId ;
@@ -95,7 +129,7 @@ void TKafkaMetadataActor::AddTopicResponse(TMetadataResponseData::TMetadataRespo
95
129
96
130
topic.Partitions .emplace_back (std::move (responsePartition));
97
131
98
- if (!withProxy ) {
132
+ if (!WithProxy ) {
99
133
auto ins = AllClusterNodes.insert (part.NodeId );
100
134
if (ins.second ) {
101
135
auto hostname = part.Hostname ;
@@ -123,12 +157,12 @@ void TKafkaMetadataActor::HandleResponse(TEvLocationResponse::TPtr ev, const TAc
123
157
Y_DEBUG_ABORT_UNLESS (!actorIter->second .empty ());
124
158
125
159
if (actorIter.IsEnd ()) {
126
- KAFKA_LOG_CRIT (" Metadata actor: got unexpected location response, ignoring. Expect malformed/incompled reply" );
160
+ KAFKA_LOG_CRIT (" Got unexpected location response, ignoring. Expect malformed/incompled reply" );
127
161
return RespondIfRequired (ctx);
128
162
}
129
163
130
164
if (actorIter->second .empty ()) {
131
- KAFKA_LOG_CRIT (" Metadata actor: corrupted state (empty actorId in mapping). Ignored location response, expect incomplete reply" );
165
+ KAFKA_LOG_CRIT (" Corrupted state (empty actorId in mapping). Ignored location response, expect incomplete reply" );
132
166
133
167
return RespondIfRequired (ctx);
134
168
}
0 commit comments