Mobile terminal offline bidirectional data synchronization method and system

By adopting offline two-way data synchronization methods on mobile power enterprise terminals, including data compression, block transmission and multi-version parallel management mechanisms, the data synchronization problem in the absence of network is solved, and data transmission efficiency and data consistency are improved.

CN119557371APending Publication Date: 2025-03-04LUCULENT SMART TECHNOLOGIES CO LTD
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411085795.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

The data synchronization problem of mobile terminals in power enterprises without networks is difficult. The existing methods cannot efficiently handle large-scale data and frequent conflicts, especially when mobile device resources are limited.

Method used

The offline two-way data synchronization method of mobile terminal is adopted to initialize the entire table synchronization mechanism, establish a file mapping structure of business table-data primary key-subtable primary key-type hierarchical, and the user performs data operations and records details in offline state. When the network connection is restored, data compression and chunking are performed, synchronization requests are sent to the server, and a multi-version parallel management mechanism is used to detect potential conflicts and resolve conflicts.

Benefits of technology

It significantly improves the efficiency of data transmission, adapts to different network environments, ensures that data can still be synchronized smoothly when the network is unstable, ensures data consistency and integrity during the data synchronization process, and avoids errors and data loss during the data synchronization process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119557371A_ABST
    Figure CN119557371A_ABST
Patent Text Reader

Abstract

The invention discloses a mobile terminal offline bidirectional data synchronization method and system, and relates to the technical field of data synchronization processing, and the method comprises the following steps: initializing a whole table synchronization mechanism, and establishing a file mapping structure; a user performs data operation in an offline state, records data operation details and stores the data operation details in a local cache; when the network connection is recovered, a whole table synchronization mechanism is started, data compression and partitioning are performed, a synchronization request is sent to a server, and segmented data transmission is performed; after receiving the data, the server performs data storage and management by using a file mapping mechanism; detecting potential conflicts by utilizing a multi-version parallel management mechanism, carrying out conflict resolution, merging data with local data after the conflict resolution, and confirming that synchronization is completed to a server; after it is confirmed that all data are synchronized, local and global timestamps are updated, and meanwhile, the optimal thread count is dynamically determined by adopting a multi-thread technology. According to the invention, the efficiency, reliability and accuracy of data synchronization of the mobile terminal are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data synchronization processing, and in particular to a method and system for offline bidirectional data synchronization of a mobile terminal. Background Art

[0002] Mobile informatization of power enterprises has entered the stage of full application, playing an important role in production, management, service and other links. However, due to the wide distribution of power facilities, network coverage is poor in some areas; the core facilities and important production sites of the power system are prohibited from deploying the Internet, and mobile terminals often have to face the scenario of performing business without network, and offline data synchronization has become a problem that needs to be solved.

[0003] Existing offline data synchronization methods mainly rely on simple timestamp comparison or server-based conflict resolution mechanisms. Conventional methods cannot efficiently handle large-scale data and frequent conflicts, especially when mobile device resources are limited. Summary of the invention

[0004] In view of the problems existing in the existing mobile offline data synchronization, the present invention is proposed.

[0005] Therefore, the problem to be solved by the present invention is how to solve the data synchronization problem of the mobile terminal of the power enterprise in the absence of a network, and ensure the integrity and correctness of the data.

