Request processing method and device, computer equipment, readable storage medium and program product
By using cache to query business table serial numbers and determine target resource data in the resource reward platform, the problem of degradation in database performance under high concurrent access is solved, and more efficient business table addressing and database performance management is achieved.
Patent Information
- Application Number
- CN202411593656.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-03-14
AI Technical Summary
In the resource reward platform, due to high concurrent access and large number of reward resource generation, database performance declines and affects user experience.
By obtaining the user identification field, querying the service table sequence number from the cache, and determining the target resource data based on the sequence number, and performing corresponding operations. If it does not exist in the cache, use hash value to query the service table sequence number from the database and establish a mapping relationship to store it in the cache.
By directly reading the service table sequence number corresponding to the user identification field from the cache, a large amount of calculations is avoided, the service table addressing efficiency is improved, the database performance pressure is reduced, and the user experience is improved.
Smart Images

Figure CN119621789A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of big data processing, and in particular to a request processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] The resource reward platform rewards users who meet transaction requirements. Due to the large daily transaction volume, a large number of reward resources are generated every day to support users to obtain reward resources. During peak hours, a large number of users will access and modify resource data at the same time. Under this large amount of data and high concurrency, the database performance is undoubtedly under great pressure.
[0003] With the development of business and the increasing business volume, the amount of reward resources generated is also increasing, and the amount of data in a single table partition is also increasing, currently reaching tens of millions or even hundreds of millions. Under high concurrent access, even if the table is partitioned at the database level and the query SQL and table field index are optimized, the database performance is still gradually declining, affecting the user experience. Therefore, after the database table is partitioned, the data in a single partition is still too large, resulting in the database performance being unable to meet business needs. Summary of the invention
[0004] Based on this, it is necessary to provide a request processing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve database performance in response to the above technical problems.
[0005] In a first aspect, the present application provides a request processing method, the method comprising:
[0006] Obtaining an operation request, wherein the operation request carries at least one user identification field;
[0007] Querying the service table sequence number from the cache according to each of the user identification fields;
[0008] If the service table sequence number exists in the cache, obtaining the first service table sequence number corresponding to each user identification field from the cache;
[0009] Determine the target resource data according to the sequence number of each of the first business tables;
[0010] A corresponding operation is performed on the target resource data according to the operation request.
[0011] In one embodiment, the method further comprises:
[0012] If the service table sequence number does not exist in the cache, query each second service table sequence number from the database according to the hash value of the user identification field;
[0013] Determine the target resource data according to the sequence number of each of the second business tables;
[0014] A corresponding operation is performed on the target resource data according to the operation request.
[0015] In one embodiment, before querying the service table sequence number from the cache according to each user identification field, the process includes:
[0016] Acquire key fields in the initial business table; wherein the key fields include a user identification field;
[0017] Calculate the hash value of each user identification field, and determine the service table sequence number corresponding to each user identification field by using a consistent hash algorithm;
[0018] Each of the service table serial numbers is used as a first service table serial number, and a second mapping relationship between each of the first service table serial numbers and the user identification field is established, and the second mapping relationship is stored in a cache.
[0019] In one embodiment, determining the target resource data according to the sequence number of each of the first service tables includes:
[0020] Each target service table is determined according to each first service table serial number, and target resource data is acquired from each target service table, wherein the target service table corresponds to the first service table serial number one by one.
[0021] In one embodiment, the operation request carries a time identification field; and the acquiring target resource data from each target service table includes:
[0022] Determine the target partition of each target business table according to the time identification field;
[0023] For each user identification field, target resource data is acquired from each target partition according to the user identification field.
[0024] In one embodiment, before determining each target service table according to each first service table sequence number, the method includes:
[0025] Get the amount of business data in the initial business table;
[0026] Splitting the initial business table into various business tables according to the amount of business data; wherein the various business tables are stored in the same database;
[0027] A third mapping relationship is established in which each of the service tables corresponds to the first service table sequence number in a one-to-one manner.
[0028] In a second aspect, the present application further provides a request processing device, the device comprising:
[0029] A first acquisition module, configured to acquire an operation request, wherein the operation request carries at least one user identification field;
[0030] A first query module, used for querying the service table sequence number from the cache according to each user identification field;
[0031] A second acquisition module, configured to acquire the first service table sequence number corresponding to each user identification field from the cache if the service table sequence number exists in the cache;
[0032] A first determination module, used to determine target resource data according to the sequence number of each of the first business tables;
[0033] The first operation execution module is used to execute a corresponding operation on the target resource data according to the operation request.
[0034] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0035] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0036] In a fifth aspect, the present application also provides a computer program product, including a computer program, which implements the steps of the above method when executed by a processor.
[0037] The request processing method, device, computer equipment, computer-readable storage medium and computer program product first query the business table sequence number from the cache according to at least one user identification field obtained, and then, if the business table sequence number exists in the cache, obtain the first business table sequence number corresponding to each user identification field from the cache; for each user operation request, the first business table sequence number corresponding to the user identification field can be directly obtained from the cache, avoiding secondary calculations and improving the business table addressing efficiency; finally, the target resource data is determined according to each first business table sequence number; and the corresponding operation is performed on the target resource data according to the operation request. By directly reading the first business table sequence number corresponding to the user identification field from the cache, it is avoided to determine the corresponding first business table sequence number after performing a large amount of calculations based on the user identification field, which reduces a large amount of calculations, improves the business table addressing efficiency and also reduces the performance pressure of the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1 An application environment diagram of a request processing method in an embodiment;
[0040] Figure 2 A schematic diagram of a request processing method in one embodiment;
[0041] Figure 3 A flowchart of a request processing method in another embodiment;
[0042] Figure 4 A schematic diagram of a process for establishing a second mapping relationship in an embodiment;
[0043] Figure 5 A schematic diagram of a process for obtaining target resource data from each target business table in one embodiment;
[0044] Figure 6 A schematic diagram of a process for establishing a third mapping relationship in an embodiment;
[0045] Figure 7 A schematic diagram of a database structure design in one embodiment;
[0046] Figure 8 A schematic diagram of a process of creating a database table in one embodiment;
[0047] Fig. 9 A flowchart of a request processing method in another embodiment;
[0048] Fig.10 is a structural block diagram of a request processing device in one embodiment;
[0049] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0051] The request processing method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The server 104 obtains an operation request, wherein the operation request carries at least one user identification field; the business table sequence number is queried from the cache according to each user identification field; if the business table sequence number exists in the cache, the first business table sequence number corresponding to each user identification field is obtained from the cache; the target resource data is determined according to each first business table sequence number; and the target resource data is performed according to the operation request. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices, and the Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0052] In an exemplary embodiment, Figure 2 As shown, a request processing method is provided, which is applied to Figure 1 The server in the example is used to illustrate, including the following steps S202 to S210. Among them:
[0053] Step S202: Acquire an operation request, wherein the operation request carries at least one user identification field.
[0054] The operation request refers to a request to perform a specific operation in the database, including an add operation request, a delete operation request, a modify operation request, and a query operation request, etc. An operation request is determined by a number of request parameters, for example, one of the request parameters includes at least one user identification field.
[0055] The resource reward platform rewards users who meet the transaction requirements. Due to the large daily transaction volume, a large number of reward resources will be generated every day to support users to obtain reward resources. During peak periods, a large number of users will access and modify resource data at the same time.
[0056] Optionally, when a large number of users access resource data through the resource reward platform, the server receives a query operation request through the resource reward platform. The query operation request carries, for example, 300 user identification fields. The server reads the target resource data corresponding to each user identification field from the database through the query operation request.
[0057] Optionally, the server receives a modification operation request through the resource reward platform, and the modification operation request carries, for example, five user identification fields. The server reads the target resource data corresponding to each user identification field from the database through the modification operation request, and performs the modification operation.
[0058] Step S204: query the service table sequence number from the cache according to each user identification field.
[0059] The cache includes non-relational databases, such as Redis, Riak, Couchbase, and RocksDB. The user identification field is a field used to uniquely identify each user in a database or resource reward system. This field can be any data that can uniquely distinguish a user, and can be a string of characters automatically generated by the system or generated by the user during the registration process.
[0060] Optionally, the cache is explained by taking the Redis database as an example. Redis is an open source high-performance key-value database, which is usually used as a data structure server, database, cache and message agent. Before querying the business table sequence number from the cache according to each user identification field, the server stores the mapping relationship between the user identification field and the business table sequence number through Redis. The server matches each user identification field with the mapping relationship between the user identification field and the business table sequence number one by one according to each user identification field obtained, so as to query the business table sequence number corresponding to each user identification field in Redis.
[0061] Step S206: If the service table sequence number exists in the cache, obtain the first service table sequence number corresponding to each user identification field from the cache.
[0062] The first service table serial number refers to the service table serial number stored in the cache.
[0063] Optionally, if the business table sequence number exists in the cache, that is, the mapping relationship between the user identification field carried in the operation request and the business table sequence number has been stored in Redis, the server obtains the business table sequence number corresponding to each user identification field from Redis as the first business table sequence number.
[0064] Alternatively, assuming that the operation request carries 5 user identification fields, and the mapping relationship between the 5 user identification fields and the business table serial number has been stored in Redis, the server reads the business table serial number corresponding to each user identification field from Redis, such as user_id1--table_bonus_89; user_id2--table_bonus_53, and so on.
[0065] Step S208, determining target resource data according to the sequence numbers of the first service tables.
[0066] Optionally, for each first business table serial number, the server obtains the target resource data from the corresponding business table according to the first business table serial number, such as the server obtains target resource data 1 from table_bonus_89 and obtains target resource data 2 from table_bonus_53.
[0067] Step S210: performing corresponding operations on the target resource data according to the operation request.
[0068] Optionally, if the operation request is an add operation request, the server performs a corresponding add operation on the target resource data according to the add operation request. If the operation request is a delete operation request, the server performs a corresponding delete operation on the target resource data according to the delete operation request.
[0069] In the above request processing method, firstly, according to at least one user identification field obtained, the business table sequence number is queried from the cache. Secondly, if the business table sequence number exists in the cache, the first business table sequence number corresponding to each user identification field is obtained from the cache. For each user operation request, the first business table sequence number corresponding to the user identification field can be directly obtained from the cache, avoiding secondary calculations and improving the efficiency of business table addressing. Finally, the target resource data is determined according to each first business table sequence number. According to the operation request, the corresponding operation is performed on the target resource data. By directly reading the first business table sequence number corresponding to the user identification field from the cache, it is avoided to determine the corresponding first business table sequence number after a large amount of calculations based on the user identification field, which reduces a large amount of calculations, improves the efficiency of business table addressing and also reduces the performance pressure of the database.
[0070] In an exemplary embodiment, Figure 3 As shown, the request processing method further includes steps S302 to S306. Among them:
[0071] Step S302: If the service table serial number does not exist in the cache, query each second service table serial number from the database according to the hash value of the user identification field.
[0072] The second service table serial number refers to a service table serial number that is not stored in the cache, such as a service table serial number read from a database.
[0073] The database can be a relational database, such as Oracle, MySQL, etc.
[0074] The hash value is the result obtained by applying a hash function to input data (such as files, messages, etc.). A hash function is a one-way mathematical function that receives data of any size and outputs a value of a fixed length. This output value is the hash value.
[0075] Optionally, taking Oracle as an example, if the business table sequence number does not exist in the cache, that is, the mapping relationship between the user identification field carried in the operation request and the business table sequence number is not stored in Redis, the server uses the target function provided by Oracle, such as dbms_utility.get_hash_value('key',min,max) function as a consistent hashing algorithm, and the application calculates the business table sequence number by calling this function, thereby avoiding the implementation of the algorithm by itself and increasing the development cost.
[0076] Optionally, assuming that the second business table is numbered 1-100; if the user identification field user_id of the resource reward data to be added to the database is "12345", the query result according to SQL "select dbms_utility.get_hash_value('12345',1,100) from dual;" is 89.
[0077] It should be noted that the hash value can be calculated based on the user identification field, and the hash value can also be calculated based on other fields that uniquely identify the user and are fixed. Since the user identification field is fixed, the hash value of the user identification field is also fixed, so the resource data corresponding to the user identification field will always fall into the same sub-table.
[0078] Step S304: determining target resource data according to the sequence numbers of the second service tables.
[0079] Optionally, for each first business table serial number, the server obtains the target resource data from the corresponding business table according to the first business table serial number, such as the server obtains target resource data 3 from table_bonus_63 and obtains target resource data 4 from table_bonus_33.
[0080] Step S306: performing corresponding operations on the target resource data according to the operation request.
[0081] Optionally, if the operation request is an add operation request, the server performs a corresponding add operation on the target resource data according to the add operation request. If the operation request is a delete operation request, the server performs a corresponding delete operation on the target resource data according to the delete operation request.
[0082] In this embodiment, the business table is split by using a database hash function to reduce the amount of data in a single business table, effectively disperse the pressure on the database, and improve performance in specific scenarios.
[0083] In the above embodiment, after searching the database for each second service table serial number according to the hash value of the user identification field, the method further includes: establishing a first mapping relationship between each second service table serial number and the user identification field; and storing the first mapping relationship in a cache.
[0084] Optionally, if the business table sequence number does not exist in the cache, the server queries each second business table sequence number from the database according to the hash value of the user identification field; the server associates the obtained user identification field with the corresponding second business table sequence number, establishes a first mapping relationship between each second business table sequence number and the user identification field; and stores the first mapping relationship in the cache redis. The naming of the key value of the "user identification field" needs to carry the hash value of the data. When the operation request is made later, the "user identification field" directly obtains the business table sequence number from redis to avoid repeated function calls for calculation.
[0085] In this embodiment, by storing the second business table serial number and user identification field that are not stored in the cache in the early cache, the business table serial number can be directly obtained from redis for subsequent operation requests, avoiding repeated function calls for calculations, reducing the amount of database calculations, and reducing database performance pressure.
[0086] In an exemplary embodiment, Figure 4 As shown, before querying the service table sequence number from the cache according to each user identification field, steps S402 to S406 are included. Among them:
[0087] Step S402: Obtain key fields in the initial business table.
[0088] Among them, the key fields generally use fields with data ownership identification and relatively dispersed values, including user identification fields. The key fields may also include other fields that uniquely identify the user and are fixed.
[0089] Optionally, before querying the service table sequence number from the cache according to each user identification field, the server needs to store the mapping relationship between the user identification field and the service table sequence number. Therefore, the server obtains the key field in the initial service table table_bonus, such as the user identification field user_id.
[0090] Step S404, calculate the hash value of each user identification field, and determine the business table sequence number corresponding to each user identification field through a consistent hashing algorithm.
[0091] Alternatively, taking Oracle as an example, the server uses the hash value of each user identification field as the function input, and uses the target function provided by Oracle, such as dbms_utility.get_hash_value('key',min,max) function as the consistent hashing algorithm. The application calculates the business table number by calling this function. Assume that the second business table number is 1-100; if the user identification field user_id of the resource reward data to be added to the database is "12345", the query result according to SQL "select dbms_utility.get_hash_value('12345',1,100) from dual;" is 89.
[0092] In actual applications, the server calls the target function provided by Oracle to avoid implementing the algorithm by itself and increase the development cost. After testing, this function has high performance. For a certain input string key, such as "user identification field user_id", if the min (minimum value) and max (maximum value) remain unchanged, the obtained hash value is fixed (in the range of [min, min+max-1]), and when the hash value is sufficiently dispersed, the obtained hash value is sufficiently uniform between min and max, so that the resource data corresponding to each user identification field is evenly distributed to all business tables.
[0093] Step S406: taking each service table serial number as a first service table serial number, establishing a second mapping relationship between each first service table serial number and a user identification field, and storing the second mapping relationship in a cache.
[0094] Optionally, the server uses each service table serial number as a first service table serial number, associates each first service table serial number with a user identification field, establishes a second mapping relationship between each first service table serial number and the user identification field, and stores the second mapping relationship in a cache.
[0095] In this embodiment, the business table serial number corresponding to each user identification field is determined by a consistent hashing algorithm, thereby avoiding the increase in development costs by implementing the algorithm yourself. By storing the second mapping relationship in the cache, the user identification field carried by the obtained operation request can be directly obtained from the cache, reducing the database calculation amount and improving the database performance.
[0096] In an exemplary embodiment, determining the target resource data according to the sequence numbers of the first business tables includes: determining each target business table according to the sequence numbers of the first business tables, and acquiring the target resource data from each target business table.
[0097] Among them, the target business table corresponds to the first business table serial number one by one.
[0098] Optionally, assuming that there are 100 target business tables, the first business table serial numbers are from 1 to 100. Each target business table corresponds to a first business table serial number, such as the first business table serial number of the first target business table is 1; the first business table serial number of the second target business table is 2; and so on.
[0099] Optionally, the server determines each target business table according to the sequence number of each first business table. For example, if the sequence number of the first business table is 2, it is the second target business table, and the server obtains the target resource data from the target business table.
[0100] It should be noted that the number of target business tables and the sequence number of the first business table are not limited here, and any number is acceptable as long as they satisfy a one-to-one correspondence and meet actual needs.
[0101] In this embodiment, the target resource data can be obtained through the first business table serial number, which can meet the corresponding operation request and reduce the database performance pressure.
[0102] In the above embodiment, Figure 5 As shown, the operation request carries a time identification field; obtaining target resource data from each target service table includes steps S502 to S504. Among them:
[0103] Step S502: determining the target partition of each target business table according to the time identification field.
[0104] The time identification field is used in the database to record information about a specific event or data entry at a specific time point. The time identification field may be a transaction date "trade_date".
[0105] Optionally, the server performs range partitioning on each target business table according to the transaction date "trade_date", and the partition that matches the transaction date "trade_date" is the target partition.
[0106] Step S504: for each user identification field, obtain target resource data from each target partition according to the user identification field.
[0107] Optionally, the server uses the user identification field "user_id" as the index of the target partition of each target business table, and obtains the target resource data from each target partition through the user identification field "user_id".
[0108] Optionally, the key field also includes a time identification field; before obtaining the target resource data from each target business table, it includes: using the time identification field as the partition range to determine the target partition of each target business table; using the user identification field as an index, storing the target data corresponding to the user identification field into the target partition of the target business table.
[0109] For example, to calculate the resource bonus table "table_bonus", 100 target business tables need to be created for it: table_red_packet_1, table_red_packet_2, table_red_packet_3..., table_red_packet_100. Create range partitions and indexes for each target business table: for each target business table, use the transaction date "trade_date" as the partition range to determine the target partition of each target business table; use the user identification field "user_id" as the index to store the target data corresponding to the user identification field into the target partition of the target business table.
[0110] In this embodiment, by using the time identification field as the partition range and the user identification field "user_id" as the index, the required data can be queried and operated from the specified partition without scanning the entire target business table each time, thereby improving the database query performance.
[0111] Continuing with the above embodiment, Figure 6 As shown, before determining each target business table according to each first business table sequence number, steps S602 to S606 are included. Among them:
[0112] Step S602: Acquire the amount of business data in the initial business table.
[0113] Optionally, before determining each target business table according to each first business table serial number, the server needs to save the mapping relationship between each business table and the first business table serial number. If the initial business table is the resource reward table "table_bonus", the server obtains the data volume of the resource reward table "table_bonus", which can be a single-day data volume or an hourly data volume; the estimated single-day data volume of the resource reward table "table_bonus" is 200 million.
[0114] Step S604: split the initial business table into various business tables according to the amount of business data; wherein the various business tables are stored in the same database.
[0115] Optionally, taking Oracle as an example, the server splits the initial business table into various business tables according to the amount of business data; wherein each business table is stored in Oracle.
[0116] In actual applications, according to Oracle's official recommendations, partitioning is recommended for single-table storage of 1G (5 million data). Since the daily data volume of the resource reward table "table_bonus" is 200 million, and considering the possible increase in data in the future, it can be split into 100 business tables. In this way, the daily data volume after partitioning is 2 million. Even if the data grows to 5 million in the future, it can cope with high concurrency scenarios and ensure high query efficiency. The server creates a table based on the daily data volume of 200 million for the resource reward table "table_bonus". For the calculation of the resource reward table "table_bonus", 100 sub-tables need to be created for it: table_bonus_1, table_bonus_2, table_bonus_3..., table_bonus_100.
[0117] It should be noted that this application needs to determine the number of sub-tables in advance and will not be expanded later. In this way, data with the same characteristics will always be allocated to the same sub-table, without the need to dynamically migrate data, which can ensure data consistency and facilitate data management, maintenance and statistics.
[0118] Step S606: Establish a third mapping relationship between each business table and the first business table serial number in a one-to-one correspondence.
[0119] Optionally, the server associates each business table with the first business table serial number one-to-one, establishes a third mapping relationship in which each business table corresponds to the first business table serial number one-to-one, and stores the third mapping relationship.
[0120] In this embodiment, by splitting the initial business table into several business tables according to the business volume, and associating the business table with the first business table sequence number, the number of sub-tables is determined in advance based on a good hash algorithm, and no subsequent expansion and data migration are required to ensure data consistency. In addition, the amount of data in each target business table can be reduced, effectively dispersing the pressure on the database and improving database performance.
[0121] In an exemplary embodiment, the database structure is designed as follows Figure 7As shown. The data splitting rules of the resource reward users are calculated at the application layer through the hash table principle and consistent hashing algorithm, and multiple different resource reward business logic tables are established according to the splitting rules. The massive data is dispersed into multiple business tables (sub-tables) in the same library according to the hash value of the user identification field. Each business table (sub-table) is then partitioned and indexed (user field identification) using the range partitioning strategy (time identification field, such as trading day). That is, through the combined use of application layer data sub-business table + Redis sub-business table cache + Oracle partitioning technology, the database performance can be improved in particularly large data volumes or in certain specific scenarios. At the same time, storing massive data in business tables can reduce the table space occupied by a single business table, improve data security and reliability, and reduce the maintenance cost of the database for partition indexes, global indexes, etc., thereby improving the overall performance of the database.
[0122] This application is divided into two stages. The database is taken as Oracle and the cache is explained as Redis. The first stage is to create a table in Oracle and store the target resource data in the corresponding table. The flowchart of database table creation is as follows: Figure 8 shown.
[0123] Evaluate the business data volume: The server obtains the business data volume in the initial business table; for example, the daily transaction volume is 200 million data.
[0124] Determine the number of sub-tables: split the initial business table, such as table_bonus, into 100 business tables according to the amount of business data; among them, the 100 business tables are stored in the same database; establish a third mapping relationship between the 100 business tables and the first business table serial number (1-100) in a one-to-one correspondence.
[0125] According to Oracle's official recommendations, partitioning is recommended when a single business table stores 1G (5 million data). It is estimated that the daily data volume of the red envelope table "table_bonus" is 200 million, and considering the possible increase in data in the future, it can be split into 100 business tables. In this way, the daily data volume after partitioning is 2 million. Even if the data grows to 5 million in the future, it can cope with high concurrency scenarios and ensure high query efficiency. This solution requires determining the number of partitions in advance and will not be expanded later. In this way, data with the same characteristics will always be assigned to the same business table, without the need to dynamically migrate data, which can ensure data consistency and facilitate data management, maintenance and statistics.
[0126] Determine the hash value: obtain the key fields in the initial business table; wherein the key fields include the "user_id" (user ID) field; calculate the hash value of each user ID field, and determine the business table number corresponding to each user identification field through the dbms_utility.get_hash_value('key',min,max) function provided by Oracle; use each business table number as the first business table number, and establish the second mapping relationship between each first business table number and the user identification field, table_bonus_1, table_bonus_2, table_bonus_3..., table_bonus_100, and store the second mapping relationship in the cache.
[0127] Determine the partition type, partition range and index: the key field also includes a time identification field; use the trading date "trade_date" as the time identification field as the partition range to determine the target partition of each target business table; use the user id "user_id" as the index.
[0128] Data is stored in the database: the target data corresponding to the user ID field is stored in the target partition of the target business table.
[0129] The second stage is the query stage, such as Fig. 9 shown.
[0130] Query the sub-table sequence number cache: the server obtains an operation request, where the operation request includes any one of an add operation request, a delete operation request, a modify operation request and a query operation request; the query operation request is used as an example for explanation, and the query operation request carries at least one user id "user_id" field; the business table sequence number cache is queried from redis according to each user id "user_id" field.
[0131] Query the business table sequence number: If the business table sequence number exists in Redis, obtain the first business table sequence number corresponding to the "user_id" field of each user id from Redis; call the Oracle database dbms_utility.get_hash_value() function to query the sub-business table sequence number according to the hash value (key) of the user id. For example, if the user id is "12345", the query result of SQL "select dbms_utility.get_hash_value('12345',1,100) from dual;" is 89, and the data to be operated is in the table with sequence number 89. After querying the business table sequence number, it needs to be saved to redis. When the data of this type is stored again in the database later, the sub-table sequence number is directly obtained from redis to avoid repeated function calls for calculation.
[0132] Concatenate table names and initialize query structured language sql: determine each target business table according to the sequence number of each first business table, such as table_bonus_1. The query operation request has a time identification field, such as "trade_date"; determine the target partition of each target business table according to the "trade_date" field; for each "user_id" field, obtain the target resource data from each target partition according to the "user_id" field. Among them, the target business table corresponds to the sequence number of the first business table one by one. sql is written according to actual needs, carrying the partition key ("trade_date") and index ("user_id") fields to avoid slow sql caused by full table scan.
[0133] Query from the database: perform query operations on the target resource data according to the query operation request.
[0134] If the business table serial number does not exist in Redis, query each second business table serial number from the database according to the hash value of the "user_id" field; establish a first mapping relationship between each second business table serial number and the user identification field; and store the first mapping relationship in the cache; determine the target resource data according to each second business table serial number; and perform corresponding operations on the target resource data according to the operation request.
[0135] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0136] Based on the same inventive concept, the embodiment of the present application also provides a request processing device for implementing the request processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more request processing device embodiments provided below can refer to the limitations on the request processing method above, and will not be repeated here.
[0137] In an exemplary embodiment, Fig.10As shown, a request processing device is provided, including: a first acquisition module 1001, a first query module 1002, a second acquisition module 1003, a first determination module 1004 and a first operation execution module 1005, wherein:
[0138] The first acquisition module 1001 is used to acquire an operation request, wherein the operation request carries at least one user identification field.
[0139] The first query module 1002 is used to query the service table sequence number from the cache according to each user identification field.
[0140] The second acquisition module 1003 is configured to acquire the first service table sequence number corresponding to each user identification field from the cache if the service table sequence number exists in the cache.
[0141] The first determination module 1004 is used to determine the target resource data according to the sequence numbers of the first service tables.
[0142] The first operation execution module 1005 is used to execute a corresponding operation on the target resource data according to the operation request.
[0143] In an exemplary embodiment, a request processing device is provided, comprising:
[0144] The second query module is used to query each second business table sequence number from the database according to the hash value of the user identification field if the business table sequence number does not exist in the cache.
[0145] The second determination module is used to determine the target resource data according to the sequence numbers of the second business tables.
[0146] The second operation execution module is used to execute a corresponding operation on the target resource data according to the operation request.
[0147] In an exemplary embodiment, a request processing device is provided, including: a first mapping relationship determination module, used to establish a first mapping relationship between each second service table sequence number and a user identification field; and store the first mapping relationship in a cache.
[0148] In an exemplary embodiment, a request processing device is provided, comprising:
[0149] The third acquisition module is used to acquire key fields in the initial business table; wherein the key fields include a user identification field.
[0150] The calculation module is used to calculate the hash value of each user identification field and determine the business table sequence number corresponding to each user identification field through a consistent hash algorithm.
[0151] The second mapping relationship determination module is used to use each service table serial number as the first service table serial number, establish a second mapping relationship between each first service table serial number and a user identification field, and store the second mapping relationship in a cache.
[0152] In an exemplary embodiment, the first determining module 1004 is further configured to determine each target business table according to each first business table serial number, and obtain target resource data from each target business table, wherein the target business table corresponds to the first business table serial number one by one.
[0153] In an exemplary embodiment, the operation request carries a time identification field; the first query module 1002 includes:
[0154] The target partition determination unit is used to determine the target partition of each target business table according to the time identification field.
[0155] The target resource data acquisition unit is used to acquire target resource data from each target partition according to the user identification field for each user identification field.
[0156] In an exemplary embodiment, a request processing device further includes:
[0157] The third mapping relationship determination module is used to obtain the business data volume in the initial business table; split the initial business table into various business tables according to the business data volume; wherein the various business tables are stored in the same database; and establish a third mapping relationship in which each business table corresponds to the first business table serial number.
[0158] Each module in the above request processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0159] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Fig.11As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store resource data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a request processing method is implemented.
[0160] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0161] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0162] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0163] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0164] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0165] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0166] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A request processing method, characterized in that: The method comprises: Obtaining an operation request, wherein the operation request carries at least one user identification field; Querying the service table sequence number from the cache according to each of the user identification fields; If the service table sequence number exists in the cache, obtaining the first service table sequence number corresponding to each user identification field from the cache; Determine the target resource data according to the sequence number of each of the first business tables; A corresponding operation is performed on the target resource data according to the operation request.
2. The method according to claim 1, characterized in that The method further comprises: If the service table sequence number does not exist in the cache, query each second service table sequence number from the database according to the hash value of the user identification field; Determine the target resource data according to the sequence number of each of the second business tables; A corresponding operation is performed on the target resource data according to the operation request.
3. The method according to claim 1, characterized in that Before querying the service table sequence number from the cache according to each user identification field, the method includes: Acquire key fields in the initial business table; wherein the key fields include a user identification field; Calculate the hash value of each user identification field, and determine the service table sequence number corresponding to each user identification field by using a consistent hash algorithm; Each of the service table serial numbers is used as a first service table serial number, and a second mapping relationship between each of the first service table serial numbers and the user identification field is established, and the second mapping relationship is stored in a cache.
4. The method according to claim 1, characterized in that: The determining of target resource data according to the sequence numbers of the first service tables includes: Each target service table is determined according to each first service table serial number, and target resource data is acquired from each target service table, wherein the target service table corresponds to the first service table serial number one by one.
5. The method according to claim 4, characterized in that The operation request carries a time identification field; the acquiring target resource data from each target service table includes: Determine the target partition of each target business table according to the time identification field; For each user identification field, target resource data is acquired from each target partition according to the user identification field.
6. The method according to claim 4, characterized in that Before determining each target service table according to each first service table sequence number, the method includes: Get the amount of business data in the initial business table; Splitting the initial business table into various business tables according to the amount of business data; wherein the various business tables are stored in the same database; A third mapping relationship is established in which each of the service tables corresponds to the first service table sequence number in a one-to-one manner.
7. A request processing device, characterized in that: The device comprises: A first acquisition module, configured to acquire an operation request, wherein the operation request carries at least one user identification field; A first query module, used for querying the service table sequence number from the cache according to each user identification field; A second acquisition module, configured to acquire the first service table sequence number corresponding to each user identification field from the cache if the service table sequence number exists in the cache; A first determination module, used to determine target resource data according to the sequence number of each of the first business tables; The first operation execution module is used to execute a corresponding operation on the target resource data according to the operation request.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.