Inventory deduction method and device

By determining the database shard identifier based on the item identifier, the database service node for the inventory deduction operation is located, solving the overselling problem of traditional inventory deduction methods in high-concurrency scenarios, and achieving rapid response and efficient inventory management.

CN120806815APending Publication Date: 2025-10-17SHANGHAI BILIBILI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510947456.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-09
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Traditional inventory deduction methods are prone to overselling in high-concurrency scenarios. Monolithic databases have poor scalability and are unable to cope with sudden increases in business volume, which increases the complexity of system maintenance and upgrades.

Method used

By determining the database shard identifier of the database service node based on the item identifier, the database service node used to perform the inventory deduction operation is located, and distributed locks and scripts are used to ensure the atomicity and fast response of the operation.

Benefits of technology

It improves the efficiency of inventory deduction operations, enhances user experience and system integrity, avoids overselling of inventory, and simplifies system maintenance and upgrade processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120806815A_ABST
    Figure CN120806815A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an inventory deduction method and device, computer equipment, a medium and a program product. Relates to the technical field of computers. The method comprises the following steps: in response to an article purchase request or an article exchange request, determining a database fragment identifier of a database service node corresponding to an article identifier based on the article identifier carried in the article purchase request or the article exchange request; determining a database service node for executing an inventory deduction operation according to the database fragment identifier; and executing an inventory deduction operation based on the article purchase request or the article exchange request through the database service node. According to the technical scheme provided by the embodiment of the invention, the inventory deduction operation can be quickly responded.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer technology, and particularly relate to an inventory deduction method and device, computer equipment, computer readable storage medium, and computer program product. BACKGROUND

[0002] In today's digital business environment, inventory management is a key link for e-commerce, retail, and various marketing activities. With the rapid development of Internet technology and the continuous improvement of user shopping experience, efficient and accurate inventory deduction methods are particularly important.

[0003] Traditional inventory deduction methods are mostly based on single database operations. When facing high-concurrency user requests, such as Double Eleven shopping festival, time-limited flash sale activities, or large-scale discount redemption scenarios, the performance bottleneck of single databases is highlighted. This can easily lead to inventory overselling, i.e., the actual inventory of an item is displayed as a negative number, and subsequent orders cannot be normally fulfilled, causing significant economic losses and negative user feedback for the merchant. At the same time, single databases have poor scalability and are difficult to cope with sudden increases in business volume, increasing the complexity of system maintenance and upgrades.

[0004] It should be noted that the above content is not necessarily prior art and does not limit the patent protection scope of the present application. SUMMARY

[0005] Embodiments of the present application provide an inventory deduction method, device, computer equipment, computer readable storage medium, and computer program product to solve or alleviate one or more technical problems raised above.

[0006] One aspect of an embodiment of the present application provides an inventory deduction method, the method comprising: in response to an item purchase request or an item redemption request, determining a database shard identifier of a database service node corresponding to an item identifier based on the item identifier carried in the item purchase request or the item redemption request; determining a database service node for performing an inventory deduction operation according to the database shard identifier; performing an inventory deduction operation based on the item purchase request or the item redemption request through the database service node.

[0007] Optionally, the determining a database service node for performing an inventory deduction operation according to the target database shard identifier comprises: obtaining a mapping relationship table of database shard identifiers and database service nodes that is established in advance; determining a database service node for performing an inventory deduction operation based on the mapping relationship table and the target database shard identifier.

[0008] Optionally, the mapping relationship table is obtained by: storing multiple pressure testing data carrying database shard identifiers into a database cluster, wherein different pressure testing data carries different database shard identifiers, and the database cluster comprises multiple database service nodes; obtaining a distribution of the pressure testing data carrying different database shard identifiers in each database service node in the database cluster; establishing the mapping relationship table according to the distribution.

[0009] Optionally, the method further comprises: in response to an item inventory creation request of multiple target items, allocating corresponding database shard identifiers to inventory data of each of the target items based on the mapping relationship table, wherein inventory data of different target items is mapped to different database service nodes through different database shard identifiers; storing the inventory data of each of the target items into different database service nodes based on the database shard identifier allocated to the inventory data of each of the target items; establishing an association between the item identifier of each of the target items and the corresponding database shard identifier.

[0010] Optionally, the method further comprises: synchronizing the inventory data of the multiple target items stored in the multiple database service nodes to a preset database.

[0011] Optionally, the method further comprises: after a target database service node fails, if it is detected that the target database service node has recovered, updating the inventory data of a target item stored in the target database service node according to the inventory data of the multiple target items stored in the database.

[0012] Optionally, the inventory deduction operation performed by the database service node based on the item purchase request or item exchange request comprises: acquiring an inventory operation lock by the database service node based on the item purchase request or item exchange request; after the database service node acquires the inventory operation lock, executing a preset script by the database service node to check whether the inventory corresponding to the item identifier is sufficient through the script, and performing an inventory deduction operation after the inventory is sufficient.

[0013] Another aspect of the embodiments of the present application provides an inventory deduction device, the device comprising: a response module, configured to determine, in response to an item purchase request or an item exchange request, a database shard identifier of a database service node corresponding to an item identifier carried in the item purchase request or the item exchange request; a determination module, configured to determine, according to the database shard identifier, a database service node for performing an inventory deduction operation; an inventory deduction module, configured to perform, by the database service node, an inventory deduction operation based on the item purchase request or the item exchange request.

[0014] Another aspect of the embodiments of the present application provides a computer device, comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method as described above.

[0015] Another aspect of the embodiments of the present application provides a computer readable storage medium, which stores computer instructions, and the computer instructions are executed by a processor to implement the method as described above.

[0016] Another aspect of the embodiments of the present application provides a computer program product, which comprises a computer program, and the computer program is executed by a processor to implement the method as described above.

[0017] The embodiments of the present application can have the following advantages: in response to an item purchase request or an item exchange request, a database shard identifier of a database service node corresponding to an item identifier carried in the item purchase request or the item exchange request is determined; according to the database shard identifier, a database service node for performing an inventory deduction operation is determined; and the inventory deduction operation is performed by the database service node based on the item purchase request or the item exchange request. The above technical solution determines the database shard identifier of the database service node according to the item identifier, and then locates the database service node for performing the inventory deduction operation, so that the inventory deduction operation can be quickly responded, the efficiency of processing the request is greatly improved, and the user experience and the overall system are improved. BRIEF DESCRIPTION OF DRAWINGS

[0018] The accompanying drawings, which are included to provide a further understanding of the application and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain exemplary implementations of the application. The illustrated embodiments are exemplary only and not limiting of the scope of the claims. In all the Figures, like reference numerals refer to like parts throughout the various Figures. The reference numerals in the claims are by no means limiting.

[0019] Figure 1 An operation environment diagram of the inventory deduction method according to Embodiment One of the present application is schematically shown; Figure 2 A flowchart of the inventory deduction method according to Embodiment One of the present application is schematically shown; Figure 3 A step refinement flowchart of determining the database service node for performing the inventory deduction operation according to the database shard identification is schematically shown; Figure 4 A step refinement flowchart of performing the inventory deduction operation by the database service node based on the item purchase request or item exchange request is schematically shown; Figure 5 An added step flowchart of the inventory deduction method according to Embodiment One of the present application is schematically shown; Figure 6 A block diagram of the inventory deduction apparatus according to Embodiment Two of the present application is schematically shown; Figure 7 A hardware architecture schematic diagram of the computer device according to Embodiment Three of the present application is schematically shown. DETAILED DESCRIPTION

[0020] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.

[0021] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for the purpose of description, and should not be understood as indicating or implying the relative importance of the technical features indicated or the number of the technical features indicated. Therefore, the features with "first", "second" can explicitly or implicitly include at least one of the features. In addition, the technical solutions of various embodiments can be combined with each other, but it must be based on the fact that a person of ordinary skill in the art can realize it, and when the combination of technical solutions appears to be contradictory or unachievable, it should be considered that the combination of technical solutions does not exist, nor within the scope of protection claimed by the present application.

[0022] It should be noted that, in the present application, if the collection, storage, use, transmission and processing of data are involved, each link of the data shall strictly follow the laws, regulations, industry standards and regulatory requirements of the data source, use location and relevant countries and regions to ensure the legality and compliance of data activities. In the collection link, the data subject is informed of the collection purpose, method and scope in a conspicuous manner, and the collection is carried out after obtaining the legal authorization of the data subject, so as to ensure that the collection process follows the "minimum necessary" principle and does not collect data beyond the scope. In the storage link, the storage period is limited, and the data is deleted or anonymized and encrypted in a timely manner after achieving the storage purpose. In the use link, a strict data security protection mechanism will be implemented, and the original data will be processed according to the preset desensitization rules through field-level desensitization technology. For different types of data, various desensitization strategies such as data generalization, data anonymization and data encryption are adopted to effectively avoid the risk of sensitive information leakage and ensure that the data used finally is desensitized data after security processing, thereby comprehensively protecting the rights and interests of data subjects and data security. In the transmission and processing link, the confidentiality and security of data in the transmission and processing process are ensured.

