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