A multi-level resource price synchronous calculation method and related device

By constructing a forward aggregation cache and a reverse tracing cache structure, the computational latency and consistency issues of multi-level association trees in high-concurrency scenarios are solved, enabling synchronous price updates within a single request and improving system response speed and data consistency.

CN122152824APending Publication Date: 2026-06-05CTRIP COMP TECH SHANGHAI

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CTRIP COMP TECH SHANGHAI
Filing Date
2026-05-07
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing recursive query schemes lead to performance bottlenecks and latency in high-concurrency scenarios with multi-level relational trees, making it difficult to accurately calculate and synchronously update the prices of all related resources within a single request.

Method used

By constructing a forward aggregation cache structure and a reverse tracing cache structure, respectively, the parent-child association rules and dependencies of node resources in the multi-level association tree are obtained and updated, thereby realizing synchronous price calculation within a single request.

Benefits of technology

It reduces network I/O time complexity from linear to constant level, avoiding computational latency and performance bottlenecks caused by multiple recursive queries, and ensuring the real-time performance and consistency of price data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122152824A_ABST
    Figure CN122152824A_ABST
Patent Text Reader

Abstract

The application provides a multi-level resource price synchronization calculation method and related device, relates to the technical field of distributed system data processing, and comprises the following steps: acquiring a price synchronization instruction of a first target node resource, the first target node resource being a node resource in a multi-level association relationship tree; calling a constructed forward aggregation cache structure, the forward aggregation cache structure containing a forward aggregation cache of a non-leaf node resource in the multi-level association relationship tree, and the forward aggregation cache containing resource identifiers of each node resource in a subtree with the non-leaf node resource as a root node and parent-child association rules when the non-leaf node resource is a parent node; and performing price synchronization on each node resource in the subtree with the first target node resource as the root node according to all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource. According to the application, network IO time complexity is reduced from linear level to constant level, and multiple network interactions caused by layer-by-layer recursive query are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of distributed system data processing technology, and in particular to a multi-level resource price synchronous calculation method and related apparatus. Background Technology

[0002] In the field of resource management and pricing, with the increasing complexity of business and the deepening of inter-relationships between resources, synchronous calculation of resource price changes based on multi-level relational trees has become the mainstream. After an operator modifies the price of a root node resource, the system can automatically cascade and calculate and update the prices of all related child node resources.

[0003] Traditional coding methods employ recursive query schemes based on relational databases or introduce homogeneous caching layers to store parent-child association rules between parent node resources and child node resources, using the resource identifier of the parent node resource as the key. During price synchronization calculations, the system needs to read the parent-child association rules at each level layer by layer through recursive SQL queries or application-layer recursive calls, until all multi-level association tree structures have been traversed.

[0004] However, as the business scale expands, the depth and breadth of the multi-level association tree continue to grow. The existing recursive query scheme results in the number of network I / Os required to obtain all association rules being linearly related to the level, which can easily lead to serious performance bottlenecks and latency in high-concurrency scenarios. Summary of the Invention

[0005] In view of the above problems, this application provides a multi-level resource price synchronization calculation method and related apparatus to achieve the goal of accurately calculating and synchronously updating the prices of all related resources within a single request. The specific solution is as follows:

[0006] The first aspect of this application provides a method for simultaneous calculation of multi-level resource prices, the method comprising:

[0007] Obtain the price synchronization instruction for the first target node resource, where the first target node resource is a node resource in a multi-level association tree;

[0008] Retrieve the constructed forward aggregation cache structure, which contains forward aggregation caches of non-leaf node resources in the multi-level association tree. The forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at the non-leaf node resource and their parent-child association rules when it is a parent node.

[0009] Based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, price synchronization is performed on the resources of each node in the subtree rooted at the first target node resource.

[0010] In one possible implementation, the step of synchronizing prices for each node resource in the subtree rooted at the first target node resource, based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, includes:

[0011] The dependency relationships between corresponding resource identifiers are determined based on all parent-child association rules in the positive aggregation cache of the first target node's resources;

[0012] Based on the aforementioned dependency relationship, the parent-child association rules in the positive aggregation cache of the first target node resource are executed sequentially to calculate and obtain the actual price corresponding to the corresponding resource identifier;

[0013] The actual prices of all resource identifiers in the forward aggregation cache of the first target node resource are written in batches to the price storage to synchronously update the prices of each node resource in the subtree rooted at the first target node resource.

[0014] In one possible implementation, the multi-level resource price synchronization calculation method further includes:

[0015] Obtain the rule update instruction for the second target node resource, where the second target node resource is a node resource in the multi-level association tree;

[0016] Retrieve the constructed reverse tracing cache structure, which contains the reverse tracing cache of non-root node resources in the multi-level association tree, and the reverse tracing cache contains the resource identifiers of the parent resource nodes of the non-root node resources up to the root resource nodes.

[0017] Based on all resource identifiers in the reverse tracing cache of the second target node resource, at least one third target node resource to be updated is determined, and the parent-child association rule of the second target node resource is updated in the forward aggregation cache of the at least one third target node resource.

[0018] In one possible implementation, determining at least one third target node resource to be updated based on all resource identifiers in the reverse sourcing cache of the second target node resource includes:

[0019] Obtain the resource identifier of the root node resource of the multi-level association tree from the reverse tracing cache of the second target node resource, and apply for a distributed lock using the resource identifier of the root node resource;

[0020] If the distributed lock acquisition is successful, the at least one third target node resource is determined based on all resource identifiers in the reverse tracing cache of the second target node resource.

[0021] In one possible implementation, the multi-level resource price synchronization calculation method further includes:

[0022] If the distributed lock acquisition fails, the rule update instructions for the second target node resource are added to the queue so that the rule update instructions in the queue are executed sequentially after the distributed lock is released.

[0023] A second aspect of this application provides a multi-level resource price synchronization calculation device, the multi-level resource price synchronization calculation device comprising:

[0024] The instruction acquisition module is used to acquire the price synchronization instruction of the first target node resource, where the first target node resource is a node resource in a multi-level association tree;

[0025] The price synchronization module is used to retrieve the constructed forward aggregation cache structure, which contains forward aggregation caches of non-leaf node resources in the multi-level association tree. The forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at the non-leaf node resource and their parent-child association rules when it is a parent node. Based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, the module performs price synchronization on each node resource in the subtree rooted at the first target node resource.

[0026] In one possible implementation, a price synchronization module, used to synchronize prices for resources in the subtree rooted at the first target node resource based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, is specifically used for:

[0027] The dependency relationships between corresponding resource identifiers are determined based on all parent-child association rules in the forward aggregation cache of the first target node resource; the parent-child association rules in the forward aggregation cache of the first target node resource are sequentially run based on the dependency relationships to calculate the actual price corresponding to the corresponding resource identifier; the actual prices of all resource identifiers in the forward aggregation cache of the first target node resource are written in batches to the price storage to synchronously update the prices of each node resource in the subtree rooted at the first target node resource.

[0028] A third aspect of this application provides a computer program product, including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement the multi-level resource price synchronization calculation method described in the first aspect or any implementation thereof.

[0029] A fourth aspect of this application provides an electronic device, including at least one processor and a memory connected to the processor, wherein:

[0030] The memory is used to store computer programs;

[0031] The processor is used to execute the computer program so that the electronic device can implement the multi-level resource price synchronous calculation method of the first aspect or any implementation thereof.

[0032] The fifth aspect of this application provides a computer storage medium carrying one or more computer programs, which, when executed by an electronic device, enable the electronic device to perform a multi-level resource price synchronous calculation method as described in the first aspect or any implementation thereof.

[0033] Using the above technical solution, this application provides a multi-level resource price synchronization calculation method and related apparatus, comprising: obtaining a price synchronization instruction for a first target node resource, wherein the first target node resource is a node resource in a multi-level association tree; retrieving a constructed forward aggregation cache structure, wherein the forward aggregation cache structure contains a forward aggregation cache of non-leaf node resources in the multi-level association tree, and the forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at the non-leaf node resource and their parent-child association rules when it is a parent node; and synchronizing the prices of each node resource in the subtree rooted at the first target node resource according to all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource. This application addresses node resources in multi-level association trees by constructing a forward aggregation cache structure containing full information about non-leaf node resources and their subtrees. Upon receiving a price synchronization command, it directly retrieves the corresponding forward aggregation cache to obtain the resource identifiers and parent-child association rules of all node resources in the subtree at once, thereby synchronizing prices. This reduces the network I / O time complexity of obtaining full association rules from linear to constant level, avoiding multiple network interactions caused by recursive queries layer by layer in traditional solutions. It effectively solves the computational latency and performance bottleneck problems caused by frequent I / O operations in high-concurrency scenarios, ensuring that the accurate calculation and synchronization update of all associated resource prices can be completed within a single request. In addition, this application can also eliminate the time window of data inconsistency, significantly improving the system's response speed, data consistency, and overall operational stability in large-scale resource management scenarios. Attached Figure Description

[0034] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.

[0035] Figure 1 A flowchart illustrating a multi-level resource price synchronization calculation method provided in this application embodiment;

[0036] Figure 2 A structural example diagram of a multi-level association tree provided in this application embodiment;

[0037] Figure 3 This is another schematic flowchart of a multi-level resource price synchronization calculation method provided in the embodiments of this application;

[0038] Figure 4 A schematic diagram of the structure of a multi-level resource price synchronization calculation device provided in this application embodiment;

[0039] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0040] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.

[0041] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.

[0042] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.

[0043] To address the computational latency and performance bottlenecks caused by frequent I / O operations in high-concurrency scenarios, and to ensure accurate calculation and synchronous updates of all related resource prices within a single request, eliminating time windows of data inconsistency, this application provides a multi-level resource price synchronization calculation method. This method, based on a bidirectional heterogeneous caching structure, enables rapid synchronous calculation of multi-level related prices for massive resources. It is suitable for applications requiring real-time synchronous price changes for resources with price relationships, such as hotel management systems, e-commerce platforms, and financial derivatives pricing. The multi-level resource price synchronization calculation method of this application embodiment is described in detail below with reference to the accompanying drawings.

[0044] See Figure 1 , Figure 1 This is a flowchart illustrating a multi-level resource price synchronization calculation method provided in an embodiment of this application. Figure 1 As shown in the embodiment of this application, a multi-level resource price synchronization calculation method may include steps S101 to S103, which are described in detail below.

[0045] S101, obtain the price synchronization instruction for the first target node resource, where the first target node resource is a node resource in a multi-level association tree.

[0046] In this embodiment, the price synchronization instruction is used to trigger a recalculation of the price of a specific node resource and its associated child node resources. This can be generated through operator price adjustments, scheduled task triggers, or price changes in the upstream system. The first target node resource is the node resource whose price is to be modified. It is the node resource in a multi-level relationship tree that serves as the starting point for this price synchronization. It can be the root node of the entire tree or any non-leaf node in the middle of the tree; this embodiment does not limit this. The first target node resource can be obtained by parsing the resource identifier in the price synchronization instruction.

[0047] See Figure 2 , Figure 2 This is a structural example diagram of a multi-level association tree provided for embodiments of this application. For example... Figure 2 As shown, the hotel management system contains a multi-level relational tree with room type A as the root node. This tree also includes room types B, C, D, E, F, and G. Taking room types A and B as an example, room type A is the parent node of room type B, and their parent-child relationship is: price of room type B = price of room type A + 10.0 yuan. Similarly, room type B is the parent node of room type C, and their parent-child relationship is: price of room type C = price of room type B × 1.2. Other node resources are not detailed further. Figure 2As shown in the multi-level relationship tree, operators can use any node resource as the first target node resource for price synchronization. For example, if room type B is used as the first target node resource and its base price is adjusted from 500 yuan to 550 yuan, the starting node resource for this price synchronization can be determined.

[0048] S102, retrieve the constructed forward aggregation cache structure. The forward aggregation cache structure contains forward aggregation caches of non-leaf node resources in a multi-level association tree. The forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at a non-leaf node resource and its parent-child association rules when it is a parent node.

[0049] In this embodiment, the forward aggregation cache structure is a pre-constructed distributed hash data structure for a multi-level association tree, aiming to flatten the multi-level association tree. The forward aggregation cache structure includes forward aggregation caches of non-leaf node resources in the multi-level association tree. Specifically, the forward aggregation cache is a specific data entry in the forward aggregation cache structure, where the key is the unique resource identifier of the non-leaf node resource, and the value is the resource identifier of all node resources in the subtree rooted by the non-leaf node resource, as well as the parent-child association rules when it is the parent node. Specifically, for each non-leaf node resource in the multi-level association tree, its forward aggregation cache stores the parent-child association rules of all descendant node resources in the subtree rooted by it, rather than only storing the parent-child association rules between it and its direct child node resources. This structure allows all descendant node resources and their parent-child association rules under a given node resource to be obtained with only one network I / O operation, reducing the I / O time complexity from O(N) to O(1), where N is the level of the multi-level association tree.

[0050] For ease of understanding this application, the following will continue to be used: Figure 2The following example illustrates a multi-level association tree. The forward aggregation cache structure of this multi-level association tree includes forward aggregation cache keys for room type A: Key=A:{B:A+10.0,C:B×1.2,D:C+10.0,E:D+5.0,F:B-20.0,G:C×1.0}, for room type B: Key=B:{C:B×1.2,D:C+10.0,E:D+5.0,F:B-20.0,G:C×1.0}, for room type C: Key=C:{D:C+10.0,E:D+5.0,G:C×1.0}, and for room type D: Key=D:{E:D+5.0}. This ensures that regardless of the size of the hierarchical relationship tree, simply retrieving the forward aggregation cache of a single node's resource allows for the acquisition of the parent-child relationships of all its descendant nodes in a single query, eliminating the need for repeated lookups. This flattened data storage structure eliminates the multiple network interactions caused by recursive layer-by-layer queries in traditional solutions, significantly reducing network latency and connection overhead, and providing a complete data foundation for subsequent high-speed parallel computing.

[0051] S103, based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, perform price synchronization on the resources of each node in the subtree rooted at the first target node resource.

[0052] In this embodiment, during price synchronization, the actual price of each node resource in the subtree can be calculated sequentially according to the topological order of the dependency relationships, based on the full resource identifiers and their parent-child relationships obtained from the forward aggregation cache of the first target node resource. Specifically, firstly, the parent-child association rules in the forward aggregation cache are parsed to construct a dependency graph between resource identifiers; then, using the new price of the first target node resource as the initial input, the actual prices of all node resources are derived using the parent-child association rules according to the order determined by the dependency graph (i.e., the price of the parent node resource is calculated before the price of the child node resource); finally, the actual prices of all node resources are packaged and synchronously updated to the database or downstream services through batch write operations.

[0053] For ease of understanding this application, the following will continue to be used: Figure 2Let's take the multi-level relationship tree shown as an example. Assume the first target node resource is room type A, and its price changes to 100.0 yuan. Based on room type A, the forward aggregation cache first calculates the actual price of room type B as 100.0 + 10.0 = 110.0 yuan, then calculates the actual price of room type C as 110.0 × 1.2 = 132.0 yuan, then calculates the actual price of room type D as 132.0 + 10.0 = 142.0 yuan, and finally calculates the actual price of room type E as 142.0 + 5.0 = 147.0 yuan. It should be noted that room type F and room type C are both child nodes of room type B, and room type D and room type G are both child nodes of room type C. Therefore, room type F can have its actual price calculated simultaneously with room type C, and room type D can have its actual price calculated simultaneously with room type G. Therefore, the forward aggregation cache structure preloaded in this application can complete the price recalculation of the entire subtree in memory, thereby ensuring that price changes can complete the update of all related resources within a single request. This not only avoids the calculation delay caused by multiple I / Os, but also completely eliminates the data inconsistency window that may exist during asynchronous updates, ensuring strong consistency and real-time performance of price data in high-concurrency scenarios.

[0054] See Figure 3 , Figure 3 This is another schematic flowchart illustrating a multi-level resource price synchronization calculation method provided in an embodiment of this application. For example... Figure 3 As shown in the embodiment of this application, a multi-level resource price synchronization calculation method is provided. In this method, step S103, "based on all resource identifiers and parent-child association rules in the positive aggregation cache of the first target node resource, price synchronization is performed on each node resource in the subtree rooted at the first target node resource", may include steps S301 to S303. These steps are described in detail below.

[0055] S301, determine the dependency relationship between corresponding resource identifiers based on all parent-child association rules in the positive aggregation cache of the first target node resource.

[0056] In this embodiment, the parent-child association rule is a variable-price rule expression stored in the forward aggregation cache to describe the relationship between a child node resource and its parent node resource. It typically exists in key-value pair form, where the key is the resource identifier of the child node resource, and the value is a string or object containing the resource identifier of the parent node resource and the computational logic. Therefore, by parsing the parent-child association rule in the forward aggregation cache, a directed acyclic graph between resource identifiers can be constructed, thereby determining the dependency relationship between child node resources and parent node resources. Continuing with... Figure 2Taking the multi-level relationship tree shown as an example, the forward aggregation cache key for room type C is C:{D: C+10.0,E:D+5.0,G:C×1.0}. After parsing, it can be determined that room type D depends on room type C, room type E depends on room type D, and room type G depends on room type C. This parsing method clarifies the calculation order of resources at each node, ensuring that when calculating the actual price of a resource at a certain node, the prices of its dependent parent node resources have been updated, thus avoiding price derivation anomalies caused by incorrect calculation order.

