HBASE-26688 Threads shared EMPTY_RESULT may lead to unexpected client job down. ...
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / RequestController.java
blob4c63e4d0881249a71abde9ea41c5eafa622fd028
1 /*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org.apache.hadoop.hbase.client;
22 import java.io.InterruptedIOException;
23 import java.util.Collection;
24 import java.util.function.Consumer;
25 import org.apache.hadoop.hbase.HRegionLocation;
26 import org.apache.hadoop.hbase.ServerName;
27 import org.apache.yetus.audience.InterfaceAudience;
29 /**
30 * An interface for client request scheduling algorithm.
32 @InterfaceAudience.Public
33 public interface RequestController {
35 @InterfaceAudience.Public
36 public enum ReturnCode {
37 /**
38 * Accept current row.
40 INCLUDE,
41 /**
42 * Skip current row.
44 SKIP,
45 /**
46 * No more row can be included.
48 END
51 /**
52 * Picks up the valid data.
54 @InterfaceAudience.Public
55 public interface Checker {
56 /**
57 * Checks the data whether it is valid to submit.
58 * @param loc the destination of data
59 * @param row the data to check
60 * @return describe the decision for the row
62 ReturnCode canTakeRow(HRegionLocation loc, Row row);
64 /**
65 * Reset the state of the scheduler when completing the iteration of rows.
66 * @throws InterruptedIOException some controller may wait
67 * for some busy region or RS to complete the undealt request.
69 void reset() throws InterruptedIOException ;
72 /**
73 * @return A new checker for evaluating a batch rows.
75 Checker newChecker();
77 /**
78 * Increment the counter if we build a valid task.
79 * @param regions The destination of task
80 * @param sn The target server
82 void incTaskCounters(Collection<byte[]> regions, ServerName sn);
84 /**
85 * Decrement the counter if a task is accomplished.
86 * @param regions The destination of task
87 * @param sn The target server
89 void decTaskCounters(Collection<byte[]> regions, ServerName sn);
91 /**
92 * @return The number of running task.
94 long getNumberOfTasksInProgress();
96 /**
97 * Waits for the running tasks to complete.
98 * If there are specified threshold and trigger, the implementation should
99 * wake up once in a while for checking the threshold and calling trigger.
100 * @param max This method will return if the number of running tasks is
101 * less than or equal to max.
102 * @param id the caller's id
103 * @param periodToTrigger The period to invoke the trigger. This value is a
104 * hint. The real period depends on the implementation.
105 * @param trigger The object to call periodically.
106 * @throws java.io.InterruptedIOException If the waiting is interrupted
108 void waitForMaximumCurrentTasks(long max, long id,
109 int periodToTrigger, Consumer<Long> trigger) throws InterruptedIOException;
112 * Wait until there is at least one slot for a new task.
113 * @param id the caller's id
114 * @param periodToTrigger The period to invoke the trigger. This value is a
115 * hint. The real period depends on the implementation.
116 * @param trigger The object to call periodically.
117 * @throws java.io.InterruptedIOException If the waiting is interrupted
119 void waitForFreeSlot(long id, int periodToTrigger,
120 Consumer<Long> trigger) throws InterruptedIOException;