MySQL and Server migration.
#1

Hello users,
I've been creating my own personal project and trying crazy things on it. However, I'm unsure of the best live migration between the MySQL server and the SA-MP server. So at the moment my server grabs the data from MySQL table and stores it on the server and only updates the users table whenever the user logs out. It never refreshes the table to grab any changed data from the MySQL server. In order to make a live migration between the MySQL and server requires the data to be saved onto the MySQL server often, so therefore I was thinking of updating the field each time you modify ANY sort of data, for example if a player was to give money, it will automatically update the MySQL field as soon as the command is executed. So it's easy to update the data, however what if I renewed the data in the MySQL (from Navicat or Phpmyadmin)? The data won't be imported into the server. What would be the best way to migrate the two? I mean SELECTing from the Database each time would be a hassle. This is basically for the UCp that I'm planning on creating in the future which allows me to edit data and not just view it. I can obviously edit the data if the player is not logged in, however I want it so I can edit it whilst they're logged in aswell.
Reply
#2

Socket plugin. When you submit your form, update the database and open a socket connection to the SA-MP server. When the SA-MP server receives the incoming socket connection it can then proceed to sync from the database.

However, there may still be a slight delay during this process during which the data may be overwritten. I think a table lock would solve this, but I've never worked with those before so I'm not sure how it would work out.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Socket plugin. When you submit your form, update the database and open a socket connection to the SA-MP server. When the SA-MP server receives the incoming socket connection it can then proceed to sync from the database.

However, there may still be a slight delay during this process during which the data may be overwritten. I think a table lock would solve this, but I've never worked with those before so I'm not sure how it would work out.
I appreciate your help and I'll look into the whole socket plugin. It would be easier for me to use the MySQL table as I know how to set it out well, but then again that requires more added onto the script. Sockets plugin will require more time, as I'm going to have to learn how to work the thing. At the end of the day I'm looking for the best option. I don't want to start on something that's going to turn out to be rubbish.
Reply
#4

I think the socket plugin is a pretty good idea for updating the player values from the database.

For the overwriting, I had a similar system myself, I made a queue for mysql updates in the script. Every 60 seconds it performed the queued updates and while these updates were running, I locked the database (creating a table named "lock" or st. and deleted the table after the queue was done).

While this table was existing, no updates from my websites could be done, so no overwriting.

The same could be done with the socket plugin. For example when changing playerid 2's money on the website, it will send this info to the server. The server then takes out all money queues for this player and queues in the new value, and its synced.
Reply
#5

So I've created a table called commands and it's currently functional. However, I've got an additional question. I've obviously got a timer which draws all the information out from the table, but if I was to set it to 100 milliseconds, would that cause any issues? That's if I was to get additional player and such. I mean I don't really know how it will effect the server.

Also, how should I work with the commands table?

Method 1:
Commands table > Server > Save server data > Save MySQL data through the server.

Method 2:
Commands table > Save MySQL data through the website > Server > Save server data.

So if I was saving players cash through method 1, it would not update the players cash in MySQL field until server executes the command (basically MySQL field gets updated through the server) and method 2 will save the players cash in the MySQL field and insert a command into the commands table and await for it to be executed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)