[0057] S302, based on the dependency relationship, sequentially run the parent-child association rules in the positive aggregation cache of the first target node resource to calculate the actual price corresponding to the corresponding resource identifier.

[0058] In this embodiment, the parent-child association rules are executed layer by layer downwards from the first target node resource according to the aforementioned dependency relationship. During execution, a temporary computational context is maintained to store the actual price calculated in the current round. Specifically, when processing the parent-child association rule of a certain node resource, the actual price of its parent node resource can be read from this context and substituted into its parent-child association rule to calculate the actual price of that node resource. The context is then immediately updated for use by subsequent nodes. In this process, if parallel dependencies are encountered, i.e., multiple child node resources directly depend on the same parent node resource, the computation tasks of these independent branches can be executed in parallel to improve efficiency. Through this sequential execution mechanism based on the dependency graph, the accuracy and logical rigor of the price transmission chain are guaranteed, effectively avoiding calculation errors caused by incomplete data.

[0059] S303, write the actual prices of all resource identifiers in the forward aggregation cache of the first target node resource to the price storage in batches, so as to synchronously update the prices of each node resource in the subtree rooted at the first target node resource.

[0060] In this embodiment, the price storage can refer to a database or distributed storage system used to persistently store the actual prices of resources on each node. After calculating and obtaining the actual prices of all resource identifiers in the forward aggregation cache of the first target node resource in memory, the actual prices of all resource identifiers can be packaged into an atomic operation unit and submitted to the price storage for update at once, instead of initiating a separate write request for each node resource. This ensures that all associated node resources complete the state change at the same time, achieving strong data consistency and completely eliminating the price display inconsistency window that may exist in asynchronous update schemes.

[0061] In one possible implementation, the parent-child association rules in the forward aggregation cache structure can also be updated by constructing a reverse sourcing cache structure. In this regard, the multi-level resource price synchronization calculation method provided in this application embodiment further includes the following steps:

[0062] Obtain the rule update instruction for the second target node resource, which is a node resource in a multi-level association tree; retrieve the constructed reverse tracing cache structure, which contains the reverse tracing cache of non-root node resources in the multi-level association tree, and the reverse tracing cache contains the resource identifiers of the parent resource nodes of the non-root node resources up to the root resource node; determine at least one third target node resource to be updated based on all resource identifiers in the reverse tracing cache of the second target node resource, and update the parent-child association rules of the second target node resource in the forward aggregation cache of at least one third target node resource.

[0063] In this embodiment, the second target node resource is a node resource whose parent-child relationship is to be modified, and can be any non-root node in a multi-level relationship tree. The rule update instruction is used to instruct the addition, modification, and deletion of parent-child relationships where the second target node resource is a child node, and it includes the resource identifier of the second target node resource and the specific rule change content.

[0064] Furthermore, the reverse sourcing cache structure is a pre-built distributed data storage structure that uses an ordered list data structure to store the complete ancestor link from the current node to the root node. Specifically, the key of the reverse sourcing cache structure is the resource identifier of a non-root node resource, and the value is the resource identifier of the parent resource node of that non-root node resource up to the root resource node (i.e., all ancestor resource nodes). For ease of understanding, let's continue with... Figure 2 Taking the multi-level relationship tree shown as an example, the reverse tracing structure includes the reverse tracing cache key=B:[A] for room type B, C:[B,A] for room type C, D:[C,B,A] for room type D, E:[D,C,B,A] for room type E, F:[B,A] for room type F, and G:[C,B,A] for room type G. Therefore, based on the reverse tracing cache structure, it can have the ability to backtrack from the leaf node to the root node. When a rule change is detected for a resource at a lower-level node, it is not necessary to recursively traverse the entire tree; the resource identifiers of all upper-level nodes can be obtained through a single network I / O read.

[0065] Based on the aforementioned reverse sourcing cache structure, the reverse sourcing cache of the second target node resource can be obtained, and all resource identifiers therein can be identified as at least one third target node resource to be updated. Further, the forward aggregation cache of each of the at least one third target node resource is accessed sequentially. In the forward aggregation cache of each third target node resource, an entry with the resource identifier of the second target node resource as the key is searched, and the parent-child association rules in that entry are modified or deleted according to the rule update instruction. Of course, in the scenario of adding a parent-child association rule, if the resource identifier of the second target node resource does not exist in the forward aggregation cache of each third target node resource, then the resource identifier of the second target node resource and its parent-child association rule are directly added to the end of the forward aggregation cache of each third target node resource. In the scenario of deleting a parent-child association rule, after deleting the resource identifier of the second target node resource and its parent-child association rule from the forward aggregation cache of each third target node resource, the reverse sourcing cache of the second target node resource in the reverse sourcing cache structure also needs to be deleted.

[0066] This invention solves the IO performance bottleneck caused by recursively traversing multi-level tree structures when association rules change by introducing a reverse tracing cache structure and a forward aggregation cache structure. Specifically, by using the ancestor link information pre-stored in the reverse tracing cache, it can directly locate all forward aggregation caches storing the corresponding parent-child association rules after receiving a rule update instruction, without performing time-consuming depth-first or breadth-first searches. Based on this, by utilizing the high-speed read and write characteristics of distributed caching, incremental updates are performed only on the specific cache key-value pairs affected, which not only significantly reduces the number of network IO operations and database load, but also effectively avoids the data inconsistency window caused by asynchronous update strategies. This bidirectional heterogeneous cache design enables O(1) level response speed in both high-concurrency price synchronization calculation scenarios and frequent rule adjustment scenarios, significantly improving real-time performance and reliability in large-scale resource management scenarios.

[0067] In one possible implementation, to maintain the consistency of the bidirectional cache, this application embodiment requests a distributed lock using the resource identifier of the root node resource, and updates the parent-child association rules of the second target node resource only after the distributed lock request is successful. To this end, this application embodiment provides a multi-level resource price synchronization calculation method, wherein the step "determining at least one third target node resource to be updated based on all resource identifiers in the reverse sourcing cache of the second target node resource" can be implemented using the following steps:

[0068] Obtain the resource identifier of the root node resource of the multi-level association tree from the reverse tracing cache of the second target node resource, and apply for a distributed lock using the resource identifier of the root node resource; if the distributed lock application is successful, determine at least one third target node resource based on all resource identifiers in the reverse tracing cache of the second target node resource.

[0069] In this embodiment, the resource identifier of the root node resource can be obtained from the reverse tracing cache of the second target node resource. A locking request is then initiated to the distributed lock service using this root node resource identifier. By locking the granularity of the distributed lock at the root node level, it ensures that all rule change operations under the same multi-level association tree can only be executed by one process at a time, thus avoiding cache data contention caused by multi-threaded concurrent modifications. If the distributed lock acquisition is successful, at least one third target node resource is determined, and subsequent parent-child association rule updates are executed. Therefore, this application constructs a mutex lock by obtaining a globally unique root node identifier, providing a prerequisite for maintaining cache consistency in high-concurrency scenarios, significantly improving data security in high-frequency rule change scenarios, and effectively preventing forward aggregation cache data corruption or overwriting loss caused by concurrent writes.

[0070] Furthermore, in the event of a failed distributed lock acquisition, the rule update instructions for the second target node resource are added to a queue. These instructions are then executed sequentially after the distributed lock is released. Specifically, in this embodiment, the queue is an ordered task queue for temporarily storing pending rule update instructions, serving as a buffer in high-concurrency scenarios to prevent request loss or service unavailability due to distributed lock resource contention. This queuing mechanism ensures that all rule update instructions targeting the same multi-level association tree are retained in an orderly manner, avoiding data update omissions caused by concurrency conflicts. After the distributed lock is released, the scheduler can automatically retrieve the next waiting rule update instruction from the head of the queue, re-triggering the lock acquisition and execution process. This significantly improves availability and throughput under high-concurrency loads while maintaining strong data consistency.

[0071] Based on the above description, the multi-level resource price synchronization calculation method provided in this application fundamentally eliminates the performance bottleneck caused by multi-level recursive queries, significantly improves system response speed and throughput, and ensures global consistency of price data at the moment of change through a synchronization calculation mechanism. This effectively solves the IO performance bottleneck and data consistency risk problems faced by existing technologies in high-concurrency scenarios. This application has the following advantages:

[0072] 1) Significantly improved computational performance: The number of network I / O operations for obtaining all parent-child association rules in the association cost calculation is optimized from O(N) to O(1). Taking a real business scenario as an example, when the level N=5 and the total number of nodes M=50 in the multi-level association tree, the existing solution requires 5 to 50 network I / O operations, while the present invention only requires 1, reducing I / O time by 80%~98%.

[0073] 2) Strong data consistency guarantee: By replacing asynchronous update with synchronous calculation, the price update of all related resources is completed within a single request, eliminating the data inconsistency window.

[0074] 3) High system availability and low load: Significantly reduces the QPS pressure of the distributed cache cluster. Taking a single IO failure rate of p=0.1% as an example, the overall success rate of 5 IOs is 99.5%, while the overall success rate of 1 IO is 99.9%, improving availability by about 0.4 percentage points.

[0075] 4) Good scalability: The computing performance is not affected by the depth and breadth of the association tree. Even if the business scale expands, the system can still maintain O(1) level IO performance.

[0076] The above describes a multi-level resource price synchronization calculation method provided by the embodiments of this application. The following will describe the apparatus for performing the above-described multi-level resource price synchronization calculation method.

[0077] See Figure 4 , Figure 4 This is a schematic diagram of a multi-level resource price synchronization calculation device provided in an embodiment of this application. Figure 4 As shown in the figure, an embodiment of this application provides a multi-level resource price synchronization calculation device, comprising:

[0078] The instruction acquisition module 401 is used to acquire the price synchronization instruction of the first target node resource, where the first target node resource is a node resource in a multi-level association tree.

[0079] The price synchronization module 402 is used to retrieve the constructed forward aggregation cache structure. The forward aggregation cache structure contains forward aggregation caches of non-leaf node resources in a multi-level association tree. The forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at the non-leaf node resource and their parent-child association rules when it is a parent node. Based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, the price of each node resource in the subtree rooted at the first target node resource is synchronized.

[0080] In one possible implementation, a price synchronization module 402, used to synchronize prices of resources in the subtree rooted at the first target node resource based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, is specifically used for:

[0081] The dependencies between corresponding resource identifiers are determined based on all parent-child association rules in the forward aggregation cache of the first target node resource; the parent-child association rules in the forward aggregation cache of the first target node resource are executed sequentially based on the dependencies to calculate the actual price corresponding to the corresponding resource identifier; the actual prices of all resource identifiers in the forward aggregation cache of the first target node resource are written in batches to the price storage to synchronously update the prices of each node resource in the subtree rooted at the first target node resource.

[0082] In one possible implementation, the instruction fetching module 401 is also used for:

[0083] Obtain the rule update instruction for the second target node resource, where the second target node resource is a node resource in a multi-level association tree;

[0084] The aforementioned multi-level resource price synchronization calculation device also includes:

[0085] The rule update module is used to retrieve the constructed reverse tracing cache structure. The reverse tracing cache structure contains the reverse tracing cache of non-root node resources in a multi-level association tree. The reverse tracing cache contains the resource identifiers of the parent resource nodes of the non-root node resources up to the root resource node. Based on all the resource identifiers in the reverse tracing cache of the second target node resource, at least one third target node resource to be updated is determined, and the parent-child association rules of the second target node resource are updated in the forward aggregation cache of at least one third target node resource.

[0086] In one possible implementation, the rule update module for determining at least one third target node resource to be updated based on all resource identifiers in the reverse sourcing cache of the second target node resource is specifically used for:

[0087] Obtain the resource identifier of the root node resource of the multi-level association tree from the reverse tracing cache of the second target node resource, and apply for a distributed lock using the resource identifier of the root node resource; if the distributed lock application is successful, determine at least one third target node resource based on all resource identifiers in the reverse tracing cache of the second target node resource.

[0088] In one possible implementation, the rule update module is also used for:

[0089] If the distributed lock acquisition fails, the rule update instructions for the second target node resource are added to the queue so that the rule update instructions in the queue are executed sequentially after the distributed lock is released.

[0090] It should be noted that the detailed functions of each module in the embodiments of this application can be found in the corresponding disclosure of the above-mentioned multi-level resource price synchronization calculation method embodiments, and will not be repeated here.

[0091] This application also provides an electronic device in its embodiments. See also... Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device in this embodiment may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0092] like Figure 5 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. When the electronic device is powered on, the RAM 503 also stores various programs and data required for the operation of the electronic device. The processing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0093] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, memory cards, hard drives, etc.; and communication devices 509. Communication device 509 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.

[0094] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the multi-level resource price synchronization calculation methods provided in this application.

[0095] This application also provides a computer-readable storage medium carrying one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the multi-level resource price synchronization calculation methods provided in this application.

[0096] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.

[0097] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0098] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.

[0099] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).

Claims

