DISTRIBUTED FILE ACCESS METHOD AND RELATED DEVICE

A distributed file access method and a related device, applied to a first electronic device, where the first electronic device is in communication connection to a second electronic device, the first electronic device stores metadata of a first file on the second electronic device, and the metadata includes a file modification type and a file modification tag. The method includes: receiving a read instruction for the first file; reading the file modification type and the file modification tag of the first file; and reading the first file according to the file modification type and the file modification tag of the first file. The method can improve performance of file access between electronic devices.

TECHNICAL FIELD

This application relates to the field of terminal technologies, and in particular, to a distributed file access method and a related device.

BACKGROUND

With continuous development of network technologies and information technologies, intelligent terminals such as mobile phones, tablets, computers, and vehicle-mounted devices are increasingly widely applied. In addition to providing convenient data storage and access services for users, intelligent terminals also generate a requirement for data access between different terminals. Existing distributed file access methods (such as remote file read/write in an SMB (Server Message Block, server message block) protocol, and file read/write based on a file proxy mode in an NFS (network file system) protocol) are mainly applied to a large-scale clusters, centralized and ideal network environment, and provides devices with high-throughput data access. In this distributed file access method, file access between devices is implemented by using a server, which is highly dependent on network stability. When the network is unstable, file access takes a long time. The intelligent terminals are generally in a complex and unstable network environment, and the terminals are not in communication connection through a server. It is clear that, an existing distributed file access method is not suitable for a scenario of file access between the terminals.

SUMMARY

Embodiments of this application disclose a distributed file access method and a related device, to improve performance of file access between electronic devices.

A first aspect of this application discloses a distributed file access method, applied to a first electronic device, where the first electronic device is in communication connection to a second electronic device, the first electronic device stores metadata of a first file on the second electronic device, the metadata includes a file modification type and a file modification tag, and the method includes:receiving a read instruction for the first file;reading a file modification type and a file modification tag of the first file; andreading the first file according to the file modification type and the file modification tag of the first file.

When reading a file across devices, the electronic device obtains the file modification type and the file modification tag of the file, and reads the file according to the file modification type and the file modification tag. The electronic device may adopt different read policies for different file modification types and file modification tags, thereby improving performance of distributed file access.

In some optional implementations, the file modification type includes at least one of the following: a terminalless write type, a single-terminal write type, an occasional multi-terminal write type, or a frequent multi-terminal write type.

In some optional implementations, the reading the first file according to the file modification type and the file modification tag includes:if the file modification type of the first file is the frequent multi-terminal write type, reading the first file from the second electronic device.

In some optional implementations, the reading the first file according to the file modification type and the file modification tag includes:if the file modification type of the first file is the terminalless write type, the single-terminal write type, or the occasional multi-terminal write type, and the first file is not in a local cache of the first electronic device, downloading the first file from the second electronic device and caching the first file locally, and reading the first file from the local cache of the first electronic device.

For a remote file of the terminalless write type, the single-terminal write type, or the occasional multi-terminal write type, in this application, the remote file is cached locally and then read, thereby improving file reading efficiency.

In some optional implementations, the reading the first file according to the file modification type and the file modification tag includes:if the file modification type of the first file is the terminalless write type, and the first file is in a local cache of the first electronic device, or if the file modification type of the first file is the single-terminal write type or the occasional multi-terminal write type, the first file is in a local cache of the first electronic device, and a device ID in the file modification tag of the first file is the same as a device ID of the first electronic device, reading the first file from the local cache of the first electronic device.

In some optional implementations, the reading the first file according to the file modification type and the file modification tag includes:if the file modification type of the first file is the single-terminal write type or the occasional multi-terminal write type, the first file is in the local cache, and a device ID in the file modification tag of the first file is different from a device ID of the first electronic device, obtaining a file modification record of the first file from the second electronic device, updating the first file according to the file modification record of the first file, and reading the updated first file.

In some optional implementations, the file modification record includes modification location information and a modified part, and the updating the first file according to the file modification record of the first file includes:updating, according to the modification location information, the modified part to the first file locally cached by the first electronic device; orthe file modification record includes the modification location information and a size of modified data, and the updating the first file according to the file modification record of the first file includes:obtaining the modified part of the first file from the second electronic device according to the modification location information and the size of the modified data, and updating, according to the modification location information, the modified part to the first file locally cached by the first electronic device.

In some optional implementations, the first electronic device further stores a second file, metadata of the second file, and a file modification record of the second file, the second electronic device stores the metadata of the second file, and the method further includes:obtaining a modification instruction for the second file; andin response to the modification instruction for the second file, modifying the second file, and updating the file modification record of the second file.

In some optional implementations, the method further includes:updating a file modification type and a file modification tag in the metadata of the second file according to the file modification record of the second file; andsynchronizing the updated metadata of the second file to the second electronic device.

In some optional implementations, the method further includes:obtaining a modification instruction for the first file;in response to the modification instruction for the first file, generating file modification information of the first file, where the file modification information includes a file modification tag before modification, a file modification tag after modification, the modification location information, and the modified part; andsending a file modification request to the second electronic device, where the file modification request carries the file modification information of the first file.

In some optional implementations, the updating a file modification type and a file modification tag in the metadata of the second file according to the file modification information of the second file and an updated file modification record of the second file includes:if the file modification type of the second file is the terminalless write type, modifying the file modification type of the second file to the single-terminal write type; orif the file modification type of the second file is the single-terminal write type, two or more devices modify the second file in a fixed time window, and a time interval between times when the two or more devices modify the second file is less than a preset time interval, modifying the file modification type of the second file to the frequent multi-terminal write type; orif the file modification type of the second file is the single-terminal write type, two or more devices modify the second file in a fixed time window, and a time interval between times when the two or more devices modify the second file is greater than or equal to a preset time interval, modifying the file modification type of the second file to the occasional multi-terminal write type; orif the file modification type of the second file is the occasional multi-terminal write type, two or more devices modify the second file in a fixed time window, and a time interval between times when the two or more devices modify the second file is less than a preset time interval, modifying the file modification type of the second file to the frequent multi-terminal write type; orif the file modification type of the second file is the occasional multi-terminal write type, and no two or more devices modify the second file in a fixed time window, modifying the file modification type of the second file to the single-terminal write type; orif the file modification type of the second file is the frequent multi-terminal write type, two or more devices modify the second file in a fixed time window, and a time interval between times when the two or more devices modify the second file is greater than or equal to a preset time interval, modifying the file modification type of the second file to the occasional multi-terminal write type; orif the file modification type of the second file is the frequent multi-terminal write type, and no two or more devices modify the second file in a fixed time window, modifying the file modification type of the second file to the single-terminal write type.

In this application, different initial file modification types are selected for different files, and the file modification type is adaptively switched in a scenario in which different files conflict. Compared with a conventional file access method, in scenarios of terminalless write, single-terminal write, and occasional multi-terminal write, the file access method provided in this application has better performance, and performance is improved more significantly in a high-latency network condition. This application reduces one-time instantaneous real-time protocol transmissions of a device. Compared with the proxy mode in the NFS protocol, this application reduces network interaction, and avoids a case in which a write operation is exclusive. In this application, when a network of a single device is unstable, operating performance of another device is not affected.

