tmysql4 - A multi-connection version of tmysql3 (Now with mysqloo wrapper!)
384 replies, posted
alright i got it, seems that CLIENT_MULTI_STATEMENTS is set on all instances when used, so i have to edit the wrappers and put it in on each one
[QUOTE=vigi8;48951306]tmysql suddenly stopped reacting to db:Query in any way. Callback wasn't called at all.
After trying some simple queries like "select 1+1" and still getting no response, not even an error, i decided to reconnect to database (server was live with players, i had to restore database connection asap). I call db:Disconnect() before attempting new connection and server crashes.
OH COME ON Almost a year passed from [url=https://facepunch.com/showthread.php?t=1441753&p=46726945&viewfull=1#post46726945]this post[/url]! Not only db:Disconnect crash is still there, but now it also randomly stops working!
There is no reason connection could be lost, gmod and sql server are on same machine. And even then, it should error when connection is lost, not just stop responding at all.[/quote]
See this is something I don't understand. What do you actually use Disconnect for? I feel like I should just remove Disconnect because no one actually uses it properly anyway, and all other mysql modules don't have a disconnect method. Can you tell me why you're actually using Disconnect?
Anyway... This might be an issue with the change I made to it auto-reconnecting when a connection is lost. I'll revert this change to the way it was in tmysql3, so hopefully that should fix it.
[QUOTE=vigi8;48951306]Also, in my wrapper, it is not possible for db:Disconnect() to be called twice on the same db object, because variable that holds object is set to nil immediately after calling :Disconnect(). So, when i called :Disconnect() manually, it was first call of this function on this db object. This crash is not even the main issue though, callback not being called is. But these two issues are probably connected anyway.
I can't provide any error IDs because callback wasn't called at all, and i can't do further testing on broken db object because server crashed.[/quote]
If you're able to get it to crash, send me the fucking crash dump.
[QUOTE=Giraffen93;48952398]alright i got it, seems that CLIENT_MULTI_STATEMENTS is set on all instances when used, so i have to edit the wrappers and put it in on each one[/QUOTE]
What?
Crash doesn't even actually matter (yet crashes still shouldn't be possible).
What's important right now is why did it stop responding?
Oh my fucking god. If you're getting it to crash, it's important. SEND ME THE CRASH DUMP. Yes, crashes shouldn't possible, BUT I WOULD LIKE TO FIX IT BUT I CANT IF I CANT SEE WHAT'S CAUSING IT TO CRASH.
I think I know why it's not auto-reconnecting and I will fix it. If you want me to help you, you need to help me.
[QUOTE=BlackAwps;48953065]What?[/QUOTE]
e.g. itemstore has a wrapper, mysqlite (darkrp) has a wrapper, and i have a wrapper
when one of them creates an instance of tmysql, it overrides all the other one's flags too
if i edit the code for all the other wrappers and put the flag on them, multi statements work again
[QUOTE=Giraffen93;48953202]e.g. itemstore has a wrapper, mysqlite (darkrp) has a wrapper, and i have a wrapper
when one of them creates an instance of tmysql, it overrides all the other one's flags too
if i edit the code for all the other wrappers and put the flag on them, multi statements work again[/QUOTE]
[code]tmysql.initialize( String hostname, String username, String password, String database, Number port, String unixSocketPath, Number ClientFlags )[/code]
So if you connect to a server with the same "database" it will just return the same object.
[code]
local DATABASE = tmysql.initialize("localhost", "username", "password", "mydatabase", 12345)
local DATABASE2 = tmysql.initialize("localhost", "username", "password", "mydatabase", 12345, nil, CLIENT_MULTI_STATEMENTS)
print(DATABASE == DATABASE2)
[/code]
That would return true. It's the same exact object. So if your itemstore or darkrp is connecting first without the client flags, then DATABASE2 won't have it's client flags set because it already had a connection to the same database before and is recycling that object for you.
oh okay, makes sense in a way
so no performance improvements of using multiple connections then
Updated the module. Every time you run a query it will check if the server is down and attempt to reconnect before running and parsing the query and results. Hopefully this should fix the issue where a database connection would be lost with no warning or error at all.
I also added a time value to the results table. The value is how long in seconds it took for the query to complete.
I also moved the repo to github, since bitbucket is shit and has been offline like every other day these past few weeks.
[url]https://github.com/blackawps/gm_tmysql4[/url]
Stupid question.
I know nothing about C++ How do I compile the .dll
[QUOTE=Unknown Gamer;48958241]Stupid question.
I know nothing about C++ How do I compile the .dll[/QUOTE]
Then you don't... You download the pre-compiled binary.
[QUOTE=BlackAwps;48953065]See this is something I don't understand. What do you actually use Disconnect for? I feel like I should just remove Disconnect because no one actually uses it properly anyway, and all other mysql modules don't have a disconnect method. Can you tell me why you're actually using Disconnect?[/QUOTE]
I need to explain to you how your module works? Well, ok, no problem.
When tmysql.initialize is called with arguments pointing to the same database it was already connected to before, it just returns already existing db object instead of reinitializing connection. Thus, i have to call :Disconnect on previous db object in order to try to reconnect.
db:Query() gives absolutely no response, and tmysql.initialize will just return the same unresponsive db object. What the hell else am i supposed to do?
[QUOTE=Revenge282;48959122]Then you don't... You download the pre-compiled binary.[/QUOTE]
He updated the tmysql4 on github but it was never pre-compiled
[QUOTE=vigi8;48959657]I need to explain to you how your module works? Well, ok, no problem.
When tmysql.initialize is called with arguments pointing to the same database it was already connected to before, it just returns already existing db object instead of reinitializing connection. Thus, i have to call :Disconnect on previous db object in order to try to reconnect.
db:Query() gives absolutely no response, and tmysql.initialize will just return the same unresponsive db object. What the hell else am i supposed to do?[/QUOTE]
You could have just said this in the first place. You were being a dick and literally talking around the issue, saying it was crashing and being unresponsive without giving me crash dumps or explaining how to replicate it. Now that I know your issue, I will look into it. Was that so hard?
[QUOTE=Unknown Gamer;48959733]He updated the tmysql4 on github but it was never pre-compiled[/QUOTE]
I always update the dlls in the op in the latest build. Also, the dlls are on the githib repo in the lib folder. You just have to rename then.
[QUOTE=Unknown Gamer;48959733]He updated the tmysql4 on github but it was never pre-compiled[/QUOTE]
The compiled dlls in first post have changed since i downloaded them several days ago, so i think they are updated.
[editline]23rd October 2015[/editline]
[QUOTE=BlackAwps;48959805]You could have just said this in the first place. You were being a dick and literally talking around the issue, saying it was crashing and being unresponsive without giving me crash dumps or explaining how to replicate it. Now that I know your issue, I will look into it. Was that so hard?[/QUOTE]
[QUOTE=vigi8;48951306]tmysql suddenly stopped reacting to db:Query in any way. Callback wasn't called at all.[/QUOTE]
[QUOTE=vigi8;48959657]db:Query() gives absolutely no response[/QUOTE]
I said exactly the same thing in those 2 posts, i don't understand you...
[QUOTE=vigi8;48959806]I said exactly the same thing in those 2 posts, i don't understand you...[/QUOTE]
At no point did you give a clear and consise way to replicate your issue. I don't understand [I]you[/I]. Even your little quotes you snipped say nothing but "it dun work"
[QUOTE=vigi8;48951306]tmysql suddenly stopped reacting to db:Query in any way. Callback wasn't called at all.[/quote]
[QUOTE=vigi8;48951306]After trying some simple queries like "select 1+1" and still getting no response, not even an error, i decided to reconnect to database (server was live with players, i had to restore database connection asap). I call db:Disconnect() before attempting new connection and server crashes.[/quote]
[QUOTE=vigi8;48951306]OH COME ON Almost a year passed from [url=https://facepunch.com/showthread.php?t=1441753&p=46726945&viewfull=1#post46726945]this post[/url]! Not only db:Disconnect crash is still there, but now it also randomly stops working!
There is no reason connection could be lost, gmod and sql server are on same machine. And even then, it should error when connection is lost, not just stop responding at all.[/quote]
You then mention it not being possible about not being able to call disconnect twice, still not telling me how to replicate it. Close to telling me in a clear way, but it's easily overlooked by your rage.
[QUOTE=vigi8;48951306]Also, in my wrapper, it is not possible for db:Disconnect() to be called twice on the same db object, because variable that holds object is set to nil immediately after calling :Disconnect(). So, when i called :Disconnect() manually, it was first call of this function on this db object. This crash is not even the main issue though, callback not being called is. But these two issues are probably connected anyway.
I can't provide any error IDs because callback wasn't called at all, and i can't do further testing on broken db object because server crashed.[/quote]
Then you try to make me feel bad or something.
[QUOTE=vigi8;48951306]We have something like 8 gmod servers on one machine, and several of them use 2 tmysql connections (one for admin system, another one for darkrp). This may or may not be connected to the issue.[/QUOTE]
And then you finally calmed down and gave me a step-by-step, still flaming me by the way, but at least I know what I can do to try and replicate your issue now.
[QUOTE=vigi8;48959657]I need to explain to you how your module works? Well, ok, no problem.
When tmysql.initialize is called with arguments pointing to the same database it was already connected to before, it just returns already existing db object instead of reinitializing connection. Thus, i have to call :Disconnect on previous db object in order to try to reconnect.
db:Query() gives absolutely no response, and tmysql.initialize will just return the same unresponsive db object. What the hell else am i supposed to do?[/QUOTE]
Either English isn't your first language, you're really immature or have anger issues.
[editline]22nd October 2015[/editline]
Even still, I can't replicate your issue at all.
[lua]require"tmysql4"
local status, error = tmysql.Connect("localhost", "test", "gofuckurself", "test")
if status then
print("FIRST CONNECTION")
DATABASE = status
end
print("tmysql.Connect", DATABASE, error)
print("ATTEMPTING QUERY ON FIRST CONNECTED DATABASE")
DATABASE:Query("SELECT 'hello world'", PrintTable)
print("DISCONNECTING FIRST CONNECTION")
DATABASE:Disconnect()
print("ATTEMPTING QUERY ON DISCONNECTED DATABASE, THIS WILL DO NOTHING")
DATABASE:Query("SELECT 'nothing'", PrintTable)
local status, error = tmysql.Connect("localhost", "test", "gofuckurself", "test")
if status then
print("SECOND CONNECTION")
DATABASE = status
end
print("tmysql.Connect", DATABASE, error)
print("ATTEMPTING QUERY ON NEWLY CONNECTED DATABASE")
DATABASE:Query("SELECT 1+2", PrintTable)[/lua]
[code]FIRST CONNECTION
tmysql.Connect userdata: 0xea7029c8 nil
ATTEMPTING QUERY ON FIRST CONNECTED DATABASE
DISCONNECTING FIRST CONNECTION
1:
affected = 1
data:
1:
hello world = hello world
lastid = 0
status = true
time = 0.216581026
ATTEMPTING QUERY ON DISCONNECTED DATABASE, THIS WILL DO NOTHING
SECOND CONNECTION
tmysql.Connect userdata: 0xef16c7f0 nil
ATTEMPTING QUERY ON NEWLY CONNECTED DATABASE
1:
affected = 1
data:
1:
1+2 = 3
lastid = 0
status = true
time = 0.251642527[/code]
Everything works as expected.
[editline]22nd October 2015[/editline]
ANYWAYYY
I updated the module again to throw errors if you attempt to call functions on a disconnected database.
[img]http://i.imgur.com/aFvHBm0.png[/img]
[QUOTE=BlackAwps;48959893]At no point did you give a clear and consise way to replicate your issue. I don't understand [I]you[/I]. Even your little quotes you snipped say nothing but "it dun work"[/QUOTE]
I'd be very glad to tell you exact steps to reproduce the issue, why wouldn't i, but i have no idea myself!
Everything was working smoothly, i didn't touch DB in any special way, didn't reconnect or anything, just normal queries from admin system (through my wrapper) and darkrp (through mysqlite darkrp wrapper). And then it stopped responding to db:Query calls. It happened only once (but i'm using tmysql for only about 3 days).
Here's my wrapper: [url]http://pastebin.com/992FFzee[/url]
Unfortunately, it didn't come to my mind at the time of making the wrapper to add a print when it reconnects, so i don't know if reconnection attempt was made or not.
But i don't know how could it be possible for connection to be lost in the first place: both gmod and sql servers are on the same machine, there can't be any network issues.
The only two 'rage' lines were:
> [I]OH COME ON Almost a year passed from this post! Not only db:Disconnect crash is still there, but now it also randomly stops working![/I]
> [I]I need to explain to you how your module works? Well, ok, no problem.[/I]
Everything else - i was just trying to explain various details, maybe some of them might be helpful. I don't know why you took everything else for 'rage'.
This, for example,
> [I]We have something like 8 gmod servers on one machine, and several of them use 2 tmysql connections (one for admin system, another one for darkrp). This may or may not be connected to the issue.[/I]
means that maybe it stops working when too many instances are created on the same machine. I'm just providing details about our environment.
And yes, of course i'm gonna be a bit angry:
Back then, when i wrote [url=https://facepunch.com/showthread.php?t=1441753&p=46726945&viewfull=1#post46726945]this[/url] and following posts, all i initially got was a box from your buddy, who doesn't understand what garbage collector does. Sorry, i didn't think i have to explain GC to someone who is making c++ modules.
And now, when i tried the module again after 10 month, i get a crash, related to :Disconnect, and an unresponsive db object, on the second day of using the module.
[editline]23rd October 2015[/editline]
Don't get me wrong. I'm grateful that you made a mysql module that doesn't make a huge performance hit like mysqloo does. But at least mysqloo always worked for me, i've never had it crash or randomly stop working. And with tmysql, i've got such issues on the second day of using it.
You should probably remove that reconnect code. The module will attempt to do that now itself.
[url]https://github.com/blackawps/gm_tmysql4/blob/master/src/database.cpp#L145[/url]
I used this module for months on end and never had a crash, but I never had to disconnect and reconnect like you are doing. But like I said, the module should handle reconnects now. Run it for a few days and see if the issue goes away. I can't replicate your issue on my end, so I can only rely on your information.
You can't use Disconnect with mysqloo :science101:
I feel stupid... But I've never used linux before, and I can't seem to get your module to work for my linux server.
*used your Linux link to download libgm_tmysql4.so
*renamed it to gmsv_tmysql4_linux.dll
*placed it inside garrysmod/lua/bin/
Try to start the server, and I get this.
[code][ERROR] gamemodes/mvw/gamemode/init.lua:11: Couldn't load module library!
1. require - [C]:-1
2. unknown - gamemodes/mvw/gamemode/init.lua:11
[/code]
[lua]require("tmysql4") --LINE 11 INSIDE init.lua
DB, DB_ERROR = tmysql.initialize("db4free.net", "****", "****", "****", 3306)[/lua]
Could anyone tell me what I'm doing wrong?
You're probably having the same issue as everyone else. What distribution are you using out of curiosity?
[url]https://facepunch.com/showthread.php?t=1490775[/url]
I did what he has done, hopefully you can find something! Let me know what else I might be able to do to help and I will.
Copy of my linux terminal after running your command line on server start:
[url]http://pastebin.com/Ks5uWUj8[/url]
Then I also tried what, bloxgate, suggested:
[code]sh-4.3$ ldd gmsv_tmysql4_linux.dll
./gmsv_tmysql4_linux.dll: /usr/lib32/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./gmsv_tmysql4_linux.dll)
linux-gate.so.1 (0xe7fb9000)
libstdc++.so.6 => /usr/lib32/libstdc++.so.6 (0xe7abe000)
libm.so.6 => /lib32/libm.so.6 (0xe7a78000)
libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xe7a5b000)
libc.so.6 => /lib32/libc.so.6 (0xe78b1000)
/lib/ld-linux.so.2 (0xe7fba000)
sh-4.3$
[/code]
I tried the "strings" command line as well, however it said command unknown. And my knowledge of anything linux related started Yesterday... So like I said, let me know what I should experiment with if none of this helps.
Ok I've figured it out: Linux users who are getting the "Couldn't load module library!" error make sure you have GCC 5 installed, and that whichever libstdc++.so.6 Garry's Mod is using has GLIBCXX_3.4.21. For ubuntu users:
[CODE]add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get update
apt-get install gcc-5
gcc-5 --version[/CODE]
Then make sure that tMySQL can see the new libstdc++:
[CODE]
ldd gmsv_tmysql4_linux.dll
linux-gate.so.1 => (0xb7744000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb7223000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb71dd000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb71be000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7010000)
/lib/ld-linux.so.2 (0xb7745000)[/CODE]
Finally, check that the libstdc++ that gmod is actually using has the new GLIBCXX:
[CODE]
strings libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_DEBUG_MESSAGE_LENGTH[/CODE]
[quote=find me;48970846]
-snip-
I tried the "strings" command line as well, however it said command unknown. And my knowledge of anything linux related started Yesterday... So like I said, let me know what I should experiment with if none of this helps.
[/quote]
Install binutils for the strings command.
Ah nice, I'm glad someone figured it out. That makes sense because I had to compile with gcc-4.8 for the C++11 features. Thanks for figuring that out!
Is there any chance that the callback function always returns the resultset as the first argument? This isn't a major gripe as it stands but I think it'd lead to more predictable behaviour. Logically we can always expect something from the query (be it some sort of status or actual data) but we're not always guaranteed to pass an object argument.
This was the behaviour until recently (I think the fix you implemented to fix argument positions is what changed this). That said this isn't some urgent matter (or something you need to change really) as my wrapper passes data separately now but it was a bit weird trying to debug this initially :v:
Yeah sorry. The way it is now is how it was originally intended so you can do things like use gamemode functions like GM:OnFetchPlayerData and stuff like that by passing GAMEMODE as the object to the query. I can see the confusion but I don't know a good way we could have both.
[QUOTE=bloxgate;48974268]Ok I've figured it out: Linux users who are getting the "Couldn't load module library!" error make sure you have GCC 5 installed, and that whichever libstdc++.so.6 Garry's Mod is using has GLIBCXX_3.4.21.[/QUOTE]
How do I install GCC 5?...
[code]
root@al:~# -bash: add-apt-repository: command not found
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package gcc-5
[/code]
System (OS)
Debian 8.1 stable (Jessie) (stable)
Try and run this for me and see if it helps.
[code]sudo apt-get update && sudo apt-get dist-upgrade[/code]
Turns out I was actually on Debian Sid, but I'm building it on Ubuntu 12.04 now so I really just don't know.
[editline]25th October 2015[/editline]
Actually, I just committed a compile on an even older version of glib and have great confidence that it will work now for you.
[editline]25th October 2015[/editline]
On a side note I updated the module again so Database:Escape can handle nulls and stuff.
[code]print(DATABASE:Escape("This is 'stoopid' a \"test\"\0 to see if it will show the null!"))
This is \'stoopid\' a \"test\"\0 to see if it will show the null![/code]
find me, the directions I gave for gcc-5 were for Ubuntu users. A quick google search tells me that gcc-5 is only available in Debian Unstable at the moment.
I don't think it's necessary anymore. Would appreciate it if people could test to see if my latest release runs nativity now.
The linux link is broken, it just comes to a error 500 page not found on github.
Sorry, you need to Log In to post a reply to this thread.