1. A method for simultaneous calculation of multi-level resource prices, characterized in that, The method for simultaneous calculation of multi-level resource prices includes: Obtain the price synchronization instruction for the first target node resource, where the first target node resource is a node resource in a multi-level association tree; Retrieve the constructed forward aggregation cache structure, which contains forward aggregation caches of non-leaf node resources in the multi-level association tree. The forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at the non-leaf node resource and their parent-child association rules when it is a parent node. Based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, price synchronization is performed on the resources of each node in the subtree rooted at the first target node resource.

2. The method for simultaneous calculation of multi-level resource prices according to claim 1, characterized in that, The step of synchronizing prices for resources in each node of the subtree rooted at the first target node resource, based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, includes: The dependency relationships between corresponding resource identifiers are determined based on all parent-child association rules in the positive aggregation cache of the first target node's resources; Based on the aforementioned dependency relationship, the parent-child association rules in the positive aggregation cache of the first target node resource are executed sequentially to calculate and obtain the actual price corresponding to the corresponding resource identifier; The actual prices of all resource identifiers in the forward aggregation cache of the first target node resource are written in batches to the price storage to synchronously update the prices of each node resource in the subtree rooted at the first target node resource.

3. The method for simultaneous calculation of multi-level resource prices according to claim 1, characterized in that, The multi-level resource price synchronization calculation method also includes: Obtain the rule update instruction for the second target node resource, where the second target node resource is a node resource in the multi-level association tree; Retrieve the constructed reverse tracing cache structure, which contains the reverse tracing cache of non-root node resources in the multi-level association tree, and the reverse tracing cache contains the resource identifiers of the parent resource nodes of the non-root node resources up to the root resource nodes. Based on all resource identifiers in the reverse tracing cache of the second target node resource, at least one third target node resource to be updated is determined, and the parent-child association rule of the second target node resource is updated in the forward aggregation cache of the at least one third target node resource.

4. The method for simultaneous calculation of multi-level resource prices according to claim 3, characterized in that, The step of determining at least one third target node resource to be updated based on all resource identifiers in the reverse tracing cache of the second target node resource includes: Obtain the resource identifier of the root node resource of the multi-level association tree from the reverse tracing cache of the second target node resource, and apply for a distributed lock using the resource identifier of the root node resource; If the distributed lock acquisition is successful, the at least one third target node resource is determined based on all resource identifiers in the reverse tracing cache of the second target node resource.

5. The method for simultaneous calculation of multi-level resource prices according to claim 4, characterized in that, The multi-level resource price synchronization calculation method also includes: If the distributed lock acquisition fails, the rule update instructions for the second target node resource are added to the queue so that the rule update instructions in the queue are executed sequentially after the distributed lock is released.

6. A multi-level resource price synchronization calculation device, characterized in that, The multi-level resource price synchronization calculation device includes: The instruction acquisition module is used to acquire the price synchronization instruction of the first target node resource, where the first target node resource is a node resource in a multi-level association tree; The price synchronization module is used to retrieve the constructed forward aggregation cache structure, which contains forward aggregation caches of non-leaf node resources in the multi-level association tree. The forward aggregation cache contains resource identifiers of each node resource in the subtree rooted at the non-leaf node resource and their parent-child association rules when it is a parent node. Based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, the module performs price synchronization on each node resource in the subtree rooted at the first target node resource.

7. The multi-level resource price synchronization calculation device according to claim 6, characterized in that, A price synchronization module, used to synchronize prices of resources in a subtree rooted at the first target node resource based on all resource identifiers and parent-child association rules in the forward aggregation cache of the first target node resource, specifically performs the following: The dependency relationships between corresponding resource identifiers are determined based on all parent-child association rules in the forward aggregation cache of the first target node resource; the parent-child association rules in the forward aggregation cache of the first target node resource are executed sequentially based on the dependency relationships to calculate the actual price corresponding to the corresponding resource identifier; The actual prices of all resource identifiers in the forward aggregation cache of the first target node resource are written in batches to the price storage to synchronously update the prices of each node resource in the subtree rooted at the first target node resource.

8. A computer program product, characterized in that, It includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the multi-level resource price synchronization calculation method as described in any one of claims 1 to 5.

9. An electronic device, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the multi-level resource price synchronous calculation method as described in any one of claims 1 to 5.

10. A computer storage medium, characterized in that, The storage medium carries one or more computer programs, which, when executed by an electronic device, enable the electronic device to implement the multi-level resource price synchronization calculation method as described in any one of claims 1 to 5.