[0023] In the description of the present application, it should be understood that the numerical reference before the step does not indicate the order of execution of the steps before and after the step, but is only used to facilitate the description of the present application and to distinguish each step, and therefore cannot be understood as a limitation on the present application.

[0024] First, the terms involved in the present application are explained: Redis: a super-fast database used to store and read data, especially suitable for handling scenarios with a large number of users accessing simultaneously.

[0025] Lua script: a small programming language that Redis can use to perform a series of operations, ensuring that these operations will not be interrupted by other requests.

[0026] Distributed lock: a mechanism that ensures that only one user can perform an operation at the same time, such as deducting inventory.

[0027] Inventory sharding: distributing inventory data across multiple database service nodes so that each node only handles a portion of the requests, thereby improving overall performance.

[0028] Spike scenario: a high-concurrency scenario, such as double 11 shopping, where a large number of users try to purchase the same item at the same time.

[0029] Taishan: a persistent storage system used to save critical data, so that data will not be lost even if Redis fails.

[0030] To facilitate the understanding of the technical solutions of the embodiments of the present application by those skilled in the art, the related art is described as follows: Traditional inventory deduction methods are mostly based on single database operation. When facing high-concurrency user requests, such as Double Eleven shopping festival, time-limited killing activities or large-scale discount redemption, the performance bottleneck of single database is highlighted. This can easily lead to inventory overselling, that is, the actual inventory of an item shows negative, and subsequent orders cannot be normally fulfilled, which brings huge economic losses and negative user feedback to the merchant. At the same time, the single database has poor scalability and is difficult to cope with the sudden increase in business volume, increasing the complexity of system maintenance and upgrading.

[0031] To this end, an embodiment of the present application provides an inventory deduction technical solution. In the technical solution, the database shard identifier of the database service node is determined according to the item identifier, and the database service node for executing the inventory deduction operation is repositioned, so that the inventory deduction operation can be quickly responded, greatly improving the efficiency of processing requests, and thus improving the user experience and system integrity. See the following.

[0032] Finally, for the convenience of understanding, an exemplary operating environment is provided below.

[0033] As shown in Figure 1 The environment diagram includes a service platform 2, a network 4, and a client 6, wherein: The service platform 2 can be composed of a single or multiple computing devices. The multiple computing devices can include virtualized computing instances. The virtualized computing instances can include virtual machines, such as emulations of computer systems, operating systems, servers, and the like. The computing devices can load the virtual machines based on virtual images and / or other data defining specific software (e.g., operating systems, specialized applications, servers) for emulation. As the demand for different types of processing services changes, different virtual machines can be loaded and / or terminated on one or more computing devices. A hypervisor can be implemented to manage the use of different virtual machines on the same computing device.

[0034] The service platform 2 can be configured to communicate with the client 6 and the like through the network 4. The network 4 includes various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network 4 can include physical links, such as coaxial cable links, twisted-pair cable links, fiber-optic links, combinations thereof, and the like, or wireless links, such as cellular links, satellite links, Wi-Fi links, and the like.

[0035] The service platform 2 can provide storage, reading, writing, querying, deleting, and the like.

[0036] The client 6 can be an electronic device running an operating system such as Windows, Android™, or iOS, such as a smartphone, a tablet device, a laptop computer, a virtual reality device, a game device, a set-top box, a vehicle terminal, a smart television. Based on the above operating system, various application programs such as inventory deduction programs can be run.

[0037] The client 6 can provide / configure a user access page for manipulating the service platform 2 or uploading objects, etc.

[0038] It should be noted that the above devices are exemplary, and the number and types of devices can be adjusted in different scenarios or according to different needs.

[0039] The technical solutions of the present application will be described below through a plurality of embodiments. It should be understood that these embodiments can be implemented in a variety of different forms, and should not be interpreted as being limited to the embodiments described herein.

[0040] Embodiment One Figure 2 A flowchart of an inventory deduction method according to Embodiment One of the present application is schematically shown.

[0041] As shown in Figure 2 The inventory deduction method can include steps S200-S204, wherein: Step S200, in response to an item purchase request or an item exchange request, determining a database shard identifier of a database service node corresponding to an item identifier based on the item identifier carried in the item purchase request or the item exchange request.

[0042] Step S202, determining a database service node for performing an inventory deduction operation according to the database shard identifier.

[0043] Step S204, performing an inventory deduction operation based on the item purchase request or the item exchange request through the database service node.

[0044] The inventory deduction method provided by the present embodiment, in response to an item purchase request or an item exchange request, determines a database shard identifier of a database service node corresponding to an item identifier based on the item identifier carried in the item purchase request or the item exchange request; determines a database service node for performing an inventory deduction operation according to the database shard identifier; and performs an inventory deduction operation based on the item purchase request or the item exchange request through the database service node. The above technical solution determines the database shard identifier of the Redis node according to the item identifier, and then locates the Redis node for performing the inventory deduction operation, so that the inventory deduction operation can be quickly responded, greatly improving the efficiency of processing requests, and further improving the user experience and system integrity.

[0045] The following describes in detail each of steps S200-S204 and optional other steps. Figure 2

[0046] Step S200 In response to the item purchase request or the item exchange request, a database shard identifier of a database service node corresponding to the item identifier is determined based on the item identifier carried in the item purchase request or the item exchange request.

[0047] When a user initiates an item purchase request or an item exchange request through a front-end page, a mobile application or other interfaces, the server first receives the request, and then parses the received request to extract the item identifier therein. The item identifier is used to uniquely distinguish different items. In this embodiment, the item identifier can be an item ID. For example, on an e-commerce platform, when a user clicks to purchase an item, a purchase request is generated, and the purchase request contains the number of the item, such as “P123456”. This number is the item identifier.

[0048] The database shard identifier is an identifier used to determine the database service node in which inventory data is stored.

[0049] In an exemplary embodiment, when inventory data is stored in a Redis cluster, a hash tag can be used as the database shard identifier.

[0050] It should be noted that the hash tag is a mechanism used in Redis to control the hash slot allocation of a key. It allows users to embed a specific string (usually wrapped in {}) in the key, so that multiple keys can be allocated to the same hash slot, and thus the data corresponding to the multiple keys can be stored in the same node.

[0051] In another exemplary embodiment, when inventory data is stored in a MySQL Cluster, the hash value of a primary key can be used as the database shard identifier.

[0052] It should be noted that the hash value of the primary key can determine which shard the data belongs to. Through configuration, data in a specific primary key range can be allocated to the same node, thereby indirectly implementing data sharding to the same node.

[0053] ​In the embodiment, in order to quickly determine the target database shard identifier corresponding to the item identifier, an association (also referred to as a mapping table) between the item identifier and the database shard identifier can be established in advance. For example, the database shard identifier corresponding to the item identifier A is 112; the database shard identifier corresponding to the item identifier B is 113; and the database shard identifier corresponding to the item identifier C is 114.

[0054] Step S202 According to the database shard identifier, the database service node used for performing the inventory deduction operation is determined.

[0055] In an embodiment, the server maintains a mapping relationship table between the database shard identifier and the database service node. The table records the database service node information of each database shard identifier, including the IP address, port number, and the like of the node.

[0056] The server finds the database service node corresponding to the database shard identifier by searching the mapping relationship table. For example, the mapping relationship table records that the database service node corresponding to the database shard identifier 123 is the IP address 192.168.1.100 and the port number 6379. The server records the node information, which is used as the target database service node for performing the inventory deduction operation.

[0057] The database service node is a database in the database cluster, which is used to perform the inventory deduction operation based on the inventory data stored therein.

[0058] In an optional embodiment, referring to Figure 3 According to the database shard identifier, the database service node used for performing the inventory deduction operation can include the following steps. In step S300, a mapping relationship table between the database shard identifier and the database service node is obtained.

[0059] In step S302, the database service node used for performing the inventory deduction operation is determined based on the mapping relationship table and the database shard identifier.

[0060] In the embodiment, by establishing the mapping relationship table between the database shard identifier and the database service node in advance, when the database service node used for performing the inventory deduction operation is subsequently determined, the database service node can be directly obtained according to the mapping relationship table.

