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
separate sqlwrite and sqlread server #378
Conversation
@MyNewBie well it should work, did not test it though. |
@H-M-H sql_server compiled done but get crash after running , cant connect to MySQL database. |
This is very likely a problem with the sql library, the same thing happened on my mac. To fix it you could try:
|
I guess I am done now, ofcourse this still needs extensive tests and possibly a review :). |
Any plan when this will be ready? Would be nice for the new Chile server, since it doesn't have enough RAM to run its own database. Would also like to get rid of a few other database servers, RUS and CHN especially. If we also remove South Africa we keep these servers as database servers: ddnet.tw, GER, USA, CAN. That would be good enough I guess. Edit: I still believe this should use the same servers for writing and reading, just fallback ones when the main one goes down. The 100 ms delay for getting /rank should be survivable. |
Any plan when this is ready? We're currently failing to store many ranks on Chile and Brazil because of DDoS attacks and other network problems. |
It is nearly done, I will try to finish it this week. |
Still happens all the time, not sure why people even still play on these servers as their ranks are mostly not saved at all. |
-moved all connectionstuff to a new class -moved sqlstring functions to an own file -do not give threads access to CSqlScore
custom configs
+ added #ifdef for sql_server.cpp (fixes compilation for release mode)
TODO: move the sqlserver objects somewhere else so they wont be destroyed on every reload
as sqlconnections should not last only until next mapreload
each sqlserver has its own lock now -> it is required that every connect call is followed by a disconnect call
reading from and writing to several different servers is now possible TODO: -handle Exceptions properly (try another sqlserver) -if everything fails while writing write the insert to a file
- write failed sqlinserts to a file - improved structure
Okay, this fixes problems on mapchange/reload. New ranks will be saved even if the map is changed during the insert. Additionally some other unwanted behaviour is fixed (threads created before a mapchange notice the change and act accordingly now). |
|
||
#if defined (CONF_SQL) | ||
CSqlServer* m_apSqlReadServers[MAX_SQLSERVERS]; | ||
CSqlServer* m_apSqlWriteServers[MAX_SQLSERVERS];; |
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.
double semicolon
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 point, but there are more. Will fix this.
What you're doing with SaveScoreThread and SaveTeamScoreThread looks dangerous. When you keep |
Right, i already thought about putting This commit introduced that btw: 8dacd88 . |
This is being tested by HMH on Chile. He can merge it himself when he feels it's ready for general use. |
CSqlData is const for threadfunctions now to avoid modification from within the threadfunctions as these might be called several times. Previously this was a problem as ClearString could possibily be applied multiple times to the same string. To solve this the class CSqlString has been added. This class takes a const char* and copies it. Additionally a clearstring is created from the given const char*. This enables access to the original as well as the cleared string safe for sql-statements. sql_string_helpers got an own source file now. A crashbug from CSqlServer has been fixed (pointer has not been set back to 0)
How are the Chile tests going? |
Pretty good, already saved more than 100 ranks and found + fixed some bugs. Currently I am testing if fallbacks work fine with more than one sql-server. |
So, the idea is to separate the sql-servers, so you can specify different servers to read from and to write to. For example you could write to a distant masterserver and read from localhost (should replicate from master). Like this it is possible to have a few core/master-sql-servers and a whole replication-ring is no longer necessary.
Additionally this Pull Requests adds the possibility to specify more than one sql-server which makes it possible to fall back to another server if the first specified is unreachable.
In order to make all this stuff possible I restructured the sql-connection-stuff, we now have:
CSqlServer: This class provides access to one sql-server, connect and disconnect automatically lock the object to avoid several threads accessing it simultaneously.
CSqlConnector: This class is used to connect a sql-server, it will iterate over the list of given sql-servers and try to connect to one of them.
CSqlScore: This class now only contains things relevant to actually inserting records into db or querying some stuff. The sql-connection stuff has been moved to the above classes.
CSqlData: This struct contains the information relevant for the sql-query/statement.
CSqlExecData: This struct is used to call a function that does some sql-stuff within its own thread. It also supplies objects of CSqlData and CSqlServer to the called function.