BinShi-SecularBird commented on a change in pull request #430: PHOENIX-5091 Add
new features to UpdateStatisticsTool
URL: https://github.com/apache/phoenix/pull/430#discussion_r252089548
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/schema/stats/BaseStatsCollectorIT.java
##########
@@ -207,20 +206,44 @@ private void collectStatistics(Connection conn, String
fullTableName,
}
private void collectStatsOnSnapshot(Connection conn, String fullTableName,
- String guidePostWidth, String
localPhysicalTableName) throws Exception {
- UpdateStatisticsTool tool = new UpdateStatisticsTool();
- Configuration conf = utility.getConfiguration();
- HBaseAdmin admin =
conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
- String snapshotName = "UpdateStatisticsTool_" + generateUniqueName();
- admin.snapshot(snapshotName, localPhysicalTableName);
- LOG.info("Successfully created snapshot " + snapshotName + " for " +
localPhysicalTableName);
- Path randomDir = getUtility().getRandomDir();
+ String guidePostWidth) throws
Exception {
if (guidePostWidth != null) {
conn.createStatement().execute("ALTER TABLE " + fullTableName + "
SET GUIDE_POSTS_WIDTH = " + guidePostWidth);
}
- Job job = tool.configureJob(conf, fullTableName, snapshotName,
randomDir);
- assertEquals(job.getConfiguration().get(MAPREDUCE_JOB_TYPE),
UPDATE_STATS.name());
- tool.runJob(job, true);
+ runUpdateStatisticsTool(fullTableName);
+ }
+
+ // Run UpdateStatisticsTool in foreground with manage snapshot option
+ private void runUpdateStatisticsTool(String fullTableName) {
+ UpdateStatisticsTool tool = new UpdateStatisticsTool();
+ tool.setConf(utility.getConfiguration());
+ String randomDir = getUtility().getRandomDir().toString();
+ final String[] cmdArgs = getArgValues(fullTableName, randomDir);
+ try {
+ int status = tool.run(cmdArgs);
+ assertEquals("MR Job should complete successfully", 0, status);
+ HBaseAdmin hBaseAdmin = utility.getHBaseAdmin();
+ assertEquals("Snapshot should be automatically deleted when
UpdateStatisticsTool has completed",
+ 0,
hBaseAdmin.listSnapshots(tool.getSnapshotName()).size());
+ } catch (Exception e) {
+ fail("Exception when running UpdateStatisticsTool for " +
tableName + " Exception: " + e);
+ } finally {
+ Job job = tool.getJob();
+ assertEquals("MR Job should have been configured with UPDATE_STATS
job type",
Review comment:
Shall we check whether job is null here? Exception could be thrown before
the job being initialized.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services