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.regionserver; 019 020import com.google.protobuf.Message; 021import java.io.IOException; 022import java.util.Collection; 023import java.util.List; 024import java.util.UUID; 025import org.apache.hadoop.hbase.HBaseInterfaceAudience; 026import org.apache.hadoop.hbase.client.Durability; 027import org.apache.hadoop.hbase.client.Mutation; 028import org.apache.hadoop.hbase.wal.WALEdit; 029import org.apache.yetus.audience.InterfaceAudience; 030import org.apache.yetus.audience.InterfaceStability; 031 032/** 033 * Defines the procedures to atomically perform multiple scans and mutations on a HRegion. This is 034 * invoked by {@link Region#processRowsWithLocks(RowProcessor)}. This class performs scans and 035 * generates mutations and WAL edits. The locks and MVCC will be handled by HRegion. The 036 * RowProcessor user code could have data that needs to be sent across for proper initialization at 037 * the server side. The generic type parameter S is the type of the request data sent to the server. 038 * The generic type parameter T is the return type of RowProcessor.getResult(). 039 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. For customization, use 040 * Coprocessors instead. 041 */ 042@Deprecated 043@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 044@InterfaceStability.Evolving 045public interface RowProcessor<S extends Message, T extends Message> { 046 047 /** 048 * Rows to lock while operation. They have to be sorted with <code>RowProcessor</code> to avoid 049 * deadlock. 050 */ 051 Collection<byte[]> getRowsToLock(); 052 053 /** 054 * Obtain the processing result. All row processor implementations must implement this, even if 055 * the method is simply returning an empty Message. 056 */ 057 T getResult(); 058 059 /** 060 * Is this operation read only? If this is true, process() should not add any mutations or it 061 * throws IOException. 062 * @return ture if read only operation 063 */ 064 boolean readOnly(); 065 066 /** 067 * HRegion handles the locks and MVCC and invokes this method properly. You should override this 068 * to create your own RowProcessor. If you are doing read-modify-write here, you should consider 069 * using <code>IsolationLevel.READ_UNCOMMITTED</code> for scan because we advance MVCC after 070 * releasing the locks for optimization purpose. 071 * @param now the current system millisecond 072 * @param region the HRegion 073 * @param mutations the output mutations to apply to memstore 074 * @param walEdit the output WAL edits to apply to write ahead log 075 */ 076 void process(long now, HRegion region, List<Mutation> mutations, WALEdit walEdit) 077 throws IOException; 078 079 /** 080 * The hook to be executed before process(). 081 * @param region the HRegion 082 * @param walEdit the output WAL edits to apply to write ahead log 083 */ 084 void preProcess(HRegion region, WALEdit walEdit) throws IOException; 085 086 /** 087 * The hook to be executed after the process() but before applying the Mutations to region. Also 088 * by the time this hook is called, mvcc transaction have started. 089 * @param walEdit the output WAL edits to apply to write ahead log 090 */ 091 void preBatchMutate(HRegion region, WALEdit walEdit) throws IOException; 092 093 /** 094 * The hook to be executed after the process() and applying the Mutations to region. The 095 * difference of this one with {@link #postProcess(HRegion, WALEdit, boolean)} is this hook will 096 * be executed before the mvcc transaction completion. 097 */ 098 void postBatchMutate(HRegion region) throws IOException; 099 100 /** 101 * The hook to be executed after process() and applying the Mutations to region. 102 * @param region the HRegion 103 * @param walEdit the output WAL edits to apply to write ahead log 104 * @param success true if batch operation is successful otherwise false. 105 */ 106 void postProcess(HRegion region, WALEdit walEdit, boolean success) throws IOException; 107 108 /** Returns The cluster ids that have the change. */ 109 List<UUID> getClusterIds(); 110 111 /** 112 * Human readable name of the processor 113 * @return The name of the processor 114 */ 115 String getName(); 116 117 /** 118 * This method should return any additional data that is needed on the server side to construct 119 * the RowProcessor. The server will pass this to the {@link #initialize(Message msg)} method. If 120 * there is no RowProcessor specific data then null should be returned. 121 * @return the PB message n 122 */ 123 S getRequestData() throws IOException; 124 125 /** 126 * This method should initialize any field(s) of the RowProcessor with a parsing of the passed 127 * message bytes (used on the server side). nn 128 */ 129 void initialize(S msg) throws IOException; 130 131 /** Returns The {@link Durability} to use */ 132 Durability useDurability(); 133}