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     * 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     * @return Oldest timestamp of all the Cells in the MemStore
77     */
78    long timeOfOldestEdit();
79
80    /**
81     * Write a delete
82     * @param deleteCell
83     * @return approximate size of the passed key and value.
84     */
85    long delete(final Cell deleteCell);
86
87    /**
88     * Given the specs of a column, update it, first by inserting a new record,
89     * then removing the old one.  Since there is only 1 KeyValue involved, the memstoreTS
90     * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying
91     * store will ensure that the insert/delete each are atomic. A scanner/reader will either
92     * get the new value, or the old value and all readers will eventually only see the new
93     * value after the old was removed.
94     *
95     * @param row
96     * @param family
97     * @param qualifier
98     * @param newValue
99     * @param now
100    * @return Timestamp
101    */
102   long updateColumnValue(byte[] row, byte[] family, byte[] qualifier, long newValue, long now);
103
104   /**
105    * Update or insert the specified cells.
106    * <p>
107    * For each Cell, insert into MemStore. This will atomically upsert the value for that
108    * row/family/qualifier. If a Cell did already exist, it will then be removed.
109    * <p>
110    * Currently the memstoreTS is kept at 0 so as each insert happens, it will be immediately
111    * visible. May want to change this so it is atomic across all KeyValues.
112    * <p>
113    * This is called under row lock, so Get operations will still see updates atomically. Scans will
114    * only see each KeyValue update as atomic.
115    * @param cells
116    * @param readpoint readpoint below which we can safely remove duplicate Cells.
117    * @return change in memstore size
118    */
119   long upsert(Iterable<Cell> cells, long readpoint);
120
121   /**
122    * @return scanner over the memstore. This might include scanner over the snapshot when one is
123    * present.
124    */
125   List<KeyValueScanner> getScanners(long readPt) throws IOException;
126
127   /**
128    * @return Total memory occupied by this MemStore.
129    */
130   long size();
131
132   /**
133    * This method is called when it is clear that the flush to disk is completed.
134    * The store may do any post-flush actions at this point.
135    * One example is to update the wal with sequence number that is known only at the store level.
136    */
137   void finalizeFlush();
138
139   /* Return true if the memstore may need some extra memory space*/
140   boolean isSloppy();
141 }