View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import java.util.List;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.Cell;
24  import org.apache.hadoop.hbase.exceptions.UnexpectedStateException;
25  import org.apache.hadoop.hbase.io.HeapSize;
26  
27  /**
28   * The MemStore holds in-memory modifications to the Store. Modifications are {@link Cell}s.
29   * <p>
30   * The MemStore functions should not be called in parallel. Callers should hold write and read
31   * locks. This is done in {@link HStore}.
32   * </p>
33   */
34  @InterfaceAudience.Private
35  public interface MemStore extends HeapSize {
36  
37    /**
38     * Creates a snapshot of the current memstore. Snapshot must be cleared by call to
39     * {@link #clearSnapshot(long)}.
40     * @return {@link MemStoreSnapshot}
41     */
42    MemStoreSnapshot snapshot();
43  
44    /**
45     * Clears the current snapshot of the Memstore.
46     * @param id
47     * @throws UnexpectedStateException
48     * @see #snapshot()
49     */
50    void clearSnapshot(long id) throws UnexpectedStateException;
51  
52    /**
53     * On flush, how much memory we will clear.
54     * Flush will first clear out the data in snapshot if any (It will take a second flush
55     * invocation to clear the current Cell set). If snapshot is empty, current
56     * Cell set will be flushed.
57     *
58     * @return size of data that is going to be flushed
59     */
60    long getFlushableSize();
61  
62    /**
63     * Return the size of the snapshot(s) if any
64     * @return size of the memstore snapshot
65     */
66    long getSnapshotSize();
67  
68    /**
69     * Write an update
70     * @param cell
71     * @return approximate size of the passed cell.
72     */
73    long add(final Cell cell);
74  
75    /**
76     * Write the updates
77     * @param cells
78     * @return approximate size of the passed cell.
79     */
80    long add(Iterable<Cell> cells);
81  
82    /**
83     * @return Oldest timestamp of all the Cells in the MemStore
84     */
85    long timeOfOldestEdit();
86  
87    /**
88     * Remove n key from the memstore. Only kvs that have the same key and the same memstoreTS are
89     * removed. It is ok to not update timeRangeTracker in this call.
90     * @param cell
91     */
92    void rollback(final Cell cell);
93  
94    /**
95     * Write a delete
96     * @param deleteCell
97     * @return approximate size of the passed key and value.
98     */
99    long delete(final Cell deleteCell);
100 
101   /**
102    * Find the key that matches <i>row</i> exactly, or the one that immediately precedes it. The
103    * target row key is set in state.
104    * @param state column/delete tracking state
105    */
106   void getRowKeyAtOrBefore(final GetClosestRowBeforeTracker state);
107 
108   /**
109    * Given the specs of a column, update it, first by inserting a new record,
110    * then removing the old one.  Since there is only 1 KeyValue involved, the memstoreTS
111    * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying
112    * store will ensure that the insert/delete each are atomic. A scanner/reader will either
113    * get the new value, or the old value and all readers will eventually only see the new
114    * value after the old was removed.
115    *
116    * @param row
117    * @param family
118    * @param qualifier
119    * @param newValue
120    * @param now
121    * @return Timestamp
122    */
123   long updateColumnValue(byte[] row, byte[] family, byte[] qualifier, long newValue, long now);
124 
125   /**
126    * Update or insert the specified cells.
127    * <p>
128    * For each Cell, insert into MemStore. This will atomically upsert the value for that
129    * row/family/qualifier. If a Cell did already exist, it will then be removed.
130    * <p>
131    * Currently the memstoreTS is kept at 0 so as each insert happens, it will be immediately
132    * visible. May want to change this so it is atomic across all KeyValues.
133    * <p>
134    * This is called under row lock, so Get operations will still see updates atomically. Scans will
135    * only see each KeyValue update as atomic.
136    * @param cells
137    * @param readpoint readpoint below which we can safely remove duplicate Cells.
138    * @param removedCells collect the removed cells. It can be null.
139    * @return change in memstore size
140    */
141   long upsert(Iterable<Cell> cells, long readpoint, List<Cell> removedCells);
142 
143   /**
144    * @return scanner over the memstore. This might include scanner over the snapshot when one is
145    * present.
146    */
147   List<KeyValueScanner> getScanners(long readPt);
148 
149   /**
150    * @return Total memory occupied by this MemStore.
151    */
152   long size();
153 }