Skip to content

HBASE-23662 : Replace HColumnDescriptor(String cf) with ColumnFamilyD… #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ public class HColumnDescriptor implements ColumnFamilyDescriptor, Comparable<HCo
public static final boolean DEFAULT_NEW_VERSION_BEHAVIOR = ColumnFamilyDescriptorBuilder.DEFAULT_NEW_VERSION_BEHAVIOR;
protected final ModifyableColumnFamilyDescriptor delegatee;

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

/**
* Construct a column descriptor specifying only the family name
* The other attributes are defaulted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.junit.Assert.assertTrue;

import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.exceptions.HBaseException;
import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
Expand All @@ -31,7 +30,6 @@
import org.apache.hadoop.hbase.util.BuilderStyleTest;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.PrettyPrinter;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -112,20 +110,6 @@ public void testHColumnDescriptorShouldThrowIAEWhenFamilyNameEmpty() throws Exce
new HColumnDescriptor(Bytes.toBytes(""));
}

/**
* Test that we add and remove strings from configuration properly.
*/
@Test
public void testAddGetRemoveConfiguration() throws Exception {
HColumnDescriptor desc = new HColumnDescriptor("foo");
String key = "Some";
String value = "value";
desc.setConfiguration(key, value);
assertEquals(value, desc.getConfigurationValue(key));
desc.removeConfiguration(key);
assertEquals(null, desc.getConfigurationValue(key));
}

@Test
public void testMobValuesInHColumnDescriptorShouldReadable() {
boolean isMob = true;
Expand Down Expand Up @@ -161,37 +145,4 @@ public void testClassMethodsAreBuilderStyle() {
BuilderStyleTest.assertClassesAreBuilderStyle(HColumnDescriptor.class);
}

@Test
public void testSetTimeToLive() throws HBaseException {
String ttl;
HColumnDescriptor desc = new HColumnDescriptor("foo");

ttl = "50000";
desc.setTimeToLive(ttl);
Assert.assertEquals(50000, desc.getTimeToLive());

ttl = "50000 seconds";
desc.setTimeToLive(ttl);
Assert.assertEquals(50000, desc.getTimeToLive());

ttl = "";
desc.setTimeToLive(ttl);
Assert.assertEquals(0, desc.getTimeToLive());

ttl = "FOREVER";
desc.setTimeToLive(ttl);
Assert.assertEquals(HConstants.FOREVER, desc.getTimeToLive());

ttl = "1 HOUR 10 minutes 1 second";
desc.setTimeToLive(ttl);
Assert.assertEquals(4201, desc.getTimeToLive());

ttl = "500 Days 23 HOURS";
desc.setTimeToLive(ttl);
Assert.assertEquals(43282800, desc.getTimeToLive());

ttl = "43282800 SECONDS (500 Days 23 hours)";
desc.setTimeToLive(ttl);
Assert.assertEquals(43282800, desc.getTimeToLive());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -37,19 +38,23 @@
import org.apache.hadoop.hbase.CoprocessorEnvironment;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.RegionMetrics;
import org.apache.hadoop.hbase.ServerMetrics;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.CoprocessorDescriptor;
import org.apache.hadoop.hbase.client.CoprocessorDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.hadoop.hbase.regionserver.TestServerCustomProtocol;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassLoaderTestHelper;
import org.apache.hadoop.hbase.util.CoprocessorClassLoader;
import org.apache.hadoop.hdfs.MiniDFSCluster;
Expand Down Expand Up @@ -167,14 +172,15 @@ public void testClassLoadingFromHDFS() throws Exception {
LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS2);

// create a table that references the coprocessors
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor("test"));
// without configuration values
htd.setValue("COPROCESSOR$1", jarFileOnHDFS1.toString() + "|" + cpName1 +
"|" + Coprocessor.PRIORITY_USER);
// with configuration values
htd.setValue("COPROCESSOR$2", jarFileOnHDFS2.toString() + "|" + cpName2 +
"|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(Bytes.toBytes("test")).build());
// without configuration values
tdb.setValue("COPROCESSOR$1", jarFileOnHDFS1 + "|" + cpName1
+ "|" + Coprocessor.PRIORITY_USER);
// with configuration values
tdb.setValue("COPROCESSOR$2", jarFileOnHDFS2 + "|" + cpName2
+ "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
Admin admin = TEST_UTIL.getAdmin();
if (admin.tableExists(tableName)) {
if (admin.isTableEnabled(tableName)) {
Expand All @@ -185,8 +191,9 @@ public void testClassLoadingFromHDFS() throws Exception {
CoprocessorClassLoader.clearCache();
byte[] startKey = {10, 63};
byte[] endKey = {12, 43};
admin.createTable(htd, startKey, endKey, 4);
waitForTable(htd.getTableName());
TableDescriptor tableDescriptor = tdb.build();
admin.createTable(tableDescriptor, startKey, endKey, 4);
waitForTable(tableDescriptor.getTableName());

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

// create a table that references the jar
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName3));
htd.addFamily(new HColumnDescriptor("test"));
htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName3));
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(Bytes.toBytes("test")).build());
tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" +
Coprocessor.PRIORITY_USER);
TableDescriptor tableDescriptor = tdb.build();
Admin admin = TEST_UTIL.getAdmin();
admin.createTable(htd);
waitForTable(htd.getTableName());
admin.createTable(tableDescriptor);
waitForTable(tableDescriptor.getTableName());

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

