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

separate sqlwrite and sqlread server #378

Merged
merged 38 commits into from May 28, 2016
Merged

separate sqlwrite and sqlread server #378

merged 38 commits into from May 28, 2016

Conversation

H-M-H
Copy link
Member

@H-M-H H-M-H commented Nov 22, 2015

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.

@H-M-H H-M-H added server Related to the server-side. incomplete More information needs to be provided for this issue. cleanup Code cleanup and refactoring. labels Nov 22, 2015
@H-M-H
Copy link
Member Author

H-M-H commented Nov 22, 2015

@MyNewBie well it should work, did not test it though.

@MyNewBie
Copy link

@H-M-H sql_server compiled done but get crash after running , cant connect to MySQL database.

@H-M-H
Copy link
Member Author

H-M-H commented Nov 23, 2015

This is very likely a problem with the sql library, the same thing happened on my mac. To fix it you could try:

  1. compile sql libs on your own
  2. check the compiler flags and additionally libs used for compiling sql libs and try to make them the same (on my mac for instance sql libs were compiled with -stdlib=libc++ but ddnet with -stdlib=libstdc++)

@H-M-H H-M-H removed the incomplete More information needs to be provided for this issue. label Nov 23, 2015
@H-M-H
Copy link
Member Author

H-M-H commented Nov 23, 2015

I guess I am done now, ofcourse this still needs extensive tests and possibly a review :).

@def-
Copy link
Member

def- commented Dec 8, 2015

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.

@def-
Copy link
Member

def- commented Dec 15, 2015

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.

@H-M-H
Copy link
Member Author

H-M-H commented Dec 15, 2015

It is nearly done, I will try to finish it this week.

@def-
Copy link
Member

def- commented Jan 12, 2016

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.

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
+ 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
@H-M-H
Copy link
Member Author

H-M-H commented May 3, 2016

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];;
Copy link
Member

Choose a reason for hiding this comment

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

double semicolon

Copy link
Member Author

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.

@def-
Copy link
Member

def- commented May 3, 2016

What you're doing with SaveScoreThread and SaveTeamScoreThread looks dangerous. When you keep %s characters in code to use them later, it's possible that user-strings could contain them as well, no?

@H-M-H
Copy link
Member Author

H-M-H commented May 3, 2016

Right, i already thought about putting 'record' back instead of '%s', but this assumes that every server is configured with 'record' as prefix. '%s' felt better but indeed not perfect. Any ideas to improve that ?

This commit introduced that btw: 8dacd88 .

@def-
Copy link
Member

def- commented May 4, 2016

This is being tested by HMH on Chile. He can merge it himself when he feels it's ready for general use.

H-M-H added 5 commits May 4, 2016 23:37
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)
@def-
Copy link
Member

def- commented May 13, 2016

How are the Chile tests going?

@H-M-H
Copy link
Member Author

H-M-H commented May 14, 2016

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.

@H-M-H H-M-H merged commit ada3b9a into ddnet:master May 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code cleanup and refactoring. server Related to the server-side.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants