ctubbsii commented on a change in pull request #1381: Update gc metrics reporting to use hadoop metrics2 URL: https://github.com/apache/accumulo/pull/1381#discussion_r332287063
########## File path: server/gc/src/main/java/org/apache/accumulo/gc/metrics/GcCycleMetrics.java ########## @@ -0,0 +1,142 @@ +/* + * 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.accumulo.gc.metrics; + +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.accumulo.core.gc.thrift.GcCycleStats; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper class for GcCycleStats so that underlying thrift code in GcCycleStats is not modified. + * Provides Thread safe access to the gc cycle stats for metrics reporting. + */ +public class GcCycleMetrics { + + private static final Logger log = LoggerFactory.getLogger(GcCycleMetrics.class); + + private AtomicReference<GcCycleStats> lastCollect = new AtomicReference<>(new GcCycleStats()); + private AtomicReference<GcCycleStats> lastWalCollect = new AtomicReference<>(new GcCycleStats()); + + private AtomicLong postOpDurationNanos = new AtomicLong(0); + private AtomicLong runCycleCount = new AtomicLong(0); + + public GcCycleMetrics() {} + + /** + * Get the last gc run statistics. + * + * @return the statistics for the last gc run. + */ + public GcCycleStats getLastCollect() { + return lastCollect.get(); + } + + /** + * Set the last gc run statistics. Makes a defensive deep copy so that if the gc implementation + * modifies the values. + * + * @param lastCollect + * the last gc run statistics. + */ + public void setLastCollect(final GcCycleStats lastCollect) { + this.lastCollect.set(new GcCycleStats(lastCollect)); + } + + /** + * The statistics from the last wal collection. + * + * @return the last wal collection statistics. + */ + public GcCycleStats getLastWalCollect() { + return lastWalCollect.get(); + } + + /** + * Set the lost wal collection statistics + * + * @param lastWalCollect + * last wal statistics + */ + public void setLastWalCollect(final GcCycleStats lastWalCollect) { + this.lastWalCollect.set(new GcCycleStats(lastWalCollect)); + } + + /** + * Duration of post operation (compact, flush, none) in nanoseconds. + * + * @return duration in nanoseconds. + */ + public long getPostOpDurationNanos() { + return postOpDurationNanos.get(); + } + + /** + * Set the duration of post operation (compact, flush, none) in nanoseconds. + * + * @param postOpDurationNanos + * the duration, in nanoseconds. + */ + public void setPostOpDurationNanos(long postOpDurationNanos) { + this.postOpDurationNanos.set(postOpDurationNanos); + } + + /** + * The number of gc cycles that have completed since initialization at process start. + * + * @return current run cycle count. + */ + public long getRunCycleCount() { + return runCycleCount.get(); + } + + /** + * Set the counter for number of completed gc collection cycles p the provided value. The value is + * expected to be >= 0. If a negative value is provided, the count is set to zero and a warning + * is logged rather than throwing an exception. Review comment: I don't see the method setting this to zero as described. The code should reflect the description. (Also, another option to setting it to zero would be to leave it as is, and not set it at all.) ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
