You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@iotdb.apache.org by 田原 <ti...@mails.tsinghua.edu.cn> on 2019/11/06 09:13:47 UTC

Re: (IOTDB-291) Statement close operation may cause the whole connection's resource to be released

Hi,

I have solved the issued by maintaining a ThreadLocal<Map<Long, Set<Long>>> in the TSServiceImpl which is a map (statementId -> all queryIds in that statement).

Every time the statement is closed, all the queryIds in that map should also be closed.
However, when a ResultSet is closed, it only releases the resources corresponding to that queryId.
When the connection is closed, the function closeSession() is invoked, it will release all the resource saved in that session thread.

The PR link is https://github.com/apache/incubator-iotdb/pull/526.


> -----原始邮件-----
> 发件人: "Yuan Tian (Jira)" <ji...@apache.org>
> 发送时间: 2019-11-05 22:53:00 (星期二)
> 收件人: dev@iotdb.apache.org
> 抄送: 
> 主题: [jira] [Created] (IOTDB-291) Statement close operation may cause the whole connection's resource to be released
> 
> Yuan Tian created IOTDB-291:
> -------------------------------
> 
>              Summary: Statement close operation may cause the whole connection's resource to be released
>                  Key: IOTDB-291
>                  URL: https://issues.apache.org/jira/browse/IOTDB-291
>              Project: Apache IoTDB
>           Issue Type: Bug
>             Reporter: Yuan Tian
> 
> 
> The function closeClientOperation() in IoTDBStatement.java invokes the function closeOperation(TSCloseOperationReq) in TSServiceImpl. 
> Because the queryId field in TSCloseOperationReq is set to be -1L, the releaseQueryResource  function will release all the resources  in that connection.
> 
> {code:java}
>   private void closeClientOperation() throws SQLException {
>     try {
>       if (operationHandle != null) {
>         TSCloseOperationReq closeReq = new TSCloseOperationReq(operationHandle, -1);
>         closeReq.setStmtId(stmtId);
>         TSStatus closeResp = client.closeOperation(closeReq);
>         RpcUtils.verifySuccess(closeResp);
>       }
>     } catch (Exception e) {
>       throw new SQLException("Error occurs when closing statement.", e);
>     }
>   }
> {code}
> 
> {code:java}
>   private void releaseQueryResource(TSCloseOperationReq req) throws StorageEngineException {
>     Map<Long, QueryContext> contextMap = contextMapLocal.get();
>     if (contextMap == null) {
>       return;
>     }
>     if (req == null || req.queryId == -1) {
>       // end query for all the query tokens created by current thread
>       for (QueryContext context : contextMap.values()) {
>         QueryResourceManager.getInstance().endQueryForGivenJob(context.getJobId());
>       }
>       contextMapLocal.set(new HashMap<>());
>     } else {
>       QueryResourceManager.getInstance()
>           .endQueryForGivenJob(contextMap.remove(req.queryId).getJobId());
>     }
>   }
> {code}
> 
> 
> 
> 
> --
> This message was sent by Atlassian Jira
> (v8.3.4#803005)

Re: (IOTDB-291) Statement close operation may cause the whole connection's resource to be released

Posted by 田原 <ti...@mails.tsinghua.edu.cn>.
Hi, Liu

You mean at the same time, one statement can only hold one ResultSet in mysql-jdbc?


> -----原始邮件-----
> 发件人: "″ 等灯.等灯`" <li...@vip.qq.com>
> 发送时间: 2019-11-06 17:41:28 (星期三)
> 收件人: dev <de...@iotdb.apache.org>
> 抄送: 
> 主题: 回复: (IOTDB-291) Statement close operation may cause the whole connection's resource to be released
> 
> hi&nbsp;tiany,&nbsp;
> in&nbsp;cluster, how to save the&nbsp;statementId Map, and how to releases the resources corresponding of&nbsp;queryIds ,&nbsp;
> i see mysql jdbc when call execute(sql) method , it will to&nbsp;implicitlyCloseAllOpenResults ,why not&nbsp;refer to this?
> you want the client nested call ?
> ------------------&nbsp;原始邮件&nbsp;------------------
> 发件人:&nbsp;"田原"<tiany19@mails.tsinghua.edu.cn&gt;;
> 发送时间:&nbsp;2019年11月6日(星期三) 下午5:13
> 收件人:&nbsp;"dev"<dev@iotdb.apache.org&gt;;
> 
> 主题:&nbsp;Re: (IOTDB-291) Statement close operation may cause the whole connection's resource to be released
> 
> 
> 
> Hi,
> 
> I have solved the issued by maintaining a ThreadLocal<Map<Long, Set<Long&gt;&gt;&gt; in the TSServiceImpl which is a map (statementId -&gt; all queryIds in that statement).
> 
> Every time the statement is closed, all the queryIds in that map should also be closed.
> However, when a ResultSet is closed, it only releases the resources corresponding to that queryId.
> When the connection is closed, the function closeSession() is invoked, it will release all the resource saved in that session thread.
> 
> The PR link is https://github.com/apache/incubator-iotdb/pull/526.
> 
> 
> &gt; -----原始邮件-----
> &gt; 发件人: "Yuan Tian (Jira)" <jira@apache.org&gt;
> &gt; 发送时间: 2019-11-05 22:53:00 (星期二)
> &gt; 收件人: dev@iotdb.apache.org
> &gt; 抄送: 
> &gt; 主题: [jira] [Created] (IOTDB-291) Statement close operation may cause the whole connection's resource to be released
> &gt; 
> &gt; Yuan Tian created IOTDB-291:
> &gt; -------------------------------
> &gt; 
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Summary: Statement close operation may cause the whole connection's resource to be released
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Key: IOTDB-291
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL: https://issues.apache.org/jira/browse/IOTDB-291
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Project: Apache IoTDB
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Issue Type: Bug
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Reporter: Yuan Tian
> &gt; 
> &gt; 
> &gt; The function closeClientOperation() in IoTDBStatement.java invokes the function closeOperation(TSCloseOperationReq) in TSServiceImpl. 
> &gt; Because the queryId field in TSCloseOperationReq is set to be -1L, the releaseQueryResource&nbsp; function will release all the resources&nbsp; in that connection.
> &gt; 
> &gt; {code:java}
> &gt;&nbsp;&nbsp; private void closeClientOperation() throws SQLException {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; try {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (operationHandle != null) {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TSCloseOperationReq closeReq = new TSCloseOperationReq(operationHandle, -1);
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; closeReq.setStmtId(stmtId);
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TSStatus closeResp = client.closeOperation(closeReq);
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RpcUtils.verifySuccess(closeResp);
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new SQLException("Error occurs when closing statement.", e);
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; }
> &gt;&nbsp;&nbsp; }
> &gt; {code}
> &gt; 
> &gt; {code:java}
> &gt;&nbsp;&nbsp; private void releaseQueryResource(TSCloseOperationReq req) throws StorageEngineException {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; Map<Long, QueryContext&gt; contextMap = contextMapLocal.get();
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; if (contextMap == null) {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; }
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; if (req == null || req.queryId == -1) {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // end query for all the query tokens created by current thread
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (QueryContext context : contextMap.values()) {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QueryResourceManager.getInstance().endQueryForGivenJob(context.getJobId());
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contextMapLocal.set(new HashMap<&gt;());
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; } else {
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QueryResourceManager.getInstance()
> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endQueryForGivenJob(contextMap.remove(req.queryId).getJobId());
> &gt;&nbsp;&nbsp;&nbsp;&nbsp; }
> &gt;&nbsp;&nbsp; }
> &gt; {code}
> &gt; 
> &gt; 
> &gt; 
> &gt; 
> &gt; --
> &gt; This message was sent by Atlassian Jira
> &gt; (v8.3.4#803005)

回复: (IOTDB-291) Statement close operation may cause the whole connection's resource to be released

Posted by "″ 等灯.等灯`" <li...@vip.qq.com>.
hi&nbsp;tiany,&nbsp;
in&nbsp;cluster, how to save the&nbsp;statementId Map, and how to releases the resources corresponding of&nbsp;queryIds ,&nbsp;
i see mysql jdbc when call execute(sql) method , it will to&nbsp;implicitlyCloseAllOpenResults ,why not&nbsp;refer to this?
you want the client nested call ?
------------------&nbsp;原始邮件&nbsp;------------------
发件人:&nbsp;"田原"<tiany19@mails.tsinghua.edu.cn&gt;;
发送时间:&nbsp;2019年11月6日(星期三) 下午5:13
收件人:&nbsp;"dev"<dev@iotdb.apache.org&gt;;

主题:&nbsp;Re: (IOTDB-291) Statement close operation may cause the whole connection's resource to be released



Hi,

I have solved the issued by maintaining a ThreadLocal<Map<Long, Set<Long&gt;&gt;&gt; in the TSServiceImpl which is a map (statementId -&gt; all queryIds in that statement).

Every time the statement is closed, all the queryIds in that map should also be closed.
However, when a ResultSet is closed, it only releases the resources corresponding to that queryId.
When the connection is closed, the function closeSession() is invoked, it will release all the resource saved in that session thread.

The PR link is https://github.com/apache/incubator-iotdb/pull/526.


&gt; -----原始邮件-----
&gt; 发件人: "Yuan Tian (Jira)" <jira@apache.org&gt;
&gt; 发送时间: 2019-11-05 22:53:00 (星期二)
&gt; 收件人: dev@iotdb.apache.org
&gt; 抄送: 
&gt; 主题: [jira] [Created] (IOTDB-291) Statement close operation may cause the whole connection's resource to be released
&gt; 
&gt; Yuan Tian created IOTDB-291:
&gt; -------------------------------
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Summary: Statement close operation may cause the whole connection's resource to be released
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Key: IOTDB-291
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL: https://issues.apache.org/jira/browse/IOTDB-291
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Project: Apache IoTDB
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Issue Type: Bug
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Reporter: Yuan Tian
&gt; 
&gt; 
&gt; The function closeClientOperation() in IoTDBStatement.java invokes the function closeOperation(TSCloseOperationReq) in TSServiceImpl. 
&gt; Because the queryId field in TSCloseOperationReq is set to be -1L, the releaseQueryResource&nbsp; function will release all the resources&nbsp; in that connection.
&gt; 
&gt; {code:java}
&gt;&nbsp;&nbsp; private void closeClientOperation() throws SQLException {
&gt;&nbsp;&nbsp;&nbsp;&nbsp; try {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (operationHandle != null) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TSCloseOperationReq closeReq = new TSCloseOperationReq(operationHandle, -1);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; closeReq.setStmtId(stmtId);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TSStatus closeResp = client.closeOperation(closeReq);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RpcUtils.verifySuccess(closeResp);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&gt;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new SQLException("Error occurs when closing statement.", e);
&gt;&nbsp;&nbsp;&nbsp;&nbsp; }
&gt;&nbsp;&nbsp; }
&gt; {code}
&gt; 
&gt; {code:java}
&gt;&nbsp;&nbsp; private void releaseQueryResource(TSCloseOperationReq req) throws StorageEngineException {
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Map<Long, QueryContext&gt; contextMap = contextMapLocal.get();
&gt;&nbsp;&nbsp;&nbsp;&nbsp; if (contextMap == null) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;
&gt;&nbsp;&nbsp;&nbsp;&nbsp; }
&gt;&nbsp;&nbsp;&nbsp;&nbsp; if (req == null || req.queryId == -1) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // end query for all the query tokens created by current thread
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (QueryContext context : contextMap.values()) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QueryResourceManager.getInstance().endQueryForGivenJob(context.getJobId());
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contextMapLocal.set(new HashMap<&gt;());
&gt;&nbsp;&nbsp;&nbsp;&nbsp; } else {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QueryResourceManager.getInstance()
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .endQueryForGivenJob(contextMap.remove(req.queryId).getJobId());
&gt;&nbsp;&nbsp;&nbsp;&nbsp; }
&gt;&nbsp;&nbsp; }
&gt; {code}
&gt; 
&gt; 
&gt; 
&gt; 
&gt; --
&gt; This message was sent by Atlassian Jira
&gt; (v8.3.4#803005)