// create a table that references the jar
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
htd.addFamily(new HColumnDescriptor("test"));
htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName4));
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(Bytes.toBytes("test")).build());
tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
Coprocessor.PRIORITY_USER);
TableDescriptor tableDescriptor = tdb.build();
Admin admin = TEST_UTIL.getAdmin();
admin.createTable(htd);
waitForTable(htd.getTableName());
admin.createTable(tableDescriptor);
waitForTable(tableDescriptor.getTableName());

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

// create a table that references the jar
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor("test"));
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(Bytes.toBytes("test")).build());

// add 3 coprocessors by setting htd attributes directly.
htd.setValue(cpKey1, cpValue1);
htd.setValue(cpKey2, cpValue2);
htd.setValue(cpKey3, cpValue3);
tdb.setValue(cpKey1, cpValue1);
tdb.setValue(cpKey2, cpValue2);
tdb.setValue(cpKey3, cpValue3);

// add 2 coprocessor by using new htd.setCoprocessor() api
htd.addCoprocessor(cpName5, new Path(getLocalPath(jarFile5)),
Coprocessor.PRIORITY_USER, null);
CoprocessorDescriptor coprocessorDescriptor = CoprocessorDescriptorBuilder
.newBuilder(cpName5)
.setJarPath(new Path(getLocalPath(jarFile5)).toString())
.setPriority(Coprocessor.PRIORITY_USER)
.setProperties(Collections.emptyMap())
.build();
tdb.setCoprocessor(coprocessorDescriptor);
Map<String, String> kvs = new HashMap<>();
kvs.put("k1", "v1");
kvs.put("k2", "v2");
kvs.put("k3", "v3");
htd.addCoprocessor(cpName6, new Path(getLocalPath(jarFile6)),
Coprocessor.PRIORITY_USER, kvs);

coprocessorDescriptor = CoprocessorDescriptorBuilder
.newBuilder(cpName6)
.setJarPath(new Path(getLocalPath(jarFile6)).toString())
.setPriority(Coprocessor.PRIORITY_USER)
.setProperties(kvs)
.build();
tdb.setCoprocessor(coprocessorDescriptor);

Admin admin = TEST_UTIL.getAdmin();
if (admin.tableExists(tableName)) {
Expand All @@ -350,8 +373,10 @@ public void testHBase3810() throws Exception {
}
admin.deleteTable(tableName);
}
admin.createTable(htd);
waitForTable(htd.getTableName());

TableDescriptor tableDescriptor = tdb.build();
admin.createTable(tableDescriptor);
waitForTable(tableDescriptor.getTableName());

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

// create a table that references the coprocessors
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor("test"));
TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(tableName);
tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(Bytes.toBytes("test")).build());
// without configuration values
htd.setValue("COPROCESSOR$1", jarFileOnHDFS.toString() + "|" + cpName1 +
"|" + Coprocessor.PRIORITY_USER);
tdb.setValue("COPROCESSOR$1", jarFileOnHDFS + "|" + cpName1
+ "|" + Coprocessor.PRIORITY_USER);
// with configuration values
htd.setValue("COPROCESSOR$2", jarFileOnHDFS.toString() + "|" + cpName2 +
"|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
tdb.setValue("COPROCESSOR$2", jarFileOnHDFS + "|" + cpName2
+ "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
Admin admin = TEST_UTIL.getAdmin();
if (admin.tableExists(tableName)) {
if (admin.isTableEnabled(tableName)) {
admin.disableTable(tableName);
}
admin.deleteTable(tableName);
}
admin.createTable(htd);
waitForTable(htd.getTableName());

TableDescriptor tableDescriptor = tdb.build();
admin.createTable(tableDescriptor);
waitForTable(tableDescriptor.getTableName());

// verify that the coprocessors were loaded
boolean found1 = false, found2 = false, found2_k1 = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import java.util.concurrent.TimeUnit;

import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.testclassification.IntegrationTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.RegionSplitter;
import org.apache.hadoop.hbase.util.RegionSplitter.SplitAlgorithm;
import org.junit.After;
Expand Down Expand Up @@ -109,15 +114,21 @@ public void tearDown() throws IOException {

@Test
public void testCreateTableWithRegions() throws Exception {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
desc.addFamily(new HColumnDescriptor("cf"));
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
.newBuilder(Bytes.toBytes("cf"))
.build();
TableDescriptor tableDescriptor =
TableDescriptorBuilder.newBuilder(TABLE_NAME)
.setColumnFamily(columnFamilyDescriptor)
.build();

SplitAlgorithm algo = new RegionSplitter.HexStringSplit();
byte[][] splits = algo.split(REGION_COUNT);

LOG.info(String.format("Creating table %s with %d splits.", TABLE_NAME, REGION_COUNT));
long startTime = System.currentTimeMillis();
try {
admin.createTable(desc, splits);
admin.createTable(tableDescriptor, splits);
LOG.info(String.format("Pre-split table created successfully in %dms.",
(System.currentTimeMillis() - startTime)));
} catch (IOException e) {
Expand Down
Loading