[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:

[0007] In the first aspect, an embodiment of the present invention provides a method for offline bidirectional data synchronization on a mobile terminal, which includes initializing a whole table synchronization mechanism, establishing a file mapping structure of business table-data primary key-subtable primary key-type hierarchy; the user performs data operations in an offline state, records the data operation details, and stores the data operations in a local cache; when the network connection is restored, the whole table synchronization mechanism is started, data compression and block division are performed, a synchronization request is sent to a server, and segmented data transmission is performed; after the server receives the data, the file mapping mechanism is used for data storage and management; a multi-version parallel management mechanism is used to detect potential conflicts and resolve conflicts. After the conflicts are resolved, the data is merged with the local data, and the synchronization completion is confirmed to the server; after confirming that all data has been synchronized, the local and global timestamps are updated, and at the same time, multi-threading technology is used to dynamically determine the optimal number of threads.

[0008] As a preferred solution of the method for mobile offline two-way data synchronization according to the present invention, wherein: the data compression and chunking includes the following: define a data compression and chunking parameter set CDP = {CM, BS, CT}, where CM represents the compression method, BS represents the block size, and CT represents the compression threshold; CM = {LZ, GZIP, DEFLATE}, representing optional compression algorithms, including LZ77, GZIP, and DEFLATE; BS represents the maximum number of bytes per data block; CT represents the data size threshold for triggering compression, in bytes; traverse each cached data item CDi in the local cache set LC: calculate the data size size(CDi) of CDi, if size(CDi) > CT, then perform compression: select one of the compression methods in CM, compress the content part of the cached data item, and obtain the compressed data com content ; otherwise, keep the content of the cached data item unchanged; chunk the compressed data: if size(com content ) > BS: then split com content into chunks of size BS, generate a chunk index BI = {B1, B2,... Bi,..., Bk}, where Bi = [bid, offset, length], bid represents the chunk ID, offset represents the offset in the compressed data, and length represents the chunk length; otherwise, take the entire com content as a single chunk and update the cached data item.

[0009] As a preferred solution of the method for mobile offline two-way data synchronization according to the present invention, wherein: the data compression and chunking further includes: the compression rate calculation function is as follows:

[0010]

[0011] wherein, is the original data content, the content of the uncompressed data item; is the compressed data content, the content of the data item processed by the compression algorithm; set a compression effect evaluation threshold CET, if Com (CDn) < CET, then change the compression method or adjust the parameters.

[0012] As a preferred solution of the method for offline bidirectional data synchronization of a mobile terminal described in the present invention, wherein: after the server receives the data, the file mapping mechanism is used to store and manage the data, including the following steps: the mobile terminal sends a synchronous download request to the server, and the server organizes the data and files according to the request, and packages them into a data.zip file and sends it to the mobile terminal; after the mobile terminal receives the data.zip file, it decompresses and parses it, and updates the local database and local storage; when the mobile terminal is offline, the newly added or modified data is marked as offline data, and a unified file identifier is set; when the mobile terminal is online, the business table data, file information and metadata are extracted based on the parsed JSON format data received, and the data is mapped to the corresponding database table and file storage location based on the established business table-data primary key-subtable primary key-type hierarchical file mapping structure.

[0013] As a preferred solution of the method for offline bidirectional data synchronization of a mobile terminal of the present invention, when the mobile terminal is online, the newly added or modified data and files in the local database are transmitted back to the server in the same format to update the central database and the file server; the server verifies the imported data and files to ensure data integrity and consistency, including: using an asymmetric encryption algorithm to sign the entire data packet, and using a public key to verify the signature at the receiving end; calculating the joint checksum of SHA-256 and MD5 for each file, the formula is as follows:

[0014] H SHA256 =SHA-256(F)

[0015] H MD5 =MD5(F)

[0016] Generate joint checksum H com as follows:

[0017] H com =H SHA256 ‖H MD5

[0018] Among them, F is the file, H is SHA256 is the SHA-256 hash value, H MD5 It is the MD5 hash value.

[0019] As a preferred solution of the method for offline bidirectional data synchronization on a mobile terminal of the present invention, the method of detecting potential conflicts by using a multi-version parallel management mechanism includes: setting the local data version as D local , the server data version is D server , data item d i ; The local data version set is:

[0020] V local = {v1,local ,v 2,local ,...,v n,local}; Server data version set: V server =

[0021] {v 1,server ,v 2,server ,...,v n,server}; For each data item d i If there are different modifications between the local data version and the server data version, that is: and It is considered that there is a potential conflict; the conflict resolution includes: assuming that the backtracking operation sequence set is O local and O server , by backtracking the operation sequence, determine the modification history of each data item; the priority of each operation p i By the corresponding weight ω i and timestamp t i Determine, the calculation formula is:

[0022] p i =ω i +f(t i )

[0023]

[0024] Where σ is the decay constant. The high-priority operation is automatically selected for application based on the priority. If the priorities are the same or difficult to solve automatically, the user is prompted to solve it manually.

[0025] As a preferred solution of the method for offline bidirectional data synchronization of a mobile terminal of the present invention, the multithreading technology includes: measuring network parameters, including bandwidth B, delay L and packet loss rate P, and calculating the network quality score:

[0026] NQ=w1×(B / Bmax)+w2×(1-L / Lmax)+w3×(1-P)

[0027] Among them, w1~w3 are weight factors, Bmax and Lmax are the preset maximum bandwidth and delay thresholds; the device parameters are measured, including CPU usage C, available memory M and battery power E, and the device performance score DP is:

[0028] DP=v1×(1-C / Cmax)+v2×(M / Mmax)+v3×(E / 100)

[0029] Among them, v1~v3 are weight factors, Cmax and Mmax are the maximum values ​​of CPU and memory respectively; dynamically determining the optimal number of threads includes the following steps:

[0030] Tbase=ceil(NQ×DP×T max )

[0031] Tadj = Tbase × (1 + log (S / S0))

[0032] T Z =min(max(Tadj,1),T max )

[0033] Among them, Tbase is the number of basic threads, T max is the preset maximum number of threads, ceil means rounding up, Tadj is the adjustment of the basic number of threads after considering the data size, S is the current data size, S0 is the benchmark data size, T Z The final number of threads.

[0034] In the second aspect, an embodiment of the present invention provides a system for offline bidirectional data synchronization on a mobile terminal, which includes a mapping initialization module for initializing a whole-table synchronization mechanism and establishing a file mapping structure of business table-data primary key-sub-table primary key-type hierarchy; an offline operation recording module for recording details of data operations performed by users in an offline state, and storing the data operations in a local cache; a network recovery synchronization module for starting the whole-table synchronization mechanism when the network connection is restored, performing data compression and block segmentation, sending a synchronization request to a server, and performing segmented data transmission; a server mapping module for storing and managing data using a mapping mechanism after the server receives the data; a conflict detection and resolution module for detecting potential conflicts using a multi-version parallel management mechanism and performing conflict resolution. After the conflicts are resolved, the data is merged with the local data and the synchronization is confirmed to the server; a synchronization confirmation and thread optimization module for updating local and global timestamps after confirming that all data has been synchronized, and at the same time, using multi-threading technology to dynamically determine the optimal number of threads.

[0035] In a third aspect, an embodiment of the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program instructions are executed by the processor, the steps of the method for offline bidirectional data synchronization on a mobile terminal as described in the first aspect of the present invention are implemented.

[0036] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program instructions are executed by a processor, the steps of the method for offline bidirectional data synchronization on a mobile terminal as described in the first aspect of the present invention are implemented.

[0037] The beneficial effects of the present invention are as follows: through data compression and block transmission, as well as the application of multi-threading technology, the present invention significantly improves the efficiency of data transmission, adapts to different network environments, and ensures that data can be smoothly synchronized even when the network is unstable; and through initialization of the whole table synchronization mechanism, offline data processing and multi-version parallel management mechanism, the present invention ensures data consistency and integrity during data synchronization, and avoids errors and data loss during data synchronization. The present invention significantly improves the efficiency, reliability and accuracy of mobile terminal data synchronization, ensures data consistency and integrity, and greatly improves user experience and system maintainability. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0039] Figure 1 This is a schematic diagram of two-way synchronization of offline data on a mobile terminal.

[0040] Figure 2 This is a structural diagram of the system for offline two-way data synchronization on mobile terminals. DETAILED DESCRIPTION

[0041] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.

[0042] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0043] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.

[0044] Example 1

[0045] Reference Figure 1-2 , which is the first embodiment of the present invention, and provides a method for offline bidirectional data synchronization of a mobile terminal, comprising:

[0046] S1: Initialize the whole table synchronization mechanism and establish a file mapping structure of business table-data primary key-subtable primary key-type hierarchy.

[0047] Specifically, a central database is established on the server side to ensure that all business tables are included, each table has a unique identifier, an optimized index structure is designed to improve query and synchronization efficiency, and a data backup and recovery strategy is implemented.

[0048] Establish a local database (such as SQLite) on the mobile terminal and ensure that the local database structure is consistent with the central database, including table structure, field types, and constraints.

[0049] Use database migration tools (such as Flyway or Liquibase) to manage database versions and changes, and establish a hierarchical file mapping structure of business table-data primary key-subtable primary key-type.

[0050] Create version information tables in the central and local databases to record the synchronization version number, time, and content, and establish a detailed logging system to prepare to record each step in the synchronization process.

[0051] S2: The user performs data operations in an offline state, records the operation details, including the modified content and local timestamp, and stores the operations in the local cache.

[0052] Specifically, offline data operations include: when a user adds or modifies data on a mobile terminal, the system automatically detects the network status, and after confirming the offline status, marks the newly added or modified data as offline data, and records information such as the operation timestamp and operation type (addition / modification); sets a unified file identifier for the newly added offline file, and records the association information between the file and related business data.

[0053] Furthermore, offline data is stored in a local database, and related files are stored in a local storage space, organized according to a predefined hierarchical structure. Data change logs are recorded in the local database, including the type, time, and specific content of the change, and operation information that may cause conflicts is recorded to prepare for subsequent conflict detection.

[0054] At the same time, the data processing capabilities of the mobile terminal are used to build H5 pages locally to display structured data.

[0055] S3: When the network connection is restored, the whole table synchronization mechanism is started to compress and block the data, send a synchronization request to the server, and transmit the data in segments.

[0056] Data compression and chunking involves compressing the changed data in the local cache and splitting the compressed data into chunks of appropriate size.

[0057] Specifically, a data compression and block parameter set CDP={CM, BS, CT} is defined, where CM represents a compression method, BS represents a block size, and CT represents a compression threshold.

[0058] CM={LZ,GZIP,DEFLATE}, indicating optional compression algorithms, including LZ77, GZIP and DEFLATE; BS indicates the maximum number of bytes of each data block; CT indicates the data size threshold that triggers compression (unit: bytes).

[0059] The operation process is as follows:

[0060] Traverse each cache data item CDi in the local cache set LC: calculate the data size size(CDi) of CDi, if size(CDi)>CT, then compress:

[0061] Select a compression method in CM to compress the content of the cache data item and obtain the compressed data com content ; Otherwise, keep the contents of the cache data item unchanged.

[0062] Divide the compressed data into blocks:

[0063] If size(com content )>BS: then com content Split into blocks of size BS, generate block index BI = {B1, B2, ...Bi, ..., Bk}, where Bi = [bid, offset, length], bid represents the block ID, offset represents the offset in the compressed data, and length represents the block length; otherwise, the entire com content as a block and updates the cached data item.

[0064] The compression rate calculation function is defined as follows:

[0065]

[0066] in, It is the original data content, which is the data item content that has not been compressed; It is the compressed data content, the data item content processed by the compression algorithm.

[0067] Set the compression effect evaluation threshold CET. If Com (CDn)<CET, then consider adjusting the compression method or parameters. For example, assume there is a cached data item CD1 = [1, "a large amount of text content...", 1628150400, 1628150400, {[create, 1628150400]}], set CT = 1024 bytes, BS = 512 bytes, select CM = GZIP, calculate size(CD1.content) = 2048 bytes > CT, then perform compression, use GZIP to compress the content part of the CD1 cached data item, and get com content , assume size(com content ) = 1200 bytes > BS, perform chunking, and generate a chunk index BI = {[1, 0, 512], [2, 512, 512], [3, 1024, 176]}.

[0068] Furthermore, among them, the synchronization request includes the global timestamp of the last synchronization, and the server returns the changed data after this timestamp.

[0069] The segmented data transmission includes the client uploading local changed data in chunks, and the server returning the data to be synchronized in segments. After each segment of synchronization is completed, the corresponding segment timestamp is updated.

[0070] S4: After the server receives the data, it uses the file mapping mechanism for data storage and management.

[0071] Preferably, first, the mobile terminal sends a synchronization download request to the server terminal. The server terminal organizes data and files according to the request and sends them as a data.zip file to the mobile terminal; after receiving the data.zip file, the mobile terminal decompresses and parses it, and updates the local database and local storage; when the mobile terminal is in the offline state, the newly added or modified data is marked as offline data, and a unified file identifier is set; when the mobile terminal is in the online state, according to the parsed JSON - format data received, it extracts business table data, file information, and metadata, and according to the business table - data primary key - sub - table primary key - type hierarchical file mapping structure established in S1, maps the data to the corresponding database tables and file storage locations.

[0072] Specifically, after the mobile terminal receives the data.zip file, the steps for decompressing and parsing it and updating the local database and local storage are as follows:

[0073] The mobile terminal decompresses the data.zip file to obtain the data.json file and related resource files; the mobile terminal parses the data.json file and imports the business table data into the local database; stores the decompressed resource files in the local storage space according to the hierarchical structure; the mobile terminal verifies the imported data to ensure data integrity and consistency.

[0074] Perform integrity and consistency checks on stored data. If any anomalies are found, they are recorded in the log system and the exception handling process is triggered.

[0075] Specifically, when the mobile terminal is in an offline state, newly added or modified data is marked as offline data, and setting a unified file identifier includes the following steps: newly added or modified business data is marked as offline data, and information such as operation timestamp and operation type are recorded, and encrypted using a locally stored encryption key to generate an encrypted file identifier for the offline file; offline data and files are stored in a local database and local storage space, and synchronized when the network is restored.

[0076] When the mobile terminal is online, the newly added or modified data and files in the local database are transmitted back to the server in the same format. The updating of the central database and the file server specifically includes the following steps:

[0077] The mobile terminal organizes the newly added or modified data and files into a data.json file and related resource files in the same format as the download, compresses and packages them into a data.zip file, and uploads the encrypted and compressed data.zip file to the server; the server decompresses and parses the data.zip file after receiving it, imports the newly added or modified data into the central database, stores the resource files to the file server, verifies the imported data and files, and ensures data integrity and consistency; the server parses the file hierarchy, binds data relationships, and assigns new file identifiers.

