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