HBASE-7782 HBaseTestingUtility.truncateTable() not acting like CLI (Sean Busbey)
This commit is contained in:
parent
906fafe93d
commit
aada70053b
|
@ -1664,22 +1664,24 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide an existing table name to truncate
|
* Provide an existing table name to truncate.
|
||||||
|
* Scans the table and issues a delete for each row read.
|
||||||
* @param tableName existing table
|
* @param tableName existing table
|
||||||
* @return HTable to that new table
|
* @return HTable to that new table
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public HTable truncateTable(byte[] tableName) throws IOException {
|
public HTable deleteTableData(byte[] tableName) throws IOException {
|
||||||
return truncateTable(TableName.valueOf(tableName));
|
return deleteTableData(TableName.valueOf(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide an existing table name to truncate
|
* Provide an existing table name to truncate.
|
||||||
|
* Scans the table and issues a delete for each row read.
|
||||||
* @param tableName existing table
|
* @param tableName existing table
|
||||||
* @return HTable to that new table
|
* @return HTable to that new table
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public HTable truncateTable(TableName tableName) throws IOException {
|
public HTable deleteTableData(TableName tableName) throws IOException {
|
||||||
HTable table = new HTable(getConfiguration(), tableName);
|
HTable table = new HTable(getConfiguration(), tableName);
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
ResultScanner resScan = table.getScanner(scan);
|
ResultScanner resScan = table.getScanner(scan);
|
||||||
|
@ -1692,6 +1694,56 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate a table using the admin command.
|
||||||
|
* Effectively disables, deletes, and recreates the table.
|
||||||
|
* @param tableName table which must exist.
|
||||||
|
* @param preserveRegions keep the existing split points
|
||||||
|
* @return HTable for the new table
|
||||||
|
*/
|
||||||
|
public HTable truncateTable(final TableName tableName, final boolean preserveRegions) throws IOException {
|
||||||
|
Admin admin = getHBaseAdmin();
|
||||||
|
admin.truncateTable(tableName, preserveRegions);
|
||||||
|
return new HTable(getConfiguration(), tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate a table using the admin command.
|
||||||
|
* Effectively disables, deletes, and recreates the table.
|
||||||
|
* For previous behavior of issuing row deletes, see
|
||||||
|
* deleteTableData.
|
||||||
|
* Expressly does not preserve regions of existing table.
|
||||||
|
* @param tableName table which must exist.
|
||||||
|
* @return HTable for the new table
|
||||||
|
*/
|
||||||
|
public HTable truncateTable(final TableName tableName) throws IOException {
|
||||||
|
return truncateTable(tableName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate a table using the admin command.
|
||||||
|
* Effectively disables, deletes, and recreates the table.
|
||||||
|
* @param tableName table which must exist.
|
||||||
|
* @param preserveRegions keep the existing split points
|
||||||
|
* @return HTable for the new table
|
||||||
|
*/
|
||||||
|
public HTable truncateTable(final byte[] tableName, final boolean preserveRegions) throws IOException {
|
||||||
|
return truncateTable(TableName.valueOf(tableName), preserveRegions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate a table using the admin command.
|
||||||
|
* Effectively disables, deletes, and recreates the table.
|
||||||
|
* For previous behavior of issuing row deletes, see
|
||||||
|
* deleteTableData.
|
||||||
|
* Expressly does not preserve regions of existing table.
|
||||||
|
* @param tableName table which must exist.
|
||||||
|
* @return HTable for the new table
|
||||||
|
*/
|
||||||
|
public HTable truncateTable(final byte[] tableName) throws IOException {
|
||||||
|
return truncateTable(tableName, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load table with rows from 'aaa' to 'zzz'.
|
* Load table with rows from 'aaa' to 'zzz'.
|
||||||
* @param t Table
|
* @param t Table
|
||||||
|
|
|
@ -61,9 +61,9 @@ public class TestReplicationChangingPeerRegionservers extends TestReplicationBas
|
||||||
utility1.getHBaseCluster().getRegionServerThreads()) {
|
utility1.getHBaseCluster().getRegionServerThreads()) {
|
||||||
r.getRegionServer().getWAL().rollWriter();
|
r.getRegionServer().getWAL().rollWriter();
|
||||||
}
|
}
|
||||||
utility1.truncateTable(tableName);
|
utility1.deleteTableData(tableName);
|
||||||
// truncating the table will send one Delete per row to the slave cluster
|
// truncating the table will send one Delete per row to the slave cluster
|
||||||
// in an async fashion, which is why we cannot just call truncateTable on
|
// in an async fashion, which is why we cannot just call deleteTableData on
|
||||||
// utility2 since late writes could make it to the slave in some way.
|
// utility2 since late writes could make it to the slave in some way.
|
||||||
// Instead, we truncate the first table and wait for all the Deletes to
|
// Instead, we truncate the first table and wait for all the Deletes to
|
||||||
// make it to the slave.
|
// make it to the slave.
|
||||||
|
|
|
@ -75,9 +75,9 @@ public class TestReplicationSmallTests extends TestReplicationBase {
|
||||||
utility1.getHBaseCluster().getRegionServerThreads()) {
|
utility1.getHBaseCluster().getRegionServerThreads()) {
|
||||||
r.getRegionServer().getWAL().rollWriter();
|
r.getRegionServer().getWAL().rollWriter();
|
||||||
}
|
}
|
||||||
utility1.truncateTable(tableName);
|
utility1.deleteTableData(tableName);
|
||||||
// truncating the table will send one Delete per row to the slave cluster
|
// truncating the table will send one Delete per row to the slave cluster
|
||||||
// in an async fashion, which is why we cannot just call truncateTable on
|
// in an async fashion, which is why we cannot just call deleteTableData on
|
||||||
// utility2 since late writes could make it to the slave in some way.
|
// utility2 since late writes could make it to the slave in some way.
|
||||||
// Instead, we truncate the first table and wait for all the Deletes to
|
// Instead, we truncate the first table and wait for all the Deletes to
|
||||||
// make it to the slave.
|
// make it to the slave.
|
||||||
|
|
|
@ -117,8 +117,8 @@ public class TestReplicationSink {
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
table1 = TEST_UTIL.truncateTable(TABLE_NAME1);
|
table1 = TEST_UTIL.deleteTableData(TABLE_NAME1);
|
||||||
table2 = TEST_UTIL.truncateTable(TABLE_NAME2);
|
table2 = TEST_UTIL.deleteTableData(TABLE_NAME2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue