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
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertTrue
;
22 import static org
.junit
.Assert
.fail
;
24 import java
.io
.IOException
;
25 import java
.util
.Collections
;
26 import org
.apache
.hadoop
.hbase
.client
.Admin
;
27 import org
.apache
.hadoop
.hbase
.client
.ColumnFamilyDescriptor
;
28 import org
.apache
.hadoop
.hbase
.client
.ColumnFamilyDescriptorBuilder
;
29 import org
.apache
.hadoop
.hbase
.client
.RegionInfoBuilder
;
30 import org
.apache
.hadoop
.hbase
.client
.TableDescriptor
;
31 import org
.apache
.hadoop
.hbase
.io
.encoding
.DataBlockEncoding
;
32 import org
.apache
.hadoop
.hbase
.regionserver
.Region
;
33 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.MiscTests
;
35 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
36 import org
.junit
.After
;
37 import org
.junit
.Before
;
38 import org
.junit
.ClassRule
;
39 import org
.junit
.Rule
;
40 import org
.junit
.Test
;
41 import org
.junit
.experimental
.categories
.Category
;
42 import org
.junit
.rules
.TestName
;
45 * Test being able to edit hbase:meta.
47 @Category({ MiscTests
.class, MediumTests
.class })
48 public class TestHBaseMetaEdit
{
50 public static final HBaseClassTestRule CLASS_RULE
=
51 HBaseClassTestRule
.forClass(TestHBaseMetaEdit
.class);
53 public TestName name
= new TestName();
54 private final static HBaseTestingUtility UTIL
= new HBaseTestingUtility();
57 public void before() throws Exception
{
58 UTIL
.startMiniCluster();
62 public void after() throws Exception
{
63 UTIL
.shutdownMiniCluster();
66 // make sure that with every possible way, we get the same meta table descriptor.
67 private TableDescriptor
getMetaDescriptor() throws TableNotFoundException
, IOException
{
68 Admin admin
= UTIL
.getAdmin();
69 TableDescriptor get
= admin
.getDescriptor(TableName
.META_TABLE_NAME
);
70 TableDescriptor list
=
71 admin
.listTableDescriptors(true).stream().filter(td
-> td
.isMetaTable()).findAny().get();
72 TableDescriptor listByName
=
73 admin
.listTableDescriptors(Collections
.singletonList(TableName
.META_TABLE_NAME
)).get(0);
74 TableDescriptor listByNs
=
75 admin
.listTableDescriptorsByNamespace(NamespaceDescriptor
.SYSTEM_NAMESPACE_NAME
).stream()
76 .filter(td
-> td
.isMetaTable()).findAny().get();
77 assertEquals(get
, list
);
78 assertEquals(get
, listByName
);
79 assertEquals(get
, listByNs
);
84 * Set versions, set HBASE-16213 indexed block encoding, and add a column family.
85 * Delete the column family. Then try to delete a core hbase:meta family (should fail).
86 * Verify they are all in place by looking at TableDescriptor AND by checking
87 * what the RegionServer sees after opening Region.
90 public void testEditMeta() throws IOException
{
91 Admin admin
= UTIL
.getAdmin();
92 admin
.tableExists(TableName
.META_TABLE_NAME
);
93 TableDescriptor originalDescriptor
= getMetaDescriptor();
94 ColumnFamilyDescriptor cfd
= originalDescriptor
.getColumnFamily(HConstants
.CATALOG_FAMILY
);
95 int oldVersions
= cfd
.getMaxVersions();
96 // Add '1' to current versions count. Set encoding too.
97 cfd
= ColumnFamilyDescriptorBuilder
.newBuilder(cfd
).setMaxVersions(oldVersions
+ 1).
98 setConfiguration(ColumnFamilyDescriptorBuilder
.DATA_BLOCK_ENCODING
,
99 DataBlockEncoding
.ROW_INDEX_V1
.toString()).build();
100 admin
.modifyColumnFamily(TableName
.META_TABLE_NAME
, cfd
);
101 byte [] extraColumnFamilyName
= Bytes
.toBytes("xtra");
102 ColumnFamilyDescriptor newCfd
=
103 ColumnFamilyDescriptorBuilder
.newBuilder(extraColumnFamilyName
).build();
104 admin
.addColumnFamily(TableName
.META_TABLE_NAME
, newCfd
);
105 TableDescriptor descriptor
= getMetaDescriptor();
106 // Assert new max versions is == old versions plus 1.
107 assertEquals(oldVersions
+ 1,
108 descriptor
.getColumnFamily(HConstants
.CATALOG_FAMILY
).getMaxVersions());
109 descriptor
= getMetaDescriptor();
110 // Assert new max versions is == old versions plus 1.
111 assertEquals(oldVersions
+ 1,
112 descriptor
.getColumnFamily(HConstants
.CATALOG_FAMILY
).getMaxVersions());
113 assertTrue(descriptor
.getColumnFamily(newCfd
.getName()) != null);
114 String encoding
= descriptor
.getColumnFamily(HConstants
.CATALOG_FAMILY
).getConfiguration().
115 get(ColumnFamilyDescriptorBuilder
.DATA_BLOCK_ENCODING
);
116 assertEquals(encoding
, DataBlockEncoding
.ROW_INDEX_V1
.toString());
117 Region r
= UTIL
.getHBaseCluster().getRegionServer(0).
118 getRegion(RegionInfoBuilder
.FIRST_META_REGIONINFO
.getEncodedName());
119 assertEquals(oldVersions
+ 1,
120 r
.getStore(HConstants
.CATALOG_FAMILY
).getColumnFamilyDescriptor().getMaxVersions());
121 encoding
= r
.getStore(HConstants
.CATALOG_FAMILY
).getColumnFamilyDescriptor().
122 getConfigurationValue(ColumnFamilyDescriptorBuilder
.DATA_BLOCK_ENCODING
);
123 assertEquals(encoding
, DataBlockEncoding
.ROW_INDEX_V1
.toString());
124 assertTrue(r
.getStore(extraColumnFamilyName
) != null);
125 // Assert we can't drop critical hbase:meta column family but we can drop any other.
126 admin
.deleteColumnFamily(TableName
.META_TABLE_NAME
, newCfd
.getName());
127 descriptor
= getMetaDescriptor();
128 assertTrue(descriptor
.getColumnFamily(newCfd
.getName()) == null);
130 admin
.deleteColumnFamily(TableName
.META_TABLE_NAME
, HConstants
.CATALOG_FAMILY
);
131 fail("Should not reach here");
132 } catch (HBaseIOException hioe
) {
133 assertTrue(hioe
.getMessage().contains("Delete of hbase:meta"));