Skip to content

Commit b97621b

Browse files
committed
HBASE-22810 Initialize an separate ThreadPoolExecutor for taking/restoring snapshot (#486)
1 parent 1500d9a commit b97621b

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/executor/EventType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ public enum EventType {
203203
* C_M_SNAPSHOT_TABLE<br>
204204
* Client asking Master to snapshot an offline table.
205205
*/
206-
C_M_SNAPSHOT_TABLE (48, ExecutorType.MASTER_TABLE_OPERATIONS),
206+
C_M_SNAPSHOT_TABLE (48, ExecutorType.MASTER_SNAPSHOT_OPERATIONS),
207207
/**
208208
* Messages originating from Client to Master.<br>
209209
* C_M_RESTORE_SNAPSHOT<br>
210210
* Client asking Master to restore a snapshot.
211211
*/
212-
C_M_RESTORE_SNAPSHOT (49, ExecutorType.MASTER_TABLE_OPERATIONS),
212+
C_M_RESTORE_SNAPSHOT (49, ExecutorType.MASTER_SNAPSHOT_OPERATIONS),
213213

214214
// Updates from master to ZK. This is done by the master and there is
215215
// nothing to process by either Master or RS

hbase-client/src/main/java/org/apache/hadoop/hbase/executor/ExecutorType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public enum ExecutorType {
3636
MASTER_RS_SHUTDOWN (5),
3737
MASTER_META_SERVER_OPERATIONS (6),
3838
M_LOG_REPLAY_OPS (7),
39+
MASTER_SNAPSHOT_OPERATIONS (8),
3940

4041
// RegionServer executor services
4142
RS_OPEN_REGION (20),

hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,33 @@ public static enum Modify {
12581258
public static final String DEFAULT_TEMPORARY_HDFS_DIRECTORY = "/user/"
12591259
+ System.getProperty("user.name") + "/hbase-staging";
12601260

1261+
/**
1262+
* Configurations for master executor services.
1263+
*/
1264+
public static final String MASTER_OPEN_REGION_THREADS =
1265+
"hbase.master.executor.openregion.threads";
1266+
public static final int MASTER_OPEN_REGION_THREADS_DEFAULT = 5;
1267+
1268+
public static final String MASTER_CLOSE_REGION_THREADS =
1269+
"hbase.master.executor.closeregion.threads";
1270+
public static final int MASTER_CLOSE_REGION_THREADS_DEFAULT = 5;
1271+
1272+
public static final String MASTER_SERVER_OPERATIONS_THREADS =
1273+
"hbase.master.executor.serverops.threads";
1274+
public static final int MASTER_SERVER_OPERATIONS_THREADS_DEFAULT = 5;
1275+
1276+
public static final String MASTER_META_SERVER_OPERATIONS_THREADS =
1277+
"hbase.master.executor.meta.serverops.threads";
1278+
public static final int MASTER_META_SERVER_OPERATIONS_THREADS_DEFAULT = 5;
1279+
1280+
public static final String MASTER_LOG_REPLAY_OPS_THREADS =
1281+
"hbase.master.executor.logreplayops.threads";
1282+
public static final int MASTER_LOG_REPLAY_OPS_THREADS_DEFAULT = 10;
1283+
1284+
public static final String MASTER_SNAPSHOT_OPERATIONS_THREADS =
1285+
"hbase.master.executor.snapshot.threads";
1286+
public static final int MASTER_SNAPSHOT_OPERATIONS_THREADS_DEFAULT = 3;
1287+
12611288
private HConstants() {
12621289
// Can't be instantiated with this ctor.
12631290
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,18 +1159,23 @@ public TableNamespaceManager getTableNamespaceManager() {
11591159
* as OOMEs; it should be lightly loaded. See what HRegionServer does if
11601160
* need to install an unexpected exception handler.
11611161
*/
1162-
private void startServiceThreads() throws IOException{
1163-
// Start the executor service pools
1164-
this.service.startExecutorService(ExecutorType.MASTER_OPEN_REGION,
1165-
conf.getInt("hbase.master.executor.openregion.threads", 5));
1166-
this.service.startExecutorService(ExecutorType.MASTER_CLOSE_REGION,
1167-
conf.getInt("hbase.master.executor.closeregion.threads", 5));
1168-
this.service.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS,
1169-
conf.getInt("hbase.master.executor.serverops.threads", 5));
1170-
this.service.startExecutorService(ExecutorType.MASTER_META_SERVER_OPERATIONS,
1171-
conf.getInt("hbase.master.executor.serverops.threads", 5));
1172-
this.service.startExecutorService(ExecutorType.M_LOG_REPLAY_OPS,
1173-
conf.getInt("hbase.master.executor.logreplayops.threads", 10));
1162+
private void startServiceThreads() throws IOException {
1163+
// Start the executor service pools
1164+
this.service.startExecutorService(ExecutorType.MASTER_OPEN_REGION, conf.getInt(
1165+
HConstants.MASTER_OPEN_REGION_THREADS, HConstants.MASTER_OPEN_REGION_THREADS_DEFAULT));
1166+
this.service.startExecutorService(ExecutorType.MASTER_CLOSE_REGION, conf.getInt(
1167+
HConstants.MASTER_CLOSE_REGION_THREADS, HConstants.MASTER_CLOSE_REGION_THREADS_DEFAULT));
1168+
this.service.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS,
1169+
conf.getInt(HConstants.MASTER_SERVER_OPERATIONS_THREADS,
1170+
HConstants.MASTER_SERVER_OPERATIONS_THREADS_DEFAULT));
1171+
this.service.startExecutorService(ExecutorType.MASTER_META_SERVER_OPERATIONS,
1172+
conf.getInt(HConstants.MASTER_META_SERVER_OPERATIONS_THREADS,
1173+
HConstants.MASTER_META_SERVER_OPERATIONS_THREADS_DEFAULT));
1174+
this.service.startExecutorService(ExecutorType.M_LOG_REPLAY_OPS, conf.getInt(
1175+
HConstants.MASTER_LOG_REPLAY_OPS_THREADS, HConstants.MASTER_LOG_REPLAY_OPS_THREADS_DEFAULT));
1176+
this.service.startExecutorService(ExecutorType.MASTER_SNAPSHOT_OPERATIONS,
1177+
conf.getInt(HConstants.MASTER_SNAPSHOT_OPERATIONS_THREADS,
1178+
HConstants.MASTER_SNAPSHOT_OPERATIONS_THREADS_DEFAULT));
11741179

11751180
// We depend on there being only one instance of this executor running
11761181
// at a time. To do concurrency, would need fencing of enable/disable of

hbase-server/src/test/java/org/apache/hadoop/hbase/executor/TestExecutorService.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.*;
2222
import java.io.IOException;
2323
import java.io.StringWriter;
24+
import java.util.concurrent.CountDownLatch;
2425
import java.util.concurrent.ThreadPoolExecutor;
2526
import java.util.concurrent.atomic.AtomicBoolean;
2627
import java.util.concurrent.atomic.AtomicInteger;
@@ -33,6 +34,7 @@
3334
import org.apache.hadoop.hbase.executor.ExecutorService.Executor;
3435
import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus;
3536
import org.apache.hadoop.hbase.testclassification.SmallTests;
37+
import org.junit.Assert;
3638
import org.junit.Test;
3739
import org.junit.experimental.categories.Category;
3840

@@ -205,5 +207,39 @@ public boolean evaluate() throws Exception {
205207
executorService.shutdown();
206208
}
207209

210+
@Test
211+
public void testSnapshotHandlers() throws Exception {
212+
final Configuration conf = HBaseConfiguration.create();
213+
final Server server = mock(Server.class);
214+
when(server.getConfiguration()).thenReturn(conf);
215+
216+
final ExecutorService executorService = new ExecutorService("testSnapshotHandlers");
217+
executorService.startExecutorService(ExecutorType.MASTER_SNAPSHOT_OPERATIONS, 1);
218+
219+
final CountDownLatch latch = new CountDownLatch(1);
220+
executorService.submit(new EventHandler(server, EventType.C_M_SNAPSHOT_TABLE) {
221+
@Override
222+
public void process() throws IOException {
223+
try {
224+
latch.await();
225+
} catch (InterruptedException e) {
226+
Thread.currentThread().interrupt();
227+
}
228+
}
229+
});
230+
231+
int activeCount = executorService.getExecutor(ExecutorType.MASTER_SNAPSHOT_OPERATIONS)
232+
.getThreadPoolExecutor().getActiveCount();
233+
Assert.assertEquals(activeCount, 1);
234+
latch.countDown();
235+
Waiter.waitFor(conf, 3000, new Predicate<Exception>() {
236+
@Override
237+
public boolean evaluate() throws Exception {
238+
int count = executorService.getExecutor(ExecutorType.MASTER_SNAPSHOT_OPERATIONS)
239+
.getThreadPoolExecutor().getActiveCount();
240+
return count == 0;
241+
}
242+
});
243+
}
208244
}
209245

0 commit comments

Comments
 (0)