Github user dschneider-pivotal commented on a diff in the pull request: https://github.com/apache/geode/pull/577#discussion_r121776319 --- Diff: geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegionRedundancyTracker.java --- @@ -0,0 +1,133 @@ +/* + * 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.geode.internal.cache; + +import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.internal.logging.log4j.LocalizedMessage; +import org.apache.logging.log4j.Logger; + +/** + * Keeps track redundancy statistics across the buckets of a given {@link PartitionedRegion} + */ +public class PartitionedRegionRedundancyTracker { + private static final Logger logger = LogService.getLogger(); + + private final PartitionedRegionStats stats; + private final String regionPath; + private final int totalBuckets; + private final int targetRedundancy; + + private int lowRedundancyBuckets; + private int noCopiesBuckets; + private int lowestBucketCopies; + + /** + * Creates a new PartitionedRegionRedundancyTracker + * + * @param totalBuckets number of buckets in the region to track + * @param redundantCopies number of redundant copies specified on the region to track + * @param stats the statistics container for the region to track + * @param regionPath the full path of the region to track + */ + PartitionedRegionRedundancyTracker(int totalBuckets, int redundantCopies, + PartitionedRegionStats stats, String regionPath) { + this.stats = stats; + this.regionPath = regionPath; + this.totalBuckets = totalBuckets; + this.targetRedundancy = redundantCopies; + this.lowestBucketCopies = redundantCopies + 1; + } + + /** + * Since consistency was last reached, provides the lowest number of copies of a bucket that have + * been remaining across all the buckets in the region + * + * @return the number of copies of the bucket with the least copies available + */ + int getLowestBucketCopies() { + return lowestBucketCopies; + } + + /** + * Increments the count of buckets that do not meet redundancy + */ + synchronized void incrementLowRedundancyBucketCount() { + if (lowRedundancyBuckets == totalBuckets) { + return; + } + lowRedundancyBuckets++; + stats.incLowRedundancyBucketCount(1); + } + + /** + * Updates the count of copies for the bucket with the least copies if a new low has been reached + * + * @param bucketCopies number of copies of a bucket remaining + */ + synchronized void reportBucketCount(int bucketCopies) { + if (bucketCopies < lowestBucketCopies) { + lowestBucketCopies = bucketCopies; + logger.warn(LocalizedMessage.create( + LocalizedStrings.BucketAdvisor_REDUNDANCY_HAS_DROPPED_BELOW_0_CONFIGURED_COPIES_TO_1_ACTUAL_COPIES_FOR_2, + new Object[] {targetRedundancy, bucketCopies + 1, regionPath})); + } + } + + /** + * Increments the count of buckets that no longer have any copies remaining + */ + synchronized void incrementNoCopiesBucketCount() { + if (noCopiesBuckets == totalBuckets) { + return; + } + noCopiesBuckets++; + stats.incNoCopiesBucketCount(1); + if (noCopiesBuckets == 1) { + logger.warn("No copies remain for " + regionPath); --- End diff -- I think this warning needs to say more. We should let them know that it may be ok but that data may have been lost
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---