65
65
import org .apache .pulsar .common .policies .data .PublishRate ;
66
66
import org .apache .pulsar .common .policies .data .RetentionPolicies ;
67
67
import org .apache .pulsar .common .policies .data .SchemaCompatibilityStrategy ;
68
+ import org .apache .pulsar .common .policies .data .SubscribeRate ;
68
69
import org .apache .pulsar .common .policies .data .TopicPolicies ;
69
70
import org .apache .pulsar .common .policies .data .impl .DispatchRateImpl ;
70
71
import org .apache .pulsar .common .protocol .schema .SchemaData ;
@@ -157,6 +158,10 @@ public AbstractTopic(String topic, BrokerService brokerService) {
157
158
this .preciseTopicPublishRateLimitingEnable = config .isPreciseTopicPublishRateLimiterEnable ();
158
159
}
159
160
161
+ public SubscribeRate getSubscribeRate () {
162
+ return this .topicPolicies .getSubscribeRate ().get ();
163
+ }
164
+
160
165
public DispatchRateImpl getSubscriptionDispatchRate () {
161
166
return this .topicPolicies .getSubscriptionDispatchRate ().get ();
162
167
}
@@ -169,6 +174,10 @@ public DispatchRateImpl getReplicatorDispatchRate() {
169
174
return this .topicPolicies .getReplicatorDispatchRate ().get ();
170
175
}
171
176
177
+ public DispatchRateImpl getDispatchRate () {
178
+ return this .topicPolicies .getDispatchRate ().get ();
179
+ }
180
+
172
181
private SchemaCompatibilityStrategy formatSchemaCompatibilityStrategy (SchemaCompatibilityStrategy strategy ) {
173
182
return strategy == SchemaCompatibilityStrategy .UNDEFINED ? null : strategy ;
174
183
}
@@ -204,8 +213,10 @@ protected void updateTopicPolicy(TopicPolicies data) {
204
213
topicPolicies .getDelayedDeliveryEnabled ().updateTopicValue (data .getDelayedDeliveryEnabled ());
205
214
topicPolicies .getReplicatorDispatchRate ().updateTopicValue (normalize (data .getReplicatorDispatchRate ()));
206
215
topicPolicies .getDelayedDeliveryTickTimeMillis ().updateTopicValue (data .getDelayedDeliveryTickTimeMillis ());
216
+ topicPolicies .getSubscribeRate ().updateTopicValue (SubscribeRate .normalize (data .getSubscribeRate ()));
207
217
topicPolicies .getSubscriptionDispatchRate ().updateTopicValue (normalize (data .getSubscriptionDispatchRate ()));
208
218
topicPolicies .getCompactionThreshold ().updateTopicValue (data .getCompactionThreshold ());
219
+ topicPolicies .getDispatchRate ().updateTopicValue (normalize (data .getDispatchRate ()));
209
220
}
210
221
211
222
protected void updateTopicPolicyByNamespacePolicy (Policies namespacePolicies ) {
@@ -247,9 +258,24 @@ protected void updateTopicPolicyByNamespacePolicy(Policies namespacePolicies) {
247
258
Arrays .stream (BacklogQuota .BacklogQuotaType .values ()).forEach (
248
259
type -> this .topicPolicies .getBackLogQuotaMap ().get (type )
249
260
.updateNamespaceValue (MapUtils .getObject (namespacePolicies .backlog_quota_map , type )));
261
+ updateNamespaceSubscribeRate (namespacePolicies , brokerService .getPulsar ().getConfig ().getClusterName ());
250
262
updateNamespaceSubscriptionDispatchRate (namespacePolicies ,
251
263
brokerService .getPulsar ().getConfig ().getClusterName ());
252
264
updateSchemaCompatibilityStrategyNamespaceValue (namespacePolicies );
265
+ updateNamespaceDispatchRate (namespacePolicies , brokerService .getPulsar ().getConfig ().getClusterName ());
266
+ }
267
+
268
+ private void updateNamespaceDispatchRate (Policies namespacePolicies , String cluster ) {
269
+ DispatchRateImpl dispatchRate = namespacePolicies .topicDispatchRate .get (cluster );
270
+ if (dispatchRate == null ) {
271
+ dispatchRate = namespacePolicies .clusterDispatchRate .get (cluster );
272
+ }
273
+ topicPolicies .getDispatchRate ().updateNamespaceValue (normalize (dispatchRate ));
274
+ }
275
+
276
+ private void updateNamespaceSubscribeRate (Policies namespacePolicies , String cluster ) {
277
+ topicPolicies .getSubscribeRate ()
278
+ .updateNamespaceValue (SubscribeRate .normalize (namespacePolicies .clusterSubscribeRate .get (cluster )));
253
279
}
254
280
255
281
private void updateNamespaceSubscriptionDispatchRate (Policies namespacePolicies , String cluster ) {
@@ -335,9 +361,26 @@ private void updateTopicPolicyByBrokerConfig() {
335
361
if (isSystemTopic ()) {
336
362
schemaCompatibilityStrategy = config .getSystemTopicSchemaCompatibilityStrategy ();
337
363
}
364
+ topicPolicies .getSubscribeRate ().updateBrokerValue (subscribeRateInBroker (config ));
338
365
topicPolicies .getSubscriptionDispatchRate ().updateBrokerValue (subscriptionDispatchRateInBroker (config ));
339
366
topicPolicies .getSchemaCompatibilityStrategy ()
340
367
.updateBrokerValue (formatSchemaCompatibilityStrategy (schemaCompatibilityStrategy ));
368
+ topicPolicies .getDispatchRate ().updateBrokerValue (dispatchRateInBroker (config ));
369
+ }
370
+
371
+ private DispatchRateImpl dispatchRateInBroker (ServiceConfiguration config ) {
372
+ return DispatchRateImpl .builder ()
373
+ .dispatchThrottlingRateInMsg (config .getDispatchThrottlingRatePerTopicInMsg ())
374
+ .dispatchThrottlingRateInByte (config .getDispatchThrottlingRatePerTopicInByte ())
375
+ .ratePeriodInSecond (1 )
376
+ .build ();
377
+ }
378
+
379
+ private SubscribeRate subscribeRateInBroker (ServiceConfiguration config ) {
380
+ return new SubscribeRate (
381
+ config .getSubscribeThrottlingRatePerConsumer (),
382
+ config .getSubscribeRatePeriodPerConsumerInSecond ()
383
+ );
341
384
}
342
385
343
386
private DispatchRateImpl subscriptionDispatchRateInBroker (ServiceConfiguration config ) {
@@ -1173,4 +1216,19 @@ public void updateBrokerReplicatorDispatchRate() {
1173
1216
topicPolicies .getReplicatorDispatchRate ().updateBrokerValue (
1174
1217
replicatorDispatchRateInBroker (brokerService .pulsar ().getConfiguration ()));
1175
1218
}
1219
+
1220
+ public void updateBrokerDispatchRate () {
1221
+ topicPolicies .getDispatchRate ().updateBrokerValue (
1222
+ dispatchRateInBroker (brokerService .pulsar ().getConfiguration ()));
1223
+ }
1224
+
1225
+ public void updateBrokerPublishRate () {
1226
+ topicPolicies .getPublishRate ().updateBrokerValue (
1227
+ publishRateInBroker (brokerService .pulsar ().getConfiguration ()));
1228
+ }
1229
+
1230
+ public void updateBrokerSubscribeRate () {
1231
+ topicPolicies .getSubscribeRate ().updateBrokerValue (
1232
+ subscribeRateInBroker (brokerService .pulsar ().getConfiguration ()));
1233
+ }
1176
1234
}
0 commit comments