Inventory processing method and device, electronic equipment and computer readable storage medium

By allocating inventory to multiple shards in the inventory processing and determining the request shard key for operation, the stability problem caused by the concentration of inventory operation pressure in the prior art is solved, and a more efficient and stable inventory processing is achieved.

CN119863183APending Publication Date: 2025-04-22HAINAN TENCENT NETWORK INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311361446.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-19
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

In the inventory processing, the prior art, because a large number of read and write operations are concentrated on a single shard, resulting in a performance upper limit breakthrough, operation failure or delay, and poor stability.

Method used

By determining the inventory quantity of the target object and the number of shards of multiple shards, a shard key is generated, the inventory is allocated to multiple shards, and upon receiving the inventory operation request, the request shard key is determined from the multiple shard keys to perform inventory operation processing.

Benefits of technology

Effectively allocate the pressure of inventory operations, avoid unavailability caused by excessive pressure in a single shard, and improve the stability and efficiency of inventory processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119863183A_ABST
    Figure CN119863183A_ABST
Patent Text Reader

Abstract

The invention provides an inventory processing method and device, electronic equipment, a computer readable storage medium and a computer program product. The method comprises the following steps: determining an inventory quantity of a target object and a fragment quantity of a plurality of fragments in an inventory database; according to the number of the fragments, generating fragment keys, corresponding to the multiple fragments, of the target object; performing inventory distribution processing according to the inventory quantity and the fragment quantity to obtain fragment inventory quantities corresponding to the plurality of fragments, and writing the fragment inventory quantities corresponding to the fragments into the fragments according to fragment keys corresponding to the fragments; receiving an inventory operation request for the target object; and in response to an inventory operation request for the target object, determining a fragmentation request key from the plurality of fragmentation keys, and performing inventory operation processing on the fragmentation inventory quantity in the fragmentation corresponding to the fragmentation request key according to the fragmentation request key. According to the invention, the stability and efficiency of inventory processing can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to computer technology, and more particularly to an inventory processing method, device, electronic device, computer-readable storage medium, and computer program product. Background Art

[0002] Inventory handling refers to the management of various objects (materials) stored for the purpose of supporting production, maintenance, operations or customer service. For example, in an e-commerce scenario, the e-commerce platform needs to manage the inventory quantity of each product. As the objects are traded or circulated, the inventory quantity needs to be operated accordingly, such as increasing or decreasing the inventory quantity.

[0003] In the solutions provided by the related art, when faced with a wide variety of objects, the inventory quantities of multiple objects are usually stored through multiple shards, and the inventory quantity of each object is specifically stored in a single shard corresponding to the database. However, this will cause a large number of read and write operations for the inventory quantity of the same object to be concentrated on a single shard, which is easy to exceed the performance limit of a single shard and cause operation failure or operation delay, that is, the stability of inventory processing according to the solutions provided by the related art is poor. Summary of the invention

[0004] The present application provides an inventory processing method, device, electronic device, computer-readable storage medium and computer program product, which can improve the stability and efficiency of inventory processing.

[0005] The technical solution of this application is implemented as follows:

[0006] The present application provides an inventory processing method, comprising:

[0007] Determine the inventory quantity of the target object and the number of shards for multiple shards in the inventory database;

[0008] Generate shard keys for the target object corresponding to the multiple shards respectively according to the number of shards;

[0009] Perform inventory allocation processing according to the inventory quantity and the shard quantity to obtain the shard inventory quantities corresponding to the multiple shards respectively, and write the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard;

[0010] receiving an inventory operation request for the target object;

[0011] In response to an inventory operation request for the target object, a request shard key is determined from multiple shard keys, and an inventory operation is performed on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key.

[0012] The present application provides an inventory processing device, comprising:

[0013] A determination module, for determining an inventory quantity of a target object and a shard quantity of a plurality of shards in an inventory database;

[0014] A generation module, used to generate shard keys of the target object corresponding to the multiple shards respectively according to the number of shards;

[0015] A writing module is used to perform inventory allocation processing according to the inventory quantity and the shard quantity, obtain the shard inventory quantities corresponding to the multiple shards respectively, and write the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard;

[0016] A receiving module, configured to receive an inventory operation request for the target object;

[0017] The operation module is used to respond to the inventory operation request for the target object, determine a request shard key from multiple shard keys, and perform inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key.

[0018] The present application provides an electronic device, including:

[0019] A memory for storing executable instructions;

[0020] The processor is used to implement the inventory processing method provided in the present application when executing the executable instructions stored in the memory.

[0021] The present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute and implement the inventory processing method provided by the present application.

[0022] The present application provides a computer program product, which includes executable instructions for causing a processor to execute and implement the inventory processing method provided by the present application.

[0023] This application has the following beneficial effects:

[0024] This application is aimed at the target object that needs to be processed in inventory, determines the inventory quantity of the target object and the number of shards in the inventory database, and generates shard keys corresponding to the target object and the multiple shards according to the number of shards, so that the data of the corresponding shards can be read and written according to the shard keys. At the same time, the inventory allocation processing is performed according to the inventory quantity and the number of shards to obtain the shard inventory quantity corresponding to the multiple shards. For each shard, the shard inventory quantity corresponding to the shard is written into the shard according to the shard key corresponding to the shard, so that the inventory quantity of the target object is apportioned and stored in each shard. When receiving an inventory operation request for the target object, the request shard key is determined from the multiple shard keys, and the inventory operation processing is performed on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key. In this way, the pressure of inventory operation processing is apportioned to multiple shards, rather than being borne by a single shard, to avoid unavailability caused by excessive pressure on a single shard. In summary, this application can effectively improve the stability and efficiency of inventory processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0026] Figure 1 It is a schematic diagram of the architecture of the inventory processing system provided in the embodiment of the present application;

[0027] Figure 2 It is a structural diagram of a server provided in an embodiment of the present application;

[0028] Figure 3A It is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0029] Figure 3B It is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0030] Figure 3C It is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0031] Figure 3D It is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0032] Figure 3E It is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0033] Figure 3FIt is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0034] Figure 3G It is a flowchart of the inventory processing method provided in the embodiment of the present application;

[0035] Figure 4A It is a flowchart of the inventory initialization phase provided by the embodiment of the present application;

[0036] Figure 4B It is a flowchart of the inventory query stage provided by the embodiment of the present application;

[0037] Figure 4C It is a flow chart of the inventory freezing stage provided in the embodiment of the present application;

[0038] Figure 4D It is a flowchart of the inventory deduction stage provided in the embodiment of the present application;

[0039] Figure 4E It is a flow chart of the inventory release phase provided in the embodiment of the present application;

[0040] Figure 5A It is a schematic diagram of the architecture of the inventory processing system provided in the embodiment of the present application;

[0041] Figure 5B is another schematic diagram of the architecture of the inventory processing system provided in an embodiment of the present application;

[0042] Figure 5C It is another architectural diagram of the inventory processing system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0044] In the following description, reference is made to "some embodiments", which describes a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. In the following description, reference is made to the term "multiple" to mean at least two.

[0045] In the following description, the terms "first\second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0047] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0048] 1) Objects: refers to various objects stored for the purpose of supporting production, maintenance, operation or customer service, also known as materials. For example, in an e-commerce scenario, an object can refer to the goods managed by the e-commerce platform.

[0049] In the embodiment of the present application, objects are divided into target objects and non-target objects. The inventory quantity of the target objects needs to be allocated and stored in multiple shards, while the inventory quantity of the non-target objects is centrally stored in a single shard.

[0050] 2) Database: In short, it can be regarded as an electronic file cabinet - a place to store electronic files, where users can add, query, update, delete, etc. The so-called "database" is a collection of data that is stored together in a certain way, can be shared with multiple users, has as little redundancy as possible, and is independent of the application.

[0051] In the embodiment of the present application, the inventory database refers to a database specifically used to store inventory quantities, wherein the type of the inventory database is not limited, and it can be a relational database or a non-relational database.

[0052] 3) Sharding: Split a database into multiple small database instances, each of which is responsible for operating only a portion of the data. These small database instances are called shards (database shards). Storing inventory quantities based on the sharding mechanism can improve overall performance and scalability, reduce database pressure, and improve data security and reliability.

[0053] 4) Key: In an architecture that uses sharding, the shard ID of the shard where the data is located is calculated based on the data key, and then the data is routed to the shard based on the shard ID, thereby realizing data reading and writing. That is, the key is a field used to determine in which shard the data is located. In the embodiments of the present application, it involves an original key and a shard key. The original key is a field used to distinguish different types of objects. For example, it can be an object ID, such as the stock keeping unit (SKU) ID of a product; the target object corresponds to multiple shard keys, and each shard key corresponds to a shard.

[0054] 5) Inventory operation request: refers to a request to operate the inventory quantity. Depending on the operation method, the inventory operation request can be an inventory query request, an inventory freeze request, an inventory deduction request, or an inventory release request.

[0055] 6) In response to: used to indicate the conditions or states on which the executed operations depend. When the dependent conditions or states are met, one or more operations executed may be in real time or have a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations executed are executed.

[0056] The embodiments of the present application provide an inventory processing method, device, electronic device, computer-readable storage medium, and computer program product, which can improve the stability and efficiency of inventory processing. The following describes an exemplary application of the electronic device provided by the embodiments of the present application, and the electronic device provided by the embodiments of the present application can be implemented as a server.

[0057] See also Figure 1 , Figure 1 1 is a schematic diagram of the structure of the inventory processing system 100 provided in the embodiment of the present application. The terminal device 400 is connected to the server 200 through the network 300, and the server 200 is connected to the database 500. The network 300 can be a wide area network or a local area network, or a combination of the two. The database 500 can be independent of the server 200, or it can be deployed inside the server 200. Figure 1 Shown is for illustration purposes only.

[0058] In some embodiments, the inventory processing method provided in the embodiments of the present application can be implemented by a server. For example, the server 200 determines the inventory quantity of the target object and the shard quantity of multiple shards in the database 500 (i.e., the inventory database); generates shard keys corresponding to the target object and multiple shards according to the shard quantity; performs inventory allocation processing according to the inventory quantity and the shard quantity, obtains the shard inventory quantity corresponding to the multiple shards, and writes the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to each shard. When the terminal device 400 needs to operate the inventory quantity of the target object, it sends an inventory operation request for the target object to the server 200, such as sending an inventory operation request for the target object to the server 200 through the client 410. The server 200 receives the inventory operation request for the target object; in response to the inventory operation request for the target object, determines the request shard key from the multiple shard keys, and performs inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key. The server 200 can send the result of the inventory operation processing (such as whether it is successful) to the terminal device 400 so that the user of the terminal device 400 knows.

[0059] In some embodiments, the target object may be a commodity managed by an e-commerce platform, the server 200 may be a server of the e-commerce platform, and the client 410 may be a client of the e-commerce platform (such as an APP).

[0060] In some embodiments, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and basic cloud computing services such as big data and artificial intelligence platforms. The terminal device 400 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, an intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc., but is not limited thereto. The terminal device and the server may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.

[0061] See also Figure 2 , Figure 2 is a schematic diagram of the structure of the server 200 provided in an embodiment of the present application, Figure 2The server 200 shown includes: at least one processor 210, a memory 250 and at least one network interface 220. The various components in the server 200 are coupled together via a bus system 240. It is understood that the bus system 240 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 240 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 240 is not described in detail. Figure 2 Various buses are labeled as bus system 240 .

[0062] The processor 210 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0063] The memory 250 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 250 may optionally include one or more storage devices that are physically remote from the processor 210.

[0064] The memory 250 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 250 described in the embodiment of the present application is intended to include any suitable type of memory.

[0065] In some embodiments, memory 250 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.

[0066] Operating system 251, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;

[0067] A network communication module 252, used to reach other computing devices via one or more (wired or wireless) network interfaces 220, exemplary network interfaces 220 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB);

[0068] In some embodiments, the inventory processing device provided in the embodiments of the present application can be implemented in a software manner. Figure 2 The inventory processing device 255 stored in the memory 250 is shown, which can be software in the form of a program and a plug-in, etc., and includes the following software modules: a determination module 2551, a generation module 2552, a writing module 2553, a receiving module 2554, and an operation module 2555. These modules are logical, and therefore can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.

[0069] The inventory processing method provided in the embodiment of the present application will be described in conjunction with the exemplary application and implementation of the electronic device provided in the embodiment of the present application.

[0070] See also Figure 3A , Figure 3A This is a flow chart of the inventory processing method provided in the embodiment of the present application, which will be combined with Figure 3A The steps shown are explained.

[0071] In step 101, the inventory quantity of the target object and the shard quantity of the plurality of shards in the inventory database are determined.

[0072] Here, for the target object, the inventory quantity of the target object is obtained, such as 30,000; at the same time, the number of shards of all shards divided in the inventory database is determined, such as 10. Among them, under the premise that inventory processing is required for multiple candidate objects, all or part of the multiple candidate objects can be determined as target objects. The inventory database refers to a database specifically used to store inventory quantities. The inventory database can be used only to store the inventory quantity of target objects, and can also be used to store the inventory quantity of non-target objects. Non-target objects refer to candidate objects that are different from target objects.

[0073] The embodiment of the present application does not limit the number of shards of the inventory database. The more shards there are, the stronger the overall performance of the inventory database is. However, the time to respond to an inventory query request may also be longer (because more shards need to be queried). The appropriate number of shards can be set according to the actual application scenario, and the shards can be divided in the inventory database according to the number of shards.

[0074] In some embodiments, before determining the inventory quantity of the target object and the number of shards of multiple shards in the inventory database, the inventory processing method further includes: determining a candidate object that meets a hotspot condition as a target object; wherein the hotspot condition includes at least one of the following: the number of inventory operation requests for the candidate object within a preset time period is greater than or equal to a first quantity threshold; a future inventory change index predicted based on the inventory quantity of the candidate object at multiple historical time points is greater than or equal to an index threshold; a configuration instruction to configure the candidate object as a target object is received; and the inventory quantity of the candidate object is greater than or equal to a second quantity threshold.

[0075] Here, whether a candidate object is a target object can be determined based on preset hotspot conditions, wherein a candidate object may refer to all types of objects that require inventory processing. For example, in an e-commerce scenario, each commodity managed by the e-commerce platform can be a candidate object.

[0076] For example, when a certain candidate object meets the hotspot condition, it proves that there are many inventory operation requests for this candidate object and the processing pressure is large, so the processing pressure needs to be distributed to multiple shards, so this candidate object is determined as the target object; on the contrary, when a certain candidate object does not meet the hotspot condition, it proves that there are few inventory operation requests for this candidate object and the processing pressure is small, so there is no need to distribute the processing pressure to multiple shards, so this candidate object is determined as a non-target object.

[0077] The hotspot condition includes at least one of the following:

[0078] 1) The number of inventory operation requests for the candidate object within a preset time period is greater than or equal to a first quantity threshold. It is understandable that the greater the number of inventory operation requests, the greater the processing pressure, and the more the processing pressure needs to be shared. The preset time period can be set according to actual application scenarios, such as the last ten minutes.

[0079] 2) The future inventory change index predicted based on the inventory quantity of the candidate object at multiple historical time points is greater than or equal to the index threshold. Here, the inventory quantity of the candidate object at multiple historical time points can be obtained, such as the inventory quantity at zero o'clock every day in the past month. Prediction processing is performed based on the inventory quantity of the candidate object at multiple historical time points to obtain a future inventory change index, which is used to represent the frequency of change of the inventory quantity of the candidate object. The higher the future inventory change index, the higher the change frequency, the greater the processing pressure, and the more the processing pressure needs to be shared. It is worth noting that the embodiment of the present application does not limit the method adopted for the above-mentioned prediction processing. For example, a machine learning model can be trained to learn the changing rules of the inventory quantity at different time points during the training process, and the prediction processing is implemented through the trained machine learning model.

[0080] 3) Receive a configuration instruction to configure the candidate object as the target object. Here, manual configuration can also be supported. For example, in an e-commerce scenario, if a certain product is about to participate in an event and will face greater processing pressure, the product can be configured as the target object. This condition is highly flexible and supports free configuration, which can be applied to various scenarios.

[0081] 4) The inventory quantity of the candidate object (referring to the latest inventory quantity) is greater than or equal to the second quantity threshold. Here, the more the inventory quantity of the candidate object is, the greater the processing pressure is, and the more the processing pressure needs to be shared. If the inventory quantity of the candidate object is too small (i.e., less than the second quantity threshold), a single shard can bear the processing pressure, and there is no need to share the processing pressure among multiple shards. In some embodiments, the condition may also be that the available inventory quantity of the candidate object is greater than or equal to the second quantity threshold.

[0082] Through the above method, the target object that needs to share the processing pressure can be screened out from multiple candidate objects through hot spot conditions, so that the processing pressure of the target object can be distributed to multiple shards, which increases the necessity of sharing the processing pressure and helps to improve the stability and efficiency of inventory processing.

[0083] In some embodiments, the inventory database can be a cache database. Relational databases are based on hard disk storage and have poor I / O performance; cache databases are based on memory storage and have better I / O performance and support more queries per second (QPS). Therefore, in an embodiment of the present application, the cache database can be used as an inventory database, which can improve data reading and writing efficiency and achieve fast response. For example, the inventory database can be a Redis cache database.

[0084] In some embodiments, the inventory quantity of the target object determined in step 101 may be an available inventory quantity, that is, an unfrozen inventory quantity.

[0085] In step 102, shard keys corresponding to multiple shards of the target object are generated according to the number of shards.

[0086] On the basis of the determined number of shards, shard keys corresponding to multiple shards of the target object are generated according to the number of shards, and the shard keys are used to route to the corresponding shards. The embodiment of the present application does not limit the generation method of the shard keys. For example, a fixed generation strategy can be used to generate shard keys, wherein the fixed generation strategy refers to a generation strategy that generates the same shard keys for the same target object each time. For example, the shard keys generated by the fixed generation strategy for the first time include 1, 2, 3, and 4, and the shard keys generated by the fixed generation strategy for the second time also include 1, 2, 3, and 4; or, a non-fixed generation strategy can be used to generate shard keys, such as generating random numbers as shard keys.

[0087] In some embodiments, for the same target object, the shard keys corresponding to different shards are different; for different target objects, the shard keys corresponding to the same shard are different. That is, the shard key corresponding to each shard of each target object is unique, which can ensure the independence of the shard key and the accuracy of data reading and writing on each shard.

[0088] In step 103, inventory allocation processing is performed according to the inventory quantity and the shard quantity to obtain the shard inventory quantities corresponding to the multiple shards, and the shard inventory quantity corresponding to each shard is written into the shard according to the shard key corresponding to the shard.

[0089] Here, inventory allocation processing is performed according to the inventory quantity and the number of shards to obtain the shard inventory quantities corresponding to the multiple shards. The inventory allocation processing can adopt average distribution to evenly distribute the processing pressure to each shard. For example, the inventory quantity is 30,000 and the number of shards is 10, then the shard inventory quantity corresponding to each shard is 30,000 / 10=3,000. Of course, this does not constitute a limitation on the embodiments of the present application. For example, random allocation or custom allocation (the user customizes the shard inventory quantity to be stored in each shard) may also be adopted.

[0090] After obtaining the shard inventory quantity corresponding to each shard, for each shard, the shard inventory quantity corresponding to the shard is written into the shard according to the shard key corresponding to the shard, so as to support subsequent read operations (query operations) based on the shard inventory quantity in the shard.

[0091] In some embodiments, the above-mentioned writing of the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard can be achieved in the following way: shard routing processing is performed according to the shard key corresponding to each shard, and the shard inventory quantity corresponding to the shard is written into the routed shard.

[0092] Here, for each shard, shard routing is first performed according to the shard key of the shard. For example, in the Redis cache database, the formula for shard routing is shard ID = CRC16 (shard key) & 16383, that is, the shard key is calculated by CRC16 and then modulo 16383 to obtain the shard ID. Then, the shard inventory quantity corresponding to the shard is written to the routed shard, where the routed shard is the shard corresponding to the calculated shard ID. In this way, the corresponding shard can be determined based on the shard routing process, thereby improving the accuracy of writing.

[0093] In some embodiments, when the number of write failures in writing the shard inventory quantity to the corresponding shard reaches a first number threshold, any one of the following processes is performed: the inventory database is switched from master to slave, and the operation of writing the shard inventory quantity to the corresponding shard is re-executed; the shard inventory quantity is written to the corresponding shard of the backup inventory database.

[0094] Here, when the shard inventory quantity fails to be written, it can be rewritten to try to ensure the success of the write based on the retry mechanism. When the number of write failures reaches the first number threshold, it proves that there is a fault inside the inventory database, so any of the following processing can be performed:

[0095] 1) Under the premise that the inventory database is served by the master node and the slave node, the master-slave switch can be performed, that is, the master node and the slave node exchange their identities. If there are multiple slave nodes, the slave node that needs to be switched to the master node can be elected through the election mechanism. After the master-slave switch is completed, the operation of writing the shard inventory quantity to the corresponding shard is re-executed. In this way, the write failure caused by the failure of the master node can be solved, and the availability of the inventory database can be improved.

[0096] 2) Write the shard inventory quantity to the corresponding shard of the backup inventory database, where the backup inventory database is preset and used as a backup of the inventory database, that is, to provide services when the inventory database is unavailable (here, the number of write failures reaches the first threshold). This method can achieve remote disaster recovery and ensure the successful writing of shard inventory quantities from another perspective.

[0097] In some embodiments, the electronic device includes multiple service nodes; the above-mentioned inventory allocation processing based on the inventory quantity and the shard quantity can be implemented in the following way: notify multiple service nodes, so that any notified service node performs inventory allocation processing based on the inventory quantity and the shard quantity, obtains the shard inventory quantities corresponding to the multiple shards, and writes the shard inventory quantities corresponding to the shards into the shard according to the shard key corresponding to each shard.

[0098] Here, electronic devices can implement inventory processing based on node clusters, and improve processing efficiency and timeliness based on the powerful computing power of node clusters. The node cluster includes multiple service nodes, and each service node can read and write data for each shard in the inventory database. There is no limitation on the type of node cluster, for example, it can be a Kubernetes cluster, and the service node can be a Pod node in the Kubernetes cluster.

[0099] Based on the above premise, when the target object is determined, multiple service nodes can be notified so that any notified service node performs inventory allocation processing according to the inventory quantity and the number of shards, obtains the shard inventory quantities corresponding to multiple shards, and writes the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to each shard. In order to avoid repeated writing of the shard inventory quantity, a distributed lock can be used to ensure that only one service node performs the operation of calculating the shard inventory quantity and writing the shard inventory quantity into the corresponding shard. In this way, the accuracy of writing can be guaranteed.

[0100] In step 104, an inventory operation request for a target object is received.

[0101] Here, when an inventory operation request is received, it is determined whether the inventory operation request is an inventory operation request for a target object.

[0102] In an embodiment of the present application, the inventory operation request may be any one of an inventory query request, an inventory freeze request, an inventory deduction request, and an inventory release request. For example, in an e-commerce scenario, the inventory query request is triggered by the operation of viewing a product, the inventory freeze request is triggered by the operation of placing an order, the inventory deduction request is triggered by the operation of payment, and the inventory release request is triggered by the operation of payment failure or payment abandonment.

[0103] In step 105, in response to an inventory operation request for a target object, a request shard key is determined from a plurality of shard keys, and an inventory operation is performed on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key.

[0104] If the received inventory operation request is an inventory operation request for a target object, then in response to the inventory operation request, the request shard key is determined from the shard keys of multiple shards corresponding to the target object specified by the inventory operation request, and the inventory operation is performed on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key. In this way, the processing pressure can be distributed to different shards, rather than a single shard bearing all the processing pressure, to avoid the situation where a single shard is overloaded with processing pressure, resulting in a crash or response delay.

[0105] It is worth noting that for different types of inventory operation requests, the way to determine the request shard key and the way the inventory operation is processed may be different.

[0106] In some embodiments, the above-mentioned inventory operation processing on the shard inventory quantity in the shard corresponding to the requested shard key according to the requested shard key can be implemented in the following way: shard routing processing is performed according to the requested shard key, and inventory operation processing is performed on the shard inventory quantity in the routed shard.

