swaroopak commented on a change in pull request #733: PHOENIX-5732: Implement
starttime, endtime in IndexTool for rebuild a…
URL: https://github.com/apache/phoenix/pull/733#discussion_r395201557
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexTool.java
##########
@@ -801,40 +747,155 @@ public int run(String[] args) throws Exception {
}
} catch (Exception ex) {
LOGGER.error("An exception occurred while performing the indexing
job: "
- + ExceptionUtils.getMessage(ex) + " at:\n" +
ExceptionUtils.getStackTrace(ex));
+ + ExceptionUtils.getMessage(ex) + " at:\n" +
ExceptionUtils.getStackTrace(ex));
return -1;
- } finally {
- boolean rethrowException = false;
- try {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- LOGGER.error("Failed to close connection ", e);
- rethrowException = true;
- }
- }
- if (htable != null) {
- try {
- htable.close();
- } catch (IOException e) {
- LOGGER.error("Failed to close htable ", e);
- rethrowException = true;
- }
- }
- if (jobFactory != null) {
- try {
- jobFactory.closeConnection();
- } catch (SQLException e) {
- LOGGER.error("Failed to close jobFactory ", e);
- rethrowException = true;
- }
- }
- } finally {
- if (rethrowException) {
- throw new RuntimeException("Failed to close resource");
- }
- }
+ }
+ }
+
+ public static void checkTimeRangeFeature(Long startTime, Long endTime,
PTable pDataTable, boolean isLocalIndexBuild) {
+ if (isTimeRangeSet(startTime, endTime) &&
!isTimeRangeFeatureApplicable(pDataTable, isLocalIndexBuild)) {
+ throw new RuntimeException(FEATURE_NOT_APPLICABLE);
+ }
+ }
+
+ private Configuration getConfiguration(String tenantId) {
+ final Configuration configuration =
HBaseConfiguration.addHbaseResources(getConf());
+ if (tenantId != null) {
+ configuration.set(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+ }
+ return configuration;
+ }
+
+ private boolean submitIndexToolJob(Connection conn, Configuration
configuration)
+ throws Exception {
+ Path outputPath = null;
+ FileSystem fs;
+ if (basePath != null) {
+ outputPath =
+ CsvBulkImportUtil.getOutputPath(new Path(basePath),
+ pIndexTable == null ?
+ pDataTable.getPhysicalName().getString() :
+ pIndexTable.getPhysicalName().getString());
+ fs = outputPath.getFileSystem(configuration);
+ fs.delete(outputPath, true);
+ }
+ JobFactory jobFactory = new JobFactory(conn, configuration,
outputPath);
+ job = jobFactory.getJob();
+ if (!isForeground) {
+ LOGGER.info("Running Index Build in Background - Submit async and
exit");
+ job.submit();
+ return true;
+ }
+ LOGGER.info("Running Index Build in Foreground. Waits for the build to
complete."
+ + " This may take a long time!.");
+ return job.waitForCompletion(true);
+ }
+
+ @VisibleForTesting
+ public void populateIndexToolAttributes(CommandLine cmdLine) {
+ boolean useTenantId = cmdLine.hasOption(TENANT_ID_OPTION.getOpt());
+ boolean useStartTime = cmdLine.hasOption(START_TIME_OPTION.getOpt());
+ boolean useEndTime = cmdLine.hasOption(END_TIME_OPTION.getOpt());
+ boolean verify = cmdLine.hasOption(VERIFY_OPTION.getOpt());
+
+ if (useTenantId) {
+ tenantId = cmdLine.getOptionValue(TENANT_ID_OPTION.getOpt());
+ }
+ if(useStartTime) {
+ startTime = new
Long(cmdLine.getOptionValue(START_TIME_OPTION.getOpt()));
+ }
+ if (useEndTime) {
+ endTime = new
Long(cmdLine.getOptionValue(END_TIME_OPTION.getOpt()));
+ }
+ if(isTimeRangeSet(startTime, endTime)) {
+ validateTimeRange();
+ }
+ if (verify) {
+ String value = cmdLine.getOptionValue(VERIFY_OPTION.getOpt());
+ indexVerifyType = IndexVerifyType.fromValue(value);
+ }
+ schemaName = cmdLine.getOptionValue(SCHEMA_NAME_OPTION.getOpt());
+ dataTable = cmdLine.getOptionValue(DATA_TABLE_OPTION.getOpt());
+ indexTable = cmdLine.getOptionValue(INDEX_TABLE_OPTION.getOpt());
+ isPartialBuild = cmdLine.hasOption(PARTIAL_REBUILD_OPTION.getOpt());
+ qDataTable = SchemaUtil.getQualifiedTableName(schemaName, dataTable);
+ basePath = cmdLine.getOptionValue(OUTPUT_PATH_OPTION.getOpt());
+ isForeground = cmdLine.hasOption(RUN_FOREGROUND_OPTION.getOpt());
+ useSnapshot = cmdLine.hasOption(SNAPSHOT_OPTION.getOpt());
+ shouldDeleteBeforeRebuild =
cmdLine.hasOption(DELETE_ALL_AND_REBUILD_OPTION.getOpt());
+ }
+
+ private void validateTimeRange() {
+ Long currentTime = EnvironmentEdgeManager.currentTimeMillis();
+ Long st = (startTime == null) ? 0 : startTime;
+ Long et = (endTime == null) ? currentTime : endTime;
+ if (st.compareTo(currentTime) > 0 || et.compareTo(currentTime) > 0 ||
st.compareTo(et) >= 0) {
+ throw new RuntimeException(INVALID_TIME_RANGE_EXCEPTION_MESSAGE);
+ }
+ }
+
+ private Connection getConnection(Configuration configuration) throws
SQLException {
+ return ConnectionUtil.getInputConnection(configuration);
+ }
+
+ private void setupIndexAndDataTable(Connection connection) throws
SQLException {
+ pDataTable = PhoenixRuntime.getTableNoCache(connection, qDataTable);
+ if (!isValidIndexTable(connection, qDataTable, indexTable, tenantId)) {
+ throw new IllegalArgumentException(
+ String.format(" %s is not an index table for %s for this
connection",
+ indexTable, qDataTable));
+ }
+ pIndexTable = PhoenixRuntime.getTable(connection, schemaName != null
&& !schemaName.isEmpty()
+ ? SchemaUtil.getQualifiedTableName(schemaName, indexTable) :
indexTable);
+ indexType = pIndexTable.getIndexType();
+ if (schemaName != null && !schemaName.isEmpty()) {
+ qIndexTable = SchemaUtil.getQualifiedTableName(schemaName,
indexTable);
+ } else {
+ qIndexTable = indexTable;
+ }
+ if (IndexType.LOCAL.equals(indexType)) {
+ isLocalIndexBuild = true;
Review comment:
This is prevalent in the file. Let's get to this in the next change in the
file.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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