Distributed database inventory processing method and device

By calculating the inventory average value and local scheduling mechanism, the problem of inventory imbalance in distributed databases is solved, efficient and balanced allocation and utilization of resources is achieved, and system impact is reduced.

CN114547200BActive Publication Date: 2025-08-22INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210173421.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-24
Publication Date
2025-08-22
Estimated Expiration
2042-02-24

AI Technical Summary

Technical Problem

In distributed databases, uneven inventory allocation of hotspot data causes some database shards to use up inventory, while other shards are still left, causing the problem that users cannot participate in the activity.

Method used

By calculating the inventory average value and deducting inventory for shards above the average value, the inventory of shards below the average value is increased until all shards have inventory balanced; when the inventory average value is zero, local inventory scheduling is performed based on the call information of the shards to ensure balanced resource allocation.

Benefits of technology

The balanced use of multiple database shard resources in a distributed system is realized, ensuring that the resources on all shards are fully utilized, reducing system impact, and solving the problem of unbalanced inventory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114547200B_ABST
    Figure CN114547200B_ABST
Patent Text Reader

Abstract

A distributed database inventory processing method and device can be used in the financial field or other fields. The method includes: determining the average inventory value based on the inventory values ​​of multiple database shards in the obtained distributed database; if the average inventory value is greater than zero, performing inventory deduction processing on the database shards whose inventory values ​​are higher than the average inventory value, and performing inventory increase processing on the database shards whose inventory values ​​are lower than the average inventory value, increasing the inventory quantity of the average inventory value so that the inventory value of each database shard is equal to the average inventory value; if the average inventory value is equal to zero, performing local inventory scheduling processing on each database shard based on the call information corresponding to each database shard. The present invention achieves resource balancing of multiple database shards in a distributed system through a simple and easy-to-operate inventory scheduling method, so that the resources on all database shards can be fully used, with little impact on the existing system, and solves the inventory management problem of multiple shards of distributed data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed databases, and in particular to a distributed database inventory processing method and device. Background Art

[0002] With the application of distributed technology, the problem of difficult expansion of performance and capacity of conventional single-point databases has been solved. Distributed databases are stable and reliable, with elastic scalability in capacity and service capabilities. They have the capabilities of automated horizontal splitting, transparent read-write separation, and online smooth expansion of service capabilities. They provide more favorable technical support for business systems with long-term growth or fluctuation in business volume.

[0003] In a distributed database scenario, data of different categories / characteristics can be routed to a specified distributed database shard (set) through routing, based on the results of a certain algorithm calculation such as user id and activity id, for example Figure 1 Userid%N means the userid modulo the number of shards N. The modulo result corresponds to the shard number and is evenly distributed to N sets, which can ensure that business data falls relatively evenly across multiple databases.

[0004] But if there is hot data, such as Figure 1 As shown, product inventory can present certain issues. For example, a database is divided into 10 sets. For a popular event, the inventory is evenly distributed across sets 1 to 10, with each set containing 1 million coupon codes. After the event reaches a certain stage, the inventory in each set begins to show irregular distribution, and eventually some sets begin to run out of stock. User A is routed to set 1, which has already run out of stock. Meanwhile, user B is routed to set 2, which still has some stock. This can prevent user A from participating in the event due to technical reasons. Summary of the Invention

[0005] In view of the problems existing in the prior art, the main purpose of the embodiments of the present invention is to provide a distributed database inventory processing method and device to achieve simple and effective inventory management and processing.

[0006] To achieve the above objectives, an embodiment of the present invention provides a distributed database inventory processing method, the method comprising:

[0007] Determine the average inventory value based on the inventory values ​​of multiple database shards in the obtained distributed database;

[0008] If the average inventory value is greater than zero, the database shards whose inventory values ​​are higher than the average inventory value are subjected to inventory deduction processing, and the database shards whose inventory values ​​are lower than the average inventory value are subjected to inventory increase processing, increasing the inventory quantity of the average inventory value so that the inventory value of each database shard is equal to the average inventory value;

[0009] If the inventory average value is equal to zero, local inventory scheduling processing is performed on each database shard according to the call information corresponding to each database shard.

[0010] Optionally, in one embodiment of the present invention, determining the average inventory value based on the acquired inventory values ​​of the plurality of database shards in the distributed database includes:

[0011] Determine the minimum inventory value among the inventory values ​​of the multiple database shards obtained in the distributed database;

[0012] If the minimum inventory value is less than a preset threshold, an average inventory value is determined based on each inventory value.

[0013] Optionally, in one embodiment of the present invention, determining the average inventory value based on the acquired inventory values ​​of the plurality of database shards in the distributed database further includes:

[0014] Sum the inventory values ​​of multiple database shards in the obtained distributed database to determine the total inventory value;

[0015] If the total inventory value is not less than the number of database shards, then determining the average inventory value based on the total inventory value and the number of database shards;

[0016] If the total inventory value is less than the number of database shards, the average inventory value is set to zero.

[0017] Optionally, in one embodiment of the present invention, the call information includes an inventory clearing timestamp and an inventory clearing count.

[0018] Optionally, in one embodiment of the present invention, performing local inventory scheduling processing on each database shard based on the call information corresponding to each database shard includes:

[0019] Obtain the inventory clearing timestamp corresponding to the database shard;

[0020] If it is known that there is a database shard without an inventory clearing timestamp, the inventory of the database shard with the largest inventory value and no inventory clearing timestamp will be deducted, and the inventory of the database shard with the latest inventory clearing timestamp will be increased.

[0021] If it is known that each database shard has a corresponding inventory clearing timestamp, then the database shard with the largest inventory value and the earliest inventory clearing timestamp is subjected to inventory deduction processing, and the database shard with the latest inventory clearing timestamp is subjected to inventory increase processing.

[0022] Optionally, in one embodiment of the present invention, performing local inventory scheduling on each database shard based on call information corresponding to each database shard further includes:

[0023] Get the number of inventory clearing times corresponding to the database shard;

[0024] The database shard with the largest inventory value and the smallest number of inventory clearing operations is deducted from the inventory, and the database shard with zero inventory value and the largest number of inventory clearing operations is increased from the inventory.

[0025] An embodiment of the present invention further provides a distributed database inventory processing device, the device comprising:

[0026] The inventory value module is used to determine the average inventory value based on the inventory values ​​of multiple database shards obtained from the distributed database;

[0027] The overall inventory scheduling module, if the inventory average value is greater than zero, performs inventory deduction processing on the database shards whose inventory values ​​are higher than the inventory average value, and performs inventory increase processing on the database shards whose inventory values ​​are lower than the inventory average value, increasing the inventory quantity of the inventory average value so that the inventory value of each database shard is equal to the inventory average value;

[0028] The inventory local scheduling module is used to perform local inventory scheduling processing on each database shard according to the call information corresponding to each database shard if the inventory average value is equal to zero.

[0029] Optionally, in one embodiment of the present invention, the inventory value module includes:

[0030] The minimum inventory value unit is used to determine the minimum inventory value among the inventory values ​​according to the inventory values ​​of multiple database shards obtained in the distributed database;

[0031] The scheduling threshold unit is used to determine the average inventory value based on each inventory value if the minimum inventory value is less than a preset threshold.

[0032] Optionally, in one embodiment of the present invention, the inventory value module further includes:

[0033] A total inventory value unit is used to sum the inventory values ​​of multiple database shards obtained in the distributed database to determine the total inventory value;

[0034] The inventory average value unit is used to determine the inventory average value based on the total inventory value and the number of database shards if the total inventory value is not less than the number of database shards; if the total inventory value is less than the number of database shards, set the inventory average value to zero.

[0035] Optionally, in one embodiment of the present invention, the local inventory scheduling module includes:

[0036] A reset timestamp unit, used to obtain the inventory reset timestamp corresponding to the database shard;

[0037] The first local scheduling unit is configured to, upon detecting that a database shard does not have an inventory clearing timestamp, deduct inventory from the database shard with the largest inventory value and no inventory clearing timestamp, and increase inventory from the database shard with the latest inventory clearing timestamp;

