hi tiany, 
in cluster, how to save the statementId Map, and how to releases the 
resources corresponding of queryIds , 
i see mysql jdbc when call execute(sql) method , it will 
to implicitlyCloseAllOpenResults ,why not refer to this??
you want the client nested call ?
------------------ ???????? ------------------
??????:&nbsp;"????"<[email protected]&gt;;
????????:&nbsp;2019??11??6??(??????) ????5:13
??????:&nbsp;"dev"<[email protected]&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)" <[email protected]&gt;
&gt; ????????: 2019-11-05 22:53:00 (??????)
&gt; ??????: [email protected]
&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)

Reply via email to