[0107] Here, the shard routing process can be performed according to the request shard key to obtain the shard identifier. For example, in the Redis cache database, the formula for shard routing process is shard identifier = CRC16 (request shard key) & 16383, that is, the request shard key is calculated by CRC16 and then modulo 16383 to obtain the shard identifier. According to the calculated shard identifier, the corresponding shard can be found, and the inventory operation process can be performed on the shard inventory quantity in the shard. In the above manner, the corresponding shard can be determined based on the shard routing process, thereby improving the accuracy of the inventory operation process.

[0108] In some embodiments, before determining the requested shard key from multiple shard keys, the inventory processing method further includes: performing any one of the following processing: generating shard keys of the target object corresponding to multiple shards according to the number of shards; obtaining the shard keys of the stored target object corresponding to multiple shards.

[0109] Here, in the case where a fixed generation strategy is adopted to generate multiple shard keys in step 102, when an inventory operation request for a target object is received, the fixed generation strategy can also be adopted to generate multiple shard keys, so that there is no need to store the multiple shard keys generated in step 102, saving storage resources; or, the multiple shard keys generated in step 102 can be stored, and when an inventory operation request for a target object is received, the stored multiple shard keys can be obtained.

[0110] In the case where a non-fixed generation strategy is adopted to generate multiple shard keys in step 102, the multiple shard keys generated in step 102 may be stored, and when an inventory operation request for a target object is received, the stored multiple shard keys may be obtained.

[0111] In some embodiments, between any steps, the inventory processing method also includes: determining the inventory quantity of the non-target object and the original key of the non-target object in the inventory database; writing the inventory quantity of the non-target object to the shard corresponding to the original key of the non-target object according to the original key of the non-target object; receiving an inventory operation request for the non-target object; and in response to the inventory operation request for the non-target object, performing inventory operation processing on the inventory quantity of the non-target object in the shard corresponding to the original key of the non-target object according to the original key of the non-target object.

[0112] For non-target objects, the inventory quantity of non-target objects can be directly stored in a single shard. For example, the inventory quantity of non-target objects and the original key of non-target objects in the inventory database are determined, wherein the original key is used to distinguish different types of objects, for example, it can be an object identifier, such as the SKU identifier of a commodity; the inventory quantity of non-target objects is written to the shard corresponding to the original key of the non-target object according to the original key of the non-target object, that is, the shard routing processing is performed according to the original key of the non-target object, and the inventory quantity of non-target objects is written to the routed shard; receive an inventory operation request for the non-target object; in response to the inventory operation request for the non-target object, the inventory quantity of non-target objects in the shard corresponding to the original key of the non-target object is processed according to the original key of the non-target object, that is, the shard routing processing is performed according to the original key of the non-target object, and the inventory quantity of non-target objects in the routed shard is processed. In the above manner, since the inventory operation processing for non-target objects is focused on a single shard without accessing multiple shards, the processing efficiency can be improved; at the same time, it can also ensure that the processing pressure of a single shard will not be too large.

[0113] In some embodiments, the above-mentioned response to the inventory operation request for the target object, determining the requested shard key from multiple shard keys, and performing inventory operation processing on the shard inventory quantity in the shard corresponding to the requested shard key according to the requested shard key can be implemented in the following manner: determining a target service node from multiple service nodes; responding to the inventory operation request for the target object through the target service node, determining the requested shard key from multiple shard keys, and performing inventory operation processing on the shard inventory quantity in the shard corresponding to the requested shard key according to the requested shard key.

[0114] Under the premise that the electronic device implements inventory processing according to the node cluster, when receiving an inventory operation request for a target object, the target service node can be determined from multiple service nodes. For example, based on the principle of load balancing, the service node with the smallest load among multiple service nodes can be determined as the target service node. Then, the target service node responds to the inventory operation request for the target object, determines the request shard key from multiple shard keys, and performs inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key. In this way, with the help of the powerful computing power of the node cluster, the efficiency and success rate of inventory operation processing are improved, which is suitable for scenarios with high concurrency of inventory operation requests.

[0115] like Figure 3AAs shown, the embodiment of the present application determines the inventory quantity of the target object and the number of shards of multiple shards in the inventory database for the target object that needs to be processed in inventory, generates shard keys corresponding to the target object for multiple shards according to the number of shards, and can read and write data of the corresponding shards according to the shard keys. At the same time, the inventory allocation processing is performed according to the inventory quantity and the number of shards to obtain the shard inventory quantity corresponding to the multiple shards. For each shard, the shard inventory quantity corresponding to the shard is written into the shard according to the shard key corresponding to the shard, so that the inventory quantity of the target object is apportioned and stored in each shard. When receiving an inventory operation request for the target object, the request shard key is determined from the multiple shard keys, and the inventory operation processing is performed on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key, and the pressure of the inventory operation processing is apportioned to multiple shards, rather than being borne by a single shard, to avoid the unavailability caused by excessive pressure on a single shard. In summary, the present application can effectively improve the stability and efficiency of inventory processing.

[0116] In some embodiments, see Figure 3B , Figure 3B is a flow chart of the inventory processing method provided in the embodiment of the present application. Figure 3A The illustrated step 105 can be implemented through steps 201 to 202 , which will be described in conjunction with each step.

[0117] In step 201, in response to a stock query request for a target object, multiple shard keys are all determined as request shard keys.

[0118] When the inventory operation request for the target object is an inventory query request, since the inventory query request is used to query the inventory quantity of the target object, the shard keys of multiple shards corresponding to the target object can be used as the request shard key.

[0119] In step 202, the shard inventory quantity in the shard corresponding to each requested shard key is queried, and the queried multiple shard inventory quantities are aggregated.

[0120] For example, shard routing is performed according to each request shard key, and the shard inventory quantity in the routed shard is queried, and then all the queried shard inventory quantities are aggregated (added) to obtain the latest inventory quantity of the target object. The latest inventory quantity can be sent to the requester of the inventory query request.

[0121] In some embodiments, the shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; the above-mentioned querying the shard inventory quantity in the shard corresponding to each requested shard key according to the requested shard key, and aggregating the queried multiple shard inventory quantities can be implemented in the following manner: querying the available shard inventory quantity in the shard corresponding to the requested shard key according to each requested shard key, and aggregating the queried multiple available shard inventory quantities.

[0122] Here, the inventory quantity includes the available inventory quantity and the frozen inventory quantity, that is, the inventory quantity = the available inventory quantity + the frozen inventory quantity, wherein the available inventory quantity is in an unfrozen state, which can be called the purchase quantity or the sale quantity in the e-commerce scenario; and the frozen inventory quantity is in a frozen state, which can refer to the quantity frozen due to the user's order in the e-commerce scenario. Similarly, for each shard, the stored shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity.

[0123] In this case, the inventory query request is usually used to query the available inventory quantity, for example, in an e-commerce scenario, a user wants to query the available purchase quantity of a certain product. Therefore, the available shard inventory quantity in the shard corresponding to each request shard key can be queried, and the multiple available shard inventory quantities queried can be aggregated to obtain the latest available inventory quantity of the target object. The latest available inventory quantity can be sent to the requester of the inventory query request, so that the requester can initiate an inventory freeze request for part or all of the latest available inventory quantity.

[0124] like Figure 3B As shown, since the inventory quantity of the target object is allocated and stored in multiple shards, when the embodiment of the present application receives an inventory query request for the target object, multiple shard keys are determined as request shard keys, and the shard inventory quantity in the shard corresponding to the request shard key is queried according to each request shard key, and the queried multiple shard inventory quantities are aggregated to obtain the latest inventory quantity of the target object, which can ensure the accuracy of the calculated latest inventory quantity.

[0125] In some embodiments, see Figure 3C , Figure 3C is a flow chart of the inventory processing method provided in the embodiment of the present application. Figure 3A The illustrated step 105 can be implemented through steps 301 to 302 , which will be described in conjunction with each step.

[0126] In step 301, in response to a request for freezing inventory of a target object, a shard key corresponding to a shard whose available shard inventory quantity is greater than zero is determined as a requested shard key.

[0127] Here, the shard inventory quantity recorded in each shard includes the available shard inventory quantity and the frozen shard inventory quantity. The shard can only support freezing when the available shard inventory quantity of the shard is greater than zero. Therefore, when receiving an inventory freezing request for a target object, at least one shard key whose available shard inventory quantity of the corresponding shard is greater than zero is first determined, and then some or all of the shard keys in the at least one shard key are determined as the requested shard keys.

[0128] The inventory freeze request includes a serial number and a requested freeze quantity. The serial number is used to identify the inventory freeze request, and the requested freeze quantity indicates the available inventory quantity that needs to be reduced for the target object or the frozen inventory quantity that needs to be increased for the target object. Taking the e-commerce scenario as an example, the order number when the user places an order is the serial number, and the quantity of goods purchased by the user is the requested freeze quantity.

[0129] In some embodiments, after writing the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard, the inventory processing method further includes: adding the shard key of each shard and the exhaustion status of the shard to the first record table; wherein the exhaustion status is used to indicate whether the available shard inventory quantity is greater than zero; the above-mentioned determination of the shard key with the available shard inventory quantity greater than zero of the corresponding shard as the requested shard key can be achieved in the following manner: according to the exhaustion status of each shard in the first record table, determine the shard key with the available shard inventory quantity greater than zero as the requested shard key.

[0130] Here, for each shard, the shard key of the shard and the exhaustion status of the shard can be added to the first record table, such as in the form of key values. The exhaustion status is used to indicate whether the available shard inventory quantity is greater than zero. If the available shard inventory quantity is greater than zero, the exhaustion status is not exhausted; if the available shard inventory quantity is equal to zero, the exhaustion status is exhausted. The exhaustion status can be represented by a numerical value, for example, a numerical value of 0 indicates exhaustion, and a numerical value of 1 indicates not exhausted.

[0131] When the request shard key needs to be determined, the shard key whose available shard inventory quantity is greater than zero (i.e., the exhaustion status is not exhausted) can be determined as the request shard key according to the exhaustion status of each shard in the first record table. The above method can quickly determine the request shard key by reading the first record table, which can improve the efficiency of determining the request shard key.

[0132] In some embodiments, the first record table is used to store in the configuration center; after adding the shard key of each shard and the exhaustion status of the shard to the first record table, the inventory processing method further includes: notifying multiple service nodes; wherein each service node, when notified, obtains the first record table from the configuration center and stores it in the local cache; when the number of notification failures for any service node reaches a second number threshold, the first record table is obtained from the configuration center by polling through any service node, and the first record table is stored in the local cache; according to the exhaustion status of each shard in the first record table, before determining the shard key with an available shard inventory quantity greater than zero as the requested shard key, the inventory processing method further includes: obtaining the first record table from the local cache through the target service node; wherein the target service node represents a service node among the multiple service nodes for responding to the inventory freeze request.

[0133] Here, when the electronic device implements inventory processing based on a node cluster, the first record table can be stored in a dedicated configuration center, and each service node of the node cluster is notified to obtain the first record table from the configuration center and store it in a local cache. The type of the configuration center is not limited, for example, it can be an etcd distributed configuration center.

[0134] During the notification process, the notification may fail due to network communication or node restart. When the notification to a service node fails, the service node is notified again until the number of notification failures for the service node reaches the second threshold (such as 3 times). That is, when the number of notification failures for a service node reaches the second threshold, the notification to the service node is abandoned, and the first record table is obtained from the configuration center in a polling manner through the service node, and the first record table is stored in the local cache. It is worth noting that the polling method refers to the periodic execution of specific operations according to a specific time interval, for example, the service node obtains the first record table from the configuration center every 10 seconds and stores it in the local cache. In this way, it can be ensured as much as possible that the first record table is stored in the local cache of each service node.

[0135] When receiving an inventory freeze request for a target object, first determine a target service node for responding to the inventory freeze request from multiple service nodes, for example, based on the principle of load balancing, and then obtain the first record table from the local cache through the target service node to determine the request sharding key according to the obtained first record table. Since the efficiency of reading and writing data to the local cache is high, the first record table can be quickly obtained through the above method, further improving the efficiency of determining the request sharding key.

[0136] In some embodiments, when the first record table is not obtained from the local cache through the target service node, the first record table is obtained from the configuration center through the target service node.

