View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import org.apache.hadoop.classification.InterfaceAudience;
22  
23  /**
24   * This interface is used for the tracking and enforcement of Deletes
25   * during the course of a Get or Scan operation.
26   * <p>
27   * This class is utilized through three methods:
28   * <ul><li>{@link #add} when encountering a Delete
29   * <li>{@link #isDeleted} when checking if a Put KeyValue has been deleted
30   * <li>{@link #update} when reaching the end of a StoreFile
31   */
32  @InterfaceAudience.Private
33  public interface DeleteTracker {
34  
35    /**
36     * Add the specified KeyValue to the list of deletes to check against for
37     * this row operation.
38     * <p>
39     * This is called when a Delete is encountered in a StoreFile.
40     * @param buffer KeyValue buffer
41     * @param qualifierOffset column qualifier offset
42     * @param qualifierLength column qualifier length
43     * @param timestamp timestamp
44     * @param type delete type as byte
45     */
46    public void add(byte [] buffer, int qualifierOffset, int qualifierLength,
47        long timestamp, byte type);
48  
49    /**
50     * Check if the specified KeyValue buffer has been deleted by a previously
51     * seen delete.
52     * @param buffer KeyValue buffer
53     * @param qualifierOffset column qualifier offset
54     * @param qualifierLength column qualifier length
55     * @param timestamp timestamp
56     * @return deleteResult The result tells whether the KeyValue is deleted and why
57     */
58    public DeleteResult isDeleted(byte [] buffer, int qualifierOffset,
59        int qualifierLength, long timestamp);
60  
61    /**
62     * @return true if there are no current delete, false otherwise
63     */
64    public boolean isEmpty();
65  
66    /**
67     * Called at the end of every StoreFile.
68     * <p>
69     * Many optimized implementations of Trackers will require an update at
70     * when the end of each StoreFile is reached.
71     */
72    public void update();
73  
74    /**
75     * Called between rows.
76     * <p>
77     * This clears everything as if a new DeleteTracker was instantiated.
78     */
79    public void reset();
80  
81  
82    /**
83     * Return codes for comparison of two Deletes.
84     * <p>
85     * The codes tell the merging function what to do.
86     * <p>
87     * INCLUDE means add the specified Delete to the merged list.
88     * NEXT means move to the next element in the specified list(s).
89     */
90    enum DeleteCompare {
91      INCLUDE_OLD_NEXT_OLD,
92      INCLUDE_OLD_NEXT_BOTH,
93      INCLUDE_NEW_NEXT_NEW,
94      INCLUDE_NEW_NEXT_BOTH,
95      NEXT_OLD,
96      NEXT_NEW
97    }
98  
99    /**
100    * Returns codes for delete result.
101    * The codes tell the ScanQueryMatcher whether the kv is deleted and why.
102    * Based on the delete result, the ScanQueryMatcher will decide the next
103    * operation
104    */
105   public static enum DeleteResult {
106     FAMILY_DELETED, // The KeyValue is deleted by a delete family.
107     COLUMN_DELETED, // The KeyValue is deleted by a delete column.
108     VERSION_DELETED, // The KeyValue is deleted by a version delete.
109     NOT_DELETED
110   }
111 
112 }