[0078] Preferably, verifying the imported data and files to ensure data integrity and consistency includes the following steps:

[0079] Use an asymmetric encryption algorithm (such as RSA or ECDSA) to sign the entire data packet, and use the public key to verify the signature at the receiving end to ensure that the data has not been tampered with; calculate the joint checksum of SHA-256 and MD5 for each file, as follows:

[0080] H SHA256 =SHA-256(F)

[0081] H MD5 =MD5(F)

[0082] Generate joint checksum H com as follows:

[0083] H com =H SHA256 ‖H MD5

[0084] Among them, F is the file, H is SHA256 is the SHA-256 hash value, HMD5 It is the MD5 hash value.

[0085] Through the above combination, the characteristics of different hash algorithms are utilized to improve the security and anti-collision ability of the checksum, and the security of the overall checksum is improved. Even if a certain hash algorithm is cracked, another algorithm can still provide protection.

[0086] The joint checksum is stored in a separate checksum file and transmitted along with the data packet. The receiving end recalculates the checksum and compares it with the transmitted joint checksum.

[0087] Furthermore, a unique version number is assigned to each data synchronization, and an incremental verification mechanism is implemented to verify only newly added or modified data, and a version history record is maintained to facilitate tracking of changes and rollbacks.

[0088] In the detailed logging system, all operation steps of this synchronization are recorded, including the receiving time, data volume, processing time, storage location and other information, and the version information table in the central database is updated to record the new synchronization version number, time and content summary.

[0089] S5: Use the multi-version parallel management mechanism to detect potential conflicts and resolve them. After resolving the conflicts, merge the data with the local data and confirm to the server that the synchronization is complete.

[0090] S5.1: Compare local data with the data returned by the server and use the multi-version parallel management mechanism to detect potential conflicts.

[0091] Set the local data version to D local , the server data version is D server , data item d i ; The local data version set is: V local = {v 1,local ,v 2,local ,...,v n,local}; Server data version set: V server = {v 1,server ,v 2,server ,...,v n,server}; For each data item d i If there are different modifications between the local data version and the server data version, that is: and A potential conflict is considered to exist.

[0092] S5.2: Conflict resolution using backtracking operation sequences.

[0093] Suppose the set of backtracking operation sequences is O local and O server,By backtracing the operation sequence, the modification history of each data item is determined in order to analyze the cause and priority of the conflict.

[0094] The priority p of each operation i By its corresponding weight ω i and timestamp t i Determine, the calculation formula is:

[0095] p i =ω i +f(t i )

[0096]

[0097] Here, σ is the decay constant.

[0098] The high-priority operation is automatically selected for application based on the priority. If the priorities are the same or difficult to solve automatically, the user is prompted to solve it manually.

[0099] S5.3: Merge the conflict-resolved data with the local data. After synchronization is complete, send a confirmation message to the server to ensure that the server updates the data status.

[0100] S6: After confirming that all data has been synchronized, update the local and global timestamps. At the same time, use multi-threading technology to dynamically determine the optimal number of threads to increase data transmission speed.

[0101] Preferably, the process of data synchronization confirmation includes:

[0102] Traverse all data tables and files that need to be synchronized, compare the local data version number with the server version number, and check the synchronization status.

[0103] Calculate the joint checksum of key data and compare the local checksum with the server-side checksum.

[0104] Implement a synchronization confirmation protocol, such as two-phase commit, where the local client sends a synchronization completion signal, and the server replies with a confirmation signal after confirming that all data has been received.

[0105] Furthermore, intelligent multi-threading technology is used to dynamically optimize data download and upload speeds, including:

[0106] Measure network parameters, including bandwidth B, latency L, and packet loss rate P, and calculate the network quality score:

[0107] NQ=w1×(B / Bmax)+w2×(1-L / Lmax)+w3×(1-P)

[0108] Among them, w1~w3 are weight factors respectively, and Bmax and Lmax are preset maximum bandwidth and delay thresholds.

[0109] Measuring device parameters, including CPU usage C, available memory M, and battery power E, the device performance score DP is:

[0110] DP=v1×(1-C / Cmax)+v2×(M / Mmax)+v3×(E / 100)

[0111] Among them, v1~v3 are weight factors, Cmax and Mmax are the maximum values ​​of CPU and memory.

[0112] Dynamically determining the optimal number of threads includes the following steps:

[0113] Tbase=ceil(NQ×DP×T max )

[0114] Tadj = Tbase × (1 + log (S / S0))

[0115] T Z =min(max(Tadj,1),T max )

[0116] Among them, Tbase is the number of basic threads, T max is the preset maximum number of threads, ceil means rounding up, Tadj is the adjustment of the basic number of threads after considering the data size, S is the current data size, S0 is the benchmark data size, T Z The final number of threads.

[0117] Furthermore, the present embodiment also provides a system for offline bidirectional data synchronization on a mobile terminal, including a mapping initialization module, which is used to initialize the whole table synchronization mechanism and establish a file mapping structure of business table-data primary key-subtable primary key-type hierarchy; an offline operation recording module, which is used to record the details of data operations performed by users in an offline state, and store the data operations in a local cache; a network recovery synchronization module, which is used to start the whole table synchronization mechanism when the network connection is restored, perform data compression and block segmentation, send a synchronization request to the server, and perform segmented data transmission; a server mapping module, which is used to store and manage data using a mapping mechanism after the server receives the data; a conflict detection and resolution module, which is used to detect potential conflicts using a multi-version parallel management mechanism and resolve conflicts. After resolving conflicts, the data is merged with the local data and the synchronization is confirmed to the server; a synchronization confirmation and thread optimization module, which is used to update local and global timestamps after confirming that all data has been synchronized, and at the same time, uses multi-threading technology to dynamically determine the optimal number of threads.

[0118] This embodiment also provides a computer device, which is suitable for the method of offline two-way data synchronization on a mobile terminal, and includes a memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute computer executable instructions to implement the method of offline two-way data synchronization on a mobile terminal as proposed in the above embodiment.

[0119] The computer device may be a terminal, and the computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covering the display screen, or a key, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.

[0120] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the method for realizing offline bidirectional data synchronization of a mobile terminal as proposed in the above embodiment is implemented.

[0121] In summary, the present invention significantly improves the efficiency of data transmission through data compression and block transmission, as well as the application of multi-threading technology, adapts to different network environments, and ensures that data can be synchronized smoothly even when the network is unstable; and by initializing the whole table synchronization mechanism, offline data processing and multi-version parallel management mechanism, the present invention ensures data consistency and integrity during data synchronization, and avoids errors and data loss during data synchronization. The present invention significantly improves the efficiency, reliability and accuracy of mobile terminal data synchronization, ensures data consistency and integrity, and greatly improves user experience and system maintainability.

[0122] Example 2

[0123] Referring to Table 1, which is a second embodiment of the present invention, this embodiment provides a method for offline bidirectional data synchronization on a mobile terminal. In order to verify the beneficial effects of the present invention, a scientific demonstration is carried out through simulation experiments.

[0124] This experiment selected a company's sales data and inventory management data as the experimental objects. The experimental environment includes a server and ten mobile devices. The server deploys a central database, and the mobile device deploys a local database (such as SQLite). The experiment uses the database migration tool Flyway to manage database versions and changes to ensure the consistency of the database structure. The specific steps are as follows:

[0125] A central database is established on the server side, which contains all business tables. Each table has a unique identifier and an optimized index structure is designed to improve query and synchronization efficiency.

[0126] Establish a local database on the mobile terminal and ensure that the local database structure is consistent with the central database, including table structure, field type and constraints. Create version information tables in the central and local databases to record the synchronization version number, time and content. Establish a detailed logging system and prepare to record each step in the synchronization process.

[0127] During the experiment, the network connection of the mobile device was deliberately disconnected, and the user performed data operations in an offline state, including adding new sales records, modifying inventory quantities, etc. The system automatically detected the network status and, after confirming that it was offline, marked the new or modified data as offline data and recorded information such as the operation timestamp and operation type.

[0128] Among them, all offline data are stored in the local database, and related files are stored in the local storage space and organized according to a predefined hierarchical structure.

[0129] When the network connection is restored, the whole table synchronization mechanism is started, data compression and block division are performed, a synchronization request is sent to the server, and segmented data transmission is performed. The data compression and block parameter set CDP = {CM, BS, CT} is defined, where CM selects GZIP, BS is set to 512 bytes, and CT is set to 1024 bytes. The compressed data is divided into blocks, and according to the global timestamp of the last synchronization included in the synchronization request, the server returns the changed data after the timestamp to complete the segmented data transmission.

[0130] After the server receives the data, the mobile terminal decompresses and parses the received data.zip file, updates the local database and local storage. The imported data is verified to ensure data integrity and consistency. If an abnormality is found, it is recorded in the log system and the abnormality handling process is triggered.

