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.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     * Creates a snapshot of the current memstore. Snapshot must be cleared by call to
46     * {@link #clearSnapshot(long)}.
47     * @param flushOpSeqId the current sequence number of the wal; to be attached to the flushed
48     *                     segment
49     * @return {@link MemStoreSnapshot}
50     */
51    MemStoreSnapshot snapshot(long flushOpSeqId);
52  
53    /**
54     * Clears the current snapshot of the Memstore.
55     * @param id
56     * @throws UnexpectedStateException
57     * @see #snapshot(long)
58     */
59    void clearSnapshot(long id) throws UnexpectedStateException;
60  
61    /**
62     * On flush, how much memory we will clear.
63     * Flush will first clear out the data in snapshot if any (It will take a second flush
64     * invocation to clear the current Cell set). If snapshot is empty, current
65     * Cell set will be flushed.
66     *
67     * @return size of data that is going to be flushed
68     */
69    long getFlushableSize();
70  
71    /**
72     * Return the size of the snapshot(s) if any
73     * @return size of the memstore snapshot
74     */
75    long getSnapshotSize();
76  
77    /**
78     * Write an update
79     * @param cell
80     * @return approximate size of the passed cell.
81     */
82    long add(final Cell cell);
83  
84    /**
85     * @return Oldest timestamp of all the Cells in the MemStore
86     */
87    long timeOfOldestEdit();
88  
89    /**
90     * Write a delete
91     * @param deleteCell
92     * @return approximate size of the passed key and value.
93     */
94    long delete(final Cell deleteCell);
95  
96    /**
97     * Given the specs of a column, update it, first by inserting a new record,
98     * then removing the old one.  Since there is only 1 KeyValue involved, the memstoreTS
99     * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying
100    * store will ensure that the insert/delete each are atomic. A scanner/reader will either
101    * get the new value, or the old value and all readers will eventually only see the new
102    * value after the old was removed.
103    *
104    * @param row
105    * @param family
106    * @param qualifier
107    * @param newValue
108    * @param now
109    * @return Timestamp
110    */
111   long updateColumnValue(byte[] row, byte[] family, byte[] qualifier, long newValue, long now);
112 
113   /**
114    * Update or insert the specified cells.
115    * <p>
116    * For each Cell, insert into MemStore. This will atomically upsert the value for that
117    * row/family/qualifier. If a Cell did already exist, it will then be removed.
118    * <p>
119    * Currently the memstoreTS is kept at 0 so as each insert happens, it will be immediately
120    * visible. May want to change this so it is atomic across all KeyValues.
121    * <p>
122    * This is called under row lock, so Get operations will still see updates atomically. Scans will
123    * only see each KeyValue update as atomic.
124    * @param cells
125    * @param readpoint readpoint below which we can safely remove duplicate Cells.
126    * @return change in memstore size
127    */
128   long upsert(Iterable<Cell> cells, long readpoint);
129 
130   /**
131    * @return scanner over the memstore. This might include scanner over the snapshot when one is
132    * present.
133    */
134   List<KeyValueScanner> getScanners(long readPt) throws IOException;
135 
136   /**
137    * @return Total memory occupied by this MemStore.
138    */
139   long size();
140 
141   /**
142    * This method is called when it is clear that the flush to disk is completed.
143    * The store may do any post-flush actions at this point.
144    * One example is to update the wal with sequence number that is known only at the store level.
145    */
146   void finalizeFlush();
147 }