michaeljmarshall commented on a change in pull request #11564: URL: https://github.com/apache/pulsar/pull/11564#discussion_r685363477
########## File path: pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorMXBeanImpl.java ########## @@ -0,0 +1,78 @@ +/** + * 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.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.LongAdder; +import org.apache.pulsar.common.stats.Sum; + +public class CompactorMXBeanImpl implements CompactorMXBean { + + private final ConcurrentMap<String, Sum> sumOps = new ConcurrentHashMap<>(); + + private final ConcurrentHashMap<String, Integer> actionOps = new ConcurrentHashMap(); Review comment: What is the purpose of this map? I see key value pairs getting updated, but never retrieved. ########## File path: pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorMXBeanImpl.java ########## @@ -0,0 +1,78 @@ +/** + * 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.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.LongAdder; +import org.apache.pulsar.common.stats.Sum; + +public class CompactorMXBeanImpl implements CompactorMXBean { + + private final ConcurrentMap<String, Sum> sumOps = new ConcurrentHashMap<>(); + + private final ConcurrentHashMap<String, Integer> actionOps = new ConcurrentHashMap(); + private final ConcurrentHashMap<String, LongAdder> removedOps = new ConcurrentHashMap<>(); + + public void addCompactSample(String topic, int size) { + sumOps.compute(topic, (k, v) -> { + if (v == null) { + v = new Sum(); + } + v.recordEvent(size); + return v; + }); Review comment: ```suggestion sumOps.computeIfAbsent(topic, k -> new Sum()).recordEvent(size); ``` ########## File path: pulsar-common/src/main/java/org/apache/pulsar/common/stats/Sum.java ########## @@ -0,0 +1,47 @@ +/** + * 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.stats; + +import java.util.concurrent.atomic.LongAdder; + +/** + */ Review comment: It'd be nice to add documentation here. For example, this class is intended to be thread safe, and a comment stating so would be good. Additionally, documenting when to use this class for metrics would be helpful. ########## File path: pulsar-common/src/main/java/org/apache/pulsar/common/stats/Sum.java ########## @@ -0,0 +1,47 @@ +/** + * 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.stats; + +import java.util.concurrent.atomic.LongAdder; + +/** + */ +public class Sum { Review comment: This `Sum` class should have associated tests. ########## File path: pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorMXBeanImpl.java ########## @@ -0,0 +1,78 @@ +/** + * 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.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.LongAdder; +import org.apache.pulsar.common.stats.Sum; + +public class CompactorMXBeanImpl implements CompactorMXBean { + + private final ConcurrentMap<String, Sum> sumOps = new ConcurrentHashMap<>(); + + private final ConcurrentHashMap<String, Integer> actionOps = new ConcurrentHashMap(); + private final ConcurrentHashMap<String, LongAdder> removedOps = new ConcurrentHashMap<>(); + + public void addCompactSample(String topic, int size) { + sumOps.compute(topic, (k, v) -> { + if (v == null) { + v = new Sum(); + } + v.recordEvent(size); + return v; + }); + } + + public void addCompactRemovedEvent(String topic) { + removedOps.compute(topic, (k, v) -> { + if (v == null) { + v = new LongAdder(); + } + v.increment(); + return v; + }); Review comment: ```suggestion removedOps.computeIfAbsent(topic, k -> new LongAdder()).increment(); ``` -- 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: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org