[0131] By backtracking the operation sequence, the modification history of each data item is determined to analyze the cause and priority of the conflict. The high-priority operation is automatically selected for application according to the priority. If the priority is the same or it is difficult to resolve automatically, the user is prompted to resolve it manually, and the conflict-resolved data is merged with the local data. After the synchronization is completed, a confirmation message is sent to the server to ensure that the server updates the data status.

[0132] After confirming that all data has been synchronized, update the local and global timestamps. The following is a partial experimental data record table:

[0133] Table 1 Part of the experimental data records

[0134]

[0135] From the table above, we can see that during the data synchronization process started after the network is restored, the compression algorithm GZIP significantly reduces the amount of data. For example, the original size of the newly added data of device 1 is 2048 bytes, which is only 1200 bytes after compression, with a compression rate of about 41.41%. This efficient compression greatly reduces the amount of transmitted data and improves data transmission efficiency.

[0136] During the experiment, the synchronization status of all devices was "synchronization completed", indicating that the multi-version parallel management mechanism effectively detected and resolved potential conflicts and ensured the consistency and integrity of the data.

[0137] During the synchronization process, the optimal number of threads is dynamically determined by measuring network and device parameters, thereby improving data transmission speed. For example, the data volume of device 6 is large, which is 4096 bytes. After multi-threaded optimized transmission, the synchronization status is displayed as "Synchronization Completed", which verifies the effectiveness of multi-threading technology.

[0138] It can be seen that the present invention shows significant innovation and advantages in the embodiments. Through efficient data compression and block transmission, multi-version parallel management mechanism and dynamic optimization technology, it solves the problems of low data synchronization efficiency, poor data consistency and insufficient system reliability in the prior art.

[0139] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.

Claims

1. A method for offline two-way data synchronization on a mobile terminal, characterized in that: include, Initialize the whole table synchronization mechanism and establish a file mapping structure of business table-data primary key-subtable primary key-type hierarchy; The user performs data operations in an offline state, records the data operation details, and stores the data operations in a local cache; When the network connection is restored, the whole table synchronization mechanism is started to compress and block the data, send a synchronization request to the server, and transmit the data in segments; After receiving the data, the server uses the file mapping mechanism to store and manage the data; Use the multi-version parallel management mechanism to detect potential conflicts and resolve them. After resolving the conflicts, merge the data with the local data and confirm the synchronization completion to the server. After confirming that all data has been synchronized, the local and global timestamps are updated. At the same time, multi-threading technology is used to dynamically determine the optimal number of threads.

2. The method for offline two-way data synchronization of a mobile terminal as claimed in claim 1, characterized in that: The data compression and segmentation includes the following contents: Define a data compression and block parameter set CDP = {CM, BS, CT}, where CM represents the compression method, BS represents the block size, and CT represents the compression threshold; CM={LZ,GZIP,DEFLATE}, indicating the optional compression algorithms, including LZ77, GZIP and DEFLATE; BS indicates the maximum number of bytes per data block; CT indicates the data size threshold that triggers compression, in bytes; Traverse each cache data item CDi in the local cache set LC: calculate the data size size(CDi) of CDi, if size(CDi)>CT, then compress: Select a compression method in CM to compress the content of the cache data item and obtain the compressed data com content ; Otherwise, keep the content of the cache data item unchanged; Divide the compressed data into blocks: If size(com content )>BS: then com content Split into blocks of size BS, generate block index BI = {B1, B2, ...Bi, ..., Bk}, where Bi = [bid, offset, length], bid represents the block ID, offset represents the offset in the compressed data, and length represents the block length; otherwise, the entire com content as a block and updates the cached data item.

3. The method for offline two-way data synchronization of a mobile terminal as claimed in claim 2, characterized in that: The data compression and segmentation also includes: The compression ratio calculation function is as follows: in, It is the original data content, which is the data item content that has not been compressed; It is the compressed data content, the data item content processed by the compression algorithm; Set the compression effect evaluation threshold CET. If Com (CDn) < CET, change the compression method or adjust the parameters.

4. The method for offline two-way data synchronization of a mobile terminal as claimed in claim 3, characterized in that: After the server receives the data, the file mapping mechanism is used to store and manage the data, including the following steps: The mobile terminal sends a synchronous download request to the server. The server organizes data and files according to the request, and packages them into a data.zip file and sends it to the mobile terminal. After receiving the data.zip file, the mobile terminal decompresses and parses it, and updates the local database and local storage; When the mobile terminal is offline, newly added or modified data is marked as offline data and a unified file identifier is set; When the mobile terminal is online, the business table data, file information and metadata are extracted by parsing the received JSON format data, and the data is mapped to the corresponding database table and file storage location according to the established business table-data primary key-subtable primary key-type hierarchical file mapping structure.

