I just tried out 2.0 and it seems you HAVE to have both DBs installed - is there any way to make that not the case as it seems very inefficient for using just one.
|
Edit: Also, I thought about your suggestion to make yid PRIMARY_KEY and realised that I could do that if it was in a separate table, so did so. Thanks. |
OK, I have a few new points.
1) You could really do with more Mutexes IMHO. Currently if "ProcessQueryThread" is running, "sql_query" (and probably other natives, I've not looked) will hang until all pending queries are complete, making multiple threads almost pointless in that case. Or instead of mutexes a lock-free single producer/single consumer list implementation (I'm know these exist). In short, the mutexes are held by a thread for FAR too long. Edit: http://www.boost.org/doc/libs/1_53_0.../lockfree.html 2) On a similar note, even non-threaded queries currently obtain the Mutex and thus wait for pending operations when there's no need for them to enter a protected section at all. |
3) It would be VERY helpful if "Unload" completed pending queries instead of dropping them, for example to save user data on server end.
|
If you care, I've started updating some of the code. I split the queries in to two containers - your map for "is_valid" checks and referencing them by ID, and a second thread-safe queue for passing queries between threads for concurrent ones. I've removed most of the locks as they protected reads from the only thread that can modify some of the data, so there wasn't any point protecting them. It also switched to using "const" methods where possible as C++11 defines those as thread read safe.
|
Yeah, it's no where near complete yet (I've not even tested compiling).
|
forward CheckMuted(playerid);
public CheckMuted(playerid) {
new query[250];
format(query, sizeof(query), "SELECT user_name FROM users WHERE user_id = '%d' AND user_muted = '1'", playersInfo[playerid][pID]);
new Result:Muted = mysql_query(mysql, query, QUERY_THREADED);
new rows = mysql_num_rows(Muted);
printf("[mysql] Mute Query %d %s %d.", playersInfo[playerid][pID], playersInfo[playerid][pUsername], rows);
if(rows == 1) {
playersInfo[playerid][pMute] = 1;
return 1;
} else {
return 0;
}
}
CheckMuted(playerid);
public OnPlayerText(playerid, text[]) {
if(playersInfo[playerid][pMute] != 1) {
new string[2000];
format(string, sizeof(string), "{FFFFFF}(%i) %s", playerid, text); /* with player ID in chat */
SendPlayerMessageToAll(playerid, string);
} else {
SendClientMessage(playerid, COLOR_RED, "(Error!) You are muted, You are not allowed to talk");
}
return 0;
}
playersInfo[playerid][pMute] = 0;
[13/05/2013 18:45:15] [mysql] Mute Query 5 Jordy2 0.
new Result:Muted = mysql_query(mysql, query, QUERY_THREADED);
new Result:Muted = mysql_query(mysql, query, QUERY_NONE);
new Result:Muted = mysql_query(mysql, query, QUERY_CACHED);
mysql_free_result(Muted);
new rows = mysql_num_rows(Muted);
COMMAND:punishments(playerid, params[]) {// needs to be fixed
if(CheckARank(playerid, 2, 4)) {
new targetid;
if(!sscanf(params, "U(-1)", targetid)) {
if(targetid == -1) {
new query[500], string[128], variable[960], reason[500];
format(query, sizeof(query), "SELECT * FROM warnings WHERE warning_userid = '%d'", playersInfo[playerid][pID]);
new Result:Warnings = mysql_query(mysql, query, QUERY_NONE);
new rows = mysql_num_rows(Warnings);
mysql_free_result(Warnings);
mysql_get_field_assoc(Result:Warnings, "warning_reason", reason, sizeof(reason));
format(string, sizeof(string), "\n%s", reason);
strcat(variable, string);
if(rows == 0) return SendClientMessage(playerid, COLOR_RED, "(Error!) No warnings found!");
if(rows == 1) { format(string, sizeof(string), "%d Punishment in your file", rows); }
if(rows > 1) { format(string, sizeof(string), "%d Punishments in your file", rows); }
ShowPlayerDialog(playerid, DIALOG_PUNISHMENTS, DIALOG_STYLE_LIST, string, variable, "Close", "");
} else {
new query[500], string[128], variable[960], reason[500];
format(query, sizeof(query), "SELECT * FROM warnings WHERE warning_userid = '%d'", playersInfo[targetid][pID]);
new Result:Warnings = mysql_query(mysql, query, QUERY_NONE);
new rows = mysql_num_rows(Warnings);
mysql_free_result(Warnings);
mysql_get_field_assoc(Result:Warnings, "warning_reason", reason, sizeof(reason));
format(string, sizeof(string), "\n%s", reason);
strcat(variable, string);
if(rows == 0) return SendClientMessage(playerid, COLOR_RED, "(Error!) No warnings found!");
if(rows == 1) { format(string, sizeof(string), "%d Punishment in %s's file", rows, playersInfo[targetid][pUsername]); }
if(rows > 1) { format(string, sizeof(string), "%d Punishments in %s's file", rows, playersInfo[targetid][pUsername]); }
ShowPlayerDialog(playerid, DIALOG_PUNISHMENTS, DIALOG_STYLE_LIST, string, variable, "Close", "");
}
}
}
return 1;
}
I actually doubt that - I know several owners of several large servers, and they don't. "Advanced server owners" know not to waste time duplicating efforts re-writing things that already exist.
|
1) try to avoid mutexes (really, please don't use them), use std::atomic instead or Concurrency::concurrent_queue / concurrent_vector etc.
|
2) any more "advanced server owner" will probably make his own plugin using ODB (like me :P Ye, making a gamemode with GDK)
Consider adding support for it somehow :P |
I have some ideas. I hope I'll implement them soon.
That looks interesting. I'll look into. |
You must call mysql_free_result after any function that is using the result (like mysql_get_field_assoc).
|
have a look at my GPS plugin if you want to see some threading code without locks
|
If you will use "mysql_connect" to connect to a database, you can use also "pgsql_connect" to connect also to that database?
|
If you will use "mysql_connect" to connect to a database, you can use also "pgsql_connect" to connect also to that database?
|
[17:15:38] [debug] Run time error 19: "File or function is not found" [17:15:38] [debug] sql_connect [17:15:38] [debug] sql_query [17:15:38] [debug] sql_num_rows [17:15:38] [debug] sql_get_field_assoc_int [17:15:38] [debug] sql_get_field_assoc [17:15:38] [debug] Run time error 19: "File or function is not found" [17:15:38] [debug] sql_connect [17:15:38] [debug] sql_query [17:15:38] [debug] sql_num_rows [17:15:38] [debug] sql_get_field_assoc_int [17:15:38] [debug] sql_get_field_assoc