Weak network data synchronization method based on field dependency graph and idempotent replay

By using a field dependency graph and idempotent replay approach, the problem of synchronization accuracy and causal consistency in concurrent operations of multiple terminals under weak network conditions is solved, achieving efficient data synchronization and conflict recovery, and ensuring idempotent execution of operations.

CN123145265APending Publication Date: 2026-11-20FUJIAN SHUCUN TECHNOLOGY DEVELOPMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611291290.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-25
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing data synchronization solutions suffer from problems such as coarse conflict granularity, repeated operation execution, disruption of business dependencies, and low efficiency of resuming interrupted data transmission in weak network environments. They cannot effectively solve the problems of synchronization accuracy, business causal consistency, and conflict recovery efficiency in concurrent operations of multiple terminals.

Method used

By adopting a method based on field dependency graphs and idempotent replay, the terminal splits transactions into field-level operations, constructs a field dependency graph for topological sorting, and performs idempotency and version verification on the server side. The minimum dependency subgraph is frozen only in case of conflict. Combined with the client's synchronization confirmation status and waiting area mechanism, accurate retransmission is achieved.

Benefits of technology

It improves the accuracy of data synchronization, business causal consistency and conflict recovery efficiency in multi-terminal concurrent operations, ensures the idempotent execution of data change operations, avoids interference from irrelevant fields and repeated execution, and optimizes the throughput and user experience of the synchronization process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123145265A_ABST
    Figure CN123145265A_ABST
Patent Text Reader

Abstract

The application provides a weak network data synchronization method based on field dependency graph and idempotent replay in the technical field of data synchronization, and comprises the following steps: a terminal intercepts transaction submission, splits field changes into operations and writes the operations into a local queue; the operations are topologically sorted according to a field dependency graph and are batched and sent to a server according to network capacity; the server performs idempotent and version checking, and if the checking is passed, the server updates and confirms; if a version conflict occurs, if exchangeable conditions are met, the conflict is continued, otherwise, a conflict influence range is frozen and conflict information is returned; the terminal updates a continuous confirmation serial number and a gap or generates a compensation operation re-queue according to a confirmation result, and continuously sends unconfirmed operations until all synchronization is completed. The application has the advantages that the synchronization accuracy, business causality consistency and conflict recovery efficiency of multi-terminal concurrent operations in a weak network environment are greatly improved, and the idempotent execution of data change operations is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data synchronization technology, and in particular to a weak network data synchronization method based on field dependency graphs and idempotent replay. Background Technology

[0002] With the widespread adoption of mobile internet and IoT technologies, enterprise-level applications such as mobile inspection, field data collection, warehouse inventory management, and mobile approvals are becoming increasingly prevalent. A core characteristic of these applications is that mobile devices (such as smartphones, tablets, and handheld devices) often need to operate even when the network is unstable or completely offline. To ensure business continuity and data consistency, these systems generally employ a dual-end storage architecture consisting of a local database on the terminal and a central database on the server. When a terminal is offline, it first saves data changes locally, and then uploads the local modification records to the server for synchronization once the network is restored.

[0003] Currently, the industry mainly adopts the following data synchronization solutions for the above scenarios: 1. Complete record overwrite: This is the simplest and most direct solution, where the later uploaded version of the record completely overwrites the entire record on the server. It is simple to implement, but has obvious drawbacks.

[0004] 2. Last-Write-Wins (LWW) based on timestamps: The server determines which operation to accept based on its timestamp, only accepting the most recent modification. This approach relies on the accuracy of the timestamps on each terminal device, and may lead to unexpected data overwriting when there are significant clock discrepancies across devices or network latency.

[0005] 3. Record-level optimistic locking: Each record maintains a version number (such as a timestamp or auto-incrementing sequence). When a terminal submits an update, it must include its version number. The server compares the version numbers and only allows the update if they match; otherwise, it is considered a conflict. This scheme can effectively detect concurrent modifications, but its conflict granularity is the entire record.

[0006] 4. Operation Log Replay: The terminal records the detailed operation of each data modification (such as "increase the value of field A by 1") and sends it to the server in sequence. The server replays these operations in sequence to achieve synchronization.

[0007] However, in weak network environments, the aforementioned existing technical solutions generally suffer from the following problems: Issue 1: Coarse-grained conflict resolution can easily lead to unrelated field modifications being accidentally overwritten or blocked. In record-level optimistic locking or whole-record overwrite schemes, the entire record is treated as an indivisible minimum conflict detection unit. When two terminals modify different fields in the same record, for example, terminal A modifies the "Number of Issues" field and terminal B modifies the "Acceptance Person" field, the system will still determine that a conflict has occurred. This causes the later-committed modification to overwrite the earlier-committed unrelated field, or forces operations that could be automatically merged to be handled manually. This not only reduces synchronization efficiency but also affects the user experience. The root cause is that the existing synchronization mechanism lacks independent tracking and version management of field-level modifications.

[0008] Issue 2: Lack of an effective idempotency mechanism leads to duplicate operation execution. In weak network environments, clients, unable to accurately determine whether a request has been successfully processed by the server, typically employ timeout retransmission strategies. However, operations such as numerical addition and subtraction, appending elements to a set, and state transitions, if executed repeatedly after being performed on the server, can result in incorrect data (e.g., duplicate deduction of inventory quantities, abnormal state machine transitions). Existing solutions fail to assign a globally unique persistent identifier to each operation and do not atomically store operation execution results and confirmation states, thus failing to reliably support idempotent replay.

[0009] Issue 3: Disrupted timing of dependencies undermines the causal consistency of business logic. Fields within the same business object often have inherent prerequisite, derivative, or mutually exclusive relationships. For example, changing an "order status" to "completed" depends on the "acceptance time" and "acceptance personnel" fields being written; while the value of the "inventory balance" field is derived from the "inbound quantity" and "outbound quantity." Due to discrepancies in local clocks across different terminals and out-of-order network transmission, if the server simply sorts and replays operations based on arrival order or terminal-generated timestamps, it's highly likely that derived field operations will be executed before their prerequisite field operations, thus disrupting the causal consistency of business data. Existing synchronization queues lack explicit descriptions and topological sorting mechanisms for inter-field dependencies.

[0010] Question 4: Inefficient conflict recovery and lack of precise breakpoint resumption capabilities. In the event of a local conflict, existing solutions often suspend the synchronization of the entire record or even the entire batch. After network recovery, the system needs to retransmit a large number of operations from a fixed checkpoint, resulting in redundant data transmission and processing overhead. The crux of the problem is that the server fails to accurately identify the minimum dependency subgraph affected by the conflict, and the client fails to maintain a fine-grained acknowledgment state consisting of "continuous acknowledgments" and "unacknowledgment gaps," thus failing to achieve precise retransmission only for failed operations.

[0011] In summary, existing data synchronization solutions cannot effectively address the issues of coarse-grained conflict resolution, redundant operation execution, disrupted business dependencies, and low efficiency of resuming interrupted data transmissions in weak network environments. Therefore, providing a data synchronization method for weak networks based on field dependency graphs and idempotent replay to improve synchronization accuracy, business causality consistency, and conflict recovery efficiency for concurrent multi-terminal operations in weak network environments, while ensuring idempotent execution of data change operations, has become a pressing technical problem. Summary of the Invention

[0012] The technical problem to be solved by this invention is to provide a weak network data synchronization method based on field dependency graph and idempotent replay, which improves the synchronization accuracy, business causal consistency and conflict recovery efficiency of multi-terminal concurrent operations in weak network environment, and ensures the idempotent execution of data change operations.

[0013] This invention provides a method for data synchronization in weak networks based on field dependency graphs and idempotent replay, comprising the following steps: Step S1: The terminal intercepts the transaction commit event of the local database, breaks down the field changes in this transaction commit into one or more field-level operations, and writes the field-level operations into the persistent local operation queue; Step S2: The terminal obtains the dependency relationships between fields within the same business entity and constructs a field dependency graph; determines the execution order constraints between field-level operations based on the field dependency graph; and performs topological sorting on the operations to be sent in the local operation queue. Step S3: The terminal determines the maximum capacity of this transmission based on the network conditions, retrieves the corresponding number of field-level operations from the local operation queue, forms a set of operations to be synchronized, and sends the set of operations to be synchronized to the server. Step S4: After receiving the set of operations to be synchronized, the server verifies the field-level operations in the set of operations to be synchronized. The verification includes: idempotency verification to determine whether the current field-level operation has been executed based on the unique identifier of the operation, and version verification to determine whether the previous version of the field on which the current field-level operation is based is consistent with the current version of the field on the server. Step S5: If the verification passes, the server executes the current field-level operation, updates the field version and confirmation status, and returns the confirmation result to the terminal; Step S6: If the version verification fails, the server determines whether the current field-level operation meets the exchangeability condition. If it does, the server continues to execute the current field-level operation, updates the field version and confirmation status, and returns the confirmation result to the terminal. If it does not meet the condition, the server starts from the current conflicting field, determines the scope of operations affected by the conflict along the field dependency graph, freezes only the field-level operations within the scope of operations affected by the conflict, and returns the conflict information to the terminal. Step S7: If the confirmation result is received, the terminal updates the locally maintained synchronization confirmation status according to the confirmation result. The synchronization confirmation status includes at least the maximum consecutive confirmation sequence number and the set of confirmed gaps. If the conflict information is received, the terminal generates a compensation operation according to the conflict information and re-adds it to the local operation queue. Step S8: Based on the synchronization confirmation status, the terminal determines the field-level operations that have not yet been continuously confirmed from the local operation queue, continues to send them to the server, and repeats the above-mentioned sending, receiving verification and updating process until all the field-level operations are synchronized.

[0014] Furthermore, in step S1, the field-level operation includes an operation unique identifier, an entity identifier, a field identifier, an operation payload, a field preceding version, and a set of dependent operation identifiers; the set of dependent operation identifiers is used to record other operation identifiers that must be completed before the current field-level operation is executed. The field-level operations also include device identifier, operation type, local monotonic sequence number, and generation time; the operation types include at least assignment, numerical increment / decrement, set append, set deletion, and state transition, and different operation types have different merging semantics and interchangeability judgment conditions.

[0015] Furthermore, in step S2, the nodes of the field dependency graph represent fields or field-level operations, and the directed edges represent execution order constraints between nodes; the directed edges include at least preceding dependency edges, derived dependency edges, and mutually exclusive dependency edges; the preceding dependency edge indicates that an operation on one field within the same business entity must be executed after an operation on another field; the derived dependency edge indicates that the value of one field is calculated from the value of another field; the mutually exclusive dependency edge indicates that two fields cannot be modified simultaneously; The dependencies are derived from preset field rules, database constraints, and local transaction groups; if a dependency loop is detected during the topology sorting process, the nodes corresponding to the dependency loop are merged into an indivisible transaction group.

[0016] Furthermore, in step S3, the network status includes available bandwidth, round-trip latency, number of consecutive failures, and number of bytes to be sent; based on the network status, field-level operations that are prioritized in the local operation queue and have a data volume less than a preset threshold in the topological order of the field dependency graph are selected to form the set of operations to be synchronized.

[0017] Furthermore, in step S4, the idempotency check specifically involves: the server querying the unique identifier of the current field-level operation in the idempotency result table; if the unique identifier already exists, the server directly returns the stored execution result summary without repeating the field-level operation; the idempotency result table uses the unique identifier as the primary key to store the execution result summary corresponding to each unique identifier. The version verification specifically involves comparing the current version of the field in the server's field version table with the previous version of the field carried by the current field-level operation. The field version table uses the entity identifier and the field identifier as a composite key to store the current field version, the most recent operation identifier, and the field value summary, respectively. Fields jointly committed in the same transaction are appended with a transaction group identifier.

[0018] Furthermore, step S4 also includes dependency verification: verifying whether all dependent operations in the current field-level operation's dependent operation identifier set have been completed; if there are any uncompleted dependent operations, then write the field-level operation into the waiting area, and reschedule it after the dependent operation is completed.

[0019] Furthermore, in step S5, the confirmation result includes at least a batch confirmation result indicating whether all field-level operations in the set of operations to be synchronized have been successfully executed, the updated maximum consecutive confirmation sequence number, and the set of confirmed gaps; the execution of the current field-level operation, the update of the field version, and the confirmation status are completed in the same database transaction; the confirmation status includes the device identifier, the maximum consecutive confirmation sequence number, the set of confirmed gaps following the maximum consecutive confirmation sequence number, and the execution result summary corresponding to the unique identifier of each operation.

[0020] Furthermore, in step S6, the commutative conditions include: for field-level operations involving numerical increment or decrement, if different field-level operations operate on the same field's numerical increment or decrement, the calculation results are merged according to the operation order; for field-level operations involving appending to a set, if different field-level operations operate on the same set field, the elements appended by each field-level operation are merged; field-level operations involving assignment and field-level operations involving state transition are determined to be non-commutative operations. The specific steps for determining the scope of operations affected by the conflict are as follows: starting from the current conflicting field, traverse the field dependency graph in the forward direction to obtain the least affected dependency subgraph, and freeze only the field-level operations corresponding to the least affected dependency subgraph; the conflict information includes the current field value, current field version, and missing dependency information on the server.

[0021] Furthermore, in step S7, updating the locally maintained synchronization confirmation status specifically includes: if the new confirmation sequence number is equal to the current maximum consecutive confirmation sequence number plus 1, then continuously merge the confirmed gap set and advance the maximum consecutive confirmation sequence number; if the new confirmation sequence number is greater than the current maximum consecutive confirmation sequence number plus 1, then write the new confirmation sequence number into the confirmed gap set; the terminal only deletes confirmed operations that are not greater than the maximum consecutive confirmation sequence number, and operations located in the confirmed gap and operations that are greater than the maximum consecutive confirmation sequence number are retained in the local operation queue; The specific steps of generating the compensation operation are as follows: based on the current field value, current field version, and missing dependency information returned by the server, generate a compensation operation with a unique identifier for the new operation and the preceding version of the new field.

[0022] Furthermore, the method also includes: Out-of-order processing mechanism: For a field-level operation that has been received, if there are any incomplete dependent operations in the set of dependent operation identifiers, the server will write the field-level operation into the waiting area; when the operations dependent on the field-level operation in the waiting area are completed, the field-level operation will be added back to the executable queue maintained by the server to participate in subsequent scheduling. Conflict loop handling mechanism: When the number of compensation operations generated for the same field exceeds the preset threshold, stop automatically generating compensation operations and output the current field version on the server and the current field version on the terminal for confirmation by the upper-layer business. Dependency loop handling mechanism: When a dependency loop is detected and the corresponding nodes of the loop cannot be merged into a transaction group that can be committed together, the operation of the group is rejected and the loop path is output.

[0023] The advantages of this invention are: 1. By decomposing terminal transactions into field-level operations carrying unique operation identifiers, previous versions of fields, and sets of dependent operations, and combining this with topological sorting using a constructed field dependency graph, the strict and orderly execution of concurrent multi-terminal operations in terms of business causality is standardized from the source. Based on this, the server-side idempotent result table, with the unique operation identifier as the primary key, is used to perform deduplication verification on executed operations, ensuring that retransmissions in weak networks do not lead to the repeated execution of data change operations. Simultaneously, field-level version verification replaces the traditional coarse-grained record-level locks, and when conflicts occur, only the least affected subgraph along the field dependency graph is frozen. Combined with the breakpoint resumption mechanism implemented by the maximum consecutive confirmation sequence number and the set of confirmed gaps maintained by the client, this approach works synergistically across multiple levels, including refining conflict granularity, ensuring causal logic, preventing duplicate execution, and accurately retransmitting unconfirmed operations. This comprehensively improves the data synchronization accuracy, business causal consistency, and conflict recovery efficiency of concurrent multi-terminal operations in weak network environments, and reliably ensures the idempotent execution of various data change operations.

[0024] 2. By breaking down transactions into field-level operations and constructing a field dependency graph to explicitly depict the relationships between fields, version verification is performed on the "previous version of the field" rather than the "record version." In the event of a version conflict, the exchangeability conditions are further determined, and only the smallest dependent subgraph containing the conflicting field is frozen. This series of designs makes conflict detection and handling granular down to the field level, allowing concurrent modifications to independent fields within the same record to be committed independently, thereby completely avoiding interference between unrelated fields and significantly improving the synchronization success rate and user experience in multi-terminal concurrent scenarios.

[0025] 3. Each field-level operation carries a unique operation identifier, introducing idempotency verification. The server queries the idempotency result table using the unique operation identifier as the primary key. If the result already exists, a summary of the historical execution result is returned directly, without repeating the field-level operation. Operation execution, field version update, and confirmation status are atomically completed within the same database transaction. This mechanism ensures that regardless of how many times the network is retransmitted, the same operation only takes effect once on the server, and the execution result is traceable. This fundamentally eliminates the risk of data pollution caused by repeated execution, laying a solid foundation for reliable synchronization in weak network environments.

[0026] 4. By constructing a field dependency graph containing pre-dependent edges, derived dependent edges, and mutually exclusive dependent edges, and performing topological sorting on the local operation queue, the sending order is ensured to naturally satisfy dependency constraints. Dependency verification further checks on the server side whether all dependent operations of the current operation have been completed; if not, they are temporarily stored in the waiting area. In the event of a version conflict, the minimum affected scope is determined along the dependency graph, rather than global blocking. These measures collectively guarantee that field operations within the same business entity are executed strictly in causal order. Regardless of the network transmission order, the server can restore the correct execution sequence through the dependency graph and waiting area mechanism, thereby perfectly maintaining the causal consistency of business data.

[0027] 5. Maintain a synchronization acknowledgment state containing the maximum consecutive acknowledgment number and the set of confirmed gaps, and explicitly define the consecutive merging logic—only delete operations with a sequence number no greater than the maximum consecutive acknowledgment number, while operations within the gap and subsequent operations are retained in the local queue; based on this state, only operations that have not yet been consecutively acknowledged are sent. Simultaneously, only the least dependent subgraph affected by the conflict is frozen, and when generating compensation operations, it is re-enqueued with the new version number, dynamically selecting operations with higher topological order for transmission based on network conditions. This mechanism eliminates the need for full retransmission during the synchronization process, requiring only precise retransmission of a few operations within the gap and compensation operations, significantly reducing redundant data transmission and processing burden under weak network conditions, and significantly improving conflict recovery efficiency and overall synchronization throughput. Attached Figure Description

[0028] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0029] Figure 1 This is a flowchart of a weak network data synchronization method based on field dependency graphs and idempotent replay, according to the present invention. Detailed Implementation

[0030] The technical solution in this application embodiment has the following general idea: Terminal local transactions are decomposed into field-level operations carrying unique identifiers, previous versions, and dependencies. A field dependency graph is introduced to perform topological sorting of operations, thereby defining causal constraints between concurrent operations at the source. During synchronization, the server achieves idempotent deduplication through unique operation identifiers and replaces traditional record-level locks with field-level version verification. Only when there is a version conflict and the commutative condition is not met, the least affected subgraph is frozen along the dependency graph to avoid global blocking. Simultaneously, the terminal maintains the maximum consecutive acknowledgment number and the set of acknowledged gaps, supporting only retransmission of unacknowledged operations and generation of compensation operations. Combined with the server's waiting area mechanism to handle out-of-order arrivals, a closed-loop synchronization process is formed, from operation decomposition, dependency sorting, idempotent verification, fine-grained conflict handling to breakpoint resumption. This ensures data accuracy, causal consistency, and recovery efficiency even in weak network environments.

[0031] Please refer to Figure 1As shown, a preferred embodiment of the present invention, a data synchronization method for weak networks based on field dependency graphs and idempotent replay, includes the following steps: Step S1: The terminal intercepts the transaction commit event of the local database, breaks down the field changes in this transaction commit into one or more field-level operations, and writes the field-level operations into the persistent local operation queue; Preferably, the local operation queue is a first-in, first-out (FIFO) queue, where each queue entry represents a field-level operation. Upon initial terminal startup or after the local database has been rebuilt, the terminal scans the local operation log, assigns a strictly monotonically increasing local sequence number (localSeq) to each operation in the queue, initializes the maximum consecutive acknowledgment number (highWatermark) to 0, and sets the acknowledged gaps (acknowledgedGaps) to an empty set. This queue is persistently stored to ensure that even after an abnormal restart, the terminal can still resume the synchronization process based on the persistent queue and synchronization acknowledgment status, preventing data loss.

[0032] Step S2: The terminal obtains the dependency relationships between fields within the same business entity and constructs a field dependency graph; determines the execution order constraints between field-level operations based on the field dependency graph; and performs topological sorting on the operations to be sent in the local operation queue. For example, in an order entity, if a business rule stipulates that the value of the "Total Order Price" field is derived from the product of the "Unit Price" and "Quantity," the system will construct a "derived dependency edge" from the "Unit Price" and "Quantity" field nodes to the "Total Order Price" field node. If another rule stipulates that the "Logistics Tracking Number" must be filled in before the "Order Status" changes to "Shipped," the system will construct a "preceding dependency edge" from the "Logistics Tracking Number" field node to the "Order Status" field node. Based on this directed graph, any operation on the "Total Order Price" will necessarily be topologically ordered after operations on its source fields, thus ensuring the correctness of the calculation results.

[0033] Step S3: The terminal determines the maximum capacity of this transmission based on the network conditions, retrieves the corresponding number of field-level operations from the local operation queue, forms a set of operations to be synchronized, and sends the set of operations to be synchronized to the server. The network condition assessment is performed periodically by the terminal's network probing module. This module calculates the current round-trip time (RTT) and packet loss rate by sending probe packets. The terminal dynamically calculates the maximum capacity for this transmission based on a preset assessment strategy: for example, if the RTT exceeds a first threshold or the packet loss rate exceeds a second threshold, the network condition is determined to be "poor," and the maximum capacity is reduced to avoid transmission failure due to excessive data volume; conversely, if the network condition is "excellent," the maximum capacity can be appropriately increased to improve synchronization efficiency. Simultaneously, the terminal also considers the number of consecutive failures; if the number of failures accumulates, the maximum capacity is further reduced, and a backoff and retransmission strategy is triggered.

[0034] Step S4: After receiving the set of operations to be synchronized, the server verifies the field-level operations in the set of operations to be synchronized. The verification includes: idempotency verification to determine whether the current field-level operation has been executed based on the unique identifier of the operation, and version verification to determine whether the previous version of the field on which the current field-level operation is based is consistent with the current version of the field on the server. Step S5: If the verification passes, the server executes the current field-level operation, updates the field version and confirmation status, and returns the confirmation result to the terminal; Step S6: If the version verification fails, the server determines whether the current field-level operation meets the exchangeability condition. If it does, the server continues to execute the current field-level operation, updates the field version and confirmation status, and returns the confirmation result to the terminal. If it does not meet the condition, the server starts from the current conflicting field, determines the scope of operations affected by the conflict along the field dependency graph, freezes only the field-level operations within the scope of operations affected by the conflict, and returns the conflict information to the terminal. Upon receiving the conflict information, the terminal first parses the server's current field values ​​and version numbers contained within. Based on this information, and combining it with the target and payload of the current local operation, the terminal constructs a new field-level operation, namely a compensation operation. This compensation operation has a newly generated unique identifier (opId), its baseVersion field is updated to the server's current field version carried in the conflict information, and its payload is adjusted according to the server's current field values ​​to ensure eventual consistency after execution. The generated compensation operation, like a newly generated operation, is appended to the tail of the local operation queue and undergoes the entire process of topology sorting, sending, and verification again.

[0035] Step S7: If the confirmation result is received, the terminal updates the locally maintained synchronization confirmation status according to the confirmation result. The synchronization confirmation status includes at least the maximum consecutive confirmation sequence number and the set of confirmed gaps. If the conflict information is received, the terminal generates a compensation operation according to the conflict information and re-adds it to the local operation queue. Step S8: Based on the synchronization confirmation status, the terminal determines the field-level operations that have not yet been continuously confirmed from the local operation queue, continues to send them to the server, and repeats the above-mentioned sending, receiving verification and updating process until all the field-level operations are synchronized.

[0036] In a more complete embodiment, assume that terminal A and terminal B simultaneously operate on the same inspection task record. The initial status is: status='in progress', quantity=5, inspector=''.

[0037] 1. Operation Generation: Terminal A modifies the quantity from 5 to 1, generating operation O1(opId:A1,field:quantity,type:INCR,baseVersion:0). Terminal B enters inspector='Zhang San' and changes the status to 'Completed' based on the rule. The system generates two operations: O2(opId:B1,field:inspector,type:ASSIGN,baseVersion:0) and O3(opId:B2,field:status,type:TRANSITION,baseVersion:0,dependencies:[B1]), because the status transition depends on the inspector already entered.