[0038] The second local scheduling unit is used to, if it is known that each database shard has a corresponding inventory clearing timestamp, perform inventory deduction processing on the database shard with the largest inventory value and the earliest inventory clearing timestamp, and perform inventory increase processing on the database shard with the latest inventory clearing timestamp.

[0039] Optionally, in one embodiment of the present invention, the local inventory scheduling module further includes:

[0040] A reset times unit, used to obtain the inventory reset times corresponding to the database shard;

[0041] The third local scheduling unit is used to perform inventory deduction processing on the database shard with the largest inventory value and the smallest number of inventory clearing times, and to perform inventory increase processing on the database shard with zero inventory value and the largest number of inventory clearing times.

[0042] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.

[0043] The present invention also provides a computer-readable storage medium storing a computer program for executing the above method.

[0044] The present invention achieves resource balancing of multiple database shards in a distributed system through a simple and easy-to-operate inventory scheduling method, efficiently allocates remaining inventory resources to database shards that need resources, so that resources on all database shards can be fully utilized, with little impact on the existing system, fundamentally solving the inventory management problem of distributed data with multiple shards. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0046] Figure 1 A schematic diagram of distributed database sharding;

[0047] Figure 2 This is a flow chart of a distributed database inventory processing method according to an embodiment of the present invention;

[0048] Figure 3 A flowchart for determining the total inventory value and the average inventory value in an embodiment of the present invention;

[0049] Figure 4 A flow chart of determining the total inventory value and the average inventory value in another embodiment of the present invention;

[0050] Figure 5 This is a flowchart of a local inventory scheduling process in an embodiment of the present invention;

[0051] Figure 6 A flowchart of a local inventory scheduling process in another embodiment of the present invention;

[0052] Figure 7 A schematic diagram of distributed database inventory processing in an embodiment of the present invention;

[0053] Figure 8 This is a structural diagram of a distributed database inventory processing device according to an embodiment of the present invention;

[0054] Figure 9 This is a schematic diagram of the structure of the inventory value module in an embodiment of the present invention;

[0055] Figure 10 This is a schematic structural diagram of an inventory value module in another embodiment of the present invention;

[0056] Figure 11 This is a schematic diagram of the structure of the inventory local scheduling module in an embodiment of the present invention;

[0057] Figure 12 This is a structural diagram of an inventory local scheduling module in another embodiment of the present invention;

[0058] Figure 13 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0059] Embodiments of the present invention provide a distributed database inventory processing method and apparatus, which can be used in the financial field and other fields. It should be noted that the distributed database inventory processing method and apparatus of the present invention can be used in the financial field as well as in any field other than the financial field, and the application field of the distributed database inventory processing method and apparatus of the present invention is not limited.

[0060] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0061] To address the problems of existing technologies, such as the potential for significant system impacts from building a database access layer, which can also pose other challenges and impacts on system stability, this invention addresses these issues efficiently and cost-effectively by accurately scheduling inventory in the database in near-real time during inventory reduction.

[0062] like Figure 2 The flowchart of a distributed database inventory processing method according to an embodiment of the present invention is shown. The execution subject of the distributed database inventory processing method provided by the embodiment of the present invention includes but is not limited to a computer. The method shown in the figure includes:

[0063] Step S1: Determine an average inventory value based on the acquired inventory values ​​of multiple database shards in the distributed database.

[0064] Among them, the number of current database shards and the inventory value of each shard are obtained from the distributed database. The total inventory value can be obtained by accumulation. The ratio of the total inventory value to the number of database shards is the average inventory value.

[0065] Furthermore, if the total inventory value is not less than the number of database shards, the resulting ratio is not less than 1, and the average inventory value is rounded to a positive integer. If the total inventory value is less than the number of database shards, the resulting ratio is less than 1, and the average inventory value is 0.

[0066] In step S2, if the average inventory value is greater than zero, the database shards whose inventory values ​​are higher than the average inventory value are subjected to inventory deduction processing, and the database shards whose inventory values ​​are lower than the average inventory value are subjected to inventory increase processing, increasing the inventory quantity of the average inventory value so that the inventory value of each database shard is equal to the average inventory value.

[0067] If the average inventory value is greater than 0, the inventory of each database shard will be scheduled as a whole.