[0137] Here, the target service node may not store the first record table in the local cache due to reasons such as restart or failure. In this case, the first record table is obtained from the configuration center through the target service node.

[0138] In some embodiments, the first record table is used to store in the configuration center; after writing the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard, the inventory processing method further includes: when all shard inventory quantities are written successfully, adding the successfully written record to the log; according to the exhaustion status of each shard in the first record table, before determining the shard key with an available shard inventory quantity greater than zero as the requested shard key, the inventory processing method further includes: when a successfully written record is obtained from the log, obtaining the first record table from the configuration center; when a successfully written record is not obtained from the log, obtaining the first record table from the configuration center by polling.

[0139] Here, when all shard inventory quantities of the target object are written successfully, the successfully written record can be added to the log, wherein the log can be stored in a specific database such as a relational database. In this way, it is possible to determine whether there is a first record table in the configuration center based on whether the log includes a successfully written record. For example, when a successfully written record is obtained from the log, the first record table is immediately obtained from the configuration center; when a successfully written record is not obtained from the log, the first record table is obtained from the configuration center by polling. The above method combines the log mechanism and the polling mechanism to take into account both the timeliness and success rate of obtaining the first record table.

[0140] The above method can also be applied to node cluster scenarios. For example, in order to avoid the failure of the local cache to store the first record table in time due to the downtime of the service node or the addition of a new service node, when the service node is started, the service node can be used to determine whether the successfully written record can be obtained from the log. When the successfully written record is obtained from the log, the first record table is immediately obtained from the configuration center and stored in the local cache; when the successfully written record is not obtained from the log, the first record table is obtained from the configuration center by polling and stored in the local cache. In this way, it is ensured that the local cache of the service node can store the first record table in time.

[0141] In some embodiments, the above-mentioned determination of a shard key whose available shard inventory quantity of the corresponding shard is greater than zero as a requested shard key can be achieved in the following manner: a shard key whose available shard inventory quantity of the corresponding shard is greater than zero is determined as a candidate shard key; when there are multiple candidate shard keys, the multiple candidate shard keys are selected and processed at least once to obtain at least one requested shard key, until the sum of the available shard inventory quantities in the shards indicated by all the requested shard keys in the at least one requested shard key is not less than the requested frozen quantity.

[0142] Here, the shard key whose available shard inventory quantity of the corresponding shard is greater than zero is determined as a candidate shard key, and the number of candidate shard keys may be one or more. When the number of candidate shard keys is one, the candidate shard key is determined as the requested shard key; when the number of candidate shard keys is multiple, multiple candidate shard keys are selected at least once to obtain at least one requested shard key, until the sum of the available shard inventory quantities in the shards indicated by all requested shard keys in at least one requested shard key is not less than the requested frozen quantity, wherein the selection process may be random selection or selection in a specific order. Through the above method, it is ensured that the number of determined requested shard keys is as small as possible, thereby minimizing the number of shards that need to be accessed, and improving processing efficiency.

[0143] In step 302, the following processing is performed according to the requested shard key: according to the requested freezing quantity in the inventory freezing request, the available shard inventory quantity in the shard corresponding to the requested shard key is reduced, and the frozen shard inventory quantity in the shard corresponding to the requested shard key is increased.

[0144] Here, when there is only one requested shard key, the requested frozen quantity is used as the shard frozen quantity corresponding to the requested shard key, and the available shard inventory quantity in the shard corresponding to the requested shard key is subtracted from the shard frozen quantity corresponding to the requested shard key to obtain the new available shard inventory quantity in the shard corresponding to the requested shard key. At the same time, the frozen shard inventory quantity in the shard corresponding to the requested shard key is added to the shard frozen quantity corresponding to the requested shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the requested shard key. For example, if the requested frozen quantity is 1000, the available shard inventory quantity in the shard corresponding to the requested shard key is 2000, and the frozen shard inventory quantity in the shard corresponding to the requested shard key is 1000, then the available shard inventory quantity is subtracted from the shard frozen quantity to obtain the new available shard inventory quantity, that is, the new available shard inventory quantity is 2000-1000=1000. At the same time, the frozen shard inventory quantity is added to the shard frozen quantity to obtain the new frozen shard inventory quantity, that is, the new frozen shard inventory quantity is 1000+1000=2000.

[0145] When the number of requested shard keys is multiple, the number of shard frozen corresponding to each requested shard key is calculated according to the requested frozen number, wherein the number of shard frozen corresponding to each requested shard key is less than or equal to the number of available shard inventory in the shard corresponding to the requested shard key, and the sum of the number of shard frozen corresponding to all requested shard keys is equal to the requested frozen number. For example, if the number of requested frozen is 1000, the number of available shard inventory in the shard corresponding to requested shard key 1 is 800, and the number of available shard inventory in the shard corresponding to requested shard key 2 is 400, then the number of shard frozen corresponding to requested shard key 1 can be 800, and the number of shard frozen corresponding to requested shard key 2 can be 200. Of course, this is only a calculation result and does not constitute a limitation on the embodiments of the present application. For example, another calculation result can be: the number of shard frozen corresponding to requested shard key 1 is 700, and the number of shard frozen corresponding to requested shard key 2 is 300. After determining the shard frozen quantity corresponding to each requested shard key, subtract the shard frozen quantity corresponding to the requested shard key from the available shard inventory quantity in the shard corresponding to the requested shard key to obtain the new available shard inventory quantity in the shard corresponding to the requested shard key. At the same time, add the frozen shard inventory quantity in the shard corresponding to the requested shard key to the frozen shard inventory quantity in the shard corresponding to the requested shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the requested shard key.

[0146] It is worth noting that, in the case where the first record table exists, if after step 202, the available shard inventory quantity in the shard corresponding to the requested shard key is reduced to zero, then the out-of-stock status of the shard corresponding to the requested shard key in the first record table is updated to out-of-stock.

[0147] exist Figure 3C In step 303, after step 302, a freezing serial record may be generated according to the serial number, the requested freezing quantity, and the requested shard key in the inventory freezing request; wherein the freezing serial record is used to respond to the inventory deduction request or the inventory release request for the target object.

[0148] Since the inventory freeze request is associated with the inventory deduction request or the inventory release request, a freeze log record is generated according to the serial number in the inventory freeze request, the requested freeze quantity in the inventory freeze request, and the request shard key, so that the inventory quantity can be deducted or released later according to the freeze log record. It is worth noting that the storage method of the freeze log record can refer to the first record table or log mentioned above, and is not limited to this.

[0149] In some embodiments, when the number of requested shard keys is multiple, after step 302, the inventory processing method further includes: generating a freezing log record according to the serial number in the inventory freezing request, multiple requested shard keys, and the shard freezing quantity corresponding to each requested shard key. In this way, the information granularity in the freezing log record is finer, that is, the shard freezing quantity corresponding to each requested shard key is stored, so that the shard freezing quantity corresponding to each requested shard key can be deducted or released in the corresponding shard later, thereby improving orderliness.

[0150] like Figure 3C As shown, the embodiment of the present application can accurately freeze the inventory quantity of the target object according to the requested freezing quantity in the inventory freezing request, that is, reduce the available shard inventory quantity in the shard corresponding to the requested shard key, and increase the frozen shard inventory quantity in the shard corresponding to the requested shard key; at the same time, generate a freezing serial record according to the serial number, the requested freezing quantity, and the requested shard key in the inventory freezing request, so as to respond to the inventory deduction request or the inventory release request according to the freezing serial record.

[0151] In some embodiments, see Figure 3D , Figure 3D is a flow chart of the inventory processing method provided in the embodiment of the present application. Figure 3A The illustrated step 105 can be implemented through steps 401 to 402 , which will be described in conjunction with each step.

[0152] In step 401, in response to an inventory deduction request for a target object, the serial number in the inventory deduction request is matched with the serial numbers in all frozen serial records, and the successfully matched frozen serial record is determined as the target frozen serial record; wherein the frozen serial record includes the serial number, the requested freezing quantity, and the requested shard key.

[0153] Here, when the received inventory operation request for the target object is an inventory deduction request, all stored frozen serial records are obtained, and the serial number in the inventory deduction request is matched with the serial number in all frozen serial records, and the frozen serial record that is successfully matched (i.e., the serial number is the same) is determined as the target frozen serial record, wherein each frozen serial record includes the serial number, the requested freezing quantity, and the requested shard key.

[0154] Taking the e-commerce scenario as an example, the inventory freeze request corresponds to the user's order placement operation, and the inventory deduction request corresponds to the user's payment operation after placing an order. Therefore, the freezing serial number record generated by the inventory freeze request can be found according to the serial number in the inventory deduction request.

[0155] In step 402, the following processing is performed according to the requested shard key in the target frozen transaction record: according to the requested frozen quantity in the target frozen transaction record, the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen transaction record is reduced.

[0156] Here, when there is only one requested shard key in the target frozen flow record, the requested frozen quantity in the target frozen flow record is used as the shard deduction quantity corresponding to the requested shard key, and the frozen shard inventory quantity in the shard corresponding to the requested shard key is subtracted from the shard deduction quantity corresponding to the requested shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the requested shard key. For example, if the requested frozen quantity in the target frozen flow record is 1000, and the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen flow record is 2000, then the frozen shard inventory quantity is subtracted from the shard deduction quantity to obtain the new frozen shard inventory quantity, that is, the new frozen shard inventory quantity is 2000-1000=1000.

[0157] When there are multiple requested shard keys in the target frozen flow record, the shard deduction quantity corresponding to each requested shard key is calculated according to the requested frozen quantity in the target frozen flow record, wherein the shard deduction quantity corresponding to each requested shard key is less than or equal to the frozen shard inventory quantity in the shard corresponding to the requested shard key, and the sum of the shard deduction quantities corresponding to all requested shard keys is equal to the requested frozen quantity. For example, if the requested frozen quantity is 1000, the frozen shard inventory quantity in the shard corresponding to the requested shard key 1 is 800, and the frozen shard inventory quantity in the shard corresponding to the requested shard key 2 is 400, then the shard deduction quantity corresponding to the requested shard key 1 can be 800, and the shard deduction quantity corresponding to the requested shard key 2 can be 200. Of course, this is only a calculation result and does not constitute a limitation on the embodiments of the present application. For example, another calculation result can be: the shard deduction quantity corresponding to the requested shard key 1 is 700, and the shard deduction quantity corresponding to the requested shard key 2 is 300. After determining the shard deduction quantity corresponding to each requested shard key, subtract the shard deduction quantity corresponding to the requested shard key from the frozen shard inventory quantity in the shard corresponding to the requested shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the requested shard key.

[0158] In some embodiments, when the target frozen transaction record includes multiple request shard keys and the frozen quantity of shards corresponding to each request shard key, after step 401, it also includes: performing the following processing according to the target request shard key in the target frozen transaction record: according to the frozen quantity of shards corresponding to the target request shard key in the target frozen transaction record, reducing the frozen shard inventory quantity in the shard corresponding to the target request shard key; wherein the target request shard key represents any one of the multiple request shard keys.

[0159] Here, when the determined target freezing flow record includes multiple request shard keys and the shard frozen quantity corresponding to each request shard key, since the shard frozen quantity corresponding to each request shard key has been determined, the inventory deduction can be performed according to the shard frozen quantity. For example, taking any request shard key of the target freezing flow record, that is, the target request shard key, as an example, the shard frozen quantity corresponding to the target request shard key is used as the shard deduction quantity, and the frozen shard inventory quantity in the shard corresponding to the target request shard key is subtracted from the shard deduction quantity corresponding to the target request shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the target request shard key. Through the above method, the quantity consistency of each shard during inventory freezing and inventory deduction can be guaranteed, and the orderliness of the operation is improved.

[0160] like Figure 3D As shown, when an inventory deduction request for a target object is received in the embodiment of the present application, since the inventory deduction request is a subsequent step of the inventory freezing request, a target frozen transaction record is determined among all frozen transaction records generated historically (each frozen transaction record is generated based on an inventory freezing request), and the frozen shard inventory quantity in the corresponding shard is reduced according to the target frozen transaction record, thereby improving the correlation between inventory freezing and inventory deduction and the accuracy of inventory deduction.

[0161] In some embodiments, see Figure 3E , Figure 3E is a flow chart of the inventory processing method provided in the embodiment of the present application. Figure 3A The illustrated step 105 can be implemented through steps 501 to 502 , which will be described in conjunction with each step.

[0162] In step 501, in response to an inventory release request for a target object, the serial number in the inventory release request is matched with the serial numbers in all frozen serial records, and the successfully matched frozen serial record is determined as the target frozen serial record; wherein the frozen serial record includes the serial number, the requested freezing quantity, and the requested shard key.

[0163] Here, when the received inventory operation request for the target object is an inventory release request, all stored frozen serial records are obtained, and the serial number in the inventory release request is matched with the serial number in all frozen serial records, and the frozen serial record that is successfully matched (i.e., the serial number is the same) is determined as the target frozen serial record, wherein each frozen serial record includes the serial number, the requested freezing quantity, and the requested shard key.

[0164] Taking the e-commerce scenario as an example, the inventory freeze request corresponds to the operation of the user placing an order, and the inventory release request corresponds to the operation of the user giving up payment or payment timeout after placing an order. Therefore, the freezing serial number generated by the inventory freeze request can be found according to the serial number in the inventory release request.

[0165] In step 502, the following processing is performed according to the requested shard key in the target frozen water flow record: according to the requested freezing quantity in the target frozen water flow record, the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen water flow record is reduced, and the available shard inventory quantity in the shard corresponding to the requested shard key in the target frozen water flow record is increased.

[0166] Here, when there is only one requested shard key in the target frozen flow record, the requested frozen quantity in the target frozen flow record is used as the shard release quantity corresponding to the requested shard key, the frozen shard inventory quantity in the shard corresponding to the requested shard key is subtracted from the shard release quantity corresponding to the requested shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the requested shard key, the available shard inventory quantity in the shard corresponding to the requested shard key is added to the shard release quantity corresponding to the requested shard key to obtain the new available shard inventory quantity in the shard corresponding to the requested shard key. For example, if the requested freezing quantity in the target freezing log is 1000, the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target freezing log is 2000, and the available shard inventory quantity in the shard corresponding to the requested shard key in the target freezing log is 1000, then the frozen shard inventory quantity is subtracted from the shard release quantity to obtain the new frozen shard inventory quantity, that is, the new frozen shard inventory quantity is 2000-1000=1000, and the available shard inventory quantity is added to the shard release quantity to obtain the new available shard inventory quantity, that is, the new available shard inventory quantity is 1000+1000=2000.

[0167] When there are multiple requested shard keys in the target frozen flow record, the number of shard releases corresponding to each requested shard key is calculated according to the number of requested freezes in the target frozen flow record, wherein the number of shard releases corresponding to each requested shard key is less than or equal to the number of frozen shard stocks in the shard corresponding to the requested shard key, and the sum of the number of shard releases corresponding to all requested shard keys is equal to the number of requested freezes. For example, if the number of requested freezes is 1000, the number of frozen shard stocks in the shard corresponding to requested shard key 1 is 800, and the number of frozen shard stocks in the shard corresponding to requested shard key 2 is 400, then the number of shard releases corresponding to requested shard key 1 can be 800, and the number of shard releases corresponding to requested shard key 2 can be 200. Of course, this is only a calculation result and does not constitute a limitation on the embodiments of the present application. For example, another calculation result can be: the number of shard releases corresponding to requested shard key 1 is 700, and the number of shard releases corresponding to requested shard key 2 is 300. After determining the number of shard releases corresponding to each requested shard key, subtract the number of shard releases corresponding to the requested shard key from the number of frozen shard inventory in the shard corresponding to the requested shard key to obtain the new number of frozen shard inventory in the shard corresponding to the requested shard key, and add the number of shard releases corresponding to the requested shard key to the number of available shard inventory in the shard corresponding to the requested shard key to obtain the new number of available shard inventory in the shard corresponding to the requested shard key.

[0168] In some embodiments, when the target frozen transaction record includes multiple request shard keys and the number of frozen shards corresponding to each request shard key, after step 501, it also includes: performing the following processing according to the target request shard key in the target frozen transaction record: according to the number of frozen shards corresponding to the target request shard key in the target frozen transaction record, reducing the number of frozen shard inventory in the shard corresponding to the target request shard key, and increasing the number of available shard inventory in the shard corresponding to the target request shard key; wherein the target request shard key represents any one of the multiple request shard keys.

[0169] Here, when the determined target freezing flow record includes multiple request shard keys and the shard freezing quantity corresponding to each request shard key, since the shard freezing quantity corresponding to each request shard key has been determined, the inventory can be released according to the shard freezing quantity. For example, taking any request shard key of the target freezing flow record, that is, the target request shard key, as an example, the shard freezing quantity corresponding to the target request shard key is used as the shard release quantity, the frozen shard inventory quantity in the shard corresponding to the target request shard key is subtracted from the shard release quantity corresponding to the target request shard key to obtain the new frozen shard inventory quantity in the shard corresponding to the target request shard key, and the available shard inventory quantity in the shard corresponding to the target request shard key is added to the shard release quantity corresponding to the target request shard key to obtain the new available shard inventory quantity in the shard corresponding to the target request shard key. Through the above method, the quantity consistency of each shard during inventory freezing and inventory release can be guaranteed, and the orderliness of operation can be improved.

[0170] like Figure 3E As shown, when an inventory release request for a target object is received in the embodiment of the present application, since the inventory release request is a subsequent step of the inventory freezing request, a target frozen transaction record is determined in all frozen transaction records generated historically (each frozen transaction record is generated based on an inventory freezing request), and the frozen shard inventory quantity in the corresponding shard is reduced and the available shard inventory quantity in the corresponding shard is increased according to the target frozen transaction record, thereby improving the correlation between inventory freezing and inventory release and the accuracy of inventory release.

[0171] In some embodiments, see Figure 3F , Figure 3F is a flow chart of the inventory processing method provided in the embodiment of the present application. Figure 3A The illustrated step 102 can be implemented through steps 601 to 603 , which will be described in conjunction with each step.

[0172] In step 601, the original key of the target object in the inventory database is determined.

[0173] Here, the original key refers to the field that distinguishes different types of objects, for example, it can be the object identifier of an object, such as the SKU identifier of a product in an e-commerce scenario. Since the original key can distinguish different types of objects, that is, the original key corresponding to each object is unique, an additional key corresponding to each shard can be added to the original key of the target object (different additional keys correspond to different shards), so that the shard key corresponding to each shard of each target object is unique.

[0174] In step 602, additional keys corresponding to multiple shards are generated according to the number of shards.

[0175] Here, different shards correspond to different additional keys, and the additional keys are used for shard routing processing to route to the corresponding shards. The additional keys can be preset or generated using a fixed generation strategy.

[0176] In some embodiments, the above-mentioned generation of additional keys corresponding to multiple shards according to the number of shards can be achieved by performing any of the following processing: generating multiple numerical values ​​in a preset numerical order that match the number of shards, and determining each numerical value as an additional key; splitting the storage range array of the inventory database according to the number of shards to obtain multiple sub-arrays that match the number of shards, and determining the numerical value at a preset position in each sub-array as an additional key.

[0177] There are two fixed generation strategies provided here:

[0178] 1) Generate multiple values ​​that match the number of shards according to a preset value sequence, and determine each value as an additional key. For example, if the preset value sequence is to generate integers starting from 0 and the number of shards is 2, then the additional key includes two values, 0 and 1, where 0 corresponds to one shard and 1 corresponds to another shard.

[0179] 2) Split the storage range array of the inventory database according to the number of shards to obtain multiple sub-arrays that match the number of shards, and determine the value at the preset position in each sub-array as an additional key. The storage range array refers to an array obtained by numbering the basic units for storing data in the inventory database. For example, if the inventory database is a Redis cache database, the basic unit for storing data in the Redis cache database is a hash slot (or slot), with a total of 16384 hash slots, and the storage range array is [0, 1, 2, 3...16383]. The preset position can be any position in the sub-array, such as the position of the first value or the position of the last value. Taking the inventory database as a Redis cache database, the number of shards is 2, and the preset position is the position of the last value as an example, the storage range array [0, 1, 2, 3...16383] is first split into two sub-arrays, namely [0, 1, 2, 3...8173] and [8174, 8175...16383], and then the last value 8173 in the sub-array [0, 1, 2, 3...8173] is determined as an additional key, and the last value 16383 in the sub-array [8174, 8175...16383] is determined as another additional key.

[0180] The above fixed generation strategies 1) and 2) improve the flexibility of generating additional keys, and any of the above fixed generation strategies can be selected according to the needs of the actual application scenario. It is worth noting that compared with the fixed generation strategy 1), the difference between different additional keys generated by the fixed generation strategy 2) is greater, so the collision probability is smaller.

[0181] In step 603, the additional key corresponding to each shard is added to the original key of the target object to obtain the shard key of the target object corresponding to the shard.

[0182] On the basis of the original key of the target object and the additional key corresponding to each shard, the additional key corresponding to each shard is added to the original key of the target object to obtain the shard key of the target object corresponding to the shard. The additional key can be added as a prefix or suffix of the original key. For example, if the original key of the target object is skuid1 and the additional key is 0, the generated shard key is {0}:skuid1. The curly brackets {} are used to indicate the position of the additional key.

[0183] exist Figure 3F middle, Figure 3A The illustrated step 103 may be updated to step 604. In step 604, inventory allocation processing is performed according to the inventory quantity and the shard quantity to obtain shard inventory quantities corresponding to the multiple shards, shard routing processing is performed according to the additional key in the shard key corresponding to each shard, and the shard inventory quantity corresponding to the shard is written into the routed shard.

[0184] After obtaining the shard inventory quantities corresponding to multiple shards, for each shard, shard routing is performed according to the additional key in the shard key of the target object corresponding to the shard, and the shard inventory quantity corresponding to the shard is written to the routed shard. In this way, the operation of writing the shard inventory quantity can be performed on the correct shard.

[0185] exist Figure 3F middle, Figure 3A The illustrated step 105 may be updated to step 605. In step 605, in response to an inventory operation request for a target object, a request shard key is determined from a plurality of shard keys, shard routing processing is performed according to an additional key in the request shard key, and inventory operation processing is performed on the shard inventory quantity in the routed shard.

[0186] Corresponding to the written shard inventory quantity, after the requested shard key is determined, shard routing processing is performed according to the additional key in the requested shard key, and inventory operation processing is performed on the shard inventory quantity in the routed shard, so that inventory operation processing can be performed on the correct shard.

[0187] In some embodiments, the above-mentioned writing of the shard inventory quantity corresponding to the shard into the routed shard can be achieved in the following manner: the original key of the target object and the shard inventory quantity corresponding to the shard are written into the routed shard in the form of key value; the above-mentioned inventory operation processing on the shard inventory quantity in the routed shard can be achieved in the following manner: according to the original key in the requested shard key, the shard inventory quantity in the routed shard is queried, and the inventory operation processing is performed on the queried shard inventory quantity.

[0188] Since a shard may need to read and write data for multiple target objects at the same time, or need to read and write data for target objects and non-target objects at the same time, for each shard, shard routing processing can be performed according to the additional key in the shard key of the shard corresponding to the target object, and the original key of the target object (which can be obtained from the shard key or determined by other means) and the shard inventory quantity corresponding to the shard are written to the routed shard in the form of key value. For example, the data structure written to the shard can be "key: original key; value: shard inventory quantity". In this way, the shard inventory quantity in the routed shard can be queried according to the original key in the requested shard key, and the queried shard inventory quantity can be processed for inventory operation to ensure the accuracy of the shard inventory quantity targeted by the inventory operation.

[0189] In some embodiments, when the shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity, the above data structure can be updated to "key: original key; value: shard inventory quantity, available shard inventory quantity" (the frozen inventory quantity can be calculated based on the shard inventory quantity and the available shard inventory quantity, and the same applies below), "key: original key; value: shard inventory quantity, frozen shard inventory quantity", "key: original key; value: frozen shard inventory quantity, available shard inventory quantity" or "key: original key; value: shard inventory quantity, frozen shard inventory quantity, available shard inventory quantity".

[0190] In some embodiments, between any steps, the inventory processing method also includes: determining the inventory quantity of a non-target object and the original key of the non-target object in the inventory database; performing shard routing processing according to the original key of the non-target object, and writing the original key of the non-target object and the inventory quantity of the non-target object into the routed shard in the form of key value; receiving an inventory operation request for the non-target object; in response to the inventory operation request for the non-target object, performing shard routing processing according to the original key of the non-target object, querying the inventory quantity of the non-target object in the routed shard according to the original key of the non-target object, and performing inventory operation processing on the queried inventory quantity of the non-target object.

[0191] Here, for non-target objects, since the inventory quantity of non-target objects is only stored in a single shard, there is no need to add an additional key to the original key of the non-target object. Instead, shard routing is performed directly according to the original key of the non-target object, and the original key of the non-target object and the inventory quantity of the non-target object are written to the routed shard in the form of key value, that is, the written data structure is "key: original key; value: inventory quantity". In this way, when an inventory operation request for a non-target object is received, shard routing is performed according to the original key of the non-target object, the inventory quantity of the non-target object in the routed shard is queried according to the original key of the non-target object, and the inventory operation is performed on the queried inventory quantity of the non-target object, so as to ensure the accuracy of the inventory quantity of the non-target object targeted by the inventory operation.

[0192] like Figure 3F As shown, the embodiment of the present application adds an additional key corresponding to each shard to the original key of the target object to obtain the shard key of the target object corresponding to each shard, thereby ensuring that the shard keys of different shards corresponding to the same target object are different, and that the shard keys of different target objects corresponding to the same shard are different, that is, ensuring the independence of the shard keys; at the same time, data is read and written according to the additional key in the shard key, ensuring that the processing pressure can be successfully distributed to multiple shards, thereby improving the accuracy of data reading and writing.

[0193] In some embodiments, see Figure 3G , Figure 3G is a flow chart of the inventory processing method provided in the embodiment of the present application. Figure 3A Before step 104 shown, in step 701, the object identifier of the target object may be added to the second record table.

[0194] Here, for each target object, the object identifier of the target object may be added to the second record table.

[0195] In some embodiments, the object identification may serve as the raw key.

[0196] exist Figure 3G middle, Figure 3A The illustrated step 104 may be implemented through steps 702 to 704. In step 702, an inventory operation request is received.

[0197] Here, the received inventory operation request includes an object identifier.

[0198] In step 703, the object identifier in the inventory operation request is matched with the object identifier in the second record table.

[0199] Here, the object identifier in the inventory operation request is matched with each object identifier in the second record table.

[0200] In some embodiments, the second record table is used to be stored in the configuration center; after the object identifier of the target object is added to the second record table, the inventory processing method further includes: notifying multiple service nodes; wherein each service node, when notified, obtains the second record table from the configuration center and stores it in the local cache; when the number of notification failures for any service node reaches a second number threshold, the second record table is obtained from the configuration center by polling through any service node, and the second record table is stored in the local cache; before matching the object identifier in the inventory operation request with the object identifier in the second record table, the inventory processing method further includes: obtaining the second record table from the local cache through the target service node; wherein the target service node represents a service node among the multiple service nodes for responding to the inventory operation request.

[0201] Here, when the electronic device implements inventory processing based on a node cluster, the second record table can be stored in a dedicated configuration center, and each service node of the node cluster can be notified to obtain the second record table from the configuration center and store it in a local cache.

[0202] During the notification process, the notification may fail due to network communication or node restart. When the notification fails for a service node, the service node is notified again until the number of notification failures for the service node reaches the second threshold (such as 3 times). That is, when the number of notification failures for a service node reaches the second threshold, the notification of the service node is abandoned, and the second record table is obtained from the configuration center in a polling manner through the service node, and the second record table is stored in the local cache. In this way, it can be ensured as much as possible that the first record table is stored in the local cache of each service node.

[0203] When an inventory operation request is received, a target service node for responding to the inventory freeze request is first determined from multiple service nodes, for example, based on the principle of load balancing, and then the second record table is obtained from the local cache through the target service node to match the object identifier in the inventory operation request with the object identifier in the second record table. Since the efficiency of reading and writing data to the local cache is high, the second record table can be quickly obtained in the above manner, and then it can be quickly determined whether the received inventory operation request is an inventory operation request for the target object.

[0204] In some embodiments, when the second record table is not obtained from the local cache through the target service node, the second record table is obtained from the configuration center through the target service node.

[0205] In some embodiments, the second record table is used to store in the configuration center; after writing the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard, the inventory processing method further includes: when all shard inventory quantities are written successfully, adding the successfully written record to the log; before matching the object identifier in the inventory operation request with the object identifier in the second record table, the inventory processing method further includes: when a successfully written record is obtained from the log, obtaining the second record table from the configuration center; when a successfully written record is not obtained from the log, obtaining the second record table from the configuration center by polling.

[0206] Here, when all shard inventory quantities of the target object are written successfully, the record of successful writing can be added to the log, wherein the log can be stored in a specific database such as a relational database. In this way, it is possible to determine whether there is a second record table in the configuration center based on whether the log includes a record of successful writing. For example, when a record of successful writing is obtained from the log, the second record table is immediately obtained from the configuration center; when a record of successful writing is not obtained from the log, the second record table is obtained from the configuration center by polling. The above method combines the log mechanism and the polling mechanism to take into account both the timeliness and success rate of obtaining the second record table.

[0207] The above method can also be applied to node cluster scenarios. For example, in order to avoid the local cache failing to store the second record table in time due to service node downtime or the addition of a new service node, when the service node is started, the service node can be used to determine whether a successfully written record can be obtained from the log. When a successfully written record is obtained from the log, the second record table is immediately obtained from the configuration center and stored in the local cache; when a successfully written record is not obtained from the log, the second record table is obtained from the configuration center by polling and stored in the local cache. In this way, it is ensured that the local cache of the service node can store the second record table in time.

[0208] In step 704, when the object identifier in the inventory operation request successfully matches the object identifier in the second record table, the inventory operation request is determined to be an inventory operation request for the target object.

[0209] Here, when the object identifier in the inventory operation request successfully matches (i.e., is the same as) a certain object identifier in the second record table, the inventory operation request is determined to be an inventory operation request for the target object; when the object identifier in the inventory operation request fails to match all object identifiers in the second record table, the inventory operation request is determined to be an inventory operation request for a non-target object.

[0210] like Figure 3GAs shown, the embodiment of the present application stores the object identifier of the target object in the second record table, and uses the second record table to determine whether the received inventory operation request is an inventory operation request for the target object, so as to perform corresponding processing according to the judgment result, thereby improving the targetedness of inventory processing.

[0211] Below, we will explain the exemplary application of the embodiment of the present application in an actual application scenario. For ease of understanding, taking the e-commerce scenario as an example, the embodiment of the present application can be applied to the inventory service in the commodity system of the e-commerce platform, distributing the pressure of inventory processing to multiple shards of Redis (corresponding to the inventory database above), solving the single point problem caused by the inventory operation processing concentrated on a single Redis shard in the solution provided by the related technology.

[0212] The present application embodiment provides FIG. 4A to FIG. 4E The process diagram shown corresponds to the five stages of inventory initialization, inventory query, inventory freezing, inventory deduction and inventory release, which will be explained separately.

[0213] 1. Inventory initialization phase (such as Figure 4A ).

[0214] Step S1. Find hot commodities (corresponding to the target objects mentioned above) among the multiple commodities (corresponding to the candidate objects mentioned above) managed by the e-commerce platform, wherein the discovery rule of hot commodities may be any one of the following: 1) a sudden increase in traffic, that is, the number of inventory operation requests for commodities within a preset time period is greater than or equal to a first quantity threshold; 2) a future inventory change index predicted based on the inventory quantity of the commodity at multiple historical time points is greater than or equal to an index threshold; 3) commodities (such as commodities that are about to participate in an event) are configured as hot commodities through manual configuration.

[0215] After discovering the hot commodity, determine whether the available inventory quantity of the hot commodity is greater than or equal to the sharding threshold (corresponding to the second quantity threshold above) in the configuration center, where the configuration center can be an etcd distributed configuration center. When the available inventory quantity of the hot commodity is greater than or equal to the sharding threshold (this condition can also be used as part of the discovery rule of the hot commodity), notify all service nodes of the hot inventory initialization event to execute step S2. Among them, the hot inventory refers to the inventory of the hot commodity.

[0216] It is worth noting that the embodiment of the present application can provide inventory services through a node cluster, and the service node refers to the node in the node cluster. For example, the node cluster can be a Kubernetes cluster, and the service node can be a container node Pod in the Kubernetes cluster. Each service node can access all shards of Redis, and each service node will evenly distribute the traffic of inventory operation requests, that is, select the service node with the lowest load to respond to the received inventory operation request. When executing step S2, a distributed lock is used to ensure that step S2 is executed by a single service node, and for other service nodes, relevant records can be obtained from the configuration center to realize the perception of hot inventory initialization events.

[0217] In the embodiment of the present application, the ideal situation is that all service nodes can perceive the hotspot inventory initialization event, so that in the process of querying, freezing, deducting and releasing, the specified shard can be operated. However, there may be some abnormal situations to consider in practice, such as notification failure due to communication reasons. Therefore, when the number of failed notifications to a service node reaches 3 times (corresponding to the second threshold value above), the notification to the service node is abandoned, and the service node perceives the hotspot inventory initialization event in a polling manner.

[0218] Step S2: Calculate the shard key (corresponding to the shard key above) of each shard corresponding to the hot commodity according to the number of shards in Redis and the skuid of the hot commodity. At the same time, divide the available inventory quantity of the hot commodity by the number of shards to obtain the shard inventory quantity that needs to be stored in each shard. Then, write the shard inventory quantity into each shard according to the shard key corresponding to each shard.

[0219] Step S3: When all shard inventory quantities are written successfully, the record of successful writing is added to the log, notifying all service nodes that the hotspot inventory initialization is successful; when the number of failed writes to the corresponding shard inventory quantity reaches 3 times (corresponding to the first number threshold above), the record of failed writing is added to the log, notifying all service nodes that the hotspot inventory initialization failed. The skuid of the corresponding hotspot product may be included in the record of successful writing or the record of failed writing.

[0220] If the hotspot inventory initialization fails, it is most likely a Redis failure. The subsequent compensation operations can be any of the following: 1) Execute the master-slave switch of Redis and re-execute the write operation after the slave node is online; 2) Execute the write operation on the remote backup Redis, that is, realize remote disaster recovery.

[0221] It is worth noting that when all shard inventory quantities are written successfully, the sold-out status list (corresponding to the first record table above) and the hot product SKU list (corresponding to the second record table above) are stored in the configuration center. Among them, the sold-out status list records "shard key-sold-out status", and the sold-out status corresponds to the sold-out status above, which is used to indicate whether the available shard inventory quantity in the shard corresponding to the shard key is greater than zero; the hot product SKU list records the skuid of the hot product.

[0222] 2. Inventory query stage (such as Figure 4B ).

[0223] Step S4: When an inventory query request is received (triggered by a user viewing a product), a target service node for responding to the inventory query request is determined from multiple service nodes. In the process of responding to the inventory query request, the target service node first determines whether there is a hot product SKU list in the local cache. If not, it is obtained from the configuration center and stored in the local cache. Then, it is determined whether the skuid in the inventory query request (hereinafter referred to as the request skuid) exists in the hot product SKU list. If it does, step S5 is executed; if it does not exist, it is directly routed to the corresponding shard according to the request skuid, and the available inventory quantity corresponding to the request skuid in the shard is queried, and returned to the requester.

[0224] Step S5: Calculate the shard key of each shard according to the number of shards in Redis and the request skuid, traverse multiple shard keys, and query the available shard inventory quantity corresponding to the request skuid in the corresponding shard according to the traversed shard key. Then, aggregate (such as add) all the available shard inventory quantities queried, and return the aggregated result to the requester.

[0225] 3. Inventory freezing stage (such as Figure 4C ).