[0038] 2. Topology Sorting and Sending: Terminal B's dependency graph explicitly states that O3 depends on O2. If, due to network issues, Terminal B sends O3 first, the server performs dependency verification and finds that its dependent O2 is incomplete, so it temporarily stores O3 in the waiting area. Subsequently, O2 arrives, the server executes O2, updates the inspector field version to 1, and wakes up O3. At this point, O3's dependency is satisfied, it is removed from the waiting area, and enters the executable queue.

[0039] 3. Concurrency Conflicts and Merging: Before O3 is woken up and executed, terminal A's O1 arrives. The server checks the version of O1 and finds that the current version of the quantity field is 0, which is consistent with the baseVersion carried by O1. The verification passes, O1 is executed, the quantity is updated to 6, and the verification is confirmed. Subsequently, O3 is executed, the version of the status field is checked and found to be 0, which passes, and the status is changed to 'completed'. Throughout the entire process, the modifications made by the two terminals to different fields of quantity and status (and their dependent inspector) perfectly maintain the causal relationship due to the topological sorting and dependency waiting mechanism, and no unnecessary conflicts or blocking occur.

[0040] In step S1, the field-level operation includes an operation unique identifier (opId), an entity identifier (entityId), a field identifier (fieldId), an operation payload, a field preceding version (baseVersion), and a set of dependent operation identifiers (dependencies); the set of dependent operation identifiers is used to record other operation identifiers that must be completed before the current field-level operation is executed. The field-level operations also include device identifier (deviceId), operation type (opType), local monotonic sequence number (localSeq), and generation time (generatedAt). The operation types at least include assignment, numeric increment / decrement, set append, set deletion, and state transition. Different operation types have different merging semantics and commutative determination conditions. Different operation types are used for assignment, numeric increment / decrement, set append, set deletion, and state transition to avoid uniformly processing operations with different merging semantics.

[0041] In step S2, the nodes of the field dependency graph represent fields or field-level operations, and the directed edges represent execution order constraints between nodes; the directed edges include at least preceding dependency edges, derived dependency edges, and mutually exclusive dependency edges; the preceding dependency edge indicates that an operation on one field within the same business entity must be executed after an operation on another field; the derived dependency edge indicates that the value of one field is calculated from the value of another field; the mutually exclusive dependency edge indicates that two fields cannot be modified simultaneously; The dependencies are derived from preset field rules, database constraints, and local transaction groups; if a dependency loop is detected during the topology sorting process, the nodes corresponding to the dependency loop are merged into an indivisible transaction group.

[0042] In step S3, the network status includes available bandwidth, round-trip time, number of consecutive failures, and number of bytes to be sent. Based on the network status, field-level operations that are ranked high in the topological order of the field dependency graph and have a data volume less than a preset threshold are selected from the local operation queue to form the set of operations to be synchronized.

[0043] In step S4, the idempotency check specifically involves: the server querying the unique identifier of the current field-level operation in the idempotency result table; if the unique identifier already exists, the server directly returns the stored execution result summary without repeating the field-level operation; the idempotency result table uses the unique identifier as the primary key to store the execution result summary corresponding to each unique identifier. The version verification specifically involves comparing the current version of the field in the server's field version table with the previous version of the field carried by the current field-level operation. The field version table uses the entity identifier and the field identifier as a composite key to store the current field version, the most recent operation identifier, and the field value summary, respectively. Fields jointly committed in the same transaction are appended with a transaction group identifier.

[0044] Step S4 also includes dependency verification: verifying whether all dependent operations in the current field-level operation's dependent operation identifier set have been completed; if there are any uncompleted dependent operations, write the field-level operation into the waiting area, and reschedule it after the dependent operation is completed.

[0045] The waiting area is a mapping structure maintained in the server's memory, indexed by the identifiers of dependent operations. When a field-level operation enters the waiting area due to incomplete dependencies, its own identifier is registered as a listener for all its dependent operations. Whenever a field-level operation completes, the server looks up this mapping structure, wakes up all waiting operations that depend on the currently completed operation, and moves them into the executable queue, awaiting the next scheduling. If all dependencies of a waiting operation have been completed, it is immediately moved into the executable queue. If an operation times out in the waiting area due to incorrect dependencies, the server determines that the operation and its dependent operations have failed as a whole and returns a clear dependency missing error message to the terminal.

[0046] In step S5, the confirmation result includes at least a batch confirmation result indicating whether all field-level operations in the set of operations to be synchronized have been successfully executed, the updated maximum consecutive confirmation number (highWatermark), and the set of acknowledged gaps (acknowledgedGaps); the execution of the current field-level operation, the update of the field version, and the confirmation status are completed in the same database transaction; the confirmation status includes the device identifier, the maximum consecutive confirmation number, the set of acknowledged gaps following the maximum consecutive confirmation number, and the execution result summary corresponding to the unique identifier (opId) of each operation.