[0061] In actual operation, the database cluster can change the mapping relationship between the database shard identifier and the node due to the addition, removal or failure of the node. Therefore, the server can periodically obtain the latest database shard identifier mapping relationship from the database cluster and update the local mapping relationship table to ensure accurate positioning to the corresponding database service node. For example, the system can send a query request to the database cluster every certain time (e.g., 1 hour) to obtain the current distribution of the database shard identifier and update the local mapping relationship table.

[0062] In an optional embodiment, the mapping relationship table is obtained by: storing multiple stress test data carrying database shard identifiers into a database cluster, wherein the database shard identifiers carried by different stress test data are different, and the database cluster includes multiple database service nodes; obtaining the distribution of the stress test data carrying different database shard identifiers in each database service node of the database cluster; and establishing the mapping relationship table according to the distribution.

[0063] The database cluster can be a Redis cluster, a MySQL Cluster, etc.

[0064] In an embodiment, each database shard identifier corresponding to each database service node can be detected by multiple stress test data carrying database shard identifiers.

[0065] As an example, the stress test data used are: stock:{100}:cny, stock:{115}:cny, stock:{120}:cny, and stock:{125}:cny.

[0066] After detection, the stress test data stock:{100}:cny is distributed in the database service node 1; the stress test data stock:{115}:cny is distributed in the database service node 2; the stress test data stock:{120}:cny is distributed in the database service node 3; and the stress test data stock:{125}:cny is distributed in the database service node 4.

[0067] Among them, these database shard identifiers serve as the "identity card number" of each node to identify which node the data should be stored in.

[0068] In this embodiment, the mapping relationship table can be quickly established through the stress test data.

[0069] Step S204 The database service node performs an inventory deduction operation based on the item purchase request or the item exchange request.

[0070] In the embodiment, the server extracts key information from the item purchase request or the item exchange request, for constructing the inventory deduction instruction. For the purchase request, the item identifier and the purchase quantity are extracted; for the exchange request, the item identifier and the exchange quantity are extracted. After obtaining the information, the database service node combines the information according to the data operation instruction format supported by the database service node. For example, if the inventory data is stored in a hash structure of Redis, the item identifier is used as the key, a determined target database shard identifier is used as the hash field, and the inventory quantity is used as the field value, the constructed instruction can be similar to "HINCRBY [hash name corresponding to the item identifier] [item identifier] - [purchase or exchange quantity]", which is used for performing an atomic decrement operation on the inventory of the specified item.

[0071] In actual application, the inventory deduction operation needs to be guaranteed atomicity to avoid inventory data confusion caused by multiple concurrent requests. The single atomic operation instruction provided by the database service node (for example, Redis) can be used for implementation. By using the single atomic operation instruction (atomic operation of checking inventory and inventory deduction combined), the inventory data can be accurately updated in the concurrent case.

[0072] In an embodiment, when executing the inventory deduction instruction, if the result returned by the database service node indicates that the inventory is insufficient (for example, the current inventory quantity minus the purchase or exchange quantity is less than zero), the server will immediately terminate the inventory deduction operation, and perform corresponding processing according to the request type. For example, for the purchase request, the server returns the prompt information "inventory is insufficient, and the purchase cannot be completed" to the user, and can recommend other similar items with inventory; for the exchange request, the server prompts the user "the inventory of the exchange item is insufficient, please select other items or try later", and can give certain compensation measures according to the business rules, such as returning part of the points.

[0073] In an optional embodiment, referring to Figure 4 , the method further includes: In step S400, in response to the item inventory creation request of a plurality of target items, a corresponding database shard identifier is allocated to the inventory data of each target item based on the mapping relationship table, wherein the inventory data of different target items is mapped to different database service nodes through different database shard identifiers.

[0074] In step S402, based on the database shard identifier to which the inventory data of each target item is allocated, the inventory data of each target item is respectively stored in different database service nodes.

[0075] In step S404, an association relationship between the item identifier of each target item and the corresponding database shard identifier is established.

[0076] In this embodiment, since the corresponding relationship between different database service nodes and database shard identifiers is recorded in the mapping relationship table in advance, when creating inventory data for the items, different database shard identifiers can be allocated to the inventory data of the items in sequence, and then the allocation of different database service nodes is realized.

