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/** 024 * Data structure of three longs. Convenient package in which to carry current state of three 025 * counters. 026 * <p> 027 * Immutable! 028 * </p> 029 * @see MemStoreSizing 030 */ 031@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 032public class MemStoreSize { 033 /** 034 * 'dataSize' tracks the Cell's data bytes size alone (Key bytes, value bytes). A cell's data can 035 * be in on heap or off heap area depending on the MSLAB and its configuration to be using on heap 036 * or off heap LABs 037 */ 038 private final long dataSize; 039 040 /** 041 * 'getHeapSize' tracks all Cell's heap size occupancy. This will include Cell POJO heap overhead. 042 * When Cells in on heap area, this will include the cells data size as well. 043 */ 044 private final long heapSize; 045 046 /** 047 * off-heap size: the aggregated size of all data that is allocated off-heap including all 048 * key-values that reside off-heap and the metadata that resides off-heap 049 */ 050 private final long offHeapSize; 051 052 private final int cellsCount; 053 054 /** 055 * Package private constructor. 056 */ 057 MemStoreSize() { 058 this(0L, 0L, 0L, 0); 059 } 060 061 /** 062 * Package private constructor. 063 */ 064 MemStoreSize(long dataSize, long heapSize, long offHeapSize, int cellsCount) { 065 this.dataSize = dataSize; 066 this.heapSize = heapSize; 067 this.offHeapSize = offHeapSize; 068 this.cellsCount = cellsCount; 069 } 070 071 /** 072 * Package private constructor. 073 */ 074 MemStoreSize(MemStoreSize memStoreSize) { 075 this.dataSize = memStoreSize.getDataSize(); 076 this.heapSize = memStoreSize.getHeapSize(); 077 this.offHeapSize = memStoreSize.getOffHeapSize(); 078 this.cellsCount = memStoreSize.getCellsCount(); 079 } 080 081 public boolean isEmpty() { 082 return this.dataSize == 0 && this.heapSize == 0 && this.offHeapSize == 0 083 && this.cellsCount == 0; 084 } 085 086 public long getDataSize() { 087 return this.dataSize; 088 } 089 090 public long getHeapSize() { 091 return this.heapSize; 092 } 093 094 public long getOffHeapSize() { 095 return this.offHeapSize; 096 } 097 098 public int getCellsCount() { 099 return this.cellsCount; 100 } 101 102 @Override 103 public boolean equals(Object obj) { 104 if (obj == null) { 105 return false; 106 } 107 if (!(obj instanceof MemStoreSize)) { 108 return false; 109 } 110 MemStoreSize other = (MemStoreSize) obj; 111 return this.dataSize == other.dataSize && this.heapSize == other.heapSize 112 && this.offHeapSize == other.offHeapSize && this.cellsCount == other.cellsCount; 113 } 114 115 @Override 116 public int hashCode() { 117 long h = this.dataSize; 118 h = h * 31 + this.heapSize; 119 h = h * 31 + this.offHeapSize; 120 h = h * 31 + this.cellsCount; 121 return (int) h; 122 } 123 124 @Override 125 public String toString() { 126 return "dataSize=" + this.dataSize + ", getHeapSize=" + this.heapSize + ", getOffHeapSize=" 127 + this.offHeapSize + ", getCellsCount=" + this.cellsCount; 128 } 129}