use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.
the class TestCompactionPolicy method initialize.
/**
* Setting up a Store
* @throws IOException with error
*/
protected void initialize() throws IOException {
Path basedir = new Path(DIR);
String logName = "logs";
Path logdir = new Path(DIR, logName);
ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("family"));
FileSystem fs = FileSystem.get(conf);
fs.delete(logdir, true);
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(Bytes.toBytes("table"))).setColumnFamily(familyDescriptor).build();
RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
hlog = new FSHLog(fs, basedir, logName, conf);
hlog.init();
ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
region = HRegion.createHRegion(info, basedir, conf, tableDescriptor, hlog);
region.close();
Path tableDir = CommonFSUtils.getTableDir(basedir, tableDescriptor.getTableName());
region = new HRegion(tableDir, hlog, fs, conf, info, tableDescriptor, null);
store = new HStore(region, familyDescriptor, conf, false);
TEST_FILE = region.getRegionFileSystem().createTempName();
fs.createNewFile(TEST_FILE);
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.
the class TestDeleteMobTable method testDeleteNonMobTable.
@Test
public void testDeleteNonMobTable() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
TableDescriptor htd = createTableDescriptor(tableName, false);
ColumnFamilyDescriptor hcd = htd.getColumnFamily(FAMILY);
Table table = createTableWithOneFile(htd);
try {
// the mob file doesn't exist
Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
Assert.assertFalse(mobTableDirExist(tableName));
} finally {
table.close();
TEST_UTIL.deleteTable(tableName);
}
Assert.assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
Assert.assertFalse(mobTableDirExist(tableName));
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.
the class TestDeleteMobTable method testMobFamilyDelete.
@Test
public void testMobFamilyDelete() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
TableDescriptor tableDescriptor = createTableDescriptor(tableName, true);
ColumnFamilyDescriptor familyDescriptor = tableDescriptor.getColumnFamily(FAMILY);
tableDescriptor = TableDescriptorBuilder.newBuilder(tableDescriptor).setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("family2"))).build();
Table table = createTableWithOneFile(tableDescriptor);
try {
// the mob file exists
Assert.assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString()));
Assert.assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString()));
String fileName = assertHasOneMobRow(table, tableName, familyDescriptor.getNameAsString());
Assert.assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName));
Assert.assertTrue(mobTableDirExist(tableName));
TEST_UTIL.getAdmin().deleteColumnFamily(tableName, FAMILY);
Assert.assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString()));
Assert.assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString()));
Assert.assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName));
Assert.assertFalse(mobColumnFamilyDirExist(tableName, familyDescriptor.getNameAsString()));
} finally {
table.close();
TEST_UTIL.deleteTable(tableName);
}
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.
the class TestThriftConnection method testThriftAdmin.
private void testThriftAdmin(Connection connection, String namespace, String table) throws Exception {
try (Admin admin = connection.getAdmin()) {
// create name space
NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build();
namespaceDescriptor.setConfiguration("key1", "value1");
namespaceDescriptor.setConfiguration("key2", "value2");
admin.createNamespace(namespaceDescriptor);
// list namespace
NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();
boolean found = false;
for (NamespaceDescriptor nd : namespaceDescriptors) {
if (nd.getName().equals(namespace)) {
found = true;
break;
}
}
assertTrue(found);
// modify namesapce
namespaceDescriptor.setConfiguration("kye3", "value3");
admin.modifyNamespace(namespaceDescriptor);
// get namespace
NamespaceDescriptor namespaceDescriptorReturned = admin.getNamespaceDescriptor(namespace);
assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
// create table
TableDescriptor tableDescriptor = createTable(admin, table);
// modify table
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
builder.setDurability(Durability.ASYNC_WAL);
admin.modifyTable(builder.build());
// modify column family
ColumnFamilyDescriptor familyA = tableDescriptor.getColumnFamily(FAMILYA);
ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(familyA);
familyABuilder.setInMemory(true);
admin.modifyColumnFamily(tableDescriptor.getTableName(), familyABuilder.build());
// add column family
ColumnFamilyDescriptorBuilder familyDBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYD);
familyDBuilder.setDataBlockEncoding(DataBlockEncoding.PREFIX);
admin.addColumnFamily(tableDescriptor.getTableName(), familyDBuilder.build());
// get table descriptor
TableDescriptor tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
assertTrue(tableDescriptorReturned.getColumnFamilies().length == 4);
assertTrue(tableDescriptorReturned.getDurability() == Durability.ASYNC_WAL);
ColumnFamilyDescriptor columnFamilyADescriptor1Returned = tableDescriptorReturned.getColumnFamily(FAMILYA);
assertTrue(columnFamilyADescriptor1Returned.isInMemory() == true);
// delete column family
admin.deleteColumnFamily(tableDescriptor.getTableName(), FAMILYA);
tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
assertTrue(tableDescriptorReturned.getColumnFamilies().length == 3);
// disable table
admin.disableTable(tableDescriptor.getTableName());
assertTrue(admin.isTableDisabled(tableDescriptor.getTableName()));
// enable table
admin.enableTable(tableDescriptor.getTableName());
assertTrue(admin.isTableEnabled(tableDescriptor.getTableName()));
assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
// truncate table
admin.disableTable(tableDescriptor.getTableName());
admin.truncateTable(tableDescriptor.getTableName(), true);
assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
// delete table
admin.disableTable(tableDescriptor.getTableName());
admin.deleteTable(tableDescriptor.getTableName());
assertFalse(admin.tableExists(tableDescriptor.getTableName()));
// delete namespace
admin.deleteNamespace(namespace);
namespaceDescriptors = admin.listNamespaceDescriptors();
// should have 2 namespace, default and hbase
found = false;
for (NamespaceDescriptor nd : namespaceDescriptors) {
if (nd.getName().equals(namespace)) {
found = true;
break;
}
}
assertTrue(found == false);
}
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.
the class TestThriftServer method testMetricsWithException.
@Test
public void testMetricsWithException() throws Exception {
String rowkey = "row1";
String family = "f";
String col = "c";
// create a table which will throw exceptions for requests
final TableName tableName = TableName.valueOf(name.getMethodName());
try {
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).build();
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(ErrorThrowingGetObserver.class.getName()).setColumnFamily(columnFamilyDescriptor).build();
Table table = UTIL.createTable(tableDescriptor, null);
long now = EnvironmentEdgeManager.currentTime();
table.put(new Put(Bytes.toBytes(rowkey)).addColumn(Bytes.toBytes(family), Bytes.toBytes(col), now, Bytes.toBytes("val1")));
Configuration conf = UTIL.getConfiguration();
ThriftMetrics metrics = getMetrics(conf);
ThriftHBaseServiceHandler hbaseHandler = new ThriftHBaseServiceHandler(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()));
Hbase.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, conf);
ByteBuffer tTableName = asByteBuffer(tableName.getNameAsString());
// check metrics increment with a successful get
long preGetCounter = metricsHelper.checkCounterExists("getRow_num_ops", metrics.getSource()) ? metricsHelper.getCounter("getRow_num_ops", metrics.getSource()) : 0;
List<TRowResult> tRowResult = handler.getRow(tTableName, asByteBuffer(rowkey), null);
assertEquals(1, tRowResult.size());
TRowResult tResult = tRowResult.get(0);
TCell expectedColumnValue = new TCell(asByteBuffer("val1"), now);
assertArrayEquals(Bytes.toBytes(rowkey), tResult.getRow());
Collection<TCell> returnedColumnValues = tResult.getColumns().values();
assertEquals(1, returnedColumnValues.size());
assertEquals(expectedColumnValue, returnedColumnValues.iterator().next());
metricsHelper.assertCounter("getRow_num_ops", preGetCounter + 1, metrics.getSource());
// check metrics increment when the get throws each exception type
for (ErrorThrowingGetObserver.ErrorType type : ErrorThrowingGetObserver.ErrorType.values()) {
testExceptionType(handler, metrics, tTableName, rowkey, type);
}
} finally {
UTIL.deleteTable(tableName);
}
}
Aggregations