Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOTDB-538]add a simple connection pool for session api #880

Merged
merged 9 commits into from Mar 14, 2020

Conversation

jixuan1989
Copy link
Member

Well, I think the pool is more easy to use than the description in IOTDB-538.

We provided a connection pool (`SessionPool) for Native API.
Using the interface, you need to define the pool size.
If you can not get a session connection in 60 secondes, there is a warning log but the program will hang.
If a session has finished an operation, it will be put back to the pool automatically.
If a session connection is broken, the session will be removed automatically and the pool will try
to create a new session and redo the operation.
For query operations:

  1. When using SessionPool to query data, the result set is SessionDataSetWrapper;
  2. Given a SessionDataSetWrapper, if you have not scanned all the data in it and stop to use it,
    you have to call SessionPool.closeResultSet(wrapper) manually;
  3. When you call hasNext() and next() of a SessionDataSetWrapper and there is an exception, then
    you have to call SessionPool.closeResultSet(wrapper) manually;
    Examples: session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java

@jixuan1989
Copy link
Member Author

I need to add a new api to enable user closing a SessionPool.

}
}
if (logger.isDebugEnabled()) {
logger.error("Create a new Session {}, {}, {}, {}", ip, port, user, password);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the password be printed?

*
* @param rowBatch data batch
*/
public TSExecuteBatchStatementResp insertSortedBatch(RowBatch rowBatch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed to export the methods of Session in this Pool? the codes are double...

Copy link
Member Author

@jixuan1989 jixuan1989 Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the codes are double...

Ah?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the interfaces are double...

return resp;
} catch (IoTDBSessionException e) {
if (e.getCause() instanceof TException) {
// TException means the connection is broken, remove it and get a new one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get a new one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix.

@jixuan1989
Copy link
Member Author

The attachment is a patch for v0.9.1.
just use git apply --check THE FILE to check it is ok and then use git apply THE FILE to use it.
session_pool_0.9.1.patch.txt

@sonarcloud
Copy link

sonarcloud bot commented Mar 14, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 5 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@qiaojialin
Copy link
Member

The Session pool is already merged into rel/0.9 branch. If you want to use it in 0.9.x, rel/0.9 branch is the best choice

@qiaojialin qiaojialin merged commit f9fd91f into master Mar 14, 2020
@qiaojialin qiaojialin deleted the simple_pool branch March 14, 2020 05:18
@jixuan1989 jixuan1989 restored the simple_pool branch March 14, 2020 07:45
@jixuan1989 jixuan1989 deleted the simple_pool branch March 14, 2020 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants