001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase; 020 021import java.util.Collections; 022import java.util.Map; 023import java.util.stream.Collectors; 024 025import org.apache.hadoop.hbase.client.RegionInfo; 026import org.apache.yetus.audience.InterfaceAudience; 027 028@InterfaceAudience.Public 029public final class CacheEvictionStats { 030 031 private final long evictedBlocks; 032 private final long maxCacheSize; 033 private final Map<byte[], Throwable> exceptions; 034 035 CacheEvictionStats(CacheEvictionStatsBuilder builder) { 036 this.evictedBlocks = builder.evictedBlocks; 037 this.maxCacheSize = builder.maxCacheSize; 038 this.exceptions = builder.exceptions; 039 } 040 041 public long getEvictedBlocks() { 042 return evictedBlocks; 043 } 044 045 public long getMaxCacheSize() { 046 return maxCacheSize; 047 } 048 049 public Map<byte[], Throwable> getExceptions() { 050 return Collections.unmodifiableMap(exceptions); 051 } 052 053 public int getExceptionCount() { 054 return exceptions.size(); 055 } 056 057 private String getFailedRegions() { 058 return exceptions.keySet().stream() 059 .map(regionName -> RegionInfo.prettyPrint(RegionInfo.encodeRegionName(regionName))) 060 .collect(Collectors.toList()) 061 .toString(); 062 } 063 064 @InterfaceAudience.Private 065 public static CacheEvictionStatsBuilder builder() { 066 return new CacheEvictionStatsBuilder(); 067 } 068 069 @Override 070 public String toString() { 071 return "CacheEvictionStats{" + 072 "evictedBlocks=" + evictedBlocks + 073 ", maxCacheSize=" + maxCacheSize + 074 ", failedRegionsSize=" + getExceptionCount() + 075 ", failedRegions=" + getFailedRegions() + 076 '}'; 077 } 078}