-
Notifications
You must be signed in to change notification settings - Fork 121
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
NebulaGraph Sessionpool #474
Conversation
Codecov ReportBase: 63.38% // Head: 62.94% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #474 +/- ##
============================================
- Coverage 63.38% 62.94% -0.44%
- Complexity 729 778 +49
============================================
Files 66 71 +5
Lines 3479 3735 +256
Branches 507 536 +29
============================================
+ Hits 2205 2351 +146
- Misses 928 1015 +87
- Partials 346 369 +23
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
521f794
to
13ff18c
Compare
b8772af
to
0f6b674
Compare
client/src/main/java/com/vesoft/nebula/client/graph/SessionPoolConfig.java
Outdated
Show resolved
Hide resolved
client/src/main/java/com/vesoft/nebula/client/graph/SessionPoolConfig.java
Outdated
Show resolved
Hide resolved
client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java
Outdated
Show resolved
Hide resolved
client/src/main/java/com/vesoft/nebula/client/graph/SessionPool.java
Outdated
Show resolved
Hide resolved
client/src/main/java/com/vesoft/nebula/client/graph/SessionPoolConfig.java
Outdated
Show resolved
Hide resolved
} | ||
} | ||
// if session size is less than max size, get session from pool | ||
if (sessionList.size() < maxSessionSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看没加锁,如果并发走到这里的话,可能会超过最大个数吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's lock on the getSession
method, so it's impossible to get here concurrently.
*/ | ||
private synchronized NebulaSession getSession() throws ClientServerIncompatibleException, | ||
AuthFailedException, IOErrorException, BindSpaceFailedException { | ||
int retry = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请教下哈:这里的retry ,没看到哪里把他设置成0呢,有啥用?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请教下哈:这里的retry ,没看到哪里把他设置成0呢,有啥用?
retry-- : use the value of retry first, then retry minus 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的while (retry-- > 0) 是不是只循环了一次,并没有在sleep之后re-get
useSpace(nebulaSession, null); | ||
throw e; | ||
} | ||
useSpace(nebulaSession, resultSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useSpace 不用放在final里面么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only when the code in try{}
throws IOErrorException, we need to execute useSpace
to release the session.
If it throws AuthFailedException, it means the session is not create successfully.
|
||
// test USE SPACE | ||
try { | ||
sessionPool.execute("USE TEST_USE_SPACE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USE TEST_USE_SPACE这里,可以一个语句中执行多个use space么?比如:
USE SPACE1 xxx;USE SPACE2 xxx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code didn't check this case, so this statement will be executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想到一种情况哈,如果用户没有这个space的权限,当前内核返回的错误信息能处理吧?--安琪反馈,会在result set中返回
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USE SPACE1 xxx;USE SPACE2 xxx
如果第一个语句报错,第二个语句自动阻塞,不会执行了对吧? 是内核处理的;已验证会报 SpaceNotFound
// NebulaPool init failed | ||
List<HostAddress> addresses = Arrays.asList(new HostAddress(ip, 1000)); | ||
SessionPoolConfig config = | ||
new SessionPoolConfig(addresses, "space", "user", "12345"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个失败原因是端口号错误么? 注释中可以明确下不?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'll add some comments, thanks for your suggestions.
assert (!sessionPool.init()); | ||
sessionPool.close(); | ||
|
||
// set MinSessionSize 0, and init will return true even if the user is wrong |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释是不是要删掉或改一下?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
|
||
// set MinSessionSize 0, and init will return true even if the user is wrong | ||
config = new SessionPoolConfig(addresses, "space", "user", "nebula") | ||
.setMinSessionSize(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最小线程池,如果允许设置成0的话,就说允许session是无效的对吧?貌似也可以
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是按我们最后定的设计来吧
client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java
Show resolved
Hide resolved
client/src/test/java/com/vesoft/nebula/client/graph/net/TestSessionPool.java
Show resolved
Hide resolved
return; | ||
} | ||
} | ||
releaseSession(nebulaSession); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看明白了:
releaseSession是放回去;
nebulaSession.release();是销毁session pool;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nebulaSession.release() is signout.
|
||
// test USE SPACE | ||
try { | ||
sessionPool.execute("USE TEST_USE_SPACE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想到一种情况哈,如果用户没有这个space的权限,当前内核返回的错误信息能处理吧?--安琪反馈,会在result set中返回
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
*/ | ||
private synchronized NebulaSession getSession() throws ClientServerIncompatibleException, | ||
AuthFailedException, IOErrorException, BindSpaceFailedException { | ||
int retry = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的while (retry-- > 0) 是不是只循环了一次,并没有在sleep之后re-get
|
||
NebulaSession nebulaSession = new NebulaSession(connection, authResult.getSessionId(), | ||
authResult.getTimezoneOffset(), state); | ||
ResultSet result = nebulaSession.execute("USE " + spaceName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"USE " + spaceName 需要加上反引号 `` 么,确保包含特殊字符的spaceName不会报错
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"USE " + spaceName 需要加上反引号 `` 么,确保包含特殊字符的spaceName不会报错
是的,感谢提出
resultSet = nebulaSession.executeWithParameter(stmt, parameterMap); | ||
|
||
// re-execute for session error | ||
if (isSessionError(resultSet)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果stmt包含多个执行语句,由于没有事物,其中部分执行成功,部分失败,这里re-execute再次执行会不会造成影响
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果stmt包含多个执行语句,由于没有事物,其中部分执行成功,部分失败,这里re-execute再次执行会不会造成影响
只有发生Session相关的异常才会re-execute,此时语句是没有被执行的
*/ | ||
private void checkSession() { | ||
for (NebulaSession nebulaSession : sessionList) { | ||
if (nebulaSession.isIdle()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有没线程安全的问题呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢提出,pr #479 中将NebulaSession的状态改为AtomicReference 原子变量。
client/src/main/java/com/vesoft/nebula/client/graph/SessionPool.java
Outdated
Show resolved
Hide resolved
@Override | ||
public boolean ping(long sessionID) { | ||
try { | ||
execute(sessionID, "YIELD 1;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the sessionID in invalid, return true or false?
|
||
// re-execute for session error | ||
if (isSessionError(resultSet)) { | ||
sessionList.remove(nebulaSession); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how to drop the connection if the session is invalid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, I'll add session.release.
stmtCheck(stmt); | ||
checkSessionPool(); | ||
NebulaSession nebulaSession = getSession(); | ||
ResultSet resultSet = nebulaSession.getSession().execute(stmt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should try the exception and finally use space
* close the session pool | ||
*/ | ||
public void close() { | ||
if (isClosed.get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it thread safe? i.e. the space is dropped, and two session use space then call use space function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the type of isClosed is thread safe.
/** | ||
* get the number of all Session | ||
*/ | ||
public int getSessionNums() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thread safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the list is thread safe.
throw new IllegalArgumentException("statement is null."); | ||
} | ||
|
||
if (stmt.trim().toLowerCase().startsWith("use") && stmt.trim().split(" ").length == 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use nba
if there're two space, split length is not 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, not judge the use a; use b
No description provided.