[0226] Step S6. When an inventory freeze request is received (triggered by a user order), a target service node for responding to the inventory freeze request is determined from multiple service nodes. In the process of responding to the inventory freeze request, the target service node first determines whether there is a hot commodity SKU list in the local cache. If not, it is obtained from the configuration center and stored in the local cache. Then, it is determined whether the skuid (hereinafter referred to as the request skuid) in the inventory freeze request exists in the hot commodity SKU list. If it does, step S7 is executed; if it does not, it is directly routed to the corresponding shard according to the request skuid, and the inventory is frozen in the shard according to the request freeze quantity in the inventory freeze request (referring to reducing the available inventory quantity corresponding to the request skuid, and increasing the frozen inventory quantity corresponding to the request skuid).

[0227] Step S7, determine whether there is a sold-out status list in the local cache, if not, obtain it from the configuration center and store it in the local cache. Then, calculate the shard key of each shard according to the number of shards in Redis and the request skuid, filter out the corresponding shard key with a sold-out status of not sold out according to the sold-out status list, and randomly select at least one of the filtered shard keys, freeze the inventory of the shard corresponding to the selected shard key (referring to reducing the available shard inventory quantity corresponding to the request skuid and increasing the frozen shard inventory quantity corresponding to the request skuid), and generate a frozen flow record according to the order number in the inventory freeze request, the requested frozen quantity, and the selected shard key.

[0228] Step S8: Determine whether the available shard inventory quantity corresponding to the requested skuid in the shard corresponding to the selected shard key is equal to zero. If it is equal to zero, update the sold-out status list of the configuration center, that is, update the sold-out status corresponding to the selected shard key in the sold-out status list to sold-out.

[0229] 4. Inventory deduction stage (such as Figure 4D ).

[0230] Step S9, when receiving an inventory deduction request (triggered by the user's payment after placing an order), determine the target service node for responding to the inventory deduction request from multiple service nodes. In the process of responding to the inventory deduction request, the target service node first determines whether there is a hot commodity SKU list in the local cache. If not, it is obtained from the configuration center and stored in the local cache. Then, it is determined whether the skuid (hereinafter referred to as the request skuid) in the inventory deduction request exists in the hot commodity SKU list. If it exists, the corresponding target frozen flow record is found according to the order number in the inventory deduction request, and the shard key in the target frozen flow record is routed to the corresponding shard, and the inventory is deducted according to the requested frozen quantity in the target frozen flow record (referring to reducing the frozen shard inventory quantity corresponding to the request skuid); if it does not exist, it is directly routed to the corresponding shard according to the request skuid, and the inventory is deducted in the shard according to the requested deduction quantity in the inventory deduction request (referring to reducing the frozen inventory quantity corresponding to the request skuid).

[0231] V. Inventory release phase (such as Figure 4E ).

[0232] Step S10, when receiving an inventory release request (triggered by the user abandoning payment or payment timeout after placing an order), determine the target service node for responding to the inventory release request from multiple service nodes. In the process of responding to the inventory release request, the target service node first determines whether there is a hot commodity SKU list in the local cache. If not, it is obtained from the configuration center and stored in the local cache. Then, it is determined whether the skuid (hereinafter referred to as the request skuid) in the inventory release request exists in the hot commodity SKU list. If it exists, the corresponding target frozen water flow record is found according to the order number in the inventory release request, and the shard key in the target frozen water flow record is routed to the corresponding shard, and the inventory is released according to the requested frozen quantity in the target frozen water flow record (referring to reducing the frozen shard inventory quantity corresponding to the request skuid, and increasing the available shard inventory quantity corresponding to the request skuid); if it does not exist, it is directly routed to the corresponding shard according to the request skuid, and the inventory is released in the shard according to the requested release quantity in the inventory release request (referring to reducing the frozen inventory quantity corresponding to the request skuid, and increasing the available inventory quantity corresponding to the request skuid).

[0233] The present application embodiment provides Figure 5A The architecture diagram shown in the figure implements inventory processing through the interaction between users, hotspot detection system and commodity system. Users are used to: 1) view commodities (corresponding to inventory query); 2) place orders (corresponding to inventory freeze); 3) pay (corresponding to inventory deduction); 4) cancel payment (corresponding to inventory release), such as when the user abandons payment or payment times out. The hotspot detection system is used to: 1) discover hot commodities; 2) push hotspot inventory initialization events to the commodity system. The commodity system is used to: 1) maintain and query basic commodity information, such as commodity name, price, etc.; 2) store basic inventory information, including inventory quantity, frozen inventory quantity and available inventory quantity; 3) inventory query, inventory freeze, inventory deduction and inventory release.

[0234] The present application also provides Figure 5B The architecture diagram shown is Figure 5B exist Figure 5AThe commodity system is refined on the basis of the basic service, which can include basic services, inventory services, configuration center, Redis cache database and relational database. Basic services are used to: 1) manage basic information of commodities; 2) query basic information of commodities. Inventory services are used to: 1) store basic information of inventory, including inventory quantity, frozen inventory quantity and available inventory quantity; 2) inventory query, inventory freezing, inventory deduction and inventory release. The configuration center is used to: 1) store the SKU list of hot commodities; 2) store the sold-out status list. Redis cache database is used to store basic information of inventory, including inventory quantity, frozen inventory quantity and available inventory quantity. Relational database is used to: 1) store basic information of commodities; 2) store basic information of inventory, including inventory quantity, frozen inventory quantity and available inventory quantity.

[0235] The present application also provides Figure 5C The architecture diagram shown is Figure 5C exist Figure 5B The inventory service is refined on this basis. The inventory service can include hot inventory initialization module, hot inventory polling module, shard key calculation module and local cache module, which will be explained separately.

[0236] 1. Hot spot inventory initialization module.

[0237] The hotspot inventory initialization module is used to receive hotspot inventory initialization events, maintain the number of Redis shards, and maintain the shard threshold. For example, taking a certain manufacturer's cloud Redis product as an example, it supports a maximum of 128 shards, but the more shards there are, the more shard keys are calculated, and the longer the inventory query takes, so you can set a suitable number of shards, such as 8 shards. The shard threshold can be set according to the actual scenario. For example, if it is set to 10,000, taking the number of shards as 8 and the available inventory of hot products as 10,000, the number of shard inventories stored in each shard is 1,250, which can meet the inventory deduction of 10,000 QPS, but the pressure of a single shard is reduced from 10,000 QPS to 1,250 QPS.

[0238] 2. Hot spot inventory polling module.

[0239] 1) Regularly poll the hot product SKU list of the configuration center to avoid the failure of hot inventory initialization event broadcast, which causes one or some service nodes to fail to pull the configuration due to failure to receive notification. The hot product SKU list can be in json format, as shown below:

[0240] {"hotStockSkuIdList":["skuid1","skuid2","skuid3","skuid4"]}

[0241] The above skuid1, skuid2, skuid3 and skuid4 are all skuids of hot products.

[0242] 2) Regularly poll the configuration center for the sold-out status list. The sold-out status list can be in json format, as shown below:

[0243] {"hotStockSkuSatus":[{"skuid1":[{"sku1-shardkey1":0},{"sku1-shardkey2":0},{"sku1-shard key3":1}],"skuid2":[{"sku2-shardkey1":0},{"sku2-shardkey2":0},{"sku2-shardkey3":1}]}]}

[0244] In the sold-out status list, i.e., the hotStockSkuSatus list, the first-level node is the skuid of the hot product, and the second-level node is the sold-out status of each shard under the skuid of the hot product. The value 0 indicates sold-out, and the value 1 indicates not sold-out.

[0245] 3. Sharding key calculation module.

[0246] Calculate multiple shard keys based on the shard threshold and the skuid of the hot products. At the same time, calculate the number of shard inventories that each shard needs to store. When calculating the number of shard inventories, you can use an average distribution method, such as shard inventory quantity = available inventory quantity of hot products / number of shards. For example, the available inventory quantity of hot products is 30,000, and the number of shards is 10, then the number of shard inventories that each shard needs to store is 3,000.

[0247] There are two calculation strategies for shard keys (corresponding to the fixed generation strategy above):

[0248] 1) Generate multiple values ​​in the same number of shards according to the preset numerical order, and use each generated value as the prefix of the original key (corresponding to the original key above) of the hot product, where the original key is skuid. For example, the original key of the hot product is skuid1, and the number of shards is 2, then 2 shard keys are calculated, namely {0}:skuid1 and {1}:skuid1.

[0249] 2) Split the Redis storage range array [0, 1, 2, 3...16383] according to the number of shards to obtain multiple sub-arrays that match the number of shards, and use the last value in each sub-array as the prefix of the original key of the hot product. For example, if the original key of the hot product is skuid1 and the number of shards is 2, then split [0, 1, 2, 3...16383] into [0, 1, 2, 3...8173] and [8174, 8175...16383] to obtain two shard keys, {8173}:skuid1 and {16383}:skuid1.

[0250] It is worth noting that when processing shard routing, the prefix in the shard key (i.e. the content in the curly braces {}) is used to route to the corresponding shard to achieve data reading and writing. Compared with calculation strategy 1), the prefixes of different shard keys obtained by calculation strategy 2) are more different and have a lower collision rate.

[0251] 4. Local cache module.

[0252] After the hot inventory polling module pulls the configuration (i.e., the hot product SKU list and the sold-out status list) from the configuration center, the hot product SKU list and the sold-out status list are stored in the local cache. In this way, the hot product SKU list can be used to determine whether the product targeted by the inventory operation request is a hot product, so as to respond in a targeted manner; the sold-out status list can be used to filter the shard keys whose sold-out status is not sold-out, so as to freeze the inventory.

[0253] In addition, the embodiment of the present application also introduces a relational database to store logs, mainly to prevent the local cache from failing to obtain the hot commodity SKU list and the sold-out status list in time due to service node downtime or the addition of a new service node. For example, when the service node is started, the log is queried first. If there is a successful write record in the log (proving that the hot inventory initialization is successful), the hot commodity SKU list and the sold-out status list in the configuration center are immediately obtained; if there is no successful write record in the log (proving that the hot inventory initialization fails), the hot commodity SKU list and the sold-out status list in the configuration center are obtained again when the next polling is performed. In this way, the log mechanism and the polling mechanism are combined to take into account both the timeliness and success rate of obtaining the configuration.

[0254] In summary, the embodiments of the present application distribute the processing pressure to multiple shards for hot commodities in the e-commerce platform, which can effectively avoid single point problems and improve the stability and efficiency of inventory services; at the same time, a specific computing strategy is used to generate shard keys, and accurate reading and writing of data in each shard is achieved according to the shard keys without modifying the underlying routing rules of Redis, thereby achieving low cost.

[0255] The following is a description of an exemplary structure of the inventory processing device 255 provided in the embodiment of the present application implemented as a software module. In some embodiments, Figure 2 As shown, the software modules stored in the inventory processing device 255 of the memory 450 may include: a determination module 2551, which is used to determine the inventory quantity of the target object and the shard quantity of multiple shards in the inventory database; a generation module 2552, which is used to generate shard keys of the target object corresponding to multiple shards according to the shard quantity; a writing module 2553, which is used to perform inventory allocation processing according to the inventory quantity and the shard quantity, obtain the shard inventory quantities corresponding to the multiple shards, and write the shard inventory quantities corresponding to each shard into the shard according to the shard key corresponding to the shard; a receiving module 2554, which is used to receive an inventory operation request for the target object; an operation module 2555, which is used to determine a request shard key from multiple shard keys in response to the inventory operation request for the target object, and perform inventory operation processing on the shard inventory quantities in the shard corresponding to the request shard key according to the request shard key.

[0256] In some embodiments, when the inventory operation request for the target object is an inventory query request, the operation module 2555 is also used to: determine multiple shard keys as request shard keys; query the shard inventory quantity in the shard corresponding to the request shard key according to each request shard key, and summarize the queried multiple shard inventory quantities.

[0257] In some embodiments, the shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; when the inventory operation request for the target object is an inventory freezing request, the operation module 2555 is also used to: determine the shard key whose available shard inventory quantity of the corresponding shard is greater than zero as the requested shard key; perform the following processing according to the requested shard key: according to the requested freezing quantity in the inventory freezing request, reduce the available shard inventory quantity in the shard corresponding to the requested shard key, and increase the frozen shard inventory quantity in the shard corresponding to the requested shard key; the inventory processing device 255 also includes a recording module, which is used to: generate a frozen serial record according to the serial number, the requested freezing quantity, and the requested shard key in the inventory freezing request; wherein the frozen serial record is used to respond to the inventory deduction request or inventory release request for the target object.

