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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.util
;
20 import static org
.junit
.Assert
.assertEquals
;
22 import java
.util
.concurrent
.ScheduledThreadPoolExecutor
;
23 import java
.util
.concurrent
.SynchronousQueue
;
24 import java
.util
.concurrent
.ThreadPoolExecutor
;
25 import java
.util
.concurrent
.TimeUnit
;
26 import org
.apache
.hadoop
.fs
.FileSystem
;
27 import org
.apache
.hadoop
.fs
.Path
;
28 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
29 import org
.apache
.hadoop
.hbase
.HConstants
;
30 import org
.apache
.hadoop
.hbase
.TableName
;
31 import org
.apache
.hadoop
.hbase
.coprocessor
.CoprocessorHost
;
32 import org
.apache
.hadoop
.hbase
.io
.hfile
.TestHFile
;
33 import org
.apache
.hadoop
.hbase
.master
.assignment
.AssignmentManager
;
34 import org
.apache
.hadoop
.hbase
.mob
.MobUtils
;
35 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
36 import org
.apache
.hadoop
.hbase
.testclassification
.MiscTests
;
37 import org
.apache
.hadoop
.hbase
.util
.hbck
.HFileCorruptionChecker
;
38 import org
.apache
.hadoop
.hbase
.util
.hbck
.HbckTestingUtil
;
39 import org
.apache
.hbase
.thirdparty
.com
.google
.common
.util
.concurrent
.ThreadFactoryBuilder
;
40 import org
.junit
.AfterClass
;
41 import org
.junit
.Before
;
42 import org
.junit
.BeforeClass
;
43 import org
.junit
.ClassRule
;
44 import org
.junit
.Test
;
45 import org
.junit
.experimental
.categories
.Category
;
47 @Category({MiscTests
.class, MediumTests
.class})
48 public class TestHBaseFsckMOB
extends BaseTestHBaseFsck
{
51 public static final HBaseClassTestRule CLASS_RULE
=
52 HBaseClassTestRule
.forClass(TestHBaseFsckMOB
.class);
55 public static void setUpBeforeClass() throws Exception
{
56 TEST_UTIL
.getConfiguration().set(CoprocessorHost
.MASTER_COPROCESSOR_CONF_KEY
,
57 MasterSyncCoprocessor
.class.getName());
59 conf
.setInt("hbase.regionserver.handler.count", 2);
60 conf
.setInt("hbase.regionserver.metahandler.count", 30);
62 conf
.setInt("hbase.htable.threads.max", POOL_SIZE
);
63 conf
.setInt("hbase.hconnection.threads.max", 2 * POOL_SIZE
);
64 conf
.setInt("hbase.hbck.close.timeout", 2 * REGION_ONLINE_TIMEOUT
);
65 conf
.setInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, 8 * REGION_ONLINE_TIMEOUT
);
66 TEST_UTIL
.startMiniCluster(1);
68 tableExecutorService
= new ThreadPoolExecutor(1, POOL_SIZE
, 60, TimeUnit
.SECONDS
,
69 new SynchronousQueue
<>(), new ThreadFactoryBuilder().setNameFormat("testhbck-pool-%d")
70 .setDaemon(true).setUncaughtExceptionHandler(Threads
.LOGGING_EXCEPTION_HANDLER
).build());
72 hbfsckExecutorService
= new ScheduledThreadPoolExecutor(POOL_SIZE
);
74 AssignmentManager assignmentManager
=
75 TEST_UTIL
.getHBaseCluster().getMaster().getAssignmentManager();
76 regionStates
= assignmentManager
.getRegionStates();
78 connection
= TEST_UTIL
.getConnection();
80 admin
= connection
.getAdmin();
81 admin
.balancerSwitch(false, true);
83 TEST_UTIL
.waitUntilAllRegionsAssigned(TableName
.META_TABLE_NAME
);
87 public static void tearDownAfterClass() throws Exception
{
88 tableExecutorService
.shutdown();
89 hbfsckExecutorService
.shutdown();
91 TEST_UTIL
.shutdownMiniCluster();
96 EnvironmentEdgeManager
.reset();
101 * This creates a table and then corrupts a mob file. Hbck should quarantine the file.
103 @SuppressWarnings("deprecation")
105 public void testQuarantineCorruptMobFile() throws Exception
{
106 TableName table
= TableName
.valueOf(name
.getMethodName());
108 setupMobTable(table
);
109 assertEquals(ROWKEYS
.length
, countRows());
112 FileSystem fs
= FileSystem
.get(conf
);
113 Path mobFile
= getFlushedMobFile(fs
, table
);
114 admin
.disableTable(table
);
115 // create new corrupt mob file.
116 String corruptMobFile
= createMobFileName(mobFile
.getName());
117 Path corrupt
= new Path(mobFile
.getParent(), corruptMobFile
);
118 TestHFile
.truncateFile(fs
, mobFile
, corrupt
);
119 LOG
.info("Created corrupted mob file " + corrupt
);
120 HBaseFsck
.debugLsr(conf
, CommonFSUtils
.getRootDir(conf
));
121 HBaseFsck
.debugLsr(conf
, MobUtils
.getMobHome(conf
));
123 // A corrupt mob file doesn't abort the start of regions, so we can enable the table.
124 admin
.enableTable(table
);
125 HBaseFsck res
= HbckTestingUtil
.doHFileQuarantine(conf
, table
);
126 assertEquals(0, res
.getRetCode());
127 HFileCorruptionChecker hfcc
= res
.getHFilecorruptionChecker();
128 assertEquals(4, hfcc
.getHFilesChecked());
129 assertEquals(0, hfcc
.getCorrupted().size());
130 assertEquals(0, hfcc
.getFailures().size());
131 assertEquals(0, hfcc
.getQuarantined().size());
132 assertEquals(0, hfcc
.getMissing().size());
133 assertEquals(5, hfcc
.getMobFilesChecked());
134 assertEquals(1, hfcc
.getCorruptedMobFiles().size());
135 assertEquals(0, hfcc
.getFailureMobFiles().size());
136 assertEquals(1, hfcc
.getQuarantinedMobFiles().size());
137 assertEquals(0, hfcc
.getMissedMobFiles().size());
138 String quarantinedMobFile
= hfcc
.getQuarantinedMobFiles().iterator().next().getName();
139 assertEquals(corruptMobFile
, quarantinedMobFile
);