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 java.io.IOException; 021import java.util.List; 022import org.apache.hadoop.hbase.Cell; 023import org.apache.hadoop.hbase.exceptions.UnexpectedStateException; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * The MemStore holds in-memory modifications to the Store. Modifications are {@link Cell}s. 028 * <p> 029 * The MemStore functions should not be called in parallel. Callers should hold write and read 030 * locks. This is done in {@link HStore}. 031 * </p> 032 */ 033@InterfaceAudience.Private 034public interface MemStore { 035 036 /** 037 * Creates a snapshot of the current memstore. Snapshot must be cleared by call to 038 * {@link #clearSnapshot(long)}. 039 * @return {@link MemStoreSnapshot} 040 */ 041 MemStoreSnapshot snapshot(); 042 043 /** 044 * Clears the current snapshot of the Memstore. nn * @see #snapshot() 045 */ 046 void clearSnapshot(long id) throws UnexpectedStateException; 047 048 /** 049 * Flush will first clear out the data in snapshot if any (It will take a second flush invocation 050 * to clear the current Cell set). If snapshot is empty, current Cell set will be flushed. 051 * @return On flush, how much memory we will clear. 052 */ 053 MemStoreSize getFlushableSize(); 054 055 /** 056 * Return the size of the snapshot(s) if any 057 * @return size of the memstore snapshot 058 */ 059 MemStoreSize getSnapshotSize(); 060 061 /** 062 * Write an update n * @param memstoreSizing The delta in memstore size will be passed back via 063 * this. This will include both data size and heap overhead delta. 064 */ 065 void add(final Cell cell, MemStoreSizing memstoreSizing); 066 067 /** 068 * Write the updates n * @param memstoreSizing The delta in memstore size will be passed back via 069 * this. This will include both data size and heap overhead delta. 070 */ 071 void add(Iterable<Cell> cells, MemStoreSizing memstoreSizing); 072 073 /** Returns Oldest timestamp of all the Cells in the MemStore */ 074 long timeOfOldestEdit(); 075 076 /** 077 * Update or insert the specified cells. 078 * <p> 079 * For each Cell, insert into MemStore. This will atomically upsert the value for that 080 * row/family/qualifier. If a Cell did already exist, it will then be removed. 081 * <p> 082 * Currently the memstoreTS is kept at 0 so as each insert happens, it will be immediately 083 * visible. May want to change this so it is atomic across all KeyValues. 084 * <p> 085 * This is called under row lock, so Get operations will still see updates atomically. Scans will 086 * only see each KeyValue update as atomic. n * @param readpoint readpoint below which we can 087 * safely remove duplicate Cells. 088 * @param memstoreSizing The delta in memstore size will be passed back via this. This will 089 * include both data size and heap overhead delta. 090 */ 091 void upsert(Iterable<Cell> cells, long readpoint, MemStoreSizing memstoreSizing); 092 093 /** 094 * @return scanner over the memstore. This might include scanner over the snapshot when one is 095 * present. 096 */ 097 List<KeyValueScanner> getScanners(long readPt) throws IOException; 098 099 /** 100 * @return Total memory occupied by this MemStore. This won't include any size occupied by the 101 * snapshot. We assume the snapshot will get cleared soon. This is not thread safe and the 102 * memstore may be changed while computing its size. It is the responsibility of the 103 * caller to make sure this doesn't happen. 104 */ 105 MemStoreSize size(); 106 107 /** 108 * This method is called before the flush is executed. 109 * @return an estimation (lower bound) of the unflushed sequence id in memstore after the flush is 110 * executed. if memstore will be cleared returns {@code HConstants.NO_SEQNUM}. 111 */ 112 long preFlushSeqIDEstimation(); 113 114 /* Return true if the memstore may use some extra memory space */ 115 boolean isSloppy(); 116 117 /** 118 * This message intends to inform the MemStore that next coming updates are going to be part of 119 * the replaying edits from WAL 120 */ 121 default void startReplayingFromWAL() { 122 return; 123 } 124 125 /** 126 * This message intends to inform the MemStore that the replaying edits from WAL are done 127 */ 128 default void stopReplayingFromWAL() { 129 return; 130 } 131}