Source:
<code>private int rebuildIndexes(Connection conn, String dataTable, IndexTool indexingTool) { for(Map.Entry<String, IndexInfo> indexMap : rebuildMap.get(dataTable).entrySet()) { String index = indexMap.getKey(); IndexInfo indexInfo = indexMap.getValue(); String indexName = SchemaUtil.getTableNameFromFullName(index); String tenantId = indexInfo.getTenantId(); String baseTable = indexInfo.getBaseTable(); String schema = indexInfo.getSchemaName(); String outFile = "/tmp/index_rebuild_" +schema+"_"+ indexName + (GLOBAL_INDEX_ID.equals(tenantId)?"":"_"+tenantId) +"_" + UUID.randomUUID().toString(); String[] args = getIndexToolArgValues(schema, baseTable, indexName, outFile, tenantId); try { LOGGER.info("Rebuilding index: " + String.join(",", args)); if (!dryRun) { String stmt = String.format("ALTER INDEX %s ON %s REBUILD ASYNC", indexName, SchemaUtil.getTableName(schema, baseTable)); try { conn.createStatement().execute(stmt); } catch (SQLException ex) { <START> LOGGER.warning("Something went wrong while running ALTER REBUILD ASYNC the index " <END> + index + " " + ex); } indexingTool.run(args); } } catch (Exception e) { LOGGER.severe("Something went wrong while building the index " + index + " " + e); return -1; } } return 0; }</code><technical_language>nit: "ASYNC index "</technical_language>

Target:
private int rebuildIndexes(Connection conn, String dataTable, IndexTool indexingTool) { for(Map.Entry<String, IndexInfo> indexMap : rebuildMap.get(dataTable).entrySet()) { String index = indexMap.getKey(); IndexInfo indexInfo = indexMap.getValue(); String indexName = SchemaUtil.getTableNameFromFullName(index); String tenantId = indexInfo.getTenantId(); String baseTable = indexInfo.getBaseTable(); String schema = indexInfo.getSchemaName(); String outFile = "/tmp/index_rebuild_" +schema+"_"+ indexName + (GLOBAL_INDEX_ID.equals(tenantId)?"":"_"+tenantId) +"_" + UUID.randomUUID().toString(); String[] args = getIndexToolArgValues(schema, baseTable, indexName, outFile, tenantId); Connection newConnection = conn; Connection tenantConnection = null; try { LOGGER.info("Rebuilding index: " + String.join(",", args)); if (!dryRun) { if (!Strings.isNullOrEmpty(tenantId) && !GLOBAL_INDEX_ID.equals(tenantId)) { Configuration conf = HBaseConfiguration.addHbaseResources(getConf()); conf.set(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); newConnection = ConnectionUtil.getInputConnection(conf); tenantConnection = newConnection; } PTable indexPTable = PhoenixRuntime.getTable(newConnection, indexInfo.getPhysicalIndexTableName()); if (indexPTable.getIndexState() == PIndexState.DISABLE) { String dataTableFullName = dataTable; if (!dataTableFullName.contains(":") && !dataTableFullName.contains(".")) { dataTableFullName = SchemaUtil.getTableName(schema, dataTable); } String stmt = String.format("ALTER INDEX %s ON %s REBUILD ASYNC", indexName, dataTableFullName); newConnection.createStatement().execute(stmt); } indexingTool.run(args); } } catch (Exception e) { LOGGER.severe("Something went wrong while building the index " + index + " " + e); return -1; } finally { try { if (tenantConnection != null) { tenantConnection.close(); } } catch (SQLException e) { LOGGER.warning("Couldn't close tenant connection. Ignoring"); } } } return 0; }