[0047] In step S6, the commutative conditions include: for field-level operations involving numerical increment or decrement, if different field-level operations operate on the same field's numerical increment or decrement, the calculation results are merged according to the operation order; for field-level operations involving appending to a set, if different field-level operations operate on the same set field, the elements appended by each field-level operation are merged; field-level operations involving assignment and field-level operations involving state transition are determined to be non-commutative operations. The specific steps for determining the scope of operations affected by the conflict are as follows: starting from the current conflicting field, traverse the field dependency graph in the forward direction to obtain the least affected dependency subgraph, and freeze only the field-level operations corresponding to the least affected dependency subgraph; the conflict information includes the current field value, current field version, and missing dependency information on the server.

[0048] In step S7, updating the locally maintained synchronization confirmation status specifically includes: if the new confirmation sequence number is equal to the current maximum consecutive confirmation sequence number plus 1, then continuously merge the confirmed gap set and advance the maximum consecutive confirmation sequence number; if the new confirmation sequence number is greater than the current maximum consecutive confirmation sequence number plus 1, then write the new confirmation sequence number into the confirmed gap set; the terminal only deletes confirmed operations that are not greater than the maximum consecutive confirmation sequence number, and operations located in the confirmed gap and operations that are greater than the maximum consecutive confirmation sequence number are retained in the local operation queue; The specific steps of generating the compensation operation are as follows: based on the current field value, current field version, and missing dependency information returned by the server, generate a compensation operation with a unique identifier for the new operation and the preceding version of the new field.

[0049] The method further includes: Out-of-order processing mechanism: For a field-level operation that has been received, if there are any incomplete dependent operations in the set of dependent operation identifiers, the server will write the field-level operation into the waiting area; when the operations dependent on the field-level operation in the waiting area are completed, the field-level operation will be added back to the executable queue maintained by the server to participate in subsequent scheduling. Conflict loop handling mechanism: When the number of compensation operations generated for the same field exceeds the preset threshold, stop automatically generating compensation operations and output the current field version on the server and the current field version on the terminal for confirmation by the upper-layer business. Dependency loop handling mechanism: When a dependency loop is detected and the corresponding nodes of the loop cannot be merged into a transaction group that can be committed together, the operation of the group is rejected and the loop path is output.

[0050] Taking a mobile inspection record as an example, a record includes fields for inspection status, number of issues, issue attachments, inspector, and inspection time. Terminal A modifies the number of issues and adds attachments offline, while Terminal B fills in the inspector and inspection time online. The field dependency rules stipulate that "inspection status = completed" depends on the inspector and inspection time, and there is no mandatory prerequisite relationship between the number of issues and attachments.

[0051] Terminal A generates an incremental problem count operation O1 and an append set of attachments operation O2. Terminal B generates an assignment operation O3 for the acceptor, an assignment operation O4 for the acceptance time, and a state transition operation O5. O5's dependencies include O3 and O4. Even if O5 arrives at the server first, it will enter a waiting area until O3 and O4 complete. After Terminal A recovers the network, O1 and O2 can be merged independently without triggering a conflict in the entire record due to a change in the inspection status. If the attachment field has been replaced by another terminal's assignment, the system only freezes the attachment field and its dependent nodes, while retaining the execution result of the incremental problem count operation.

[0052] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A weak network data synchronization method based on field dependency graphs and idempotent replay, characterized in that, Includes the following steps: Step S1: The terminal intercepts the transaction commit event of the local database, breaks down the field changes in this transaction commit into one or more field-level operations, and writes the field-level operations into the persistent local operation queue; Step S2: The terminal obtains the dependency relationships between fields within the same business entity and constructs a field dependency graph; Determine the execution order constraints between field-level operations based on the field dependency graph; perform topological sorting on the operations to be sent in the local operation queue; Step S3: The terminal determines the maximum capacity of this transmission based on the network conditions, retrieves the corresponding number of field-level operations from the local operation queue, forms a set of operations to be synchronized, and sends the set of operations to be synchronized to the server. Step S4: After receiving the set of operations to be synchronized, the server verifies the field-level operations in the set of operations to be synchronized. The verification includes: idempotency verification to determine whether the current field-level operation has been executed based on the unique identifier of the operation, and version verification to determine whether the previous version of the field on which the current field-level operation is based is consistent with the current version of the field on the server. Step S5: If the verification passes, the server executes the current field-level operation, updates the field version and confirmation status, and returns the confirmation result to the terminal; Step S6: If the version verification fails, the server determines whether the current field-level operation meets the exchangeability condition. If it does, the server continues to execute the current field-level operation, updates the field version and confirmation status, and returns the confirmation result to the terminal. If it does not meet the condition, the server starts from the current conflicting field, determines the scope of operations affected by the conflict along the field dependency graph, freezes only the field-level operations within the scope of operations affected by the conflict, and returns the conflict information to the terminal. Step S7: If the confirmation result is received, the terminal updates the locally maintained synchronization confirmation status according to the confirmation result. The synchronization confirmation status includes at least the maximum consecutive confirmation sequence number and the set of confirmed gaps. If the conflict information is received, the terminal generates a compensation operation according to the conflict information and re-adds it to the local operation queue. Step S8: Based on the synchronization confirmation status, the terminal determines the field-level operations that have not yet been continuously confirmed from the local operation queue, continues to send them to the server, and repeats the above-mentioned sending, receiving verification and updating process until all the field-level operations are synchronized.

2. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S1, the field-level operation includes an operation unique identifier, an entity identifier, a field identifier, an operation payload, a field preceding version, and a set of dependent operation identifiers; the set of dependent operation identifiers is used to record other operation identifiers that must be completed before the current field-level operation is executed. The field-level operations also include device identifier, operation type, local monotonic sequence number, and generation time; the operation types include at least assignment, numerical increment / decrement, set append, set deletion, and state transition, and different operation types have different merging semantics and interchangeability judgment conditions.

3. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S2, the nodes of the field dependency graph represent fields or field-level operations, and the directed edges represent execution order constraints between nodes; the directed edges include at least preceding dependency edges, derived dependency edges, and mutually exclusive dependency edges; the preceding dependency edge indicates that an operation on one field within the same business entity must be executed after an operation on another field; the derived dependency edge indicates that the value of one field is calculated from the value of another field; the mutually exclusive dependency edge indicates that two fields cannot be modified simultaneously; The dependencies are derived from preset field rules, database constraints, and local transaction groups; if a dependency loop is detected during the topology sorting process, the nodes corresponding to the dependency loop are merged into an indivisible transaction group.

4. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S3, the network status includes available bandwidth, round-trip time, number of consecutive failures, and number of bytes to be sent. Based on the network status, field-level operations that are ranked high in the topological order of the field dependency graph and have a data volume less than a preset threshold are selected from the local operation queue to form the set of operations to be synchronized.

5. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S4, the idempotency check specifically involves: the server querying the unique identifier of the current field-level operation in the idempotency result table; if the unique identifier already exists, the server directly returns the stored execution result summary without repeating the field-level operation; the idempotency result table uses the unique identifier as the primary key to store the execution result summary corresponding to each unique identifier. The version verification specifically involves comparing the current version of the field in the server's field version table with the previous version of the field carried by the current field-level operation. The field version table uses the entity identifier and the field identifier as a composite key to store the current field version, the most recent operation identifier, and the field value summary, respectively. Fields jointly committed in the same transaction are appended with a transaction group identifier.

6. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, Step S4 also includes dependency verification: verifying whether each dependency operation in the dependency operation identifier set of the current field-level operation has been completed; If there are any dependent operations that have not yet been completed, the field-level operation is written to the waiting area and rescheduled after the dependent operation is completed.

7. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S5, the confirmation result includes at least a batch confirmation result indicating whether all field-level operations in the set of operations to be synchronized have been successfully executed, the updated maximum consecutive confirmation sequence number, and the set of confirmed gaps. The execution of the current field-level operation, the update of the field version, and the confirmation status are all completed within the same database transaction; the confirmation status includes the device identifier, the maximum consecutive confirmation sequence number, the set of confirmed gaps following the maximum consecutive confirmation sequence number, and the execution result summary corresponding to the unique identifier of each operation.

8. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S6, the commutative conditions include: for field-level operations involving numerical increment or decrement, if different field-level operations operate on the same field's numerical increment or decrement, the calculation results are merged according to the operation order; for field-level operations involving appending to a set, if different field-level operations operate on the same set field, the elements appended by each field-level operation are merged; field-level operations involving assignment and field-level operations involving state transition are determined to be non-commutative operations. The specific steps for determining the scope of operations affected by the conflict are as follows: starting from the current conflicting field, traverse the field dependency graph in the forward direction to obtain the least affected dependency subgraph, and freeze only the field-level operations corresponding to the least affected dependency subgraph; the conflict information includes the current field value, current field version, and missing dependency information on the server.

9. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, In step S7, updating the locally maintained synchronization confirmation status specifically includes: if the new confirmation number is equal to the current maximum consecutive confirmation number plus 1, then continuously merge the confirmed gap set and advance the maximum consecutive confirmation number; if the new confirmation number is greater than the current maximum consecutive confirmation number plus 1, then write the new confirmation number into the confirmed gap set; the terminal only deletes confirmed operations that are not greater than the maximum consecutive confirmation number, and operations located in the confirmed gap and operations that are greater than the maximum consecutive confirmation number are retained in the local operation queue; The specific steps of generating the compensation operation are as follows: based on the current field value, current field version, and missing dependency information returned by the server, generate a compensation operation with a unique identifier for the new operation and the preceding version of the new field.

10. The weak network data synchronization method based on field dependency graph and idempotent replay as described in claim 1, characterized in that, The method further includes: Out-of-order processing mechanism: For a field-level operation that has been received, if there are any incomplete dependent operations in the set of dependent operation identifiers, the server will write the field-level operation into the waiting area; when the operations dependent on the field-level operation in the waiting area are completed, the field-level operation will be added back to the executable queue maintained by the server to participate in subsequent scheduling. Conflict loop handling mechanism: When the number of compensation operations generated for the same field exceeds the preset threshold, stop automatically generating compensation operations and output the current field version on the server and the current field version on the terminal for confirmation by the upper-layer business. Dependency loop handling mechanism: When a dependency loop is detected and the corresponding nodes of the loop cannot be merged into a transaction group that can be committed together, the operation of the group is rejected and the loop path is output.