001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.coprocessor.example;
019
020import org.apache.hadoop.hbase.client.Scan;
021import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
022
023/**
024 * Defines a protocol to delete data in bulk based on a scan. The scan can be range scan or with
025 * conditions(filters) etc.
026 * </br> Example: <code><pre>
027 * Scan scan = new Scan();
028 * // set scan properties(rowkey range, filters, timerange etc).
029 * HTable ht = ...;
030 * long noOfDeletedRows = 0L;
031 * Batch.Call&lt;BulkDeleteProtocol, BulkDeleteResponse&gt; callable = 
032 *     new Batch.Call&lt;BulkDeleteProtocol, BulkDeleteResponse&gt;() {
033 *   public BulkDeleteResponse call(BulkDeleteProtocol instance) throws IOException {
034 *     return instance.deleteRows(scan, BulkDeleteProtocol.DeleteType, timestamp, rowBatchSize);
035 *   }
036 * };
037 * Map&lt;byte[], BulkDeleteResponse&gt; result = ht.coprocessorExec(BulkDeleteProtocol.class,
038 *      scan.getStartRow(), scan.getStopRow(), callable);
039 *  for (BulkDeleteResponse response : result.values()) {
040 *    noOfDeletedRows = response.getRowsDeleted();
041 *  }
042 * </pre></code>
043 */
044public interface BulkDeleteProtocol extends CoprocessorProtocol {
045  
046  public interface DeleteType {
047    /** 
048     * Delete full row
049     */
050    byte ROW = 0;
051    /**
052     * Delete full family(s).
053     * Which family(s) to be deleted will be determined by the Scan.
054     * Scan need to select all the families which need to be deleted.
055     */
056    byte FAMILY = 1;
057    /**
058     * Delete full column(s).
059     * Which column(s) to be deleted will be determined by the Scan.
060     * Scan need to select all the qualifiers which need to be deleted.
061     */
062    byte COLUMN = 2;
063    /**
064     * Delete one or more version(s) of column(s).
065     * Which column(s) and version(s) to be deleted will be determined by the Scan.
066     * Scan need to select all the qualifiers and its versions which need to be deleted.
067     * When a timestamp is passed only one version at that timestamp will be deleted(even if scan
068     * fetches many versions)
069     */
070    byte VERSION = 3;
071  }
072  
073  /**
074   * 
075   * @param scan
076   * @param deleteType
077   * @param timestamp
078   * @param rowBatchSize
079   *          The number of rows which need to be accumulated by scan and delete as one batch
080   * @return
081   */
082  BulkDeleteResponse delete(Scan scan, byte deleteType, Long timestamp, int rowBatchSize);
083}