[0077] For example, the inventory data (stock: cny) of item A is allocated with a database shard identifier {100}, and the corresponding database service node of the inventory data is node 1; The inventory data (stock: cny) of item B is allocated with a database shard identifier {115}, and the corresponding database service node of the inventory data is node 2; The inventory data (stock: cny) of item C is allocated with a database shard identifier {120}, and the corresponding database service node of the inventory data is node 3; The inventory data (stock: cny) of item D is allocated with a database shard identifier {125}, and the corresponding database service node of the inventory data is node 4.

[0078] In this embodiment, through the above inventory sharding processing, the inventory data of each item can be evenly distributed on different database service nodes.

[0079] In this embodiment, after the storage of the inventory data is completed, the association relationship between the item identifier of each target item and the corresponding database shard identifier is established, so as to facilitate the subsequent search for the database shard identifier corresponding to different items based on the association relationship.

[0080] In an optional embodiment, the method further comprises: Synchronizing the inventory data of the plurality of target items stored in the plurality of database service nodes to a preset database.

[0081] In this embodiment, the inventory data can be written into the database in an asynchronous manner, such as being written into Taishan, to realize the persistent storage of the inventory data. In this way, when the database service node (for example, Redis) fails, the inventory data recorded in the database can be used to avoid overselling of items.

[0082] In an optional embodiment, the method further comprises: after the target database service node fails, if it is detected that the target database service node recovers normally, updating the inventory data of the target item stored in the target database service node according to the inventory data of the plurality of target items stored in the database.

[0083] In the embodiment, after the target database service node fails, in order to avoid overselling of the goods, the inventory data stored in the database (for example, Taishan) is used to overwrite the inventory data in the database service node (for example, Redis) when it is detected that the target database service node is restored to normal, so as to update the inventory data.

[0084] In an embodiment, in order to update the inventory data in time, the state of the database service node can be identified by a fault identification switch, and once it is identified that the state of the database service node changes from a fault state to a normal state, the inventory data of the target goods stored in the database service node is updated.

[0085] In an optional embodiment, referring to Figure 5 The inventory deduction operation performed by the database service node based on the goods purchase request or the goods exchange request includes: In step S500, the database service node acquires an inventory operation lock based on the goods purchase request or the goods exchange request.

[0086] In step S502, after the database service node acquires the inventory operation lock, the database service node executes a preset script to first check whether the inventory corresponding to the goods identifier is sufficient through the script, and performs an inventory deduction operation after the inventory is sufficient.

[0087] The script is used to first check whether the inventory corresponding to the goods identifier is sufficient, and perform an inventory deduction operation after the inventory is sufficient.

[0088] In a specific embodiment, when the database service node is a Redis node, the script is a Lua script.

[0089] In the embodiment, when performing the inventory deduction operation, the inventory operation lock is first acquired, and if the inventory operation lock is successfully acquired, the database service node executes a preset script to first check whether the inventory corresponding to the goods identifier is sufficient through the script, and performs an inventory deduction operation after the inventory is sufficient, so as to ensure that the same user can only initiate one deduction request within 500 ms. In addition, the atomic operation of the inventory deduction is realized by the script, so as to avoid overselling.

[0090] Embodiment two Figure 6The block diagram of the inventory deduction device 600 according to the second embodiment of the present application is schematically shown. The device can be divided into one or more program modules, one or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Figure 6 As shown, the apparatus 600 may include: a response module 610, a determination module 620, and an inventory deduction module 630, wherein: A response module 610 is configured to respond to an item purchase request or an item exchange request and determine, based on an item identifier carried in the item purchase request or the item exchange request, a database shard identifier of a database service node corresponding to the item identifier; A determination module 620 is configured to determine a database service node for executing an inventory deduction operation according to the database shard identifier; The inventory deduction module 630 is configured to execute an inventory deduction operation based on the item purchase request or item exchange request through the database service node.

[0091] As an optional embodiment, determining the database service node for executing the inventory deduction operation according to the target database shard identifier includes: Obtain a pre-established mapping relationship table between database shard identifiers and database service nodes; A database service node for executing the inventory deduction operation is determined based on the mapping relationship table and the target database shard identifier.

[0092] As an optional embodiment, the mapping relationship table is obtained by the following operations: Storing multiple stress test data carrying database shard identifiers in a database cluster, wherein different stress test data carry different database shard identifiers, and the database cluster includes multiple database service nodes; Obtaining the distribution of stress testing data carrying different database shard identifiers on each database service node in the database cluster; The mapping relationship table is established according to the distribution situation.

[0093] As an optional embodiment, the apparatus 600 is further configured to: In response to item inventory creation requests for multiple target items, assigning a corresponding database shard identifier to the inventory data of each target item based on the mapping relationship table, wherein the inventory data of different target items is mapped to different database service nodes via different database shard identifiers; respectively, based on the database shard identifier allocated to the inventory data of each of the target items; An association between the item identifier of each of the target items and the corresponding database shard identifier is established.

[0094] As an optional embodiment, the apparatus 600 is further configured to: synchronize the inventory data of the plurality of target items stored in the plurality of database service nodes to a preset database.

[0095] As an optional embodiment, the apparatus 600 is further configured to: If it is detected that the target database service node recovers after the target database service node fails, update the inventory data of the target item stored in the target database service node according to the inventory data of the plurality of target items stored in the database.

[0096] As an optional embodiment, the inventory deduction operation performed by the database service node based on the item purchase request or item exchange request comprises: acquiring, by the database service node, an inventory operation lock based on the item purchase request or item exchange request; After the database service node acquires the inventory operation lock, executing a preset script by the database service node to check, by the script, whether the inventory corresponding to the item identifier is sufficient, and performing an inventory deduction operation after the inventory is sufficient.

[0097] In this embodiment, in response to an item purchase request or an item exchange request, the database shard identifier of the database service node corresponding to the item identifier is determined based on the item identifier carried in the item purchase request or item exchange request; the database service node used to perform the inventory deduction operation is determined according to the database shard identifier; and the inventory deduction operation is performed by the database service node based on the item purchase request or item exchange request. The above technical solution determines the database shard identifier of the database service node according to the item identifier, and then locates the database service node used to perform the inventory deduction operation, so that the inventory deduction operation can be quickly responded, greatly improving the efficiency of processing requests, and further improving the user experience and system integrity.

[0098] Embodiment Three Figure 7The following schematically shows a hardware architecture diagram of a computer device 10000 suitable for implementing the inventory deduction method according to the third embodiment of the present application. In some embodiments, the computer device 10000 can be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle-mounted terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 can be a rack server, a blade server, a tower server, or a cabinet server (including an independent server or a server cluster composed of multiple servers), etc. Figure 7 As shown, the computer device 10000 includes but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other via a system bus. Memory 10010 includes at least one type of computer-readable storage medium, including flash memory, a hard disk, a multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic storage, a magnetic disk, an optical disk, and the like. In some embodiments, memory 10010 may be an internal storage module of computer device 10000, such as a hard disk or memory of computer device 10000. In other embodiments, memory 10010 may also be an external storage device of computer device 10000, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, and the like equipped on computer device 10000. Of course, memory 10010 may also include both internal storage modules and external storage devices of computer device 10000. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed on the computer device 10000, such as the program code of the inventory deduction method, etc. In addition, the memory 10010 can also be used to temporarily store various data that has been output or is to be output.

[0099] In some embodiments, processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. Processor 10020 is typically used to control the overall operation of computer device 10000, such as performing control and processing related to data exchange or communication with computer device 10000. In this embodiment, processor 10020 is used to execute program code stored in memory 10010 or process data.

[0100] The network interface 10030 can include a wireless network interface or a wired network interface, and is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 with an external terminal through a network, establish a data transmission channel and a communication link between the computer device 10000 and the external terminal, and the like. The network can be an Intranet, the Internet, a Global System of Mobile communication (GSM), a Wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, Bluetooth, Wi-Fi, and the like wireless or wired network.

[0101] It should be noted that, Figure 7 Only the computer device with components 10010-10030 is shown, but it should be understood that all the shown components are not required to be implemented, and more or less components can be alternatively implemented.

[0102] In this embodiment, the inventory deduction method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as the processor 10020) to complete the embodiments of the present application.

[0103] Embodiment Four The embodiments of the present application also provide a computer readable storage medium, and the computer readable storage medium has a computer program stored thereon, wherein the computer program is executed by a processor to implement the steps of the inventory deduction method in the embodiments.

[0104] In this embodiment, the computer readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read only memory (ROM), an electrically erasable programmable read only memory (EEPROM), a programmable read only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the computer readable storage medium can be an internal storage unit of the computer device, for example, a hard disk or a memory of the computer device. In other embodiments, the computer readable storage medium can also be an external storage device of the computer device, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device. Of course, the computer readable storage medium can also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the computer readable storage medium is usually used to store an operating system and various application software installed on the computer device, for example, program codes of the inventory deduction method in the embodiments, etc. In addition, the computer readable storage medium can also be used to temporarily store various data that have been output or will be output.

[0105] Embodiment five The embodiments of the present application also provide a computer program product, comprising a computer program which, when executed by a processor, implements the method in the above embodiments.

[0106] Obviously, those skilled in the art should understand that each module or each step of the above-mentioned embodiments of the present application can be implemented by using a general computer device, which can be concentrated on a single computer device or distributed on a network composed of multiple computer devices, and optionally, each module or each step can be implemented by using program codes executable by a computer device, so that each module or each step can be stored in a storage device and executed by a computer device, and in some cases, the steps shown or described can be executed in an order different from that shown here, or each module or each step can be manufactured into an individual integrated circuit module, or multiple modules or steps can be manufactured into a single integrated circuit module. Therefore, the embodiments of the present application are not limited to any particular combination of hardware and software.

[0107] It should be noted that the above is only the preferred embodiment of the present application, and does not limit the patent protection scope of the present application, and any equivalent structure or equivalent process transformation using the content of the specification and drawings of the present application, or direct or indirect application in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for reducing inventory, characterized in that: The method comprises: In response to an item purchase request or an item exchange request, determining a target database shard identifier corresponding to the item identifier based on the item identifier carried in the item purchase request or the item exchange request; Determine a database service node for executing the inventory deduction operation according to the target database shard identifier; An inventory deduction operation is performed based on the item purchase request or the item exchange request by the database service node.

2. The method according to claim 1, characterized in that The determining of the database service node for executing the inventory deduction operation according to the target database shard identifier includes: Obtain a pre-established mapping relationship table between database shard identifiers and database service nodes; A database service node for executing the inventory deduction operation is determined based on the mapping relationship table and the target database shard identifier.

3. The method according to claim 2, characterized in that The mapping relationship table is obtained by the following operations: Storing multiple stress test data carrying database shard identifiers in a database cluster, wherein different stress test data carry different database shard identifiers, and the database cluster includes multiple database service nodes; Obtaining the distribution of stress testing data carrying different database shard identifiers on each database service node in the database cluster; The mapping relationship table is established according to the distribution situation.

4. The method according to claim 3, characterized in that The method further comprises: In response to item inventory creation requests for multiple target items, assigning a corresponding database shard identifier to the inventory data of each target item based on the mapping relationship table, wherein the inventory data of different target items is mapped to different database service nodes via different database shard identifiers; Based on the database shard identifiers assigned to the inventory data of each target item, the inventory data of each target item is stored in different database service nodes; An association relationship is established between the item identifier of each target item and the corresponding database shard identifier.

5. The method according to claim 4, characterized in that The method further comprises: The inventory data of the plurality of target items stored in the plurality of database service nodes are synchronized to a preset database.

6. The method according to claim 5, characterized in that The method further comprises: After a target database service node fails, if it is detected that the target database service node recovers to normal, the inventory data of the target items stored in the target database service node is updated according to the inventory data of multiple target items stored in the database.

7. The method according to any one of claims 1 to 6, characterized in that The performing of the inventory deduction operation based on the item purchase request or the item exchange request by the database service node includes: Acquiring an inventory operation lock based on the item purchase request or item redemption request through the database service node; After the database service node obtains the inventory operation lock, a preset script is executed by the database service node to first check whether the inventory corresponding to the item identifier is sufficient through the script, and if the inventory is sufficient, perform the inventory deduction operation.

8. A stock deduction device, characterized in that: The device comprises: a response module, configured to respond to an item purchase request or an item exchange request and determine, based on an item identifier carried in the item purchase request or the item exchange request, a database shard identifier of a database service node corresponding to the item identifier; a determination module, configured to determine a database service node for executing an inventory deduction operation according to the database shard identifier; An inventory deduction module is configured to execute an inventory deduction operation based on the item purchase request or the item exchange request through the database service node.

9. A computer device, characterized in that: include: at least one processor; and a memory communicatively coupled to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, which, when executed by a processor, implement the method according to any one of claims 1 to 7.

11. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to claims 1 to 7 are implemented.