001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import org.apache.hadoop.hbase.HBaseInterfaceAudience; 021import org.apache.yetus.audience.InterfaceAudience; 022/** 023 * Data structure of three longs. 024 * Convenient package in which to carry current state of three counters. 025 * <p>Immutable!</p> 026 * @see MemStoreSizing 027 */ 028@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 029public class MemStoreSize { 030 /** 031 *'dataSize' tracks the Cell's data bytes size alone (Key bytes, value bytes). A cell's data can 032 * be in on heap or off heap area depending on the MSLAB and its configuration to be using on 033 * heap or off heap LABs 034 */ 035 private final long dataSize; 036 037 /**'getHeapSize' tracks all Cell's heap size occupancy. This will include Cell POJO heap overhead. 038 * When Cells in on heap area, this will include the cells data size as well. 039 */ 040 private final long heapSize; 041 042 /** off-heap size: the aggregated size of all data that is allocated off-heap including all 043 * key-values that reside off-heap and the metadata that resides off-heap 044 */ 045 private final long offHeapSize; 046 047 /** 048 * Package private constructor. 049 */ 050 MemStoreSize() { 051 this(0L, 0L, 0L); 052 } 053 054 /** 055 * Package private constructor. 056 */ 057 MemStoreSize(long dataSize, long heapSize, long offHeapSize) { 058 this.dataSize = dataSize; 059 this.heapSize = heapSize; 060 this.offHeapSize = offHeapSize; 061 } 062 063 /** 064 * Package private constructor. 065 */ 066 MemStoreSize(MemStoreSize memStoreSize) { 067 this.dataSize = memStoreSize.getDataSize(); 068 this.heapSize = memStoreSize.getHeapSize(); 069 this.offHeapSize = memStoreSize.getOffHeapSize(); 070 } 071 072 public boolean isEmpty() { 073 return this.dataSize == 0 && this.heapSize == 0 && this.offHeapSize == 0; 074 } 075 076 public long getDataSize() { 077 return this.dataSize; 078 } 079 080 public long getHeapSize() { 081 return this.heapSize; 082 } 083 084 public long getOffHeapSize() { 085 return this.offHeapSize; 086 } 087 088 @Override 089 public boolean equals(Object obj) { 090 if (obj == null) { 091 return false; 092 } 093 if (!(obj instanceof MemStoreSize)) { 094 return false; 095 } 096 MemStoreSize other = (MemStoreSize)obj; 097 return this.dataSize == other.dataSize && this.heapSize == other.heapSize && 098 this.offHeapSize == other.offHeapSize; 099 } 100 101 @Override 102 public int hashCode() { 103 long h = 31 * this.dataSize; 104 h = h + 31 * this.heapSize; 105 h = h + 31 * this.offHeapSize; 106 return (int) h; 107 } 108 109 @Override 110 public String toString() { 111 return "dataSize=" + this.dataSize + ", getHeapSize=" + this.heapSize + 112 ", getOffHeapSize=" + this.offHeapSize; 113 } 114}