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 private final int cellsCount; 048 049 /** 050 * Package private constructor. 051 */ 052 MemStoreSize() { 053 this(0L, 0L, 0L, 0); 054 } 055 056 /** 057 * Package private constructor. 058 */ 059 MemStoreSize(long dataSize, long heapSize, long offHeapSize, int cellsCount) { 060 this.dataSize = dataSize; 061 this.heapSize = heapSize; 062 this.offHeapSize = offHeapSize; 063 this.cellsCount = cellsCount; 064 } 065 066 /** 067 * Package private constructor. 068 */ 069 MemStoreSize(MemStoreSize memStoreSize) { 070 this.dataSize = memStoreSize.getDataSize(); 071 this.heapSize = memStoreSize.getHeapSize(); 072 this.offHeapSize = memStoreSize.getOffHeapSize(); 073 this.cellsCount = memStoreSize.getCellsCount(); 074 } 075 076 public boolean isEmpty() { 077 return this.dataSize == 0 && this.heapSize == 0 && this.offHeapSize == 0 078 && this.cellsCount == 0; 079 } 080 081 public long getDataSize() { 082 return this.dataSize; 083 } 084 085 public long getHeapSize() { 086 return this.heapSize; 087 } 088 089 public long getOffHeapSize() { 090 return this.offHeapSize; 091 } 092 093 public int getCellsCount() { 094 return this.cellsCount; 095 } 096 097 @Override 098 public boolean equals(Object obj) { 099 if (obj == null) { 100 return false; 101 } 102 if (!(obj instanceof MemStoreSize)) { 103 return false; 104 } 105 MemStoreSize other = (MemStoreSize) obj; 106 return this.dataSize == other.dataSize && this.heapSize == other.heapSize 107 && this.offHeapSize == other.offHeapSize && this.cellsCount == other.cellsCount; 108 } 109 110 @Override 111 public int hashCode() { 112 long h = 31 * this.dataSize; 113 h = h + 31 * this.heapSize; 114 h = h + 31 * this.offHeapSize; 115 h = h + 31 * this.cellsCount; 116 return (int) h; 117 } 118 119 @Override 120 public String toString() { 121 return "dataSize=" + this.dataSize + ", getHeapSize=" + this.heapSize + ", getOffHeapSize=" 122 + this.offHeapSize + ", getCellsCount=" + this.cellsCount; 123 } 124}