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.constraint;
19  
20  import org.apache.hadoop.hbase.classification.InterfaceAudience;
21  import org.apache.hadoop.conf.Configurable;
22  import org.apache.hadoop.hbase.client.Put;
23  
24  /**
25   * Apply a {@link Constraint} (in traditional database terminology) to a HTable.
26   * Any number of {@link Constraint Constraints} can be added to the table, in
27   * any order.
28   * <p>
29   * A {@link Constraint} must be added to a table before the table is loaded via
30   * {@link Constraints#add(HTableDescriptor, Class...)} or
31   * {@link Constraints#add(HTableDescriptor,
32   * org.apache.hadoop.hbase.util.Pair...)}
33   * (if you want to add a configuration with the {@link Constraint}). Constraints
34   * will be run in the order that they are added. Further, a Constraint will be
35   * configured before it is run (on load).
36   * <p>
37   * See {@link Constraints#enableConstraint(HTableDescriptor, Class)} and
38   * {@link Constraints#disableConstraint(HTableDescriptor, Class)} for
39   * enabling/disabling of a given {@link Constraint} after it has been added.
40   * <p>
41   * If a {@link Put} is invalid, the Constraint should throw some sort of
42   * {@link org.apache.hadoop.hbase.constraint.ConstraintException}, indicating
43   * that the {@link Put} has failed. When
44   * this exception is thrown, not further retries of the {@link Put} are
45   * attempted nor are any other {@link Constraint Constraints} attempted (the
46   * {@link Put} is clearly not valid). Therefore, there are performance
47   * implications in the order in which {@link BaseConstraint Constraints} are
48   * specified.
49   * <p>
50   * If a {@link Constraint} fails to fail the {@link Put} via a
51   * {@link org.apache.hadoop.hbase.constraint.ConstraintException}, but instead
52   * throws a {@link RuntimeException},
53   * the entire constraint processing mechanism ({@link ConstraintProcessor}) will
54   * be unloaded from the table. This ensures that the region server is still
55   * functional, but no more {@link Put Puts} will be checked via
56   * {@link Constraint Constraints}.
57   * <p>
58   * Further, {@link Constraint Constraints} should probably not be used to
59   * enforce cross-table references as it will cause tremendous write slowdowns,
60   * but it is possible.
61   * <p>
62   * NOTE: Implementing classes must have a nullary (no-args) constructor
63   *
64   * @see BaseConstraint
65   * @see Constraints
66   */
67  @InterfaceAudience.Private
68  public interface Constraint extends Configurable {
69  
70    /**
71     * Check a {@link Put} to ensure it is valid for the table. If the {@link Put}
72     * is valid, then just return from the method. Otherwise, throw an
73     * {@link Exception} specifying what happened. This {@link Exception} is
74     * propagated back to the client so you can see what caused the {@link Put} to
75     * fail.
76     * @param p {@link Put} to check
77     * @throws org.apache.hadoop.hbase.constraint.ConstraintException when the
78     * {@link Put} does not match the
79     *         constraint.
80     */
81    void check(Put p) throws ConstraintException;
82  
83  }