About game server combination

Source: Internet
Author: User
Original Website: our game went through the first data combination server last week. Simply put, two databases are merged into one database to allow players on two servers to play together. The process is thrilling, and finally the task is completed safely. This article will share the technical details of the next service combination. Requirement Description: -------------------------- two servers must be added.

Original Website: our game went through the first data combination server last week. Simply put, two databases are merged into one database to allow players on two servers to play together. The process is thrilling, and finally the task is completed safely. This article will share the technical details of the next service combination. Requirement Description: -------------------------- two servers must be added.

Original Website:

Our game went through the first data combination server last week. Simply put, the Hong Kong Space is to merge two databases into one database so that players on two servers can play together.

The process is thrilling, and finally the task is completed safely.

This article will share the technical details of the next service combination.

Requirement Description:

--------------------------

To merge two server players, the external players are not changed, including the URL of the game to log on to and the role in the game. However, it is physically a server and a database.

To put it simply, gamers in a server use the portal to log in and use the account of the server. gamers in two servers use the portal to log in and use the account of two servers;

Even if I only have one account, I can still use different game accounts for different logon entries.

Database Design

--------------------------

To implement the combination, the table's primary keys must all be generated using code, and the server encoding is used as the prefix.

For example, the primary key of my server table is 001 GMxxxxxxxxxxxxxxxx. The second server is 002 GMxxxxxxxxxxxxxxxx. In this way, data is not pre-processed. Direct import.

Second, a platform user uses an account to log on to different servers and obtain different accounts. Therefore, the player table in the game must be differentiated by server encoding. For example:

Usr_Profile

: Usercode primary key

: Username platform account

: Servercode server code

In this way, based on the input username + servercode, you will know the server account to be obtained.

In the game, the player identifies the other party by using a nickname. Therefore, you must correct the nickname to prevent duplication during server combination. Therefore, all nicknames must be suffixed. The final solution is to add the suffix. x server.

With these three guarantees, the combination of services becomes simple. (Simple fart ...)

Service Combination Process

--------------------------------

1. Prepare for Database Analysis

Make preparations before you do things. Therefore, we must first analyze the database table structure to determine what table structures need to be combined and what can be ignored.

In our game, there are more than 60 tables, of which only 27 need to be merged. Other tables are configuration tables and log tables, which do not need to be merged.

2. Data Backup

Needless to say, the first thing to do is to back up the database in full to prevent operation errors and data loss. Generally, a new backup database is created in MySQL on the local machine and then copied using bult insert, which is fast. Of course, during backup, you can skip a large log table.

3. data deletion

This part is very important. A web game has nearly 80% of accounts and is a dead number. Therefore, you must filter out the dead number when merging servers. The rules are as follows: if the logon time is less than 10, no recharge, or the last logon time is greater than 30 days, all are cleared.

Then, in the 27 tables mentioned above, the data related to the obsolete account is also cleared.

The cleanup volume is actually very large. I have a data table that is close to 30 W, and the result is cleared by 20 W as soon as it is clear, which is super comfortable.

4. Data Detection

This part is also very important, because our second server was configured incorrectly at the time and the server code was not used as the primary key, resulting in a conflict with the data of a server, therefore, we need to check the primary keys of 27 tables to determine whether the prefix is 002. If not, we need to manually correct them.

5. Data Correction

This module is mainly used to modify data with primary key conflicts. Generally, you can use SQL statements, which takes about 30-30 minutes ~ In 60 Minutes, I used an SQL statement, for example, update xxx set pk = concat ('001', substring (pk, 4) to fix the data.

Of course, the structure of the table needs to be analyzed before the restoration. There should be no omissions. Hong Kong servers, especially foreign key associations.

6. Export data

Do not try to use code or other methods for combination. The speed is too slow. I use SQLYog to export all tables. The Insert configuration is Bult Insert, which is very fast.

7. Data Import Test

At the end of the import, test to see if the exported SQL has any problems.

8. Import.

This is done, and the combination is successful.

The steps seem very simple, but there are actually a lot of problems. Next, I will describe the traps in the actual deployment.

Combined Service survival test

------------------------------

1. The table structure of the combination server does not match

When I joined the server, I found that the table was always inaccessible, prompting that the primary key was repeated. Impossible .. If you import data from a table with no duplicate primary keys, a duplicate error is displayed?

After checking for a long time, we found that the primary key of Server 1 is 21 bits, and the primary key of Server 2 is 22 Bits. When the result is imported, the primary key of 22 Bits automatically skips the last bits, naturally, duplicate primary keys are generated...

2. SQLYog damn bug

The table structure changed by SQLYog does not correspond to the actual table structure. I obviously modified char (100), but the database still had to use the command line to modify it ..

Hi. These tools are always troublesome.

3. There is no prompt for an error in SQLYog import.

This is also a damn tool problem. Finally, I used navicat to work with SQLYog.

4. Some dynamically generated data cannot be imported in batches

For example, the same ranking cannot appear in the arena ranking. Therefore, this data must be automatically generated when players log on. This type of data is dynamically generated and cannot be corrected in batches. It must be supplemented by the game logic.

Therefore, this data will not be merged during the combination.

Adventure

------------------------------

After talking about so much theoretical knowledge, let's talk about how I got together that day. Everything went smoothly on the test machine and it was merged in less than two hours. But it took 8 hours to complete the operation ....

The operation was still smooth, and data backup, deletion, and correction were completed in more than three hours. However, during the import, the primary key conflict is always prompted, so we kept looking for the cause. It took an hour before we found that the original table structure did not match. Dizzy.

After importing the data, four hours have passed. When the game leaves, the players complain about Chinese garbled characters, lost equipment, and lost military commanders.

I spent another hour checking the problem of lost equipment and military commanders. It turned out that some of the potential primary keys still lost the last one bit, so I could not find it. At this time, I cannot stop, so I compare two tables with different databases, generate a bunch of update SQL statements, and then perform manual operations. However, SQLYog will be stuck and the game will be stuck even if there are more SQL statements. I had to open more than 10 SQLYog and use the parallel method to split the SQL into 50 groups for manual operations .. Exhausted.

The name of the martial arts account is garbled. The encoding format was incorrect when the SQL file was generated. However, the generals had nearly data records, and it was impossible to manually update the data. Therefore, I wrote an update program for background updates. It took one hour.

Finally, the game has fewer exceptions, so you can just take a break. As a result, the Operation says that the player recharge failed! I checked the Code. In the past, the recharge interface did not use servercode to differentiate the player account, which is an oversight.

The next day, the operation complained that the Chamber of Commerce failed to collect resources and went back to the inspection to find that the primary key of the account provider was corrected, which is also an oversight.

Summary

----------------------------

I had already rehearsed for two days in advance, but there was no problem, but there were still many mistakes on the battlefield.

If the preparation is too detailed, it will lead to slow development. If the preparation is inadequate, there will be many problems. This is a dilemma. In the end, I chose a solution for rapid preparation and rapid correction.

After all, the website space cannot be found during the rehearsal. It is better to go directly to the battlefield and adapt to random situations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.