Data transmission method, electronic device, and computer-readable storage medium
By using a database-level mapping method, the problem of slow cross-device data synchronization was solved, enabling fast data synchronization and efficient data fusion access.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2021-05-31
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies have relatively slow data synchronization speeds, especially in cross-device data synchronization, which is time-consuming and involves data format conversion.
By employing a database-level mapping method, the source database and the empty mapping database are virtualized to achieve data synchronization without involving data format conversion. Version comparison and upgrade or downgrade are used to ensure database version consistency and improve synchronization speed.
It reduces data synchronization time, increases data availability speed, and improves cross-device data fusion access performance.
Smart Images

Figure CN115481101B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a data transmission method, electronic device, and computer-readable storage medium. Background Technology
[0002] An electronic device can synchronize local data to another electronic device through data synchronization. Currently, the data synchronization process involves synchronizing data one data entry at a time, and the read / write process involves data format conversion, which is time-consuming and results in a slow data synchronization speed.
[0003] In other words, the data synchronization speed of existing technologies is relatively slow. Summary of the Invention
[0004] This application provides a data transmission method, an electronic device, and a computer-readable storage medium, which can improve data synchronization speed.
[0005] In a first aspect, embodiments of this application provide a cross-device data transmission method using a second electronic device. The method includes: receiving a first event from a first electronic device, the first event including first database version information, the first database version information describing the database version of a second source database, the second source database being a local database of the first electronic device; creating a first empty mapping database of the first source database based on the first database version information, the first source database being a local database of the second electronic device; virtualizing the first source database and the first empty mapping database to obtain a first virtual database; performing data mapping in the first virtual database to map data in the first source database to the first empty mapping database, obtaining a first database with completed data mapping; obtaining the first mapping database based on the first database; and sending the first mapping database to the first electronic device.
[0006] As can be seen, the embodiments of this application map the database as a whole to the peer device, realizing database-level data synchronization without involving data format conversion, reducing data synchronization time, improving data synchronization speed, and making data available faster.
[0007] Among some possible implementations of the first aspect, a first mapping database is obtained based on the first database, including:
[0008] Based on the first database version information and the second database version information, compare the database versions of the first source database and the second source database. The second database version information is used to describe the database version of the first source database.
[0009] If the version of the first source database is higher than the version of the second source database, the version of the first database is downgraded to obtain the first mapping database, and the version of the first mapping database is the same as the version of the second source database.
[0010] If the version of the first source database is lower than or equal to the version of the second source database, the first database will be used as the first mapping database, and the version of the first mapping database will be consistent with the version of the first source database.
[0011] Furthermore, when the data versions and data table structures of the two electronic devices are different, the embodiments of this application perform version downgrading accordingly based on the database versions of the two electronic devices, thereby making the database-level synchronization method of the embodiments of this application more widely applicable.
[0012] In some possible implementations of the first aspect, when the version of the first source database is higher than the version of the second source database, the version of the first empty mapping database is consistent with the version of the first source database, and the table structure of the first empty mapping database is consistent with the table structure of the second source database.
[0013] When the version of the first source database is lower than the version of the second source database, the version of the first empty mapping database is the same as the version of the first source database, and the table structure of the first empty mapping database is the same as the table structure of the first source database.
[0014] Among some possible implementations of the first aspect, the method also includes:
[0015] Send a second event to the first electronic device, the second event including second database version information;
[0016] The system receives a second mapping database from a first electronic device. The second mapping database is a mapping database of a second source database established by the first electronic device based on the second database version information.
[0017] In this implementation, both the first electronic device and the second electronic device can synchronize their local databases as a whole to the peer device.
[0018] In some possible implementations of the first aspect, after receiving the second mapping database from the first electronic device, the method further includes:
[0019] If the version of the first source database is lower than the version of the second source database, the second mapping database and the first source database are virtualized to obtain the second virtual database;
[0020] If the version of the first source database is higher than the version of the second source database, the second mapping database is upgraded to obtain an upgraded second mapping database. The version of the upgraded second mapping database is the same as the version of the first source database.
[0021] The upgraded second mapping database and the first source database are virtualized to obtain the second virtual database.
[0022] In this implementation, a virtualized database is obtained by virtualizing the first source database and the second mapping database, eliminating the need to synchronize data from the two databases one by one, thus further improving data synchronization speed. The second virtual database comprises the independent first source database and the second mapping database.
[0023] In addition, virtualizing the two databases into a single virtual database facilitates subsequent cross-device data fusion and access.
[0024] In some possible implementations of the first aspect, after virtualizing the second mapping database and the first source database to obtain the second virtual database, the method further includes:
[0025] Obtain a first data access request from a first application, wherein the second electronic device includes the first application;
[0026] If the first data access request includes the device identifier of the first electronic device, the second mapping database in the second virtual database is queried to obtain the first query result, and the first query result is returned to the first application;
[0027] If the first data access request does not include the device identifier, query the second mapping database and the first source database in the second virtual database to obtain the second query result, and return the second query result to the first application;
[0028] If the first data access request includes the device identifier of the second electronic device, the first source database in the second virtual database is queried to obtain the third query result, and the third query result is returned to the first application.
[0029] In this implementation, the second electronic device pre-maps the local database of the first electronic device to its local storage space, allowing access to data on the first electronic device to be treated like accessing a local database—providing cross-device data access similar to local database access. Furthermore, when accessing data on the first electronic device, the process from initiating an access request to obtaining the query result does not involve connecting to a remote database or data backhauling from the remote database. Query speed is unaffected by network transmission quality, resulting in shorter processing time and higher performance for cross-device data access. Additionally, the second electronic device virtualizes its local database and the mapped database of the peer device into a single database, allowing for querying and filtering of data from multiple devices with a single query request, achieving integrated cross-device data access.
[0030] Furthermore, during data synchronization, the database is mapped as a whole to the peer device, which reduces data synchronization time, improves data availability speed, and further enhances data fusion access performance.
[0031] In some possible implementations of the first aspect, after the second electronic device receives the second mapping database from the first electronic device, it further includes:
[0032] Receive a first change script from a first electronic device, the first change script including a table for recording change data of a second source database;
[0033] If the version of the first source database is higher than the version of the second source database, the first change script will be upgraded to obtain the upgraded first change script. The table structure of the upgraded first change script is consistent with the table structure of the first source database.
[0034] By executing the upgraded first change script, the changed data of the second source database is loaded into the second mapping database;
[0035] If the version of the first source database is lower than the version of the second source database, the changed data of the second source database is loaded into the second mapping database by executing the first change script.
[0036] Among some possible implementations of the first aspect, the method also includes:
[0037] Based on the first data state tree, it is determined whether the data in the first source database has changed. The first data state tree is used to describe the state of the data in the first source database mapped to the first empty mapping database.
[0038] If the data in the first source database changes, the changed data in the first source database will be recorded in the second change script. The second change script includes a table for recording the changed data.
[0039] Send the second change script to the first electronic device;
[0040] Where the version of the first source database is higher than the version of the second source database, the table structure of the second change script is consistent with the table structure of the second source database.
[0041] When the version of the first source database is lower than the version of the second source database, the table structure of the second change script is consistent with the table structure of the first source database.
[0042] In this implementation, data status information is recorded during data mapping, and the data is monitored in real time to see if any changes are detected. When changes are detected, the changed data is synchronized to the peer device based on the data status information, which enables cross-device data status management and real-time cross-device data query.
[0043] Among some possible implementations of the first aspect, after determining that the data in the first source database has changed, it also includes:
[0044] Update the first data state tree.
[0045] Secondly, embodiments of this application provide a cross-device data transmission method, applied to a first electronic device, the method comprising:
[0046] Send a first event to the second electronic device. The first event includes first database version information, which describes the database version of the second source database. The second source database is the local database of the first electronic device.
[0047] The device receives a first mapping database from a second electronic device. The first mapping database is a mapping database of a first source database established by the second electronic device based on the first database version information. The first source database is a local database of the second electronic device.
[0048] In some possible implementations of the second aspect, after receiving the first mapping database from the second electronic device, the following is also included:
[0049] If the version of the first source database is higher than the version of the second source database, the first mapping database and the second source database are virtualized to obtain the third virtualized database.
[0050] If the version of the first source database is lower than the version of the second source database, the first mapping database will be upgraded to obtain an upgraded first mapping database. The version of the upgraded first mapping database will be the same as the version of the second source database.
[0051] The upgraded first mapping database and second source database are virtualized to obtain a third virtual database.
[0052] In some possible implementations of the second aspect, after obtaining the third virtual database, the method further includes:
[0053] Obtain a second data access request from a second application, wherein the first electronic device includes the second application;
[0054] If the second data access request includes the device identifier of the first electronic device, query the second source database in the third virtual database to obtain the fourth query result, and return the fourth query result to the second application;
[0055] If the second data access request does not include the device identifier, query the first mapping database and the second source database in the third virtual database to obtain the fifth query result, and return the fifth query result to the second application;
[0056] If the second data access request includes the device identifier of the second electronic device, query the first mapping database in the third virtual database to obtain the sixth query result, and return the sixth query result to the second application.
[0057] In some possible implementations of the second aspect, after receiving the first mapping database from the second electronic device, the method further includes:
[0058] Receive a second change script from a second electronic device, the second change script including a table for recording change data of the first source database;
[0059] If the version of the first source database is lower than the version of the second source database, the second change script will be upgraded to obtain the upgraded second change script. The table structure of the upgraded second change script is consistent with the table structure of the second source database.
[0060] By executing the upgraded second change script, the changed data of the first source database is loaded into the first mapping database;
[0061] If the version of the first source database is higher than the version of the second source database, the changed data of the first source database is loaded into the first mapped database by executing the second change script.
[0062] Among some possible implementations of the second aspect, the method also includes:
[0063] Receive a second event from a second electronic device, the second event including second database version information, the second database version information being used to describe the database version of the first source database;
[0064] Based on the second database version information, create a second empty mapping database for the second source database;
[0065] The second source database and the second empty mapping database are virtualized to obtain the fourth virtual database;
[0066] Data mapping is performed in the fourth virtual database to map the data in the second source database to the second empty mapping database, resulting in the second database with completed data mapping.
[0067] Based on the second database, a second mapping database is obtained;
[0068] Send the second mapping database to the second electronic device.
[0069] Among some possible implementations of the second aspect, a second mapping database is obtained based on the second database, including:
[0070] Based on the version information of the first database and the version information of the second database, compare the database versions of the first source database and the second source database.
[0071] If the version of the first source database is lower than or equal to the version of the second source database, the version of the second database is downgraded to obtain the second mapping database, and the version of the second mapping database is consistent with the version of the first source database.
[0072] If the version of the first source database is higher than the version of the second source database, the second database will be used as the first mapping database, and the version of the second mapping database will be the same as the version of the second source database.
[0073] In some possible implementations of the second aspect, when the version of the first source database is lower than the version of the second source database, the version of the second empty mapping database is consistent with the version of the second source database, and the table structure of the second empty mapping database is consistent with the table structure of the first source database.
[0074] When the version of the first source database is higher than the version of the second source database, the version of the second empty mapping database is the same as the version of the second source database, and the table structure of the second empty mapping database is the same as the table structure of the second source database.
[0075] In some possible implementations of the second aspect, after sending the first mapping database to the first electronic device, the following is also included:
[0076] Based on the second data state tree, it is determined whether the data in the second source database has changed. The second data state tree is used to describe the state of the data in the second source database that is mapped to the second empty mapping database.
[0077] If the data in the second source database changes, the changed data in the second source database will be recorded in the first change script. The first change script includes a table for recording the changed data.
[0078] Update the second data state tree;
[0079] Send the first change script to the second electronic device;
[0080] Where the version of the first source database is lower than the version of the second source database, the table structure of the first change script is consistent with the table structure of the first source database.
[0081] When the version of the first source database is higher than the version of the second source database, the table structure of the first change script is consistent with the table structure of the second source database.
[0082] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method as described in either the first or second aspect above.
[0083] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method as described in either the first or second aspect above.
[0084] Fifthly, embodiments of this application provide a chip system including a processor coupled to a memory. The processor executes a computer program stored in the memory to implement the method described in either the first or second aspect above. The chip system may be a single chip or a chip module composed of multiple chips.
[0085] Sixthly, embodiments of this application provide a computer program product that, when run on an electronic device, causes the electronic device to perform the method described in either the first or second aspect above.
[0086] It is understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0087] Figure 1 A schematic block diagram of the system architecture provided in the embodiments of this application;
[0088] Figure 2 A detailed schematic diagram of the system architecture provided in the embodiments of this application;
[0089] Figure 3 A schematic flowchart illustrating the data mapping process provided in this application embodiment;
[0090] Figure 4 A schematic flowchart of a database mapping mode provided in an embodiment of this application;
[0091] Figure 5 This is a schematic diagram of database mapping when the database versions are the same, provided in an embodiment of this application.
[0092] Figure 6 A schematic diagram of database mapping from a higher version to a lower version provided in an embodiment of this application;
[0093] Figure 7 A schematic diagram of database mapping from a lower version to a higher version provided in an embodiment of this application;
[0094] Figure 8 A schematic flowchart of a database mapping mode provided in an embodiment of this application;
[0095] Figure 9 A schematic diagram of the table mapping process provided in this application embodiment;
[0096] Figure 10 A schematic diagram of a data change monitoring process provided in an embodiment of this application;
[0097] Figure 11 This is a schematic diagram illustrating the data change monitoring process for synchronizing from a higher version to a lower version according to an embodiment of this application.
[0098] Figure 12 A schematic diagram illustrating the data change monitoring process during synchronization from a lower version to a higher version, provided in an embodiment of this application;
[0099] Figure 13 A schematic flowchart illustrating the data fusion access process provided in this application embodiment;
[0100] Figure 14 This is a schematic diagram illustrating cross-device media data fusion access provided in an embodiment of this application;
[0101] Figure 15 This is a schematic diagram illustrating cross-device access to image data provided in an embodiment of this application;
[0102] Figure 16 This is a schematic diagram of cross-device image search provided in an embodiment of this application;
[0103] Figure 17 This is a schematic diagram of data fusion access under the database mapping mode provided in the embodiments of this application;
[0104] Figure 18 This is a schematic diagram of data fusion access under the table mapping mode provided in the embodiments of this application;
[0105] Figure 19 A schematic diagram of a database mapping pattern based on distributed data middleware provided in an embodiment of this application;
[0106] Figure 20 A schematic diagram of a table mapping pattern based on distributed data middleware provided in an embodiment of this application;
[0107] Figure 21 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0108] In the following description, specific details such as particular system architectures and technologies are set forth for illustrative purposes and not for limiting purposes, in order to provide a thorough understanding of the embodiments of this application.
[0109] The system architecture and application scenarios that may be involved in the embodiments of this application are first described below by way of example.
[0110] See Figure 1 The illustrated system architecture diagram provided in this application embodiment includes a first electronic device 11 and at least one second electronic device 12. The first electronic device 11 and the second electronic device 12 can communicate with each other via a communication connection. The communication connection between the first electronic device 11 and the second electronic device 12 can be a short-range communication connection, such as a Wi-Fi point-to-point connection or a Bluetooth connection; or it can be a long-range communication connection, such as an internet connection. The specific type of communication connection is not limited here.
[0111] The first electronic device 11 can be a terminal device such as a mobile phone, tablet computer, or laptop computer, or a non-terminal device such as a server. Similarly, the second electronic device 12 can be a terminal device such as a mobile phone, tablet computer, or laptop computer, or a non-terminal device such as a server. This application embodiment does not limit the device types of the first electronic device 11 and the second electronic device 12.
[0112] For example, see Figure 2 The illustrated system architecture diagram of this application embodiment shows a system including a mobile phone 21, a mobile phone 22, a tablet 23, and a cloud server 24. Specifically, the first electronic device is mobile phone 21, while the second electronic device includes mobile phone 22, tablet 23, and cloud server 24.
[0113] The communication connection between mobile phone 21 and mobile phone 22 can be a Wi-Fi peer-to-peer connection, the communication connection between mobile phone 21 and tablet 23 can be a Wi-Fi peer-to-peer connection, and the communication connection between mobile phone 21 and cloud server 24 can be an Internet connection.
[0114] Based on the communication connection between the first electronic device 11 and the second electronic device 12, the first electronic device 11 can map the data of the second electronic device 12 to its local storage space. In this way, the first electronic device 11 can access the data of the second electronic device 12 in its local storage space, realizing cross-device data fusion access. Similarly, the second electronic device 12 can also map the data of the first electronic device 11 to its local storage space to achieve cross-device data fusion access.
[0115] Data fusion access refers to the ability to filter, sort, and perform other queries on data from multiple electronic devices using a single query request. For example, a first electronic device 11 maps the database of a second electronic device 12 to its local storage space and virtualizes both the database of the first electronic device 12 and the local database to obtain a virtual database. Based on this virtual database, the first electronic device 11 can access its own data and the data of the second electronic device 12 from this virtual database through a single query request, filtering and sorting the data from both devices to obtain the query results.
[0116] The data accessed across devices can be media data, such as video, audio, and images; it can also be other types of data. This application does not limit the data types accessed across devices.
[0117] For example, in a distributed image library scenario, a user can browse or search for images stored on any of the following electronic devices: mobile phone 22, tablet 23, and cloud server 24, in the image library on mobile phone 21.
[0118] The technical solutions provided in the embodiments of this application will be described in detail below.
[0119] The technical solutions provided in this application embodiment may include a data mapping process, a data change monitoring process, and a data fusion access process.
[0120] Data mapping process (also known as data transfer process):
[0121] In the data mapping process, this application embodiment maps the database or database table as a whole to the peer device, achieving data synchronization at the database level or file level. Compared to the ordinary data synchronization process, the data mapping process in this application embodiment can improve data synchronization speed and make data available faster.
[0122] Specifically, a typical data synchronization process involves synchronizing data line by line, and the read / write process involves data format conversion, which is time-consuming and results in a slow data synchronization speed. For example, in order to synchronize data from a second electronic device to its local storage, the first electronic device reads data from the second electronic device line by line and writes the read data to its local storage, requiring format conversion during the read / write process.
[0123] The data mapping process in this application embodiment achieves data synchronization at the database level or file level, without involving data format conversion, reducing data synchronization time, improving data synchronization speed, and making data available faster.
[0124] For example, after the second electronic device is connected to the network, through the data mapping process of the embodiments of this application, the data of the second electronic device is mapped to the first electronic device in a very short time. In this way, the data of the second electronic device can be used by the first electronic device (e.g., query). The data is available quickly and can be used as soon as the second electronic device is online. That is, as soon as the second electronic device is online, the first electronic device can access the data of the second electronic device locally.
[0125] In addition, the data mapping process in this application improves the data synchronization speed, further enhancing the performance of cross-device data fusion access.
[0126] To better illustrate the data mapping process, the following section will provide a detailed explanation of the process in conjunction with the accompanying diagram.
[0127] See Figure 3 The illustrated flowchart represents a data mapping process provided in an embodiment of this application. The method may include the following steps:
[0128] Step S301: The first electronic device sends a first event to the second electronic device.
[0129] The aforementioned first event may include, but is not limited to, device information and database version information of the first electronic device. Device information of the first electronic device includes, but is not limited to, device type, device identifier, and Internet Protocol address (IP). Database version information of the first electronic device describes information such as the version number (i.e., version code) of its local database.
[0130] In some embodiments, the first event may include database version information, while in other embodiments, the first event may not include database version information.
[0131] The aforementioned first event can manifest as a device online event. That is, after the first electronic device and the second electronic device establish a communication connection, in order to map the data of the second electronic device to the local device, the first electronic device can send a device online event to the second electronic device. For example, after a mobile phone and a tablet establish a Wi-Fi peer-to-peer connection, in order to map the tablet's data to the mobile phone's local device, the mobile phone sends a device online event to the tablet. Alternatively, the mobile phone is already connected to a wireless router, and after the tablet is connected to the same wireless router, the mobile phone sends a device online event to the tablet.
[0132] Of course, the first event is not limited to the device going online event; it can be any other event that can have the same effect. Furthermore, the time when the first electronic device sends the first event is not limited to after the device goes online.
[0133] Step S302: The second electronic device sends a second event to the first electronic device.
[0134] The aforementioned second event may include, but is not limited to, device information and database version information of the second electronic device. Device information of the second electronic device includes, but is not limited to, device type, device identifier, and IP address. Database version information of the second electronic device describes information such as the version number of its local database. In some cases, the second event may not include database version information.
[0135] The aforementioned second event can manifest as a device online event. That is, after the first electronic device and the second electronic device establish a communication connection, in order to map the data of the first electronic device to the local device, the second electronic device can send a device online event to the first electronic device. Of course, the second event is not limited to a device online event and can be other types of events. Furthermore, the timing of the second electronic device sending the second event is not limited to after the device goes online.
[0136] It should be noted that the execution order between steps S301 and S302 can be arbitrary.
[0137] Step S303: The second electronic device establishes a first mapping data set of the first source data set according to the first event.
[0138] The first source data set refers to the local data set of the second electronic device, which can be specifically a database or a database table. When the first source data set is a database, the first mapping data set is correspondingly a mapping database of the local database; when the first source data set is a database table, the first mapping data set is correspondingly a mapping table of the local database table.
[0139] Step S304: The second electronic device sends the first mapping data set to the first electronic device.
[0140] If the first mapped data set is a mapped database, after receiving the first mapped data set, the first electronic device can virtualize the first mapped data set and the local database into a single virtual database to facilitate subsequent data fusion access. Of course, if data fusion access is not required, it is not necessary to virtualize the first mapped data set and the local data set into a single virtual database.
[0141] If the first mapping data set is a mapping table, the first electronic device can load the first mapping data set into the intermediate result database after receiving it.
[0142] After receiving the first mapping data set, the first electronic device can associate the device information of the second electronic device with the first mapping data set, so that the first mapping data set can be queried through the device information of the second electronic device.
[0143] Step S305: The first electronic device establishes a second mapping data set of the second source data set according to the second event.
[0144] The aforementioned second source data set refers to the local data set of the first electronic device, which can be a database or a database table. When the first source data set is a local database, the second mapping data set is a mapping database of the local database; when the first source data set is a local database table, the second mapping data set is a mapping table of the local database table.
[0145] Step S306: The first electronic device sends the second mapping data set to the second electronic device.
[0146] If the second mapped data set is a mapped database, after receiving the second mapped data set, the second electronic device can virtualize the second mapped data set and the local database into a single virtual database to achieve data fusion access. Of course, if data fusion access is not required, it is not necessary to virtualize the second mapped data set and the local data set into a single virtual database.
[0147] If the second mapping data set is a mapping table, the second electronic device can load the second mapping data set into the intermediate result database after receiving it.
[0148] After receiving the second mapping data set, the second electronic device can associate the device information of the first electronic device with the second mapping data set, so that the second mapping data set can be queried through the device information of the first electronic device.
[0149] Figure 3The process of a second electronic device mapping a local data set to a first electronic device is illustrated, specifically including steps S301, S303, and S304; the process of the first electronic device mapping a local data set to the second electronic device is also illustrated, specifically including steps S302, S305, and S306. That is, in some embodiments, the data mapping process of this application embodiment may include both the process of the second electronic device mapping a local data set to the first electronic device and the process of the first electronic device mapping a local data set to the second electronic device.
[0150] In other embodiments, the data mapping process may only include the process of the second electronic device mapping the local data set to the first electronic device, that is, the first electronic device maps the data set of the second electronic device to the local device without mapping the local data set to the second electronic device; or it may only include the process of the first electronic device mapping the local data set to the second electronic device.
[0151] As can be seen from the above, the embodiments of this application map the database or database table as a whole to the peer device, realize data synchronization at the database level or file level, reduce data synchronization time, make data available faster, and further improve the performance of cross-device data fusion access.
[0152] Depending on the type of mapped data set established by the first or second electronic device, the data mapping process can be divided into a database mapping process or a table mapping process. Specifically, when the mapped data set established by the first or second electronic device is a mapped database, the data mapping process is a database mapping process, also known as a database mapping mode; when the mapped data set established by the first or second electronic device is a mapped database table, the data mapping process is a table mapping process, also known as a table mapping mode. These two modes will be described in detail below.
[0153] Database mapping process:
[0154] See Figure 4 The illustrated embodiment of this application provides a schematic diagram of a database mapping pattern, which may include the following steps:
[0155] Step S401: The first electronic device sends a first event to the second electronic device.
[0156] Step S402: The second electronic device creates the first empty mapping database of the first source database based on the database version information in the first event.
[0157] At this point, the first source data set is specifically the first source database, which is the local database of the second electronic device. The aforementioned first empty mapping database refers to an empty database that has not yet been loaded with data and is still an empty database.
[0158] The second electronic device compares the database version of the first electronic device with the database version of the second electronic device based on the database version information from the first event.
[0159] If the database version of the first electronic device is higher than the database version of the second electronic device, the version of the first empty mapping database is the same as the version of the first source database, and the table structure of the first empty mapping database is the same as the table structure of the first source database.
[0160] If the database version of the first electronic device is lower than or equal to the database version of the second electronic device, the version of the first empty mapping database is consistent with the version of the first source database, and the table structure within the first empty mapping database is consistent with the table structure of the local database of the first electronic device. Since the higher version database can know the table structure information of the lower version database, the second electronic device can know the table structure information of the database of the first electronic device.
[0161] Step S403: The second electronic device virtualizes the first source database and the first empty mapping database to obtain the first virtual database.
[0162] Step S404: The second electronic device performs data mapping in the first virtual database to map the data in the first source database to the first empty mapping database, thereby obtaining the mapped database.
[0163] If the database version of the first electronic device is lower than or equal to the database version of the second electronic device, the table structure in the first empty mapping database is consistent with the table structure of the local database of the first electronic device. Therefore, the data is filtered according to the table structure of the local database of the first electronic device during data mapping.
[0164] Step S405: The second electronic device obtains the first mapping database based on the mapped database. At this time, the first mapping data set is specifically the first mapping database.
[0165] If the database version of the first electronic device is higher than the database version of the second electronic device, the second electronic device will use the mapped database as the first mapped data set.
[0166] If the database version of the first electronic device is lower than that of the database version of the second electronic device, the second electronic device will downgrade the mapped database to obtain the first mapped database. The version of the first mapped database is consistent with the version of the local database of the first electronic device.
[0167] Step S406: The first electronic device receives the first mapping database from the second electronic device.
[0168] If the database version of the first electronic device is lower than or equal to the database version of the second electronic device, then the version of the first mapped database is consistent with the version of the local database of the first electronic device, and the table structure is also consistent with the table structure of the local database of the first electronic device. In this case, after receiving the first mapped database, the first electronic device can virtualize the first mapped database and the local database to obtain a third virtual database.
[0169] If the database version of the first electronic device is higher than that of the second electronic device, then the version of the first mapping database is the same as the version of the first source database of the second electronic device, and the table structure is also the same as that of the first source database of the second electronic device. In this case, the first electronic device needs to upgrade the version of the first mapping database to obtain the upgraded mapping database. The version of the upgraded mapping database is the same as the version of the local database of the first electronic device, and the table structure is also the same as that of the local database of the first electronic device. After the version upgrade is completed, the first electronic device virtualizes the upgraded mapping database and the local database to obtain a third virtual database.
[0170] Based on a third virtual database, the first electronic device can access data from the second electronic device across devices.
[0171] In this process, after receiving the first mapping database, the first electronic device can associate the device information of the second electronic device with the first mapping database.
[0172] It should be noted that virtualizing the mapping database and the local source database to obtain a virtualized database avoids the need for data fusion by fusing data record by record. This also enables subsequent data fusion access, allowing a single query request to retrieve and filter data from multiple electronic devices from a single database. Of course, in some embodiments, the step of virtualizing the mapping database and the local source database may not be necessary.
[0173] It should also be noted that the first mapped database and the first virtual database in the second electronic device are temporary. Specifically, after the second electronic device sends the first mapped database to the first electronic device, it can clear the first mapped database from its local cache. Similarly, after performing a data version downgrade, the second electronic device can also clear the mapped database from its local cache. After mapping data from the first source database to the first empty mapped database, the second electronic device can revoke the first virtual database.
[0174] As can be seen, the database mapping process maps the database as a whole to the peer device, reducing data synchronization time, improving data availability speed, and enhancing cross-device data fusion access performance.
[0175] To better explain the database mapping process, the following will combine... Figure 5 , Figure 6 and Figure 7 An introduction and explanation will be provided. Among them, Figure 5 This is a schematic diagram illustrating database mapping when database versions are the same, as provided in the embodiments of this application. Figure 6 This is a schematic diagram of database mapping from a higher version to a lower version provided in an embodiment of this application. Figure 7 This is a schematic diagram of database mapping from a lower version to a higher version, provided in an embodiment of this application.
[0176] See Figure 5 The second electronic device 52 includes a source database 53 and a mapping database 54, and the first electronic device 51 includes a mapping database 54 and a target database 55.
[0177] At this point, the first electronic device 51 and the second electronic device 52 have the same database version and table structure; that is, the source database 53 and the target database 55 have the same version and table structure. Specifically, the first source data set is the source database 53, and the first mapped data set is the mapped database 54. The local database of the first electronic device is the target database 55.
[0178] After receiving the first event from the first electronic device 51, the second electronic device 52 creates a first empty mapping database for the source database 53. The table structure of the first empty mapping database is consistent with the table structure of the target database 53, and the database version is consistent with the version of the source database 53. Then, the first empty mapping database and the source database 53 are virtualized to obtain a first virtual database, and fast data mapping is performed within the first virtual database to map the data of the source database 53 to the first empty mapping database, resulting in a mapping database 54. Finally, the mapping database 54 is transmitted to the first electronic device 51.
[0179] After receiving the mapping database 54, the first electronic device 51 virtualizes the mapping database 54 and the target database 55 to obtain a third virtual database.
[0180] The second electronic device 52 can transmit the database file of the mapping database 54 to the first electronic device 51, and can also transmit the data of the mapping database 54 to the first electronic device 51.
[0181] In some embodiments, after the second electronic device 52 performs data mapping in the first virtual database and obtains the mapped database 54, it can cancel the first virtual database. After sending the mapped database 54 to the first electronic device 51, it can clear the mapped database 54 in the local cache.
[0182] See Figure 6 The database version of the second electronic device 62 is higher than that of the first electronic device 61, that is, the version of the source database 63 is higher than that of the target database 66. The second electronic device 62 includes the source database 63, the mapping database 64, and the mapping database 65, while the first electronic device 61 includes the mapping database 65 and the target database 66.
[0183] At this point, the first source data set is specifically the source database 63, the mapped database after mapping is the mapping database 64, the first mapped data set is specifically the mapping database 65, and the local database of the first electronic device is the target database 66.
[0184] After receiving a first event from the first electronic device 61, the second electronic device 62 determines, based on the database version information in the first event, that the version of the source database 63 is higher than the version of the target database 66, and based on the database version information of the target database 66, obtains the table structure information of the target database 66. Then, it creates a first empty mapping database for the source database 63. At this time, the version of the first empty mapping database is the same as the version of the source database 63, and the table structure is the same as the table structure of the target database 66. Next, the source database 63 and the first empty mapping database are virtualized to obtain a first virtual database. Fast data mapping is performed within the first virtual database, and data filtering is performed according to the table structure of the target database 66 to map the data of the source database 63 to the first empty mapping database, resulting in a mapping database 64. The version of the mapping database 64 is the same as the version of the source database 63, and the table structure is the same as the table structure of the target database 66.
[0185] Next, the second electronic device 62 downgrades the version of the mapping database 64 to obtain the mapping database 65. The version of the mapping database 65 is the same as that of the target database 66, and the table structure is also the same as that of the target database 66. Finally, the second electronic device 62 transmits the mapping database 65 to the first electronic device 61.
[0186] After receiving the mapping database 65, the first electronic device 61 virtualizes the mapping database 65 and the target database 66 to obtain a third virtual database.
[0187] In some embodiments, after performing data mapping and obtaining the mapping database 64, the second electronic device 62 can revoke the first virtual database; after performing version downgrading and obtaining the mapping database 65, it can clear the mapping database 64 in the local cache; after sending the mapping database 65 to the first electronic device 61, it can clear the mapping database 65 in the local cache.
[0188] See Figure 7 The database version of the first electronic device 71 is higher than that of the second electronic device 72, that is, the version of the target database 76 is higher than that of the source database 73. The first electronic device 71 includes the target database 76, the mapping database 75, and the mapping database 74, and the second electronic device 72 includes the source database 73 and the mapping database 74.
[0189] At this point, the first source data set is specifically the source database 73, the mapped database and the first mapped data set are both specifically the mapping database 74, and the local database of the first electronic device is the target database 76.
[0190] After receiving the first event from the first electronic device 71, the second electronic device 72 determines, based on the database version information in the first event, that the version of the target database 76 is higher than the version of the source database 73. Then, it creates a first empty mapping database for the source database 73, whose version and table structure are identical to those of the source database 73. Next, it virtualizes the first empty mapping database and the source database 73 to obtain a first virtual database, and performs fast data mapping within the first virtual database to obtain a mapping database 74. The version and table structure of the mapping database 74 are identical to those of the source database 73. Finally, the second electronic device 72 transmits the mapping database 74 to the first electronic device 71.
[0191] After receiving the mapping database 74, the first electronic device 71 upgrades the version of the mapping database 74 to obtain the mapping database 75. The version of the mapping database 75 is the same as that of the target database 76, and the table structure is also the same as that of the target database 76. Then, the first electronic device 71 virtualizes the mapping database 75 and the target database 76 to obtain a third virtual database.
[0192] In some embodiments, after performing data mapping and obtaining the mapping database 74, the second electronic device 72 can revoke the first virtual database; after sending the mapping database 74 to the first electronic device 71, it can clear the mapping database 74 from its local cache. Additionally, after performing a version upgrade and obtaining the mapping database 75, the first electronic device 71 can clear the mapping database 74 from its local cache.
[0193] This application provides a database mapping process when the table structures between devices are the same (i.e., the database versions are the same), and a database mapping process when the table structures between devices are different (i.e., the database versions are different). In this way, database mapping can still be achieved even when the table structures between devices are different, thus expanding the application scope.
[0194] The above describes the specific process by which the second electronic device establishes the first mapped data set of the first source data set based on the first event of the first electronic device. The following will describe the process by which the first electronic device establishes the second mapped data set of the second source data set based on the second event of the second electronic device.
[0195] See Figure 8 The illustrated embodiment of this application provides a schematic diagram of a database mapping pattern, which may include the following steps:
[0196] Step S801: The second electronic device sends a second event to the first electronic device.
[0197] Step S802: The first electronic device creates a second empty mapping database of the second source database based on the database version information in the second event.
[0198] The second source database refers to the local database of the first electronic device. The database version information included in the second event describes the version of the local database of the second electronic device. The second hole mapping database refers to an empty database that has not yet been loaded with data.
[0199] Step S803: The first electronic device virtualizes the second source database and the second empty mapping database to obtain the fourth virtual database.
[0200] Step S804: The first electronic device performs data mapping in the fourth virtual database to map the data in the second source database to the second empty mapping database, thereby obtaining the mapped database.
[0201] Step S805: The first electronic device obtains the second mapping database based on the mapped database.
[0202] Step S806: The first electronic device sends the second mapping database to the second electronic device.
[0203] After receiving the second mapping database, the second electronic device can virtualize it based on the second mapping database and the second source database to obtain a third virtual database. Based on the third virtual database, the second electronic device can access the data of the first electronic device across devices.
[0204] It should be noted that the process of the second electronic device establishing the second mapping database is similar to the process of the first electronic device establishing the first mapping database. For the same or similar parts, please refer to [link to relevant documentation]. Figure 4 , Figure 5 , Figure 6 as well as Figure 7 The relevant content will not be repeated here.
[0205] After introducing the database mapping process, the following will combine... Figure 9 The table mapping process will be introduced.
[0206] Table mapping process:
[0207] See Figure 9 The diagram shown is a schematic representation of a table mapping process provided in an embodiment of this application. This table mapping process may include the following steps:
[0208] Step S901: The first electronic device sends a first event to the second electronic device.
[0209] At this point, since the second electronic device can disregard the database version when creating the first mapping table, the first event may not include database version information.
[0210] Step S902: The second electronic device establishes a first mapping table of the first source table based on the first event.
[0211] At this point, the aforementioned first source data set specifically refers to the first source table, and the aforementioned first mapping data set specifically refers to the first mapping table. The first source table refers to a database table within the local database of the second electronic device.
[0212] In practical applications, when the second electronic device maps the data content of the first source table to the first mapping table, it can disregard whether the structures of the first mapping table and the first source table are the same.
[0213] Step S903: The second electronic device sends the first mapping table to the first electronic device.
[0214] Step S904: The second electronic device sends a second event to the first electronic device.
[0215] Similarly, when the first electronic device creates the second mapping table, it does not need to consider the database version. Therefore, the second event may not include database version information.
[0216] Step S905: The first electronic device establishes a second mapping table of the second source table based on the two events.
[0217] At this point, the aforementioned second source data set specifically refers to the second source table, and the aforementioned second mapping data set specifically refers to the second mapping table. The second source table refers to a database table within the local database of the first electronic device. The structure of the second mapping table is consistent with the structure of the second source table.
[0218] Similarly, when the first electronic device maps the data content of the second source table to the second mapping table, it can disregard whether the structures of the second mapping table and the second source table are the same.
[0219] Step S906: The first electronic device sends the second mapping table to the second electronic device.
[0220] After receiving the first mapping table from the second electronic device, the first electronic device can associate the device information of the second electronic device with the first mapping table. Similarly, the second electronic device can associate the device information of the first electronic device with the second mapping table.
[0221] As can be seen, mapping the database table as a whole to the peer device achieves database table-level data synchronization, reduces data synchronization time, and improves data availability speed.
[0222] In some embodiments, in order to achieve cross-device data fusion access, a first electronic device or a second electronic device can create an intermediate result database, load the mapping table of the peer device into the intermediate result database, and load the local mapping table into the intermediate result database. In this way, data from multiple devices can be accessed from the intermediate result database with a single query.
[0223] Specifically, after initializing the local data database, the first electronic device can create a mapping table of the local database tables. The first electronic device sends a first event to the second electronic device to create an intermediate result database; after receiving the first mapping table from the second electronic device, it loads the first mapping table and the mapping table of the local database tables into the created intermediate result database. In this way, the application on the first electronic device can access the data of the first electronic device and the data of the second electronic device from the intermediate result database through a single query request.
[0224] Similarly, after initializing its local database, the second electronic device can create a mapping table of the local database tables, send a second event to the first electronic device, and create an intermediate result database. After receiving the second mapping table from the first electronic device, it loads the second mapping table and the mapping table of the local database tables into the created intermediate result database. The application on the second electronic device can access data from both the first and second electronic devices from the intermediate result database through a single query request.
[0225] It should be noted that the data mapping and synchronization scheme at the database level and database table level provided in this application embodiment can be applied to data fusion access scenarios, as well as other scenarios.
[0226] Data change monitoring process:
[0227] After receiving the mapping data set of the peer device, the first or second electronic device can monitor the data change information of the peer device in real time, and after receiving the data change information of the peer device, load the changed data into the mapping data set of the peer device in the local storage space based on the data change information.
[0228] join Figure 10 The illustration shows a schematic diagram of a data change monitoring process provided in an embodiment of this application. This process may include the following steps:
[0229] Step S1001: The second electronic device monitors whether local data has changed based on data status information.
[0230] The aforementioned data status information is created by the second electronic device during data mapping. For example, such as... Figure 5 , Figure 6 and Figure 7 As shown, when the second electronic device performs data mapping in the first virtual database, it records data status information. This data status information describes the status of the data mapped to the peer device, and it can specifically be a data status tree.
[0231] The second electronic device uses data status information as a basis to compare the current data with the data status recorded in the data status information, and determines whether the current data has changed compared with the data previously mapped to the first electronic device.
[0232] Step S1002: When the monitored data changes, the second electronic device generates data change information.
[0233] If a change is determined to have occurred, the second electronic device generates data change information based on the changed data. This data change information describes the changed data.
[0234] In some embodiments, after generating data change information, the second electronic device can also modify the data status information, that is, update the status record of the changed data in the data status information according to the changed data. The modified data status information can be used as the basis for determining whether the data has changed in the next instance.
[0235] Step S1003: The second electronic device sends data change information to the first electronic device.
[0236] In some embodiments, the second electronic device can monitor and record data changes via a change script, record the data change information in a table within the change script, and then transmit the change script to the first electronic device. This achieves file-level synchronization and improves the data change synchronization speed.
[0237] Of course, in other embodiments, the second electronic device may also synchronize the changed data to the first electronic device one by one.
[0238] Step S1004: The first electronic device loads the changed data into the first mapping data set of the second electronic device according to the data change information.
[0239] In database mapping mode, the database versions of the first electronic device and the second electronic device may be different. In this case, the first electronic device can merge the changed data with the data in the first mapped data set based on the database version. The following section will combine... Figure 11 and Figure 12 The process of monitoring data changes is described.
[0240] See Figure 11 The diagram shown is a data change monitoring process for high-version to low-version synchronization provided in an embodiment of this application. The database version of the first electronic device 111 is lower than the database version of the second electronic device 112. The second electronic device 112 includes a source database 113 and a change script 114. The first electronic device 111 includes a change script 114, a mapping database 115, and a target database 116.
[0241] Among them, the source database 113 is the local database of the second electronic device 112, the mapping database 115 is the mapping database of the source database 113, and the target database 116 is the local database of the first electronic device.
[0242] After the data mapping process, the second electronic device 112 transmits the mapping database of the source database 113 to the first electronic device 111, and the first electronic device 111 virtualizes the mapping database 115 and the target database 116 into a virtual database.
[0243] After data mapping, the second electronic device 112, based on the data state tree created during the data mapping process, monitors data changes in the source database 113 in real time via a change script 114, and records the changed data in the source database 113 in a table within the change script 114. The table structure in the change script 114 is consistent with that of the target database 116. At this point, the aforementioned data change information is specifically represented by the change script 114.
[0244] After determining that the data has changed, the second electronic device 112 records the changed data in the database table in the change script 114, updates the data state tree, and then transmits the change script 114 to the first electronic device 111.
[0245] After receiving the change script 114, the first electronic device 111 loads the changed data into the mapping database 115 in batches using the change script 114. Thus, after data mapping, when the data in the second electronic device changes, the changed data can be synchronized to the first electronic device in real time.
[0246] See Figure 12 The diagram illustrates a data change monitoring process for synchronizing from a lower version to a higher version, provided in an embodiment of this application. The database version of the first electronic device 121 is higher than that of the database version of the second electronic device 122. The second electronic device 122 includes a source database 123 and a change script 124, while the first electronic device 121 includes a change script 124, a change script 125, a mapping database 126, and a target database 127.
[0247] Among them, source database 123 is the local database of the second electronic device 122, mapping database 126 is the mapping database of source database 123, and target database 127 is the local database of the first electronic device 121.
[0248] After the data mapping process, the second electronic device 122 transmits the mapping database of the source database 123 to the first electronic device 121, and the first electronic device 121 virtualizes the mapping database 126 and the target database 127 into a virtual database.
[0249] After data mapping, the second electronic device 122, based on the data state tree created during the data mapping process, monitors data changes in the source database 113 in real time via change script 124, and records the changed data in the source database 123 in a table within change script 124. The table structure in change script 124 is identical to the table structure in the source database 123. At this point, the aforementioned data change information is specifically represented by change script 124.
[0250] After determining that the data has changed, the second electronic device 122 records the changed data in the database table in the change script 124, updates the data state tree, and transmits the change script 124 to the first electronic device 121.
[0251] After receiving the change script 124, the first electronic device 121 first upgrades the change script 124 to obtain the change script 125. The table structure of the change script 125 is consistent with the table structure of the target database 127. Then, the changed data is loaded into the mapping database 126 in batches through the change script 125. In this way, after data mapping, when the data of the second electronic device changes, the changed data can be synchronized to the first electronic device in real time.
[0252] When the database version of the first electronic device is equal to the database version of the second electronic device, the data change monitoring process can be as follows: Figure 11 As shown, the data change monitoring process when the database versions of two devices are the same can be the same as the data change monitoring process when synchronizing from a higher version to a lower version.
[0253] When the data mapping process is a table mapping process, the second electronic device can monitor and record data changes through a change script, and record the changed data in the table within the change script. When the first electronic device receives a change script, it can use the change script to batch load the changed data into the corresponding mapping table in the intermediate result database. This corresponding mapping table refers to the mapping table of the local database table of the second electronic device.
[0254] The above illustrates the flow of events on the first and second electronic devices when the data on the second electronic device side changes. When the data on the first electronic device side changes, the flow on the first electronic device side is similar to that on the second electronic device side, and vice versa; therefore, it will not be repeated here.
[0255] In this embodiment, data status information is recorded during data mapping, and data status information is used to monitor whether changes are detected in the data in real time. When changes are detected, the changed data is synchronized to the peer device based on the data status information, which can realize cross-device data status management and cross-device real-time data query.
[0256] Data fusion access process:
[0257] Electronic devices can achieve cross-device data fusion access through database links (DBlink).
[0258] Specifically, the electronic device pre-configures a DBlink for the peer device within its local database. Upon receiving an access request, it first connects to the peer device's database based on the peer device's DBlink, then scans the peer device's database and transmits all data from the peer device's database back to its local database. Finally, it disconnects from the peer device's database and returns the access result corresponding to the access request. In this way, the electronic device can retrieve the peer device's data from its local database with a single query, achieving cross-device data access.
[0259] As can be seen from the above, from initiating an access to obtaining the access result, the process involves connecting to the peer device's database, scanning the peer device's database, and data backhauling, which takes a long time and results in poor cross-device data access performance. Furthermore, backhauling data from the peer device to the local device involves a large data transfer volume, consuming significant bandwidth. The transmission time depends on network quality; in other words, network transmission quality directly impacts the performance of cross-device data access.
[0260] The data fusion access process will be described below using the first electronic device as an example. The data fusion access process on the second electronic device side can be referred to the process on the first electronic device side, and will not be repeated here.
[0261] See Figure 13 The illustrated flowchart represents a data fusion access process provided in an embodiment of this application. This process may include the following steps:
[0262] Step S1301: The first electronic device obtains a data access request from the application. The first electronic device includes the application.
[0263] Applications on the first electronic device can be, for example, a gallery or a third-party application; no specific application is limited here.
[0264] Step S1302: If the first electronic device determines that the data access request includes the device identifier of the second electronic device, it queries the first data set in the target database to obtain the first query result. The first data set is a mapping data set of the local data set of the second electronic device. The target database includes the first data set and the second data set. The second data set is the local data set of the first electronic device or a mapping data set of the local data set. The first electronic device includes the target database.
[0265] The data access request initiated by the application carries a device identifier, which is used to uniquely identify the device. For example, the device identifier can be a specific device ID. When the data access request carries a device identifier, the data of the corresponding device is accessed according to the pre-established association between the device identifier and the data set; when the data access request does not carry a device identifier, the data of all devices is accessed.
[0266] The device identifier of the second electronic device may be pre-stored locally on the first electronic device. For example, during the data mapping process, the first electronic device receives a second event from the second electronic device and stores the device identifier of the second electronic device carried in the second event locally.
[0267] The target database mentioned above can be a virtual database or an intermediate result database. When the target database is a virtual database, the first data set is specifically a mapping database of the local database of the second electronic device. When the target database is an intermediate result database, the first data set is specifically a mapping table of the local database tables of the second electronic device.
[0268] When the data access request includes the device identifier of the second electronic device, the first electronic device queries the mapping database of the second electronic device in the target database to obtain the first query result.
[0269] Step S1303: The first electronic device returns the first query result to the application.
[0270] Optionally, in step S1304, if the first electronic device determines that the data access request does not include the device identifier, it queries the first data set and the second data set in the target database to obtain the second query result and returns the second query result to the application.
[0271] Step S1305: If the first electronic device determines that the data access request includes the device identifier of the first electronic device, it queries the second data set in the target database to obtain the third query result and returns the third query result to the application.
[0272] For example, see cross-device media data fusion access. Figure 14 The illustrated diagram of cross-device media data fusion access provided in this application embodiment shows that the first electronic device 141 maps data from the second electronic device 142 and data from the cloud 143 to a local media library database. Thus, when the application of the first electronic device 141 needs to access data from the second electronic device 142 or the cloud 143, it can achieve cross-device data fusion access by accessing the corresponding data in the local media library database. In this case, the cloud 143 can be considered as a single device.
[0273] The first electronic device 141 includes a media library, which is a media data management framework developed by Huawei that supports applications to access distributed media data.
[0274] The first electronic device 141 includes, for example, application 1, application 2, application 3 and application 4, each of which can access media data fusion across devices by calling the unified interface of the media library.
[0275] For example, application 1 can initiate a data access request by calling the unified interface of the media library, and specify the device identifier of the second electronic device 142 in the data access request, that is, application 1 needs to access the media data of the second electronic device 142; the media library service framework passes the data access request to the media data fusion access module, the media data fusion access module queries the data of the second electronic device in the fused data based on the device identifier carried in the data access request, and obtains the query result; finally, the media library database returns the query result to application 1.
[0276] For example, see Figure 15 The diagram shown is a schematic diagram of cross-device access to image data provided in an embodiment of this application. In this case, the first electronic device is a mobile phone 151, and the second electronic device includes a tablet and a mobile phone 2.
[0277] like Figure 15 As shown, the main interface of phone 151 includes multiple applications such as Settings, Calendar, Clock, App Store, and Gallery 152. When phone 151 receives a click on Gallery 152, it responds by displaying the photo album interface 153. The photo album interface 153 displays photos, videos, and camera images stored on the device. If the user needs to access image data from other devices, they can click on "Other Devices" on the camera interface 153. When phone 151 receives a click on "Other Devices," it responds by displaying interface 154. Interface 154 includes folders 155 for the tablet and 156 for phone 2.
[0278] If a user wants to access data on the tablet across devices, they can click on folder 155; if they want to access data on phone 2 across devices, they can click on folder 156.
[0279] When mobile phone 151 receives a click operation on folder 155, it responds to the click operation by displaying interface 157. Interface 157 includes camera folder 158, picture folder 159, Huawei share folder 1510, and screenshot / screen recording folder 1511.
[0280] In response to a click on folder 155, mobile phone 151 invokes the unified interface of the media library to initiate a data access request, specifying the tablet's device identifier in the request. Based on the data access request, the media data fusion access module in mobile phone 151 queries the tablet's data in the media library database and returns the query results to the image library. Upon receiving the query results, the image library displays interface 157 based on those results.
[0281] When mobile phone 151 receives a click operation on camera folder 158, it responds by displaying interface 1512, which includes all the photos taken by the tablet camera. This allows the user to access image data on the tablet from mobile phone 151.
[0282] See Figure 16 The illustrated diagram shows a cross-device image search provided in an embodiment of this application, based on... Figure 15 The phone's camera interface includes a search box 161, where users can enter relevant information to search for photos taken on the phone or other devices. For example, a user enters "8.7" in search box 161, meaning they are searching for photos taken on August 7th. After the user completes the input, the phone displays interface 162 based on the search results. At this point, the phone finds one photo matching the search criteria on its own device and two photos matching the search criteria on the tablet.
[0283] When a user enters search criteria in search box 161, the image library initiates a data access request by calling the unified interface of the media library. At this time, the data access request does not include device identifiers, meaning it needs to query data from all devices. Based on the data access request initiated by the image library, the data fusion access module on the mobile phone queries the media library database for data from the local device, the tablet, and mobile phone 2, obtains the query results, and returns the results to the image library. After receiving the query results, the image library displays them on interface 162.
[0284] The cross-device data fusion access scheme provided in this application embodiment pre-maps the data of the second electronic device (i.e., the peer device) to its local storage space, so that accessing the data of the second electronic device can be like accessing a local database, thus providing cross-device data access similar to local database access. Furthermore, when accessing the data of the second electronic device, the process from initiating the access request to obtaining the query result does not involve linking to a remote database or data backhaul from the remote database. The query speed is not affected by network transmission quality, resulting in shorter processing time and thus higher cross-device data access performance. In addition, the first electronic device integrates its local data set and the mapped data set of the peer device into a single target database, allowing for querying and filtering of data from multiple devices with a single query request, achieving cross-device data fusion access.
[0285] Before data fusion access, the data of the second electronic device needs to be synchronized to the local storage of the first electronic device. In some embodiments, the data of the second electronic device can be synchronized to the local storage space of the first electronic device one item at a time. Alternatively, the database or database table of the second electronic device can be mapped to the first electronic device as a whole through the data mapping process mentioned above. Of course, other methods can also be used to synchronize the data of the second electronic device to the local storage space of the first electronic device. In comparison, mapping the database or database table as a whole to the peer device reduces data synchronization time and improves data availability speed.
[0286] When the target database is a virtual database, a database mapping method is used to map the data from the second electronic device to the local data on the first electronic device. When the target database is an intermediate result database, a table mapping method is used to map the data from the second electronic device to the local data on the first electronic device. The different data mapping processes may lead to different cross-device data fusion access procedures. The following section will discuss these differences in conjunction with... Figure 17 and Figure 18 The access process under both modes is described exemplarily.
[0287] See Figure 17 The diagram shown illustrates data fusion access under the database mapping mode provided in the embodiments of this application, as follows: Figure 17 As shown, the first electronic device 171 includes a media library, a media data fusion access module 174, and a fusion data management module 175.
[0288] The media data fusion access module 174 is used to obtain data access requests from applications and, in response to these requests, to query the corresponding media data through the fusion data management module 175 and return the query results to the application. The media data fusion access module 174 can provide cross-device media data fusion access capabilities.
[0289] The converged data management module 175 is used to manage local data and cross-device data.
[0290] The distributed data mapping module 176 is used to implement the mapping and modification of media data across devices. This distributed database mapping module 176 can be a module within a distributed data middleware system that spans multiple devices.
[0291] Through the distributed data mapping module 176, the cloud 172 and the second electronic device 173 can map the local media database to the first electronic device 171. At this time, the cloud 172 can be regarded as a special second electronic device.
[0292] The application of the first electronic device 171 can initiate a data access request by calling the media library interface to access media data in the cloud 172 and the second electronic device 173.
[0293] See Figure 18 The diagram shown illustrates data fusion access under the table mapping mode provided in the embodiments of this application, such as... Figure 18 As shown, the first electronic device 181 can access data in the cloud 182 and data in the second electronic device 183 across devices.
[0294] The media data fusion access module 184 in the first electronic device 181 can be found in [reference needed]. Figure 17 The relevant content will not be repeated here.
[0295] The distributed data mapping module 186 is used to implement the mapping and modification of media data across devices. At this time, the first electronic device 181 uses the distributed data mapping module 186 to create a mapping table for its local database table and loads this mapping table into the intermediate process data 185. Meanwhile, the cloud device 182 and the second electronic device 183 can use the distributed data mapping module 186 to map the entire local database table to the intermediate process data 185 of the first electronic device 181.
[0296] The intermediate process data 185 can be specifically represented as an intermediate result database, which may include a mapping table of the local database table of the first electronic device 181, a mapping table of the local database table of the cloud 182, and a mapping table of the local database table of the second electronic device 183.
[0297] The application on the first electronic device 181 can initiate a data access request by calling the media library interface. In response to the data access request, the media data fusion access module 184 queries the intermediate process data 185 to obtain the query results. Specifically, if the data access request includes the device identifier of the first electronic device 181, the mapping table of the first electronic device 181 in the intermediate process data 185 is queried. If the data access request includes the device identifier of the cloud device 182 or the second electronic device 183, the mapping table of the cloud device 182 or the second electronic device 183 in the intermediate process data 185 is queried. If the data access request does not include a device identifier, the mapping table of all devices in the intermediate process data 185 is queried.
[0298] In practical applications, the distributed data mapping module can be used to implement cross-device data mapping and changes. The distributed data mapping module is a module in the distributed data middleware. The following will exemplarily introduce the data mapping process based on the distributed data middleware.
[0299] See Figure 19 The diagram shown illustrates a database mapping model based on distributed data middleware provided in this application embodiment. The distributed data middleware includes the following components: Driver 191, MetadataStore 192, Execution Engine 193, Batch Operator 194, and Real-time Operator 195. The media library includes the following components: Media Library Interface 196, Data Fusion Access Module 197, Virtual Mapping Database 198, and Local Database 199.
[0300] The database mapping process based on distributed data middleware may include the following steps:
[0301] First, after receiving the device online event, the media library calls the distributed data middleware interface through the media library interface 196 to create a virtual mapping database 198.
[0302] like Figure 19 As shown, the distributed data middleware first defines a mapping database, such as defining the tables and database file names contained in the mapping database; then, based on the definition of the mapping database, it creates the mapping database. At this point, the mapping database has not yet been loaded with data; then, it executes database mapping to perform stateful data loading, that is, it first creates a data state tree, and then starts data loading based on the data state, loading the data in the source database into the pre-created mapping database in batches, resulting in a mapping database with completed data loading, and thus a virtual mapping database 198.
[0303] For example, see Figure 5 After the media library of the second electronic device 52 receives the device online event from the first electronic device 51, the distributed database middleware of the second electronic device 52 defines a mapping database based on the database version information of the device online event of the first electronic device 51, and then creates the mapping database according to the definition. Next, a data state tree is created, and data mapping is performed within the first virtual database to obtain the mapped database 54. The mapped database 54 is then transmitted across devices to the first electronic device 51. At this point, the mapped database 54 on the first electronic device 51 is the aforementioned virtual mapped database.
[0304] After completing cross-device database mapping, the distributed data middleware can also monitor database changes in real time and, based on the monitoring results, load the changed data from the remote database into the virtual mapped database 198 in real time. For example... Figure 19 As shown, after real-time monitoring of data changes, the real-time operation processor 195 in the distributed data middleware loads the data changes from the remote device into the virtual mapping database 198 in a stateful manner.
[0305] like Figure 19 As shown, the application can call the media library interface 196 to initiate a data fusion access request to the data fusion access module 197. In response to the data fusion access request, the data fusion access module 197 queries the local database 199 and / or the virtual mapping database 198, obtains the query results, and then returns the query results to the application through the media library interface 196.
[0306] It should be noted that distributed data middleware is cross-device, therefore Figure 19 The distributed middleware illustrated in the example involves processes from two devices. For instance, Figure 19 The process of the distributed data middleware shown includes: Figure 5 The process of the first electronic device 51 and the second electronic device 52.
[0307] See Figure 20 The diagram shown is a schematic of the table mapping pattern based on distributed data middleware provided in the embodiments of this application, and... Figure 19 Similarly, the distributed data middleware includes the following components: Driver 201, Metadata Store 202, Execution Engine 203, Batch Operator 204, and Real-time Operator 205. The media library includes the following components: Media Library Interface 206, Data Fusion Access Module 207, and Intermediate Results Database 208.
[0308] The distributed data middleware first creates local and remote mapping tables. For example, the distributed data middleware of the first electronic device creates a mapping table for its local database table, and the distributed database middleware of the second electronic device creates a mapping table for its local database table (i.e., the aforementioned remote mapping table). Then, the distributed data middleware creates an intermediate process database, then a data state tree, and loads data statefully based on the data state tree, that is, batch-loading the local and remote mapping tables into the intermediate process database to obtain the intermediate result database 208. The remote mapping table needs to be transferred to the local device; for example, the second electronic device transfers the created mapping table to the first electronic device.
[0309] Distributed data middleware can also monitor data changes in real time, including local data and cross-device data. When a data change is detected, the changed data is loaded into the intermediate result database.
[0310] like Figure 20 As shown, the application can call the media library interface 206 to initiate a data fusion access request to the data fusion access module 207. In response to the data fusion access request, the data fusion access module 207 queries the intermediate result database 208 to obtain the query results, and then returns the query results to the application through the media library interface 206.
[0311] It should be noted that distributed data middleware is cross-device, therefore Figure 19 The distributed middleware shown in the example includes processes involving two devices.
[0312] It should be noted that the process of implementing cross-device data mapping and data modification based on distributed data middleware shown above is merely an example and does not limit the specific implementation methods of cross-device data mapping and data modification. For details on data mapping and data modification, please refer to the data mapping process and data modification monitoring process described above, which will not be repeated here.
[0313] As can be seen from the above, the data mapping process provided in this application's embodiments maps the entire database or database table to the peer device, achieving data synchronization at the database level or data table level. Compared to the data synchronization process of synchronizing each record individually, this application's embodiments reduce the time consumed in cross-device data synchronization and improve data availability speed. This enables plug-and-play functionality, meaning that as soon as a device goes online, its data can be quickly synchronized to the peer device, making the device's data available much faster.
[0314] In some embodiments, after the peer device goes offline, the first electronic device can clear the data set of the offline device from its local cache. For example, the first electronic device is a mobile phone, and the second electronic device is a tablet. After the mobile phone and tablet establish a Wi-Fi peer-to-peer connection, the mobile phone receives the mapping database sent by the tablet and stores the tablet's mapping database locally. After the Wi-Fi peer-to-peer connection between the mobile phone and the tablet is broken, that is, after the tablet goes offline, the mobile phone clears the tablet's mapping database from its local cache.
[0315] Furthermore, in order to solve the problem of data mapping failure caused by different table structures between different devices during database mapping, this application embodiment also provides a heterogeneous table structure mapping scheme, so that database mapping can still be achieved even when the table structures between devices are different, and the application scope is wider.
[0316] This application embodiment also creates and records data status information during data mapping, listens for changes in data based on the data status information, and synchronizes the changed data to the peer device when the data changes, so as to realize cross-device data change monitoring and provide cross-device real-time data query capability.
[0317] The data fusion access process provided in this application pre-maps the database of the peer device to the local storage space, improves cross-device data fusion access for quasi-local database access, avoids the impact of network transmission quality on query performance, and achieves high-performance cross-device data fusion access.
[0318] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0319] Corresponding to the data transmission method described in the above embodiments, the data transmission device provided in the embodiments of this application will be described below. For ease of explanation, only the parts related to the embodiments of this application are shown.
[0320] The data transmission device includes:
[0321] The first receiving module is configured to receive a first event from the first electronic device. The first event includes first database version information, which describes the database version of the second source database, which is the local database of the first electronic device.
[0322] The first creation module is used to create the first empty mapping database of the first source database based on the first database version information. The first source database is the local database of the second electronic device.
[0323] The first virtualization module is used to virtualize the first source database and the first empty mapping database to obtain the first virtual database;
[0324] The first mapping module is used to perform data mapping in the first virtual database to map the data in the first source database to the first empty mapping database, so as to obtain the first database with completed data mapping.
[0325] The first acquisition module is used to obtain the first mapping database based on the first database;
[0326] The first sending module is used to send the first mapping database to the first electronic device.
[0327] In some possible implementations, the first obtaining module is specifically used to: compare the database versions of the first source database and the second source database based on the first database version information and the second database version information, wherein the second database version information is used to describe the database version of the first source database; if the version of the first source database is higher than the version of the second source database, downgrade the first database to obtain the first mapping database, wherein the version of the first mapping database is consistent with the version of the second source database; if the version of the first source database is lower than or equal to the version of the second source database, use the first database as the first mapping database, wherein the version of the first mapping database is consistent with the version of the first source database.
[0328] In some possible implementations, when the version of the first source database is higher than the version of the second source database, the version of the first empty mapping database is the same as the version of the first source database, and the table structure of the first empty mapping database is the same as the table structure of the second source database; when the version of the first source database is lower than the version of the second source database, the version of the first empty mapping database is the same as the version of the first source database, and the table structure of the first empty mapping database is the same as the table structure of the first source database.
[0329] In some possible implementations, the device also includes:
[0330] The second sending module is used to send a second event to the first electronic device, the second event including second database version information;
[0331] The second receiving module is used to receive a second mapping database from the first electronic device. The second mapping database is a mapping database of the second source database established by the first electronic device according to the second database version information.
[0332] In some possible implementations, the device further includes a second virtualization module, configured to: if the version of the first source database is lower than the version of the second source database, virtualize the second mapping database and the first source database to obtain a second virtual database; if the version of the first source database is higher than the version of the second source database, upgrade the second mapping database to obtain an upgraded second mapping database, wherein the version of the upgraded second mapping database is consistent with the version of the first source database; and virtualize the upgraded second mapping database and the first source database to obtain a second virtual database.
[0333] In some possible implementations, the device further includes a first fusion access module, configured to: obtain a first data access request from a first application, wherein the second electronic device includes the first application; if the first data access request includes a device identifier of the first electronic device, query a second mapping database in a second virtual database to obtain a first query result, and return the first query result to the first application; if the first data access request does not include a device identifier, query the second mapping database and the first source database in the second virtual database to obtain a second query result, and return the second query result to the first application; if the first data access request includes a device identifier of the second electronic device, query the first source database in the second virtual database to obtain a third query result, and return the third query result to the first application.
[0334] In some possible implementations, the device also includes:
[0335] The first change script receiving module is used to receive a first change script from a first electronic device. The first change script includes a table for recording change data of a second source database.
[0336] The first batch update module is used to upgrade the first change script if the version of the first source database is higher than the version of the second source database, resulting in an upgraded first change script. The table structure of the upgraded first change script is consistent with the table structure of the first source database. By executing the upgraded first change script, the changed data of the second source database is loaded into the second mapping database. If the version of the first source database is lower than the version of the second source database, the changed data of the second source database is loaded into the second mapping database by executing the first change script.
[0337] In some possible implementations, the device further includes a first update module, configured to: determine, based on a first data state tree, whether data in a first source database has changed, the first data state tree describing the state of data in the first source database mapped to a first empty mapping database; if data in the first source database has changed, record the changed data in the first source database in a second change script, the second change script including a table for recording the changed data; and send the second change script to a first electronic device.
[0338] Where the version of the first source database is higher than the version of the second source database, the table structure of the second change script is consistent with the table structure of the second source database.
[0339] When the version of the first source database is lower than the version of the second source database, the table structure of the second change script is consistent with the table structure of the first source database.
[0340] In some possible implementations, the first update module described above is also used to: update the first data state tree.
[0341] It should be noted that the information interaction and execution process between the above-mentioned devices and modules are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0342] Corresponding to the data transmission method described in the above embodiments, the data transmission device provided in the embodiments of this application will be described below. For ease of explanation, only the parts related to the embodiments of this application are shown.
[0343] The data transmission device includes:
[0344] The third sending module is used to send a first event to the second electronic device. The first event includes first database version information, which describes the database version of the second source database. The second source database is the local database of the first electronic device.
[0345] The third receiving module is used to receive a first mapping database from the second electronic device. The first mapping database is a mapping database of the first source database established by the second electronic device according to the first database version information. The first source database is the local database of the second electronic device.
[0346] In some possible implementations, the device further includes a third virtualization module, configured to: if the version of the first source database is higher than the version of the second source database, virtualize the first mapping database and the second source database to obtain a third virtualized database; if the version of the first source database is lower than the version of the second source database, upgrade the first mapping database to obtain an upgraded first mapping database, wherein the version of the upgraded first mapping database is consistent with the version of the second source database; and virtualize the upgraded first mapping database and the second source database to obtain a third virtual database.
[0347] In some possible implementations, the device further includes a second fusion access module, configured to: obtain a second data access request from a second application, wherein the first electronic device includes the second application; if the second data access request includes a device identifier of the first electronic device, query the second source database in the third virtual database to obtain a fourth query result, and return the fourth query result to the second application; if the second data access request does not include a device identifier, query the first mapping database and the second source database in the third virtual database to obtain a fifth query result, and return the fifth query result to the second application; if the second data access request includes a device identifier of the second electronic device, query the first mapping database in the third virtual database to obtain a sixth query result, and return the sixth query result to the second application.
[0348] In some possible implementations, the device also includes:
[0349] The second change script receiving module is used to receive a second change script from a second electronic device. The second change script includes a table for recording change data from the first source database.
[0350] The second batch update module is used to upgrade the second change script if the version of the first source database is lower than the version of the second source database, resulting in an upgraded second change script. The table structure of the upgraded second change script is consistent with the table structure of the second source database. By executing the upgraded second change script, the changed data of the first source database is loaded into the first mapping database. If the version of the first source database is higher than the version of the second source database, the changed data of the first source database is loaded into the first mapping database by executing the second change script.
[0351] In some possible implementations, the device also includes:
[0352] The fourth receiving module is used to receive a second event from the second electronic device. The second event includes second database version information, which describes the database version of the first source database.
[0353] The second creation module is used to create a second empty mapping database of the second source database based on the second database version information;
[0354] The fourth virtualization module is used to virtualize the second source database and the second empty mapping database to obtain the fourth virtual database;
[0355] The second mapping module is used to perform data mapping in the fourth virtual database to map the data in the second source database to the second empty mapping database, so as to obtain the second database with completed data mapping.
[0356] The second acquisition module is used to obtain the second mapping database based on the second database;
[0357] The fourth sending module is used to send the second mapping database to the second electronic device.
[0358] In some possible implementations, the second obtaining module is specifically used to: compare the version of the first source database and the second source database based on the version information of the first database and the version information of the second database; if the version of the first source database is lower than or equal to the version of the second source database, downgrade the version of the second database to obtain a second mapping database, the version of the second mapping database being consistent with the version of the first source database; if the version of the first source database is higher than the version of the second source database, use the second database as the first mapping database, the version of the second mapping database being consistent with the version of the second source database.
[0359] In some possible implementations, when the version of the first source database is lower than the version of the second source database, the version of the second empty mapping database is the same as the version of the second source database, and the table structure of the second empty mapping database is the same as the table structure of the first source database; when the version of the first source database is higher than the version of the second source database, the version of the second empty mapping database is the same as the version of the second source database, and the table structure of the second empty mapping database is the same as the table structure of the second source database.
[0360] In some possible implementations, the device further includes a second update module, configured to: determine, based on a second data state tree, whether data in the second source database has changed, the second data state tree describing the state of data in the second source database mapped to the second empty mapping database; if data in the second source database has changed, record the changed data in the second source database in a first change script, the first change script including a table for recording the changed data; update the second data state tree; and send the first change script to the second electronic device.
[0361] Where the version of the first source database is lower than the version of the second source database, the table structure of the first change script is consistent with the table structure of the first source database.
[0362] When the version of the first source database is higher than the version of the second source database, the table structure of the first change script is consistent with the table structure of the second source database.
[0363] It should be noted that the information interaction and execution process between the above-mentioned devices and modules are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0364] Figure 21 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 21 As shown, the electronic device 21 of this embodiment includes: at least one processor 210 ( Figure 21 (Only one is shown) a processor, a memory 211, and a computer program 212 stored in the memory 211 and executable on the at least one processor 210, wherein the processor 210 executes the computer program 212 to implement the steps in any of the above-described data transmission method embodiments.
[0365] The electronic device 21 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. This electronic device may include, but is not limited to, a processor 210 and a memory 211. Those skilled in the art will understand that... Figure 21 This is merely an example of electronic device 21 and does not constitute a limitation on electronic device 21. It may include more or fewer components than shown, or combine certain components, or different components, such as input / output devices, network access devices, etc.
[0366] The processor 210 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0367] In some embodiments, the memory 211 may be an internal storage unit of the electronic device 21, such as a hard disk or memory of the electronic device 21. In other embodiments, the memory 211 may be an external storage device of the electronic device 21, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device 21. Furthermore, the memory 211 may include both internal and external storage units of the electronic device 21. The memory 211 is used to store the operating system, applications, bootloader, data, and other programs, such as the program code of the computer program. The memory 211 can also be used to temporarily store data that has been output or will be output.
[0368] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps described in the various method embodiments above.
[0369] This application provides a computer program product that, when run on an electronic device, enables the electronic device to perform the steps described in the various method embodiments above.
[0370] This application also provides a chip system, which includes a processor coupled to a memory. The processor executes a computer program stored in the memory to implement the methods described in the above embodiments. The chip system may be a single chip or a chip module composed of multiple chips.
[0371] In the above embodiments, the descriptions of each embodiment have their own emphasis. Parts not detailed or described in a particular embodiment can be referred to in the relevant descriptions of other embodiments. It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. Furthermore, in the description of this application specification and the appended claims, the terms "first," "second," "third," etc., are only used to distinguish descriptions and should not be construed as indicating or implying relative importance. References to "one embodiment" or "some embodiments" in this application specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in yet other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized.
[0372] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data transmission method, characterized in that, The method, which employs a second electronic device, includes: Receive a first event from a first electronic device, the first event including first database version information, the first database version information being used to describe the database version of a second source database, the second source database being a local database of the first electronic device; Based on the first database version information, create a first empty mapping database for the first source database, wherein the first source database is the local database of the second electronic device; The first source database and the first empty mapping database are virtualized to obtain the first virtual database; Data mapping is performed in the first virtual database to map the data in the first source database to the first empty mapping database, thus obtaining the first database with completed data mapping. Based on the first database, a first mapping database is obtained; Send the first mapping database to the first electronic device; Specifically, based on the first database version information, creating the first empty mapping database of the first source database includes: Based on the first database version information, and considering the difference in database versions between the first source database and the second source database, a first empty mapping database is created. When the version of the first source database is higher than the version of the second source database, the version of the first empty mapping database is the same as the version of the first source database, and the table structure of the first empty mapping database is the same as the table structure of the second source database. When the version of the first source database is lower than the version of the second source database, the version of the first empty mapping database is the same as the version of the first source database, and the table structure of the first empty mapping database is the same as the table structure of the first source database. The process of obtaining the first mapping database based on the first database includes: Based on the first database version information and the second database version information, the database versions of the first source database and the second source database are compared. The second database version information is used to describe the database version of the first source database. If the version of the first source database is higher than the version of the second source database, the first database is downgraded to obtain the first mapping database, and the version of the first mapping database is the same as the version of the second source database. If the version of the first source database is lower than or equal to the version of the second source database, the first database is used as the first mapping database, and the version of the first mapping database is consistent with the version of the first source database.
2. The method according to claim 1, characterized in that, The method further includes: Send a second event to the first electronic device, the second event including second database version information; The system receives a second mapping database from the first electronic device, wherein the second mapping database is a mapping database of the second source database established by the first electronic device based on the second database version information.
3. The method according to claim 2, characterized in that, After receiving the second mapping database from the first electronic device, the method further includes: If the version of the first source database is lower than the version of the second source database, the second mapping database and the first source database are virtualized to obtain a second virtual database; If the version of the first source database is higher than the version of the second source database, the second mapping database is upgraded to obtain an upgraded second mapping database, wherein the version of the upgraded second mapping database is the same as the version of the first source database. The upgraded second mapping database and the first source database are virtualized to obtain a second virtual database.
4. The method according to claim 3, characterized in that, After virtualizing the second mapping database and the first source database to obtain the second virtual database, the method further includes: Obtain a first data access request from a first application, wherein the second electronic device includes the first application; If the first data access request includes the device identifier of the first electronic device, query the second mapping database in the second virtual database to obtain the first query result, and return the first query result to the first application; If the first data access request does not include a device identifier, query the second mapping database and the first source database in the second virtual database to obtain a second query result, and return the second query result to the first application; If the first data access request includes the device identifier of the second electronic device, the first source database in the second virtual database is queried to obtain a third query result, and the third query result is returned to the first application.
5. The method according to claim 2, characterized in that, After the second electronic device receives the second mapping database from the first electronic device, the process further includes: Receive a first change script from the first electronic device, the first change script including a table for recording change data of the second source database; If the version of the first source database is higher than the version of the second source database, the first change script is upgraded to obtain an upgraded first change script. The table structure of the upgraded first change script is consistent with the table structure of the first source database. By executing the upgraded first change script, the changed data of the second source database is loaded into the second mapping database; If the version of the first source database is lower than the version of the second source database, the changed data of the second source database is loaded into the second mapping database by executing the first change script.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Based on the first data state tree, it is determined whether the data in the first source database has changed. The first data state tree is used to describe the state of the data in the first source database mapped to the first empty mapping database. If the data in the first source database changes, the changed data in the first source database is recorded in the second change script. The second change script includes a table for recording the changed data. Send the second change script to the first electronic device; Wherein, when the version of the first source database is higher than the version of the second source database, the table structure of the second change script is consistent with the table structure of the second source database; When the version of the first source database is lower than the version of the second source database, the table structure of the second change script is consistent with the table structure of the first source database.
7. The method according to claim 6, characterized in that, After determining that the data in the first source database has changed, the process also includes: Update the first data state tree.
8. A data transmission method, characterized in that, Applied to a first electronic device, the method includes: Send a first event to a second electronic device, the first event including first database version information, the first database version information being used to describe the database version of the second source database, the second source database being the local database of the first electronic device; Receive a first mapping database from the second electronic device, the first mapping database being a database established by the second electronic device according to the method of claim 1.
9. The method according to claim 8, characterized in that, After receiving the first mapping database from the second electronic device, the process also includes: If the version of the first source database is higher than the version of the second source database, the first mapping database and the second source database are virtualized to obtain a third virtualized database; If the version of the first source database is lower than the version of the second source database, the first mapping database is upgraded to obtain an upgraded first mapping database, wherein the version of the upgraded first mapping database is the same as the version of the second source database. The upgraded first mapping database and the second source database are virtualized to obtain a third virtual database.
10. The method according to claim 9, characterized in that, After obtaining the third virtual database, the method further includes: Obtain a second data access request from a second application, wherein the first electronic device includes the second application; If the second data access request includes the device identifier of the first electronic device, query the second source database in the third virtual database to obtain a fourth query result, and return the fourth query result to the second application; If the second data access request does not include a device identifier, query the first mapping database and the second source database in the third virtual database to obtain a fifth query result, and return the fifth query result to the second application; If the second data access request includes the device identifier of the second electronic device, the first mapping database in the third virtual database is queried to obtain the sixth query result, and the sixth query result is returned to the second application.
11. The method according to claim 8, characterized in that, After receiving the first mapping database from the second electronic device, the method further includes: Receive a second change script from the second electronic device, the second change script including a table for recording change data of the first source database; If the version of the first source database is lower than the version of the second source database, the second change script is upgraded to obtain an upgraded second change script. The table structure of the upgraded second change script is consistent with the table structure of the second source database. By executing the upgraded second change script, the changed data of the first source database is loaded into the first mapping database; If the version of the first source database is higher than the version of the second source database, the modified data of the first source database is loaded into the first mapped database by executing the second change script.
12. The method according to any one of claims 8 to 11, characterized in that, The method further includes: Receive a second event from the second electronic device, the second event including second database version information, the second database version information being used to describe the database version of the first source database; Based on the second database version information, create a second empty mapping database for the second source database; The second source database and the second empty mapping database are virtualized to obtain a fourth virtual database; Data mapping is performed in the fourth virtual database to map the data in the second source database to the second empty mapping database, resulting in a second database with completed data mapping. Based on the second database, a second mapping database is obtained; The second mapping database is sent to the second electronic device.
13. The method according to claim 12, characterized in that, The process of obtaining the second mapping database based on the second database includes: Based on the first database version information and the second database version information, compare the database versions of the first source database and the second source database. If the version of the first source database is lower than or equal to the version of the second source database, the version of the second database is downgraded to obtain the second mapping database, and the version of the second mapping database is consistent with the version of the first source database. If the version of the first source database is higher than the version of the second source database, the second database is used as the first mapping database, and the version of the second mapping database is the same as the version of the second source database.
14. The method according to claim 12, characterized in that, When the version of the first source database is lower than the version of the second source database, the version of the second empty mapping database is the same as the version of the second source database, and the table structure of the second empty mapping database is the same as the table structure of the first source database. When the version of the first source database is higher than the version of the second source database, the version of the second empty mapping database is the same as the version of the second source database, and the table structure of the second empty mapping database is the same as the table structure of the second source database.
15. The method according to claim 12, characterized in that, After sending the first mapping database to the first electronic device, the method further includes: Based on the second data state tree, it is determined whether the data in the second source database has changed. The second data state tree is used to describe the state of the data in the second source database mapped to the second empty mapping database. If the data in the second source database changes, the changed data in the second source database will be recorded in the first change script. The first change script includes a table for recording the changed data. Update the second data state tree; Send the first change script to the second electronic device; Wherein, when the version of the first source database is lower than the version of the second source database, the table structure of the first change script is consistent with the table structure of the first source database; When the version of the first source database is higher than the version of the second source database, the table structure of the first change script is consistent with the table structure of the second source database.
16. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 7 or 8 to 15.
17. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 7 or 8 to 15.