michaeljmarshall commented on a change in pull request #11564:
URL: https://github.com/apache/pulsar/pull/11564#discussion_r691796316



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorMXBeanImpl.java
##########
@@ -0,0 +1,124 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.compaction;
+
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.LongAdder;
+import org.apache.pulsar.broker.service.BrokerService;
+import org.apache.pulsar.broker.service.persistent.PersistentTopic;
+
+public class CompactorMXBeanImpl implements CompactorMXBean {
+
+    private final ConcurrentHashMap<String, CompactRecord> compactRecordOps = 
new ConcurrentHashMap<>();
+
+    private final Optional<BrokerService> brokerService;
+    private final ScheduledExecutorService scheduler;
+
+    public CompactorMXBeanImpl(Optional<BrokerService> brokerService, 
ScheduledExecutorService scheduler) {
+        this.brokerService = brokerService;
+        this.scheduler = scheduler;
+        this.scheduler.scheduleAtFixedRate(this::cleanup, 2, 2, 
TimeUnit.HOURS);

Review comment:
       I see that the `BrokerService` has a method to reactively remove a topic 
from its cache when appropriate, which has the affect of removing the metrics 
for that topic on that broker.
   
   In an environment where topics are unloaded frequently, 2 hours time is a 
long time to have incorrect metrics hosted by a broker. It might be possible to 
update the `removeTopicFromCache` method by adding a method call like the 
following:
   
   ```java
   pulsar.getCompactor().getStats().removeTopic(topicName)
   ```
   
   In this way, we could remove this scheduled task and then we wouldn't have 
incorrect metrics.

##########
File path: 
pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/policies/data/CompactStats.java
##########
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.common.policies.data;
+
+/**
+ * Statistics about compact.
+ */
+public interface CompactStats {

Review comment:
       Nit: I've been wondering if it is worth changing the name of these stats 
to `CompactionStats`. The documentation talks about `compaction`, and so I 
somewhat expect the metrics to have `compaction` in the metric's name. I can 
see why you chose `CompactStats`, but I also could see `CompactionStats` as a 
valid alternative. Do you have a strong opinion either way?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to