View Javadoc

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