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.coprocessor.example; 19 20 import org.apache.hadoop.hbase.client.Scan; 21 import org.apache.hadoop.hbase.ipc.CoprocessorProtocol; 22 23 /** 24 * Defines a protocol to delete data in bulk based on a scan. The scan can be range scan or with 25 * conditions(filters) etc. 26 * </br> Example: <code><pre> 27 * Scan scan = new Scan(); 28 * // set scan properties(rowkey range, filters, timerange etc). 29 * HTable ht = ...; 30 * long noOfDeletedRows = 0L; 31 * Batch.Call<BulkDeleteProtocol, BulkDeleteResponse> callable = 32 * new Batch.Call<BulkDeleteProtocol, BulkDeleteResponse>() { 33 * public BulkDeleteResponse call(BulkDeleteProtocol instance) throws IOException { 34 * return instance.deleteRows(scan, BulkDeleteProtocol.DeleteType, timestamp, rowBatchSize); 35 * } 36 * }; 37 * Map<byte[], BulkDeleteResponse> result = ht.coprocessorExec(BulkDeleteProtocol.class, 38 * scan.getStartRow(), scan.getStopRow(), callable); 39 * for (BulkDeleteResponse response : result.values()) { 40 * noOfDeletedRows = response.getRowsDeleted(); 41 * } 42 * </pre></code> 43 */ 44 public interface BulkDeleteProtocol extends CoprocessorProtocol { 45 46 public interface DeleteType { 47 /** 48 * Delete full row 49 */ 50 byte ROW = 0; 51 /** 52 * Delete full family(s). 53 * Which family(s) to be deleted will be determined by the Scan. 54 * Scan need to select all the families which need to be deleted. 55 */ 56 byte FAMILY = 1; 57 /** 58 * Delete full column(s). 59 * Which column(s) to be deleted will be determined by the Scan. 60 * Scan need to select all the qualifiers which need to be deleted. 61 */ 62 byte COLUMN = 2; 63 /** 64 * Delete one or more version(s) of column(s). 65 * Which column(s) and version(s) to be deleted will be determined by the Scan. 66 * Scan need to select all the qualifiers and its versions which need to be deleted. 67 * When a timestamp is passed only one version at that timestamp will be deleted(even if scan 68 * fetches many versions) 69 */ 70 byte VERSION = 3; 71 } 72 73 /** 74 * 75 * @param scan 76 * @param deleteType 77 * @param timestamp 78 * @param rowBatchSize 79 * The number of rows which need to be accumulated by scan and delete as one batch 80 * @return 81 */ 82 BulkDeleteResponse delete(Scan scan, byte deleteType, Long timestamp, int rowBatchSize); 83 }