/** * Modify an existing column family on a table. Synchronous operation. * Use {@link #modifyColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it * returns a {@link Future} from which you can learn whether success or failure. * @param tableName name of table * @param columnFamily new column family descriptor to use * @throws IOException if a remote or network exception occurs * @deprecated As of release 2.0.0. * This will be removed in HBase 3.0.0. * Use {@link #modifyColumnFamily(TableName, ColumnFamilyDescriptor)}. */ @Deprecated default void modifyColumn(TableName tableName, ColumnFamilyDescriptor columnFamily) throws IOException { modifyColumnFamily(tableName, columnFamily); }
@Override public void modifyColumnFamily(TTableName tableName, TColumnFamilyDescriptor column) throws TIOError, TException { try { TableName table = tableNameFromThrift(tableName); ColumnFamilyDescriptor columnFamilyDescriptor = columnFamilyDescriptorFromThrift(column); connectionCache.getAdmin().modifyColumnFamily(table, columnFamilyDescriptor); } catch (IOException e) { throw getTIOError(e); } }
admin.modifyColumnFamily(name, hcd); } else { admin.addColumnFamily(name, hcd);
private void modifyColumnExpiryDays(int expireDays) throws Exception { HColumnDescriptor hcd = new HColumnDescriptor(family); hcd.setMobEnabled(true); hcd.setMobThreshold(3L); // change ttl as expire days to make some row expired int timeToLive = expireDays * secondsOfDay(); hcd.setTimeToLive(timeToLive); admin.modifyColumnFamily(tableName, hcd); }
@Test public void testReadExpiredDataForRawScan() throws IOException { TableName tableName = TableName.valueOf(name.getMethodName()); long ts = System.currentTimeMillis() - 10000; byte[] value = Bytes.toBytes("expired"); try (Table table = TEST_UTIL.createTable(tableName, FAMILY)) { table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, ts, value)); assertArrayEquals(value, table.get(new Get(ROW)).getValue(FAMILY, QUALIFIER)); TEST_UTIL.getAdmin().modifyColumnFamily(tableName, new HColumnDescriptor(FAMILY).setTimeToLive(5)); try (ResultScanner scanner = table.getScanner(FAMILY)) { assertNull(scanner.next()); } try (ResultScanner scanner = table.getScanner(new Scan().setRaw(true))) { assertArrayEquals(value, scanner.next().getValue(FAMILY, QUALIFIER)); assertNull(scanner.next()); } } }
private void createTableIfMissing(Admin admin, boolean useMob) throws IOException { if (!admin.tableExists(TABLE_NAME)) { TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLE_NAME); Stream.of(FAMILIES).map(ColumnFamilyDescriptorBuilder::of) .forEachOrdered(builder::setColumnFamily); admin.createTable(builder.build()); } ColumnFamilyDescriptor cfd = admin.getDescriptor(TABLE_NAME).getColumnFamilies()[0]; if (cfd.isMobEnabled() != useMob) { admin.modifyColumnFamily(TABLE_NAME, ColumnFamilyDescriptorBuilder.newBuilder(cfd) .setMobEnabled(useMob).setMobThreshold(4).build()); } }
@Test public void testModifyNonExistingColumnFamily() throws IOException { Admin admin = TEST_UTIL.getAdmin(); HColumnDescriptor cfDescriptor = new HColumnDescriptor(FAMILY_1); int blockSize = cfDescriptor.getBlocksize(); // Create a table with one families HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME); baseHtd.addFamily(new HColumnDescriptor(FAMILY_0)); admin.createTable(baseHtd); admin.disableTable(TABLE_NAME); try { // Verify the table descriptor verifyTableDescriptor(TABLE_NAME, FAMILY_0); int newBlockSize = 2 * blockSize; cfDescriptor.setBlocksize(newBlockSize); // Modify a column family that is not in the table. try { admin.modifyColumnFamily(TABLE_NAME, cfDescriptor); Assert.fail("Modify a non-exist column family should fail"); } catch (InvalidFamilyOperationException e) { // Expected. } } finally { admin.deleteTable(TABLE_NAME); } }
private void setEncodingConf(DataBlockEncoding encoding, boolean onlineChange) throws Exception { LOG.debug("Setting CF encoding to " + encoding + " (ordinal=" + encoding.ordinal() + "), onlineChange=" + onlineChange); hcd.setDataBlockEncoding(encoding); try (Admin admin = TEST_UTIL.getConnection().getAdmin()) { if (!onlineChange) { admin.disableTable(tableName); } admin.modifyColumnFamily(tableName, hcd); if (!onlineChange) { admin.enableTable(tableName); } } // This is a unit test, not integration test. So let's // wait for regions out of transition. Otherwise, for online // encoding change, verification phase may be flaky because // regions could be still in transition. TEST_UTIL.waitUntilNoRegionsInTransition(TIMEOUT_MS); }
HColumnDescriptor hcd = new HColumnDescriptor(VisibilityConstants.LABELS_TABLE_FAMILY); hcd.setBloomFilterType(BloomType.ROWCOL); admin.modifyColumnFamily(LABELS_TABLE_NAME, hcd); fail("Lables table should not get altered by user."); } catch (Exception e) {
this.admin.modifyColumnFamily(nonexistentTable, nonexistentHcd); } catch (IOException e) { exception = e; this.admin.modifyColumnFamily(htd.getTableName(), nonexistentHcd); } catch (IOException e) { exception = e;
@Test public void testModifyColumnFamily() throws IOException { Admin admin = TEST_UTIL.getAdmin(); HColumnDescriptor cfDescriptor = new HColumnDescriptor(FAMILY_0); int blockSize = cfDescriptor.getBlocksize(); // Create a table with one families HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME); baseHtd.addFamily(cfDescriptor); admin.createTable(baseHtd); admin.disableTable(TABLE_NAME); try { // Verify the table descriptor verifyTableDescriptor(TABLE_NAME, FAMILY_0); int newBlockSize = 2 * blockSize; cfDescriptor.setBlocksize(newBlockSize); // Modify colymn family admin.modifyColumnFamily(TABLE_NAME, cfDescriptor); HTableDescriptor htd = admin.getTableDescriptor(TABLE_NAME); HColumnDescriptor hcfd = htd.getFamily(FAMILY_0); assertTrue(hcfd.getBlocksize() == newBlockSize); } finally { admin.deleteTable(TABLE_NAME); } }
/** * Modify an existing column family on a table. Synchronous operation. * Use {@link #modifyColumnFamilyAsync(TableName, ColumnFamilyDescriptor)} instead because it * returns a {@link Future} from which you can learn whether success or failure. * @param tableName name of table * @param columnFamily new column family descriptor to use * @throws IOException if a remote or network exception occurs * @deprecated As of release 2.0.0. * This will be removed in HBase 3.0.0. * Use {@link #modifyColumnFamily(TableName, ColumnFamilyDescriptor)}. */ @Deprecated default void modifyColumn(TableName tableName, ColumnFamilyDescriptor columnFamily) throws IOException { modifyColumnFamily(tableName, columnFamily); }
@Override @Test public void loadTest() throws Exception { Admin admin = TEST_UTIL.getAdmin(); compression = Compression.Algorithm.GZ; // used for table setup super.loadTest(); HColumnDescriptor hcd = getColumnDesc(admin); System.err.println("\nDisabling encode-on-disk. Old column descriptor: " + hcd + "\n"); Table t = TEST_UTIL.getConnection().getTable(TABLE); assertAllOnLine(t); admin.disableTable(TABLE); admin.modifyColumnFamily(TABLE, hcd); System.err.println("\nRe-enabling table\n"); admin.enableTable(TABLE); System.err.println("\nNew column descriptor: " + getColumnDesc(admin) + "\n"); // The table may not have all regions on line yet. Assert online before // moving to major compact. assertAllOnLine(t); System.err.println("\nCompacting the table\n"); admin.majorCompact(TABLE); // Wait until compaction completes Threads.sleepWithoutInterrupt(5000); HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0); while (rs.compactSplitThread.getCompactionQueueSize() > 0) { Threads.sleep(50); } System.err.println("\nDone with the test, shutting down the cluster\n"); }
@Override protected void initTable() throws IOException { super.initTable(); TableName tableName = getTablename(); try (Connection connection = ConnectionFactory.createConnection(); Admin admin = connection.getAdmin()) { HTableDescriptor tableDesc = admin.getTableDescriptor(tableName); LOG.info("Disabling table " + getTablename()); admin.disableTable(tableName); ColumnFamilyDescriptor mobColumn = tableDesc.getColumnFamily(mobColumnFamily); ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(mobColumn) .setMobEnabled(true) .setMobThreshold((long) threshold) .build(); admin.modifyColumnFamily(tableName, cfd); LOG.info("Enabling table " + getTablename()); admin.enableTable(tableName); } }
admin.modifyColumnFamily(TABLE_NAME, hcdA); while (TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager(). getRegionStates().hasRegionsInTransition()) { admin.modifyColumnFamily(TABLE_NAME, hcdB); while (TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates() .hasRegionsInTransition()) {
conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, User.getCurrent().getShortName()), secondCFKey)); TEST_UTIL.getAdmin().modifyColumnFamily(htd.getTableName(), hcd); Thread.sleep(5000); // Need a predicate for online schema change
admin.addColumnFamily(tableName, columnDescBuilder.build()); } else { admin.modifyColumnFamily(tableName, columnDescBuilder.build());
@Before @Override public void setUp() throws Exception { // Initialize the cluster. This invokes LoadTestTool -init_only, which // will create the test table, appropriately pre-split super.setUp(); if (!initialized) { return; } // Update the test table schema so HFiles from this point will be written with // encryption features enabled. final Admin admin = util.getAdmin(); TableDescriptor tableDescriptor = admin.getDescriptor(getTablename()); for (ColumnFamilyDescriptor columnDescriptor : tableDescriptor.getColumnFamilies()) { ColumnFamilyDescriptor updatedColumn = ColumnFamilyDescriptorBuilder .newBuilder(columnDescriptor).setEncryptionType("AES").build(); LOG.info( "Updating CF schema for " + getTablename() + "." + columnDescriptor.getNameAsString()); admin.disableTable(getTablename()); admin.modifyColumnFamily(getTablename(), updatedColumn); admin.enableTable(getTablename()); util.waitFor(30000, 1000, true, new Predicate<IOException>() { @Override public boolean evaluate() throws IOException { return admin.isTableAvailable(getTablename()); } }); } }
expectedException = false; try { this.admin.modifyColumnFamily(tableName, hcd); } catch (TableNotDisabledException re) { expectedException = true;
.newBuilder(familyA); familyABuilder.setInMemory(true); admin.modifyColumnFamily(tableDescriptor.getTableName(), familyABuilder.build());