1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.client;
21
22 import java.util.List;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.junit.experimental.categories.Category;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.Cell;
28 import org.apache.hadoop.hbase.HBaseTestingUtility;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.MetaTableAccessor;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.hbase.testclassification.LargeTests;
33 import org.apache.hadoop.hbase.util.Bytes;
34
35 @Category({ LargeTests.class})
36 public class TestZKLessAssignment {
37
38 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
39
40 @Test
41 public void testZkLessAssignmentRollbackAndRollForward() throws Exception {
42 Configuration config = TEST_UTIL.getConfiguration();
43 config.setBoolean("hbase.assignment.usezk.migrating", true);
44 TEST_UTIL.startMiniCluster(2);
45 TableName tableName = TableName.valueOf("testZkLessAssignmentRollbackAndRollForward");
46 TEST_UTIL.createTable(tableName.getName(), new byte[][] { Bytes.toBytes("cf1") }, config)
47 .close();
48
49 try (Connection connection = ConnectionFactory.createConnection(config)) {
50 List<Result> results = MetaTableAccessor.fullScanOfMeta(connection);
51 boolean isSNQualifierExist = false;
52 boolean isStateQualifierExist = false;
53 for (Result result : results) {
54 Cell cell =
55 result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.SERVERNAME_QUALIFIER);
56 if (cell != null && cell.getValueLength() > 0) {
57 isSNQualifierExist = true;
58 }
59 cell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER);
60 if (cell != null && cell.getValueLength() > 0) {
61 isStateQualifierExist = true;
62 }
63 }
64 Assert.assertTrue(isSNQualifierExist);
65 Assert.assertTrue(isStateQualifierExist);
66 }
67
68 TEST_UTIL.shutdownMiniHBaseCluster();
69 config.unset("hbase.assignment.usezk.migrating");
70 TEST_UTIL.restartHBaseCluster(2);
71
72 try (Connection connection = ConnectionFactory.createConnection(config)) {
73 List<Result> results = MetaTableAccessor.fullScanOfMeta(connection);
74 boolean isSNQualifierExist = false;
75 boolean isStateQualifierExist = false;
76 for (Result result : results) {
77 Cell cell =
78 result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.SERVERNAME_QUALIFIER);
79 if (cell != null && cell.getValueLength() > 0) {
80 isSNQualifierExist = true;
81 }
82 cell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER);
83 if (cell != null && cell.getValueLength() > 0) {
84 isStateQualifierExist = true;
85 }
86 }
87 Assert.assertFalse(isSNQualifierExist);
88 Assert.assertFalse(isStateQualifierExist);
89 }
90 }
91
92 }