A cross-service settlement and compensation consistency method and system based on tree-structured BOM node modeling
By using a tree-structured BOM node model and an adaptive compensation mechanism, the problems of low-latency writing and consistency of cross-service settlement data are solved. It achieves complete awareness and minimum cost compensation for explicit failures and silent forks, ensuring the security of financial data and the stability of the system.
Patent Information
- Application Number
- CN202611336292.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-17
AI Technical Summary
Without a cross-database coordinator, how can we achieve low-latency writing of cross-service settlement data, complete awareness of inconsistencies between explicit failures and silent forks, and minimum-cost child node-level compensation, while also addressing the issues of unreasonable utilization of fixed-period compensation scheduling resources and the inability to easily reconstruct financial data in payment failure scenarios?
The cross-service settlement process is abstracted into a tree-like BOM node model. The timing orchestration rules are defined through the set of dependency edges between nodes. The expected topology snapshot is constructed and child node writing is performed in parallel. The write receipt table and compensation log table are used to record the execution consistency verification. The compensation scheduling cycle is adaptively adjusted. Dual-channel detection of explicit failure and silent fork is adopted, and structured re-attack is used to handle payment failure.
It achieves low-latency writing, accurate compensation, reduces resource waste, ensures data consistency and financial security, reduces the risk of concurrency conflicts, and improves the stability and reliability of the system.
Smart Images

Figure CN123115140A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed data storage and consistency control technology, and in particular to a cross-service settlement compensation consistency method and system based on tree-structured BOM node modeling. Background Technology
[0002] In information systems such as flexible employment platforms and e-commerce order platforms, a cross-service settlement transaction can be abstracted as a tree-like BOM node model: the root node carries the main information such as the order subject, settlement batch or tax summary, while the child nodes carry detailed information such as order items, commissions, tasks, contracts, and settlement records. To support high-concurrency access and independent scaling, these nodes are split and stored in multiple independent database instances of microservices. For example, the root node and order item child nodes are located in the database instance of the business domain service, while the task child nodes and settlement child nodes are located in the database instance of the employment domain service. Completing a cross-service settlement requires writing hundreds to thousands of child node records across more than 30 data tables. Ensuring the consistency of settlement data writes across services and database instances becomes a core technical challenge.
[0003] Existing technologies mainly employ three types of solutions. The first type is the two-phase commit protocol, where the coordinator needs to complete two rounds of network round trips with all participants, one for the preparation phase and one for the commit phase. The overall latency increases linearly with the number of child nodes, typically exceeding 150ms. Furthermore, if the coordinator fails, the write locks held by participants who have prepared but not yet committed are not released, causing severe lock contention and latency jitter in concurrent scenarios with over 200 requests per second. The second type is TCC flexible transactions, which requires each child node's service provider to implement three interfaces: attempt, confirm, and cancel. This is highly intrusive, and the cancel interface faces issues of empty rollback and request hanging. The third category is an eventual consistency scheme based on local message tables and timed retries. This scheme has three unresolved drawbacks: First, it can only detect explicitly thrown failures in write operations, and cannot detect silent forks caused by partial truncation of batch writes or loss of write receipts, i.e., situations where the actual write result in the database is inconsistent with the expected write result but no failure log is generated; Second, its compensation granularity is the entire transaction, and the failure of a single child node writes to roll back all written child nodes, wasting high-cost operations such as completed third-party electronic signature calls; Third, the compensation scheduling uses fixed-period scanning, which wastes computing resources when the anomaly density is low, and convergence is slow when the anomaly density is high. In addition, existing batch settlement schemes put the entire batch of records into the same transaction. The failure of a single record verification leads to the rollback of the entire batch, and records that have been paid need to be compensated and refunded, increasing the complexity of reconciliation and financial risk.
[0004] Therefore, how to simultaneously achieve low-latency writes, complete awareness of both explicit failures and silent forks, node-level compensation with minimal cost, and fault isolation for batch operations without a cross-database coordinator has become an urgent technical problem to be solved. Summary of the Invention
[0005] This invention abstracts the cross-service settlement process into a tree-structured BOM (Business Orchestration Bill of Materials) node model. This model uses a settlement task as the root node and sub-tasks in three stages—settlement detail writing, tax result calculation, and payment instruction execution—as child nodes. The timing orchestration rules are defined through a set of dependency edges between nodes. Unlike manufacturing BOMs, the BOM nodes in this invention are not limited to the physical writing of database records; they also include computational and financial execution logical units. However, all nodes must generate fingerprintable execution traces in the write receipt table, thus uniformly incorporating them into a consistency verification framework.
[0006] The technical problem to be solved by this invention is: how to simultaneously achieve low-latency writing of cross-service settlement data based on a tree-structured BOM node model, complete awareness of two types of inconsistencies, explicit failure and silent forking, and minimum-cost child node-level compensation, without a cross-database coordinator, and further solve the problems of unreasonable utilization of fixed-period compensation scheduling resources, the inability to easily reconstruct financial data in payment failure scenarios, and concurrent state change conflicts.
[0007] To address the aforementioned technical problems, this invention provides a cross-service settlement and compensation consistency method based on tree-structured BOM node modeling, comprising: Step 1: Parsing the cross-service settlement request, constructing a tree-structured BOM node model, and building a desired topology snapshot based on the tree-structured BOM node model, calculating the desired consistency fingerprint using all desired child node identifiers, synchronously writing the root node record with the initial state field, and synchronously returning the root node identifier; Step 2: Executing the writing tasks of each child node in parallel according to the desired topology snapshot, with each child node writing task independently wrapped in a fault isolation block, recording a write receipt in the write receipt table when the write is successful, and recording a compensation log in the compensation log table when the write fails; Step 3: Querying the compensation log. The table determines whether there is an explicit failure, aggregates the write receipts to calculate the actual consistency fingerprint and compares it with the expected consistency fingerprint. If there is an explicit failure, the status field of the root node record is updated to the state to be compensated. If the comparison is inconsistent, regardless of whether there is an explicit failure, the set of forked child nodes is located according to the node type and the compensation log is rewritten, and the status field of the root node record is updated to the state to be compensated. If there is no explicit failure and the comparison is consistent, the status field of the root node record is updated to the confirmed state. Step 4: The compensation scheduler scans the abnormal root node records according to the adaptive scan cycle calculated by the abnormal root node density, and performs idempotent cleanup and rewriting on the child nodes with compensation logs in descending order of compensation priority score.
[0008] Furthermore, the expected topology snapshot includes the node type, target service identifier, target table name, target shard identifier, expected write quantity, write data, and set of inter-node dependency edges for each expected child node. The write data consists of the field values and row content of the corresponding expected child node business record. The expected consistency fingerprint is obtained by concatenating all expected child node identifiers in lexicographical order and then performing a secure hash algorithm. The expected topology snapshot and the expected consistency fingerprint are written to the root node shadow table associated with the root node record.
[0009] Furthermore, in step 2, a directed acyclic write task graph is constructed based on the set of inter-node dependency edges, and the topology is layered. The number of threads in the thread pool is the minimum of the number of processor cores and the number of child node write tasks in the same topology layer. Multiple child node write tasks with the same target shard identifier and target table name are merged into one batch write statement for execution. The fault isolation block is an independent exception catching code block. When an exception is caught, only the compensation log is recorded and the exception is not thrown to the upper layer. The write receipt includes the root node identifier, child node identifier, node type, actual number of rows written, and row content checksum. The compensation log includes the root node identifier, node type, child node identifier, exception information, first failure timestamp, and number of retries.
[0010] Furthermore, in step 3, when there is a discrepancy in the comparison, regardless of whether there is an explicit failure, the expected topology snapshot and the write receipt are grouped by node type to calculate the type sub-fingerprint, the fork node type is determined by comparing the node types one by one, the fork child node set is located by comparing the identifiers one by one within the fork node type and the compensation log is supplemented, and the status field recorded by the root node is updated to the state to be compensated.
[0011] Furthermore, the adaptive scan period is calculated according to the formula... The density of abnormal root nodes is calculated as the ratio of the number of abnormal root nodes hit in each scan round to the total number of root nodes scanned; the compensation priority score is calculated according to the formula. The calculation process involves rewriting cost weights by querying the cost weight table, retry counts by reading from the compensation log table, and normalized retention time by calculating the ratio of retention time to baseline scan cycle. Idempotent cleanup physically deletes partially written child nodes and skips cleanup for unwritten child nodes. Child nodes with more than 3 retries are moved to the dead-letter queue. When the compensation log is completely cleared and the fingerprints are consistent, the root node record is updated to the confirmed state.
[0012] Furthermore, it also includes step 5: when payment fails, a structured refactoring is performed, which involves dual-condition scanning, same task identifier verification, grouping and summarizing by user identifier, atomic auto-incrementing to generate a new batch number, creating a new batch record and a new settlement record, assigning the settlement record to three source data remapping sub-processes according to the settlement record type, batch canceling old settlement records with dual-condition optimistic locking and verifying the actual number of updated rows, and then the new settlement record re-enters the payment process.
[0013] Furthermore, the root node record also includes a version number field. All update operations on the status field of the root node record carry the old value of the status field and the old value of the version number field as update conditions. When the actual number of updated rows is 0, a version conflict is determined, the latest version number field value is reread, the changed content is merged, and the operation is re-executed, with a maximum of 3 times.
[0014] The present invention also provides a cross-service settlement compensation consistency system based on tree-structured BOM node modeling, including: a root node commit module, a child node parallel write module, a dual-channel consistency detection module, and an adaptive compensation scheduling module, each module being used to execute steps 1 to 4 of the above method.
[0015] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method.
[0016] The beneficial effects of this invention are: 1. Root node commit first makes the write latency perceived by the caller converge to the single-point write latency of the root node, which does not exceed 5ms; dependency-aware topology hierarchical parallel write makes the latency of all child node confirmations depend on the longest dependency path rather than the total number of child nodes. 2. It is expected that the combination of topological snapshot and dual-channel inconsistency detection will cover two types of inconsistency: explicit failure and silent fork. When only fingerprint comparison is inconsistent, the fork range can be converged from the entire tree to the specific set of fork child nodes according to the node type, so as to realize discovery and location and compensation. 3. The compensation granularity is accurate to a single child node, and child nodes that have been successfully written to are not touched; the adaptive scanning cycle expands and contracts with the density of abnormal root nodes, and the compensation priority scoring prioritizes the recovery of high-cost and high-latency child nodes. Compensation resources are allocated according to the abnormal situation in both scanning timing and compensation order. 4. Structured restructuring preserves original financial data for full traceability; dual-condition optimistic locking atomic cancellation, combined with actual update row verification, prevents duplicate payments caused by the simultaneous effect of old and new settlement records; and line-by-line fault isolation ensures that the failure of a single record in batch operations does not affect the remaining records in the same batch. 5. Version number optimistic locking does not hold long locks, and concurrency conflicts are resolved through rereading, merging, and retrying, ensuring the correctness of state changes in high-concurrency scenarios. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, those skilled in the art can obtain other drawings based on these drawings without creative effort.
[0018] Figure 1 The overall flowchart of the cross-service settlement and compensation consistency method based on tree-structured BOM node modeling provided in this embodiment of the invention; Figure 2 This is a flowchart of dual-channel inconsistency detection provided in an embodiment of the present invention; Figure 3 A flowchart of adaptive compensation scheduling provided in an embodiment of the present invention; Figure 4 This is a flowchart of a structured refactoring process in a payment failure scenario provided by an embodiment of the present invention; Figure 5 This is a structural block diagram of a cross-service settlement and compensation consistency system based on tree-structured BOM node modeling, provided in an embodiment of the present invention. Detailed Implementation
[0019] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. It should also be noted that, to make the embodiments more comprehensive, the following embodiments are the best and preferred embodiments, and those skilled in the art can use other alternative methods to implement some well-known technologies; moreover, the accompanying drawings are only for more specific description of the embodiments and are not intended to specifically limit the present invention.
[0020] according to Figure 1-5 As shown, the tree-structured BOM node model of this invention is not limited to the physical bill of materials, but broadly refers to the set of nodes with temporal dependencies that must be executed to complete a settlement task in cross-service settlement operations. This model uses the settlement task context as the root node, and the parallel execution of settlement detail writing nodes, tax calculation nodes dependent on previous results, and payment chain orchestration nodes dependent on tax results as child nodes. A complete logical topology from data readiness to result calculation and then to fund execution is established through the set of inter-node dependency edges. This model is used to determine the execution boundaries, temporal orchestration order, and compensation boundaries of each child node. In this invention, the root node record is stored in the database instance of the business domain service, and the child node records are stored in the database instances of both the business domain service and the user domain service.
[0021] The expected topology snapshot is a structured record of the entire intent of a cross-service settlement write operation organized based on a tree-like BOM node model. It includes seven items for each expected child node: node type, target service identifier, target table name, target shard identifier, expected write quantity, write data, and a set of inter-node dependency edges. The write data consists of the field values and row content of the corresponding expected child node's business record, persisted along with the expected topology snapshot to the root node's shadow table as the data source for rewriting during the compensation phase. The target shard identifier determines the scope of batch merging; only child node write tasks with the same target shard identifier and target table name can be merged into a single batch write statement to avoid the inability to locate failure details when cross-shard batch writes fail. The set of inter-node dependency edges is generated by the timing orchestration rules between expected child nodes, specifically including three categories: Data-writing child nodes have no dependency edges and execute in full parallel; computational child nodes generate convergent dependency edges with all data-writing child nodes, where convergent dependency uses AND semantics, meaning the computational child node can only execute after all preceding data-writing child nodes have confirmed their status; and fund execution child nodes generate serial dependency edges with computational child nodes, meaning the fund execution child node can only execute after the tax calculation result is stored in the database. Topology layering ensures that the preceding child nodes that are depended upon execute before the dependent nodes.
[0022] In this invention, child nodes are divided into three types based on execution semantics: data writing nodes, corresponding to the persistent writing of settlement records for each project, located at the first topology level, with no dependencies between them, and all executions are parallel; calculation nodes, corresponding to the calculation and writing of tax calculation results, located at the second topology level, and dependent on all data writing nodes through AND aggregation; and fund execution nodes, corresponding to the execution of payment instructions, located at the third topology level, and dependent on the tax calculation results of calculation nodes. Although calculation nodes and fund execution nodes are not simply database record writes, their execution results are all stored in the database and generate fingerprintable execution traces in the write receipt table, thus being included in the consistency verification framework along with data writing nodes. Taking a cross-service settlement task as an example: the root node is the settlement task context; the first level consists of data writing nodes corresponding to each settlement order; the second level consists of calculation nodes merging tax calculation results, which aggregate dependencies on all data writing nodes; the third level consists of fund execution nodes such as Alipay transfers, which trigger the platform wallet deposit node when an Alipay transfer fails, followed by the user withdrawal node.
[0023] The expected consistency fingerprint, actual consistency fingerprint, and type sub-fingerprint are all calculated using the same secure hash algorithm. This embodiment uses the SHA-256 algorithm and extracts the first 128 bits of the result as the fingerprint value. Before calculation, all identifiers are sorted lexicographically and then concatenated. The purpose of sorting is to eliminate the influence of the identifier order on the hash result, ensuring that the same set of identifiers corresponds to a unique fingerprint, thereby making fingerprint comparison deterministic. The row content checksum is calculated using the CRC-64 cyclic redundancy check algorithm on all fields of the written row. This is used to detect whether there is content-level truncation in the data already partially written to the target table before compensation rewriting.
[0024] Silent forks refer to a situation where the actual write result to the database is inconsistent with the expected write result, but no failure log is generated. There are two typical causes: The first is that the batch write statement is partially written to the database during a network interruption, and the database driver layer does not throw an exception to the upper layer. For the first cause, write receipts are generated according to the child nodes that are actually written to the database: After the batch write statement is executed, the number of affected rows returned by the database driver layer is compared with the expected number of rows to be written by the batch write statement. If they match, write receipts are generated for all child nodes in the batch. If they do not match, a check is triggered by identifier. The target table is queried one by one according to the identifier of each child node in the batch to confirm whether it has been written to the database. Write receipts are only generated for child nodes that have been confirmed to have been written to the database. No write receipts are generated for child nodes that have not been written to the database, so that they can be detected in the consistency fingerprint comparison channel. The second is that the write action is actually successful, but the success receipt is lost in cross-service transmission, resulting in the lack of corresponding records in the write receipt table. In dual-channel inconsistency detection, the first channel detects explicit failures through the compensation log table, while the second channel detects silent forks by comparing the actual consistency fingerprint with the expected consistency fingerprint. The combination of these two channels covers two types of inconsistency scenarios. When anomalies are detected only through the second channel, type sub-fingerprints are calculated separately for each node type and compared type by type. This narrows the fork range from the entire tree to a single node type. Then, within each fork node type, a marker-by-mark comparison locates the specific set of fork child nodes, ensuring that subsequent compensation is accurate to a single child node without needing to reach successfully written child nodes.
[0025] It should be noted that the consistency fingerprint comparison channel described in this invention aims to verify the write integrity of tree-structured BOM nodes, that is, whether the expected set of nodes to be executed is consistent with the actual set of nodes to be executed, to prevent nodes from being missed, silently lost, or repeatedly executed; for the business correctness of the tax calculation result itself, this invention adopts independent tax calculation rule recalculation verification: when a refund triggers a structured re-damage, the tax calculation logic is re-executed based on the remaining valid nodes, and the new tax calculation fingerprint is compared with the historical tax calculation fingerprint according to business rules.
[0026] Regarding the update conditions for the status field of the root node record, there are two levels: the upper level uses the old value of the status field as the update condition; in the lower level where concurrency safety control is enabled, the update operation carries both the old value of the status field and the old value of the version number field as update conditions. These two levels are inclusive and do not contradict each other.
[0027] The values of each parameter in the adaptive scan cycle formula are based on the reference scan cycle. The value is 30s, consistent with the business-tolerable final convergence time; lower limit of scan cycle. The value is set to 5 seconds to prevent excessive scanning during periods of extremely high abnormal density, which could put additional strain on the database; sensitivity coefficient The value is 2, which is calibrated by production environment stress test data. For every 0.1 increase in the density of abnormal root nodes, the scan cycle is shortened by about 17%. The preset time threshold is 30s, which is consistent with the baseline scan cycle. It is used to identify unacknowledged root nodes that have timed out due to the crash of the write thread pool.
[0028] In the compensation priority scoring formula, the weighting coefficient The values are 0.5, 0.3, and 0.2 respectively, with a sum of 1. Child nodes with higher rewrite cost weights take longer to rewrite; child nodes with more retries have higher recovery difficulty; and child nodes with longer normalized dwell times have longer suspension times. These three factors are weighted and executed in descending order, ensuring that limited compensation resources are prioritized for the failed child nodes with the greatest recovery benefit. The normalized dwell time is the ratio of dwell time to the baseline scan period, aiming to eliminate the dimensional difference between time-based and dimensionless factors. The cost weight table is maintained by the moving average of historical write times for each node type, with the sliding window containing the most recent 100 write records.
[0029] Dead letter queues are queues used to temporarily store records that require manual intervention. Records entering the dead letter queue trigger an alarm notification and are then manually processed and archived.
[0030] Structured refactoring is designed for payment failure scenarios. Payments involve real fund transfers, and old settlement records cannot be simply deleted and rebuilt; otherwise, the fund flow would lose its traceability. Structured refactoring ensures that only one settlement record is active at any given time through three actions: creating a new settlement record that inherits the amount and attendance data from the old one, remapping the foreign keys of the related source data records to the new settlement record identifier, and then atomically canceling the old settlement record using a two-condition optimistic lock. The actual number of updated rows is checked to prevent the status of the old record from being changed before cancellation due to concurrent payments. If the check fails, the entire operation is rolled back to prevent duplicate payments caused by the simultaneous effectiveness of the old and new records. The rollback is achieved through a reverse compensation chain: for each write action executed in the structured refactoring, a corresponding reverse compensation action is recorded sequentially; if the verification fails, each reverse compensation action is executed in reverse order of the write sequence, including deleting the newly created settlement record and new batch record, and restoring the identifier field of the remapped source data record to its old value; each reverse compensation action is executed locally within the database instance of the corresponding service, without the need for a cross-database coordinator; when the reverse compensation action itself fails, the failure details are recorded and an alarm notification is sent, and the corresponding settlement record is moved to the dead-letter queue for manual intervention.
[0031] Example 1: Writing Flexible Employment Order Settlement Data Based on a Tree-like BOM Node Model A chain restaurant tenant places an order for 1,000 part-time positions on a flexible employment platform. The tree-structured BOM node model corresponding to the settlement task of this order is as follows: the root node is the settlement task context record, stored in the database instance of the business domain service; the child nodes include 1,000 product item records, 1 commission record, 50 task records, 1 contract record, 1 settlement batch record, and 1,000 settlement records. Among them, the product item records and commission records are stored in the database instance of the business domain service, while the task records, contract records, settlement batch records, and settlement records are stored in the database instance of the employment domain service.
[0032] Step 1 execution process: Parse the cross-service settlement request, construct a tree-structured BOM node model, and obtain a set of child node details containing 1053 child node details from the tree-structured BOM node model. The expected write quantity for each type of node is obtained from the number of entries: 1000 product items, 1 commission, 50 tasks, 1 contract, 1 settlement batch, and 1000 settlement records. A root node identifier 1001 and 1053 globally unique expected child node identifiers are generated. The execution of the contract child node depends on the data readiness of the corresponding task child node in time sequence. 50 serial dependency edges are generated from the contract child node to the task child node, forming a set of inter-node dependency edges. All expected child node identifiers are sorted lexicographically, concatenated, and then subjected to SHA-256 computation, with the first 128 bits truncated to obtain the expected consistency fingerprint. The root node record is synchronously written to the database instance of the commercial domain service. The status field is set to the initial state, the version number field is set to 1, the expected topology snapshot and the expected consistency fingerprint are written to the root node shadow table, and the write takes 4ms. The root node identifier 1001 is returned synchronously, and the caller obtains the order voucher at this time.
[0033] Step 2 execution process: Construct a directed acyclic write task graph and topologically layer it based on the set of dependency edges between nodes: task child nodes, product item child nodes, commission child nodes, and settlement batch child nodes are in the first topological layer, and contract child nodes and settlement record child nodes are in the second topological layer. The server processor has 8 cores, the number of write tasks for child nodes in the first topological layer is 1052, and the number of threads in the thread pool is the minimum of 8 and 1052, i.e., 8. The target shard identifier and target table name of the product item child nodes are the same, and every 500 records are merged into 1 batch write statement, for a total of 2 statements; the settlement records are similarly merged into 2 batch write statements. Two types of exceptions occur during execution: When the second batch of settlement records is written, the target shard connection times out, the exception is thrown, and after the fault isolation block captures it, 1 compensation log is written to the compensation log table, with the child node identifier being... The retry count is set to 0, and the timestamp of the first failure is recorded. No exception is thrown to the upper layer. During the second batch of product item writes, there was a brief network interruption. Only 450 records were actually written to the database, and the database driver layer did not throw an exception. No compensation log was generated, resulting in a silent fork with 50 records missing. The number of affected rows returned by this batch write statement was 450, which was inconsistent with the expected number of 500 rows to be written. This triggered a check by identifier, and only the child nodes of the 450 product items that were actually written to the database generated write receipts. After the remaining child nodes were successfully written, write receipts were written to the write receipt table. Each write receipt includes the root node identifier, child node identifier, node type, actual number of rows written, and row content checksum.
[0034] Step 3 execution process: After all write tasks are completed, a dual-channel inconsistency detection is triggered. Channel 1 queries the compensation log table with root node identifier 1001 and finds one explicit failure record. Channel 2 aggregates the write receipt table. The number of child node identifiers in the write receipt is 1002, which is inconsistent with the expected total number of writes of 1053. The child node identifiers in the write receipt are sorted in lexicographical order, concatenated, and subjected to SHA-256 operation to obtain the actual consistency fingerprint, which is inconsistent with the expected consistency fingerprint. Subsequently, type sub-fingerprints are calculated and compared type by type according to node type: the type sub-fingerprint of the product item type does not match, while the other 5 types match, determining that the fork node type is the product item type. Within the product item type, the identifiers are compared one by one, locating 50 missing expected child node identifiers, forming a fork child node set, and compensation logs are written for each fork child node. Finally, using the old value of the status field as the initial state and the old value of the version number field as 1 as the update conditions, the status field of the root node record is updated to the state to be compensated, and the version number field is updated to 2. The actual number of rows updated is 1, and the update is successful.
[0035] Step 4 execution process: During the k-th round of scanning by the compensation scheduler, the total number of root nodes scanned is 50,000, the number of abnormal root nodes hit is 400, and the density of abnormal root nodes is:
[0036] The scanning period for the (k+1)th round is:
[0037] As a comparison, during the fault injection stress test period, the density of abnormal root nodes was 0.4, and the scan cycle was shortened to:
[0038] After the compensation scheduler scans the root node record with root node identifier 1001, it queries the compensation log table and obtains 51 compensation logs. It then calculates the compensation priority score for each child node with a compensation log. The rewriting cost weight for settlement record type in the cost weight table is 0.8, and the rewriting cost weight for product item type is 0.2. The number of retries was 0, the dwell time was 35 seconds, the normalized dwell time was the ratio of 35 to 30 seconds (1.17), and the compensation priority score was:
[0039] The compensation priority score for the forked child nodes of the product item is as follows:
[0040] Compensation will be awarded in descending order of priority, with priority given to those who receive the highest compensation. Idempotent cleanup was detected. After partial writing to the target table and physical deletion by child node identifier, the data was rewritten based on the corresponding write data in the expected topology snapshot. The write was successful, the corresponding compensation log was cleared, and a write receipt was added. Subsequently, the 50 product item forked child nodes were merged into a single batch write statement and rewritten, all of which were successful. After clearing all compensation logs, the actual consistency fingerprint was recalculated and matched the expected consistency fingerprint. Using the old value of the status field as the pending compensation state and the old value of the version number field as 2 as update conditions, the status field of the root node record was updated to the confirmed state, and the version number field was updated to 3. The entire process from root node record creation to final consistency convergence took 35 seconds, of which approximately 34 seconds were spent from the write failure to compensation recovery.
[0041] The execution process of concurrency safety control: After the root node record is in the confirmed state, the caller simultaneously initiates a payment confirmation request and an order cancellation request. Both requests carry the old value 3 of the version number field. The payment confirmation request performs the update first, with 1 row actually updated and the version number field updated to 4. In the order cancellation request, the old value 3 of the version number field in the update condition has become invalid, and 0 rows are actually updated. A version conflict is determined, the latest version number field of the root node record is read again and the value is 4, the changed content is merged, and the update operation is re-executed. The first retry is successful. No long locks are held throughout the process.
[0042] Example 2: Structured Restructuring After Payment Failure There are 3 settlement records under a certain settlement batch with the identifier 4001, belonging to user identifiers 101, 102 and 103 respectively. All of them failed to pay due to insufficient available balance in the operator's settlement account.
[0043] A dual-condition scan batch 4001, with a record status of "pending settlement" and a payment status of "payment failed," yielded a set of 3 settlement records. Verification showed that all 3 settlement records shared the same task ID (3001), indicating they belonged to the same task ID; the verification passed. The records were then grouped and summarized by user ID: User ID 101 corresponds to a group payable amount of 5000.00 yuan and a group attendance duration of 8.0 hours; User ID 102 corresponds to a group payable amount of 6000.00 yuan and a group attendance duration of 10.0 hours; User ID 103 corresponds to a group payable amount of 4500.00 yuan and a group attendance duration of 7.5 hours. A new batch number JS20260816002 is generated using the atomic increment instruction of the distributed cache. A new batch record is created with a batch identifier of 4002. Three new settlement records are created and assigned new new settlement record identifiers. The amount due and attendance duration of each new settlement record are taken from the group's amount due and attendance duration, respectively. In this embodiment, each group has only one old settlement record, and the group summary value is equal to the value of the corresponding old settlement record.
[0044] All three old settlement records are task settlement types. The source data remapping sub-process for task settlement types is as follows: update the settlement record identifier field of the attendance summary record to the new settlement record identifier, and update the settlement record identifier field of the advance salary record to the new settlement record identifier. For promotion settlement type settlement records, the corresponding source data remapping sub-process is as follows: update the settlement record identifier field of the promotion settlement record to the new settlement record identifier, and simultaneously update the batch number field of the promotion settlement record to the new batch number. For advance settlement type settlement records, the corresponding source data remapping sub-process is as follows: update the advance settlement record identifier field of the advance salary record to the new settlement record identifier.
[0045] After remapping, three old settlement records are batch-cancelled using a two-condition optimistic lock with the old record status being "pending settlement" and the old payment status being "payment failed." The actual number of updated rows is three, equal to the number of old settlement records. Verification passes, and the cancellation takes effect. A new batch identifier (4002) is returned, and the three new settlement records re-enter the payment process and are successfully paid. If the structured remapping fails three consecutive times, the corresponding settlement record is moved to a dead-letter queue, and an alarm notification is sent for manual intervention.
[0046] Example 3: System Composition and Data Flow This embodiment provides a cross-service settlement and compensation consistency system based on tree-structured BOM node modeling, including a root node commit module, a child node parallel write module, a dual-channel consistency detection module, and an adaptive compensation scheduling module.
[0047] The root node submission module includes a request parsing unit, a desired topology snapshot construction unit, a desired consistency fingerprint calculation unit, and a root node writing unit. The request parsing unit receives cross-service settlement requests, constructs a tree-structured BOM node model, and obtains a detailed set of child nodes from the tree-structured BOM node model; the desired topology snapshot construction unit generates desired child node identifiers and a set of dependency edges between nodes, and assembles the desired topology snapshot; the desired consistency fingerprint calculation unit performs sorting concatenation and secure hashing algorithm operations; and the root node writing unit synchronously writes root node records to the database instance of the commercial domain service and synchronously returns the root node identifier to the caller.
[0048] The child node parallel write module includes a task graph construction unit, a topology layering unit, a thread pool scheduling unit, a shard merging unit, a fault isolation execution unit, and a write receipt recording unit. The task graph construction unit constructs a directed acyclic write task graph based on the set of dependency edges between nodes; the topology layering unit outputs a topology hierarchy sequence; the thread pool scheduling unit configures the thread pool according to the minimum value between the number of processor cores and the number of tasks at the same level; the shard merging unit merges child node write tasks with the same target shard identifier and target table name into batch write statements; the fault isolation execution unit executes each child node write task with an independent exception handling code block; and the write receipt recording unit writes a write receipt to the write receipt table when the write is successful and a compensation log to the compensation log table when the write fails.
[0049] The dual-channel consistency detection module includes an explicit failure detection unit, an actual consistency fingerprint calculation unit, a silent fork location unit, and a state transition unit. The explicit failure detection unit queries the compensation log table; the actual consistency fingerprint calculation unit aggregates and writes data to the receipt table and calculates the actual consistency fingerprint; the silent fork location unit calculates type sub-fingerprints based on node type and locates the set of fork child nodes; and the state transition unit migrates the state fields of the root node record according to the dual-channel detection results.
[0050] The adaptive compensation scheduling module includes a scan cycle adaptive calculation unit, an abnormal root node scanning unit, a compensation priority sorting unit, an idempotent cleanup and rewrite unit, and a dead letter handling unit. The scan cycle adaptive calculation unit calculates the adaptive scan cycle based on the abnormal root node density; the abnormal root node scanning unit scans abnormal root node records according to the adaptive scan cycle; the compensation priority sorting unit calculates the compensation priority score and sorts them in descending order; the idempotent cleanup and rewrite unit performs idempotent cleanup and rewriting; and the dead letter handling unit moves the corresponding child node into the dead letter queue and sends an alarm notification when the number of retries exceeds 3.
[0051] The data flow between the modules of the above system is as follows: the output of the root node commit module is the input of the child node parallel write module; the output of the child node parallel write module is the input of the dual-channel consistency detection module; the output of the dual-channel consistency detection module is the input of the adaptive compensation scheduling module; and the convergence result of the adaptive compensation scheduling module is written back to the root node record. This embodiment also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the methods described in the above embodiments.
[0052] Comparative Example: Cross-Database Two-Phase Submission Scheme To verify the technical effect of the present invention, a comparative example was set up. The comparative example used a cross-database two-phase commit scheme based on the XA specification to handle an order creation request identical to that in Example 1. Specifically, one transaction coordinator and two transaction participants were set up, with the two participants corresponding to the database instances of the business domain service and the employment domain service, respectively. The first phase was the preparation phase, where the transaction coordinator sent a preparation request to the two participants. Each participant wrote all 1053 records but did not commit, holding write locks on all written rows. The transaction coordinator waited for all participants to return a ready response, taking 78ms. The second phase was the commit phase, where the transaction coordinator sent a commit instruction to all participants. Each participant committed the transaction and released the write locks, taking 74ms. The total latency perceived by the caller was 152ms. When the settlement record... When a write operation fails, the transaction coordinator sends a rollback command to all transaction participants. All 1052 successfully written records are rolled back. The completed third-party e-signature calls have already incurred costs and cannot be reversed; the failure of a single record affects the entire transaction. The counterparty lacks silent fork detection capabilities. When a portion of the data is written in batches and the driver layer does not throw an exception, the coordinator still considers the preparation successful and commits, leaving an inconsistent state permanently. The counterparty manually investigates and repairs data inconsistencies, with an average recovery time of 1800 seconds. Under a concurrent stress test of 200 requests per second, the counterparty, holding write locks during the preparation phase, experiences a peak response latency jitter of 420ms at the matching interface.
[0053] The comparison results are shown in Table 1: Table 1
[0054] As shown in Table 1, the solution of the present invention is significantly better than the comparative solution in terms of caller-aware write latency, fault impact area, silent fork detection capability, compensation recovery time, and concurrency stability.
[0055] This invention encompasses any substitutions, modifications, equivalent methods, and solutions made within the spirit and scope of this invention. To provide the public with a thorough understanding of this invention, specific details are described in detail in the following preferred embodiments; however, those skilled in the art will fully understand the invention even without these details. Furthermore, to avoid unnecessary misunderstanding of the essence of this invention, well-known methods, processes, procedures, components, and circuits are not described in detail.
[0056] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A cross-service settlement and compensation consistency method based on tree-structured BOM node modeling, characterized in that, include: Step 1: Parse the cross-service settlement request, construct a tree-structured BOM node model, and construct a desired topology snapshot based on the tree-structured BOM node model. Calculate the desired consistency fingerprint using all desired child node identifiers, synchronously write the root node record with the initial state in the status field, and synchronously return the root node identifier. Step 2: Execute the write task of each child node in parallel according to the desired topology snapshot. Each child node write task is independently wrapped in a fault isolation block. When the write is successful, record the write receipt in the write receipt table. When the write fails, record the compensation log in the compensation log table. Step 3: Query the compensation log table to determine if there is an explicit failure. Aggregate the write receipts in the write receipt table to calculate the actual consistency fingerprint and compare it with the expected consistency fingerprint. If there is an explicit failure, update the status field of the root node record to the pending compensation state. If the comparison is inconsistent, regardless of whether there is an explicit failure, locate the set of forked child nodes according to the node type and write the compensation log, and update the status field of the root node record to the pending compensation state. If there is no explicit failure and the comparison is consistent, update the status field of the root node record to the confirmed state. Step 4: The compensation scheduler scans the abnormal root node records according to the adaptive scan cycle calculated from the abnormal root node density, and performs idempotent cleanup and rewriting on the child nodes with compensation logs in descending order of compensation priority score.
2. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 1, characterized in that, Step 1 includes: The tree-structured BOM node model is a logical orchestration dependency tree model abstracted from the cross-service settlement process. It takes the settlement task context of a settlement task as the root node and the sub-tasks of the three stages—settlement detail writing, tax result calculation, and payment instruction execution—as sub-nodes. These sub-nodes include data writing sub-nodes, calculation sub-nodes, and fund execution sub-nodes. The tree-structured BOM node model is used to determine the execution boundaries, timing orchestration order, and compensation boundaries of each sub-node. The cross-service settlement request is parsed, the tree-structured BOM node model is constructed, and a set of sub-node details is obtained from the tree-structured BOM node model. Each sub-node detail in the set includes node type, target service identifier, target table name, and target shard identifier. The expected write quantity corresponding to each node type is obtained by collecting the number of entries in the sub-node details. A globally unique expected sub-node identifier is generated for each expected sub-node. The expected topology snapshot includes the node type, target service identifier, target table name, target shard identifier, expected write quantity, and write... The data and the set of inter-node dependency edges, wherein the written data is the field values and row content of the corresponding expected child node business record, the set of inter-node dependency edges is generated by the temporal orchestration rules between expected child nodes, the temporal orchestration rules include: no dependency edges between data writing child nodes; convergence dependency edges between computational child nodes and all data writing child nodes; serial dependency edges between fund execution child nodes and computational child nodes; the calculation of the expected consistency fingerprint from all expected child node identifiers includes: sorting all expected child node identifiers in lexicographical order and concatenating them into an identifier string, performing a secure hash algorithm operation on the identifier string, and using the operation result as the expected consistency fingerprint; synchronously writing the root node record to the database instance of the commercial domain service, the root node record including the root node identifier and a status field, writing the expected topology snapshot and the expected consistency fingerprint to the root node shadow table associated with the root node record; the synchronous return of the root node identifier means: the root node identifier is returned to the caller as soon as the root node record is successfully written, without waiting for the execution result of any child node write task.
3. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 2, characterized in that, Step 2 includes: constructing a directed acyclic write task graph based on the set of inter-node dependency edges; performing topological layering on the directed acyclic write task graph, ensuring that there are no dependency edges between child node write tasks at the same topological layer; starting a thread pool to execute child node write tasks, wherein the number of threads in the thread pool is the minimum of the number of processor cores and the number of child node write tasks at the same topological layer; executing child node write tasks within the same topological layer in parallel, and executing child node write tasks at different topological layers in the order of dependency; merging multiple child node write tasks with the same target shard identifier and the same target table name into a single batch write statement for execution; the fault isolation block is: each child node write task is wrapped in an independent exception handling code block, and only when an exception is caught... The system records compensation logs without throwing exceptions to the upper layer. The failure of a single child node write task does not affect the execution of write tasks for other child nodes. The write receipt includes the root node identifier, child node identifier, node type, actual number of rows written, and row content checksum. The write receipt is generated based on the child nodes that are actually written to the database: after the batch write statement is executed, if the number of affected rows returned by the database driver layer is consistent with the expected number of rows written by the batch write statement, a write receipt is generated for all child nodes in the batch; if they are inconsistent, the target table is checked back row by row according to the identifier of each child node in the batch, and a write receipt is generated only for the child nodes that are confirmed to have been written to the database. The compensation log includes the root node identifier, node type, child node identifier, exception information, first failure timestamp, and number of retries, with the initial value of the number of retries being 0.
4. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 2, characterized in that, Step 3 includes: dual-channel inconsistency detection is triggered after all child node write tasks are completed; the write receipt includes child node identifiers; querying the compensation log table to determine if there is an explicit failure means: querying the compensation log table with the root node identifier as the query condition, and determining that there is an explicit failure when the query result is not empty; calculating the actual consistency fingerprint means: aggregating the write receipts in the write receipt table with the root node identifier as the query condition, sorting the child node identifiers of all write receipts in lexicographical order and concatenating them into a receipt identifier string, performing the same secure hash algorithm operation as calculating the expected consistency fingerprint on the receipt identifier string, and using the operation result as the actual consistency fingerprint; the step of classifying by node The set of forked child nodes for positioning includes: grouping the expected child node identifiers in the expected topology snapshot by node type and calculating type sub-fingerprints for each; grouping the child node identifiers of the write receipt by node type and calculating type sub-fingerprints for each; comparing the type sub-fingerprints on both sides of each node type; determining the node types with inconsistent comparisons as forked node types; comparing the expected child node identifiers with the child node identifiers of the write receipts for each identifier within the forked node type; determining the missing expected child node identifiers as the set of forked child nodes; and writing compensation logs for each forked child node in the set of forked child nodes; the updates to the status fields recorded by the root node are all based on the old values of the status fields as update conditions.
5. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 1, characterized in that, The formula for calculating the adaptive scan period in step 4 is as follows: In the formula: The (k+1)th scan cycle is expressed in seconds. The baseline scan period is 30 seconds. This is the lower limit of the scan cycle, with a value of 5 seconds. This is the sensitivity coefficient; The abnormal root node density is obtained from the statistical analysis of the k-th scan. The abnormal root node density is collected as follows: the compensation scheduler counts the number of abnormal root nodes hit and the total number of root nodes scanned during the k-th scan, and uses the ratio of the number of abnormal root nodes to the total number of root nodes as the abnormal root node density. The scanned abnormal root node records refer to: root node records whose scan status field is in the state to be compensated, and root node records whose status field is in the initial state and whose creation time is more than a preset time threshold from the current time. The preset time threshold is 30s.
6. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 5, characterized in that, The calculation formula for the compensation priority score mentioned in step 4 is as follows: In the formula: Score the compensation priority for the i-th child node that has a compensation log record; To determine the rewrite cost weight, the node type of the i-th child node that records the compensation log is obtained by querying the cost weight table, which is maintained by the moving average of the historical write time corresponding to each type of node. The number of retries is directly read from the compensation log table; To normalize the dwell time, the dwell time is obtained by subtracting the first failure timestamp in the compensation log from the current timestamp, and then calculated by the ratio of the dwell time to the baseline scan cycle. The weighting coefficients are 1, and the sum of the three is 1. The idempotent cleanup includes: when a child node with a compensation log has been partially written to the target table, physical deletion is performed according to the child node identifier; when it has not been written, cleanup is skipped and rewriting is performed directly. The rewritten data is provided by the write data of the corresponding expected child node in the expected topology snapshot; when the rewriting is successful, the corresponding compensation log is cleared and a write receipt is added; when the rewriting fails, the retry count is incremented by 1; when the retry count exceeds 3, the corresponding child node is moved into the dead letter queue and an alarm notification is sent; when the compensation log corresponding to the root node record is completely cleared and the recalculated actual consistency fingerprint is consistent with the expected consistency fingerprint, the status field of the root node record is updated to the confirmed state.
7. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 1, characterized in that, The process also includes step 5: When a child node in the tree-structured BOM node model corresponds to a settlement record and payment fails, a structured refactoring is performed: the set of settlement records in the same batch is scanned under the dual conditions of record status pending settlement and payment status payment failure; all settlement records are verified to belong to the same task identifier, otherwise the process is stopped; the records are grouped by user identifier, and the group payable amount and group attendance duration are summarized. A new batch number is generated using the distributed cache atomic auto-increment instruction, creating a new batch record and one new settlement record for each group. The new settlement record is assigned a brand new identifier, and the amount due and attendance duration are taken from the group's group amount due and attendance duration. The settlement record is then assigned to the corresponding source data remapping subprocess according to the settlement record type: task settlement type, updating the settlement record identifier field of the attendance summary record and the prepaid salary record to the new settlement record identifier. For promotion settlement type, update the settlement record identifier field of the promotion settlement record to the new settlement record identifier and update the batch number field simultaneously; for advance settlement type, update the advance settlement record identifier field of the advance salary record to the new settlement record identifier; use a two-condition optimistic locking to batch cancel old settlement records with the old record status pending settlement and the old payment status payment failed, verify that the actual number of updated rows is equal to the number of old settlement records, otherwise roll back the entire structured refactoring operation; The new batch identifier is returned, and the new settlement record re-enters the payment process; The maximum number of retry attempts for a structured critical hit is 3. If this limit is exceeded, the corresponding settlement record will be moved to the dead letter queue.
8. The cross-service settlement and compensation consistency method based on tree-structured BOM node modeling according to claim 1, characterized in that, The root node record also includes a version number field. When synchronously writing to the root node record in step 1, the version number field is set to 1. All update operations on the status field of the root node record carry the old value of the status field and the old value of the version number field as update conditions. After the update is successful, the version number field is incremented by 1. If the actual number of updated rows is 0, a version conflict is determined. The latest version number field of the root node record is reread, the changed content is merged, and the update operation is re-executed. The maximum number of re-executions is 3.
9. A cross-service settlement and compensation consistency system based on tree-structured BOM node modeling, characterized in that, include: The root node submission module is used to execute the parsing of cross-service settlement requests, construct a tree-like BOM node model, construct a desired topology snapshot based on the tree-like BOM node model, calculate the desired consistency fingerprint by identifying all desired child nodes, synchronously write the root node record with the initial state in the status field, and synchronously return the root node identifier. The child node parallel write module is used to execute the write task of each child node in parallel according to the desired topology snapshot. Each child node write task is independently wrapped in a fault isolation block. When the write is successful, a write receipt is recorded in the write receipt table. When the write fails, a compensation log is recorded in the compensation log table. The dual-channel consistency detection module is used to query the compensation log table to determine whether there is an explicit failure, aggregate the write receipts in the write receipt table to calculate the actual consistency fingerprint and compare it with the expected consistency fingerprint. If there is an explicit failure, the status field of the root node record is updated to the state to be compensated. If the comparison is inconsistent, regardless of whether there is an explicit failure, the set of forked child nodes is located according to the node type and the compensation log is rewritten, and the status field of the root node record is updated to the state to be compensated. If there is no explicit failure and the comparison is consistent, the status field of the root node record is updated to the confirmed state. The adaptive compensation scheduling module is used to execute the compensation scheduler to scan the abnormal root node records according to the adaptive scanning cycle calculated by the abnormal root node density, and to perform idempotent cleanup and rewriting on the child nodes with compensation logs in descending order of compensation priority score.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the cross-service settlement compensation consistency method based on tree-structured BOM node modeling as described in any one of claims 1 to 8.
