-
Notifications
You must be signed in to change notification settings - Fork 8
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
timeout option for the pool:get() #28
Conversation
Please, we need a version with this changes. |
1 similar comment
Please, we need a version with this changes. |
Okay, I’ll look at the week. |
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.
It would be good to add a test. Other then one comment below I have no objections. Please, fix it and then we can push it.
I had tried to do test to emulate connection errors, but it is complicated task for current tests infrastructure. |
483d398
to
f56b2a3
Compare
@mkv We should at least verify work of the pool in usual cases when a pool was drained and we make attempts to receive a connection with and without a timeout. I wrote a test case and found that your implementation would not give Please, look into the new version of the patch and let me know whether are you okay. If you have some external tests (say, within your project), it would be glab if you'll verify that everything works as expected for your cases. |
@Gerold103 I would be grateful if you'll find a time to look into the patch. |
Waiting for @mkv verification. |
How we can restart broken connections in this version of code?
Is it right way? |
It seems it should work, but okay I'll add a test case to ensure. |
Something wrong happenes. |
It seems that "conn.__gc_hook" adds extra connection into queue. |
@mkv While I'm working on that, can you please share a reason why you need to mark a connection as broken manually? Does not automatic reestablished work in your case? If so, what is the case? |
Yes, broken connections does not automatic reestablished. Currently we testing this patch:
Suspending of a fiber on the channel:put is gone. |
@mkv It seems you're step into a problem that was exist before this PR. I'll prepare a test case and a fix. As I see, your fix at least in the right direction. I see that in case of any failed request a connection is marked as broken (either with BTW, I just observed a typo I made in my changes: diff --git a/mysql/init.lua b/mysql/init.lua
index ec6c2e9..235620f 100644
--- a/mysql/init.lua
+++ b/mysql/init.lua
@@ -60,7 +60,7 @@ local function conn_put(conn)
ffi.gc(conn.__gc_hook, nil)
if not conn.queue:get() then
conn.usable = false
- return nil
+ return POOL_EMPTY_SLOT
end
conn.usable = false
return mysqlconn Hope it'll help with testing on your side. |
My initial assumption was not true. There are broken connections (a connection is marked as broken after any failed request) and unusable connections (after explicit :close() or putting back into a pool). If you don't close a connection from a pool (it seems you shouldn't), don't touch private fields like diff --git a/mysql/init.lua b/mysql/init.lua
index 235620f..7e56ed3 100644
--- a/mysql/init.lua
+++ b/mysql/init.lua
@@ -185,7 +185,7 @@ local function pool_close(self)
self.usable = false
for i = 1, self.size do
local mysql_conn = self.queue:get()
- if mysql_conn ~= nil then
+ if mysql_conn ~= POOL_EMPTY_SLOT then
mysql_conn:close()
end
end Don't sure about leaks at the moment. I'll continue looking into that and at least will cover the pool behaviour with appropriate tests in separate PRs. Then I'll update this PR with proper fixes and test cases. Thanks for testing! |
Updated the PR with the proposed fixes for convenience. |
Now I'm more or less organized things for myself. Filed issues about things that looks as subjects to change: #30, #31, #32, #33, #34. Wrote basic test cases for the connection pool: PR #35. Verified that this PR does not break those test cases. The plan is the following: do self-review and push the test cases to master (PR #35), rebase this PR on top of the new master (and squash commits), wait for @mkv for verification on his cases. If everything will be okay, we can finally push this feature. |
Currently we can say that our test is OK. |
Great, thanks! |
d945c3e
to
dd39e2f
Compare
My tests about broken connections do not actually broke connections (#37), so I verified them manually before and after this PR. I added a parse error to the list of non-transitive errors: Lines 149 to 157 in 2d22046
Everything looks okay with this PR. I going to merge it. |
Thank you very much! |
We have to deviler our packages continuosly. This PR was pushed as 2.0-42-g7a63383 and all packages are already in the repository: https://packagecloud.io/app/tarantool/2_3/search?q=2.0.42&filter=all&dist= (The same for 1.10, 2x and 2.2 repos.) However if you're using tarantoolctl rocks / luarocks, then, yep, explicit release is necessary to hold a specific version. It seems it worth to release 2.1. |
@Totktonada Thank you for this link, that`s enough. |
This patch adds timeout option for the pool:get() operation.
It is may be necessary to know when there are no connections at the pool.
E.g. when we lost the server.