Skip to content

Commit a770ff0

Browse files
committed
HBASE-23662 : Replace HColumnDescriptor(String cf) with ColumnFamilyDescriptor
1 parent 66d1258 commit a770ff0

File tree

54 files changed

+1055
-724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1055
-724
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,6 @@ public class HColumnDescriptor implements ColumnFamilyDescriptor, Comparable<HCo
101101
public static final boolean DEFAULT_NEW_VERSION_BEHAVIOR = ColumnFamilyDescriptorBuilder.DEFAULT_NEW_VERSION_BEHAVIOR;
102102
protected final ModifyableColumnFamilyDescriptor delegatee;
103103

104-
/**
105-
* Construct a column descriptor specifying only the family name
106-
* The other attributes are defaulted.
107-
*
108-
* @param familyName Column family name. Must be 'printable' -- digit or
109-
* letter -- and may not contain a <code>:</code>
110-
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0
111-
* (<a href="https://issues.apache.org/jira/browse/HBASE-18433">HBASE-18433</a>).
112-
* Use {@link ColumnFamilyDescriptorBuilder#of(String)}.
113-
*/
114-
@Deprecated
115-
public HColumnDescriptor(final String familyName) {
116-
this(Bytes.toBytes(familyName));
117-
}
118-
119104
/**
120105
* Construct a column descriptor specifying only the family name
121106
* The other attributes are defaulted.

hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.junit.Assert.assertTrue;
2222

2323
import org.apache.hadoop.hbase.exceptions.DeserializationException;
24-
import org.apache.hadoop.hbase.exceptions.HBaseException;
2524
import org.apache.hadoop.hbase.io.compress.Compression;
2625
import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
2726
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
@@ -31,7 +30,6 @@
3130
import org.apache.hadoop.hbase.util.BuilderStyleTest;
3231
import org.apache.hadoop.hbase.util.Bytes;
3332
import org.apache.hadoop.hbase.util.PrettyPrinter;
34-
import org.junit.Assert;
3533
import org.junit.ClassRule;
3634
import org.junit.Rule;
3735
import org.junit.Test;
@@ -112,20 +110,6 @@ public void testHColumnDescriptorShouldThrowIAEWhenFamilyNameEmpty() throws Exce
112110
new HColumnDescriptor(Bytes.toBytes(""));
113111
}
114112

115-
/**
116-
* Test that we add and remove strings from configuration properly.
117-
*/
118-
@Test
119-
public void testAddGetRemoveConfiguration() throws Exception {
120-
HColumnDescriptor desc = new HColumnDescriptor("foo");
121-
String key = "Some";
122-
String value = "value";
123-
desc.setConfiguration(key, value);
124-
assertEquals(value, desc.getConfigurationValue(key));
125-
desc.removeConfiguration(key);
126-
assertEquals(null, desc.getConfigurationValue(key));
127-
}
128-
129113
@Test
130114
public void testMobValuesInHColumnDescriptorShouldReadable() {
131115
boolean isMob = true;
@@ -161,37 +145,4 @@ public void testClassMethodsAreBuilderStyle() {
161145
BuilderStyleTest.assertClassesAreBuilderStyle(HColumnDescriptor.class);
162146
}
163147

164-
@Test
165-
public void testSetTimeToLive() throws HBaseException {
166-
String ttl;
167-
HColumnDescriptor desc = new HColumnDescriptor("foo");
168-
169-
ttl = "50000";
170-
desc.setTimeToLive(ttl);
171-
Assert.assertEquals(50000, desc.getTimeToLive());
172-
173-
ttl = "50000 seconds";
174-
desc.setTimeToLive(ttl);
175-
Assert.assertEquals(50000, desc.getTimeToLive());
176-
177-
ttl = "";
178-
desc.setTimeToLive(ttl);
179-
Assert.assertEquals(0, desc.getTimeToLive());
180-
181-
ttl = "FOREVER";
182-
desc.setTimeToLive(ttl);
183-
Assert.assertEquals(HConstants.FOREVER, desc.getTimeToLive());
184-
185-
ttl = "1 HOUR 10 minutes 1 second";
186-
desc.setTimeToLive(ttl);
187-
Assert.assertEquals(4201, desc.getTimeToLive());
188-
189-
ttl = "500 Days 23 HOURS";
190-
desc.setTimeToLive(ttl);
191-
Assert.assertEquals(43282800, desc.getTimeToLive());
192-
193-
ttl = "43282800 SECONDS (500 Days 23 hours)";
194-
desc.setTimeToLive(ttl);
195-
Assert.assertEquals(43282800, desc.getTimeToLive());
196-
}
197148
}

hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/TestClassLoading.java

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.File;
2626
import java.io.IOException;
2727
import java.util.Arrays;
28+
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.HashSet;
3031
import java.util.Map;
@@ -37,19 +38,23 @@
3738
import org.apache.hadoop.hbase.CoprocessorEnvironment;
3839
import org.apache.hadoop.hbase.HBaseClassTestRule;
3940
import org.apache.hadoop.hbase.HBaseTestingUtility;
40-
import org.apache.hadoop.hbase.HColumnDescriptor;
41-
import org.apache.hadoop.hbase.HTableDescriptor;
4241
import org.apache.hadoop.hbase.MiniHBaseCluster;
4342
import org.apache.hadoop.hbase.RegionMetrics;
4443
import org.apache.hadoop.hbase.ServerMetrics;
4544
import org.apache.hadoop.hbase.ServerName;
4645
import org.apache.hadoop.hbase.TableName;
4746
import org.apache.hadoop.hbase.client.Admin;
47+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
48+
import org.apache.hadoop.hbase.client.CoprocessorDescriptor;
49+
import org.apache.hadoop.hbase.client.CoprocessorDescriptorBuilder;
50+
import org.apache.hadoop.hbase.client.TableDescriptor;
51+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
4852
import org.apache.hadoop.hbase.regionserver.HRegion;
4953
import org.apache.hadoop.hbase.regionserver.Region;
5054
import org.apache.hadoop.hbase.regionserver.TestServerCustomProtocol;
5155
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
5256
import org.apache.hadoop.hbase.testclassification.MediumTests;
57+
import org.apache.hadoop.hbase.util.Bytes;
5358
import org.apache.hadoop.hbase.util.ClassLoaderTestHelper;
5459
import org.apache.hadoop.hbase.util.CoprocessorClassLoader;
5560
import org.apache.hadoop.hdfs.MiniDFSCluster;
@@ -167,14 +172,15 @@ public void testClassLoadingFromHDFS() throws Exception {
167172
LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS2);
168173

169174
// create a table that references the coprocessors
170-
HTableDescriptor htd = new HTableDescriptor(tableName);
171-
htd.addFamily(new HColumnDescriptor("test"));
172-
// without configuration values
173-
htd.setValue("COPROCESSOR$1", jarFileOnHDFS1.toString() + "|" + cpName1 +
174-
"|" + Coprocessor.PRIORITY_USER);
175-
// with configuration values
176-
htd.setValue("COPROCESSOR$2", jarFileOnHDFS2.toString() + "|" + cpName2 +
177-
"|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
175+
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
176+
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
177+
.newBuilder(Bytes.toBytes("test")).build());
178+
// without configuration values
179+
tdb.setValue("COPROCESSOR$1", jarFileOnHDFS1 + "|" + cpName1
180+
+ "|" + Coprocessor.PRIORITY_USER);
181+
// with configuration values
182+
tdb.setValue("COPROCESSOR$2", jarFileOnHDFS2 + "|" + cpName2
183+
+ "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
178184
Admin admin = TEST_UTIL.getAdmin();
179185
if (admin.tableExists(tableName)) {
180186
if (admin.isTableEnabled(tableName)) {
@@ -185,8 +191,9 @@ public void testClassLoadingFromHDFS() throws Exception {
185191
CoprocessorClassLoader.clearCache();
186192
byte[] startKey = {10, 63};
187193
byte[] endKey = {12, 43};
188-
admin.createTable(htd, startKey, endKey, 4);
189-
waitForTable(htd.getTableName());
194+
TableDescriptor tableDescriptor = tdb.build();
195+
admin.createTable(tableDescriptor, startKey, endKey, 4);
196+
waitForTable(tableDescriptor.getTableName());
190197

191198
// verify that the coprocessors were loaded
192199
boolean foundTableRegion=false;
@@ -253,13 +260,15 @@ public void testClassLoadingFromLocalFS() throws Exception {
253260
File jarFile = buildCoprocessorJar(cpName3);
254261

255262
// create a table that references the jar
256-
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName3));
257-
htd.addFamily(new HColumnDescriptor("test"));
258-
htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
263+
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName3));
264+
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
265+
.newBuilder(Bytes.toBytes("test")).build());
266+
tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
259267
Coprocessor.PRIORITY_USER);
268+
TableDescriptor tableDescriptor = tdb.build();
260269
Admin admin = TEST_UTIL.getAdmin();
261-
admin.createTable(htd);
262-
waitForTable(htd.getTableName());
270+
admin.createTable(tableDescriptor);
271+
waitForTable(tableDescriptor.getTableName());
263272

264273
// verify that the coprocessor was loaded
265274
boolean found = false;
@@ -278,13 +287,15 @@ public void testPrivateClassLoader() throws Exception {
278287
File jarFile = buildCoprocessorJar(cpName4);
279288

280289
// create a table that references the jar
281-
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
282-
htd.addFamily(new HColumnDescriptor("test"));
283-
htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
290+
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName4));
291+
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
292+
.newBuilder(Bytes.toBytes("test")).build());
293+
tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
284294
Coprocessor.PRIORITY_USER);
295+
TableDescriptor tableDescriptor = tdb.build();
285296
Admin admin = TEST_UTIL.getAdmin();
286-
admin.createTable(htd);
287-
waitForTable(htd.getTableName());
297+
admin.createTable(tableDescriptor);
298+
waitForTable(tableDescriptor.getTableName());
288299

289300
// verify that the coprocessor was loaded correctly
290301
boolean found = false;
@@ -325,23 +336,35 @@ public void testHBase3810() throws Exception {
325336
" | org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver | | k=v ";
326337

327338
// create a table that references the jar
328-
HTableDescriptor htd = new HTableDescriptor(tableName);
329-
htd.addFamily(new HColumnDescriptor("test"));
339+
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
340+
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
341+
.newBuilder(Bytes.toBytes("test")).build());
330342

331343
// add 3 coprocessors by setting htd attributes directly.
332-
htd.setValue(cpKey1, cpValue1);
333-
htd.setValue(cpKey2, cpValue2);
334-
htd.setValue(cpKey3, cpValue3);
344+
tdb.setValue(cpKey1, cpValue1);
345+
tdb.setValue(cpKey2, cpValue2);
346+
tdb.setValue(cpKey3, cpValue3);
335347

336348
// add 2 coprocessor by using new htd.setCoprocessor() api
337-
htd.addCoprocessor(cpName5, new Path(getLocalPath(jarFile5)),
338-
Coprocessor.PRIORITY_USER, null);
349+
CoprocessorDescriptor coprocessorDescriptor = CoprocessorDescriptorBuilder
350+
.newBuilder(cpName5)
351+
.setJarPath(new Path(getLocalPath(jarFile5)).toString())
352+
.setPriority(Coprocessor.PRIORITY_USER)
353+
.setProperties(Collections.emptyMap())
354+
.build();
355+
tdb.setCoprocessor(coprocessorDescriptor);
339356
Map<String, String> kvs = new HashMap<>();
340357
kvs.put("k1", "v1");
341358
kvs.put("k2", "v2");
342359
kvs.put("k3", "v3");
343-
htd.addCoprocessor(cpName6, new Path(getLocalPath(jarFile6)),
344-
Coprocessor.PRIORITY_USER, kvs);
360+
361+
coprocessorDescriptor = CoprocessorDescriptorBuilder
362+
.newBuilder(cpName6)
363+
.setJarPath(new Path(getLocalPath(jarFile6)).toString())
364+
.setPriority(Coprocessor.PRIORITY_USER)
365+
.setProperties(kvs)
366+
.build();
367+
tdb.setCoprocessor(coprocessorDescriptor);
345368

346369
Admin admin = TEST_UTIL.getAdmin();
347370
if (admin.tableExists(tableName)) {
@@ -350,8 +373,10 @@ public void testHBase3810() throws Exception {
350373
}
351374
admin.deleteTable(tableName);
352375
}
353-
admin.createTable(htd);
354-
waitForTable(htd.getTableName());
376+
377+
TableDescriptor tableDescriptor = tdb.build();
378+
admin.createTable(tableDescriptor);
379+
waitForTable(tableDescriptor.getTableName());
355380

356381
// verify that the coprocessor was loaded
357382
boolean found_2 = false, found_1 = false, found_3 = false,
@@ -426,23 +451,26 @@ void loadingClassFromLibDirInJar(String libPrefix) throws Exception {
426451
LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS);
427452

428453
// create a table that references the coprocessors
429-
HTableDescriptor htd = new HTableDescriptor(tableName);
430-
htd.addFamily(new HColumnDescriptor("test"));
454+
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
455+
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
456+
.newBuilder(Bytes.toBytes("test")).build());
431457
// without configuration values
432-
htd.setValue("COPROCESSOR$1", jarFileOnHDFS.toString() + "|" + cpName1 +
433-
"|" + Coprocessor.PRIORITY_USER);
458+
tdb.setValue("COPROCESSOR$1", jarFileOnHDFS + "|" + cpName1
459+
+ "|" + Coprocessor.PRIORITY_USER);
434460
// with configuration values
435-
htd.setValue("COPROCESSOR$2", jarFileOnHDFS.toString() + "|" + cpName2 +
436-
"|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
461+
tdb.setValue("COPROCESSOR$2", jarFileOnHDFS + "|" + cpName2
462+
+ "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
437463
Admin admin = TEST_UTIL.getAdmin();
438464
if (admin.tableExists(tableName)) {
439465
if (admin.isTableEnabled(tableName)) {
440466
admin.disableTable(tableName);
441467
}
442468
admin.deleteTable(tableName);
443469
}
444-
admin.createTable(htd);
445-
waitForTable(htd.getTableName());
470+
471+
TableDescriptor tableDescriptor = tdb.build();
472+
admin.createTable(tableDescriptor);
473+
waitForTable(tableDescriptor.getTableName());
446474

447475
// verify that the coprocessors were loaded
448476
boolean found1 = false, found2 = false, found2_k1 = false,

hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestManyRegions.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
import java.util.concurrent.TimeUnit;
2323

2424
import org.apache.hadoop.hbase.client.Admin;
25+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
26+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
27+
import org.apache.hadoop.hbase.client.TableDescriptor;
28+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
2529
import org.apache.hadoop.hbase.testclassification.IntegrationTests;
30+
import org.apache.hadoop.hbase.util.Bytes;
2631
import org.apache.hadoop.hbase.util.RegionSplitter;
2732
import org.apache.hadoop.hbase.util.RegionSplitter.SplitAlgorithm;
2833
import org.junit.After;
@@ -109,15 +114,21 @@ public void tearDown() throws IOException {
109114

110115
@Test
111116
public void testCreateTableWithRegions() throws Exception {
112-
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
113-
desc.addFamily(new HColumnDescriptor("cf"));
117+
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
118+
.newBuilder(Bytes.toBytes("cf"))
119+
.build();
120+
TableDescriptor tableDescriptor =
121+
TableDescriptorBuilder.newBuilder(TABLE_NAME)
122+
.setColumnFamily(columnFamilyDescriptor)
123+
.build();
124+
114125
SplitAlgorithm algo = new RegionSplitter.HexStringSplit();
115126
byte[][] splits = algo.split(REGION_COUNT);
116127

117128
LOG.info(String.format("Creating table %s with %d splits.", TABLE_NAME, REGION_COUNT));
118129
long startTime = System.currentTimeMillis();
119130
try {
120-
admin.createTable(desc, splits);
131+
admin.createTable(tableDescriptor, splits);
121132
LOG.info(String.format("Pre-split table created successfully in %dms.",
122133
(System.currentTimeMillis() - startTime)));
123134
} catch (IOException e) {

0 commit comments

Comments
 (0)