In some optional implementations, the updating a file modification type and a file modification tag in the metadata of the second file according to the file modification information of the second file and an updated file modification record of the second file further includes:if the updated file modification type of the second file is the single-terminal write type or the occasional multi-terminal write type, and a file modification tag before modification in the file modification information of the second file is different from the file modification tag in the metadata of the second file, or if the updated file modification type of the second file is the frequent multi-terminal write type, generating a new file modification tag for the second file; and updating the file modification tag in the metadata of the second file to the new file modification tag; orif the updated file modification type of the second file is the single-terminal write type or the occasional multi-terminal write type, and a file modification tag before modification in the file modification information of the second file is the same as the file modification tag in the metadata of the second file, updating the file modification tag in the metadata of the second file to a file modification tag after modification in the file modification information of the second file.

In some optional implementations, the modification location information includes a modification location offset.

A second aspect of this application discloses a distributed file access apparatus, applied to a first electronic device, where the first electronic device is in communication connection to a second electronic device, the first electronic device stores metadata of a first file on the second electronic device, the metadata includes a file modification type and a file modification tag, and the apparatus includes:a receiving module, configured to receive a read instruction for the first file; anda reading module, configured to: read the file modification type and the file modification tag of the first file, and read the first file according to the file modification type and the file modification tag of the first file.

In some optional implementations, the file modification type includes at least one of the following: a terminalless write type, a single-terminal write type, an occasional multi-terminal write type, or a frequent multi-terminal write type.

In some optional implementations, the reading module is configured to:if the file modification type of the first file is the frequent multi-terminal write type, read the first file from the second electronic device.

In some optional implementations, the reading module is configured to:if the file modification type of the first file is the terminalless write type, the single-terminal write type, or the occasional multi-terminal write type, and the first file is not in a local cache of the first electronic device, download the first file from the second electronic device and cache the first file locally, and read the first file from the local cache of the first electronic device.

In some optional implementations, the reading module is configured to:if the file modification type of the first file is the terminalless write type, and the first file is in a local cache of the first electronic device, or if the file modification type of the first file is the single-terminal write type or the occasional multi-terminal write type, the first file is in a local cache of the first electronic device, and a device ID in the file modification tag of the first file is the same as a device ID of the first electronic device, read the first file from the local cache of the first electronic device.

In some optional implementations, the reading module is configured to:if the file modification type of the first file is the single-terminal write type or the occasional multi-terminal write type, the first file is in the local cache, and a device ID in the file modification tag of the first file is different from a device ID of the first electronic device, obtain a file modification record of the first file from the second electronic device, update the first file according to the file modification record of the first file, and read the updated first file.

In some optional implementations, the file modification record includes modification location information and a modified part, and the reading module is configured to:update, according to the modification location information, the modified part to the first file locally cached by the first electronic device; orthe file modification record includes modification location information and a size of modified data, and the reading module is configured to:obtain the modified part of the first file from the second electronic device according to the modification location information and the size of the modified data, and update, according to the modification location information, the modified part to the first file locally cached by the first electronic device.

In some optional implementations, the first electronic device further stores a second file, metadata of the second file, and a file modification record of the second file, the second electronic device stores the metadata of the second file, and the apparatus further includes:an in-device modification module, configured to obtain a modification instruction for the second file; wherethe in-device modification module is further configured to: in response to the modification instruction for the second file, modify the second file, and update the file modification record of the second file.

In some optional implementations, the in-device modification module is further configured to: update the file modification type and the file modification tag in the metadata of the second file according to the file modification record of the second file, and synchronize the updated metadata of the second file to the second electronic device.

In some optional implementations, the apparatus further includes:a cross-device modification module, configured to: obtain a modification instruction for the first file; in response to the modification instruction for the first file, generate file modification information of the first file, where the file modification information includes a file modification tag before modification, a file modification tag after modification, modification location information, and a modified part; and send a file modification request to the second electronic device, where the file modification request carries the file modification information of the first file.

A third aspect of this application discloses a distributed file access method, applied to a second electronic device, where the second electronic device is in communication connection to a first electronic device, the second electronic device stores a first file, metadata of the first file, and a file modification record of the first file, the metadata includes a file modification type and a file modification tag, and the method includes:synchronizing the metadata of the first file to the first electronic device; andif a modification record obtaining request sent by the first electronic device is received, returning the file modification record of the first file to the first electronic device.

In some optional implementations, the method further includes:if a file modification request for the first file that is sent by the first electronic device is received, modifying the first file according to the file modification request;updating the file modification record of the first file;updating the metadata of the first file; andsynchronizing the updated metadata of the first file to the first electronic device.

A fourth aspect of this application discloses a distributed file access apparatus, applied to a second electronic device, where the second electronic device is in communication connection to a first electronic device, the second electronic device stores a first file, metadata of the first file, and a file modification record of the first file, the metadata includes a file modification type and a file modification tag, and the apparatus includes:a synchronization module, configured to synchronize the metadata of the first file to the first electronic device; anda modification response module, configured to: if a modification record obtaining request sent by the first electronic device is received, return the file modification record of the first file to the first electronic device.

In some optional implementations, the modification response module is further configured to: if a file modification request for the first file that is sent by the first electronic device is received, modify the first file according to the file modification request, update the file modification record and the metadata of the first file, and synchronize the updated metadata of the first file to the first electronic device.

A fifth aspect of this application discloses a computer program product, where when the computer program product runs on a computer, the computer is enabled to perform the distributed file access method according to the first aspect or the third aspect.

A sixth aspect of this application discloses a computer-readable storage medium, including a computer instruction, where when the computer instructions are run on an electronic device, the electronic device is enabled to perform the distributed file access method according to the first aspect or the third aspect.

A seventh aspect of this application discloses an electronic device. The electronic device includes a processor and a memory, where the memory is configured to store instructions, and the processor is configured to invoke the instructions in the memory, so that the electronic device performs the distributed file access method according to the first aspect or the third aspect.

An eighth aspect of this application discloses a chip system. The chip system is applied to an electronic device. The chip system includes an interface circuit and a processor. The interface circuit and the processor are interconnected by using a line. The interface circuit is configured to receive a signal from a memory of the electronic device, and send the signal to the processor, where the signal includes computer instructions stored in the memory. When the processor executes the computer instructions, the chip system performs the distributed file access method according to the first aspect or the third aspect.

It should be understood that the distributed file access apparatuses according to the second aspect and the fourth aspect, the computer program product according to the fifth aspect, the computer-readable storage medium according to the sixth aspect, the electronic device according to the seventh aspect, and the chip system according to the eighth aspect correspond to the methods according to the first aspect and the second aspect. Therefore, for beneficial effects that can be achieved by the distributed file access apparatuses, the computer program product, the computer-readable storage medium, and the chip system, refer to the beneficial effects in the corresponding methods provided above. Details are not described herein again.

DESCRIPTION OF EMBODIMENTS

For ease of understanding, descriptions of some concepts related to embodiments of this application are provided as examples for reference, as shown in the following:

It should be noted that, in this application, “at least one” means one or more, and “a plurality of” means two or more. “And/or” describes an association relationship between associated objects, and represents that three relationships may exist. For example, A and/or B may represent the following cases: Only A exists, both A and B exist, and only B exists, where A and B may be singular or plural. In this specification, claims, and accompanying drawings of this application, terms “first”, “second”, “third”, “fourth”, and the like (if existent) are intended to distinguish between similar objects but do not necessarily indicate a specific order or sequence.

To better understand a distributed file access method and a related device disclosed in embodiments of this application, the following first describes an application scenario of the distributed file access method according to this application.

FIG.1is a schematic diagram of an application scenario of a distributed file access method according to an embodiment of this application. As shown inFIG.1, a plurality of electronic devices10are in communication connection through a network (that is, a distributed network), and the electronic device10performs inter-device file access according to a file modification type and a file modification tag, to improve performance of file access between the electronic devices10.

The electronic device10may be a mobile phone, a tablet, a computer, a vehicle-mounted device, a large screen, a smart band, a smartwatch, or the like. As shown inFIG.1, the electronic devices10in the distributed network include a mobile phone, a tablet, and a large screen.

The distributed network may be established for a plurality of electronic devices10, and file access may be performed between any two electronic devices10in the distributed network by using the distributed file access method according to this application. Each electronic device10in the distributed network may provide a local file for another electronic device to access, or may access a file on another electronic device.

The electronic devices10may be wirelessly connected or wiredly connected. The electronic devices10may be in stable communication connection, or may be in unstable communication connection. In an embodiment of this application, short-range wireless communication may be performed between the electronic devices10. For example, the electronic devices10may perform short-range wireless communication with each other by using Bluetooth, Wi-Fi, near field communication (NFC), a ZigBee technology, an infrared data association (IrDA) technology, an ultra wideband (UWB) technology, or a wireless universal serial bus (USB).

FIG.2is a diagram of a software architecture of an electronic device10for implementing a distributed file access method according to this application.

As shown inFIG.2, the electronic device10may include a distributed file system driver100, a communication module101, an application102, a distributed file server103, a distributed file client104, a distributed metadata server105, and a distributed database106. The electronic device10may include a kernel space11and a user space12. In an embodiment of this application, the distributed file system driver100and the communication module101are located in the kernel space11of the electronic device10, and the application102, the distributed file server103, the distributed file client104, the distributed metadata server105, and the distributed database106are located in the user space12of the electronic device10.

In another embodiment of this application, the distributed file system driver100, the distributed file server103, the distributed file client104, the distributed metadata server105, and the distributed database106may be distributed in another manner. For example, the distributed file system driver100, the distributed file server103, the distributed file client104, the distributed metadata server105, and the distributed database106may all be located in the kernel space11. For another example, the distributed file system driver100may be located in the kernel space11, and the distributed file server103, the distributed file client104, the distributed metadata server105, and the distributed database106may be located in the user space12.

The distributed file system driver100is configured to provide a distributed file access capability.

The communication module101is configured to communicate with another electronic device.

The application102may be any application that can run on the electronic device10, for example, a utility application, a social chat application, or a media application. The electronic device10accesses a file by using the application102. For example, the electronic device10includes a music player, and the electronic device10plays an audio file on another electronic device by using the music player. For another example, the electronic device10includes a text editor, and the electronic device10edits a text in another electronic device by using the text editor.

The distributed file server103is configured to provide capabilities of managing and accessing local files.

The distributed file client104is configured to interact with the distributed file server103, so as to implement file access between devices. For example, the distributed file client104of a device B interacts with the distributed file server103of the device A to access a file on a device A.

The distributed metadata server105is responsible for synchronizing and managing metadata of each electronic device. The distributed metadata server105may generate a distributed file directory, and display a file of each electronic device in the distributed file directory. The distributed database106is configured to store metadata of a file.

The metadata stored in each electronic device (for example, the device B) includes metadata of a local file, and further includes metadata of a remote file (for example, a file on the device A) synchronized from a remote device (for example, the device A).

The metadata of a file is used to record file attribute information, such as a file name, a file size, a file location, and a last modification time. Before performing an operation (for example, reading or editing) on a file, file location information of the file needs to be obtained, a location of the file needs to be located according to the file location information, and content of the file needs to be obtained from the location. For example, the device B may obtain file location information of a file on the device A according to metadata synchronized from the device A, and access the file on the device A according to the file location information.

In the distributed file access method in this application, two fields are added to metadata of a file: a file modification type and a file modification tag, so as to improve performance of cross-device file access. For details about the file modification type and the file modification tag, refer to related descriptions inFIG.3.

FIG.3is a schematic diagram of metadata used in this application.

As shown inFIG.3, the metadata used in this application includes two fields: a file modification type (represented as File Type) and a file modification tag (represented as Tag). An electronic device (for example, a device A) determines the file modification type and the file modification tag in the metadata of a local file, and synchronizes the metadata including the file modification type and the file modification tag to another electronic device (for example, a device B) by using a distributed metadata server.

In an embodiment of this application, the file modification type includes a terminalless write type, a single-terminal write type, an occasional multi-terminal write type, and a frequent multi-terminal write type.

It should be understood that, in other embodiments of this application, another file modification type may be used. For example, the file modification type includes a read-only type, the single-terminal write type, the occasional multi-terminal write type, and the frequent multi-terminal write type. A quantity of the file modification types may be more (for example, five) or less (for example, three). For example, the file modification type includes the read-only type, the terminalless write type, the single-terminal write type, and a multi-terminal write type. Terminalless write type: No device modifies a file in a fixed time window (for example, minutes before a current time). For example, if a user uses the device B to read a media file of the device A, and the media file is not modified in a fixed time window, the media file is of the terminalless write type.

Single-terminal write type: A device modifies a file in a fixed time window. For example, if a user uses the device B to modify a document file of the device A, and no other device modifies the document file in a fixed time window, the document file is of the single-terminal write type.

Occasional multi-terminal write type: Two or more devices modify a file in a fixed time window, and a time interval between times when different times modify the file is greater than or equal to a preset time interval (for example, 10 seconds), or a quantity of modification times of the file is less than or equal to a preset quantity, or a quantity of devices that modify the file is less than or equal to a preset quantity. For example, if a user uses the device B to modify a document file of the device A, and then uses a device C to continue to modify the document file of the device A, a time interval between a time when the device B modifies the document file and a time when the device C modifies the document file is greater than 10 seconds, and the device B and the device C do not modify the document file of the device A at the same time, the document file is of the occasional multi-terminal write type.

Frequent multi-terminal write type: Two or more devices modify a file in a fixed time window, and a time interval between times when different devices modify the file is less than a preset time interval, or a quantity of modification times of the file is greater than a preset quantity, or a quantity of devices that modify the file is greater than a preset quantity. For example, if a first user modifies the document file of the device A on the device B and a second user modifies the document file of the device A on the device C at the same time, the document file is of the frequent multi-terminal write type.

It should be noted that, when the file modification type is determined, the device that modifies the file (for example, the file on the device A) may be a device to which the file belongs (for example, the device A), or may be a remote device (for example, the device B). For example, if the device A includes a file “test”, and the device A and the device B modify the file “test” in a fixed time window, the two devices modify the file “test”.

In an embodiment of this application, the electronic device may update the file modification type of the local file according to a preset update time interval. During each update, if no device modifies the file in the fixed time window, the file modification type is modified to the terminalless write type; or if one device modifies the file in the fixed time window, the file modification type is modified to the single-terminal write type; or if two or more devices modify the file in the fixed time window, and the time interval between the times when different devices modify the file is greater than or equal to the preset time interval, or the quantity of modification times of the file is less than or equal to the preset quantity, or the quantity of devices that modify the file is less than or equal to the preset quantity, the file modification type is modified to the occasional multi-terminal write type; or if two or more devices modify the file in the fixed time window, and the time interval between the times when different devices modify the file is less than the preset time interval, or the quantity of modification times of the file is greater than the preset quantity, or the quantity of devices that modify the file is greater than the preset quantity, the file modification type is modified to the frequent multi-terminal write type.