[0068] Furthermore, if the inventory value of a database shard is greater than the average inventory value, the inventory of that database shard is deducted. Specifically, the deducted inventory value is the difference between the inventory value of that database shard and the average inventory value. If the inventory value of a database shard is less than the average inventory value, the inventory of that database shard is increased. Specifically, the increased inventory value is the difference between the average inventory value and the inventory value of that database shard.

[0069] Furthermore, each time an inventory deduction is performed, the current deducted inventory value is recorded. When an inventory increase is performed, it is necessary to ensure that the total increased inventory value is not greater than the deducted inventory value, that is, no new inventory is added, and the original total inventory value is guaranteed to remain unchanged.

[0070] Step S3: If the average inventory value is zero, local inventory scheduling is performed on each database shard based on the call information corresponding to each database shard.

[0071] If the average inventory value is zero, local inventory scheduling is performed on each database shard. Specifically, local inventory scheduling is performed using the call information of each database, which includes the inventory clearing timestamp and inventory clearing count of each database shard.

[0072] Furthermore, local inventory scheduling is performed based on the database shard's inventory clearing timestamp. This specifically involves obtaining the inventory clearing timestamp for each database shard. If a database shard does not have an inventory clearing timestamp, this indicates that the inventory of that database shard has never reached zero and has the highest inventory value, indicating that the database shard is infrequently used. Therefore, the inventory of the database shard with the highest inventory value and no inventory clearing timestamp is deducted. The deduction value is generally 1, but can be modified based on actual needs. The shard whose inventory value is increased is the shard with the most recent inventory clearing timestamp, i.e., the shard with the most recent inventory clearing timestamp.

[0073] Specifically, for example, in the database, only shard A's inventory has not been cleared, and the current inventory value of shard A is the largest, at 1, while the inventory of shard B has just been cleared. At this time, one of the inventory items in A is allocated to shard B. After the scheduling, the inventory value of shard A becomes 0, the inventory value of shard B becomes 1, and the inventory clearing timestamp of shard A is updated.

[0074] Furthermore, when the inventory of all shards has been cleared, local inventory scheduling is performed based on the number of clears performed on each database shard. Specifically, if a database shard has the fewest clears and the highest inventory value, it indicates that it is infrequently used. Inventory for this database shard is deducted, typically by 1, but this value can be set based on actual circumstances. Correspondingly, the deducted inventory is added to the database shard with the highest number of clears and a value of 0. The highest number of clears indicates that this database shard is frequently used.

[0075] Specifically, for example, shard A in the database has had its inventory cleared 1 times and its current inventory value is the highest, at 1. Shard B has had its inventory cleared 3 times and its current inventory value is 0. Then, one inventory item is deducted from shard A and added to shard B. After local inventory scheduling, shard A's inventory value is 0, shard B's inventory value is 1, and shard A's inventory clear count increases by 1.

[0076] As an embodiment of the present invention, Figure 3 As shown, determining the total inventory value and the average inventory value based on the inventory values ​​of multiple database shards in the distributed database includes:

[0077] Step S21, determining the minimum inventory value among the inventory values ​​of the plurality of database shards in the obtained distributed database;

[0078] Step S22: If the minimum inventory value is less than the preset threshold, the average inventory value is determined based on each inventory value.

[0079] After obtaining the inventory values ​​for each distributed database shard, the system determines whether the current minimum inventory value is less than a preset threshold. If so, inventory scheduling for the database shard begins. This preset threshold serves as the critical value for enabling database shard inventory scheduling and can be set based on actual needs.

[0080] As an embodiment of the present invention, Figure 4 As shown, according to the obtained inventory values ​​of multiple database shards in the distributed database, determining the average inventory value also includes:

[0081] Step S31, summing the inventory values ​​of multiple database shards in the obtained distributed database to determine the total inventory value;

[0082] Step S32: If the total inventory value is not less than the number of database shards, determine the average inventory value based on the total inventory value and the number of database shards;

[0083] Step S33: If the total inventory value is less than the number of database shards, the average inventory value is set to zero.

[0084] Among them, the number of current database shards and the inventory value of each shard are obtained from the distributed database. The total inventory value can be obtained by accumulation. The ratio of the total inventory value to the number of database shards is the average inventory value.

