Java Code Examples for org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder#setMobEnabled()

The following examples show how to use org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder#setMobEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCopyTable.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void doCopyTableTestWithMob(boolean bulkload) throws Exception {
  final TableName tableName1 = TableName.valueOf(name.getMethodName() + "1");
  final TableName tableName2 = TableName.valueOf(name.getMethodName() + "2");
  final byte[] FAMILY = Bytes.toBytes("mob");
  final byte[] COLUMN1 = Bytes.toBytes("c1");

  ColumnFamilyDescriptorBuilder cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);

  cfd.setMobEnabled(true);
  cfd.setMobThreshold(5);
  TableDescriptor desc1 = TableDescriptorBuilder.newBuilder(tableName1)
          .setColumnFamily(cfd.build())
          .build();
  TableDescriptor desc2 = TableDescriptorBuilder.newBuilder(tableName2)
          .setColumnFamily(cfd.build())
          .build();

  try (Table t1 = TEST_UTIL.createTable(desc1, null);
       Table t2 = TEST_UTIL.createTable(desc2, null);) {

    // put rows into the first table
    for (int i = 0; i < 10; i++) {
      Put p = new Put(Bytes.toBytes("row" + i));
      p.addColumn(FAMILY, COLUMN1, COLUMN1);
      t1.put(p);
    }

    CopyTable copy = new CopyTable();

    int code;
    if (bulkload) {
      code = ToolRunner.run(new Configuration(TEST_UTIL.getConfiguration()),
          copy, new String[] { "--new.name=" + tableName2.getNameAsString(),
            "--bulkload", tableName1.getNameAsString() });
    } else {
      code = ToolRunner.run(new Configuration(TEST_UTIL.getConfiguration()),
          copy, new String[] { "--new.name=" + tableName2.getNameAsString(),
          tableName1.getNameAsString() });
    }
    assertEquals("copy job failed", 0, code);

    // verify the data was copied into table 2
    for (int i = 0; i < 10; i++) {
      Get g = new Get(Bytes.toBytes("row" + i));
      Result r = t2.get(g);
      assertEquals(1, r.size());
      assertTrue(CellUtil.matchingQualifier(r.rawCells()[0], COLUMN1));
      assertEquals("compare row values between two tables",
            t1.getDescriptor().getValue("row" + i),
            t2.getDescriptor().getValue("row" + i));
    }

    assertEquals("compare count of mob rows after table copy", MobTestUtil.countMobRows(t1),
            MobTestUtil.countMobRows(t2));
    assertEquals("compare count of mob row values between two tables",
            t1.getDescriptor().getValues().size(),
            t2.getDescriptor().getValues().size());
    assertTrue("The mob row count is 0 but should be > 0",
            MobTestUtil.countMobRows(t2) > 0);
  } finally {
    TEST_UTIL.deleteTable(tableName1);
    TEST_UTIL.deleteTable(tableName2);
  }
}
 
Example 2
Source File: LoadTestTool.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Apply column family options such as Bloom filters, compression, and data
 * block encoding.
 */
protected void applyColumnFamilyOptions(TableName tableName,
    byte[][] columnFamilies) throws IOException {
  try (Connection conn = ConnectionFactory.createConnection(conf);
      Admin admin = conn.getAdmin()) {
    TableDescriptor tableDesc = admin.getDescriptor(tableName);
    LOG.info("Disabling table " + tableName);
    admin.disableTable(tableName);
    for (byte[] cf : columnFamilies) {
      ColumnFamilyDescriptor columnDesc = tableDesc.getColumnFamily(cf);
      boolean isNewCf = columnDesc == null;
      ColumnFamilyDescriptorBuilder columnDescBuilder = isNewCf ?
          ColumnFamilyDescriptorBuilder.newBuilder(cf) :
          ColumnFamilyDescriptorBuilder.newBuilder(columnDesc);
      if (bloomType != null) {
        columnDescBuilder.setBloomFilterType(bloomType);
      }
      if (compressAlgo != null) {
        columnDescBuilder.setCompressionType(compressAlgo);
      }
      if (dataBlockEncodingAlgo != null) {
        columnDescBuilder.setDataBlockEncoding(dataBlockEncodingAlgo);
      }
      if (inMemoryCF) {
        columnDescBuilder.setInMemory(inMemoryCF);
      }
      if (cipher != null) {
        byte[] keyBytes = new byte[cipher.getKeyLength()];
        new SecureRandom().nextBytes(keyBytes);
        columnDescBuilder.setEncryptionType(cipher.getName());
        columnDescBuilder.setEncryptionKey(
            EncryptionUtil.wrapKey(conf,
                User.getCurrent().getShortName(),
                new SecretKeySpec(keyBytes,
                    cipher.getName())));
      }
      if (mobThreshold >= 0) {
        columnDescBuilder.setMobEnabled(true);
        columnDescBuilder.setMobThreshold(mobThreshold);
      }

      if (isNewCf) {
        admin.addColumnFamily(tableName, columnDescBuilder.build());
      } else {
        admin.modifyColumnFamily(tableName, columnDescBuilder.build());
      }
    }
    LOG.info("Enabling table " + tableName);
    admin.enableTable(tableName);
  }
}