CN117952508A - Inventory processing method, inventory processing device, electronic equipment, storage medium and product - Google Patents

Inventory processing method, inventory processing device, electronic equipment, storage medium and product Download PDF

Info

Publication number
CN117952508A
CN117952508A CN202211276802.6A CN202211276802A CN117952508A CN 117952508 A CN117952508 A CN 117952508A CN 202211276802 A CN202211276802 A CN 202211276802A CN 117952508 A CN117952508 A CN 117952508A
Authority
CN
China
Prior art keywords
inventory
deduction
commodity
state
operation request
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211276802.6A
Other languages
Chinese (zh)
Inventor
刘雨龙
裴振涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202211276802.6A priority Critical patent/CN117952508A/en
Publication of CN117952508A publication Critical patent/CN117952508A/en
Pending legal-status Critical Current

Links

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The application provides an inventory processing method, an inventory processing device, electronic equipment and a storage medium, wherein the inventory processing method comprises the following steps: detecting an operation type aimed by an operation request sent by a requester; if the operation type is the inventory deduction operation type, performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result; if the state detection result represents that the operation request accords with the sequence of execution among different inventory deduction operation types, setting the commodity inventory corresponding to the operation request as a deduction state, and performing deduction operation on the commodity quantity in the commodity inventory; if the operation type is the inventory updating operation type, setting the commodity inventory corresponding to the operation request as an updating state, and updating the commodity quantity in the commodity inventory; the deducted state and the updated state are mutually exclusive. According to the technical scheme provided by the embodiment of the application, the commodity inventory modification and the deduction cannot be performed simultaneously, so that the occurrence of overstock can be reduced.

Description