[0258] In some embodiments, the recording module is further used to: add the shard key of each shard and the exhaustion status of the shard to the first recording table; wherein the exhaustion status is used to indicate whether the available shard inventory quantity is greater than zero; the operation module 2555 is further used to: determine, based on the exhaustion status of each shard in the first recording table, a shard key with an available shard inventory quantity greater than zero as the requested shard key.

[0259] In some embodiments, the operation module 2555 is further used to: determine a shard key whose corresponding shard's available shard inventory quantity is greater than zero as a candidate shard key; when there are multiple candidate shard keys, perform at least one selection process on the multiple candidate shard keys to obtain at least one requested shard key, until the sum of the available shard inventory quantities in the shards indicated by all requested shard keys in the at least one requested shard key is not less than the requested frozen quantity.

[0260] In some embodiments, the shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; when the inventory operation request for the target object is an inventory deduction request, the operation module 2555 is also used to: match the serial number in the inventory deduction request with the serial number in all frozen serial records, and determine the successfully matched frozen serial record as the target frozen serial record; wherein the frozen serial record includes the serial number, the requested frozen quantity and the requested shard key; perform the following processing according to the requested shard key in the target frozen serial record: according to the requested frozen quantity in the target frozen serial record, reduce the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen serial record.

[0261] In some embodiments, the shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; when the inventory operation request for the target object is an inventory release request, the operation module 2555 is also used to: match the serial number in the inventory release request with the serial number in all frozen serial records, and determine the successfully matched frozen serial record as the target frozen serial record; wherein the frozen serial record includes the serial number, the requested frozen quantity and the requested shard key; perform the following processing according to the requested shard key in the target frozen serial record: according to the requested frozen quantity in the target frozen serial record, reduce the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen serial record, and increase the available shard inventory quantity in the shard corresponding to the requested shard key in the target frozen serial record.

[0262] In some embodiments, the generation module 2552 is also used to: determine the original key of the target object in the inventory database; generate additional keys corresponding to multiple shards according to the number of shards; append the additional key corresponding to each shard to the original key of the target object to obtain the shard key of the target object corresponding to the shard; the writing module 2553 is also used to: perform shard routing processing according to the additional key in the shard key corresponding to each shard, and write the shard inventory quantity corresponding to the shard to the routed shard; the operation module 2555 is also used to: perform shard routing processing according to the additional key in the requested shard key, and perform inventory operation processing on the shard inventory quantity in the routed shard.

[0263] In some embodiments, the generation module 2552 is also used to perform any of the following processing: generating multiple numerical values ​​in a preset numerical order, whose quantity matches the number of shards, and determining each numerical value as an additional key; splitting the storage range array of the inventory database according to the number of shards to obtain multiple sub-arrays whose quantity matches the number of shards, and determining the numerical value at a preset position in each sub-array as an additional key.

[0264] In some embodiments, the write module 2553 is also used to: write the original key of the target object and the shard inventory quantity corresponding to the shard into the routed shard in the form of key value; the operation module 2555 is also used to: query the shard inventory quantity in the routed shard according to the original key in the requested shard key, and perform inventory operations on the queried shard inventory quantity.

[0265] In some embodiments, the inventory processing device 255 also includes a non-target object processing module, which is used to: determine the inventory quantity of the non-target object and the original key of the non-target object in the inventory database; write the inventory quantity of the non-target object to the shard corresponding to the original key of the non-target object according to the original key of the non-target object; receive an inventory operation request for the non-target object; and in response to the inventory operation request for the non-target object, perform inventory operation processing on the inventory quantity of the non-target object in the shard corresponding to the original key of the non-target object according to the original key of the non-target object.

[0266] In some embodiments, the inventory processing device 255 also includes a recording module, which is used to: add the object identifier of the target object to the second record table; the receiving module 2554 is also used to: receive an inventory operation request; match the object identifier in the inventory operation request with the object identifier in the second record table; when the object identifier in the inventory operation request successfully matches the object identifier in the second record table, determine the inventory operation request as an inventory operation request for the target object.

[0267] The embodiment of the present application provides a computer program product or a computer program, which includes executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the executable instructions from the computer-readable storage medium, and the processor executes the executable instructions, so that the electronic device executes the inventory processing method described above in the embodiment of the present application.

[0268] An embodiment of the present application provides a computer-readable storage medium storing executable instructions, wherein executable instructions are stored. When the executable instructions are executed by a processor, the processor will be caused to execute the inventory processing method provided by the embodiment of the present application.

[0269] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.

[0270] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0271] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0272] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0273] The above are only embodiments of the present application and are not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims

1. A method for inventory processing, characterized in that: include: Determine the inventory quantity of the target object and the number of shards for multiple shards in the inventory database; Generate shard keys for the target object corresponding to the multiple shards respectively according to the number of shards; Perform inventory allocation processing according to the inventory quantity and the shard quantity to obtain the shard inventory quantities corresponding to the multiple shards respectively, and write the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard; receiving an inventory operation request for the target object; In response to an inventory operation request for the target object, a request shard key is determined from multiple shard keys, and an inventory operation is performed on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key.

2. The method according to claim 1, characterized in that When the inventory operation request for the target object is an inventory query request, determining a request shard key from the multiple shard keys, and performing inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key, includes: Determine multiple shard keys as requested shard keys; According to each requested shard key, query the shard inventory quantity in the shard corresponding to the requested shard key, and summarize the queried inventory quantities of multiple shards.

3. The method according to claim 1, characterized in that The shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; When the inventory operation request for the target object is an inventory freeze request, determining a request shard key from the multiple shard keys, and performing inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key, includes: The shard key whose available shard inventory quantity of the corresponding shard is greater than zero is determined as the requested shard key; The following processing is performed according to the requested shard key: according to the requested freezing quantity in the inventory freezing request, the available shard inventory quantity in the shard corresponding to the requested shard key is reduced, and the frozen shard inventory quantity in the shard corresponding to the requested shard key is increased; The method further comprises: Generate a freezing serial record according to the serial number in the inventory freezing request, the requested freezing quantity, and the requested shard key; The frozen transaction record is used to respond to an inventory deduction request or an inventory release request for the target object.

4. The method according to claim 3, characterized in that After writing the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard, the method further includes: Add the shard key of each shard and the exhaustion status of the shard to the first record table; wherein the exhaustion status is used to indicate whether the available shard inventory quantity is greater than zero; The step of determining a shard key corresponding to a shard whose available shard inventory quantity is greater than zero as the requested shard key includes: According to the exhaustion status of each shard in the first record table, a shard key whose available shard inventory quantity is greater than zero is determined as the requested shard key.

5. The method according to claim 3, characterized in that: The step of determining a shard key corresponding to a shard whose available shard inventory quantity is greater than zero as the requested shard key includes: The shard keys whose available shard inventory quantity of the corresponding shard is greater than zero are determined as candidate shard keys; When there are multiple candidate shard keys, at least one selection process is performed on the multiple candidate shard keys to obtain at least one requested shard key, until the sum of the available shard inventory quantities in the shards indicated by all requested shard keys in the at least one requested shard key is not less than the requested frozen quantity.

6. The method according to claim 1, characterized in that The shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; When the inventory operation request for the target object is an inventory deduction request, determining a request shard key from the multiple shard keys, and performing inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key, includes: Matching the serial number in the inventory deduction request with the serial numbers in all frozen serial records, and determining the successfully matched frozen serial record as the target frozen serial record; wherein the frozen serial record includes the serial number, the requested frozen quantity, and the requested shard key; The following processing is performed according to the requested shard key in the target frozen water flow record: according to the requested frozen quantity in the target frozen water flow record, the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen water flow record is reduced.

7. The method according to claim 1, characterized in that The shard inventory quantity includes the available shard inventory quantity and the frozen shard inventory quantity; When the inventory operation request for the target object is an inventory release request, determining a request shard key from the multiple shard keys, and performing inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key, includes: Matching the serial number in the inventory release request with the serial numbers in all frozen serial records, and determining the successfully matched frozen serial record as the target frozen serial record; wherein the frozen serial record includes the serial number, the requested frozen quantity, and the requested shard key; The following processing is performed according to the requested shard key in the target frozen water flow record: according to the requested freezing quantity in the target frozen water flow record, the frozen shard inventory quantity in the shard corresponding to the requested shard key in the target frozen water flow record is reduced, and the available shard inventory quantity in the shard corresponding to the requested shard key in the target frozen water flow record is increased.

8. The method according to any one of claims 1 to 7, characterized in that: The generating, according to the number of shards, shard keys of the target object corresponding to the plurality of shards respectively includes: determining an original key of the target object in the inventory database; Generate additional keys corresponding to the plurality of shards respectively according to the number of shards; Append the additional key corresponding to each shard to the original key of the target object to obtain the shard key of the target object corresponding to the shard; The step of writing the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard includes: Perform shard routing processing according to the additional key in the shard key corresponding to each shard, and write the shard inventory quantity corresponding to the shard to the routed shard; The performing inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key includes: Shard routing processing is performed according to the additional key in the requested shard key, and inventory operation processing is performed on the shard inventory quantity in the routed shard.

9. The method according to claim 8, characterized in that The generating, according to the number of shards, the additional keys respectively corresponding to the plurality of shards comprises: Perform any of the following: Generate multiple values ​​in a predetermined numerical order, the number of which matches the number of shards, and determine each value as an additional key; The storage range array of the inventory database is split according to the number of shards to obtain a plurality of sub-arrays whose number matches the number of shards, and a value at a preset position in each sub-array is determined as an additional key.

10. The method according to claim 8, characterized in that The step of writing the shard inventory quantity corresponding to the shard into the routed shard includes: Write the original key of the target object and the shard inventory quantity corresponding to the shard into the routed shard in key-value form; The performing inventory operation processing on the shard inventory quantity in the routed shards includes: According to the original key in the requested shard key, the shard inventory quantity in the routed shard is queried, and inventory operation processing is performed on the queried shard inventory quantity.

11. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: determining an inventory quantity of a non-target object and an original key of the non-target object in the inventory database; Writing the inventory quantity of the non-target object into the shard corresponding to the original key of the non-target object according to the original key of the non-target object; receiving an inventory operation request for the non-target object; In response to the inventory operation request for the non-target object, an inventory operation is performed on the inventory quantity of the non-target object in the shard corresponding to the original key of the non-target object according to the original key of the non-target object.

12. The method according to any one of claims 1 to 7, characterized in that: Before receiving the inventory operation request for the target object, the method further includes: Adding the object identifier of the target object to the second record table; The receiving an inventory operation request for the target object includes: Receive inventory operation requests; Matching the object identifier in the inventory operation request with the object identifier in the second record table; When the object identifier in the inventory operation request successfully matches the object identifier in the second record table, the inventory operation request is determined as an inventory operation request for the target object.

13. An inventory processing device, characterized in that: include: A determination module, for determining an inventory quantity of a target object and a shard quantity of a plurality of shards in an inventory database; A generation module, used to generate shard keys of the target object corresponding to the multiple shards respectively according to the number of shards; A writing module is used to perform inventory allocation processing according to the inventory quantity and the shard quantity, obtain the shard inventory quantities corresponding to the multiple shards respectively, and write the shard inventory quantity corresponding to each shard into the shard according to the shard key corresponding to the shard; A receiving module, configured to receive an inventory operation request for the target object; The operation module is used to respond to the inventory operation request for the target object, determine a request shard key from multiple shard keys, and perform inventory operation processing on the shard inventory quantity in the shard corresponding to the request shard key according to the request shard key.

14. An electronic device, characterized in that: include: A memory for storing executable instructions; A processor, configured to implement the inventory processing method according to any one of claims 1 to 12 when executing the executable instructions stored in the memory.

15. A computer-readable storage medium, characterized in that: Executable instructions are stored, and when executed by a processor, the inventory processing method according to any one of claims 1 to 12 is implemented.

16. A computer program product, characterized in that The method comprises executable instructions for implementing the inventory processing method according to any one of claims 1 to 12 when executed by a processor.