Search in sources :

Example 41 with ColumnFamilyDescriptor

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.

the class BaseTestHBaseFsck method setupMobTable.

/**
 * Setup a clean table with a mob-enabled column.
 *
 * @param tablename The name of a table to be created.
 * @throws Exception
 */
void setupMobTable(TableName tablename) throws Exception {
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tablename);
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(FAM).setMobEnabled(true).setMobThreshold(0).build();
    // If a table has no CF's it doesn't get checked
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    createTable(TEST_UTIL, tableDescriptorBuilder.build(), SPLITS);
    tbl = connection.getTable(tablename, tableExecutorService);
    List<Put> puts = new ArrayList<>(ROWKEYS.length);
    for (byte[] row : ROWKEYS) {
        Put p = new Put(row);
        p.addColumn(FAM, Bytes.toBytes("val"), row);
        puts.add(p);
    }
    tbl.put(puts);
}
Also used : ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) Put(org.apache.hadoop.hbase.client.Put)

Example 42 with ColumnFamilyDescriptor

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.

the class BaseTestHBaseFsck method setupTableWithRegionReplica.

/**
 * Setup a clean table with a certain region_replica count
 *
 * It will set tbl which needs to be closed after test
 *
 * @throws Exception
 */
void setupTableWithRegionReplica(TableName tablename, int replicaCount) throws Exception {
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tablename);
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(FAM).build();
    tableDescriptorBuilder.setRegionReplication(replicaCount);
    // If a table has no CF's it doesn't get checked
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    createTable(TEST_UTIL, tableDescriptorBuilder.build(), SPLITS);
    tbl = connection.getTable(tablename, tableExecutorService);
    List<Put> puts = new ArrayList<>(ROWKEYS.length);
    for (byte[] row : ROWKEYS) {
        Put p = new Put(row);
        p.addColumn(FAM, Bytes.toBytes("val"), row);
        puts.add(p);
    }
    tbl.put(puts);
}
Also used : ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) Put(org.apache.hadoop.hbase.client.Put)

Example 43 with ColumnFamilyDescriptor

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.

the class TestSnapshotManifest method createRegionManifest.

private Path createRegionManifest() throws IOException {
    byte[] startKey = Bytes.toBytes("AAAAAA");
    byte[] stopKey = Bytes.toBytes("BBBBBB");
    RegionInfo regionInfo = RegionInfoBuilder.newBuilder(TABLE_NAME).build();
    SnapshotRegionManifest.Builder dataRegionManifestBuilder = SnapshotRegionManifest.newBuilder();
    dataRegionManifestBuilder.setRegionInfo(ProtobufUtil.toRegionInfo(regionInfo));
    for (ColumnFamilyDescriptor hcd : builder.getTableDescriptor().getColumnFamilies()) {
        SnapshotRegionManifest.FamilyFiles.Builder family = SnapshotRegionManifest.FamilyFiles.newBuilder();
        family.setFamilyName(UnsafeByteOperations.unsafeWrap(hcd.getName()));
        for (int j = 0; j < TEST_NUM_REGIONFILES; ++j) {
            SnapshotRegionManifest.StoreFile.Builder sfManifest = SnapshotRegionManifest.StoreFile.newBuilder();
            sfManifest.setName(String.format("%064d", j));
            sfManifest.setFileSize(j * 1024);
            family.addStoreFiles(sfManifest.build());
        }
        dataRegionManifestBuilder.addFamilyFiles(family.build());
    }
    SnapshotRegionManifest manifest = dataRegionManifestBuilder.build();
    Path regionPath = new Path(snapshotDir, SnapshotManifestV2.SNAPSHOT_MANIFEST_PREFIX + regionInfo.getEncodedName());
    FSDataOutputStream stream = fs.create(regionPath);
    try {
        manifest.writeTo(stream);
    } finally {
        stream.close();
    }
    return regionPath;
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotRegionManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Example 44 with ColumnFamilyDescriptor

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.

the class TestSnapshotManifest method createDataManifest.

private Path createDataManifest() throws IOException {
    SnapshotDataManifest.Builder dataManifestBuilder = SnapshotDataManifest.newBuilder();
    byte[] startKey = null;
    byte[] stopKey = null;
    for (int i = 1; i <= TEST_NUM_REGIONS; i++) {
        stopKey = Bytes.toBytes(String.format("%016d", i));
        RegionInfo regionInfo = RegionInfoBuilder.newBuilder(TABLE_NAME).build();
        SnapshotRegionManifest.Builder dataRegionManifestBuilder = SnapshotRegionManifest.newBuilder();
        for (ColumnFamilyDescriptor hcd : builder.getTableDescriptor().getColumnFamilies()) {
            SnapshotRegionManifest.FamilyFiles.Builder family = SnapshotRegionManifest.FamilyFiles.newBuilder();
            family.setFamilyName(UnsafeByteOperations.unsafeWrap(hcd.getName()));
            for (int j = 0; j < 100; ++j) {
                SnapshotRegionManifest.StoreFile.Builder sfManifest = SnapshotRegionManifest.StoreFile.newBuilder();
                sfManifest.setName(String.format("%032d", i));
                sfManifest.setFileSize((1 + i) * (1 + i) * 1024);
                family.addStoreFiles(sfManifest.build());
            }
            dataRegionManifestBuilder.addFamilyFiles(family.build());
        }
        dataRegionManifestBuilder.setRegionInfo(ProtobufUtil.toRegionInfo(regionInfo));
        dataManifestBuilder.addRegionManifests(dataRegionManifestBuilder.build());
        startKey = stopKey;
    }
    dataManifestBuilder.setTableSchema(ProtobufUtil.toTableSchema(builder.getTableDescriptor()));
    SnapshotDataManifest dataManifest = dataManifestBuilder.build();
    return writeDataManifest(dataManifest);
}
Also used : SnapshotDataManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDataManifest) SnapshotRegionManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Example 45 with ColumnFamilyDescriptor

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptor in project hbase by apache.

the class TestVisibilityLabels method testUserShouldNotDoDDLOpOnLabelsTable.

@Test
public void testUserShouldNotDoDDLOpOnLabelsTable() throws Exception {
    Admin admin = TEST_UTIL.getAdmin();
    try {
        admin.disableTable(LABELS_TABLE_NAME);
        fail("Lables table should not get disabled by user.");
    } catch (Exception e) {
    }
    try {
        admin.deleteTable(LABELS_TABLE_NAME);
        fail("Lables table should not get disabled by user.");
    } catch (Exception e) {
    }
    try {
        ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("testFamily")).build();
        admin.addColumnFamily(LABELS_TABLE_NAME, columnFamilyDescriptor);
        fail("Lables table should not get altered by user.");
    } catch (Exception e) {
    }
    try {
        admin.deleteColumnFamily(LABELS_TABLE_NAME, VisibilityConstants.LABELS_TABLE_FAMILY);
        fail("Lables table should not get altered by user.");
    } catch (Exception e) {
    }
    try {
        ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(VisibilityConstants.LABELS_TABLE_FAMILY).setBloomFilterType(BloomType.ROWCOL).build();
        admin.modifyColumnFamily(LABELS_TABLE_NAME, familyDescriptor);
        fail("Lables table should not get altered by user.");
    } catch (Exception e) {
    }
    try {
        TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(LABELS_TABLE_NAME);
        ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f1")).build();
        tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
        columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f2")).build();
        tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
        admin.modifyTable(tableDescriptorBuilder.build());
        fail("Lables table should not get altered by user.");
    } catch (Exception e) {
    }
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)199 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)95 Test (org.junit.Test)92 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)78 IOException (java.io.IOException)44 TableName (org.apache.hadoop.hbase.TableName)44 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)42 Path (org.apache.hadoop.fs.Path)41 Admin (org.apache.hadoop.hbase.client.Admin)36 Configuration (org.apache.hadoop.conf.Configuration)34 ArrayList (java.util.ArrayList)32 Put (org.apache.hadoop.hbase.client.Put)32 FileSystem (org.apache.hadoop.fs.FileSystem)28 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)24 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)22 Get (org.apache.hadoop.hbase.client.Get)20 Result (org.apache.hadoop.hbase.client.Result)19 ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)17 Scan (org.apache.hadoop.hbase.client.Scan)17 Table (org.apache.hadoop.hbase.client.Table)17