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.io.HeapSize;
25  
26  /**
27   * The MemStore holds in-memory modifications to the Store. Modifications are {@link Cell}s.
28   * <p>
29   * The MemStore functions should not be called in parallel. Callers should hold write and read
30   * locks. This is done in {@link HStore}.
31   * </p>
32   */
33  @InterfaceAudience.Private
34  public interface MemStore extends HeapSize {
35  
36    /**
37     * Creates a snapshot of the current memstore. Snapshot must be cleared by call to
38     * {@link #clearSnapshot(long)}.
39     * @return {@link MemStoreSnapshot}
40     */
41    MemStoreSnapshot snapshot();
42  
43    /**
44     * Clears the current snapshot of the Memstore.
45     * @param id
46     * @throws UnexpectedStateException
47     * @see #snapshot()
48     */
49    void clearSnapshot(long id) throws UnexpectedStateException;
50  
51    /**
52     * On flush, how much memory we will clear.
53     * Flush will first clear out the data in snapshot if any (It will take a second flush
54     * invocation to clear the current Cell set). If snapshot is empty, current
55     * Cell set will be flushed.
56     *
57     * @return size of data that is going to be flushed
58     */
59    long getFlushableSize();
60  
61    /**
62     * Return the size of the snapshot(s) if any
63     * @return size of the memstore snapshot
64     */
65    long getSnapshotSize();
66  
67    /**
68     * Write an update
69     * @param cell
70     * @return approximate size of the passed cell.
71     */
72    long add(final Cell cell);
73  
74    /**
75     * @return Oldest timestamp of all the Cells in the MemStore
76     */
77    long timeOfOldestEdit();
78  
79    /**
80     * Remove n key from the memstore. Only kvs that have the same key and the same memstoreTS are
81     * removed. It is ok to not update timeRangeTracker in this call.
82     * @param cell
83     */
84    void rollback(final Cell cell);
85  
86    /**
87     * Write a delete
88     * @param deleteCell
89     * @return approximate size of the passed key and value.
90     */
91    long delete(final Cell deleteCell);
92  
93    /**
94     * Given the specs of a column, update it, first by inserting a new record,
95     * then removing the old one.  Since there is only 1 KeyValue involved, the memstoreTS
96     * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying
97     * store will ensure that the insert/delete each are atomic. A scanner/reader will either
98     * get the new value, or the old value and all readers will eventually only see the new
99     * value after the old was removed.
100    *
101    * @param row
102    * @param family
103    * @param qualifier
104    * @param newValue
105    * @param now
106    * @return Timestamp
107    */
108   long updateColumnValue(byte[] row, byte[] family, byte[] qualifier, long newValue, long now);
109 
110   /**
111    * Update or insert the specified cells.
112    * <p>
113    * For each Cell, insert into MemStore. This will atomically upsert the value for that
114    * row/family/qualifier. If a Cell did already exist, it will then be removed.
115    * <p>
116    * Currently the memstoreTS is kept at 0 so as each insert happens, it will be immediately
117    * visible. May want to change this so it is atomic across all KeyValues.
118    * <p>
119    * This is called under row lock, so Get operations will still see updates atomically. Scans will
120    * only see each KeyValue update as atomic.
121    * @param cells
122    * @param readpoint readpoint below which we can safely remove duplicate Cells.
123    * @return change in memstore size
124    */
125   long upsert(Iterable<Cell> cells, long readpoint);
126 
127   /**
128    * @return scanner over the memstore. This might include scanner over the snapshot when one is
129    * present.
130    */
131   List<KeyValueScanner> getScanners(long readPt);
132 
133   /**
134    * @return Total memory occupied by this MemStore.
135    */
136   long size();
137 }