5. The method for offline two-way data synchronization of a mobile terminal as claimed in claim 4, characterized in that: When the mobile terminal is online, the newly added or modified data and files in the local database are transmitted back to the server in the same format to update the central database and file server; The server verifies the imported data and files to ensure data integrity and consistency, including: Use an asymmetric encryption algorithm to sign the entire data packet, and use the public key to verify the signature at the receiving end; calculate the joint checksum of SHA-256 and MD5 for each file, the formula is as follows: H SHA256 =SHA-256(F) H MD5 =MD5(F) Generate joint checksum H com as follows: H com =H SHA256 ‖H MD5 Among them, F is the file, H is SHA256 is the SHA-256 hash value, H MD5 It is the MD5 hash value.

6. The method for offline two-way data synchronization of a mobile terminal as claimed in claim 5, characterized in that: The use of a multi-version parallel management mechanism to detect potential conflicts includes: Set the local data version to D local , the server data version is D server , data item d i ; The local data version set is: V local = {v 1,local ,v 2,local ,...,v n,local }; Server data version set: V server = {v 1,server ,v 2,server ,...,v n,server }; For each data item d i If there are different modifications between the local data version and the server data version, that is: and It is considered that there is a potential conflict; The conflict resolution comprises: Suppose the set of backtracking operation sequences is O local and O server ,Determine the modification history of each data item by backtracking the sequence of operations; The priority p of each operation i By the corresponding weight ω i and timestamp t i Determine, the calculation formula is: p i =ω i +f(t i ) Where σ is the decay constant; The high-priority operation is automatically selected for application based on the priority. If the priorities are the same or difficult to solve automatically, the user is prompted to solve it manually.

7. The method for offline two-way data synchronization of a mobile terminal as claimed in claim 6, characterized in that: The multi-threading technology includes: Measure network parameters, including bandwidth B, latency L, and packet loss rate P, and calculate the network quality score: NQ=w1×(B / Bmax)+w2×(1-L / Lmax)+w3×(1-P) Among them, w1~w3 are weight factors, Bmax and Lmax are the preset maximum bandwidth and delay thresholds; Measuring device parameters, including CPU usage C, available memory M, and battery power E, the device performance score DP is: DP=v1×(1-C / Cmax)+v2×(M / Mmax)+v3×(E / 100) Among them, v1~v3 are weight factors, Cmax and Mmax are the maximum values ​​of CPU and memory; Dynamically determining the optimal number of threads includes the following steps: Tbase=ceil(NQ×DP×T max ) Tadj = Tbase × (1 + log (S / S0)) T Z =min(max(Tadj,1),T max ) Among them, Tbase is the number of basic threads, T max is the preset maximum number of threads, ceil means rounding up, Tadj is the adjustment of the basic number of threads after considering the data size, S is the current data size, S0 is the benchmark data size, T Z The final number of threads.

8. A system for offline two-way data synchronization of a mobile terminal, based on the method for offline two-way data synchronization of a mobile terminal according to any one of claims 1 to 7, characterized in that: Also includes, The mapping initialization module is used to initialize the whole table synchronization mechanism and establish a file mapping structure of business table-data primary key-subtable primary key-type hierarchy; An offline operation recording module is used to record the details of data operations performed by users in an offline state and store the data operations in a local cache; The network recovery synchronization module is used to start the whole table synchronization mechanism when the network connection is restored, perform data compression and block division, send synchronization requests to the server, and perform segmented data transmission; The server mapping module is used to store and manage data using the mapping mechanism after the server receives the data; The conflict detection and resolution module is used to detect potential conflicts using the multi-version parallel management mechanism and resolve conflicts. After resolving conflicts, the data is merged with the local data and the synchronization is confirmed to the server. The synchronization confirmation and thread optimization module is used to confirm that all data has been synchronized and then update the local and global timestamps. At the same time, it uses multi-threading technology to dynamically determine the optimal number of threads.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for offline bidirectional data synchronization on a mobile terminal as described in any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for offline bidirectional data synchronization on a mobile terminal as described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Data synchronization method, computing device, storage medium and program product

    CN121092635A

  • Offline electronic signing method and device for low network environment, and medium

    CN121462672A

  • Full-amount and increment collaborative intelligent verification method and system for data migration

    CN121560907A

  • A collaborative intelligent verification method and system for full and incremental data migration

    CN121560907B