Data processing method, apparatus and electronic device
By sharding the database data and establishing a cache on each shard, the problem of excessive server and database load in multi-user systems is solved, enabling efficient data querying and processing.
Patent Information
- Application Number
- CN202211413575.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-11
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2042-11-11
AI Technical Summary
In existing technologies, when multi-user systems query large amounts of target user data, the server and database are overloaded, affecting normal operation.
The database data is sharded into multiple shards, each shard corresponds to a data management process, and a cache is established in the process. The data shard and management process are identified by the data identifier. First, the data is queried in the cache. If it is not found, it is queried from the database and saved. The query result is then returned.
This reduced the query workload on the server and database, decreased the operating load, and ensured the normal operation of the system.
Smart Images

Figure CN115840764B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a data processing method, apparatus, and electronic device. Background Technology
[0002] In multi-user application systems, a user might send a query request to retrieve relevant data for a large number of other target users. In this case, the system's server needs to query the database once for each target user, and obtain the final query result after multiple queries. If there are hundreds of target users, hundreds of data query operations need to be processed. This data query method places a heavy load on the server and database, affecting the normal operation of the server and database. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a data processing method, apparatus and electronic device to reduce the load on the server and database during the data query process and ensure the normal operation of the server and database.
[0004] In a first aspect, embodiments of the present invention provide a data processing method, wherein data in a database is divided into multiple data shards; each data shard corresponds to a data management process; the data management process runs on a server, or the device running the data management process is communicatively connected to the server; at least one cache is established in the data management process; the method is applied to the server; the method includes: receiving a data query request, and determining a first target data identifier based on the data query request; wherein the first target data identifier is used to: indicate data to be queried; based on the first target data identifier, determining at least one data shard to which the data to be queried belongs, and a first target management process corresponding to the data shard; based on the first target data identifier, determining a target cache from at least one cache, and querying the data to be queried from the target cache; wherein the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, querying the data to be queried from the database, and saving the data to be queried to the cache; and returning the data to be queried to the device that sent the data query request.
[0005] Secondly, embodiments of the present invention also provide a data processing apparatus, wherein data in a database is divided into multiple data shards; each data shard corresponds to a data management process; the data management process runs on a server, or the device running the data management process is communicatively connected to the server; at least one cache is established in the data management process; the apparatus is disposed on the server; the apparatus includes: a receiving module, configured to receive a data query request and determine a first target data identifier based on the data query request; wherein the first target data identifier is used to: indicate data to be queried; a determining module, configured to determine at least one data shard to which the data to be queried belongs, and a first target management process corresponding to the data shard, based on the first target data identifier; a querying module, configured to determine a target cache from at least one cache based on the first target data identifier, and query the data to be queried from the target cache; wherein the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, the data to be queried is queried from the database and the data to be queried is saved to the cache; and a returning module, configured to return the data to be queried to the device that sent the data query request.
[0006] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described data processing method.
[0007] Fourthly, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are invoked and executed by a processor, the machine-executable instructions cause the processor to implement the above-described data processing method.
[0008] The embodiments of the present invention bring the following beneficial effects:
[0009] The aforementioned data processing method, apparatus, and electronic device receive a data query request and determine a first target data identifier based on the data query request. The first target data identifier is used to: indicate the data to be queried; determine, based on the first target data identifier, at least one data shard to which the data to be queried belongs, and a first target management process corresponding to the data shard; determine a target cache from at least one cache based on the first target data identifier, and query the data to be queried from the target cache; wherein the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, query the data to be queried from the database and save the data to be queried to the cache; and return the data to be queried to the device that sent the data query request. In this method, the data management process in the server corresponds to the data shard in the database, and the cache in the data management process corresponds to the identifier attribute. When a large amount of user data needs to be queried, the data to be queried is first queried from the cache corresponding to the identifier attribute. For data not found in the cache, it is then queried from the database. This method can reduce the query workload of the server and data, reduce the operating load, and ensure the normal operation of the server and data.
[0010] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0011] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0012] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0013] Figure 1 A schematic diagram illustrating a hardware scenario example provided in an embodiment of the present invention;
[0014] Figure 2 A flowchart of a data processing method provided in an embodiment of the present invention;
[0015] Figure 3 A flowchart of a data query method provided in an embodiment of the present invention;
[0016] Figure 4A flowchart of a data transaction method provided in an embodiment of the present invention;
[0017] Figure 5 A flowchart of a data publishing method provided in an embodiment of the present invention;
[0018] Figure 6 This is a schematic diagram of the structure of a data processing device provided in an embodiment of the present invention;
[0019] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] In existing technologies, for multi-user systems, when a user wants to query data related to a large number of target users and sends a query request, the system's server needs to query the database sequentially for each target user. When the number of target users is large, multiple data query operations are required. This query method results in a very high load on the server and database, thus affecting their normal operation. Based on this, the data processing method, apparatus, and electronic device provided in this invention can be applied to data processing scenarios to perform operations such as querying, publishing, and trading data. For example, in a game trading scenario, it can query data about all of a player's friends.
[0022] To facilitate understanding of this embodiment, a data processing method disclosed in this embodiment of the invention will first be described in detail. In this method, the data in the database is divided into multiple data shards; each data shard corresponds to a data management process; the data management process runs on a server, or the device on which the data management process runs is connected to the server; at least one cache is established in the data management process; the method is applied to the server.
[0023] Figure 1This is an example of a hardware scenario involved in an embodiment of the present invention. A database is a collection of large amounts of organized, shareable, and uniformly managed data that is stored long-term in a computer. In this embodiment, the data in the database is sharded into multiple data shards. For example, for a large amount of data in the database, it can be divided into n shards, resulting in n data shards. Then, for each data shard, the data ID (Identity) can be hashed, and the hash value can be modulo n to obtain n-1 numbers, which can serve as the identifier of the data shard. Additionally, the database can connect to a server to provide data, and the server can process the data in the database. In one specific implementation, the database is connected to a central server. In one approach, a data management process can run on the central server, which can handle messages from different processes. In another approach, the central server can have multiple devices, and the data management processes can be distributed across these devices, which can communicate with the server. It should be noted that the data management process can correspond one-to-one with the aforementioned data shards, allowing data to be sent only to the corresponding data management process for processing.
[0024] It is important to note that at least one cache must be established during the data management process. There are several ways to establish a cache, such as using LRU (Least Recently Used) or Redis (RemoteDictionary Server).
[0025] Furthermore, the central server can connect to multiple regional servers, such as Regional Server 1, Regional Server 2, etc. Taking the central server as a game server as an example, in a game, there are usually multiple different regions. The data for each region is stored on different lobby servers, and these different lobby servers share a central server. The data management process running on the central server can receive requests from all lobby servers. Therefore, the central server can process data from all different lobby servers, and players on different lobby servers can also access the data management process running on the central server to process their respective data information.
[0026] In this embodiment, the above data processing method can be implemented through a server, such as... Figure 2 As shown, the data processing method includes the following steps:
[0027] Step S202: Receive a data query request and determine a first target data identifier based on the data query request; wherein, the first target data identifier is used to: indicate the data to be queried;
[0028] Specifically, databases can be divided into relational databases and non-relational databases. Relational databases can be queried using SQL (Structured Query Language) statements, while non-relational databases use MongoDB (MongoDB Distributed Document Storage) query statements. Furthermore, data queries can include various types, such as select queries, parameter queries, and operation queries. Different types of data queries can be implemented using different query statements. Therefore, in practice, the implementation method of the data query request can be determined based on the database type and the type of data query.
[0029] Furthermore, a data query request can contain various information, such as the query path. From the data query request, a first target data identifier can be determined. This data identifier can have multiple forms, such as a unique identifier like an ID. This first target data identifier indicates the data to be queried. It should be noted that the data to be queried can be one or multiple. In one approach, the data query request carries the first target data identifier of the data to be queried. This first target data identifier can be a user identifier, data attribute identifier, etc., corresponding to the data to be queried.
[0030] Step S204: Based on the first target data identifier, determine at least one data shard to which the data to be queried belongs, and the first target management process corresponding to the data shard.
[0031] In this embodiment, a large amount of data in the database is divided into multiple data shards, each with its own identifier. A data management process is also assigned to each data shard. Therefore, after determining the first target data identifier, at least one data shard to which the data to be queried belongs can be determined based on this identifier. Specifically, if the data to be queried contains only one piece of data, or if multiple pieces of data are located in the same data shard, then the data to be queried belongs to one data shard. If the data to be queried includes multiple pieces of data distributed across different data shards, then the data to be queried belongs to multiple data shards.
[0032] Furthermore, the first target management process corresponding to the data shard to which the data to be queried belongs can be determined. There can be one or more first target management processes. Specifically, if the data shard to which the data to be queried belongs is single, then the first target management process is the data management process corresponding to that data shard; if the data shard to which the data to be queried belongs is multiple, then the first target management process is multiple data management processes each corresponding to a different data shard to which the data to be queried belongs.
[0033] Step S206: Based on the first target data identifier, determine the target cache from at least one cache, and query the data to be queried from the target cache; wherein, the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried cannot be found in the target cache, query the data to be queried from the database, and save the data to be queried to the cache;
[0034] Specifically, at least one cache is established within the data management process to accelerate data access and reduce query volume. In actual implementation, after determining the first target management process, the data to be queried can be retrieved from the cache of that first target management process. If the data to be queried can be found in the cache of the first target management process, there is no need to query the database. If the data to be queried cannot be found in the cache of the first target management process, that is, this is the first query or write to the data to be queried, then the data to be queried is retrieved from the database and saved to the cache. In this way, if the data to be queried is queried again in the future, it can be retrieved directly from the cache in the data management process without querying the database.
[0035] In this step, the data to be queried is retrieved from the cache of the first target management process. If the data is not found in the cache, it is retrieved from the database and then saved to the cache. On the one hand, this updates the cache, ensuring its accuracy and timeliness; on the other hand, retrieving the data from the cache reduces the load on the database.
[0036] Furthermore, the data management process can set up one or more caches, each corresponding to a specified identifier attribute. This identifier attribute can be categorized in various ways, such as friend relationship identifiers, organization identifiers, etc. Each identifier value corresponds to a cache, allowing different data to be queried to be retrieved from different caches.
[0037] Step S208: Return the data to be queried to the device that sent the data query request.
[0038] Finally, the retrieved data is returned to the device that sent the data query request, allowing the user to obtain the data and complete the data query task.
[0039] The aforementioned data processing method receives a data query request and determines a first target data identifier based on the request. This first target data identifier is used to: indicate the data to be queried; determine at least one data shard to which the data to be queried belongs, and a first target management process corresponding to that data shard, based on the first target data identifier; determine a target cache from at least one cache, and query the data to be queried from the target cache, based on the first target data identifier; the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, query the data to be queried from the database and save it to the cache; and return the data to be queried to the device that sent the data query request. In this method, the data management process in the server corresponds to the data shard in the database, and the cache in the data management process corresponds to the identifier attribute. When querying a large amount of user data, the data shard to which the data to be queried belongs and the corresponding data management process can be determined based on the data identifier. The data to be queried is first queried from the cache of that data management process; for data not found in the cache, it is then queried from the database. This method reduces the query workload of the server and data, lowers the operating load, and ensures the normal operation of the server and data.
[0040] The following examples illustrate specific implementation methods for determining the first target data identifier.
[0041] In one approach, the user identifier of the first user account that sent the data query request is determined; the target object that has a specified association with the first user account is determined, and the object identifier of the target object is determined as the first target data identifier.
[0042] Specifically, when using the client, users typically log in with a user account and then perform various operations, such as posting or querying information. In practice, each user account can be assigned a unique identifier to identify the user upon login. This identifier can be a unique identifier such as a user ID (Identity Document). Furthermore, for different servers or systems, different types of user accounts can establish specific associations with other users. For example, in an education system, user accounts can be categorized as those for staff in the academic affairs office, functional departments, teachers, and students. Teachers can log in using their teacher accounts to manage student attendance, exam scores, and other aspects of their class's performance; in this case, the aforementioned association is a management relationship. Similarly, in a game system, players can add friends after logging in with their user accounts; in this case, the aforementioned association is a friend relationship.
[0043] In practice, when a user sends a data query request through the client, the user identifier of the first user account sending the request can be obtained and determined. Then, the target object with a specified association with the first user account can be identified. There can be one or more target objects. Each target object also has a corresponding object identifier, which can also be implemented by setting an ID. Finally, the object identifier of the target object can be determined as the first target data identifier.
[0044] Furthermore, identify friend user accounts that have a friend relationship with the first user account, and determine the friend user identifier of the friend user account as the first target data identifier; and / or, if the first user account belongs to a first preset user organization, determine the organization identifier in the first preset user organization as the first target data identifier.
[0045] Taking a game system as an example, after the first user logs into the game, they can trade in-game items and need to query transaction data. At this point, a transaction data query request can be sent. If the player has added friends in the game, the target objects for determining the first user account's specified association can be identified by determining the friend user accounts that are friends with the first user account, and then using the friend user identifier of that friend user account as the first target data identifier. If the first user account has joined a game team or club, meaning the first user account belongs to a first preset user organization, the organization identifier of that first preset user organization can be used as the first target data identifier. This organization identifier can be used to distinguish different organizations in the game, similar to the function of the user identifier mentioned above. If the player has both friends and belongs to the first preset organization, then both the friend user identifier and the organization identifier of the first preset user organization can be used as the first target data identifier.
[0046] The following examples will describe a specific implementation of querying the data to be queried corresponding to the data identifier from the cache of the first target management process.
[0047] Establish an identifier list corresponding to the first target management process; wherein, the identifier list includes: data identifiers of at least some of the data to be queried; the at least some of the data to be queried belongs to the data shard to which the first target management process belongs; for the data identifiers in the identifier list, query the target cache for the data to be queried corresponding to the data identifiers.
[0048] In practice, a corresponding identifier list can be established for the first target management process. This identifier list can include at least some data identifiers of the data to be queried. In one specific implementation, the data to be queried can be data related to the friend user accounts of the first user account. The identifier list corresponding to the first target management process can then consist of several friend user identifiers that are friends with the first user account. It should be noted that at least some of the data to be queried is located in a database and belongs to a data shard corresponding to the first target management process. Based on this, for the data identifiers in the identifier list, that is, for the friend user identifiers of the first user account, the data related to the friend user account corresponding to the data identifier can be queried from the target cache on the first target management process.
[0049] In this embodiment, considering that a user account can have many friend user accounts, and each friend user account can have a lot of data, the data in the database can be divided into multiple data shards based on friend user identifiers. Then, for each data shard, a corresponding data management process can be set up. For each data process, a corresponding identifier list is created, which can include several friend user identifiers.
[0050] Furthermore, a friend data cache is established in the aforementioned data management process; a friend user identifier is obtained from the first target data identifier; wherein the friend user account corresponding to the friend user identifier has a friend relationship with the first user account that sent the data query request; and the data to be queried corresponding to the friend user identifier is queried from the friend data cache of the first target management process.
[0051] Specifically, at least one cache is set up in the data management process. The cache can improve data retrieval speed, directly serve the client, and reduce data interaction between the client and the server. In one specific implementation, a friend data cache can be established in the data management process. In actual implementation, the friend user identifier can be obtained from the first target data identifier, and then the data to be queried corresponding to the friend user identifier can be retrieved from the friend data cache of the first target data process. It should be noted that each friend user identifier corresponds to a friend user account, and the aforementioned friend user identifier and the first user account that sent the data query request have a friend relationship.
[0052] In this embodiment, a friend data cache is established in the data management process, which can be used to store the transaction information of all players, making it convenient for players to obtain the corresponding information through the friend user identifier.
[0053] In one specific implementation, user identifiers belonging to a first preset user organization are deleted from the friend user identifiers; wherein, the first user account that sends the data query request belongs to the first preset user organization.
[0054] Specifically, in the game, players and their friends can simultaneously join a game team or organization, or players can add friends from their own game team or club. That is, the first user account and its friend user accounts can both belong to a first preset user organization. Therefore, in actual implementation, when the first user account sending the data query request belongs to the first preset user organization, the user ID belonging to the first preset user organization can be deleted from the first user account's friend user IDs. For example, if the first user account has multiple friends with friend IDs id1, id2, id3, etc., and the first user account also belongs to the first preset user organization, when a friend with the user ID id1 also belongs to the first preset user organization, the friend ID id1 can be deleted from the friend user IDs.
[0055] In this step, when the first user account belongs to the first preset user organization, deleting the user identifier belonging to the first preset user organization from the friend user identifier can reduce the amount of data query.
[0056] The following embodiments further describe specific implementation methods for querying the data to be queried corresponding to the data identifier from the cache of the first target management process.
[0057] The above data management process establishes an organizational data cache; obtains an organizational identifier from the first target data identifier; wherein, the first user account that sends the data query request belongs to the first preset user organization corresponding to the organizational identifier; queries the data to be queried corresponding to the organizational identifier from the organizational data cache; wherein, the data to be queried corresponding to the organizational identifier includes: the data to be queried corresponding to each user account in the first preset user organization corresponding to the organizational identifier.
[0058] Specifically, in the data management process, an organizational data cache is also established. In actual implementation, the organizational identifier can be obtained from the first target data identifier. This organizational identifier corresponds to the first preset user organization to which the first user account sending the data query request belongs. There can be multiple user accounts in this first preset user organization. Then, the data to be queried corresponding to the organizational identifier can be queried from the aforementioned organizational data cache. Since there can be multiple user accounts in the first preset user organization corresponding to the organizational identifier, the data to be queried corresponding to the organizational identifier can include the relevant data corresponding to each user account in the first preset user organization.
[0059] In this embodiment, an organizational data cache is established in the data management process, which can be used to store all transaction information within the organization, making it convenient for players to obtain all the relevant club information at once.
[0060] For ease of understanding, the following will be used as... Figure 3 As an example, the specific process of data query is described in detail. In this embodiment, the user identifier is id, and the first preset user organization is a club.
[0061] Step S302: The customer queries transaction data; that is, the customer first sends a transaction data query request, and then executes step S304.
[0062] Step S304: The server queries the set of all friend IDs and club member IDs, and removes the club member IDs from the friend IDs. Specifically, a friend ID is the user identifier of a friend, and a club member ID is the user identifier of the first preset organization. The server queries all the player's friend IDs and the club member IDs to which the player belongs. If there are overlaps, for example, some friends and the player are in the same club, then the club member IDs belonging to the club can be deleted from the friend IDs. Then, steps S306 and S312 are executed respectively.
[0063] Step S306: Data is sharded according to friend ID. For each stub, a friend_list is created. For each friend_list, the corresponding stub is queried. Specifically, the data in the database can be divided into multiple data shards according to friend ID. Each data shard has its corresponding data management process. For each data management process, an identifier list can be created. Then, for each identifier list, data can be queried from the corresponding data management process. Then, step S308 is executed.
[0064] Step S308: For each ID in friend_list, query player_cache. For the parts that are successfully queried, if there is transaction information, return it uniformly. For the parts that are not in the cache, query the database and update player_cache. Specifically, for each friend in the identifier list, query the friend data cache in the data management process using the identifier. For the parts that are successfully queried in the friend data cache, if there is transaction information, return it uniformly. For the parts that are not successfully queried in the friend data cache, query the database and then update the friend data cache. Further, execute step S310.
[0065] Step S310: The server receives the transaction data and notifies the client. Specifically, the client sends the queried data to the server, and the server notifies the client after receiving the transaction data.
[0066] Step S312: Based on club_id, enter the stub corresponding to club_id; specifically, based on the organization identifier, determine the data management process corresponding to the organization identifier, and then execute step S314;
[0067] Step S314: Determine whether club_id is in club_cache; specifically, an organization data cache is also set in the data management process. Determine whether the organization identifier is in the organization data cache. If yes, proceed to step S318; otherwise, proceed to step S316.
[0068] Step S316: Query all transaction information of the club in the database and write it to the cache; specifically, if the organization identifier is not found in the organization data cache of the data management process, query the transaction information of the organization from the database and save it to the cache, and then execute step S318.
[0069] Step S318: Send the transaction information of all club members back to the server; that is, send the transaction information of all users in the first preset organization to the server, and then execute step S320.
[0070] In step S320, the server receives the transaction data and notifies the client. That is, the server notifies the client after receiving the transaction data.
[0071] The following embodiments provide a specific implementation method for data transactions.
[0072] Receive a data transaction request, which carries a second target data identifier for the data to be traded; determine the second target management process corresponding to the second target data identifier, and query the data to be traded from the cache of the second target management process; if the data to be traded is found in the cache of the second target management process, lock the data to be traded in the database; determine that the data to be traded has been successfully traded, and return a transaction success message to the device that sent the data transaction request.
[0073] Taking the game system as an example, after a second user account logs into the game, it can trade game items and send data transaction requests. These requests can include the identifier of the second target data to be traded. It should be noted that this second target data identifier can include the user identifier of the second user account that posted the data to be traded, and this identifier corresponds to the second target management process.
[0074] In one specific implementation, after receiving a data transaction request, the server obtains the second target data identifier carried in the request. Then, it can determine the second target management process corresponding to this second data identifier. This second target management process can also establish friend data caches and organization data caches. Further, from the friend data cache of the second target management process, it first checks whether the user identifier of the second user account is present. If the user identifier is not found in the second target management process, it retrieves the user identifier from the database and saves the data to the friend data cache. Then, it checks whether the cache contains data to be traded. If the user identifier is found in the second target management process, it checks the cache for data to be traded. If the data is found in the cache, it locks the data in the database to ensure the uniqueness of the transaction. After confirming the successful transaction of the data to be traded, it returns a successful transaction message to the device that sent the data transaction request.
[0075] Additionally, if the second user account identifier cannot be found in the database, and the cache is still not searched, the transaction will fail.
[0076] It should be noted that when the data to be traded can be retrieved from the cache of the second target management process, and the data to be traded is locked in the database, the atomic operation of MongoDB's find_and_modify can be used to simulate the locking operation to lock the data and ensure the uniqueness of the transaction.
[0077] Furthermore, the pending data is deleted from the second target management process and from the database; the first transaction object corresponding to the pending data is provided to the data transaction request sending device; and the second associated object corresponding to the pending data is provided to the data transaction publishing device.
[0078] Specifically, once a transaction is confirmed to be successful, the data to be traded can be deleted from the friend data cache and database of the second target management process, thus updating the cache and ensuring its correctness. Additionally, a first transaction object corresponding to the data to be traded can be provided to the device sending the data transaction request. This first transaction object can be items such as game props. Simultaneously, a second associated object corresponding to the transaction data can be provided to the publishing party of the data to be traded. This second associated object can be game coins or other items of equivalent value to the first transaction object.
[0079] The aforementioned second target data identifier includes: the user identifier of the second user account that published the data to be traded; the organization identifier of the target organization to which the second user account belongs; the target data management process corresponding to the organization identifier of the target organization; and the data to be traded is deleted from the cache of the target data management process.
[0080] In practice, the aforementioned second target data may include the user identifier of the second user account that published the data to be traded. This second user account may also belong to a user organization; therefore, the organization identifier of the target organization to which the second user account belongs can also be determined. Then, the target data management process corresponding to the organization identifier of this target organization is determined. This target data management process also establishes friend data cache and organization data cache. Furthermore, the data to be traded is deleted from the organization data cache of this target data management process to update the cache and ensure its correctness.
[0081] In one specific approach, if no transaction data is found in the cache of the second target management process, the transaction data is retrieved from the database and saved to the cache. Specifically, if no transaction data is found in the friend data cache of the second target management process, the database can be checked for the existence of transaction data. If the transaction data is found in the database, it is saved to the cache.
[0082] The following embodiment provides a specific implementation method for transaction failure.
[0083] If the data to be traded cannot be found in either the cache or the database of the second target management process, the transaction is deemed to have failed; or, if locking the data to be traded in the database fails, the transaction is deemed to have failed. Specifically, in one approach, if the data to be traded is not found in either the cache or the database of the second target management process—for example, if the second user account that published the data to be traded is in the cache of the second target management process, but the data to be traded is not in the cache—it can be assumed that the transaction information has expired, and the transaction is deemed to have failed. In another approach, if locking the data to be traded in the database fails, the transaction is also deemed to have failed.
[0084] For ease of understanding, the following will be used as... Figure 4 As an example, a specific process for a data transaction is introduced.
[0085] Step S402: The player requests to trade a certain transaction information; specifically, after the second user account logs into the game, it can request to trade a certain transaction information, such as requesting to trade each game item, and then proceed to step S404.
[0086] Step S404: The server first deducts the item; specifically, after the second user account applies to trade a certain game item, the server first deducts the game item, and then executes step S406.
[0087] Step S406: Enter the stub corresponding to the player_id to be traded; specifically, connect to the second target management process corresponding to the user identifier of the second user account, and then execute step S408;
[0088] Step S408: Determine whether the player_id is in the player_cache; specifically, if the user identifier of the second user account exists in the friend data cache, proceed to step S410; if the user identifier of the second user account does not exist in the friend data cache, proceed to step S412.
[0089] Step S410: Query the database and store the player_id data in player_cache; specifically, if the user identifier of the second user account does not exist in the friend data cache, query the database for the user identifier and save the data corresponding to the user identifier to the friend data cache, and then execute step S412.
[0090] Step S412: Determine whether the transaction is in the cache; if it exists, proceed to step S414; if it does not exist, proceed to step S418.
[0091] Step S414: Attempt to lock the transaction in the database and determine if the locking was successful; if successful, proceed to step S416; if unsuccessful, proceed to step S418.
[0092] Step S416: Delete the transaction information from the database; delete the transaction information from the player_cache; notify the server of the successful transaction and send the trade items; notify the player being traded and send the items; access the stub corresponding to the club_id of the player being traded and update the club_cache; specifically, after confirming the successful transaction, send the trade items to the player who requested the trade and to the player being traded, and update the friend data cache and organization data cache to ensure the correctness and timeliness of the cache. End.
[0093] Step S418: The transaction fails, and the deducted items are returned. Specifically, if the transaction fails, the server needs to return the items previously downloaded to the player who requested the transaction.
[0094] The following example provides a specific implementation method for data publishing.
[0095] The system receives a data publishing request, which carries the data to be published and the target user identifier of the third user account that sent the data publishing request; it determines the target data fragment and the corresponding third target management process based on the target user identifier; it queries the cache of the third target management process to see if the target user identifier exists; if the target user identifier exists in the cache of the third target management process, it saves the data to be published to the cache and database of the third target management process respectively; and it returns a publishing success message to the device that sent the data publishing request.
[0096] Taking a game system as an example, after logging into the game, a third-party user account can publish various information within the game, thus requiring a data publishing request. This request can carry the data to be published and the target user identifier of the third-party user account sending the request. Upon receiving the data publishing request, the server can determine the target data shard based on the target user identifier. It should be noted that when sharding data in the database, the division can be based on user identifiers, ensuring a correspondence between user identifiers and data shards. Therefore, the target data shard can be determined based on the target user identifier. Furthermore, since this embodiment sets a one-to-one correspondence between data shards and data management processes, the third target management process corresponding to the target data shard can also be determined based on the target user identifier.
[0097] Then, the system checks the cache of the third target management process to see if the target user identifier exists. If the target user identifier can be found in the cache of the third target management process, the data to be published can be saved to the cache of the third target management process and the database respectively, thereby updating the cache of the third target management process. Finally, the system returns a successful publication message to the device that sent the data publication request.
[0098] In one approach, if the target user identifier is not present in the cache of the third target management process, the transaction data corresponding to the target user identifier is retrieved from the database and saved to the cache of the third target management process; if the transaction data corresponding to the target user identifier cannot be retrieved from the database, the target user identifier is saved in both the cache of the third target management process and the database.
[0099] Specifically, if the target user identifier does not exist in the cache of the third target management process, then all transaction data corresponding to the target user identifier are queried from the database. If the user corresponding to the target user identifier has transaction data, then after obtaining all the transaction data corresponding to the target user identifier, the transaction data corresponding to the target user account identifier is saved to the friend data cache of the third target management process. If the user corresponding to the target user identifier does not have transaction data, that is, the transaction data corresponding to the target user identifier cannot be obtained from the database, then the target user identifier can be saved in the cache of the third target management process and in the database.
[0100] Furthermore, based on the target user identifier, query whether the third user account belongs to the second preset user organization; if the third user account belongs to the second preset user organization, determine the fourth target management process corresponding to the second preset user organization based on the organization identifier of the second preset user organization; determine whether the organization identifier of the second preset user organization exists in the cache of the fourth target management process; if the organization identifier of the second preset user organization exists in the cache of the fourth target management process, save the data to be published to the cache of the fourth target management process.
[0101] In practice, based on the target user identifier, it can be queried whether the third user account belongs to the second preset user organization, which can be a game team, club, etc. If the third user account belongs to the second preset user organization, then based on the organization identifier of the second preset user organization, the fourth target management process corresponding to the second preset user organization can be determined. This fourth target management process has an organization data cache. Further, it is queried whether the organization identifier of the second preset user organization exists in the organization data cache of the fourth target management process. If the organization identifier of the second preset organization exists in the fourth target management process, the data to be published can be saved to the cache of the fourth target management process to update the cache in the fourth target management process.
[0102] In one specific implementation, if the organization identifier of the second preset user organization does not exist in the cache of the fourth target management process, the transaction data of the second preset user organization is retrieved from the database and saved to the cache of the fourth target management process. Specifically, if the organization identifier of the second preset user organization does not exist in the cache of the fourth target management process, then the transaction data of the second preset user organization is queried from the database and saved to the cache of the fourth target management process.
[0103] For ease of understanding, the following will be used as... Figure 5 As an example, a specific process for data publishing is introduced.
[0104] Step S502: The client publishes the player's transaction data; specifically, the player can publish transaction data through the client, and then step S504 is executed.
[0105] Step S504: The server deducts items; generates a unique ID for the transaction; stores the transaction data of this ID in the virtual store; performs data sharding based on the player ID and connects it to the corresponding stub. Specifically, after receiving the published transaction data, the server will first deduct items and generate a unique ID for this transaction, and save the transaction data of this ID in the virtual store. In addition, the data in the database can be sharded based on the user identifier, and the data shards can be connected to the corresponding data management process. Then, step S506 is executed.
[0106] Step S506: Check if the corresponding player's ID exists in the cache; specifically, the corresponding player's ID can be the target user identifier of the third user account mentioned above. If the corresponding player's ID is not in the cache, proceed to step S508; if the corresponding player's ID is in the cache, proceed to step S510.
[0107] Step S508: Query all transaction information of the player in the database and store it in player_cache. If there is no information, store it in an empty dictionary. Specifically, when the corresponding player's ID is not in the cache, query all transaction information of the player in the database and save the transaction information in the friend data cache. If the player has no transaction information, save it in an empty cache dictionary. Then, execute S510.
[0108] Step S510: Use the previously generated unique ID as the _id of MongoDB and store the transaction information in the database. Specifically, the generated unique ID can be used as the ID of the atomic operation to ensure the uniqueness of the transaction. Save the transaction information to the database, and then execute steps S512, S516, and S518 respectively.
[0109] Step S512: Notify the server to publish the successful transaction number and store it in the virtual mall; then, execute step S514;
[0110] Step S514: Notify the client that the publication was successful.
[0111] Step S516: The transaction information is updated in player_cache.
[0112] Step S518: Is there a club? Specifically, determine whether the corresponding player has joined a club. If yes, proceed to step S520; otherwise, proceed to step S528.
[0113] Step S520: The transaction data is entered into the stub of the corresponding club_id; specifically, if the player has joined a club, the transaction data is connected to the data management process corresponding to the organization identifier to which the player belongs, and then step S522 is executed.
[0114] Step S522: Determine whether club_id is in club_cache. Specifically, determine whether the organization identifier is in the organization data management process. If yes, proceed to step S524; otherwise, proceed to step S526.
[0115] Step S524, update the cache; specifically, if the organization identifier exists in the organization data management process, update the cache of the organization data management process.
[0116] Step S526: Query all transaction information of the club in the database and write it to the cache; specifically, if the organization identifier does not exist in the organization data management process, query the transaction information of all organization users in the organization from the database and then save it to the cache.
[0117] Step S528, End.
[0118] Taking in-game item trading as an example, for the caching in the data management process, it's unnecessary to read all transaction data from the database at once when the server is started. Data can be queried and saved to the database simultaneously. For users or pre-defined organizations whose transaction data is not found, the user account's user ID and organization ID can be saved in the corresponding cache as markers to prevent duplicate database queries and reduce database load. Furthermore, if an error occurs in a data management process, there's no need to process the data corresponding to that process; simply restarting the process is sufficient, demonstrating high disaster recovery capabilities.
[0119] Before each query, write, or delete of transaction data, the cache can be checked first. If the user's identifier is not found in the cache, it can be retrieved from the database and then written to the cache (i.e., saved to the cache) before other operations are performed. This avoids the problem of inaccurate cached data caused by operating on the database first and then updating the cache. Therefore, this embodiment ensures the accuracy and timeliness of the cache.
[0120] In addition, in this embodiment, MongoDB's find_and_modify function is used to lock the data transactions, ensuring the uniqueness of the transactions.
[0121] For the above method embodiments, see Figure 6 The diagram shows a structural schematic of a data processing device. Data in the database is divided into multiple data shards; each data shard corresponds to a data management process; the data management process runs on a server, or the device running the data management process is communicatively connected to the server; at least one cache is established within the data management process; the device is located on the server; the device includes:
[0122] The receiving module 62 is used to receive a data query request and determine a first target data identifier based on the data query request; wherein the first target data identifier is used to indicate the data to be queried;
[0123] The determination module 64 is used to determine, based on the first target data identifier, at least one data shard to which the data to be queried belongs, and the first target management process corresponding to the data shard;
[0124] The query module 66 is used to determine the target cache from at least one cache based on the first target data identifier, and query the data to be queried from the target cache; wherein the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, the data to be queried is queried from the database and the data to be queried is saved to the cache;
[0125] Return module 68 is used to return the data to be queried to the device that sent the data query request.
[0126] The aforementioned data processing device receives a data query request and determines a first target data identifier based on the request. This first target data identifier is used to: indicate the data to be queried; determine at least one data shard to which the data to be queried belongs, and a first target management process corresponding to that data shard, based on the first target data identifier; determine a target cache from at least one cache, and query the data to be queried from the target cache, based on the first target data identifier; the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, query the data to be queried from the database and save it to the cache; and return the data to be queried to the device that sent the data query request. In this method, the data management process in the server corresponds to the data shard in the database, and the cache in the data management process corresponds to the identifier attribute. When querying a large amount of user data, the data shard to which the data to be queried belongs and the corresponding data management process can be determined based on the data identifier. The data to be queried is first queried from the cache of the data management process; for data not found in the cache, it is then queried from the database. This method reduces the query workload of the server and data, lowers the operating load, and ensures the normal operation of the server and data.
[0127] The receiving module is further configured to: determine the user identifier of the first user account that sent the data query request; determine the target object that has a specified association with the first user account, and determine the object identifier of the target object as the first target data identifier.
[0128] The receiving module is further configured to: determine a friend user account that has a friend relationship with the first user account, and determine the friend user identifier of the friend user account as the first target data identifier; and / or, if the first user account belongs to a first preset user organization, determine the organization identifier in the first preset user organization as the first target data identifier.
[0129] The query module described above is also used to: establish an identifier list corresponding to the first target management process; wherein the identifier list includes: data identifiers of at least some of the data to be queried; the at least some of the data to be queried belongs to the data shard to which the first target management process belongs; and query the target cache for the data to be queried corresponding to the data identifier in the identifier list.
[0130] The aforementioned data management process includes a friend data cache; the aforementioned query module is also used to: obtain a friend user identifier from the first target data identifier; wherein the friend user account corresponding to the friend user identifier has a friend relationship with the first user account that sent the data query request; and query the data to be queried corresponding to the friend user identifier from the friend data cache of the first target management process.
[0131] The aforementioned device further includes: a deletion module, used to: delete user identifiers belonging to a first preset user organization from friend user identifiers; wherein the first user account that sent the data query request belongs to the first preset user organization.
[0132] The aforementioned data management process establishes an organizational data cache; the aforementioned query module is also used to: obtain an organizational identifier from a first target data identifier; wherein, the first user account that sends the data query request belongs to a first preset user organization corresponding to the organizational identifier; query the data to be queried corresponding to the organizational identifier from the organizational data cache; wherein, the data to be queried corresponding to the organizational identifier includes: the data to be queried corresponding to each user account in the first preset user organization corresponding to the organizational identifier.
[0133] The aforementioned apparatus further includes a transaction module, configured to: receive a data transaction request, wherein the data transaction request carries a second target data identifier of the data to be traded; determine the second target management process corresponding to the second target data identifier, and query the data to be traded from the cache of the second target management process; if the data to be traded is found in the cache of the second target management process, lock the data to be traded in the database; determine that the data to be traded has been successfully traded, and return a transaction success message to the device that sent the data transaction request.
[0134] The aforementioned transaction module is also used to: delete the data to be traded from the second target management process, delete the data to be traded from the database; provide the first transaction object corresponding to the data to be traded to the data transaction request sending device; and provide the second associated object corresponding to the data to be traded to the data to be traded publishing device.
[0135] The aforementioned second target data identifier includes: the user identifier of the second user account that published the data to be traded; the aforementioned transaction module is also used to: determine the organization identifier of the target organization to which the second user account belongs; determine the target data management process corresponding to the organization identifier of the target organization; and delete the data to be traded from the cache of the target data management process.
[0136] The aforementioned device further includes: a first storage module, configured to: if no transaction data is found in the cache of the second target management process, query the transaction data from the database and save the transaction data to the cache.
[0137] The aforementioned apparatus further includes a transaction determination module, configured to: determine transaction failure if the data to be traded cannot be found in the cache or database of the second target management process; or determine transaction failure if locking the data to be traded in the database fails.
[0138] The aforementioned apparatus further includes: a publishing module, configured to: receive a data publishing request, the data publishing request carrying data to be published and a target user identifier of a third user account that sent the data publishing request; determine a target data fragment and a third target management process corresponding to the target data fragment based on the target user identifier; query whether the target user identifier exists in the cache of the third target management process; if the target user identifier exists in the cache of the third target management process, save the data to be published to the cache and database of the third target management process respectively; and return a publishing success message to the device that sent the data publishing request.
[0139] The aforementioned device further includes: a second storage module, configured to, if the target user identifier is not present in the cache of the third target management process, retrieve the transaction data corresponding to the target user identifier from the database and save the transaction data corresponding to the target user identifier to the cache of the third target management process; if the transaction data corresponding to the target user identifier cannot be retrieved from the database, save the target user identifier in both the cache of the third target management process and the database.
[0140] The aforementioned device further includes: a third storage module, used to query whether a third user account belongs to a second preset user organization based on the target user identifier; if the third user account belongs to the second preset user organization, determine the fourth target management process corresponding to the second preset user organization based on the organization identifier of the second preset user organization; determine whether the organization identifier of the second preset user organization exists in the cache of the fourth target management process; if the organization identifier of the second preset user organization exists in the cache of the fourth target management process, save the data to be published to the cache of the fourth target management process.
[0141] The above-mentioned device further includes: a fourth storage module, used to: if the organization identifier of the second preset user organization does not exist in the cache of the fourth target management process, retrieve the transaction data of the second preset user organization from the database, and save the transaction data of the second preset user organization to the cache of the fourth target management process.
[0142] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described data processing method. This electronic device can be a server or a terminal device.
[0143] See Figure 7 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the above-described data processing method.
[0144] Furthermore, Figure 7 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 100, the communication interface 103 and the memory 101 connected via the bus 102.
[0145] The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0146] Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101, and the processor 100 reads the information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0147] The processor in the aforementioned electronic device can perform the following operations in the aforementioned data processing method by executing machine-executable instructions:
[0148] The system receives a data query request and determines a first target data identifier based on the request. The first target data identifier is used to: indicate the data to be queried; determine at least one data shard to which the data to be queried belongs, and a first target management process corresponding to the data shard, based on the first target data identifier; determine a target cache from at least one cache, and query the data to be queried from the target cache, based on the first target data identifier; the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, query the data to be queried from the database and save the data to be queried to the cache; and return the data to be queried to the device that sent the data query request.
[0149] In this approach, the data management process on the server corresponds to the data shards in the database, and the cache and identifier attributes within the data management process also correspond. When querying a large amount of user data, the data shard and corresponding data management process to which the data to be queried belongs can be determined based on the data identifier. The data to be queried is first retrieved from the cache of that data management process. If the data cannot be found in the cache, it is then retrieved from the database. This approach reduces the workload of server and data queries, lowers the operating load, and ensures the normal operation of the server and data.
[0150] Determine the user identifier of the first user account that sent the data query request; determine the target object that has a specified association with the first user account, and determine the object identifier of the target object as the first target data identifier.
[0151] Identify friend user accounts that have a friend relationship with the first user account, and determine the friend user identifier of the friend user account as the first target data identifier; and / or, if the first user account belongs to a first preset user organization, determine the organization identifier in the first preset user organization as the first target data identifier.
[0152] Establish an identifier list corresponding to the first target management process; wherein, the identifier list includes: data identifiers of at least some of the data to be queried; the at least some of the data to be queried belongs to the data shard to which the first target management process belongs; for the data identifiers in the identifier list, query the target cache for the data to be queried corresponding to the data identifiers.
[0153] The aforementioned data management process includes establishing a friend data cache; obtaining a friend user identifier from the first target data identifier; wherein the friend user account corresponding to the friend user identifier has a friend relationship with the first user account that sent the data query request; and querying the data to be queried corresponding to the friend user identifier from the friend data cache of the first target management process.
[0154] In this embodiment, a friend data cache is established in the data management process, which can be used to store the transaction information of all players, making it convenient for players to obtain the corresponding information through the friend user identifier.
[0155] Remove the user identifier belonging to the first preset user organization from the friend user identifier; wherein, the first user account that sent the data query request belongs to the first preset user organization.
[0156] The above data management process establishes an organizational data cache; obtains an organizational identifier from the first target data identifier; wherein, the first user account that sends the data query request belongs to the first preset user organization corresponding to the organizational identifier; queries the data to be queried corresponding to the organizational identifier from the organizational data cache; wherein, the data to be queried corresponding to the organizational identifier includes: the data to be queried corresponding to each user account in the first preset user organization corresponding to the organizational identifier.
[0157] In this embodiment, an organizational data cache is established in the data management process, which can be used to store all transaction information within the organization, making it convenient for players to obtain all the relevant club information at once.
[0158] Receive a data transaction request, which carries a second target data identifier for the data to be traded; determine the second target management process corresponding to the second target data identifier, and query the data to be traded from the cache of the second target management process; if the data to be traded is found in the cache of the second target management process, lock the data to be traded in the database; determine that the data to be traded has been successfully traded, and return a transaction success message to the device that sent the data transaction request.
[0159] Delete the data to be traded from the database in the second target management process; provide the first transaction object corresponding to the data to be traded to the data transaction request sending device; provide the second associated object corresponding to the data to be traded to the data publishing device.
[0160] The aforementioned second target data identifier includes: the user identifier of the second user account that published the data to be traded; the organization identifier of the target organization to which the second user account belongs; the target data management process corresponding to the organization identifier of the target organization; and the data to be traded is deleted from the cache of the target data management process.
[0161] If the data to be traded cannot be found in the cache of the second target management process, the data to be traded is retrieved from the database and saved to the cache.
[0162] If the data to be traded cannot be found in the cache or database of the second target management process, the transaction is determined to have failed; or, if locking the data to be traded in the database fails, the transaction is determined to have failed.
[0163] The system receives a data publishing request, which carries the data to be published and the target user identifier of the third user account that sent the data publishing request; it determines the target data fragment and the corresponding third target management process based on the target user identifier; it queries the cache of the third target management process to see if the target user identifier exists; if the target user identifier exists in the cache of the third target management process, it saves the data to be published to the cache and database of the third target management process respectively; and it returns a publishing success message to the device that sent the data publishing request.
[0164] If the target user identifier is not found in the cache of the third target management process, the transaction data corresponding to the target user identifier is retrieved from the database and saved to the cache of the third target management process; if the transaction data corresponding to the target user identifier cannot be retrieved from the database, the target user identifier is saved in both the cache of the third target management process and the database.
[0165] Based on the target user identifier, query whether the third user account belongs to the second preset user organization; if the third user account belongs to the second preset user organization, determine the fourth target management process corresponding to the second preset user organization based on the organization identifier of the second preset user organization; determine whether the organization identifier of the second preset user organization exists in the cache of the fourth target management process; if the organization identifier of the second preset user organization exists in the cache of the fourth target management process, save the data to be published to the cache of the fourth target management process.
[0166] If the organization identifier of the second preset user organization is not found in the cache of the fourth target management process, the transaction data of the second preset user organization is retrieved from the database and saved to the cache of the fourth target management process.
[0167] This embodiment also provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions cause the processor to implement the above-described data processing method.
[0168] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the aforementioned data processing method:
[0169] The system receives a data query request and determines a first target data identifier based on the request. The first target data identifier is used to: indicate the data to be queried; determine at least one data shard to which the data to be queried belongs, and a first target management process corresponding to the data shard, based on the first target data identifier; determine a target cache from at least one cache, and query the data to be queried from the target cache, based on the first target data identifier; the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, query the data to be queried from the database and save the data to be queried to the cache; and return the data to be queried to the device that sent the data query request.
[0170] In this approach, the data management process on the server corresponds to the data shards in the database, and the cache and identifier attributes within the data management process also correspond. When querying a large amount of user data, the data shard and corresponding data management process to which the data to be queried belongs can be determined based on the data identifier. The data to be queried is first retrieved from the cache of that data management process. If the data cannot be found in the cache, it is then retrieved from the database. This approach reduces the workload of server and data queries, lowers the operating load, and ensures the normal operation of the server and data.
[0171] Determine the user identifier of the first user account that sent the data query request; determine the target object that has a specified association with the first user account, and determine the object identifier of the target object as the first target data identifier.
[0172] Identify friend user accounts that have a friend relationship with the first user account, and determine the friend user identifier of the friend user account as the first target data identifier; and / or, if the first user account belongs to a first preset user organization, determine the organization identifier in the first preset user organization as the first target data identifier.
[0173] Establish an identifier list corresponding to the first target management process; wherein, the identifier list includes: data identifiers of at least some of the data to be queried; the at least some of the data to be queried belongs to the data shard to which the first target management process belongs; for the data identifiers in the identifier list, query the target cache for the data to be queried corresponding to the data identifiers.
[0174] The aforementioned data management process includes establishing a friend data cache; obtaining a friend user identifier from the first target data identifier; wherein the friend user account corresponding to the friend user identifier has a friend relationship with the first user account that sent the data query request; and querying the data to be queried corresponding to the friend user identifier from the friend data cache of the first target management process.
[0175] In this embodiment, a friend data cache is established in the data management process, which can be used to store the transaction information of all players, making it convenient for players to obtain the corresponding information through the friend user identifier.
[0176] Remove the user identifier belonging to the first preset user organization from the friend user identifier; wherein, the first user account that sent the data query request belongs to the first preset user organization.
[0177] The above data management process establishes an organizational data cache; obtains an organizational identifier from the first target data identifier; wherein, the first user account that sends the data query request belongs to the first preset user organization corresponding to the organizational identifier; queries the data to be queried corresponding to the organizational identifier from the organizational data cache; wherein, the data to be queried corresponding to the organizational identifier includes: the data to be queried corresponding to each user account in the first preset user organization corresponding to the organizational identifier.
[0178] In this embodiment, an organizational data cache is established in the data management process, which can be used to store all transaction information within the organization, making it convenient for players to obtain all the relevant club information at once.
[0179] Receive a data transaction request, which carries a second target data identifier for the data to be traded; determine the second target management process corresponding to the second target data identifier, and query the data to be traded from the cache of the second target management process; if the data to be traded is found in the cache of the second target management process, lock the data to be traded in the database; determine that the data to be traded has been successfully traded, and return a transaction success message to the device that sent the data transaction request.
[0180] Delete the data to be traded from the database in the second target management process; provide the first transaction object corresponding to the data to be traded to the data transaction request sending device; provide the second associated object corresponding to the data to be traded to the data publishing device.
[0181] The aforementioned second target data identifier includes: the user identifier of the second user account that published the data to be traded; the organization identifier of the target organization to which the second user account belongs; the target data management process corresponding to the organization identifier of the target organization; and the data to be traded is deleted from the cache of the target data management process.
[0182] If the data to be traded cannot be found in the cache of the second target management process, the data to be traded is retrieved from the database and saved to the cache.
[0183] If the data to be traded cannot be found in the cache or database of the second target management process, the transaction is determined to have failed; or, if locking the data to be traded in the database fails, the transaction is determined to have failed.
[0184] The system receives a data publishing request, which carries the data to be published and the target user identifier of the third user account that sent the data publishing request; it determines the target data fragment and the corresponding third target management process based on the target user identifier; it queries the cache of the third target management process to see if the target user identifier exists; if the target user identifier exists in the cache of the third target management process, it saves the data to be published to the cache and database of the third target management process respectively; and it returns a publishing success message to the device that sent the data publishing request.
[0185] If the target user identifier is not found in the cache of the third target management process, the transaction data corresponding to the target user identifier is retrieved from the database and saved to the cache of the third target management process; if the transaction data corresponding to the target user identifier cannot be retrieved from the database, the target user identifier is saved in both the cache of the third target management process and the database.
[0186] Based on the target user identifier, query whether the third user account belongs to the second preset user organization; if the third user account belongs to the second preset user organization, determine the fourth target management process corresponding to the second preset user organization based on the organization identifier of the second preset user organization; determine whether the organization identifier of the second preset user organization exists in the cache of the fourth target management process; if the organization identifier of the second preset user organization exists in the cache of the fourth target management process, save the data to be published to the cache of the fourth target management process.
[0187] If the organization identifier of the second preset user organization is not found in the cache of the fourth target management process, the transaction data of the second preset user organization is retrieved from the database and saved to the cache of the fourth target management process.
[0188] The computer program products of the data processing methods, apparatus, and electronic devices provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementations, please refer to the method embodiments, which will not be repeated here.
[0189] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0190] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0191] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0192] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0193] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A data processing method, characterized in that, The data in the database is divided into multiple data shards; each data shard corresponds to a data management process; the data management process runs on a server, or the device on which the data management process runs is connected to the server. At least one cache is established in the data management process; The method is applied to the server; the method includes: Receive a data query request, and determine a first target data identifier based on the data query request; wherein, the first target data identifier is used to: indicate the data to be queried; Based on the first target data identifier, at least one data shard to which the data to be queried belongs, and the first target management process corresponding to the data shard; Based on the first target data identifier, a target cache is determined from the at least one cache, and the data to be queried is queried from the target cache; wherein, the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, the data to be queried is queried from the database, and the data to be queried is saved to the cache; The device that sent the data query request returns the data to be queried; The method further includes: Receive a data publishing request, the data publishing request carrying the data to be published, and the target user identifier of the third user account that sent the data publishing request; The target data shards and the corresponding third target management processes are determined based on the target user identifiers. Check if the target user identifier exists in the cache of the third target management process; If the target user identifier exists in the cache of the third target management process, the data to be published is saved to both the cache of the third target management process and the database. The device that sent the data publishing request returned a publishing success message; Before the step of returning a publication success message to the device that sent the data publication request, the method further includes: Based on the target user identifier, query whether the third user account belongs to the second preset user organization; If the third user account belongs to the second preset user organization, the fourth target management process corresponding to the second preset user organization is determined based on the organization identifier of the second preset user organization; Determine whether the organization identifier of the second preset user organization exists in the cache of the fourth target management process; If the organization identifier of the second preset user organization exists in the cache of the fourth target management process, the data to be published is saved to the cache of the fourth target management process.
2. The method according to claim 1, characterized in that, The step of determining the first target data identifier based on the data query request includes: Determine the user identifier of the first user account that sent the data query request; Identify a target object that has a specified association with the first user account, and determine the object identifier of the target object as the first target data identifier.
3. The method according to claim 2, characterized in that, The step of identifying a target object that has a specified association with the first user account and determining the object identifier of the target object as the first target data identifier includes: Identify friend user accounts that have a friend relationship with the first user account, and determine the friend user identifier of the friend user account as the first target data identifier; And / or, if the first user account belongs to a first preset user organization, the organization identifier in the first preset user organization is determined as the first target data identifier.
4. The method according to claim 1, characterized in that, The step of retrieving the data to be queried from the target cache includes: Establish an identifier list corresponding to the first target management process; wherein, the identifier list includes: data identifiers of at least some of the data to be queried; the at least some of the data to be queried belongs to the data fragment to which the first target management process belongs; For each data identifier in the identifier list, query the target cache for the data to be queried corresponding to that data identifier.
5. The method according to claim 1, characterized in that, The data management process establishes a friend data cache; the step of querying the data to be queried from the target cache includes: Obtain the friend user identifier from the first target data identifier; wherein the friend user account corresponding to the friend user identifier has a friend relationship with the first user account that sent the data query request; Retrieve the data to be queried corresponding to the friend user identifier from the friend data cache of the first target management process.
6. The method according to claim 5, characterized in that, After the step of obtaining the friend user identifier from the first target data identifier, the method further includes: Remove the user identifier belonging to the first preset user organization from the friend user identifiers; wherein, the first user account that sent the data query request belongs to the first preset user organization.
7. The method according to claim 1, characterized in that, An organized data cache is established within the data management process; The step of querying the data to be queried from the target cache includes: Obtain the organization identifier from the first target data identifier; wherein the first user account that sends the data query request belongs to the first preset user organization corresponding to the organization identifier; Query the data to be queried corresponding to the organization identifier from the organization data cache; wherein, the data to be queried corresponding to the organization identifier includes: the data to be queried corresponding to each user account in the first preset user organization corresponding to the organization identifier.
8. The method according to claim 1, characterized in that, After the step of returning the data to be queried to the device that sent the data query request, the method further includes: Receive a data transaction request, wherein the data transaction request carries a second target data identifier of the data to be traded; Determine the second target management process corresponding to the second target data identifier, and query the data to be traded from the cache of the second target management process; If the data to be traded is found in the cache of the second target management process, the data to be traded is locked in the database; Once the transaction of the data to be traded is confirmed to be successful, a transaction success message is returned to the device that sent the data transaction request.
9. The method according to claim 8, characterized in that, After determining that the data transaction to be traded has been successful and returning transaction success information to the device that sent the data transaction request, the method further includes: Delete the pending transaction data from the second target management process and delete the pending transaction data from the database. The device that sends the data transaction request provides a first transaction object corresponding to the data to be traded; the device that publishes the data to be traded provides a second associated object corresponding to the data to be traded.
10. The method according to claim 8, characterized in that, The second target data identifier includes: the user identifier of the second user account that published the data to be traded; after the step of determining that the data to be traded has been successfully traded and returning transaction success information to the device that sent the data transaction request, the method further includes: Determine the organization identifier of the target organization to which the second user account belongs; Determine the target data management process corresponding to the organization identifier of the target organization; Delete the data to be traded from the cache of the target data management process.
11. The method according to claim 8, characterized in that, The method further includes: If the data to be traded cannot be found in the cache of the second target management process, the data to be traded is retrieved from the database and saved to the cache.
12. The method according to claim 8, characterized in that, The method further includes: If the data to be traded cannot be found in the cache of the second target management process or in the database, the transaction is determined to have failed. Alternatively, if locking the data to be traded in the database fails, the transaction is deemed to have failed.
13. The method according to claim 1, characterized in that, The method further includes: If the target user identifier is not present in the cache of the third target management process, the transaction data corresponding to the target user identifier is retrieved from the database and saved to the cache of the third target management process. If the transaction data corresponding to the target user identifier cannot be obtained from the database, the target user identifier is stored in the cache of the third target management process and in the database.
14. The method according to claim 1, characterized in that, The method further includes: If the organization identifier of the second preset user organization is not present in the cache of the fourth target management process, the transaction data of the second preset user organization is retrieved from the database and saved to the cache of the fourth target management process.
15. A data processing apparatus, characterized in that, The data in the database is divided into multiple data shards; each data shard corresponds to a data management process; the data management process runs on a server, or the device on which the data management process runs is connected to the server. At least one cache is established in the data management process; The device is disposed on the server; the device includes: A receiving module is configured to receive a data query request and determine a first target data identifier based on the data query request; wherein, the first target data identifier is used to: indicate the data to be queried; The determination module is used to determine, based on the first target data identifier, at least one data shard to which the data to be queried belongs, and the first target management process corresponding to the data shard; A query module is configured to determine a target cache from the at least one cache based on the first target data identifier, and query the data to be queried from the target cache; wherein the target cache corresponds to the identifier attribute of the first target data identifier; if the data to be queried is not found in the target cache, the data to be queried is queried from the database, and the data to be queried is saved to the cache; The return module is used to return the data to be queried to the device that sent the data query request; The publishing module is used to receive a data publishing request, which carries the data to be published and the target user identifier of the third user account that sent the data publishing request; determine the target data fragment and the third target management process corresponding to the target data fragment based on the target user identifier; query whether the target user identifier exists in the cache of the third target management process; if the target user identifier exists in the cache of the third target management process, save the data to be published to the cache of the third target management process and the database respectively; and return a publishing success message to the device that sent the data publishing request. The storage module is used to query whether the third user account belongs to the second preset user organization based on the target user identifier; if the third user account belongs to the second preset user organization, determine the fourth target management process corresponding to the second preset user organization based on the organization identifier of the second preset user organization; determine whether the organization identifier of the second preset user organization exists in the cache of the fourth target management process; if the organization identifier of the second preset user organization exists in the cache of the fourth target management process, save the data to be published to the cache of the fourth target management process.
16. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the data processing method according to any one of claims 1-14.
17. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores machine-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the data processing method according to any one of claims 1-14.
Citation Information
Patent Citations
Game data query method and device
CN113360526A
Fragmented data caching and accessing method and device, terminal and storage medium
CN113590915A