[0085] Furthermore, if the total inventory value is not less than the number of database shards, the resulting ratio is not less than 1, and the average inventory value is rounded to a positive integer. If the total inventory value is less than the number of database shards, the resulting ratio is less than 1, and the average inventory value is 0.

[0086] Specifically, for example, if the number of database shards is 10 and the total inventory value is 100, then the average inventory value is 10; if the number of database shards is 10 and the total inventory value is 9, then the average inventory value is 0.

[0087] As an embodiment of the present invention, the call information includes an inventory clearing timestamp and an inventory clearing count.

[0088] In this embodiment, if Figure 5 As shown, according to the call information corresponding to each database shard, the local inventory scheduling process for each database shard includes:

[0089] Step S41, obtaining the inventory clearing timestamp corresponding to the database shard;

[0090] Step S42: If it is known that there is a database shard without an inventory clearing timestamp, then the inventory is deducted from the database shard with the largest inventory value and no inventory clearing timestamp, and the inventory is increased from the database shard with the latest inventory clearing timestamp.

[0091] In step S43, if it is known that each database shard has a corresponding inventory clearing timestamp, an inventory deduction process is performed on the database shard with the largest inventory value and the earliest inventory clearing timestamp, and an inventory increase process is performed on the database shard with the latest inventory clearing timestamp.

[0092] The inventory reset timestamp is obtained for each database shard. If a database shard does not have an inventory reset timestamp, it indicates that the inventory of that database shard has never been zero and has the highest inventory value, indicating that the database shard is infrequently used. Therefore, the inventory of the database shard with the highest inventory value and no inventory reset timestamp is deducted. The deduction value is generally 1, but can be modified according to actual needs. The shard whose inventory value is increased is the shard with the most recent inventory reset timestamp, that is, the shard with the most recent inventory reset timestamp.

[0093] Furthermore, if the inventory of all shards has been cleared, the inventory of the shard with the earliest database clear timestamp and the largest inventory value is deducted. The earliest inventory timestamp and the largest inventory value indicate that the database shard is less frequently used. Correspondingly, the deducted inventory is added to the shard with the most recent inventory clear timestamp.

[0094] In this embodiment, if Figure 6 As shown, according to the call information corresponding to each database shard, the local inventory scheduling process for each database shard also includes:

[0095] Step S51, obtaining the inventory clearing times corresponding to the database shard;

[0096] Step S52: perform inventory deduction processing on the database shard with the largest inventory value and the smallest number of inventory clearing times, and perform inventory increase processing on the database shard with zero inventory value and the largest number of inventory clearing times.

[0097] When the inventory of all shards has been cleared, local inventory scheduling is performed based on the number of clears for each database shard. Specifically, if a database shard has the fewest clears and the highest inventory value, it indicates that it is infrequently used. Inventory for this database shard is deducted, typically by 1, but this value can be set based on actual circumstances. Correspondingly, the deducted inventory is added to the database shard with the highest number of clears and a value of 0. The highest number of clears indicates that this database shard is frequently used.

[0098] In a specific embodiment of the present invention, Figure 7 The database shard inventory processing process shown includes:

[0099] 1. Create a new background thread to retrieve the total inventory and the inventory of each shard (set) and store them in Redis (RemoteDictionary Server). Set the threshold for starting the background thread. For example, if the set with the lowest inventory falls below XX%, the inventory synchronization function will be triggered.

[0100] 2. Create a new background thread for inventory scheduling.

[0101] (1) Use the rounding method "total inventory / N" to calculate the average inventory value of the quasi-synchronized inventory, where N represents the number of sets (for example, if the remaining inventory is 100 and there are 10 sets, the average value is 10; if the remaining inventory is 9 and there are 10 sets, the average value is 0).

[0102] (2) If the average inventory value is greater than 0, start the overall inventory average scheduling process. Use the set inventory-average value in redis as the amount of inventory to be deducted. First deduct the set library that is higher than the average value. After the deduction, check if it is greater than or equal to 0. At the same time, record the total deduction amount update number = number - increment, in the order from highest to lowest. After the deduction is completed. Then increase the inventory of the set library that is lower than the average value, update number = number + increment, in the order from lowest to highest. Because there may be situations where the deduction cannot be made, it is necessary to additionally control the total amount of increase to be the same as the total amount of deduction.