Inventory processing method, inventory processing device, electronic equipment, storage medium and product
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and apparatus for inventory processing, an electronic device, and a storage medium.
Background
With the development of networks, online transactions are more and more popular, some transaction platforms can push out second killing and preferential activities to attract users, and in such a scene, the concurrent quantity of operation requests sent out for commodities is large, at the moment, the commodity inventory processing rate is high, and the problem of inconsistent processing data is easy to occur, so that the condition of overstock or understock is caused. Such as overstock or understock caused by inconsistent amounts of the merchandise sold and inventory amounts of the merchandise or by incorrect order processing resulting in incorrect inventory amounts.
The conditions of overstock and understock of commodity inventory are mostly caused by errors in updating and deducting the commodity inventory, such as error in order processing sequence and failure in order processing, but related inventory is deducted in the commodity inventory, so that the inventory quantity of the commodity inventory is less than the actual quantity, and the condition of understock is caused; in addition, when the inventory in the remote database is killed in seconds, the inventory in the remote database is generally forbidden to be modified, so that the inventory in the hardware database is updated while the inventory is updated, the inventory in the remote database is unchanged, the inventory in the remote database is larger than the newly set inventory in the hardware database, the overstock condition occurs, and if the modification of the inventory in the remote database is not forbidden, the inventory is modified when the inventory is deducted, the actual inventory in the inventory cannot be confirmed, and thus the quantity is modified erroneously, and the overstock or understock condition is caused.
Disclosure of Invention
To solve the above technical problems, embodiments of the present application provide an inventory processing method and apparatus, an electronic device, a computer readable storage medium, and a computer program product.
According to an aspect of an embodiment of the present application, there is provided an inventory processing method including: detecting an operation type aimed by an operation request sent by a requester; if the operation type is an inventory deduction operation type, performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result; wherein, the relation among a plurality of preset state values represents that different inventory deduction operation types have a sequence of execution; if the state detection result represents that the operation request accords with the sequence of execution among different inventory deduction operation types, setting the commodity inventory corresponding to the operation request as a deduction state, and performing deduction operation on the number of commodities in the commodity inventory; if the operation type is an inventory updating operation type, setting the commodity inventory corresponding to the operation request as an updating state, and updating the commodity quantity in the commodity inventory; the deduction state and the update state of the commodity inventory are mutually exclusive, so that the deduction operation or the update operation can only be carried out on the commodity quantity in the commodity inventory at the same time.
According to an aspect of an embodiment of the present application, there is provided an inventory processing apparatus including: the operation type detection module is configured to detect an operation type aimed by an operation request sent by a requester; the state detection module is configured to perform state detection on the operation request according to the state node value of the operation request and a plurality of preset state values if the operation type is an inventory deduction operation type, so as to obtain a state detection result; wherein, the relation among a plurality of preset state values represents that different inventory deduction operation types have a sequence of execution; the deduction module is configured to characterize that the operation request accords with the sequence of execution among different inventory deduction operation types according to the state detection result, set the commodity inventory corresponding to the operation request as a deduction state, and perform deduction operation on the commodity quantity in the commodity inventory; the updating module is configured to set the commodity inventory corresponding to the operation request as an updating state if the operation type is an inventory updating operation type, and perform updating operation on the commodity quantity in the commodity inventory; the deduction state and the update state of the commodity inventory are mutually exclusive, so that the deduction operation or the update operation can only be carried out on the commodity quantity in the commodity inventory at the same time.
In one embodiment, the inventory processing apparatus further comprises:
An idempotent module configured to detect whether the operation request is a repeat request; wherein the repeated request is a request for representing that the repeated transmission times exceeds a preset time threshold value in a specified time period;
The first processing module is configured to execute the step of performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values if the operation request is not the repeated request, so as to obtain a state detection result;
And the second processing module is configured to determine the operation request as idempotent and intercept the operation request if the operation request is the repeated request.
In an embodiment, the inventory deduction operation type includes a preemption operation type and a deduction operation type, and the plurality of preset state values includes a stateless value and a preemption state value; the state detection module comprises:
The first matching unit is configured to obtain a state detection result representing that the operation request accords with the sequence of execution among different inventory deduction operation types if the operation type is the preemption operation type and the state node value is detected to be matched with the stateless value;
And the second matching unit is configured to obtain a state detection result representing whether the operation request accords with the sequence of execution among different inventory deduction operation types if the operation type is the deduction operation type and the state node value is detected to be matched with the preemption state value.
In one embodiment, the subtraction module includes:
The first current state acquisition unit is configured to detect the current state of the commodity inventory corresponding to the operation request;
The first deduction unit is configured to obtain a first detection result used for representing that the quantity of the commodities in the commodity inventory can be deducted if the current state is a deduction state, and to carry out deduction operation on the quantity of the commodities in the commodity inventory based on the first detection result;
And the second deduction unit is configured to obtain a second detection result for representing that the quantity of the commodities in the commodity inventory is currently updated if the current state is an updated state, set the commodity inventory corresponding to the operation request as the deduction state after the updating operation of the quantity of the commodities in the commodity inventory is waited to be completed based on the second detection result, and perform the deduction operation on the quantity of the commodities in the commodity inventory after the updating operation is completed.
In one embodiment, the second deduction unit includes:
the request commodity quantity acquisition plate is configured to acquire the request commodity quantity corresponding to the operation request;
A quantity detecting block configured to detect whether the quantity of the commodity in the commodity inventory after the update operation is completed satisfies the requested commodity quantity;
and the deduction plate is configured to deduct the commodity quantity in the commodity inventory after the updating operation is finished based on the required commodity quantity if the commodity quantity in the commodity inventory after the updating operation is finished meets the required commodity quantity.
In one embodiment, the commodity inventory includes a remote database and a relational database, wherein the remote database is stored in a cache and the relational database is stored in a hard disk; the deduction module comprises:
The cache deduction unit is configured to carry out deduction operation on the commodity quantity in the remote database and send deduction information generated after the deduction operation is completed to the message queue;
And the hard disk deduction unit is configured to return operation request success response information to the requester if the deduction information is successfully sent to the message queue, and perform deduction operation on the commodity quantity in the relational database based on the deduction information in the message queue.
In one embodiment, the update module includes:
the second current state acquisition unit is configured to detect the current state of the commodity inventory corresponding to the operation request;
The first updating unit is configured to obtain a third detection result used for representing that the quantity of the commodities in the commodity inventory can be updated if the current state is an updating state, and update the quantity of the commodities in the commodity inventory based on the third detection result;
And the second updating unit is configured to obtain a fourth detection result for representing that the quantity of the commodities in the commodity inventory is currently subjected to deduction operation if the current state is a deduction state, set the commodity inventory corresponding to the operation request as an updating state after the quantity of the commodities in the commodity inventory is subjected to deduction operation based on the fourth detection result, and perform updating operation on the quantity of the commodities in the commodity inventory after the deduction operation is completed.
In one embodiment, the commodity inventory includes a remote database stored in a cache and a relational database stored in a hard disk; the updating module comprises:
The hard disk updating unit is configured to update the commodity quantity in the relational database;
And the cache updating unit is configured to synchronize the quantity of the commodities in the remote database based on the quantity of the commodities in the commodity inventory after the updating operation is completed.
According to an aspect of an embodiment of the present application, there is provided an electronic device including one or more processors; storage means for storing one or more computer programs which, when executed by the one or more processors, cause the electronic device to implement the inventory processing method as described above.
According to an aspect of an embodiment of the present application, there is provided a computer-readable storage medium having stored thereon computer-readable instructions, which when executed by a processor of a computer, cause the computer to perform the inventory processing method as described above.
According to an aspect of embodiments of the present application, there is provided a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions so that the computer device performs the inventory processing methods provided in the various alternative embodiments described above.
According to an aspect of an embodiment of the present application, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the steps of an inventory processing method as described above.
In the technical scheme provided by the embodiment of the application, the state node value of the operation request is detected, the operation request is ensured to conform to the sequence of execution among different inventory deduction operation types, the inventory quantity error condition caused by the execution sequence error of the operation request is reduced, meanwhile, different states are set for the commodity inventory according to the operation request of different operation types, and the operations in the two different states cannot be simultaneously carried out, so that the commodity inventory can be ensured to be updated and the deduction cannot be carried out on the commodity inventory; when the commodity inventory is deducted, the commodity inventory cannot be updated, so that the condition that overstock or understock cannot occur during commodity inventory processing is ensured, the accuracy of commodity inventory processing is higher, and the method is suitable for a plurality of wide application scenes.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application. It is evident that the drawings in the following description are only some embodiments of the present application and that other drawings may be obtained from these drawings without inventive effort for a person of ordinary skill in the art. In the drawings:
FIG. 1 is a schematic illustration of an implementation environment in which the present application is directed;
FIG. 2 is a schematic diagram of a server-side architecture according to an exemplary embodiment of the present application;
FIG. 3 is a flow chart of an inventory processing method shown in an exemplary embodiment of the application;
FIG. 4 is a scene graph showing a terminal making an order interaction with a server side according to an exemplary embodiment of the present application;
FIG. 5 is a diagram illustrating a scenario in which a terminal performs payment interaction with a server side according to an exemplary embodiment of the present application;
FIG. 6 is a diagram illustrating a scenario in which a terminal performs a cancel order interaction with a server side according to an exemplary embodiment of the present application;
FIG. 7 is a diagram illustrating a scenario in which a terminal and a server side interact to update inventory according to an exemplary embodiment of the present application;
FIG. 8 is a flowchart of an inventory processing method according to an exemplary embodiment of the application;
FIG. 9 is a schematic diagram of a behavior tree shown in an exemplary embodiment of the present application;
FIG. 10 is a flow chart of an inventory processing method shown in another exemplary embodiment of the application;
FIG. 11 is a flow chart of step S850 in the embodiment of FIG. 8 in an exemplary embodiment;
FIG. 12 is a diagram of a key-value pair structure, according to an exemplary embodiment of the present application;
FIG. 13 is a flow chart illustrating a distributed lock for acquiring inventory of goods in accordance with an exemplary embodiment of the present application;
FIG. 14 is a flow chart of a distributed lock for acquiring inventory of goods, shown in another exemplary embodiment of the application;
FIG. 15 is a flow chart of step S850 in the embodiment of FIG. 8 in an exemplary embodiment;
FIG. 16 is a schematic diagram of an inventory processing apparatus according to an exemplary embodiment of the application;
fig. 17 shows a schematic diagram of a computer system suitable for use in implementing an embodiment of the application.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the application. Rather, they are merely examples of apparatus and methods consistent with aspects of the application as detailed in the accompanying claims.
The block diagrams depicted in the figures are merely functional entities and do not necessarily correspond to physically separate entities. That is, the functional entities may be implemented in software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
The flow diagrams depicted in the figures are exemplary only, and do not necessarily include all of the elements and operations/steps, nor must they be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the order of actual execution may be changed according to actual situations.
Also to be described is: in the present application, the term "plurality" means two or more. "and/or" describes an association relationship of an association object, meaning that there may be three relationships, e.g., a and/or B may represent: a exists alone, A and B exist together, and B exists alone. The character "/" generally indicates that the context-dependent object is an "or" relationship.
The Database (Database), which can be considered as an electronic filing cabinet, is a place for storing electronic files, and users can perform operations such as adding, inquiring, updating, deleting and the like on the data in the files. A "database" is a collection of data stored together in a manner that can be shared with multiple users, with as little redundancy as possible, independent of the application.
The Database management system (Database MANAGEMENT SYSTEM, DBMS) is a computer software system designed for managing databases, and generally has basic functions of storage, interception, security, backup and the like. The database management system may classify according to the database model it supports, e.g., relational, XML (Extensible Markup Language ); or by the type of computer supported, e.g., server cluster, mobile phone; or by classification according to the query language used, e.g., structured query language (Structured Query Language, SQL), XQuery; or by performance impact emphasis, such as maximum scale, maximum speed of operation; or other classification schemes. Regardless of the manner of classification used, some DBMSs are able to support multiple query languages across categories, for example, simultaneously.
It will be appreciated that in the specific embodiments of the present application, related data such as requester information, commodity information, requester operation information, etc. are referred to, and when the above embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data is required to comply with related laws and regulations and standards of related countries and regions.
Referring first to fig. 1, fig. 1 is a schematic diagram of an implementation environment according to the present application. The implementation environment includes a terminal 100 and a server side 200, and communication is performed between the terminal 100 and the server side 200 through a wired or wireless network.
It should be understood that the number of terminals 100 and server-side 200 in fig. 1 is merely illustrative. There may be any number of terminals 100 and server sides 200 as practical.
In some embodiments of the present application, the inventory processing method may be performed by the server 200, and accordingly, the user category identifying device is configured in the server 200.
In this embodiment, the terminal 100 is configured to receive an operation generation operation request of a requester, and send the operation request to the server 200, and the server 200 processes the inventory based on the operation request.
In a specific embodiment, the terminal 100 sends an operation request sent by the requester to the server 200, and the server 200 detects an operation type for which the operation request sent by the requester is directed; if the operation type is the inventory deduction operation type, carrying out state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result; wherein, the relation among a plurality of preset state values represents that different inventory deduction operation types have a sequence of execution; if the state detection result represents that the operation request accords with the sequence of execution among different inventory deduction operation types, setting the commodity inventory corresponding to the operation request as a deduction state, and performing deduction operation on the commodity quantity in the commodity inventory; if the operation type is the inventory updating operation type, setting the commodity inventory corresponding to the operation request as an updating state, and updating the commodity quantity in the commodity inventory; of course, the deduction state and the update state of the commodity inventory are mutually exclusive, so that only the deduction operation or the update operation can be performed on the commodity quantity in the commodity inventory at the same time.
After the update operation or the deduction operation is completed, the server 200 generates an inventory processing result, and sends the inventory processing result to the terminal 100, and the inventory processing result is displayed through a visualization module of the terminal 100.
Of course, the terminal 100 may be divided into a management terminal and a user terminal, where the management terminal has authority to perform an update operation on the commodity inventory, that is, only the management terminal may send an operation request of an update operation type to perform an update operation on the number of commodities in the commodity inventory; in contrast, the user terminal may send an operation request of the deduction operation type to perform the deduction operation on the number of goods in the goods inventory.
The terminal 100 includes, but is not limited to, a mobile phone, a computer, an intelligent voice interaction device, an intelligent home appliance, a vehicle-mounted terminal, an aircraft, etc., and may be, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc. The server 200 may be an independent physical server, or may be a server cluster or a distributed system formed by a plurality of physical servers, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network ), and basic cloud computing services such as big data and artificial intelligent platform.
It should be noted that this embodiment is only an exemplary implementation environment provided for the convenience of understanding the idea of the present application, and should not be construed as providing any limitation on the scope of use of the present application, and in other embodiments, the inventory processing method may be separately completed by the terminal 100.
Referring to fig. 2, fig. 2 is a functional block diagram of the server side in fig. 1 in one embodiment, where the server side includes an inventory module 201, a remote database 202, a queue 203, and a relational database 204.
The inventory module 201 performs inventory processing on the operation request, and may control the remote database 202, the queue 203, and the relational database 204, where the remote database 202 is stored in a cache, and the relational database 204 is stored in a hard disk.
In this embodiment, according to the attribute parameters of the commodity, the commodity with the same attribute (the same attribute such as size and color) is regarded as one SKU (minimum stock keeping unit), and the commodity stock of a plurality of SKUs is stored in the relational database 204.
The stored data of the remote database 202 in this embodiment is synchronized with the relational database 204, i.e., the remote database 202 also stores inventory of items for a plurality of SKUs.
The queue 203 is configured to generate a response deduction message after the inventory of a SKU in the remote database 202 is deducted, where the deduction message is sent to the queue 203, so that the relational database 204 performs a deduction operation on the number of commodities of the same SKU based on the deduction message.
In this embodiment, since the remote database 202 is stored in the cache, and the data of the remote database 202 is synchronized with the relational database 204, the efficiency of writing and writing data during inventory processing can be improved, i.e. the processing time of inventory processing can be reduced, and the inventory processing efficiency in the scenario of high burst-volume operation request processing (e.g. commodity second killing) can be ensured.
In a specific embodiment, relational database 204 may be a mysql database, remote database 202 may be a redis (remote dictionary service, supporting a key-value storage system), and queue 203 may be kafka (an instant message queue).
FIG. 3 is a flow chart illustrating inventory processing performed by the server side of FIG. 2 in one embodiment. Referring to fig. 3, in S1, a user/requester may issue an order through the terminal 100, and then generate an operation request, where the operation request is a preemptive operation request, the operation request arrives at the inventory module, the inventory module acquires an idempotent lock from redis, determines whether the operation request is a repeat request, if yes, idempotent the operation request, if not, proceeds to S2, performs a state machine check, that is, acquires a state node value of the operation request, and matches a relationship between the state node value and a preset state value.
And when the matching is successful, the verification of the state machine is proved to pass, S3 is entered, a re-entrant lock is obtained, whether the current state of the commodity inventory of the redis is in a deduction state is judged, if yes, S4 is directly entered, if not, the commodity inventory of the redis is indicated to be updated, after the operation is completed, the commodity inventory corresponding to the operation request is set to be in the deduction state, S4 is entered, in S4, whether the commodity inventory in the redis meets the number required by the operation request or not can be judged, if yes, the corresponding number of commodities are preempted from the redis, and the ordering success information is returned to the terminal 100.
Then, entering S5, the requestor may pay the commodity successfully ordered through the terminal, the operation request reaching the inventory module is of deduction operation type, steps S1 to S4 are the same, idempotent, state machine check and reentrant lock acquisition are performed on the operation request, when the reentrant lock acquisition is successful, S8 is reached, deduction is performed through lua (a script) in redis, at this time, the deduction is performed on the commodity pre-occupied in S4, after the deduction is successful, deduction information is sent to kafka, if the deduction information is sent successfully, the purchase completion is proved, purchase success information is returned to the terminal 100, meanwhile, kafka pulls deduction information from the inventory module, and mysql performs deduction synchronized with redis based on the deduction information of kafka.
In the inventory processing process of fig. 3, there are two scenarios of interaction between the terminal 100 and the server 200, one is to issue an operation request to the server 200 through the terminal 100, as shown in fig. 4, and one is to issue an operation request to the server 200 through terminal payment, as shown in fig. 5.
Of course, in other embodiments, there is also an interaction manner between the other terminal 100 and the server 200, for example, after the terminal 100 issues a list successfully, cancel the order, and send an operation request to the server 200, as shown in fig. 6, when the terminal 100 issues a list successfully, that is, the list is already preempted, and after the operation request to cancel the order is sent to the server 200, the preempted list is released, that is, the preempted list is released to redis; as shown in fig. 7, when an operation request for updating inventory is sent by the management terminal in the terminal 100, SKUs corresponding to the operation request cannot be ordered; conversely, when the SKU is in the order or payment, then no inventory update can be performed.
Fig. 8 is a flowchart illustrating an inventory processing method applicable to the implementation environment of fig. 1, and executed by the server 200 of fig. 1, and specifically implemented by an inventory module in the server 200, it should be understood that the method may be applied to other exemplary implementation environments and executed by devices in other implementation environments, and the implementation environment to which the method is applicable is not limited by the present embodiment.
In an exemplary embodiment, the method may include steps S810 to S870, which are described in detail as follows:
Step S810: the type of operation for which the request for operation was sent by the requestor is detected.
In this embodiment, after receiving the operation request, an operation type of the operation request is detected, where the operation type indicates what operation is performed by the operation request on the number of commodities in the commodity inventory.
Specifically, the operation types may include an inventory update operation type and an inventory deduction operation type, where the inventory deduction operation type is to perform a deduction operation on the number of commodities in the commodity inventory, and the inventory update operation type is to perform an update operation on the number of commodities in the commodity inventory.
In an embodiment, the inventory deduction operation types further include a preemption operation type and a deduction operation type, the operation request corresponding to the preemption operation type is to perform preemption processing on the commodities in the commodity inventory, and the operation request corresponding to the deduction operation type is to perform deduction processing on the commodities in the commodity inventory, and since the preemption processing also temporarily reduces the number of the commodities in the commodity inventory, preemption can be regarded as deducting the commodities in the commodity inventory.
Of course, in this embodiment, the operation requests are all processing for the commodity inventory corresponding to one SKU, and when the user sends the operation requests for multiple SKUs through the terminal, the server side still respectively performs processing for the commodity inventory corresponding to the SKUs for the operation requests of different SKUs.
The operation request is generated by the terminal receiving the operation of the requesting party on the terminal page, and in the second killing or other operation request high sending scenes, a load equalizer is loaded between the terminal and the server end, so that a plurality of operation requests are uniformly distributed to each server end through the load equalizer, and each server end performs inventory processing on the distributed operation requests.
Step S830: if the operation type is the stock deduction operation type, performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result.
In this embodiment, after determining that the operation type is the inventory deduction operation type, the idempotent determination may be performed on the operation request, to determine whether the operation request is a repeat request, so as to reduce occurrence of a bill; if the operation request is not the repeated request, the state detection of the operation request is also needed to prevent the commodity inventory processing error.
Specifically, for the operation request of the deduction operation type, it is generally experienced that the preemption (locking a part of the goods in the goods inventory) is to be reduced (after payment, the locked part of the goods is reduced, i.e. the goods inventory is reduced) or the preemption is to be released (canceling payment, releasing the locked inventory, the locked inventory entering the goods inventory, i.e. increasing the goods inventory), i.e. the preemption is in the state of being executed first, i.e. if the upstream service writes a very bad code, the calling sequence is wrong, the release state is directly called, which results in the goods inventory being newly increased, but the goods inventory does not have so many goods in essence, thereby resulting in the occurrence of the overstock condition.
Therefore, in this embodiment, the execution order of the inventory deduction operation types is different, and when the inventory deduction operation types include the preemption operation type and the deduction operation type, the preemption operation type needs to be executed before the deduction operation type, that is, the preemption state needs to be ensured to be before the deduction or release state, and this is achieved by the preset state value.
Specifically, through the preset state values, the number of the preset state values is multiple, different preset state values correspond to the type of the operation request, and the relation among the preset state values characterizes that the sequence of execution exists among different inventory deduction operation types.
Then, by receiving a status node value of an operation request, the status node value being one of a plurality of preset status values, and by matching the status node value with the preset status value of the operation request under the corresponding type, determining whether the status order of the operation request is the same.
In one embodiment, the preset STATE values include a no STATE value (NON_STATE), a pre-emptive STATE value (LOCK_STATE), a released STATE value (UN_LOCK_STATE) and a deducted STATE value (DEDUCT _STATE), and the behavior tree of the four preset STATE values is shown in FIG. 9.
Referring to fig. 9, in a purchase process, a stateless value is always at the forefront, when a requester starts to place a bill, an operation request is sent to a server, the operation request at this time is a preemption operation type, and if preemption is successful at this time, the stateless value is changed into a preemption state value; after the settlement is successful, if the requester pays, the operation request is sent to the server again, the operation request at the moment is of a deduction operation type, and if the deduction is successful at the moment, the preemption state value is changed into a deduction state value; of course, if the order is cancelled after the order is successfully placed, the operation request is also sent to the server, and the operation request at this time can be regarded as a cancellation operation type, and when the cancellation is successful, the operation request is changed from the preemption state value to the release state value.
It can be seen that, when the operation types are different, the state node value obtained for the current operation type is different, and the state node value is obtained between the related operations performed based on the operation type, so the state node value should be the state value between the state values corresponding to the operation type and the state value not changed yet.
Specifically, if the operation type is the preemption operation type, when the state node value is acquired, the obtained state node value is a stateless value; if the operation type is the deduction operation type, detecting that the status node value should be a preemption status value, if the obtained status node value is not a stateless value when the operation type is the preemption operation type, or if the obtained status node value is not a preemption status value when the operation type is the deduction operation type, indicating that the operation sequence of the commodity inventory is wrong when the requester purchases,
Therefore, in this embodiment, after the status node value is obtained, the status detection is performed on the operation request according to the status node value of the operation request and a plurality of preset status values, so as to obtain a status detection result; if the operation type is the preemption operation type, and the state node value is detected to be matched with the stateless value, a state detection result which characterizes that the operation request accords with the sequence of execution among different inventory deduction operation types is obtained; if the operation type is the deduction operation type, and the state node value is detected to be matched with the preemption state value, a state detection result which indicates whether the operation request accords with the sequence of execution among different inventory deduction operation types is obtained.
When the operation type is the preemption operation type or when the operation type is the deduction operation type, the state detection result indicates that the operation request accords with the sequence of execution among different inventory deduction operation types, the ordering failure/payment failure information is directly sent to the terminal of the requesting party, meanwhile, if the inventory is processed corresponding to the operation request, the processing is restored or cancelled, and if the inventory is preempted, the preempted inventory is released to the commodity inventory.
As can be seen from the above, the preemption operation type and the deduction operation type are both substantially subtracting operations for the amount in the commodity inventory, and therefore, the commodity inventory corresponding to the operation request is set to be in the deduction state regardless of whether the operation request is the preemption operation type or the deduction operation type.
In an embodiment, idempotent and state detection may be implemented through string (data type in redis), where key is skuid (SKU identifier) of SKU corresponding to the operation request, value is the obtained state node value, and of course, other middleware such as zk (ZooKeeper, a distributed application coordination service of distributed and open source code) may also be implemented, but specific implementation logic is not changed, and specific limitation is not herein imposed.
Of course, in some special scenarios, when there may be a bill making process, no preemption operation is performed, and when payment is made, a deduction is directly performed (when a bill is made in such a scenario, it indicates that the requester has a purchasing qualification, that is, the number of commodities required by the requester corresponds to the commodity inventory and the direct deduction is not insufficient), at this time, when the operation type is the deduction operation type, it is detected that the state node value needs to be in a stateless state, and then the state node value of the operation request can be considered to be matched with the preset state value.
Step S850: if the state detection result indicates that the operation request accords with the sequence of execution among different inventory deduction operation types, setting the commodity inventory corresponding to the operation request as a deduction state, and performing deduction operation on the commodity quantity in the commodity inventory.
In this embodiment, when the operation type is an inventory deduction operation type, and the state detection result indicates that the operation request accords with the sequence of execution among different inventory deduction operation types, it is proved that the deduction operation needs to be performed on the number of commodities in the commodity inventory, at this time, the commodity inventory corresponding to the operation request is set to be in a deduction state, and only when the commodity inventory is in the deduction state, the deduction can be performed on the commodity inventory.
In this embodiment, the state of the commodity inventory may be a deduction state and an update state, and in the deduction state, the deduction operation may be performed on the number of commodities in the commodity inventory, but the update operation may not be performed on the number of commodities in the commodity inventory; similarly, in the updated state, the number of the commodities in the commodity inventory may be updated, but the number of the commodities in the commodity inventory may not be subtracted.
Specifically, the deduction state and the update state of the commodity inventory are mutually exclusive, so that only the quantity of commodities in the commodity inventory can be deducted or updated at the same time.
Of course, the state of the commodity inventory is for the commodity inventory of a single SKU, the commodity inventory state of one SKU is a deduction state, and the states of the commodity inventories of other SKUs are not affected, for example, the commodity inventory state of SKU1 is a deduction state, at this time, the number of commodities in the commodity inventory of SKU1 cannot be updated, and the commodity inventory state of SKU2 is an updating state, at this time, the number of commodities in the commodity inventory of SKU2 can be updated.
In other embodiments, if the operation type is an inventory deduction operation type, and the current state of the commodity inventory corresponding to the operation request is an update state, the commodity inventory corresponding to the operation request cannot be directly set to be the deduction state, and after the update operation in the corresponding commodity inventory is completed, the commodity inventory corresponding to the operation request is set to be the deduction state, and the quantity of commodities in the commodity inventory is deducted.
When the current state of the commodity inventory corresponding to the operation request is the deduction state, the deduction operation can be directly carried out on the commodity quantity in the commodity inventory.
Step S870: if the operation type is the inventory updating operation type, setting the commodity inventory corresponding to the operation request as an updating state, and updating the commodity quantity in the commodity inventory.
Similarly to step S850, when the operation type is the inventory update operation type, it indicates that the update operation needs to be performed on the number of the commodities in the commodity inventory, and the update operation needs to be performed in the state that the commodity inventory corresponding to the operation request is updated, then the commodity inventory corresponding to the operation request needs to be set to be in the updated state.
Similarly, if the current state of the commodity inventory corresponding to the operation request is a deduction state, the commodity inventory corresponding to the operation request can be set to be an update state only after the deduction operation in the corresponding commodity inventory is completed, and the number of commodities in the commodity inventory is updated; when the current state of the commodity inventory corresponding to the operation request is the updated state, the number of the commodities in the commodity inventory can be directly updated.
In this embodiment, different states are set for different commodity inventories by detecting operation types of operation requests, and by setting a deduction state and an update state mutually exclusive, only the quantity of commodities in the commodity inventory can be subjected to deduction operation or update operation at the same time, the commodity inventory can be updated in a view of execution ground seconds, and the commodity inventory is ensured not to be continuously deducted during update, so that the quantity of commodities in the final commodity inventory is different from the actual quantity, and the overstock or overstock condition is caused; meanwhile, for the operation request of the inventory deduction operation type, the processing sequence corresponding to the operation request is ensured to be consistent with the processing sequence in actual purchase through the matching of the state node values of the operation request, so that the problems of more commodity inventory, overstock and the like caused by the calling error of the state value are reduced.
Fig. 10 is a flowchart illustrating a method of inventory processing according to another exemplary embodiment. As shown in fig. 10, in an exemplary embodiment, the method is performed before step S830 in fig. 8, and the method may include steps S1010 to S1050, which are described in detail below:
Step S1010: it is detected whether the operation request is a repeat request.
In this embodiment, after the operation request is obtained, if the operation request is of the deduction operation type, the operation request needs to be preprocessed, and it is determined that the operation request is a normal request.
First, it is required to detect whether the operation request is a repeat request, where the repeat request is a request indicating that the number of times of repeat transmission exceeds a preset number of times threshold in a specified period of time, and the step of determining whether the operation request is a repeat request is similar to S1 and S5 in fig. 3, that is, determining whether the operation request is idempotent, where the specified period of time and the preset number of times threshold can be determined by empirical parameters, for example, if the number of times of repeat transmission exceeds 5 times in 10 minutes, the operation request is regarded as a repeat request.
The number of times of sending the operation request can be obtained by counting the ID of the requester sending the operation request, and the number of times of occurrence of the identification corresponding to the operation request (when the operation request is ordered or purchased, a string of character strings is used as an order or payment number) can be directly calculated.
When the operation request is a repeat request, indicating that the operation request may be a request triggered by a refresh, the operation request may be denied service.
Step S1030: and if the operation request is not a repeated request, executing the step of detecting the state of the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result.
In this embodiment, when the operation request is not a repeat request, the operation request may be considered as a normal request, and the steps of status detection, inventory processing, and the like for the operation request may be performed.
Step S1050: if the operation request is a repeat request, the operation request is determined to be idempotent, and the operation request is intercepted.
When the operation request is a repeated request, the operation request may be an abnormal request such as a cattle bill, etc., and the idempotent of the operation request is set, for example, the operation request failure information is directly returned to the terminal based on the operation request, or the identification of the requester corresponding to the operation request is marked, and the requester can be prevented from sending the operation request in a period of time or permanently.
In this embodiment, by determining whether the operation request is a repeat request, the occurrence of a refresh condition is reduced.
Fig. 11 is a flowchart of step S850 in the embodiment shown in fig. 8 in an exemplary embodiment. As shown in fig. 11, in an exemplary embodiment, the step S850 sets the commodity inventory corresponding to the operation request to be in the deduction state, and the process of performing the deduction operation on the number of commodities in the commodity inventory may include steps S1110 to S1150, which are described in detail below:
Step S1110: and detecting the current state of the commodity inventory corresponding to the operation request.
In this embodiment, when the operation type is the inventory deduction operation type, it is indicated that the operation request is a request for ordering or a payment request, and the operation of the inventory corresponding to the operation request is a deduction operation, and the deduction operation is performed only when the inventory is in the deduction state, so that the inventory corresponding to the operation request needs to be set in the deduction state.
Step S1130: if the current state is the deduction state, a first detection result used for representing that the deduction operation can be performed on the quantity of the commodities in the commodity inventory is obtained, and the deduction operation is performed on the quantity of the commodities in the commodity inventory based on the first detection result.
If the current state is a deduction state, the fact that the commodity inventory at the moment can be deducted is proved, namely a first detection result used for representing that the quantity of the commodities in the commodity inventory can be deducted is obtained, and the quantity of the commodities in the commodity inventory is deducted according to the first detection result.
In one embodiment, the first detection result may be regarded as that the operation request is successful in obtaining the distributed lock, and the deduction operation may be performed on the merchandise store.
Step S1150: if the current state is the update state, a second detection result used for representing that the quantity of the commodity in the commodity inventory is currently updated is obtained, after the updating operation of the quantity of the commodity in the commodity inventory is waited to be completed based on the second detection result, the commodity inventory corresponding to the operation request is set to be in a deduction state, and the quantity of the commodity in the commodity inventory after the updating operation is completed is deducted.
If the current state is the update state, the current state indicates that the number of the commodities in the commodity inventory is currently updated, and in order to prevent the occurrence of overstock and other conditions, the deduction operation cannot be performed on the commodity inventory.
The second detection result may be regarded as failure of the operation request to acquire the distributed lock, and corresponds to success of acquiring the distributed lock for another operation request of the inventory update operation type.
At this time, setting a thread spin corresponding to the operation request, waiting for the update operation to be completed, releasing the distributed lock for the other operation request of the inventory update operation type, and obtaining the distributed lock by the deduction operation, namely setting the commodity inventory corresponding to the operation request to be in a deduction state, and then performing deduction operation on the commodity quantity in the commodity inventory after the update operation is completed.
It should be noted that, in the state of setting the inventory of the commodity set in this embodiment, the states of the inventory of the commodity of the SKUs corresponding to the operation request are not affected.
And setting the commodity inventory corresponding to the operation request as an update state for the operation request of the inventory update operation type, and performing update operation on the commodity quantity in the commodity inventory in the same manner as the operation request of subtracting the new operation type for the inventory deduction.
Specifically, if the operation request is of an inventory updating operation type, detecting the current state of the commodity inventory corresponding to the operation request; if the current state is the update state, a third detection result used for representing that the quantity of the commodities in the commodity inventory can be updated is obtained, and the quantity of the commodities in the commodity inventory is updated based on the third detection result; if the current state is the deduction state, a fourth detection result used for representing that the quantity of the commodities in the commodity inventory is currently subjected to deduction operation is obtained, after the quantity of the commodities in the commodity inventory is subjected to deduction operation based on the fourth detection result, the commodity inventory corresponding to the operation request is set to be in an updated state, and the quantity of the commodities in the commodity inventory after the deduction operation is completed is updated.
The third detection result indicates that the distributed lock is successfully obtained for the operation request of the inventory updating operation type, and other operation requests of the inventory deduction operation type cannot be deducted; the fourth detection result shows that the acquisition of the distributed lock fails for the operation request of the inventory updating operation type, and other failure of owning the distributed lock for the operation request of the inventory deduction operation type exists.
In this embodiment, the operation request obtains the distributed lock to determine the relevant operations that can be performed on the current commodity inventory, so long as there is one operation request of the inventory deduction operation type having the distributed lock, all operation requests of other inventory deduction operation types can perform deduction operations, and operation requests of the inventory update operation type cannot perform update operations; similarly, as long as there is one inventory update operation type of operation request with a distributed lock, other inventory update operation types of operation requests can be updated, while inventory deduction operation type of operation requests cannot be deducted.
That is, for the commodity inventory of a SKU, the distributed lock can only exist in the operation request of one operation type at the same time, and if the operation request of the inventory deduction operation type acquires the distributed lock, the operation request of the inventory update operation type cannot acquire the distributed lock.
In this embodiment, the manner of obtaining the distributed lock may be implemented through a hash (hash, a mapping table of keys and values of String types in redis), unlike the control of a conventional distributed lock, which is specific to an interface (deduction interface and update structure), and only can be implemented: when the operation request deducts the inventory, the updating of the inventory is not operable, and as long as one operation request is deducting the inventory, the new operation request cannot deduct the inventory at the same time; and because the granularity of the lock is an interface, when the operation request of one SKU1 is deducting the inventory of goods, the operation request of another SKU2 cannot update the inventory of goods.
Based on this, a new hash table is proposed in this embodiment to implement the function of the distributed lock, where a hash table is set for one SKU, and two key-value pairs are set in one hash table. Referring to fig. 12, in an embodiment, a key-value pair structure in a hash table is shown, where the key is skuid corresponding to SKU, the value includes a reentrant keyword and a counter, the reentrant keywords in the two hash tables are different, the reentrant keyword corresponding to the operation request of the stock deduction operation type is stockdeduct, and the reentrant keyword corresponding to the operation request of the stock deduction operation type is stockupdate; the counter is used to indicate whether the two operation requests acquire a distributed lock.
The hash table value proposed in this embodiment takes effect for the same SKU, that is, different SKUs can deduct the inventory of the commodity and update the inventory of the commodity at the same time, as long as the SKU deducted from the inventory of the commodity is inconsistent with the SKU updated from the inventory of the commodity, the deduction operation and the update operation can be performed at the same time, and in addition, different operation requests deduct the inventory of the commodity of the same SKU, the two operation methods cannot affect each other, and the distributed lock takes effect only for different operation methods of the same SKU, and the same operation method does not take effect.
In a specific embodiment, when none of the inventory of a certain SKU1 is operated, the counter pair of two table key-value pairs in the SKU is 0, which indicates that no operation request is taken to the distributed lock at this time, then, an inventory deduction operation type operation request is sent to the server, which requests the distributed lock to be redis, the counter behind stockdeduct in the hash table corresponding to the operation request is added with 1, which indicates that the inventory deduction operation type operation request obtains the distributed lock, and the deduction operation can be performed on the inventory of the SKU, if the inventory deduction operation type operation request is still entered at this time, since the counter value behind stockdeduct is not 0, the inventory deduction operation type operation request cannot obtain the distributed lock, and then, the inventory update operation type operation request is set to spin until the distributed lock is obtained.
When the deduction operation is performed on the operation request of the deduction operation type, the distributed lock is released, namely, counter behind stockdeduct is subtracted by 1, at this time, the distributed lock can be applied to the operation request of the stock deduction operation type, then the counter behind stockupdate in the hash table corresponding to the operation request is added by 1, the commodity stock can be updated, and the operation request spin of the stock deduction operation type is set until the distributed lock is acquired.
Of course, for an operation request of the same operation type, as long as there is one operation request of that type that first acquired the distributed lock, then other operation requests of the same type are all considered to acquire the distributed lock.
The flow diagrams of the merchandise inventory acquisition distributed lock are shown in fig. 13 and 14, wherein thread is the thread of the operation request, thread1, thread2 and thread3 are all operation requests of the inventory deduction operation type for SKU1, and thread4 is the operation request of the inventory update operation type for SKU 1.
In fig. 13, when steps S10thread1, thread2 and thread3 enter the server, if no distributed lock is distributed in the hash table in SKU1 at this time, the locking process of step S11 is performed, and the counter 1 of stockdeduct, thread1, thread2 and thread3 can be subtracted from the inventory of SKU1, i.e. step S12; when the deduction processing of thread1, thread2 and thread3 is completed, step S13 is executed to release the lock stockdeduct and the counter is decremented by 1.
In fig. 14, if during the processing of thread1, thread2 and thread3, as shown in step S20, when thread4 also enters the server, it needs to acquire a lock, step S22 is executed first, if the counter of stockdeduct is 0, if not 0, it is proved that the distributed lock is in the operation request of the inventory deduction operation type, if 0, it is proved that the distributed lock can be acquired from the hash table, then the locking operation of step S23 may be executed, the counter of stockupdate is incremented by 1, and when the inventory setting operation of step S24 is completed, i.e. after the updating operation is completed, step S25 is executed, the counter of stockupdate is released, and minus 1 is executed.
Of course, the above procedure is the deduction operation and the update operation of the commodity inventory for SKU1, and the update operation and the deduction operation of other SKUs are not affected by the hash table of SKU 1.
In this embodiment, only one type of operation can be guaranteed for the commodity inventory through the current state of the commodity inventory, and when the commodity inventory is in a deduction state, only the commodity inventory can be deducted; when the commodity inventory is in an updated state, only the commodity inventory can be updated, so that the number of commodities in the commodity inventory is ensured not to be wrong; meanwhile, through the key-value pair provided in the embodiment, as long as the commodity inventory is in a deduction state, the commodity inventory can be deducted according to all deduction operation types of the commodity inventory, and the commodity inventory processing speed is improved.
Fig. 15 is a flowchart of step S850 in the embodiment shown in fig. 8 in an exemplary embodiment. As shown in fig. 15, in an exemplary embodiment, the commodity inventory includes a remote database and a relational database, wherein the remote database is stored in a cache, the relational database is stored in a hard disk, and the process of subtracting the number of commodities in the commodity inventory in step S850 may include steps S1510 to S1530, which are described in detail below:
step S1510: and performing deduction operation on the commodity quantity in the remote database, and sending the deduction information generated after the deduction operation is completed to a message queue.
In this embodiment, by the time the operation request is of the deduction operation type, that is, the operation request is generated in response to the payment action of the requester, the deduction operation is performed on the commodity quantity in the remote database.
In an embodiment, before the operation request processing of the deduction operation type, a ordering operation is generally performed, that is, the operation request processing of the preemption operation type is processed, when the operation request processing of the preemption operation type is processed, deduction is performed in the remote database, but the deduction is not really performed at the moment, and is a preemption process, so that the preempted amount of commodities is ensured not to be deducted or preempted by other operation requests, and therefore, the preemption in the remote database is not synchronized to the relational database at the moment; only after receiving the operation request of deduction operation type, the inventory of the pre-occupied commodity in the remote database is truly deducted, and then the deduction of the relational database is synchronized.
Of course, when the operation request of the preempting operation type does not preempt, the operation request of the deducting operation type is received later, commodity inventory in the remote database is directly deducted, and the commodity inventory is synchronized to the relational database.
Specifically, before the operation request of the deduction operation type is processed, the number of commodities in the corresponding commodity inventory is updated, if the number of commodities is increased or decreased, the number of required commodities corresponding to the operation request is required to be acquired first; and then detecting whether the quantity of the commodities in the commodity inventory after the updating operation is finished meets the required commodity quantity, if so, carrying out deduction operation on the quantity of the commodities in the commodity inventory after the updating operation is finished based on the required commodity quantity, and if not, returning purchase failure information to the terminal.
Of course, the above case is a case where, when the operation request of the preemption operation type is processed, preemption is not performed in the commodity inventory, for example, when the operation request of the preemption operation type is processed, preemption is performed in the commodity inventory, and at this time, before the operation request of the deduction operation type is not processed, the commodity inventory is updated, and the number of commodities in the updated commodity inventory cannot be smaller than the number of the preempted commodities.
Step S1530: if the deduction information is successfully sent to the message queue, operation request success response information is returned to the requesting party, and deduction operation is carried out on the commodity quantity in the relational database based on the deduction information in the message queue.
In this embodiment, the deduction information generated after the deduction operation is completed is sent to the message queue, and only if the deduction information is sent successfully, the purchase success can be indicated, and the deduction information in the message queue is controlled while the operation request success response information is returned to the requesting party, so that the deduction operation is performed on the commodity quantity in the relational database.
In this embodiment, the remote database stored in the cache is used to perform quick inventory processing of the commodity, so as to improve the efficiency of processing the operation request, and meanwhile, after the inventory of the commodity in the remote database is changed, the read-write efficiency of the relational database is considered, the inventory of the commodity in the relational database is not modified in real time, but the generated deduction information reaches the queue, so that the relational database can change the corresponding inventory of the commodity in the relational database based on the information in the queue, and the synchronization of the data in the remote database and the relational database is ensured.
It should be noted that, in this embodiment, the remote database and the relational database have the same data, and different from the remote database which is generally used with higher read-write speed, only commodity values exist in the remote database, and the quick commodity inventory change is realized by directly subtracting the values, only the remote database with the values exists, so that the overstock condition is easy to occur, if the overstock condition is not really deducted after the overstock condition, so that the commodity values cannot be changed, if the payment is cancelled, the preempted value is released, the preempted value is added to the commodity values, and the condition that the commodity values in the commodity inventory exceed the actual values at this time occurs.
In this embodiment, the remote database and the relational database have the same data, and when the remote database is subjected to operations such as deduction and the like, the operations are directly performed on the original inventory data, so that the safety of numerical processing is improved, and the overstock condition of numerical processing is reduced.
In an embodiment, if the operation request is an update operation type, and when the commodity inventory corresponding to the operation request is in an update state, the update is performed on the commodity quantity in the relational database, that is, the commodity quantity in the relational database is updated, and then the commodity quantity in the remote database is synchronized based on the commodity quantity in the commodity inventory after the update operation is completed, so that the commodity quantity in the relational database is consistent with the commodity quantity in the relational database.
For the inventory processing method proposed in fig. 1 to 15, in this embodiment, inventory processing under the high-speed scenario of operation request is performed by 20 4C8G physical machines, 1 redis cluster of 2C4G mysql,8G dual nodes, so as to obtain the experimental results shown in table 1:
operation request handling for inventory update operation types Operation request handling for inventory deduction operation type
0Tps (throughput) 15000tps
10tps 13000tps
TABLE 1
As can be seen from table 1, the inventory processing method provided in the present embodiment ensures that the inventory system satisfies daily common selling and burst flow second killing selling simultaneously; the problem that commodity inventory cannot be updated under the scene of execution ground seconds is solved (traditional second killing, during second killing activity, inventory setting needs to be disabled, otherwise overstock situations can occur), and even under extreme conditions, overstock situations of commodity inventory can not occur; meanwhile, unreasonable calling of the upstream business to commodity inventory operation is effectively avoided, and the conditions of repeated calling and incorrect calling are avoided.
Fig. 16 is a schematic diagram showing a structure of an inventory processing apparatus according to an exemplary embodiment. As shown in fig. 16, in an exemplary embodiment, the inventory processing apparatus includes:
An operation type detection module 1610 configured to detect an operation type for which an operation request sent by a requester is directed;
The state detection module 1630 is configured to perform state detection on the operation request according to the state node value of the operation request and a plurality of preset state values if the operation type is the inventory deduction operation type, so as to obtain a state detection result; wherein, the relation among a plurality of preset state values represents that different inventory deduction operation types have a sequence of execution;
The deduction module 1650 is configured to make the state detection result show that the operation request accords with the sequence of execution among different inventory deduction operation types, set the commodity inventory corresponding to the operation request as a deduction state, and perform deduction operation on the number of commodities in the commodity inventory;
An updating module 1670 configured to set the commodity inventory corresponding to the operation request to be in an updating state if the operation type is an inventory updating operation type, and to update the number of commodities in the commodity inventory; the deduction state and the update state of the commodity inventory are mutually exclusive, so that the deduction operation or the update operation can only be carried out on the commodity quantity in the commodity inventory at the same time.
In one embodiment, the inventory processing apparatus further comprises:
An idempotent module configured to detect whether an operation request is a repeat request; wherein the repeated request is a request for representing that the repeated transmission times exceeds a preset time threshold value in a specified time period;
The first processing module is configured to execute the step of performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result if the operation request is not a repeated request;
and the second processing module is configured to determine the operation request as idempotent and intercept the operation request if the operation request is a repeated request.
In an embodiment, the inventory deduction operation type includes a preemption operation type and a deduction operation type, and the plurality of preset status values includes a stateless value and a preemption status value; the state detection module comprises:
The first matching unit is configured to obtain a state detection result representing that the operation request accords with the sequence of execution among different inventory deduction operation types if the operation type is a preemptive operation type and the state node value is detected to be matched with a stateless value;
The second matching unit is configured to obtain a state detection result representing whether the operation request accords with the sequence of execution among different inventory deduction operation types if the operation type is the deduction operation type and the state node value is detected to be matched with the preemption state value. In one embodiment, the subtraction module includes:
The first current state acquisition unit is configured to detect the current state of the commodity inventory corresponding to the operation request;
The first deduction unit is configured to obtain a first detection result used for representing that the quantity of the commodities in the commodity inventory can be deducted if the current state is a deduction state, and to carry out deduction operation on the quantity of the commodities in the commodity inventory based on the first detection result;
The second deduction unit is configured to obtain a second detection result for representing that the number of the commodities in the commodity inventory is currently updated if the current state is the updated state, set the commodity inventory corresponding to the operation request to be the deduction state after the updating operation of the number of the commodities in the commodity inventory is waited for being completed based on the second detection result, and perform the deduction operation on the number of the commodities in the commodity inventory after the updating operation is completed.
In one embodiment, the second deduction unit includes:
the request commodity quantity acquisition plate is configured to acquire the request commodity quantity corresponding to the operation request;
A quantity detecting block configured to detect whether the quantity of the commodity in the commodity inventory after the completion of the updating operation satisfies the requested commodity quantity;
The deduction plate is configured to deduct the commodity number in the commodity inventory after the updating operation is completed based on the required commodity number if the commodity number in the commodity inventory after the updating operation is completed meets the required commodity number.
In one embodiment, the inventory of goods comprises a remote database and a relational database, wherein the remote database is stored in a cache and the relational database is stored in a hard disk; the deduction module comprises:
The cache deduction unit is configured to carry out deduction operation on the commodity quantity in the remote database and send deduction information generated after the deduction operation is completed to the message queue;
The hard disk deduction unit is configured to return operation request success response information to the requesting party if the deduction information is successfully sent to the message queue, and perform deduction operation on the commodity quantity in the relational database based on the deduction information in the message queue.
In one embodiment, the update module includes:
the second current state acquisition unit is configured to detect the current state of the commodity inventory corresponding to the operation request;
the first updating unit is configured to obtain a third detection result used for representing that the quantity of the commodities in the commodity inventory can be updated if the current state is the updating state, and update the quantity of the commodities in the commodity inventory based on the third detection result;
The second updating unit is configured to obtain a fourth detection result for representing that the quantity of the commodities in the commodity inventory is currently subjected to the deduction operation if the current state is the deduction state, set the commodity inventory corresponding to the operation request to be the updating state after the quantity of the commodities in the commodity inventory is subjected to the deduction operation based on the fourth detection result, and perform the updating operation on the quantity of the commodities in the commodity inventory after the deduction operation is completed.
In one embodiment, the inventory of goods includes a remote database and a relational database, the remote database being stored in a cache and the relational database being stored in a hard disk; the updating module comprises:
The hard disk updating unit is configured to update the commodity quantity in the relational database;
And the cache updating unit is configured to synchronize the quantity of the commodities in the remote database based on the quantity of the commodities in the commodity inventory after the updating operation is completed.
It should be noted that, the inventory processing apparatus provided in the foregoing embodiment and the inventory processing method provided in the foregoing embodiment belong to the same concept, and the specific manner in which each module and unit perform the operation has been described in detail in the method embodiment, which is not described herein.
The embodiment of the application also provides electronic equipment, which comprises: one or more processors; and a storage means for storing one or more programs which, when executed by the one or more processors, cause the electronic device to implement the inventory processing methods provided in the respective embodiments described above.
Fig. 17 shows a schematic diagram of a computer system suitable for use in implementing an embodiment of the application.
It should be noted that, the computer system 1700 of the electronic device shown in fig. 17 is only an example, and should not impose any limitation on the functions and the application scope of the embodiments of the present application.
As shown in fig. 17, the computer system 1700 includes a central processing unit (Central Processing Unit, CPU) 1701, which can perform various appropriate actions and processes, such as performing the methods in the above-described embodiments, according to a program stored in a Read-Only Memory (ROM) 1702 or a program loaded from a storage portion 1708 into a random access Memory (Random Access Memory, RAM) 1703. In the RAM 1703, various programs and data required for system operation are also stored. The CPU 1701, ROM 1702, and RAM 1703 are connected to each other through a bus 1704. An Input/Output (I/O) interface 1705 is also connected to the bus 1704.
The following components are connected to the I/O interface 1705: an input section 1706 including a keyboard, a mouse, and the like; an output portion 1707 including a Cathode Ray Tube (CRT), a Liquid crystal display (Liquid CRYSTAL DISPLAY, LCD), and a speaker, etc.; a storage portion 1708 including a hard disk or the like; and a communication section 1709 including a network interface card such as a LAN (Local Area Network ) card, a modem, or the like. The communication section 1709 performs communication processing via a network such as the internet. The driver 1710 is also connected to the I/O interface 1705 as needed. A removable medium 1711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on the drive 1710, so that a computer program read therefrom is installed into the storage portion 1708 as needed.
In particular, according to embodiments of the present application, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising a computer program for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion 1709, and/or installed from the removable media 1711. When executed by a Central Processing Unit (CPU) 1701, performs various functions defined in the system of the present application.
It should be noted that, the computer readable medium shown in the embodiments of the present application may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium may be, for example, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-Only Memory (ROM), an erasable programmable read-Only Memory (Erasable Programmable Read Only Memory, EPROM), a flash Memory, an optical fiber, a portable compact disc read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present application, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with a computer-readable computer program embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. A computer program embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. Where each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present application may be implemented by software, or may be implemented by hardware, and the described units may also be provided in a processor. Wherein the names of the units do not constitute a limitation of the units themselves in some cases.
Another aspect of the application also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements a stock handling method as before. The computer-readable storage medium may be included in the electronic device described in the above embodiment or may exist alone without being incorporated in the electronic device.
Another aspect of the application also provides a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions so that the computer device performs the inventory processing method provided in the above-described respective embodiments.
The foregoing is merely illustrative of the preferred embodiments of the present application and is not intended to limit the embodiments of the present application, and those skilled in the art can easily make corresponding variations or modifications according to the main concept and spirit of the present application, so that the protection scope of the present application shall be defined by the claims.

