Grant that all SQL Transactions finish until Restart Server
#1

hello,

How i can grant that all sql transactions finish until i execute rcon command gmx?

Im using MySQL Plugin R7 that using threads..

I have any form that know thread ids of unfinished transactions to wait for threads end with any function like pthread_join (like in c++)?

My command is:

Код:
CMD:ggmx(playerid, params[])
{
   	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
	new string[128];
	format(string, sizeof(string), "AdmCmd: %s has issued an instant server restart.", RPN(playerid));
	SendClientMessageToAll(COLOR_LIGHTRED, string);
	
	foreach(Player, i)
	{
		if(IsPlayerLoggedIn(i))
		{
		    SaveChar(i);
		}
	}
	SaveFactions();
	SaveFamilies();
	SavePoints();
	SaveBiz();
	SaveHouses();
	SaveDoors();
	SaveGates();
	SaveMapIcons();
	SaveArrestPoint();
	SaveDrugs();
	SaveMOTDS();
	SendRconCommand("gmx");

			
	return 1;
}
But its logical that when server executes SendRconCommand("gmx") exists threads of sql querys that not finish and server restart, cancel threads and information aren't saved..


I have any way to resolve this?

Regards
Reply
#2

Anyone can helpme ? I really need one solution.

Thanks
Reply
#3

Create a variable which adds 1 at the end of every saving function, when the amount of each saving function is called, then you should let the server GMX.

pawn Код:
foreach(Player, i)
    {
        if(IsPlayerLoggedIn(i))
        {
            SaveChar(i);
        }
    }
    SaveFactions();
    SaveFamilies();
    SavePoints();
    SaveBiz();
    SaveHouses();
    SaveDoors();
    SaveGates();
    SaveMapIcons();
    SaveArrestPoint();
    SaveDrugs();
    SaveMOTDS();
You could do something like:

pawn Код:
new iCount;

stock randomSavingFunctionYouCallWhenTheServerIsAlmostGMXed() {
     iCount++;

     if(iCount == AMOUNTOFSAVINGFUNCTIONS)
          SendRconCommand("gmx");
     return 1;
}
Reply
#4

Hello Calgon,

Your solution is good but whereby i have seen, the all functions of Save end but changes in database dont take effects in same time because the plugin using threads and when server executes the function mysql_function_query launch a new thread and script continues to the next instruction. I think that to solve this is necessary a way to wait for all threads finish.

Regards
Reply
#5

Well, in this case you would have to estimate how long it would take for everything to save. Just try setting a delaying timer.

pawn Код:
CMD:ggmx(playerid, params[])
{
   // rest of your code
   
    SaveFactions();
    SaveFamilies();
    SavePoints();
    SaveBiz();
    SaveHouses();
    SaveDoors();
    SaveGates();
    SaveMapIcons();
    SaveArrestPoint();
    SaveDrugs();
    SaveMOTDS();
   
    // 1 second is guessing
    SetTimer("gmxfunction", 1000, 0);
       
    return 1;
}

forward gmxfunction();
public gmxfunction() {
    SendRconCommand("gmx");
    return 1;
}
Reply
#6

Sorry I mean add the code to the bottom of each thread call. When you specify a function to call when the thread has called, you can create the function and have it add 1 to the count.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)