From 9cb0503bbfb442c44be201c5bae28a34a3cd8edf Mon Sep 17 00:00:00 2001 From: Liqiangcc <43640935+liqiangcc@users.noreply.github.com> Date: Sat, 6 May 2023 23:31:12 +0800 Subject: [PATCH] [improve][broker] Use bulk operation instead of iteration (#20219) --- .../pulsar/broker/admin/impl/PersistentTopicsBase.java | 2 +- .../broker/resourcegroup/ResourceGroupConfigListener.java | 4 +--- .../java/org/apache/pulsar/broker/service/PulsarStats.java | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java index fcade8270cb12..9dcbe13d6159b 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java @@ -226,7 +226,7 @@ protected CompletableFuture>> internalGetPermissions String topicUri = topicName.toString(); AuthPolicies auth = policies.get().auth_policies; // First add namespace level permissions - auth.getNamespaceAuthentication().forEach(permissions::put); + permissions.putAll(auth.getNamespaceAuthentication()); // Then add topic level permissions if (auth.getTopicAuthentication().containsKey(topicUri)) { diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupConfigListener.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupConfigListener.java index 5428d12ebad8c..c15edd2be4e43 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupConfigListener.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupConfigListener.java @@ -68,9 +68,7 @@ private void loadAllResourceGroups() { final Set existingSet = rgService.resourceGroupGetAll(); HashSet newSet = new HashSet<>(); - for (String rgName : rgList) { - newSet.add(rgName); - } + newSet.addAll(rgList); final Sets.SetView deleteList = Sets.difference(existingSet, newSet); diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarStats.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarStats.java index 2059aa04350d4..e959e9bbda2bb 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarStats.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarStats.java @@ -204,11 +204,10 @@ public synchronized void updateStats( } }); if (clusterReplicationMetrics.isMetricsEnabled()) { - clusterReplicationMetrics.get().forEach(clusterMetric -> tempMetricsCollection.add(clusterMetric)); + tempMetricsCollection.addAll(clusterReplicationMetrics.get()); clusterReplicationMetrics.reset(); } - brokerOperabilityMetrics.getMetrics() - .forEach(brokerOperabilityMetric -> tempMetricsCollection.add(brokerOperabilityMetric)); + tempMetricsCollection.addAll(brokerOperabilityMetrics.getMetrics()); // json end topicStatsStream.endObject();