Claims (12)

1.A method of inventory processing, comprising:
Detecting an operation type aimed by an operation request sent by a requester;
If the operation type is an inventory deduction operation type, performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result; wherein, the relation among a plurality of preset state values represents that different inventory deduction operation types have a sequence of execution;
if the state detection result represents that the operation request accords with the sequence of execution among different inventory deduction operation types, setting the commodity inventory corresponding to the operation request as a deduction state, and performing deduction operation on the number of commodities in the commodity inventory;
If the operation type is an inventory updating operation type, setting the commodity inventory corresponding to the operation request as an updating state, and updating the commodity quantity in the commodity inventory;
The deduction state and the update state of the commodity inventory are mutually exclusive, so that the deduction operation or the update operation can only be carried out on the commodity quantity in the commodity inventory at the same time.
2. The method of claim 1, wherein before performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values, the method further comprises:
Detecting whether the operation request is a repeat request; wherein the repeated request is a request for representing that the repeated transmission times exceeds a preset time threshold value in a specified time period;
if the operation request is not the repeated request, executing the state node value and a plurality of preset state values according to the operation request, and carrying out state detection on the operation request to obtain a state detection result;
And if the operation request is the repeated request, determining the operation request as idempotent, and intercepting the operation request.
3. The method of claim 1, wherein the inventory deduction operation type comprises a preemption operation type and a deduction operation type, and wherein the plurality of preset status values comprises a no status value and a preemption status value; the step of performing state detection on the operation request according to the state node value of the operation request and a plurality of preset state values to obtain a state detection result, includes:
If the operation type is the preemption operation type, and the state node value is detected to be matched with the stateless value, a state detection result which characterizes that the operation request accords with the sequence of execution among different inventory deduction operation types is obtained;
If the operation type is the deduction operation type, and the state node value is detected to be matched with the preemption state value, a state detection result which indicates whether the operation request accords with the sequence of execution among different inventory deduction operation types is obtained.
4. The method of claim 1, wherein the setting the commodity inventory corresponding to the operation request to be in the deduction state and performing the deduction operation on the number of commodities in the commodity inventory comprise:
Detecting the current state of the commodity inventory corresponding to the operation request;
If the current state is a deduction state, a first detection result used for representing that the quantity of the commodities in the commodity inventory can be deducted is obtained, and the quantity of the commodities in the commodity inventory is deducted based on the first detection result;
If the current state is the update state, a second detection result used for representing that the quantity of the commodities in the commodity inventory is currently updated is obtained, after the updating operation of the quantity of the commodities in the commodity inventory is waited to be completed based on the second detection result, the commodity inventory corresponding to the operation request is set to be in a deduction state, and the deduction operation is carried out on the quantity of the commodities in the commodity inventory after the updating operation is completed.
5. The method of claim 4, wherein the subtracting the number of the products in the product inventory after the updating operation is completed comprises:
acquiring the number of the requested commodities corresponding to the operation request;
detecting whether the quantity of the commodities in the commodity inventory after the updating operation is finished meets the required commodity quantity;
And if the quantity of the commodities in the commodity inventory after the updating operation is finished meets the requested commodity quantity, carrying out deduction operation on the quantity of the commodities in the commodity inventory after the updating operation is finished based on the requested commodity quantity.
6. The method of claim 1, wherein the inventory of goods comprises a remote database and a relational database, wherein the remote database is stored in a cache and the relational database is stored in a hard disk; the deducting operation for the commodity quantity in the commodity inventory comprises the following steps:
Performing deduction operation on the commodity quantity in the remote database, and sending deduction information generated after the deduction operation is completed to a message queue;
and if the deduction information is successfully sent to the message queue, returning operation request success response information to the requester, and performing deduction operation on the commodity quantity in the relational database based on the deduction information in the message queue.
7. The method of claim 1, wherein the setting the commodity inventory corresponding to the operation request to be in the updated state and performing the update operation on the number of commodities in the commodity inventory comprise:
Detecting the current state of the commodity inventory corresponding to the operation request;
If the current state is an updating state, a third detection result used for representing that the quantity of the commodities in the commodity inventory can be updated is obtained, and the quantity of the commodities in the commodity inventory is updated based on the third detection result;
If the current state is a deduction state, a fourth detection result used for representing that the quantity of the commodities in the commodity inventory is currently subjected to deduction operation is obtained, after the quantity of the commodities in the commodity inventory is subjected to deduction operation based on the fourth detection result, the commodity inventory corresponding to the operation request is set to be in an updated state, and the quantity of the commodities in the commodity inventory after the deduction operation is completed is updated.
8. The method of claim 1, wherein the inventory of goods comprises a remote database and a relational database, the remote database stored in a cache and the relational database stored in a hard disk; the operation of updating the number of the commodities in the commodity inventory comprises the following steps:
Updating the commodity quantity in the relational database;
And synchronizing the quantity of the commodities in the remote database based on the quantity of the commodities in the commodity inventory after the updating operation is completed.
9. An inventory processing apparatus, comprising:
the operation type detection module is configured to detect an operation type aimed by an operation request sent by a requester;
The state detection module is configured to perform state detection on the operation request according to the state node value of the operation request and a plurality of preset state values if the operation type is an inventory deduction operation type, so as to obtain a state detection result; wherein, the relation among a plurality of preset state values represents that different inventory deduction operation types have a sequence of execution;
the deduction module is configured to set the commodity inventory corresponding to the operation request as a deduction state and perform deduction operation on the number of commodities in the commodity inventory if the state detection result indicates that the operation request accords with the sequence of execution among different inventory deduction operation types;
the updating module is configured to set the commodity inventory corresponding to the operation request as an updating state if the operation type is an inventory updating operation type, and perform updating operation on the commodity quantity in the commodity inventory;
The deduction state and the update state of the commodity inventory are mutually exclusive, so that the deduction operation or the update operation can only be carried out on the commodity quantity in the commodity inventory at the same time.
10. An electronic device, comprising:
one or more processors;
Storage means for storing one or more computer programs which, when executed by the one or more processors, cause the electronic device to implement the method of any of claims 1-8.
11. A computer readable storage medium having stored thereon computer readable instructions which, when executed by a processor of a computer, cause the computer to perform the method of any of claims 1 to 8.
12. A computer program product comprising a computer program, characterized in that the computer program, when executed by a processor, implements the method of any one of claims 1 to 8.
CN202211276802.6A 2022-10-17 2022-10-17 Inventory processing method, inventory processing device, electronic equipment, storage medium and product Pending CN117952508A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211276802.6A CN117952508A (en) 2022-10-17 2022-10-17 Inventory processing method, inventory processing device, electronic equipment, storage medium and product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211276802.6A CN117952508A (en) 2022-10-17 2022-10-17 Inventory processing method, inventory processing device, electronic equipment, storage medium and product

