Commodity inventory deduction method and device
By creating multiple threads in the case of high concurrency, and generating compensation records after successful execution, the problem of oversold inventory deduction operations in the existing technology is solved, and the system's parallel processing capability is improved and user experience.
Patent Information
- Application Number
- CN202111108670.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-22
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2041-09-22
AI Technical Summary
The prior art is prone to oversold problems of commodity inventory deductions under high concurrency conditions, affecting the user experience.
By receiving product inventory deduction requests, create multiple threads to perform inventory deduction operations in parallel, perform corresponding inventory deduction operations in different databases, and generate compensation records after successful execution to avoid overselling.
It improves the parallel processing capability of inventory deduction operations, reduces the probability of deadlocks, avoids oversold goods, improves user experience, and improves the system's qps and overall throughput.
Smart Images

Figure CN113836158B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a commodity inventory deduction method and device. Background Art
[0002] With the development of Internet technology and the popularization of mobile terminals, people are becoming more and more accustomed to purchasing goods through e-commerce platforms. When processing goods ordered by users, e-commerce platforms need to deduct / freeze the inventory of goods based on the inventory keeping unit (SKU) of the goods. For ordinary goods, there is no high concurrency of orders and inventory deductions. However, for flash sales of multiple goods, there is a high concurrency of orders and inventory deductions. In the state of high concurrency of commodity inventory deductions, overselling problems are prone to occur, affecting user experience. Summary of the invention
[0003] In view of this, a commodity inventory deduction method, device, computer equipment and computer-readable storage medium are now provided to solve the problem that the existing inventory deduction operation is prone to overselling.
[0004] This application provides a commodity inventory deduction method, including:
[0005] receiving a commodity inventory deduction request, wherein the commodity inventory deduction request includes inventory deduction quantities of a plurality of commodities to be deducted and inventory identification information of a plurality of commodities to be deducted;
[0006] Determine a database storing inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted;
[0007] When there are multiple determined databases, multiple threads are created, and corresponding inventory deduction operations are performed in parallel in the corresponding databases according to the inventory deduction quantities corresponding to the commodities to be deducted through the multiple threads, wherein each thread corresponds to one database;
[0008] When there is a thread that fails to successfully execute the inventory deduction operation, a corresponding compensation record is generated according to all successfully executed inventory deduction operations, and the compensation record is written into the inventory compensation table, wherein the compensation record includes the inventory identification information of the commodity to be compensated and the inventory deduction quantity;
[0009] A compensation record is obtained from the inventory compensation table, and the inventory information stored in the corresponding database is updated with compensation according to the inventory identification information and the inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record.
[0010] Optionally, the database storing the inventory information of the commodities is divided into sub-libraries and sub-tables according to the inventory identification information of the commodities, so that the inventory information of different commodities is stored in different databases.
[0011] Optionally, determining a database storing inventory information of each commodity to be deducted according to inventory identification information of each commodity to be deducted includes:
[0012] Sort the inventory identification information of each commodity to be deducted;
[0013] A database storing inventory information of each commodity to be deducted is determined according to the sorted inventory identification information of each commodity to be deducted.
[0014] Optionally, after the step of executing the corresponding inventory deduction operation in the corresponding database according to the corresponding inventory deduction quantity in parallel through multiple threads, the method further includes:
[0015] When all threads have successfully executed the inventory deduction operation, a message of successful inventory deduction is returned to the sender of the commodity inventory deduction request; and
[0016] When there is a thread that fails to execute the inventory deduction operation successfully, an inventory deduction failure message is returned to the sending end of the commodity inventory deduction request.
[0017] Optionally, the method further comprises:
[0018] After the thread successfully executes the inventory deduction operation, inserting the inventory deduction operation into the inventory update flow table;
[0019] When there is a thread that fails to successfully execute the inventory deduction operation, the inserted inventory deduction operation is deleted from the inventory update flow table.
[0020] Optionally, obtaining a compensation record from the inventory compensation table, and performing compensation update on the inventory information stored in the corresponding database according to the inventory identification information and the inventory deduction quantity of the commodity to be compensated in the obtained compensation record includes:
[0021] The compensation records are obtained from the inventory compensation table at regular intervals, and the inventory information stored in the corresponding database is updated based on the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation records.
[0022] Optionally, the commodity inventory deduction request is an inventory deduction request for multiple orders, and after the step of receiving the commodity inventory deduction request, the step further includes:
[0023] Aggregate inventory reduction requests with the same inventory identification information contained in multiple orders.
[0024] The present application also provides a commodity inventory deduction device, comprising:
[0025] A receiving module, configured to receive a commodity inventory deduction request, wherein the commodity inventory deduction request includes inventory deduction quantities of multiple commodities to be deducted and inventory identification information of multiple commodities to be deducted;
[0026] A determination module, used to determine a database storing inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted;
[0027] A deduction module is used to create multiple threads when there are multiple determined databases, and execute corresponding inventory deduction operations in the corresponding databases in parallel according to the inventory deduction quantities corresponding to the commodities to be deducted through the multiple threads, wherein each thread corresponds to one database;
[0028] A generating module, configured to generate corresponding compensation records according to all successfully executed inventory deduction operations when there is a thread that fails to execute the inventory deduction operation, and write the compensation records into an inventory compensation table, wherein the compensation records include inventory identification information and inventory deduction quantity of the commodity to be compensated;
[0029] The compensation module is used to obtain the compensation record from the inventory compensation table, and to compensate and update the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record.
[0030] The present application also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0031] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.
[0032] This embodiment can improve the parallel processing capability of inventory deduction operations by concurrently executing inventory deduction operations in different databases through different threads after receiving inventory deduction operations for multiple commodities, rather than implementing inventory deduction operations in one database through one transaction. And because the inventory deduction operations are executed in different databases, the probability of deadlock can be reduced. In addition, when the thread of the present application fails to successfully execute the inventory deduction operation, a compensation record will be generated so that the inventory data can be compensated in time according to the compensation record, thereby avoiding overselling of commodities and improving user experience. In addition, the inventory deduction method of the present application can improve the qps (query rate per second) by 3-5 times under the same hardware conditions, and can improve the overall inventory throughput and carrying capacity. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 This is a schematic diagram of the environment of the commodity inventory deduction method according to an embodiment of the present application;
[0034] Figure 2 A flowchart of an embodiment of the commodity inventory deduction method described in this application;
[0035] Figure 3 A schematic diagram of a detailed flow chart of the steps of determining a database storing inventory information of each commodity to be deducted according to inventory identification information of each commodity to be deducted in one embodiment of the present application;
[0036] Figure 4 A flowchart of another embodiment of the commodity inventory deduction method described in the present application;
[0037] Figure 5 A flowchart of another embodiment of the commodity inventory deduction method described in the present application;
[0038] Figure 6 A flowchart of the steps of obtaining a compensation record from the inventory compensation table in one embodiment of the present application, and compensating and updating the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record;
[0039] Figure 7 A program module diagram of an embodiment of the commodity inventory deduction device described in this application;
[0040] Figure 8 A schematic diagram of the hardware structure of a computer device for executing a commodity inventory deduction method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The advantages of the present application are further described below in conjunction with the accompanying drawings and specific embodiments.
[0042] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0043] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0044] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0045] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.
[0046] Figure 1 The schematic diagram of the application environment of the commodity inventory deduction method according to the embodiment of the present application is schematically shown. In an exemplary embodiment, the system of the application environment may include a terminal device 10, and the server 20 may include an e-commerce server and an inventory server. Among them, the terminal device 10 forms a wireless or wired connection with the server 20. The terminal device 10 can be a mobile phone, an iPAD, a tablet computer, etc. The server 20 can be a server cluster or a cloud computing center composed of one server or multiple servers, etc., which is not limited here. The user can place an order to purchase goods through the commodity shopping APP installed in the terminal device 10, and send the user's order to the e-commerce server. The e-commerce server is used to generate an inventory deduction request based on the user's order, and send the inventory deduction request to the inventory server. The inventory server is used to implement the inventory deduction operation according to the inventory deduction request.
[0047] It is understandable that in other embodiments of the present application, the server 20 may also only include an inventory server. Accordingly, after receiving the user's order, the terminal device 10 will generate a corresponding inventory deduction request according to the order, and then send the inventory deduction request to the inventory server, so that the inventory server can implement the inventory deduction operation according to the inventory deduction request.
[0048] See also Figure 2, which is a flowchart of a commodity inventory deduction method in an embodiment of the present application. It can be understood that the flowchart in the embodiment of the present method is not used to limit the order of executing the steps. As can be seen from the figure, the commodity inventory deduction method provided in the present embodiment includes:
[0049] Step S20: receiving a commodity inventory deduction request, wherein the commodity inventory deduction request includes inventory deduction quantities of multiple commodities to be deducted and inventory identification information of multiple commodities to be deducted.
[0050] Specifically, the multiple commodities to be deducted are commodities that need to be deducted from the inventory, and may include multiple different commodities to be deducted, or may include multiple identical commodities to be deducted. For example, the multiple commodities to be deducted may include commodity a to be deducted, commodity b to be deducted, and commodity c to be deducted. The multiple commodities to be deducted may also include two commodities a to be deducted and one commodity b to be deducted.
[0051] It should be noted that the different commodities to be deducted in this embodiment refer to commodities with different SKUs (Stockkeeping Units), and SKUs are in units of pieces, boxes, pallets, etc. SKU is the smallest physically indivisible inventory unit of a commodity. When in use, it should be handled according to different business formats and different management modes. It is most commonly used in clothing and footwear. For example, a piece of clothing has styles of different colors, and the different styles of clothing are all clothes with different SKUs, that is, they can be different commodities to be deducted.
[0052] The inventory deduction quantity corresponds to the quantity of the goods to be deducted that the user has ordered and purchased, and is the quantity of the inventory of the goods to be deducted that needs to be deducted / frozen.
[0053] The inventory identification information is information used to uniquely distinguish different commodities to be deducted. In the present embodiment, the inventory identification information is SKUID, and different commodities to be deducted have different inventory identification information. For example, the inventory identification information corresponding to commodity a to be deducted is SKUID1, and the inventory identification information corresponding to commodity b to be deducted is SKUID2.
[0054] In an exemplary implementation, when the received commodity inventory deduction request is an inventory deduction request for multiple orders, that is, the current commodity inventory deduction operation includes inventory deduction requests generated by multiple users placing orders at the same time, in this embodiment, in order to improve the tps (system throughput) of the database, the method further includes:
[0055] Aggregate inventory reduction requests with the same inventory identification information contained in multiple orders.
[0056] As an example, assume that the inventory deduction request for goods is an inventory deduction request for 2 orders, specifically including an inventory deduction request for order 1 and an inventory deduction request for order 2, wherein the inventory deduction request for order 1 includes the inventory deduction quantity N and inventory identification information SKUID1 of commodity A to be deducted and the inventory deduction quantity M and inventory identification information SKUID2 of commodity B to be deducted; the inventory deduction request for order 2 includes the inventory deduction quantity I and inventory identification information SKUID1 of commodity A to be deducted and the inventory deduction quantity P and inventory identification information SKUID3 of commodity C to be deducted. In this embodiment, the inventory deduction requests with the same inventory identification information can be aggregated, and the aggregated inventory deduction requests for goods are the following three inventory deduction requests: the inventory deduction quantity N+I and inventory identification information SKUID1 of commodity A to be deducted, the inventory deduction quantity M and inventory identification information SKUID2 of commodity B to be deducted, and the inventory deduction quantity P and inventory identification information SKUID3 of commodity C to be deducted.
[0057] Step S21, determining a database storing inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted.
[0058] Specifically, a modulo operation (or remainder operation) can be performed on the inventory identification information of the goods to be deducted, and then a database storing the inventory information of each of the goods to be deducted can be determined according to the result of the modulo operation. Specifically, the following mod function can be used to determine the database storing the inventory information of each of the goods to be deducted.
[0059] mod(nExp1,nExp2), where nExp1 is the inventory identification information, and nExp2 is the total number of databases. Assuming that in this embodiment, the inventory identification information is 17, and there are a total of 16 databases, the database corresponding to the inventory identification information 17 is mod(17,16)=1, indicating that the database corresponding to the to-be-deducted product with the inventory identification information 17 is the first database.
[0060] It can be understood that in order to determine the database corresponding to each commodity to be deducted, the association relationship between the databases corresponding to the values obtained after processing by the mod function can be established in advance. For example, when mod(nExp1,nExp2)=1, it is associated with database A; when mod(nExp1,nExp2)=2, it is associated with database B; when mod(nExp1,nExp2)=3, it is associated with database C, etc.
[0061] In an exemplary embodiment, in order to subsequently determine a database storing inventory information of each commodity to be deducted according to the inventory identification information of the commodity to be deducted, the method further includes:
[0062] The database storing the inventory information of the commodities is divided into different databases according to the inventory identification information of the commodities, so that the inventory information of different commodities is stored in different databases.
[0063] Specifically, database sharding is to solve the problem of database performance degradation caused by excessive data volume. The original independent database is split into several databases, and the large data table is split into several data tables, so that the data volume of a single database and a single data table becomes smaller, thereby achieving the purpose of improving database performance. Database sharding includes two parts: database sharding and table sharding. In production, there are usually four methods: vertical database sharding, horizontal database sharding, vertical table sharding, and horizontal table sharding.
[0064] As an example, the database for inventory information of goods can be divided into 16 databases, and the data table storing inventory information of goods can be divided into 16 tables, wherein each database is used to store inventory information of goods corresponding to inventory identification information of different ranges. Accordingly, different data tables contain inventory information of goods corresponding to inventory identification information of different ranges. For example, the data table of database 1 contains the inventory information of all goods whose remainder result is 1 after the inventory identification information is processed by remainder; the data table of database 2 contains the inventory information of all goods whose remainder result is 2 after the inventory identification information is processed by remainder; and so on, the data table of database 15 contains the inventory information of all goods whose remainder result is 15 after the inventory identification information is processed by remainder; the data table of database 16 contains the inventory information of all goods whose remainder result is 0 after the inventory identification information is processed by remainder.
[0065] In an exemplary embodiment, in order to further reduce the probability of deadlock, refer to Figure 3 , the database for storing the inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted may include:
[0066] Step S30, sorting the inventory identification information of each commodity to be deducted.
[0067] Specifically, the inventory identification information may be sorted from large to small, or from small to large, according to the size of the inventory identification information.
[0068] As an example, assuming there are 5 inventory identification information, namely SKUID5, SKUID9, SKUID3, SKUID1, and SKUID7, then these 5 inventory identification information can be sorted in ascending order. The 5 inventory identification information after sorting are: SKUID1, SKUID3, SKUID5, SKUID7, and SKUID9.
[0069] Step S31, determining a database storing inventory information of each commodity to be deducted according to the sorted inventory identification information of each commodity to be deducted.
[0070] Specifically, after obtaining the sorted inventory identification information, the database storing the inventory information of each commodity to be deducted can be determined in the sorted order. The specific method of determining the database has been described in detail in the above embodiment and will not be repeated in this embodiment.
[0071] In this embodiment, by sorting the inventory identification information, the subsequent execution of the inventory deduction request can be executed in sequence, thereby avoiding resource competition caused by row locks when executing the inventory deduction request, and further avoiding the deadlock problem.
[0072] Step S22, when there are multiple determined databases, create multiple threads, and use the multiple threads to perform corresponding inventory deduction operations in the corresponding databases in parallel according to the inventory deduction quantities corresponding to the commodities to be deducted, wherein each thread corresponds to one database.
[0073] Specifically, when it is determined that there are multiple databases storing inventory information of each commodity to be deducted, threads equal to the number of databases will be created so that the inventory deduction operation is performed in a corresponding database through each thread processing. For example, if there are 4 databases, 4 threads need to be created.
[0074] As an example, assuming that there are always databases and 4 threads, namely database 1, database 2, database 3, database 4 and thread 1, thread 2, thread 3 and thread 4, then the inventory deduction operation can be executed in parallel in database 1 through thread 1, in database 2 through thread 2, in database 3 through thread 3, and in database 4 through thread 4.
[0075] The inventory deduction operation refers to deducting / freezing the inventory of the quantity to be deducted from the current inventory information in the database according to the quantity to be deducted, so as to update the inventory information. For example, if the current inventory information is 50 and the quantity to be deducted is 20, the inventory information after the deduction operation is performed is 50-20=30.
[0076] In this embodiment, when each thread performs an inventory deduction operation, the innoDb row lock of the MySQL database can be used to ensure that the inventory will not be over-deducted or under-deducted in a high-concurrency scenario.
[0077] Step S23: when there is a thread that fails to execute the inventory deduction operation successfully, a corresponding compensation record is generated according to all successfully executed inventory deduction operations, and the compensation record is written into the inventory compensation table.
[0078] Specifically, the inventory compensation table is used to record inventory compensation information. Through the inventory compensation table, the deducted inventory can be compensated and updated to achieve the recovery of inventory information.
[0079] As an example, suppose there are a total of 6 threads performing inventory deduction operations, among which 5 threads successfully perform the inventory deduction operations and 1 thread fails to perform the inventory deduction operations. At this time, compensation records will be generated for the 5 successful inventory deduction operations, and one compensation record will be generated for each successful inventory deduction operation. That is to say, a total of 5 compensation records will be generated.
[0080] The compensation record includes the inventory identification information and inventory deduction quantity of the commodity to be compensated.
[0081] It should be noted that the commodities to be compensated in this embodiment refer to commodities for which the inventory deduction operation has been successfully performed through the thread.
[0082] Step S24, obtaining a compensation record from the inventory compensation table, and performing compensation update on the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record.
[0083] Specifically, when performing compensation update, the database storing the inventory information of the commodity to be compensated can be first found according to the inventory identification information of the commodity to be compensated in the compensation record. The specific method has been described in detail in the above embodiment and will not be repeated in this embodiment. After determining the database, the inventory information stored in the database can be compensated and updated according to the inventory deduction quantity to realize the recovery of the commodity inventory.
[0084] This embodiment can improve the parallel processing capability of inventory deduction operations by concurrently executing inventory deduction operations in different databases through different threads after receiving inventory deduction operations for multiple commodities, rather than implementing inventory deduction operations in one database through one transaction. And because the inventory deduction operations are executed in different databases, the probability of deadlock can be reduced. In addition, when the thread of the present application fails to successfully execute the inventory deduction operation, a compensation record will be generated so that the inventory data can be compensated in time according to the compensation record, thereby avoiding overselling of commodities and improving user experience. In addition, the inventory deduction method of the present application can improve the qps (query rate per second) by 3-5 times under the same hardware conditions, and can improve the overall inventory throughput and carrying capacity.
[0085] In an exemplary embodiment, see Figure 4After the step of executing the corresponding inventory deduction operation in the corresponding database according to the corresponding inventory deduction quantity in parallel through multiple threads, it also includes: step S40, when all threads successfully execute the inventory deduction operation, returning an inventory deduction success message to the sending end of the commodity inventory deduction request; step S41, when there is a thread that fails to successfully execute the inventory deduction operation, returning an inventory deduction failure message to the sending end of the commodity inventory deduction request.
[0086] Specifically, when all threads have successfully executed the inventory deduction operation, an inventory deduction success message can be returned to the sender of the commodity inventory deduction request to prompt the sender user that the order to purchase the commodity has been successfully placed; when there is a thread that has not successfully executed the inventory deduction operation, an inventory deduction failure message is returned to the sender of the commodity inventory deduction request to prompt the sender user that the order to purchase the commodity has failed and there is insufficient inventory of the commodity.
[0087] In this embodiment, after the thread executes the inventory deduction operation, an execution result message is returned to the sending end, so that the sending end can know the result of the user's order in time.
[0088] In an exemplary embodiment, see Figure 5 , the method may further include:
[0089] Step S50: After the thread successfully executes the inventory deduction operation, the inventory deduction operation is inserted into the inventory update flow table.
[0090] Specifically, the inventory update flow table is a data table used to record the update status of inventory information.
[0091] Step S51: when there is a thread that fails to execute the inventory deduction operation successfully, the inserted inventory deduction operation is deleted from the inventory update flow table.
[0092] Specifically, when a thread fails to successfully execute an inventory deduction operation, in order to be able to query the inventory request according to the inventory update flow table later, the inserted inventory deduction operation needs to be deleted from the inventory update flow table.
[0093] In this embodiment, after a thread successfully executes an inventory deduction operation, the inventory deduction operation is inserted into the inventory update flow table. After a thread fails to successfully execute the inventory deduction operation, the inserted inventory deduction operation is deleted from the inventory update flow table, so that the inventory flow table can accurately record the inventory update status.
[0094] In an exemplary embodiment, see Figure 6, the obtaining of compensation records from the inventory compensation table, and compensating and updating the inventory information stored in the corresponding database according to the inventory identification information and the inventory deduction quantity of the to-be-compensated goods in the obtained compensation records may include: step S60, periodically obtaining compensation records from the inventory compensation table, and compensating and updating the inventory information stored in the corresponding database according to the inventory identification information and the inventory deduction quantity of the to-be-compensated goods in the obtained compensation records.
[0095] Specifically, compensation records for which compensation operations have not been performed may be pulled from the inventory compensation table at preset intervals, and then the inventory information stored in the database may be compensated and updated according to the pulled compensation records to implement inventory update of the inventory information stored in the database.
[0096] In this embodiment, each time a compensation operation is executed, the compensation record corresponding to the compensation operation may be added with execution status information, and the status information may be "compensation success" or "compensation failure". When the status information is "compensation failure", the compensation operation needs to be executed again according to the compensation record until the compensation operation is successfully executed.
[0097] In an exemplary embodiment, in order to reduce the number of compensation times, before performing the compensation operation, the compensation records with the same inventory identification information can be merged to merge multiple compensation records with the same inventory identification information into one compensation record. In this way, when the compensation operation is performed subsequently, only one compensation operation needs to be performed for the multiple compensation records.
[0098] It should be noted that the compensation operation in this embodiment refers to an operation of compensating and updating the inventory information stored in the corresponding database according to the inventory identification information and the inventory deduction quantity of the commodity to be compensated in the compensation record.
[0099] In this embodiment, the inventory information stored in the database is periodically updated based on the compensation records in the inventory compensation table, thereby ensuring that the inventory information stored in the database is accurate.
[0100] In order to facilitate the understanding of the present application, the technical solution of the present application is described below with reference to a specific example.
[0101] If the inventory deduction operation is performed on three commodities to be deducted (the inventory identification information is SKUID1, SKUID2 and SKUID17 respectively), after the modulo 16 operation, the inventory information of the commodities to be deducted corresponding to SKUID1 and SKUID17 is in one database, and the inventory information of the commodities to be deducted corresponding to SKUID2 is in another database, then two library threads are created, thread 1 performs the inventory deduction operation on the inventory information of the commodities to be deducted corresponding to SKUID1 and SKUID17, and thread 2 performs the inventory deduction operation on the inventory information of the commodities to be deducted corresponding to SKUID2. If the inventory deduction operation of the inventory information of the commodities to be deducted corresponding to SKUID2 is successful, the corresponding thread 2 operation is successful, and the inventory deduction operation is inserted into the inventory update flow table. If the inventory deduction operation of the inventory information of the goods to be deducted corresponding to SKUID1 succeeds, but the inventory deduction operation of the inventory information of the goods to be deducted corresponding to SKUID17 fails, the corresponding thread 1 operation fails, and only the inventory deduction operation corresponding to SKUID1 is inserted into the inventory update flow, and the inventory deduction operation corresponding to SKUID17 is not inserted into the inventory update flow. Since one of thread 1 and thread 2 fails, the inventory deduction failure message is returned to the sender, the inventory update flow inserted by thread 2 is deleted, and the inventory deduction operation corresponding to SKUID1 and the inventory deduction operation corresponding to SKUID2 are recorded in the inventory compensation table.
[0102] See also Figure 7 , which is a program module diagram of an embodiment of a commodity inventory deduction device 70 of the present application.
[0103] In this embodiment, the commodity inventory deduction device 70 includes a series of computer program instructions stored in a memory. When the computer program instructions are executed by a processor, the commodity inventory deduction function of each embodiment of the present application can be implemented. In some embodiments, based on the specific operations implemented by each part of the computer program instructions, the commodity inventory deduction device 70 can be divided into one or more modules. The specific modules that can be divided are as follows:
[0104] A receiving module 71 is used to receive a commodity inventory deduction request, wherein the commodity inventory deduction request includes inventory deduction quantities of multiple commodities to be deducted and inventory identification information of multiple commodities to be deducted;
[0105] A determination module 72, configured to determine a database storing inventory information of each commodity to be deducted according to inventory identification information of each commodity to be deducted;
[0106] The deduction module 73 is used to create multiple threads when there are multiple determined databases, and execute corresponding inventory deduction operations in the corresponding databases in parallel according to the inventory deduction quantities corresponding to the commodities to be deducted through the multiple threads, wherein each thread corresponds to one database;
[0107] A generating module 74 is used for generating corresponding compensation records according to all successfully executed inventory deduction operations when there is a thread that fails to execute the inventory deduction operation, and writing the compensation records into the inventory compensation table, wherein the compensation records include inventory identification information and inventory deduction quantity of the commodity to be compensated;
[0108] The compensation module 75 is used to obtain the compensation record from the inventory compensation table, and to perform compensation update on the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record.
[0109] In an exemplary embodiment, the commodity inventory deduction device 70 further includes a sub-library and sub-table module.
[0110] The library and table division module is used to divide the database storing the inventory information of commodities into libraries and tables according to the inventory identification information of commodities, so as to store the inventory information of different commodities in different databases.
[0111] In an exemplary embodiment, the determination module 72 is further used to sort the inventory identification information of each commodity to be deducted; and determine a database storing the inventory information of each commodity to be deducted according to the sorted inventory identification information of each commodity to be deducted.
[0112] In an exemplary embodiment, the commodity inventory deduction device 70 further includes a return module.
[0113] The return module is used to return an inventory deduction success message to the sending end of the commodity inventory deduction request when all threads successfully execute the inventory deduction operation; and to return an inventory deduction failure message to the sending end of the commodity inventory deduction request when there is a thread that fails to successfully execute the inventory deduction operation.
[0114] In an exemplary embodiment, the commodity inventory deduction device 70 further includes an insertion module and a deletion module.
[0115] The insertion module is used to insert the inventory deduction operation into the inventory update flow table after the thread successfully executes the inventory deduction operation.
[0116] The deleting module is used to delete the inserted inventory deduction operation from the inventory update flow table when there is a thread that fails to execute the inventory deduction operation successfully.
[0117] In an exemplary embodiment, the compensation module 75 is also used to periodically obtain compensation records from the inventory compensation table, and to compensate and update the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated goods in the obtained compensation records.
[0118] In an exemplary embodiment, the commodity inventory deduction request is an inventory deduction request for multiple orders, and the commodity inventory deduction device 70 further includes an aggregation module.
[0119] The aggregation module is used to aggregate inventory deduction requests with the same inventory identification information contained in multiple orders.
[0120] This embodiment can improve the parallel processing capability of inventory deduction operations by concurrently executing inventory deduction operations in different databases through different threads after receiving inventory deduction operations for multiple commodities, rather than implementing inventory deduction operations in one database through one transaction. And because the inventory deduction operations are executed in different databases, the probability of deadlock can be reduced. In addition, when the thread of the present application fails to successfully execute the inventory deduction operation, a compensation record will be generated so that the inventory data can be compensated in time according to the compensation record, thereby avoiding overselling of commodities and improving user experience. In addition, the inventory deduction method of the present application can improve the qps (query rate per second) by 3-5 times under the same hardware conditions, and can improve the overall inventory throughput and carrying capacity.
[0121] Figure 8 The hardware architecture diagram of a computer device 8 suitable for implementing the commodity inventory deduction method according to an embodiment of the present application is schematically shown. In this embodiment, the computer device 8 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. For example, it can be a tablet computer, a laptop computer, a desktop computer, a rack server, a blade server, a tower server or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Figure 8 As shown, the computer device 8 includes at least but is not limited to: a memory 120, a processor 121, and a network interface 122 that can communicate with each other through a system bus. Among them:
[0122] The memory 120 includes at least one type of computer-readable storage medium, which may be volatile or non-volatile. Specifically, the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 120 may be an internal storage module of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 120 may also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the memory 120 may also include both the internal storage module of the computer device 8 and its external storage device. In this embodiment, the memory 120 is generally used to store the operating system and various application software installed on the computer device 8, such as the program code of the commodity inventory deduction method, etc. In addition, the memory 120 can also be used to temporarily store various data that have been output or will be output.
[0123] In some embodiments, the processor 121 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other commodity inventory deduction chip. The processor 121 is generally used to control the overall operation of the computer device 8, such as performing control and processing related to data interaction or communication with the computer device 8. In this embodiment, the processor 121 is used to run the program code stored in the memory 120 or process data.
[0124] The network interface 122 may include a wireless network interface or a wired network interface, and the network interface 122 is generally used to establish a communication link between the computer device 8 and other computer devices. For example, the network interface 122 is used to connect the computer device 8 to an external terminal through a network, to establish a data transmission channel and a communication link between the computer device 8 and the external terminal, etc. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0125] It should be pointed out that Figure 8 Only a computer device having components 120 - 122 is shown, but it should be understood that implementation of all of the components shown is not a requirement, and more or fewer components may be implemented instead.
[0126] In this embodiment, the commodity inventory deduction method stored in the memory 120 can be divided into one or more program modules and executed by one or more processors (processor 121 in this embodiment) to complete the present application.
[0127] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the commodity inventory deduction method in the embodiment are implemented.
[0128] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store the operating system and various application software installed on the computer device, such as the program code of the commodity inventory deduction method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.
[0129] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on at least two network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiment scheme of the present application. Those of ordinary skill in the art may understand and implement it without creative labor.
[0130] Through the description of the above implementation methods, a person of ordinary skill in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. 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 program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0131] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A commodity inventory deduction method, characterized in that: include: receiving a commodity inventory deduction request, wherein the commodity inventory deduction request includes inventory deduction quantities of a plurality of commodities to be deducted and inventory identification information of a plurality of commodities to be deducted; Determine a database storing inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted; When there are multiple determined databases, multiple threads are created, and corresponding inventory deduction operations are performed in parallel in the corresponding databases according to the inventory deduction quantities corresponding to the commodities to be deducted through the multiple threads, wherein each thread corresponds to one database; When there is a thread that fails to successfully execute the inventory deduction operation, a corresponding compensation record is generated according to all successfully executed inventory deduction operations, and the compensation record is written into the inventory compensation table, wherein the compensation record includes the inventory identification information of the commodity to be compensated and the inventory deduction quantity; Obtaining a compensation record from the inventory compensation table, and performing compensation update on the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record; After the step of executing the corresponding inventory deduction operation in the corresponding database according to the corresponding inventory deduction quantity in parallel through multiple threads, the method further includes: When all threads have successfully executed the inventory deduction operation, a message of successful inventory deduction is returned to the sender of the commodity inventory deduction request; and When there is a thread that fails to execute the inventory deduction operation successfully, returning an inventory deduction failure message to the sender of the commodity inventory deduction request; Wherein, the method further comprises: After the thread successfully executes the inventory deduction operation, inserting the inventory deduction operation into the inventory update flow table; When there is a thread that fails to successfully execute the inventory deduction operation, the inserted inventory deduction operation is deleted from the inventory update flow table.
2. The commodity inventory deduction method according to claim 1, characterized in that: The method further comprises: The database storing the inventory information of the commodities is divided into different databases according to the inventory identification information of the commodities, so that the inventory information of different commodities is stored in different databases.
3. The commodity inventory deduction method according to claim 1, characterized in that: The method of determining a database for storing inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted comprises: Sort the inventory identification information of each commodity to be deducted; A database storing inventory information of each commodity to be deducted is determined according to the sorted inventory identification information of each commodity to be deducted.
4. The commodity inventory deduction method according to claim 1, characterized in that: The step of acquiring the compensation record from the inventory compensation table and performing compensation update on the inventory information stored in the corresponding database according to the inventory identification information and the inventory deduction quantity of the commodity to be compensated in the acquired compensation record includes: The compensation records are obtained from the inventory compensation table at regular intervals, and the inventory information stored in the corresponding database is updated based on the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation records.
5. The commodity inventory deduction method according to claim 1, characterized in that: The commodity inventory deduction request is an inventory deduction request for multiple orders. After the step of receiving the commodity inventory deduction request, the step further includes: Aggregate inventory reduction requests with the same inventory identification information contained in multiple orders.
6. A commodity inventory deduction device, characterized in that: include: A receiving module, configured to receive a commodity inventory deduction request, wherein the commodity inventory deduction request includes inventory deduction quantities of multiple commodities to be deducted and inventory identification information of multiple commodities to be deducted; A determination module, used to determine a database storing inventory information of each commodity to be deducted according to the inventory identification information of each commodity to be deducted; A deduction module is used to create multiple threads when there are multiple determined databases, and execute corresponding inventory deduction operations in the corresponding databases in parallel according to the inventory deduction quantities corresponding to the commodities to be deducted through the multiple threads, wherein each thread corresponds to one database; A generating module, configured to generate corresponding compensation records according to all successfully executed inventory deduction operations when there is a thread that fails to execute the inventory deduction operation, and write the compensation records into an inventory compensation table, wherein the compensation records include inventory identification information and inventory deduction quantity of the commodity to be compensated; A compensation module, used to obtain a compensation record from the inventory compensation table, and to perform compensation update on the inventory information stored in the corresponding database according to the inventory identification information and inventory deduction quantity of the to-be-compensated commodity in the obtained compensation record; A return module, used to return a stock deduction success message to the sending end of the commodity stock deduction request when all threads successfully execute the stock deduction operation; and to return a stock deduction failure message to the sending end of the commodity stock deduction request when there is a thread that fails to execute the stock deduction operation; An insertion module, used for inserting the inventory deduction operation into the inventory update flow table after the thread successfully executes the inventory deduction operation; The deleting module is used to delete the inserted inventory deduction operation from the inventory update flow table when there is a thread that fails to execute the inventory deduction operation successfully.
7. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 5 when executing the computer program.
8. 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 5 are implemented.
Citation Information
Patent Citations
Inventory management method and apparatus
CN108268474A
Cache-based inventory management method and device
CN110347692A