A file modification type may be initialized for each file. In a file access process, the distributed file server updates the file modification type in the metadata according to a modification status of the file.

FIG.4is a schematic diagram of initializing a file modification type. The file modification type may be initialized according to a file name extension. For example, as shown inFIG.4, media files with file name extensions such as .mp4 and .mp3 and image files with file name extensions such as .jpg and .bmp may be initialized to the terminalless write type, and document files with file name extensions such as .doc, .ppt, and .xls may be initialized to the single-terminal write type.

In an embodiment of this application, an initialization setting interface of a file may be displayed on an electronic device, and a user may set or adjust an initial file modification type of the file by using the initialization setting interface. For example, an initial file modification type is preset for each file according to a file name extension of the file (for example, an initial file modification type of a file with the file name extension .mp4 is preset as the terminalless write type), and the user may adjust the initial file modification type of the file by using an initialization setting interface (for example, the user may adjust the file modification type of the file with the file name extension .mp4 to the single-terminal write type).

FIG.5Ais a schematic diagram of a file modification tag used in this application.

The file modification tag is used to identify each modification performed by an electronic device on a file. The file modification tag in metadata indicates the latest modification of the file.

Refer toFIG.5A. In an embodiment of this application, the file modification tag includes a device identifier (identifier, ID) and a timestamp, so as to ensure uniqueness of the file modification tag. The device ID indicates a device that modifies the file, and the timestamp indicates a time when the file is modified.

In other embodiments of this application, the file modification tag may include a device ID and a modification number. For example, a device A modifies the file for a plurality of times, the file modification tag corresponding to the first modification may be A+1, and the file modification tag corresponding to the second modification may be A+2, where A is the device ID, and 1 and 2 are modification numbers.

When an electronic device (for example, the device A) stores a new file (for example, stores a newly created document file, or stores a downloaded audio file), the device ID in the file modification tag may be set to the device ID of the electronic device (for example, the device A), and the timestamp may be set to the storage time of the file.

After modifying the file, the electronic device generates a new file modification tag for the file. For example, a device B modifies a file on the device A, and a file modification tag of the file before modification is “A+1”, and a new file modification tag B+1 is generated after modification.

FIG.5Bis a schematic diagram of file modification information used in this application.

An electronic device sends file modification information to a remote device when modifying a file of the remote device. Refer toFIG.5B. In an embodiment of this application, the file modification information includes a file modification tag before modification, a file modification tag after modification, modification location information, and a modified part. In the figure, “Base Tag” indicates the file modification tag before modification, “New Tag” indicates the file modification tag after modification, “offset” indicates the modification location information, and “data” indicates the modified part.

The file modification tag before modification is a file modification tag in metadata. The file modification tag after modification is a new file modification tag generated for the current modification.

The modification location information indicates the modification location of the file. The modification location information may be a modification location offset.

The modified part indicates modified content of the file.

In another embodiment of this application, the file modification information may further include a size of modified data. For example, if the electronic device modifies data of one byte in the file, the size of the modified data is one byte. The size of the modified data can be represented by “size”.

When the electronic device modifies the file, the electronic device generates the file modification information. If the file is modified across devices, the electronic device further sends the file modification information to a device to which the file belongs. For example, after modifying a file on a device A, a device B generates file modification information, and sends the file modification information to device A.

FIG.5Cis a schematic diagram of a file modification record used in this application.

An electronic device stores the file modification record of a local file, where the file modification record is used to indicate a modification history of the file.

Refer toFIG.5C. In an embodiment of this application, the electronic device generates file modification records according to N pieces of latest file modification information of a local file. Each record corresponds to one piece of file modification information, and indicates one modification to the file. N is a natural number, and a value of N may be set according to a requirement, for example, the value is 10. In an embodiment of this application, the file modification records may include file modification tags after modification (for example, New Tag 1, New Tag 2, . . . , and New Tag N in the figure), modification location information (for example, offset 1, offset 2, . . . , and offset N in the figure), and modified parts (for example, data 1, data 2, . . . , and data N in the figure). In another embodiment of this application, the file modification record may include a file modification tag after modification, modification location information, and a size of modified data.

The electronic device determines a file modification tag after modification (for example, New Tag N in the figure) in the last record in the file modification records as the file modification tag in the metadata of the file.

FIG.6is a schematic diagram of modifying a file across devices in a distributed file access method according to this application. In the figure, an example in which a device B modifies a file on a device A is used for description.

Before the device B modifies the file on the device A, the device A synchronizes metadata of the file to the device B, where the metadata includes a file modification type (represented as File Type 1 in the figure) and a file modification tag (represented as Tag X in the figure).

After the device B modifies the file, the device B sends file modification information to the device A. As shown in the figure, the file modification information sent by the device B to the device A is (Base Tag X, New Tag Y, offset, data), where “Base Tag X” is a file modification tag before modification, that is, a file modification tag synchronized from the device A to the device B; “New Tag Y” is a file modification tag after modification, including a device ID of the device B and a timestamp of modifying the file by device B; “offset” is modification location information (a modification location offset); and “data” is a modified part.

After receiving the file modification information, the device A updates the file modification record of the file according to the file modification information, modifies the locally stored file according to the modification location information and the modified part in the file modification information, modifies the locally stored file modification type and file modification tag according to the file modification type, the file modification tag before modification, and the file modification tag after modification in the file modification information, and synchronizes the file modification type and file modification tag after modification (for example, File Type 2, Tag Y) to the device B.

FIG.7shows policies for reading a file across devices and related analysis in a distributed file access method according to this application.

For a file of a terminalless write type, an electronic device downloads the file from a remote device and caches the file locally, and reads the file from a cache. If a size of the file is less than or equal to a preset size (that is, a small file), the entire file may be cached; or if the size of the file is greater than the preset size (that is, a large file, for example, a media file), a part of the file may be cached (that is, block-based caching). The electronic device only needs to check the file modification type of the file (that is, check the File Type field) in the locally stored metadata, to determine whether the file is of the terminalless write type.

For a file of the single-terminal write type, the electronic device caches the file from the remote device locally, and reads the file from the cache. In addition to checking the file modification type of the file in the locally stored metadata, so as to determine whether the file is of the single-terminal write type, the electronic device further checks the file modification tag of the file in the locally stored metadata. If the device ID in the file modification tag is not the ID of the electronic device, the electronic device requests the file modification record from the remote device, and updates, according to the file modification record, the locally cached file to ensure consistency with the file on the remote device.

For a file of the occasional multi-terminal write type, the electronic device caches the file from the remote device locally, and reads the file from the cache. In addition to checking the file modification type of the file in the locally stored metadata, the electronic device further checks the file modification tag of the file in the locally stored metadata. If the device ID in the file modification tag is not the ID of the electronic device, the electronic device requests the file modification record from the remote device, and updates, according to the file modification record, the locally cached file to ensure consistency with the file on the remote device.

For a file of the frequent multi-terminal write type, the electronic device does not cache the file, and reads the file from the remote device.

It should be noted that, when the electronic device reads a file of the terminalless write type, the single-terminal write type, or the occasional multi-terminal write type across devices, the electronic device first determines whether a required file/data block exists in the cache; and if the required file/data block does not exist in the cache, the electronic device downloads the corresponding file/data block from the remote device, and caches the file/data block locally. The electronic device may keep the cached file until the file cache space exceeds a preset threshold or the file is aged due to timeout.

That the electronic device further needs to check the file modification tag of the file from the locally stored metadata when the electronic device reads a file of the single-terminal write type or the occasional multi-terminal write type across devices means that when a required file/data block exists in the cache, the electronic device needs to check the file modification tag of the file from the locally stored metadata. If the required file/data block does not exist in the cache, the electronic device only needs to download the corresponding file/data block from the remote device, and cache the file/data block locally for reading.

For more details about reading a file across devices, refer toFIG.13A-FIG.13B.

FIG.7also compares information such as a scenario frequency and performance of different file modification types. For details, refer to the figure.

FIG.8is a schematic diagram of reading a file of a terminalless write type across devices in a distributed file access method according to this application. For a remote file (a file on a device A) of the terminalless write type, the electronic device (a device B) reads the file through a local cache.

It can be learned fromFIG.8that the device B reads the file of the terminalless write type on the device A by using a distributed file client on the device B and a distributed file server on the device A. For more details about reading the file of the terminalless write type across devices, refer toFIG.13A-FIG.13Band related descriptions.

It should be noted thatFIG.8only shows that the device B reads a file of the terminalless write type on the device A. It should be understood that the device B may modify/write a file of the terminalless write type on the device A.

FIG.9is a schematic diagram of reading and writing a file of a single-terminal write type across devices in a distributed file access method according to this application. For a remote file (a file on a device A) of the single-terminal write type, the electronic device (a device B) reads and writes the file through a local cache.

It can be learned fromFIG.9that the device B reads and writes a file of the single-terminal write type on the device A by using a distributed file client on the device B and a distributed file server on the device A.FIG.9shows that the device B reads a file of the single-terminal write type on the device A through a local cache. For more details, refer toFIG.13A-FIG.13B,FIG.15, and related descriptions.

FIG.10andFIG.11are schematic diagrams of reading and writing a file of an occasional multi-terminal write type across devices in a distributed file access method according to this application.FIG.10shows cached data that is modified when a write conflict exists, andFIG.11shows cached data that is modified and then read when a write conflict exists.

It can be learned fromFIG.10andFIG.11that a device B reads and writes a file of an occasional multi-terminal write type on a device A by using a distributed file client on the device B and a distributed file server on the device A.

For a remote file (a file on the device A) of the occasional multi-terminal write type, electronic devices (the device B and a device C) read and write the file through a local cache. As shown inFIG.10, when the device B and a device C modify files on the device A and a write conflict exists, the device B caches the files modified by the device B, and the device C caches the files modified by the device C. As shown inFIG.11, when the device B and the device C read files after modifying the files on the device A (a write conflict exists), the device B and the device C update locally cached files, so that the locally cached files are consistent with the files on the device A.

A write conflict occurs when a plurality of devices (for example, the device B and the device C) modify a same remote file (for example, a file on the device A): Another device modifies the file while the file is being modified by a device. As a result, the file cached on the device is inconsistent with the remote file. In this application, a file modification tag is used to detect whether a write conflict exists.

It should be noted that the device B and the device C may modify the file on the device A at the same location (including partially the same location), or may modify the file on the device A at different locations. The figure shows a case in which the modification locations are different. For a case in which the modification locations are the same and a case in which the modification locations are different, the processing procedures of the device A, the device B, and the device C are the same. For more details about reading and writing a file of the occasional multi-terminal write type across devices, refer toFIG.13A-FIG.13B,FIG.15, and related descriptions.

FIG.12is a schematic diagram of reading and writing a file of a frequent multi-terminal write type across devices in a distributed file access method according to this application. For a remote file (for example, a file on a device A in the figure) of the frequent multi-terminal write type, an electronic device (for example, a device B and a device C in the figure) does not cache the file locally, and reads and writes the file from a remote device (for example, the device A in the figure) each time.

It can be learned fromFIG.12that the device B reads and writes a file of the frequent multi-terminal write type on the device A by using a distributed file client on the device B and a distributed file server on the device A.

The following uses the first electronic device and the second electronic device as an example to describe how an electronic device performs efficient file access in the distributed file access method according to this application. The first electronic device stores a second file, metadata of the second file, and a file modification record of the second file. The second electronic device stores a first file, metadata of the first file, and a file modification record of the first file. The first electronic device further stores the metadata that is of the first file and that is synchronized from the second electronic device. The second electronic device further stores the metadata that is of the second file and that is synchronized from the first electronic device. The metadata includes a file modification type and a file modification tag.

The first electronic device and the second electronic device may synchronize metadata with each other when being connected for the first time. That is, the first electronic device synchronizes metadata of local files (including the second file) to the second electronic device, and the second electronic device synchronizes metadata of local files (including the first file) to the first electronic device.

Alternatively, the first electronic device may send a metadata synchronization request to the second electronic device. After receiving the metadata synchronization request, the second electronic device synchronizes the metadata of the local files of the second electronic device to the first electronic device. Similarly, the second electronic device may send a metadata synchronization request to the first electronic device. After receiving the metadata synchronization request, the first electronic device synchronizes the metadata of the local files of the first electronic device to the second electronic device.

FIG.13A-FIG.13Bare a flowchart of reading, by a first electronic device (for example, a device B), a first file on a second electronic device (for example, a device A) (that is, reading the file across devices) in a distributed file access method according to this application.

1301: The first electronic device receives a read instruction for the first file.

A distributed file directory may be displayed on the first electronic device, files of each electronic device (for example, the electronic device10shown inFIG.1) are displayed in the distributed file directory, and a user clicks the first file of the second electronic device from the distributed file directory, so as to send a read instruction for the first file.

Alternatively, the first electronic device (for example, the device B) may receive a read instruction of another electronic device (for example, a device C) for the first file (for example, a file on the device A).

1302: The first electronic device reads a file modification type and a file modification tag of the first file that are stored in the first electronic device.

In an embodiment of this application, the first electronic device may be provided with a distributed database, and metadata of a local file and metadata of a remote file are stored in the distributed database. The first electronic device reads the metadata of the first file from the distributed database, and reads the file modification type of the first file from the metadata of the first file.

1303: The first electronic device determines whether the file modification type of the first file is a terminalless write type.

1304: If the file modification type of the first file is the terminalless write type, the first electronic device determines whether the first file is in a local cache.

If the first file is in the local cache, step1313is performed.

1305: If the first file is not in the local cache, the first electronic device downloads the first file from the second electronic device and caches the first file locally, and then performs step1313.

1306: If the file modification type of the first file is not the terminalless write type, the first electronic device determines whether the file modification type of the first file is a frequent multi-terminal write type.

1307: If the file modification type of the first file is the frequent multi-terminal write type, the first electronic device reads the first file from the second electronic device. The first electronic device may send a file read request to the second electronic device, so as to read the first file on the second electronic device. After receiving the file read request, the second electronic device sends the first file to the first electronic device.

1308: If the file modification type of the first file is not the frequent multi-terminal write type, the first electronic device determines whether the file modification type of the first file is a single-terminal write type or an occasional multi-terminal write type.

If the file modification type of the first file is not the single-terminal write type or the occasional multi-terminal write type, it indicates that the file modification type of the first file is incorrect, and the procedure ends.

1309: If the file modification type of the first file is the single-terminal write type or the occasional multi-terminal write type, the first electronic device determines whether the first file is in the local cache.

If the first file is not in the local cache,1305and1313are performed.

1310: If the first file is in the local cache, the first electronic device determines whether a device ID in the file modification tag of the first file is a device ID of the first electronic device. If the device ID in the file modification tag of the first file is the device ID of the first electronic device,1313is performed.

1311: If the device ID in the file modification tag of the first file is not the device ID of the first electronic device, the first electronic device obtains a file modification record of the first file from the second electronic device.

The first electronic device may send a modification record obtaining request to the second electronic device, and receive the file modification record of the first file returned by the second electronic device.

1312: The first electronic device updates, according to the file modification record, the locally cached first file to ensure consistency with the first file on the second electronic device.

In an embodiment of this application, the file modification record includes modification location information and a modified part, and the first electronic device updates, according to the modification location information (for example, a modification location offset), the modified part to the first file locally cached by the first electronic device. For example, if the first file locally cached by the first electronic device is “123456799”, the modification location offset in the file modification record is 0, and the modified part is “55”, the first electronic device updates the locally cached first file to “553456799”.

In another embodiment of this application, the file modification record includes modification location information and a size of modified data. The first electronic device obtains a modified part from the second electronic device according to the modification location information (for example, a modification location offset) and the size of modified data in the file modification record, and updates the locally cached first file according to the modified part obtained from the second electronic device. For example, if the first file locally cached by the first electronic device is “123456799”, the modification location offset in the file modification record is 0, and the size of the modified data is 2 (indicating that two digits are changed), the first electronic device obtains the modified part “55” from the second electronic device, and updates the locally cached first file to “553456799”.

1313: The first electronic device reads the first file from the local cache.

It should be understood that, in the embodiment described inFIG.13A-FIG.13B, the first electronic device sequentially determines whether the file modification type of the first file is the terminalless write type, the single-terminal write type, the occasional multi-terminal write type, and the frequent multi-terminal write type. In another embodiment of this application, a sequence of determining the file modification type of the first file may be changed. For example, it may be sequentially determined whether the file modification type of the first file is the frequent multi-terminal write type, the occasional multi-terminal write type, the single-terminal write type, or the terminalless write type. Alternatively, in one step, it may be directly determined that the file modification type of the first file is one of the following: the terminalless write type, the single-terminal write type, the occasional multi-terminal write type, and the frequent multi-terminal write type; and corresponding processing is performed according to a determining result.

It should be noted that, in1301, if the first electronic device (for example, the device B) receives the read instruction of another electronic device (for example, the device C) for the first file (for example, the file on the device A), the first electronic device reads the first file from the local cache, and then sends the first file to the another electronic device.

In the embodiment shown inFIG.13A-FIG.13B, when reading a file across devices, the electronic device obtains the file modification type and the file modification tag of the file, and reads the file according to the file modification type and the file modification tag. The electronic device may adopt different read policies for different file modification types and file modification tags, thereby improving performance of distributed file access.

For a remote file of the terminalless write type, the single-terminal write type, or the occasional multi-terminal write type, in this embodiment of this application, the remote file is cached locally and then read, thereby improving file reading efficiency.

FIG.14is a flowchart of modifying, by a first electronic device, a second file on the first electronic device in a distributed file access method according to this application.

1401: The first electronic device receives a modification instruction for a second file.

A distributed file directory may be displayed on the first electronic device, and files of each electronic device in a distributed network are displayed in the distributed file directory. A user opens the second file from the distributed file directory to modify the second file, so as to send a modification instruction for the second file.

Alternatively, the first electronic device (for example, a device B) may receive a modification instruction of another electronic device (for example, a device C) for the second file.

1402: The first electronic device generates file modification information of the second file.

The generated file modification information may include a file modification tag before modification, a file modification tag after modification, modification location information (for example, a modification location offset), and a modified part.

For example, the first electronic device generates the file modification information (Base Tag (N+1), New Tag (N+1), offset (N+1), data (N+1)). “Base Tag (N+1)” is the file modification tag before modification; “New Tag (N+1)” is the file modification tag after modification; “offset (N+1)” is the modification location offset; and “data (N+1)” is the modified part.

1403: The first electronic device updates a file modification record of the second file according to the file modification information of the second file.

For example, the file modification record includes the file modification tag after modification, the modification location information, and the modified part. The file modification record of the second file before update is shown inFIG.5C. The first electronic device adds (New Tag (N+1), offset (N+1), data (N+1)) to the file modification record of the second file before update, to obtain the updated file modification record of the second file.

1404: The first electronic device updates a file modification type and the file modification tag in metadata of the second file according to the file modification information of the second file and the updated file modification record of the second file.

For a specific process in which the first electronic device updates the file modification type and the file modification tag in the metadata of the second file according to the file modification information of the second file and the updated file modification record of the second file, refer toFIG.16A-FIG.16C.

1405: The first electronic device synchronizes the updated metadata of the second file to the second electronic device.

The first electronic device may synchronize the updated metadata of the second file to each electronic device in the distributed network.

FIG.15is a flowchart of modifying, by a first electronic device, a first file on a second electronic device in a distributed file access method according to this application.

1501: The first electronic device receives a modification instruction for the first file.

A distributed file directory may be displayed on the first electronic device, and files of each electronic device in a distributed network are displayed in the distributed file directory. A user opens the first file from the distributed file directory to modify the first file, so as to send a modification instruction for the first file.

Alternatively, the first electronic device (for example, the device B) may receive a read instruction of another electronic device (for example, a device C) for the first file (for example, a file on the device A).

1502: The first electronic device generates file modification information of the first file.

1503: The first electronic device sends a file modification request to the second electronic device, where the file modification request carries the file modification information that is of the first file and that is generated by the first electronic device.

1504: The second electronic device modifies the locally stored first file according to the file modification information in the file modification request.

1505: The second electronic device updates a file modification record of the first file according to the file modification information in the file modification request.

1506: The second electronic device updates a file modification type and a file modification tag in metadata of the first file according to the file modification information of the first file and the updated file modification record of the first file.

For a specific process in which the second electronic device updates the file modification type and the file modification tag in the metadata of the first file according to the file modification information of the first file and the updated file modification record of the first file, refer toFIG.16A-FIG.16C.

1507: The second electronic device synchronizes the updated metadata of the first file to the first electronic device.

The second electronic device may synchronize the updated metadata of the first file to each electronic device in the distributed network.

FIG.16A-FIG.16Care a detailed flowchart of updating, by a first electronic device, a file modification type and a file modification tag in metadata of a second file according to file modification information of a second file and an updated file modification record of the second file (that is,1404inFIG.14) in a distributed file access method according to this application. A method for updating, by the second electronic device, the file modification type and the file modification tag (that is,1506inFIG.15) in the metadata of the first file according to the file modification information of the first file and the updated file modification record of the first file is the same as that for updating, by the first electronic device, the file modification type and the file modification tag (that is,1404inFIG.14) in the metadata of the second file according to the file modification information of the second file and the updated file modification record of the second file. Details are not described herein again.

1601: The first electronic device determines whether the file modification type of the second file is a terminalless write type.

1602: If the file modification type of the second file is the terminalless write type, the first electronic device modifies the file modification type of the second file to a single-terminal write type, and then performs1608.

1603: If the file modification type of the second file is not the terminalless write type, the first electronic device determines whether the file modification type of the second file is the single-terminal write type.

1604: If the file modification type of the second file is the single-terminal write type, the first electronic device determines, according to the updated file modification record of the second file, whether two or more devices modify the second file (that is, multi-device modification) in a fixed time window (for example, 10 minutes before a current time).

1605: If two or more devices modify the second file in the fixed time window, the first electronic device determines whether a time interval between times when the two or more devices modify the second file is greater than or equal to a preset time interval (for example, 10 seconds).

1606: If the time interval between the times when the two or more devices modify the second file is not greater than or equal to (that is, less than) the preset time interval, the first electronic device modifies the file modification type of the second file to a frequent multi-terminal write type, and then performs1620.

1607: If the time interval between the times when the two or more devices modify the second file is greater than or equal to the preset time interval, the first electronic device modifies the file modification type of the second file to an occasional multi-terminal write type, and then performs step1618.

1608: If the file modification type of the second file is not the single-terminal write type, the first electronic device determines whether the file modification type of the second file is the occasional multi-terminal write type.

1609: If the file modification type of the second file is the occasional multi-terminal write type, the first electronic device determines, according to the updated file modification record of the second file, whether two or more devices modify the second file (that is, multi-device modification) in the fixed time window.

1610: If no two or more devices modify the second file in the fixed time window, the first electronic device modifies the file modification type of the second file to the single-terminal write type, and then performs1618.

1611: If two or more devices modify the second file in the fixed time window, the first electronic device determines whether the time interval between the times when the two or more devices modify the second file is greater than or equal to the preset time interval.

If the time interval between the times when the two or more devices modify the second file is not greater than or equal to the preset time interval,1618is performed.

1612: If the time interval between the times when the two or more devices modify the second file is not greater than or equal to (that is, less than) the preset time interval, the first electronic device modifies the file modification type of the second file to a frequent multi-terminal write type, and then performs1620.

1613: If the file modification type of the second file is not the occasional multi-terminal write type, the first electronic device determines whether the file modification type of the second file is the frequent multi-terminal write type.

If the file modification type of the second file is not the frequent multi-terminal write type, it indicates that the file modification type of the second file is incorrect, and the procedure ends.

1614: If the file modification type of the second file is the frequent multi-terminal write type, the first electronic device determines, according to the updated file modification record of the second file, whether two or more devices modify the second file (that is, multi-device modification) in the fixed time window.

1615: If no two or more devices modify the second file in the fixed time window, the first electronic device modifies the file modification type of the second file to the single-terminal write type.

1616: If two or more devices modify the second file in the fixed time window, the first electronic device determines whether the time interval between the times when the two or more devices modify the second file is greater than or equal to the preset time interval, and then performs1618.

1617: If the time interval between the times when the two or more devices modify the second file is greater than or equal to the preset time interval, the first electronic device modifies the file modification type of the second file to the occasional multi-terminal write type, and then performs step1618.

1618: The first electronic device determines whether a file modification tag before modification in the file modification information is the same as the file modification tag in the metadata.

1619: If the file modification tag before modification in the file modification information is the same as the file modification tag in the metadata, the first electronic device updates the file modification tag in the metadata of the second file to the file modification tag after modification in the file modification information.

1620: If the file modification tag before modification in the file modification information is different from the file modification tag in the metadata, it indicates that a write conflict exists, and the first electronic device generates a new file modification tag for the second file, and updates the file modification tag in the metadata of the second file to the new file modification tag.

It should be understood that, in the embodiment described inFIG.16A-FIG.16C, the first electronic device sequentially determines whether the file modification type of the second file is the terminalless write type, the single-terminal write type, the occasional multi-terminal write type, and the frequent multi-terminal write type. In another embodiment of this application, a sequence of determining the file modification type of the second file may be changed. For example, it may be sequentially determined whether the file modification type of the second file is the frequent multi-terminal write type, the occasional multi-terminal write type, the single-terminal write type, or the terminalless write type. Alternatively, in one step, it may be directly determined that the file modification type of the second file is one of the following: the terminalless write type, the single-terminal write type, the occasional multi-terminal write type, and the frequent multi-terminal write type; and corresponding processing is performed according to a determining result.

In this application, different initial file modification types are selected for different files, and the file modification type is adaptively switched in a scenario in which different files conflict. Compared with a conventional file access method, in scenarios of terminalless write, single-terminal write, and occasional multi-terminal write, the file access method provided in this application has better performance, and performance is improved more significantly in a high-latency network condition. This application reduces one-time instantaneous real-time protocol transmissions of a device. Compared with the proxy mode in the NFS protocol, this application reduces network interaction, and avoids a case in which a write operation is exclusive. In this application, when a network of a single device is unstable, operating performance of another device is not affected.

FIG.17A-FIG.17Bare a schematic diagram of a processing procedure when a write conflict occurs in a distributed file access method according to this application.

As shown inFIG.17A-FIG.17B, a device A stores a file whose file name is “test” and file content is “123456”, and the device A further stores metadata of the file “test”, where a file modification type of the file “test” is occasional multi-terminal write, and a file modification tag is “C+1”. The device A synchronizes the metadata of the file “test” to a device B and a device C. The device B reads the file “test” from the device A, and caches the file content “123456” locally. The device B modifies the file content “123456” to “12345699”. The device B sends a file modification request (file writing) carrying file modification information to the device A, where a file modification tag before modification is “C+1”, a file modification tag after modification is “B+1”, modification location information (a modification location offset) is “7”, and a modified part is “99”. The device A modifies the file modification tag in the metadata to “B+1” and modifies the file content to “12345699” according to the file modification request of the device B. When the device B writes a file to the device A, the device C reads the file “test” from the device A, and caches the file content “123456” locally. The device C modifies the file content “123456” to “553456”. The device C sends a file modification request carrying file modification information to the device A, where a file modification tag before modification is “C+1”, modification location information (a modification location offset) is 0, a file modification tag after modification is “C+1”, and a modified part is “55”. After receiving the file modification request from the device C, the device A detects a write conflict, modifies the file modification tag in the metadata to “C+2”, and modifies the file content to “55345699”. The device A synchronizes the modified metadata to the device B and the device C. The device B and the device C read the file “test” again, and the read file content is “55345699”.

FIG.18is a schematic diagram of functional modules of a distributed file access apparatus18according to an embodiment of this application. The distributed file access apparatus18is applied to a first electronic device, and the first electronic device is in communication connection to a second electronic device. As shown inFIG.18, the distributed file access apparatus18includes a receiving module180, a reading module181, an in-device modification module182, and a cross-device modification module183.

The receiving module180is configured to receive a read instruction for a first file. The reading module181is configured to: read a file modification type and a file modification tag of the first file that are locally stored in the first electronic device, and read the first file according to the read file modification type and the file modification tag.

The in-device modification module182is configured to: obtain a modification instruction for a second file; in response to the modification instruction for the second file, modify the second file and update a file modification record of the second file; update a file modification type and a file modification tag in metadata of the second file according to the file modification record of the second file; and synchronize the updated metadata of the second file to the second electronic device.

The cross-device modification module183is configured to: obtain a modification instruction for the first file; in response to the modification instruction for the first file, generate file modification information of the first file; and send a file modification request to the second electronic device. The file modification information includes a file modification tag before modification, a file modification tag after modification, modification location information, and a modified part. The file modification request carries the file modification information of the first file.

FIG.19is a schematic diagram of functional modules of a distributed file access apparatus19according to an embodiment of this application. The distributed file access apparatus19is applied to a second electronic device, and the second electronic device is in communication connection to a first electronic device. The distributed file access apparatus19includes a synchronization module191and a modification response module192.

The synchronization module191is configured to synchronize metadata of a first file to the first electronic device.

The modification response module192is configured to: if a modification record obtaining request sent by the first electronic device is received, return the file modification record of the first file to the first electronic device. If a file modification request for the first file that is sent by the first electronic device is received, the modification response module192modifies the first file according to the file modification request.

The modification response module192is further configured to update the file modification record of the first file and the metadata of the first file, and synchronize the updated metadata of the first file to the first electronic device.

FIG.20is a schematic diagram of a structure of an electronic device (a first electronic device or a second electronic device) according to an embodiment of this application. As shown inFIG.20, the electronic device200may include components such as a radio frequency (Radio Frequency, RF) circuit2001, a memory2002, an input unit2003, a display unit2004, a sensor2005, an audio circuit2006, a Wireless Fidelity (wireless fidelity, Wi-Fi) module2007, a processor2008, and a power supply2009. A person skilled in the art may understand that the structure shown inFIG.20does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.

The RF circuit2001may be configured to receive and send signals in an information sending and receiving process or in a call process. Particularly, after receiving downlink information from a base station, the RF circuit2001forwards the downlink information to the processor2008for processing. In addition, the RF circuit2001sends related uplink data to the base station. Generally, the RF circuit2001includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, and the like.

The memory2002may be configured to store a software program and a module. The processor2008runs the software program and the module that are stored in the memory2002, to execute various function applications and data processing of the electronic device. The memory2002may mainly include a program storage area and a data storage area. The program storage area may store an operating system, an application required for at least one function (such as a sound play function and an image play function), and the like. The data storage area may store data created according to use of the electronic device (such as audio data and a phone book), and the like. In addition, the memory2002may include a high-speed random access memory, or may include a non-volatile memory such as at least one magnetic disk storage device, a flash memory device, or another volatile solid-state storage device.

The input unit2003may be configured to: receive input digit or character information and generate key signal input related to user settings and function control of the electronic device. Specifically, the input unit2003may include a touch panel20031and another input device20032. The touch panel20031, also referred to as a touchscreen, may collect a touch operation of a user on or near the touch panel20031(for example, an operation of the user on or near the touch panel20031by using any suitable object or accessory, for example, a finger or a stylus), and drive a corresponding connection apparatus according to a preset program. Optionally, the touch panel20031may include two parts: a touch detection apparatus and a touch controller. The touch detection apparatus detects a touch location of the user, detects a signal along with a touch operation, and transfers the signal to the touch controller. The touch controller receives touch information from the touch detection apparatus, converts the touch information to touch point coordinates, sends the touch point coordinates to the processor2008, and receives and executes a command sent by the processor2008. In addition, the touch panel20031may be implemented by using a plurality of types, such as a resistive type, a capacitive type, an infrared ray type, and a surface acoustic wave type. In addition to the touch panel20031, the input unit2003may further include another input device20032. Specifically, the another input device20032may include, but is not limited to, one or more of a physical keyboard, a functional key (for example, a volume control key or an on/off key), a trackball, a mouse, and a joystick.

The display unit2004may be configured to display information entered by the user, information provided for the user, and various menus of the electronic device. The display unit2004may include a display panel20041. Optionally, the display panel20041may be configured in a form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like. Further, the touch panel20031may cover the display panel20041. After detecting a touch operation on or near the touch panel20031, the touch panel20031transfers the touch operation to the processor2008, to determine a type of a touch event. Subsequently, the processor2008provides corresponding visual output in the display panel20041according to the type of the touch event. Although the touch panel20031and the display panel20041are used as two separate components to implement input and output functions of the electronic device inFIG.20, in some embodiments, the touch panel20031and the display panel20041may be integrated to implement the input and output functions of the electronic device.

The electronic device may further include at least one type of sensor2005, such as a light sensor, a motion sensor, and another sensor. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor may adjust brightness of the display panel20041according to intensity of ambient light. The proximity sensor may turn off the display panel20041and/or backlight when the electronic device moves close to an ear. As a type of motion sensor, an accelerometer sensor may detect values of acceleration in various directions (there are usually three axes), may detect a value and a direction of gravity when the electronic device is stationary, and may be used for an application of recognizing a posture of the electronic device (for example, landscape/portrait mode switching, a related game, or magnetometer posture calibration), a vibration recognition related function (for example, a pedometer or a stroke), and the like. In addition, other sensors may be disposed for the electronic device, such as a gyroscope, a barometer, a hygrometer, a thermometer, and an infrared sensor. Details are not described herein.

The audio circuit2006, a speaker20061, and a microphone20062may provide an audio interface between a user and the electronic device. The audio circuit2006can transmit, to the speaker20061, an electrical signal converted from received audio data, and the speaker20061converts the electrical signal to a sound signal for outputting. In addition, the microphone20062converts a collected sound signal to an electrical signal, and audio circuit2006receives the electrical signal and then converts the electrical signal to audio data. Then the audio data is output to the processor2008for processing and then sent to another electronic device through the RF circuit2001; or the audio data is output to the memory2002for further processing.

Wi-Fi is a short-range wireless transmission technology. The electronic device may help, by using the Wi-Fi module2007, the user receive and send emails, browse a web page, access streaming media, and the like, to provide wireless broadband Internet access for the user. AlthoughFIG.20shows the Wi-Fi module2007, it may be understood that the Wi-Fi module2007is not a mandatory component of the electronic device, and may be omitted according to a requirement without changing the essence of the present invention.

The processor2008is a control center of the electronic device, connects to various parts of the entire electronic device by using various interfaces and lines, and executes various functions and data processing of the electronic device by running or executing a software program and/or a module stored in the memory2002and invoking data stored in the memory2002, so as to perform overall monitoring on the electronic device. Optionally, the processor2008may include one or more processing units. Preferably, an application processor and a modem may be integrated into the processor2008. The application processor mainly processes an operating system, a user interface, an application, and the like. The modem mainly processes wireless communication. It may be understood that the foregoing modem processor may alternatively not be integrated into the processor2008.

The electronic device further includes the power supply2009(for example, a battery) that supplies power to all the components. Optionally, the power supply may be logically connected to the processor2008by using a power management system, so as to implement functions, such as charging management, discharging management, and power consumption management, by using the power management system.

Although not shown in the figure, the electronic device may further include a camera, a Bluetooth module, and the like, and details are not described herein.

The electronic device described inFIG.20may be configured to implement some or all of the procedures in the method embodiments described inFIG.13A-FIG.13BtoFIG.16A-FIG.16Cof this application. For details, refer to related descriptions in the foregoing embodiments described inFIG.13A-FIG.13BtoFIG.16A-FIG.16C. Details are not described herein again. An embodiment further provides a computer storage medium. The computer storage medium stores computer instructions. When the computer instructions are run on an electronic device, the electronic device is enabled to perform the foregoing related method steps, to implement the distributed file access methods in the foregoing embodiments.

This embodiment further provides a computer program product. When the computer program product runs on an electronic device, the electronic device is enabled to perform the foregoing related steps, to implement the distributed file access methods in the foregoing embodiments.

In addition, an embodiment of this application further provides an apparatus. The apparatus may be specifically a chip, a component, or a module. The apparatus may include a processor and a memory that are connected to each other. The memory is configured to store computer executable instructions. When the apparatus runs, the processor may execute the computer executable instructions stored in the memory, so that the chip performs the distributed file access methods in the foregoing method embodiments.

The electronic device, the computer storage medium, the computer program product, or the chip provided in embodiments is configured to perform the corresponding method provided above. Therefore, for beneficial effects that can be achieved, refer to the beneficial effects of the corresponding method provided above. Details are not described herein again.