[0103] (3) If the average inventory value is 0, start local inventory scheduling. Use the shard with the largest inventory and the earliest last inventory 0 timestamp, or the shard without an inventory clearing timestamp, and deduct 1 from the inventory; use the record in Redis with an inventory of 0 and the most recent last inventory 0 timestamp, and increase the inventory by 1. Follow this logic until all inventories are 0, and the inventory is exhausted.

[0104] (4) Optionally, in addition to the solution in step (3), the priority selection condition can also be supported based on the number of inventory 0s in Redis. That is, if the average inventory value = 0, start the local inventory scheduling process. Use the shard with the largest inventory and the smallest number of last inventory 0s, and deduct 1 from the inventory; use the record with the inventory 0 and the largest number of last inventory 0s in Redis, and increase the inventory by 1. According to this logic, when all inventories are 0, the inventory is used up.

[0105] This invention addresses resource imbalance in distributed systems with multiple set libraries through relatively simple inventory scheduling. It ensures that all set resources are fully utilized. Through a simple and efficient scheduling approach, surplus inventory resources are allocated to sets in need, while minimizing the impact on existing systems. This fundamentally solves the inventory management problem of distributed data sets.

[0106] like Figure 8 FIG2 is a schematic diagram of the structure of a distributed database inventory processing device according to an embodiment of the present invention. The device shown in the figure includes:

[0107] An inventory value module 10 is configured to determine an average inventory value based on the acquired inventory values ​​of multiple database shards in the distributed database;

[0108] The overall inventory scheduling module 20, if the average inventory value is greater than zero, performs inventory deduction processing on the database shards whose inventory values ​​are higher than the average inventory value, and performs inventory increase processing on the database shards whose inventory values ​​are lower than the average inventory value, increasing the inventory quantity of the average inventory value so that the inventory value of each database shard is equal to the average inventory value;

[0109] The inventory local scheduling module 30 is used to perform local inventory scheduling processing on each database shard according to the call information corresponding to each database shard if the inventory average value is equal to zero.

[0110] As an embodiment of the present invention, Figure 9 As shown, the inventory value module 10 includes:

[0111] The inventory minimum value unit 11 is used to determine the inventory minimum value among the inventory values ​​according to the inventory values ​​of multiple database shards obtained in the distributed database;

[0112] The scheduling threshold unit 12 is configured to determine an average inventory value based on each inventory value if the minimum inventory value is less than a preset threshold value.

[0113] As an embodiment of the present invention, Figure 10 As shown, the inventory value module 10 further includes:

[0114] A total inventory value unit 13 is used to sum the inventory values ​​of multiple database shards obtained in the distributed database to determine the total inventory value;

[0115] The inventory average value unit 14 is used to determine the inventory average value based on the total inventory value and the number of database shards if the total inventory value is not less than the number of database shards; if the total inventory value is less than the number of database shards, set the inventory average value to zero.

[0116] As an embodiment of the present invention, Figure 11 As shown, the inventory local scheduling module 30 includes:

[0117] A reset timestamp unit 31 is used to obtain an inventory reset timestamp corresponding to a database shard;

[0118] The first local scheduling unit 32 is configured to, if it is detected that there is a database shard without an inventory clearing timestamp, deduct inventory from the database shard with the largest inventory value and without an inventory clearing timestamp, and increase inventory from the database shard with the latest inventory clearing timestamp;

[0119] The second local scheduling unit 33 is configured to, upon learning that each database shard has a corresponding inventory clearing timestamp, deduct inventory from the database shard with the largest inventory value and the earliest inventory clearing timestamp, and increase inventory from the database shard with the latest inventory clearing timestamp.

[0120] As an embodiment of the present invention, Figure 12 As shown, the inventory local scheduling module 30 also includes:

[0121] A clearing times unit 34 is used to obtain the inventory clearing times corresponding to the database shard;

[0122] The third local scheduling unit 35 is configured to perform inventory deduction processing on the database shard with the largest inventory value and the smallest number of inventory clearing operations, and perform inventory increase processing on the database shard with zero inventory value and the largest number of inventory clearing operations.

[0123] Based on the same application concept as the aforementioned distributed database inventory processing method, the present invention also provides the aforementioned distributed database inventory processing device. Because the principles underlying the distributed database inventory processing device are similar to those of the distributed database inventory processing method, the implementation of the distributed database inventory processing device can be referenced to the implementation of the distributed database inventory processing method, and any repetitive details will not be repeated.

[0124] The present invention achieves resource balancing of multiple database shards in a distributed system through a simple and easy-to-operate inventory scheduling method, efficiently allocates remaining inventory resources to database shards that need resources, so that resources on all database shards can be fully utilized, with little impact on the existing system, fundamentally solving the inventory management problem of distributed data with multiple shards.

[0125] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.

[0126] The present invention also provides a computer-readable storage medium storing a computer program for executing the above method.

[0127] like Figure 13 As shown, the electronic device 600 may further include: a communication module 110, an input unit 120, an audio processing unit 130, a display 160, and a power supply 170. It is worth noting that the electronic device 600 does not necessarily have to include Figure 13 In addition, the electronic device 600 may also include all components shown in Figure 13 For components not shown, reference may be made to the prior art.

[0128] like Figure 13 As shown, the central processing unit 100 is sometimes also referred to as a controller or an operation control unit, and may include a microprocessor or other processor device and / or logic device. The central processing unit 100 receives inputs and controls the operations of various components of the electronic device 600 .

[0129] Memory 140 may be, for example, one or more of a cache, flash memory, hard drive, removable media, volatile memory, non-volatile memory, or other suitable devices. It may store the aforementioned failure-related information and may also store programs that execute the relevant information. The CPU 100 may execute the programs stored in memory 140 to implement information storage or processing.

[0130] The input unit 120 provides input to the CPU 100. The input unit 120 may be, for example, a keypad or touch input device. The power supply 170 is used to provide power to the electronic device 600. The display 160 is used to display objects such as images and text. The display may be, for example, an LCD display, but is not limited thereto.

[0131] The memory 140 may be a solid-state memory, such as a read-only memory (ROM), a random access memory (RAM), or a SIM card. Alternatively, it may be a memory that retains information even when power is off, can be selectively erased, and is provided with more data. Examples of such memory are sometimes referred to as EPROMs. The memory 140 may also be some other type of device. The memory 140 includes a buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application / function storage unit 142 for storing application programs and function programs or processes for executing the operations of the electronic device 600 via the central processing unit 100.

[0132] The memory 140 may also include a data storage unit 143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 144 of the memory 140 may include various driver programs for communication functions of the electronic device and / or for executing other functions of the electronic device (such as messaging applications, address book applications, etc.).

[0133] The communication module 110 is a transmitter / receiver 110 that transmits and receives signals via an antenna 111. The communication module (transmitter / receiver) 110 is coupled to the central processor 100 to provide input signals and receive output signals, which may be the same as in a conventional mobile communication terminal.

[0134] Based on different communication technologies, multiple communication modules 110 may be provided in the same electronic device, such as a cellular network module, a Bluetooth module, and / or a wireless local area network module. The communication module (transmitter / receiver) 110 is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide audio output via the speaker 131 and receive audio input from the microphone 132, thereby implementing common telecommunication functions. The audio processor 130 may include any suitable buffer, decoder, amplifier, etc. Furthermore, the audio processor 130 is also coupled to the central processing unit 100, enabling local recording via the microphone 132 and playback of stored audio via the speaker 131.

[0135] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0136] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0137] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0138] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0139] Specific embodiments are used in the present invention to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core ideas. At the same time, for those skilled in the art, according to the ideas of the present invention, there may be changes in the specific implementation methods and application scopes. In summary, the contents of this specification should not be understood as limiting the present invention.

Claims