Publications (1)

Publication Number Publication Date
CN117952508A true CN117952508A (en) 2024-04-30

Family

ID=90796631

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211276802.6A Pending CN117952508A (en) 2022-10-17 2022-10-17 Inventory processing method, inventory processing device, electronic equipment, storage medium and product

Country Status (1)

Country Link
CN (1) CN117952508A (en)

Similar Documents

Publication Publication Date Title
US11281665B2 (en) Read/write split database query routing
US10678808B2 (en) Eager replication of uncommitted transactions
US9756469B2 (en) System with multiple conditional commit databases
US8589510B2 (en) Method and system of synchronizing accounting objects between a client and server
CN111522631B (en) Distributed transaction processing method, device, server and medium
CN107766080B (en) Transaction message processing method, device, equipment and system
CN112817995B (en) Data processing method and device, electronic equipment and storage medium
US9697042B2 (en) Extensibility of business process and application logic
CN109862102B (en) Distributed data multi-copy concurrency control system, server and method
CN111538519A (en) Version upgrading method and device
CN110599277A (en) Inventory deduction method and device
US20210176077A1 (en) Integrating blockchain with off-chain services
CN112988812B (en) Inventory data processing method, device, equipment and storage medium
EP3542265A1 (en) Defining variability schemas in an application programming interface (api)
CN117952508A (en) Inventory processing method, inventory processing device, electronic equipment, storage medium and product
US9652766B1 (en) Managing data stored in memory locations having size limitations
CN107277108B (en) Method, device and system for processing messages at nodes of block chain
CN113835780A (en) Event response method and device
CN111881149A (en) Large-scale concurrency solution method and system based on Java
CN110851533A (en) Data synchronization method, device, medium and electronic equipment for crossing heterogeneous databases
CN111046055A (en) Block chain global configuration changing method, equipment and storage medium
CN117010983A (en) Method and device for achieving commodity reservation order state synchronization based on mybatis interceptor
CN109460288B (en) Transaction processing method, management server, transaction processing system and storage medium
CN116703517A (en) Method, apparatus and computer readable medium for processing information
US20220156736A1 (en) Payment transaction handling in a radio communication network

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination