[
https://issues.apache.org/jira/browse/PHOENIX-6087?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17223350#comment-17223350
]
ASF GitHub Bot commented on PHOENIX-6087:
-----------------------------------------
yanxinyi commented on a change in pull request #943:
URL: https://github.com/apache/phoenix/pull/943#discussion_r514726107
##########
File path: phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
##########
@@ -1211,36 +1213,56 @@ public static void
addViewIndexToParentLinks(PhoenixConnection oldMetaConnection
String createViewIndexLink = "UPSERT INTO
SYSTEM.CATALOG (TENANT_ID, TABLE_SCHEM, TABLE_NAME, COLUMN_FAMILY, LINK_TYPE)
VALUES (?,?,?,?,?) ";
ResultSet rs =
queryConn.createStatement().executeQuery(indexQuery);
String prevTenantId = null;
- PhoenixConnection metaConn = queryConn;
+ metaConn = queryConn;
Properties props = new Properties(queryConn.getClientInfo());
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
Long.toString(HConstants.LATEST_TIMESTAMP));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
+ Long.toString(HConstants.LATEST_TIMESTAMP));
while (rs.next()) {
- String tenantId = rs.getString("TENANT_ID");
- if (!java.util.Objects.equals(prevTenantId,
tenantId)) {
- prevTenantId = tenantId;
-
props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
- metaConn = new PhoenixConnection(oldMetaConnection,
props);
- }
- String schemaName = rs.getString("TABLE_SCHEM");
- String parentTableName = rs.getString("TABLE_NAME");
- String fullParentTableName =
SchemaUtil.getTableName(schemaName, parentTableName);
- String indexName = rs.getString("COLUMN_FAMILY");
- PTable table = PhoenixRuntime.getTable(metaConn,
fullParentTableName);
- if (table==null) {
- throw new TableNotFoundException(fullParentTableName);
- }
- if (table.getType().equals(PTableType.VIEW)) {
- PreparedStatement prepareStatement =
upsertConn.prepareStatement(createViewIndexLink);
- prepareStatement.setString(1, tenantId);
- prepareStatement.setString(2, schemaName);
- prepareStatement.setString(3, indexName);
- prepareStatement.setString(4, parentTableName);
- prepareStatement.setByte(5,
LinkType.VIEW_INDEX_PARENT_TABLE.getSerializedValue());
- prepareStatement.execute();
- upsertConn.commit();
- }
+ String tenantId = rs.getString("TENANT_ID");
+ if (!java.util.Objects.equals(prevTenantId, tenantId)) {
+ prevTenantId = tenantId;
+ props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB,
tenantId);
+ // guard again queryConn because we don't want to close
+ // queryConn if metaConn was assigned queryConn at
+ // this point
+ if (!isMetaConnUsingQueryConn) {
+ metaConn.close();
+ }
+ metaConn = new PhoenixConnection(oldMetaConnection, props);
+ // now that we have reassigned metaConn, make
+ // isMetaConnUsingQueryConn false so that we make
+ // metaConn eligible for closure
+ isMetaConnUsingQueryConn = false;
+ }
+ String schemaName = rs.getString("TABLE_SCHEM");
Review comment:
please using `PhoenixDatabaseMetaData.TABLE_SCHEM` constant
----------------------------------------------------------------
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]
> Phoenix Connection leak in UpgradeUtil.addViewIndexToParentLinks()
> ------------------------------------------------------------------
>
> Key: PHOENIX-6087
> URL: https://issues.apache.org/jira/browse/PHOENIX-6087
> Project: Phoenix
> Issue Type: Bug
> Affects Versions: 5.0.0, 4.15.0
> Reporter: Chinmay Kulkarni
> Assignee: Viraj Jasani
> Priority: Major
> Labels: phoenix-hardening, quality-improvement
> Fix For: 5.1.0, 4.16.0
>
>
> Inside UpgradeUtil.addViewIndexToParentLinks(), we assign a new Phoenix
> connection to the existing metaConn variable without closing the previous
> cloned tenant connection
> ([here|https://github.com/apache/phoenix/blob/1922895dfe5960dc025709b04acfaf974d3959dc/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java#L1206]).
> We should close the tenant-connection before re-initializing metaConn.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)