1. A distributed database inventory processing method, characterized in that: The method comprises: Determine the average inventory value based on the inventory values ​​of multiple database shards in the distributed database. The ratio of the total inventory value to the number of database shards is rounded to the average inventory value. If the total inventory value is less than the number of database shards and the obtained ratio is less than 1, the average inventory value is directly 0. If the average inventory value is greater than zero, the database shards whose inventory values ​​are higher than the average inventory value are subjected to inventory deduction processing, and the database shards whose inventory values ​​are lower than the average inventory value are subjected to inventory increase processing, increasing the inventory quantity of the average inventory value so that the inventory value of each database shard is equal to the average inventory value; If the inventory average value is zero, local inventory scheduling is performed on each database shard based on the call information corresponding to each database shard; The call information includes an inventory clearing timestamp and an inventory clearing count; and performing local inventory scheduling on each database shard based on the call information corresponding to each database shard includes: Obtain the inventory clearing timestamp corresponding to the database shard, and perform local inventory scheduling on each database shard based on the inventory clearing timestamp corresponding to each database shard: if it is known that there is a database shard without an inventory clearing timestamp, perform inventory deduction on the database shard with the largest inventory value and no inventory clearing timestamp, and perform inventory increase on the database shard with the latest inventory clearing timestamp; if it is known that all database shards have corresponding inventory clearing timestamps, perform inventory deduction on the database shard with the largest inventory value and the earliest inventory clearing timestamp, and perform inventory increase on the database shard with the latest inventory clearing timestamp.

2. The method according to claim 1, characterized in that Determining the average inventory value based on the acquired inventory values ​​of the plurality of database shards in the distributed database includes: Determine the minimum inventory value among the inventory values ​​of the multiple database shards obtained in the distributed database; If the minimum inventory value is less than a preset threshold, an average inventory value is determined based on each inventory value.

3. The method according to claim 1, characterized in that Determining the average inventory value based on the acquired inventory values ​​of the plurality of database shards in the distributed database further includes: Sum the inventory values ​​of multiple database shards in the obtained distributed database to determine the total inventory value; If the total inventory value is not less than the number of database shards, then determining the average inventory value based on the total inventory value and the number of database shards; If the total inventory value is less than the number of database shards, the average inventory value is set to zero.

4. The method according to claim 1, wherein The performing local inventory scheduling processing on each database shard according to the call information corresponding to each database shard further includes: Get the number of inventory clearing times corresponding to the database shard; The database shard with the largest inventory value and the smallest number of inventory clearing operations is deducted from the inventory, and the database shard with zero inventory value and the largest number of inventory clearing operations is increased from the inventory.

5. A distributed database inventory processing device, characterized in that: The device comprises: The inventory value module is used to determine the inventory average based on the inventory values ​​of multiple database shards in the distributed database. The ratio of the total inventory value to the number of database shards is rounded to the inventory average. If the total inventory value is less than the number of database shards and the obtained ratio is less than 1, the inventory average is directly set to 0; The overall inventory scheduling module, if the inventory average value is greater than zero, performs inventory deduction processing on the database shards whose inventory values ​​are higher than the inventory average value, and performs inventory increase processing on the database shards whose inventory values ​​are lower than the inventory average value, increasing the inventory quantity of the inventory average value so that the inventory value of each database shard is equal to the inventory average value; An inventory local scheduling module, configured to perform local inventory scheduling processing on each database shard based on call information corresponding to each database shard if the inventory average value is zero; The call information includes an inventory clearing timestamp and an inventory clearing count; the inventory local scheduling module is specifically used to: Obtain the inventory clearing timestamp corresponding to the database shard, and perform local inventory scheduling on each database shard based on the inventory clearing timestamp corresponding to each database shard: if it is known that there is a database shard without an inventory clearing timestamp, perform inventory deduction on the database shard with the largest inventory value and no inventory clearing timestamp, and perform inventory increase on the database shard with the latest inventory clearing timestamp; if it is known that all database shards have corresponding inventory clearing timestamps, perform inventory deduction on the database shard with the largest inventory value and the earliest inventory clearing timestamp, and perform inventory increase on the database shard with the latest inventory clearing timestamp.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.

7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data migration method and device of distributed database cluster

    CN106844510A

  • Inventory item management method and system suitable for multiple scenes, terminal and storage medium

    CN112069253A