WO2017177752A1 - File storage method and device - Google Patents

File storage method and device Download PDF

Info

Publication number
WO2017177752A1
WO2017177752A1 PCT/CN2017/073080 CN2017073080W WO2017177752A1 WO 2017177752 A1 WO2017177752 A1 WO 2017177752A1 CN 2017073080 W CN2017073080 W CN 2017073080W WO 2017177752 A1 WO2017177752 A1 WO 2017177752A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
stored
keyword
metadata
storage
Prior art date
Application number
PCT/CN2017/073080
Other languages
French (fr)
Chinese (zh)
Inventor
丁智勇
汪渭春
陈伟
曹力
Original Assignee
杭州海康威视数字技术股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 杭州海康威视数字技术股份有限公司 filed Critical 杭州海康威视数字技术股份有限公司
Publication of WO2017177752A1 publication Critical patent/WO2017177752A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/907Retrieval characterised by using metadata, e.g. metadata not derived from the content or metadata generated manually
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/164File meta data generation

Definitions

  • the present application relates to the field of data processing, and in particular, to a file storage method and apparatus.
  • the metadata of the file is generally stored in a metabase of the storage terminal, and the file itself is stored in another location of the storage terminal.
  • the storage terminal determines the storage location of the file according to the metadata stored in the metadata database, thereby obtaining the file.
  • the metadata stored in the metabase is lost, even if the file data corresponding to the lost metadata is read, it cannot be determined that the file data read belongs to those files, thereby causing file loss.
  • the embodiment of the present application discloses a file storage method and device, which ensures metadata recovery and avoids file loss.
  • the embodiment of the present application discloses a file storage method, which is applied to a storage terminal, and the method includes:
  • the first file identifier, the data volume, and the to-be-stored file are stored in the value of the target key according to the preset storage format, including:
  • the first keyword is a keyword that is identified by the file
  • the file identifier length is a number of bytes occupied by the first file identifier.
  • the second keyword is a keyword for the file.
  • the method further includes:
  • the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
  • the updating the preset metadata database according to the first keyword and the second keyword stored in values of all the keys includes:
  • the obtaining, according to the second file identifier, the target data segment that includes the second file identifier from the values of all the keys including:
  • the data segment is a target data segment, wherein the first keyword W2 is: the second of the values of the key K a first keyword that is identified by the file and that is closest to the second file identifier;
  • the obtaining the metadata to be stored when the file to be stored is stored according to the preset storage format according to the target key includes:
  • the metadata to be stored of the file to be stored is determined according to the calculated offset.
  • the embodiment of the present application further discloses a file storage device, which is applied to a storage terminal, and the device includes: a storage request receiving module, an information determining module, a metadata obtaining module, and a data storage module;
  • the storage request receiving module is configured to receive a storage request for a file to be stored
  • the information determining module is configured to obtain a first file identifier of the file to be stored and a data amount of the file to be stored, and determine a target key for storing the file to be stored;
  • the metadata obtaining module is configured to obtain, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format
  • the data storage module is configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format, and store the
  • the storage metadata is stored in a preset metabase.
  • the data storage module includes:
  • a file storage submodule configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format
  • a metadata storage submodule configured to store the to-be-stored metadata into a preset metadata database
  • the file storage submodule includes: a file identifier storage unit and a file storage unit;
  • the file identifier storage unit is configured to: the first keyword, the file identifier length, and the first file identifier according to a first keyword, a file identifier length, and an order of the first file identifier And storing, in the value of the target key, where the first keyword is a keyword for a file identifier, where the file identifier length is a number of bytes occupied by the first file identifier;
  • the file storage unit configured to store the second keyword, the data amount, and the file to be stored to the target according to a second keyword, the data amount, and an order of the file to be stored
  • the device further includes: a metabase update module, configured to:
  • the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
  • the metabase update module includes: a file identifier obtaining submodule, a target data segment determining submodule, and a metabase updating submodule;
  • the file identifier obtaining submodule is configured to obtain a second file identifier of the file with the metadata lost in the case that the metadata of the preset metabase is lost;
  • the target data segment determining submodule is configured to obtain, according to the second file identifier, a target data segment that includes the second file identifier from values of all keys;
  • the meta-database update sub-module is configured to update the preset meta-database according to the second file identifier and the data amount stored in the target data segment.
  • the target data segment determining submodule includes: a key obtaining unit, a keyword determining unit, a first target data segment determining unit, and a second target data segment determining unit;
  • the key obtaining unit configured to obtain, according to the second file identifier, a key K that includes the second file identifier
  • the keyword determining unit is configured to determine whether the first keyword is stored after the second file identifier in the value of the key K, and if yes, triggering the first target data segment determining unit, if No, the second target data segment determining unit is triggered;
  • the first target data segment determining unit is configured to obtain a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determine the first keyword W2 and Place
  • the data segment between the first keywords W1 is a target data segment, wherein the first keyword W2 is: the value of the key K is before the second file identifier and is closest to the second file identifier.
  • the second target data segment determining unit is configured to determine a data segment between the first keyword W2 and a storage location at the end of the value of the key K as a target data segment.
  • the metadata obtaining module includes: a keyword obtaining submodule, an offset calculating submodule, and a metadata determining submodule;
  • the keyword obtaining submodule configured to obtain a first keyword and a second keyword stored in a value of the target key
  • the offset calculation submodule is configured to calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in a value of the target key;
  • the metadata determining submodule is configured to determine metadata to be stored of the file to be stored according to the calculated offset.
  • an embodiment of the present application further discloses a storage terminal, where the storage terminal includes: a casing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is disposed in the casing Inside the space, the processor and the memory are disposed on the circuit board; the power circuit is configured to supply power to each circuit or device of the storage terminal; and the memory is used to store executable program code
  • the processor executes the following steps by running executable program code stored in the memory:
  • an embodiment of the present application further discloses an executable program code, where the executable program code is configured to perform the following steps at runtime:
  • the embodiment of the present application further discloses a storage medium for storing executable program code, and the executable program code is executed to perform the following steps:
  • the storage terminal after receiving the storage request for the file to be stored, the storage terminal obtains the first file identifier of the file to be stored and the data amount of the file to be stored, and determines to store the file to be stored.
  • the target key is obtained according to the target key, and the metadata to be stored when the file to be stored is stored according to the preset storage format is obtained, and the first file identifier, the data volume, and the file to be stored are stored in the target key according to the preset storage format. And storing the to-be-stored metadata in a preset metabase.
  • the first file identifier, the data amount, and the stored text of the stored file in the value of the key may be determined according to a preset storage format.
  • the offset of the value in the key, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding Loss of documents.
  • FIG. 1 is a schematic flowchart diagram of a file storage method according to an embodiment of the present application
  • FIG. 2 is a schematic structural diagram of a TLV storage format
  • FIG. 3 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure.
  • FIG. 4 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure.
  • FIG. 5 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure.
  • FIG. 6 is a schematic diagram of a file storage arrangement according to an embodiment of the present application.
  • FIG. 7 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure.
  • FIG. 8 is a schematic structural diagram of a file storage device according to an embodiment of the present disclosure.
  • FIG. 9 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure.
  • FIG. 10 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure.
  • FIG. 11 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure.
  • FIG. 12 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure.
  • FIG. 1 is a schematic flowchart of a file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal, and the method may include the following steps:
  • S101 Receive a storage request for a file to be stored
  • the storage request includes a file to be stored, and may further include an identifier of the file to be stored, so that the storage terminal can quickly obtain the identifier of the file to be stored, and then store the metadata of the file to be stored; or, the storage request may also be
  • the storage terminal does not include the identifier of the file to be stored, and the storage terminal can parse the identifier of the file to be stored in the file to be stored, so that the storage request is simpler and clearer.
  • S102 Obtain a first file identifier of the file to be stored and a data amount of the file to be stored, and determine a target key for storing the file to be stored;
  • the first file identifier and the data amount of the file to be stored are part of the metadata of the file to be stored, and may be directly obtained when the storage request is obtained, and therefore, the storage is to be stored. Before the file, the first file identifier and the amount of data of the file to be stored are obtained first.
  • the massive data storage with high reliability and scalability is a huge challenge for the current storage terminal, and the traditional database is often difficult to meet the requirement. In this case, the relationship is used. Databases will make storing and reading data inefficient, and scaling databases will be a big problem. In such cases, using key storage would be a good choice. Key storage has the following advantages:
  • the key consists of the name Key and the value Value, and a Key corresponds to a Value.
  • the metadata of the file to be stored generally includes metadata information such as an identifier of the file to be stored in the target key, an amount of data, and an offset from a start storage location of the target key.
  • S103 can be implemented by the following process:
  • the storage location of the file to be stored in the target key may be determined according to the storage format. At this time, it may be determined that the file to be stored is stored relative to the target key.
  • the offset of the location such that the metadata of the file to be stored, that is, the metadata to be stored, can be obtained by combining the obtained first file identifier, the amount of data, the offset, and the name of the target key.
  • the preset storage format may be a format of TLV (TAG_LENGTH_VALUE, mark_length_value), as shown in FIG. 2, and FIG. 2 is a schematic structural diagram of a TLV storage format. For the sake of simplicity.
  • S104 Store the first file identifier of the file to be stored, the data volume of the file to be stored, and the file to be stored in the value of the target key according to the preset storage format, and store the metadata to be stored in the preset metabase. in.
  • the preset metabase is used to store metadata of the file.
  • the storage terminal may store a plurality of files having a small capacity relative to the value of the key, such as: the value of the key has a capacity of 1 Mbytes, and the size of the file to be stored is 100 Kbytes.
  • the value of a key is Storing only one file in it will easily cause a waste of storage space, so you can consider storing multiple complete files in the value of one key.
  • the storage device obtains the first file identifier of the file to be stored, the data amount of the file to be stored, and the file to be stored, and stores the value in the target key according to a preset storage format, so that If the meta-database has metadata loss, the data belonging to the same file may be determined in the value of the key according to the storage format, and according to the storage format, the obtained data is obtained.
  • the metadata information such as the file identifier and the data amount of the file is stored, and the metadata stored in the metadata database is restored.
  • metadata information such as the offset amount in the value of the target key when the data to be stored is stored according to the preset storage format can be obtained, and integrated.
  • the data identifier of the file to be stored may be determined by the first file identifier and the data volume of the file to be stored, and the metadata to be stored is stored in a preset metadata database. In this way, when data access is performed, the storage terminal can perform data access according to the metadata in the metadata database.
  • the storage terminal after successfully storing the file to be stored, stores the metadata of the file to be stored, thereby ensuring the accuracy of the metadata in the metadata database, and avoiding unsuccessful storage to be stored.
  • the file stores the metadata of the file to be stored, and the storage terminal cannot correctly read the metadata stored in the metadata database, and the storage terminal library crashes.
  • step of storing the file to be stored may be performed simultaneously with the step of storing the metadata to be stored, or may be performed after storing the metadata to be stored before S102, or may be performed after storing the metadata to be stored, this application This is not limited.
  • the storage terminal after receiving the storage request for the file to be stored, the storage terminal obtains the first file identifier of the file to be stored and the data amount of the file to be stored, and determines a target key for storing the file to be stored. According to the target key, the metadata to be stored when the file to be stored is stored according to the preset storage format is obtained, and the first file identifier, the data volume, and the file to be stored are stored in the target key according to the preset storage format, and The metadata to be stored is stored in a preset metabase.
  • the first file identifier, the data amount, and the amount of the stored file in the value of the key can be determined according to a preset storage format.
  • the offset of the stored file in the value of the key, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata. Avoid the loss of files.
  • FIG. 3 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal.
  • step S104 may include the following steps:
  • the first keyword is a keyword for the file identifier
  • the file identifier length is the number of bytes occupied by the first file identifier
  • the TAG may be used to store the first keyword
  • the first keyword may be TAG_FILE_NAME, and other characters may be used to represent the first keyword, which is not limited in this embodiment of the present application.
  • S1042 Store the second keyword, the data volume, and the file to be stored in the value of the target key according to the second keyword, the data volume of the file to be stored, and the order of the file to be stored;
  • the second keyword is a keyword for the file.
  • the TAG may also be used to store the second keyword
  • the second keyword may be TAG_FILE_DATA
  • the other keywords may be used to represent the second keyword, which is not limited in this embodiment of the present application.
  • S1043 Store the metadata to be stored into a preset metabase.
  • the storage terminal stores the first keyword, the file identifier length, and the first file identifier of the file to be stored according to the first keyword, the file identifier length, and the first file identifier of the file to be stored.
  • the metadata is stored in a preset metabase.
  • FIG. 4 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal, and the method may include the following steps:
  • each time the metadata database is updated a first check value is obtained, and a second check value may be obtained again before the next time the metadata is stored, when the first check is performed.
  • the check value can be obtained according to a CRC (Cyclic Redundancy Check) check algorithm or other check algorithm.
  • the identifier and data of the stored file in the value of the key may be obtained according to the first keyword and the second keyword stored in the values of all the keys.
  • the amount of metadata information, and then the metadata database is updated according to the obtained metadata information, which ensures the recovery of the metadata in the metadata database and avoids file loss.
  • step S105 may occur before any of steps S101, S102, S103, and S104, and may also occur after any of steps S101, S102, S103, and S104, and may also be followed by step S101. Any of the steps S102, S103, and S104 occur at the same time, which is not limited by the examples in the present application.
  • the storage terminal obtains the identifier of the stored file and the stored file according to the preset storage format when the metadata is lost from the preset key database.
  • the amount of data, according to the first keyword and the second keyword stored in the values of all the keys, obtaining the offset of the stored file in the value of the key, and updating the preset metabase according to the obtained information, can effectively Restore metadata in the metabase to avoid file loss.
  • FIG. 5 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal.
  • step S105 may include the following steps:
  • S1051 Obtain a second file identifier of the file in which the metadata is lost in the case that the metadata of the preset metabase is lost.
  • the metadata lost in the metabase may be only a small part. In this case, if all the metadata stored in the metabase is updated, the workload of the storage terminal will be increased, and the metadata is The recovery speed is slow. If only the missing metadata in the metabase is updated, the workload of the storage terminal will be greatly reduced, and the metadata recovery speed will be fast.
  • the metadata of the file in the metadata database may be considered to be lost, thereby obtaining the second file identifier of the file.
  • the second file identification of the file can be obtained from a read request when the file is read.
  • S1052 Obtain a target data segment that includes the second file identifier from the values of all the keys according to the second file identifier of the lost file;
  • the obtaining, according to the second file identifier of the lost file, the target data segment that includes the second identifier from the file stored by the value of all the keys may include:
  • the first keyword is read in the value of all the keys, and then the corresponding file identifier length is determined according to the first keyword, and then the file identifier is determined according to the file identifier length, and the second file is obtained from the determined file identifier.
  • the same file identifier and the key corresponding to the file identifier are identified, and the key obtained here is the key containing the second file identifier.
  • the above-mentioned key K may be a plurality of keys, or may be only one key.
  • the above-mentioned key K is a plurality of keys, it is explained that one file is stored in a plurality of keys.
  • step S2 determining whether the first key is stored in the value of the key K after the second file identification, if yes, proceeding to step S3, if not, executing step S4;
  • the identifier of the file, the amount of data, and the order of the file itself may be: first store the identifier of the file, then store the data amount of the file and the file itself, and the first keyword is a data segment storing a file. Starting storage location.
  • FIG. 6 is a schematic diagram of a file storage arrangement according to an embodiment of the present application. As can be seen from FIG. 6, two files are stored in the value of the key named Key1, and file2 is stored after file1, and no file is stored after file2.
  • the first keyword A (TAG_FILE_NAME) corresponding to file1 and
  • the space between the first key B (TAG_FILE_NAME) corresponding to file2 is the data segment storing file1
  • the first key corresponding to file2 The space between the word B and the end of the value of the key named Key1 is the data segment in which file2 is stored.
  • the first keyword W2 is: a first keyword in the value of the key K before the second file identifier and closest to the second file identifier;
  • the first keyword is a data segment starting storage location for storing a file
  • a file identifier corresponds to a first keyword
  • a space between two adjacent first keywords is a data segment
  • the file The identifier corresponding to the first keyword is: the first keyword before the file identifier and closest to the file identifier.
  • the file identifier length may be obtained according to the first keyword stored in the target data segment, and then the file identifier is determined according to the file identifier length; and the second identifier may be stored according to the target data segment.
  • the keyword gets the amount of data for the file and gets the file.
  • the file identifier and the data amount of the file are metadata, so that the metadata in the metadata database can be restored according to the metadata obtained in the value of the key.
  • the first keyword W2 corresponding to the file identifier and the last storage location of the value of the key K where the file identifier is located may be determined.
  • the data segment between them is the target data segment.
  • S1053 Update the preset metabase according to the second file identifier of the lost file stored in the target data segment and the data amount of the lost file.
  • the storage terminal only needs to obtain the second file identifier of the file whose metadata is lost, and obtain the second identifier from the file stored in the value of all the keys according to the second file identifier of the lost file.
  • the target data segment is finally updated according to the second file identifier of the lost file stored in the target data segment and the data amount of the lost file, and the default metadata database is updated, which is reduced.
  • the workload of the storage terminal improves the efficiency of the metadata database update.
  • FIG. 7 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal.
  • step S103 may include the following steps:
  • S1031 Obtain a first keyword and a second keyword stored in a value of the target key
  • the number of bytes occupied by the TAG and LENGTH in the file stored in the TLV format is a fixed size, so only the first keyword and the second keyword stored in the value of the target key are required (also That is, TAG), it is determined according to the number of the first keyword and the second keyword and the file identifier length corresponding to the first keyword and the data amount corresponding to the second keyword (ie, LENGTH), to determine the to-be-stored The offset of the file in the value of the target key.
  • S1032 Calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in the value of the target key;
  • the number of bytes occupied by TAG and LENGTH is 4Kbytes
  • the identifier length of file1 is 10Kbytes
  • the data amount of file1 is 100Kbytes
  • the identification length of file2 is 12Kbytes
  • the data volume of file2 is 200Kbytes
  • file1 and The storage order of file2 is as follows: first store file1 and then store file2.
  • the metadata of file1 and file2 obtained at this time are shown in Table 1.
  • the offset of file1 and file2 in the value of the key is calculated by storing the file1 in the value of the target key named Key1, the value of the target key is empty, and at this time, it can be determined
  • the starting storage location of the value of the target key has a first keyword and a second keyword between the file headers of the file1 file (this is the first keyword and the default storage format carried by the TLV itself)
  • the obtained second keyword that is, there are 2 TAGs, corresponding to 2 LENGTH, from LENGTH, the file length of file1 can be 10Kbytes, and the data amount of file1 is 100Kbytes. Therefore, the value of file1 at Key1 can be determined.
  • the first keyword carried and the obtained second keyword that is, there are 4 TAGs, corresponding to 4 LENGTH, and the file length of file1 is 10Kbytes, the data amount of file1 is 100Kbytes, and file2 is obtained from LENGTH.
  • the identifier length is 12Kbytes, and the data volume of file2 is 200Kbytes.
  • S1033 Determine, according to the calculated offset, the metadata to be stored of the file to be stored;
  • the offset of the file in the value of the key is also part of the metadata of the file, so that the storage terminal quickly obtains the storage location of the file according to the offset.
  • the metadata of the file to be stored is determined in combination with the first file identifier and the data amount of the file to be stored.
  • the storage terminal obtains the first keyword and the second keyword stored in the value of the target key, and calculates the file to be stored in the target key according to the obtained first keyword and the obtained second keyword.
  • the offset in the value and based on the calculated offset, determine the metadata to be stored of the file to be stored.
  • the offset of the file is calculated according to the first keyword and the second keyword stored in the value of the target key, thereby determining the metadata to be stored of the file to be stored, without having to count the storage location and target of the file to be stored one by one.
  • the amount of data between the starting storage locations of the values of the keys to determine the offset of the file, the determination of the metadata is faster and more convenient.
  • FIG. 8 is a schematic structural diagram of a file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal, and the device may include: a storage request receiving module 801, an information determining module 802, a metadata obtaining module 803, and data.
  • the storage request receiving module 801 is configured to receive a storage request for a file to be stored
  • the information determining module 802 is configured to obtain a first file identifier of the file to be stored and a file to be stored. The amount of data, and determine the target key for storing the file to be stored;
  • the metadata obtaining module 803 is configured to obtain, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format
  • the data storage module 804 is configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format, and store the to-be-stored
  • the metadata is stored in a preset metabase, wherein a preset metabase is used to store metadata of the file.
  • the storage terminal after receiving the storage request for the file to be stored, the storage terminal obtains the first file identifier of the file to be stored and the data amount of the file to be stored, and determines a target key for storing the file to be stored. According to the target key, the metadata to be stored when the file to be stored is stored according to the preset storage format is obtained, and the first file identifier, the data volume, and the file to be stored are stored in the target key according to the preset storage format, and The metadata to be stored is stored in a preset metabase.
  • the first file identifier, the data amount, and the amount of the stored file in the value of the key can be determined according to a preset storage format.
  • the offset of the stored file in the value of the key, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata. Avoid the loss of documents.
  • FIG. 9 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal.
  • the data storage module 804 may include: a file identifier storage submodule 8041 and a metadata storage device. Module 8042;
  • a file storage sub-module 8041 configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format
  • a metadata storage sub-module 8042 configured to store the to-be-stored metadata into a preset metadata database
  • the file storage submodule 8041 includes: a file identifier storage unit 8041a and a file storage unit 8041b;
  • the file identifier storage unit 8041a is configured to store the first keyword, the file identifier length, and the first file identifier to the target key according to the first keyword, the file identifier length, and the first file identifier.
  • the value of the first keyword is a keyword for the file identifier, and the file identifier length is the number of bytes occupied by the first file identifier;
  • the file storage unit 8041b is configured to store the second keyword, the data amount, and the file to be stored in the value of the target key according to the second keyword, the data amount, and the order of the file to be stored, where the second keyword is for The keyword of the file.
  • the storage terminal stores the first keyword, the file identifier length, and the first file identifier of the file to be stored according to the first keyword, the file identifier length, and the first file identifier of the file to be stored.
  • the storage terminal stores the first keyword, the file identifier length, and the first file identifier of the file to be stored according to the first keyword, the file identifier length, and the first file identifier of the file to be stored.
  • the metadata is stored in a preset metabase.
  • FIG. 10 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal, and the device may further include: a metabase update module 805;
  • metabase update module 805 is configured to:
  • the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
  • the storage terminal obtains the identifier of the stored file and the stored file according to the preset storage format when the data is read from each key in the case that the metadata is lost in the preset metabase.
  • the amount of data, according to the first keyword and the second keyword stored in the values of all the keys, determine the offset of each stored file in the value of each key, and update the preset metabase according to the obtained information, which can be effective Restore metadata in the metabase to avoid file loss.
  • FIG. 11 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal.
  • the meta-database update module 805 may include: a file identifier obtaining sub-module 8051 and a target data segment. Determining submodule 8052 and metabase update submodule 8053;
  • the file identifier obtaining sub-module 8051 is configured to obtain a second file identifier of the file in which the metadata is lost if the metadata of the preset meta-database is lost.
  • a target data segment determining sub-module 8052 configured to obtain, according to the second file identifier, a target data segment that includes the second file identifier from values of all the keys;
  • the metabase update submodule 8053 is configured to update the preset metabase according to the second file identifier and the amount of data stored in the target data segment.
  • the target data segment determining submodule 8052 may include: a key obtaining unit, a keyword determining unit, a first target data segment determining unit, and a second target data segment determining unit (not shown in FIG. 11 show);
  • the key obtaining unit is configured to obtain, according to the second file identifier, a key K that includes the second file identifier;
  • a keyword determining unit configured to determine whether a first keyword is stored after the second file identifier in the value of the key K, and if yes, triggering the first target data segment determining unit, and if not, triggering the second target data Segment determination unit;
  • a first target data segment determining unit configured to obtain a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determine data between the first keyword W2 and the first keyword W1
  • the segment is a target data segment, where the first keyword W2 is: a first keyword in the value of the key K before the second file identifier and closest to the second file identifier;
  • the second target data segment determining unit is configured to determine the data segment between the first keyword W2 and the storage location at the end of the value of the key K as the target data segment.
  • the storage terminal only needs to obtain the second file identifier of the file whose metadata is lost, and obtain the second identifier from the file stored in the value of all the keys according to the second file identifier of the lost file.
  • the target data segment finally updates the preset metabase according to the second file identifier of the lost file stored in the target data segment and the data amount of the lost file, thereby reducing the workload of the storage terminal and improving the metabase. Updated efficiency.
  • FIG. 12 is a schematic structural diagram of another file storage apparatus according to an embodiment of the present disclosure, which is applied to a storage terminal.
  • the metadata obtaining module 803 may include: a keyword obtaining submodule 8031, and an offset. a quantity calculation sub-module 8032, a metadata determination sub-module 8033;
  • the keyword obtaining submodule 8031 is configured to obtain the first stored in the value of the target key. Keyword and second keyword;
  • the offset calculation sub-module 8032 is configured to calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in the value of the target key;
  • the metadata determining sub-module 8033 is configured to determine metadata to be stored of the file to be stored according to the calculated offset.
  • the storage terminal obtains the first keyword and the second keyword stored in the value of the target key, and calculates the file to be stored in the target key according to the obtained first keyword and the obtained second keyword.
  • the offset in the value and based on the calculated offset, determine the metadata to be stored of the file to be stored.
  • the offset of the file is calculated according to the first keyword and the second keyword stored in the value of the target key, thereby determining the metadata to be stored of the file to be stored, without having to count the storage location and target of the file to be stored one by one.
  • the amount of data between the starting storage locations of the values of the keys to determine the offset of the file, the determination of the metadata is faster and more convenient.
  • the embodiment of the present application provides a storage terminal, including: a casing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is disposed inside a space enclosed by the casing, The processor and the memory are disposed on the circuit board; the power supply circuit is configured to supply power to each circuit or device of the storage terminal; the memory is configured to store executable program code; Executing executable program code stored in the memory to perform the following steps:
  • the storage terminal After receiving the storage request for the file to be stored, the storage terminal Obtaining a first file identifier of the file to be stored and a data volume of the file to be stored, and determining a target key for storing the file to be stored, and obtaining metadata to be stored when the file to be stored is stored according to a preset storage format according to the target key And storing the first file identifier, the data volume, and the file to be stored in the target key according to the preset storage format, and storing the to-be-stored metadata in a preset metabase.
  • the metadata loss of the metadata database the first file identifier, the data amount of the stored file in the value of the key, and the stored file in the value of the key may be determined according to a preset storage format.
  • the offset combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding file loss.
  • the storage terminal exists in various forms including, but not limited to:
  • Mobile communication devices These devices are characterized by mobile communication functions and are mainly aimed at providing voice and data communication.
  • Such terminals include: smart phones (such as iPhone), multimedia phones, functional phones, and low-end phones.
  • Ultra-mobile personal computer equipment This type of equipment belongs to the category of personal computers, has computing and processing functions, and generally has mobile Internet access.
  • Such terminals include: PDAs, MIDs, and UMPC devices, such as the iPad.
  • Portable entertainment devices These devices can display and play multimedia content. Such devices include: audio, video players (such as iPod), handheld game consoles, e-books, and smart toys and portable car navigation devices.
  • the server consists of a processor, a hard disk, a memory, a system bus, etc.
  • the server is similar to a general-purpose computer architecture, but because of the need to provide highly reliable services, processing power and stability High reliability in terms of reliability, security, scalability, and manageability.
  • Applying the storage request for the file to be stored obtaining the first file identifier of the file to be stored and the data amount of the file to be stored, and determining a target key for storing the file to be stored, according to the target key.
  • obtaining the to-be-stored metadata when the file to be stored is stored according to the preset storage format, storing the first file identifier, the data volume, and the file to be stored in the target key according to the preset storage format, and storing the to-be-stored element
  • the data is stored in a preset metabase.
  • the metadata loss of the metadata database the first file identifier, the data amount of the stored file in the value of the key, and the stored file in the value of the key may be determined according to a preset storage format.
  • the offset combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding file loss.
  • Embodiments of the present application provide a storage medium for storing executable program code, the executable program code being executed to perform the following steps:
  • the application After the storage request for the file to be stored is received, the application is obtained. And storing the first file identifier of the file and the data volume of the file to be stored, and determining a target key for storing the file to be stored, and obtaining the metadata to be stored when the file to be stored is stored according to the preset storage format according to the target key, according to the target key
  • the preset storage format stores the first file identifier, the data volume, and the file to be stored in the target key, and stores the to-be-stored metadata in a preset metabase.
  • the metadata loss of the metadata database the first file identifier, the data amount of the stored file in the value of the key, and the stored file in the value of the key may be determined according to a preset storage format.
  • the offset combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding file loss.
  • the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Library & Information Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A file storage method and device, the method comprising: receiving a storage request for a file to be stored (S101); obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key used for storing the file to be stored (S102); according to the target key, obtaining metadata to be stored when the file to be stored is stored according to a preset storage format (S103); according to the preset storage format, storing the first file identifier, the data amount and the file to be stored in a value of the target key, and storing the metadata to be stored in a preset metadata library (S104). The method and device effectively ensure metadata recovery, thereby preventing file loss.

Description

一种文件存储方法及装置File storage method and device
本申请要求于2016年4月14日提交中国专利局、申请号为201610230618.6发明名称为“一种文件存储方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. 20161023061, the entire disclosure of which is incorporated herein in
技术领域Technical field
本申请涉及数据处理领域,特别涉及一种文件存储方法及装置。The present application relates to the field of data processing, and in particular, to a file storage method and apparatus.
背景技术Background technique
目前,在存储文件时,需要存储文件的元数据和文件本身,现有技术中,一般将文件的元数据存储在存储终端的元数据库中,而将文件本身存储在存储终端的其他位置,这样存在数据访问需求时,存储终端根据元数据库中存储的元数据确定文件的存储位置,进而获得文件。此时若元数据库中存储的元数据丢失了,那么即使读取到了丢失的元数据对应的文件数据,也不能确定所读取到的文件数据是属于那些文件的,从而造成文件损失。Currently, when storing a file, it is necessary to store the metadata of the file and the file itself. In the prior art, the metadata of the file is generally stored in a metabase of the storage terminal, and the file itself is stored in another location of the storage terminal. When there is a data access requirement, the storage terminal determines the storage location of the file according to the metadata stored in the metadata database, thereby obtaining the file. At this time, if the metadata stored in the metabase is lost, even if the file data corresponding to the lost metadata is read, it cannot be determined that the file data read belongs to those files, thereby causing file loss.
发明内容Summary of the invention
本申请实施例公开了一种文件存储方法及装置,保证元数据的恢复,避免文件的损失。The embodiment of the present application discloses a file storage method and device, which ensures metadata recovery and avoids file loss.
为达到上述目的,本申请实施例公开了一种文件存储方法,应用于存储终端,所述方法包括:To achieve the above objective, the embodiment of the present application discloses a file storage method, which is applied to a storage terminal, and the method includes:
接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。 And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
可选的,所述按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,包括:Optionally, the first file identifier, the data volume, and the to-be-stored file are stored in the value of the target key according to the preset storage format, including:
按照第一关键字、文件标识长度和所述第一文件标识的顺序,将所述第一关键字、所述文件标识长度和所述第一文件标识存储至所述目标键的值中,其中,所述第一关键字为针对文件标识的关键字,所述文件标识长度为所述第一文件标识占用的字节数;And storing, in the order of the first keyword, the file identifier length, and the first file identifier, the first keyword, the file identifier length, and the first file identifier into a value of the target key, where The first keyword is a keyword that is identified by the file, and the file identifier length is a number of bytes occupied by the first file identifier.
按照第二关键字、所述数据量和所述待存储文件的顺序,将所述第二关键字、所述数据量和所述待存储文件存储至所述目标键的值中,其中,所述第二关键字为针对文件的关键字。And storing, in the order of the second keyword, the data amount, and the file to be stored, the second keyword, the data amount, and the file to be stored in a value of the target key, where The second keyword is a keyword for the file.
可选的,所述方法还包括:Optionally, the method further includes:
在所述预设的元数据库存在元数据丢失的情况下,根据所有键的值中存储的所述第一关键字和所述第二关键字,更新所述预设的元数据库。In the case that the preset metabase has metadata loss, the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
可选的,所述根据所有键的值中存储的所述第一关键字和所述第二关键字,更新所述预设的元数据库,包括:Optionally, the updating the preset metadata database according to the first keyword and the second keyword stored in values of all the keys includes:
获得元数据丢失的文件的第二文件标识;Obtaining a second file identifier of the file in which the metadata is lost;
根据所述第二文件标识,从所有键的值中获得包含所述第二文件标识的目标数据段;Obtaining, according to the second file identifier, a target data segment that includes the second file identifier from values of all keys;
根据所述目标数据段中存储的所述第二文件标识和所述数据量,更新所述预设的元数据库。Updating the preset metabase according to the second file identifier and the data amount stored in the target data segment.
可选的,所述根据所述第二文件标识,从所有键的值中获得包含所述第二文件标识的目标数据段,包括:Optionally, the obtaining, according to the second file identifier, the target data segment that includes the second file identifier from the values of all the keys, including:
根据所述第二文件标识,获得包含所述第二文件标识的键K;Obtaining, according to the second file identifier, a key K including the identifier of the second file;
判断所述键K的值中所述第二文件标识之后是否存储有第一关键字;Determining whether the first keyword is stored after the second file identifier in the value of the key K;
若为是,则获得所述键K的值中所述第二文件标识之后与所述第二文件标识最近的第一关键字W1,并确定第一关键字W2和所述第一关键字W1间的数据段为目标数据段,其中,所述第一关键字W2为:所述键K的值中所述第二 文件标识之前且与所述第二文件标识最近的第一关键字;If yes, obtaining a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determining the first keyword W2 and the first keyword W1 The data segment is a target data segment, wherein the first keyword W2 is: the second of the values of the key K a first keyword that is identified by the file and that is closest to the second file identifier;
若为否,则确定所述第一关键字W2与所述键K的值末尾存储位置间的数据段为目标数据段。If not, it is determined that the data segment between the first keyword W2 and the storage location at the end of the value of the key K is the target data segment.
可选的,所述根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据,包括:Optionally, the obtaining the metadata to be stored when the file to be stored is stored according to the preset storage format according to the target key includes:
获得所述目标键的值中存储的第一关键字和第二关键字;Obtaining a first keyword and a second keyword stored in a value of the target key;
根据所获得第一关键字和所获得第二关键字,计算所述待存储文件在所述目标键的值中的偏移量;Calculating an offset of the file to be stored in a value of the target key according to the obtained first keyword and the obtained second keyword;
根据计算得到的偏移量,确定所述待存储文件的待存储元数据。The metadata to be stored of the file to be stored is determined according to the calculated offset.
为达到上述目的,本申请实施例还公开了一种文件存储装置,应用于存储终端,所述装置包括:存储请求接收模块、信息确定模块、元数据获得模块和数据存储模块;To achieve the above objective, the embodiment of the present application further discloses a file storage device, which is applied to a storage terminal, and the device includes: a storage request receiving module, an information determining module, a metadata obtaining module, and a data storage module;
其中,所述存储请求接收模块,用于接收针对待存储文件的存储请求;The storage request receiving module is configured to receive a storage request for a file to be stored;
所述信息确定模块,用于获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;The information determining module is configured to obtain a first file identifier of the file to be stored and a data amount of the file to be stored, and determine a target key for storing the file to be stored;
所述元数据获得模块,用于根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;The metadata obtaining module is configured to obtain, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
所述数据存储模块,用于按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。The data storage module is configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format, and store the The storage metadata is stored in a preset metabase.
可选的,所述数据存储模块,包括:Optionally, the data storage module includes:
文件存储子模块,用于按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中;a file storage submodule, configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format;
元数据存储子模块,用于将所述待存储元数据存储至预设的元数据库中;a metadata storage submodule, configured to store the to-be-stored metadata into a preset metadata database;
所述文件存储子模块,包括:文件标识存储单元和文件存储单元; The file storage submodule includes: a file identifier storage unit and a file storage unit;
其中,所述文件标识存储单元,用于按照第一关键字、文件标识长度和所述第一文件标识的顺序,将所述第一关键字、所述文件标识长度和所述第一文件标识存储至所述目标键的值中,其中,所述第一关键字为针对文件标识的关键字,所述文件标识长度为所述第一文件标识占用的字节数;The file identifier storage unit is configured to: the first keyword, the file identifier length, and the first file identifier according to a first keyword, a file identifier length, and an order of the first file identifier And storing, in the value of the target key, where the first keyword is a keyword for a file identifier, where the file identifier length is a number of bytes occupied by the first file identifier;
所述文件存储单元,用于按照第二关键字、所述数据量和所述待存储文件的顺序,将所述第二关键字、所述数据量和所述待存储文件存储至所述目标键的值中,其中,所述第二关键字为针对文件的关键字。The file storage unit, configured to store the second keyword, the data amount, and the file to be stored to the target according to a second keyword, the data amount, and an order of the file to be stored The value of the key, wherein the second keyword is a keyword for a file.
可选的,所述装置还包括:元数据库更新模块,用于:Optionally, the device further includes: a metabase update module, configured to:
在所述预设的元数据库存在元数据丢失的情况下,根据所有键的值中存储的所述第一关键字和所述第二关键字,更新所述预设的元数据库。In the case that the preset metabase has metadata loss, the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
可选的,所述元数据库更新模块,包括:文件标识获得子模块、目标数据段确定子模块和元数据库更新子模块;Optionally, the metabase update module includes: a file identifier obtaining submodule, a target data segment determining submodule, and a metabase updating submodule;
其中,所述文件标识获得子模块,用于在所述预设的元数据库存在元数据丢失的情况下,获得元数据丢失的文件的第二文件标识;The file identifier obtaining submodule is configured to obtain a second file identifier of the file with the metadata lost in the case that the metadata of the preset metabase is lost;
所述目标数据段确定子模块,用于根据所述第二文件标识,从所有键的值中获得包含所述第二文件标识的目标数据段;The target data segment determining submodule is configured to obtain, according to the second file identifier, a target data segment that includes the second file identifier from values of all keys;
所述元数据库更新子模块,用于根据所述目标数据段中存储的所述第二文件标识和所述数据量,更新所述预设的元数据库。The meta-database update sub-module is configured to update the preset meta-database according to the second file identifier and the data amount stored in the target data segment.
可选的,所述目标数据段确定子模块,包括:键获得单元、关键字判断单元、第一目标数据段确定单元和第二目标数据段确定单元;Optionally, the target data segment determining submodule includes: a key obtaining unit, a keyword determining unit, a first target data segment determining unit, and a second target data segment determining unit;
其中,所述键获得单元,用于根据所述第二文件标识,获得包含所述第二文件标识的键K;The key obtaining unit, configured to obtain, according to the second file identifier, a key K that includes the second file identifier;
所述关键字判断单元,用于判断所述键K的值中所述第二文件标识之后是否存储有第一关键字,若为是,则触发所述第一目标数据段确定单元,若为否,则触发所述第二目标数据段确定单元;The keyword determining unit is configured to determine whether the first keyword is stored after the second file identifier in the value of the key K, and if yes, triggering the first target data segment determining unit, if No, the second target data segment determining unit is triggered;
所述第一目标数据段确定单元,用于获得所述键K的值中所述第二文件标识之后与所述第二文件标识最近的第一关键字W1,并确定第一关键字W2和所 述第一关键字W1间的数据段为目标数据段,其中,所述第一关键字W2为:所述键K的值中所述第二文件标识之前且与所述第二文件标识最近的第一关键字;The first target data segment determining unit is configured to obtain a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determine the first keyword W2 and Place The data segment between the first keywords W1 is a target data segment, wherein the first keyword W2 is: the value of the key K is before the second file identifier and is closest to the second file identifier. First keyword;
所述第二目标数据段确定单元,用于确定所述第一关键字W2与所述键K的值末尾存储位置间的数据段为目标数据段。The second target data segment determining unit is configured to determine a data segment between the first keyword W2 and a storage location at the end of the value of the key K as a target data segment.
可选的,所述元数据获得模块,包括:关键字获得子模块、偏移量计算子模块和元数据确定子模块;Optionally, the metadata obtaining module includes: a keyword obtaining submodule, an offset calculating submodule, and a metadata determining submodule;
其中,所述关键字获得子模块,用于获得所述目标键的值中存储的第一关键字和第二关键字;The keyword obtaining submodule, configured to obtain a first keyword and a second keyword stored in a value of the target key;
所述偏移量计算子模块,用于根据所获得第一关键字和所获得第二关键字,计算所述待存储文件在所述目标键的值中的偏移量;The offset calculation submodule is configured to calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in a value of the target key;
所述元数据确定子模块,用于根据计算得到的偏移量,确定所述待存储文件的待存储元数据。The metadata determining submodule is configured to determine metadata to be stored of the file to be stored according to the calculated offset.
为达到上述目的,本申请实施例还公开了一种存储终端,所述存储终端包括:壳体、处理器、存储器、电路板和电源电路,其中,所述电路板安置在所述壳体围成的空间内部,所述处理器和所述存储器设置在所述电路板上;所述电源电路,用于为所述存储终端的各个电路或器件供电;所述存储器用于存储可执行程序代码;所述处理器通过运行所述存储器中存储的可执行程序代码,以执行以下步骤:To achieve the above objective, an embodiment of the present application further discloses a storage terminal, where the storage terminal includes: a casing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is disposed in the casing Inside the space, the processor and the memory are disposed on the circuit board; the power circuit is configured to supply power to each circuit or device of the storage terminal; and the memory is used to store executable program code The processor executes the following steps by running executable program code stored in the memory:
接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。 And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
为达到上述目的,本申请实施例还公开了一种可执行程序代码,所述可执行程序代码用于在运行时执行以下步骤:To achieve the above objective, an embodiment of the present application further discloses an executable program code, where the executable program code is configured to perform the following steps at runtime:
接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
为达到上述目的,本申请实施例还公开了一种存储介质,所述存储介质用于存储可执行程序代码,所述可执行程序代码被运行以执行以下步骤:To achieve the above objective, the embodiment of the present application further discloses a storage medium for storing executable program code, and the executable program code is executed to perform the following steps:
接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
由上可知,在本申请实施例中,存储终端在接收到针对待存储文件的存储请求后,获得待存储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键,根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据,按照预设的存储格式,将第一文件标识、数据量和待存储文件存储至目标键中,并将该待存储元数据存储至预设的元数据库中。这样,在元数据库存在元数据丢失的情况下,就可以根据预设的存储格式确定出键的值中已存储文件的第一文件标识、数据量以及该已存储文 件在该键的值中的偏移量,结合该键的名字,确定出该已存储文件的元数据,进而根据该元数据来恢复元数据库中的元数据,保证了元数据的恢复,避免文件的损失。It can be seen that, in the embodiment of the present application, after receiving the storage request for the file to be stored, the storage terminal obtains the first file identifier of the file to be stored and the data amount of the file to be stored, and determines to store the file to be stored. The target key is obtained according to the target key, and the metadata to be stored when the file to be stored is stored according to the preset storage format is obtained, and the first file identifier, the data volume, and the file to be stored are stored in the target key according to the preset storage format. And storing the to-be-stored metadata in a preset metabase. In this way, in the case that the metadata loss of the metadata database, the first file identifier, the data amount, and the stored text of the stored file in the value of the key may be determined according to a preset storage format. The offset of the value in the key, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding Loss of documents.
附图说明DRAWINGS
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings to be used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description are only It is a certain embodiment of the present application, and other drawings can be obtained according to the drawings without any creative work for those skilled in the art.
图1为本申请实施例提供的一种文件存储方法的流程示意图;FIG. 1 is a schematic flowchart diagram of a file storage method according to an embodiment of the present application;
图2为TLV存储格式的结构示意图;2 is a schematic structural diagram of a TLV storage format;
图3为本申请实施例提供的另一种文件存储方法的流程示意图;FIG. 3 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure;
图4为本申请实施例提供的另一种文件存储方法的流程示意图;FIG. 4 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure;
图5为本申请实施例提供的另一种文件存储方法的流程示意图;FIG. 5 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure;
图6为本申请实施例提供的一种文件存储排布示意图;FIG. 6 is a schematic diagram of a file storage arrangement according to an embodiment of the present application;
图7为本申请实施例提供的另一种文件存储方法的流程示意图;FIG. 7 is a schematic flowchart diagram of another file storage method according to an embodiment of the present disclosure;
图8为本申请实施例提供的一种文件存储装置的结构示意图;FIG. 8 is a schematic structural diagram of a file storage device according to an embodiment of the present disclosure;
图9为本申请实施例提供的另一种文件存储装置的结构示意图;FIG. 9 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure;
图10为本申请实施例提供的另一种文件存储装置的结构示意图;FIG. 10 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure;
图11为本申请实施例提供的另一种文件存储装置的结构示意图;FIG. 11 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure;
图12为本申请实施例提供的另一种文件存储装置的结构示意图。FIG. 12 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。 The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the drawings in the embodiments of the present application. It is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without departing from the inventive scope are the scope of the present application.
下面通过具体实施例,对本申请进行详细说明。The present application will be described in detail below through specific embodiments.
参考图1,图1为本申请实施例提供的一种文件存储方法的流程示意图,应用于存储终端,该方法可以包括如下步骤:Referring to FIG. 1 , FIG. 1 is a schematic flowchart of a file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal, and the method may include the following steps:
S101:接收针对待存储文件的存储请求;S101: Receive a storage request for a file to be stored;
这里,存储请求中包含待存储文件,还可以包含该待存储文件的标识,以便于存储终端快速获得该待存储文件的标识,进而存储该待存储文件的元数据;或者,存储请求中也可以不包含该待存储文件的标识,存储终端可以在待存储文件中解析获得该待存储文件的标识,这样存储请求更为简单明了。Here, the storage request includes a file to be stored, and may further include an identifier of the file to be stored, so that the storage terminal can quickly obtain the identifier of the file to be stored, and then store the metadata of the file to be stored; or, the storage request may also be The storage terminal does not include the identifier of the file to be stored, and the storage terminal can parse the identifier of the file to be stored in the file to be stored, so that the storage request is simpler and clearer.
S102:获得待存储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键;S102: Obtain a first file identifier of the file to be stored and a data amount of the file to be stored, and determine a target key for storing the file to be stored;
在本申请的一个实施例中,第一文件标识和待存储文件的数据量是该待存储文件的元数据的一部分,并且可以在获得存储请求时直接获得这些信息,因此,在存储该待存储文件前,先获得第一文件标识和该待存储文件的数据量。In an embodiment of the present application, the first file identifier and the data amount of the file to be stored are part of the metadata of the file to be stored, and may be directly obtained when the storage request is obtained, and therefore, the storage is to be stored. Before the file, the first file identifier and the amount of data of the file to be stored are obtained first.
在本申请的一个实施例中,具备高可靠性及可扩展性的海量数据存储对当前存储终端来说是一个巨大的挑战,传统的数据库往往很难满足该需求,在这种情况下使用关系型数据库将使得存储和读取数据的效率低下,并且扩展数据库也将成为很大的难题。在这样的情况下,使用键存储将会是一个很好的选择。键存储具有以下优点:In one embodiment of the present application, the massive data storage with high reliability and scalability is a huge challenge for the current storage terminal, and the traditional database is often difficult to meet the requirement. In this case, the relationship is used. Databases will make storing and reading data inefficient, and scaling databases will be a big problem. In such cases, using key storage would be a good choice. Key storage has the following advantages:
1、Availability可用性;1. Availability availability;
2、Scalability可扩展性;2. Scalability scalability;
3、Failover故障恢复;3, Failover failure recovery;
4、Performance高性能。4, Performance high performance.
键由名字Key和值Value组成,一个Key对应一个Value。The key consists of the name Key and the value Value, and a Key corresponds to a Value.
S103:根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据; S103: Obtain metadata to be stored when the file to be stored is stored according to a preset storage format according to the target key.
一般地,待存储文件的元数据一般包括:在该目标键中的待存储文件的标识、数据量和相对于目标键起始存储位置的偏移量等元数据信息。Generally, the metadata of the file to be stored generally includes metadata information such as an identifier of the file to be stored in the target key, an amount of data, and an offset from a start storage location of the target key.
在本申请的一个实施例中,可以通过下述过程实现S103:In one embodiment of the present application, S103 can be implemented by the following process:
由于确定了目标键以及待存储文件的存储格式,从而就可以根据该存储格式确定该待存储文件在该目标键中的存储位置,此时,可以确定该待存储文件相对于目标键起始存储位置的偏移量,这样,结合获得的第一文件标识、数据量、偏移量和该目标键的名字就可以获得该待存储文件的元数据,也就是上述的待存储元数据。Because the target key and the storage format of the file to be stored are determined, the storage location of the file to be stored in the target key may be determined according to the storage format. At this time, it may be determined that the file to be stored is stored relative to the target key. The offset of the location, such that the metadata of the file to be stored, that is, the metadata to be stored, can be obtained by combining the obtained first file identifier, the amount of data, the offset, and the name of the target key.
在本申请的一个实施例中,预设的存储格式可以为TLV(TAG_LENGTH_VALUE,标记_长度_值)的格式,如图2所示,图2为TLV存储格式的结构示意图,这种存储格式更为简洁明了。In an embodiment of the present application, the preset storage format may be a format of TLV (TAG_LENGTH_VALUE, mark_length_value), as shown in FIG. 2, and FIG. 2 is a schematic structural diagram of a TLV storage format. For the sake of simplicity.
S104:按照预设的存储格式,将待存储文件的第一文件标识、待存储文件的数据量和待存储文件存储至目标键的值中,并将待存储元数据存储至预设的元数据库中。S104: Store the first file identifier of the file to be stored, the data volume of the file to be stored, and the file to be stored in the value of the target key according to the preset storage format, and store the metadata to be stored in the preset metabase. in.
其中,预设的元数据库,用于存储文件的元数据。The preset metabase is used to store metadata of the file.
在本申请的一个实施例中,存储终端可能会存储许多相对键的值的容量小的文件,如:键的值的容量为1Mbytes,待存储文件的大小100Kbytes,此时,如果一个键的值中只存储一个文件,将容易造成存储空间的浪费,因此,可以考虑在一个键的值中存储多个完整的文件。In an embodiment of the present application, the storage terminal may store a plurality of files having a small capacity relative to the value of the key, such as: the value of the key has a capacity of 1 Mbytes, and the size of the file to be stored is 100 Kbytes. At this time, if the value of a key is Storing only one file in it will easily cause a waste of storage space, so you can consider storing multiple complete files in the value of one key.
进行文件存储时,存储文件的同时,如果只将文件的元数据存储至元数据库中,即使以键的形式存储文件,不管一个键的值中存储一个完整的文件,还是存储多个完整的文件,一旦元数据库中某一文件的元数据丢失,即便从相应键的值中读取到了元数据丢失的文件的数据,由于缺乏元数据信息,也无法获知读取到的数据是该元数据丢失了的文件的数据。When storing files, if you only store the metadata of the file in the metabase, even if the file is stored as a key, whether a full file is stored in the value of a key, multiple complete files are stored. Once the metadata of a file in the metabase is lost, even if the data of the file whose metadata is lost is read from the value of the corresponding key, due to the lack of metadata information, it is impossible to know that the read data is the metadata lost. The data of the file.
在本申请的一个实施例中,存储终端将获得的待存储文件的第一文件标识、待存储文件的数据量和待存储文件,按照预设的存储格式存储在目标键的值中,这样就算是元数据库存在元数据丢失的情况,也可以根据该存储格式,在键的值中确定出属于同一文件的数据,并且根据该存储格式,获得已 存储文件的文件标识和数据量等元数据信息,进而恢复元数据库中存储的元数据。In an embodiment of the present application, the storage device obtains the first file identifier of the file to be stored, the data amount of the file to be stored, and the file to be stored, and stores the value in the target key according to a preset storage format, so that If the meta-database has metadata loss, the data belonging to the same file may be determined in the value of the key according to the storage format, and according to the storage format, the obtained data is obtained. The metadata information such as the file identifier and the data amount of the file is stored, and the metadata stored in the metadata database is restored.
一般地,存储终端确定了待存储数据要存储至的目标键之后,就可以获得该待存储数据按照预设的存储格式存储时在该目标键的值中的偏移量等元数据信息,综合上述获得的第一文件标识和该待存储文件的数据量,可以确定出该待存储文件的待存储元数据,并将待存储元数据存储至预设的元数据库中。这样,在进行数据访问时,存储终端就可以根据元数据库中的元数据进行数据访问了。Generally, after the storage terminal determines the target key to which the data to be stored is to be stored, metadata information such as the offset amount in the value of the target key when the data to be stored is stored according to the preset storage format can be obtained, and integrated. The data identifier of the file to be stored may be determined by the first file identifier and the data volume of the file to be stored, and the metadata to be stored is stored in a preset metadata database. In this way, when data access is performed, the storage terminal can perform data access according to the metadata in the metadata database.
在本申请的一种实现方式中,存储终端在成功存储了待存储文件后,再存储该待存储文件的元数据,保证了元数据库中的元数据的准确性,避免出现未成功存储待存储文件,却存储了该待存储文件的元数据,进而导致存储终端不能正确读取元数据库中存储的元数据,出现存储终端库崩溃等问题。In an implementation manner of the present application, after successfully storing the file to be stored, the storage terminal stores the metadata of the file to be stored, thereby ensuring the accuracy of the metadata in the metadata database, and avoiding unsuccessful storage to be stored. The file stores the metadata of the file to be stored, and the storage terminal cannot correctly read the metadata stored in the metadata database, and the storage terminal library crashes.
需要说明的是,上述存储待存储文件的步骤可以与存储待存储元数据的步骤同时执行,也可以在存储待存储元数据之前S102之后执行,甚至可以在存储待存储元数据之后执行,本申请并不对此进行限定。It should be noted that the foregoing step of storing the file to be stored may be performed simultaneously with the step of storing the metadata to be stored, or may be performed after storing the metadata to be stored before S102, or may be performed after storing the metadata to be stored, this application This is not limited.
应用图1所示实施例,存储终端在接收到针对待存储文件的存储请求后,获得待存储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键,根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据,按照预设的存储格式,将第一文件标识、数据量和待存储文件存储至目标键中,并将该待存储元数据存储至预设的元数据库中。这样,在元数据库存在元数据丢失的情况下,从一个键中读取数据时,就可以根据预设的存储格式确定出键的值中已存储文件的第一文件标识、数据量以及该已存储文件在该键的值中的偏移量,结合该键的名字,确定出该已存储文件的元数据,进而根据该元数据来恢复元数据库中的元数据,保证了元数据的恢复,避免了文件的损失。Applying the embodiment shown in FIG. 1 , after receiving the storage request for the file to be stored, the storage terminal obtains the first file identifier of the file to be stored and the data amount of the file to be stored, and determines a target key for storing the file to be stored. According to the target key, the metadata to be stored when the file to be stored is stored according to the preset storage format is obtained, and the first file identifier, the data volume, and the file to be stored are stored in the target key according to the preset storage format, and The metadata to be stored is stored in a preset metabase. In this way, in the case that the metadata is lost in the metadata database, when the data is read from a key, the first file identifier, the data amount, and the amount of the stored file in the value of the key can be determined according to a preset storage format. The offset of the stored file in the value of the key, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata. Avoid the loss of files.
参考图3,图3为本申请实施例提供的另一种文件存储方法的流程示意图,应用于存储终端,该方法中,步骤S104可以包括如下步骤:Referring to FIG. 3, FIG. 3 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal. In the method, step S104 may include the following steps:
S1041:按照第一关键字、文件标识长度和待存储文件的第一文件标识的 顺序,将第一关键字、文件标识长度和待存储文件的第一文件标识存储至目标键的值中;S1041: According to the first keyword, the file identifier length, and the first file identifier of the file to be stored Sequence, storing the first keyword, the file identifier length, and the first file identifier of the file to be stored into the value of the target key;
其中,第一关键字为针对文件标识的关键字,文件标识长度为第一文件标识占用的字节数。The first keyword is a keyword for the file identifier, and the file identifier length is the number of bytes occupied by the first file identifier.
在图2中,TAG可以用于存储第一关键字,该第一关键字可以为TAG_FILE_NAME,也可以用其他字符来表示第一关键字,本申请实施例对此不进行限定。按照TLV格式存储了文件后,若存储终端读取到TAG_FILE_NAME,则表示其后LENGTH中存储的为文件标识长度,例如,LENGTH中存储的为4,当读取得到LENGTH中存储的4时,表示其后VALUE占用了4字节数,进而可以在VALUE中读取到占用了4字节数的文件标识。In FIG. 2, the TAG may be used to store the first keyword, and the first keyword may be TAG_FILE_NAME, and other characters may be used to represent the first keyword, which is not limited in this embodiment of the present application. After the file is stored in the TLV format, if the storage terminal reads TAG_FILE_NAME, it indicates that the length of the file identifier stored in LENGTH is 4, for example, 4 stored in LENGTH, and 4 when stored in LENGTH. VALUE then takes up 4 bytes, which in turn can read a file identifier that occupies 4 bytes in VALUE.
S1042:按照第二关键字、待存储文件的数据量和待存储文件的顺序,将第二关键字、数据量和待存储文件存储至目标键的值中;S1042: Store the second keyword, the data volume, and the file to be stored in the value of the target key according to the second keyword, the data volume of the file to be stored, and the order of the file to be stored;
其中,第二关键字为针对文件的关键字。The second keyword is a keyword for the file.
一般地,在图3中,TAG还可以用于存储第二关键字,该第二关键字可以为TAG_FILE_DATA,也可以用其他字符来表示第二关键字,本申请实施例对此不进行限定。按照TLV格式存储了文件后,若存储终端读取到TAG_FILE_DATA,则表示其后LENGTH中存储的为文件的数据量,例如,LENGTH中存储的为200,当读取得到LENGTH中存储的200时,表示其后VALUE占用了200字节数,进而可以在VALUE中读取到占用了200字节数的文件。Generally, in FIG. 3, the TAG may also be used to store the second keyword, and the second keyword may be TAG_FILE_DATA, and the other keywords may be used to represent the second keyword, which is not limited in this embodiment of the present application. After the file is stored in the TLV format, if the storage terminal reads TAG_FILE_DATA, it indicates the amount of data stored in the LENGTH file, for example, 200 stored in LENGTH, and 200 when stored in LENGTH. It means that the VALUE takes up 200 bytes, and then it can read the file that takes up 200 bytes in VALUE.
S1043:将待存储元数据存储至预设的元数据库中。S1043: Store the metadata to be stored into a preset metabase.
应用图3所示实施例,存储终端按照第一关键字、文件标识长度和待存储文件的第一文件标识的顺序,将第一关键字、文件标识长度和待存储文件的第一文件标识存储至目标键的值中,并按照第二关键字、待存储文件的数据量和待存储文件的顺序,将第二关键字、数据量和待存储文件存储至目标键的值中,将待存储元数据存储至预设的元数据库中。这样在元数据库存在元数据丢失的情况下,仍然可以根据按照预设的存储格式存储在键的值中的文件的标识和数据量,确定读取到的数据是属于哪一文件的,有效地避免了文 件的损失。Applying the embodiment shown in FIG. 3, the storage terminal stores the first keyword, the file identifier length, and the first file identifier of the file to be stored according to the first keyword, the file identifier length, and the first file identifier of the file to be stored. Up to the value of the target key, and storing the second keyword, the data amount, and the file to be stored in the value of the target key according to the second keyword, the data amount of the file to be stored, and the order of the file to be stored, to be stored The metadata is stored in a preset metabase. In this way, in the case that the metadata loss of the metadata database, it is still possible to determine which file the read data belongs to according to the identifier and the data amount of the file stored in the value of the key according to the preset storage format, effectively Avoided the text The loss of pieces.
参考图4,图4为本申请实施例提供的另一种文件存储方法的流程示意图,应用于存储终端,该方法可以包括如下步骤:Referring to FIG. 4, FIG. 4 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal, and the method may include the following steps:
S105:在预设的元数据库存在元数据丢失的情况下,根据所有键的值中存储的第一关键字和第二关键字,更新该预设的元数据库。S105: In a case where the metadata of the preset metabase is lost, the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
在本申请的一个实施例中,每次元数据库更新了存储的元数据后,都获得一个第一校验值,在下一次存储元数据之前可以再次获得一个第二校验值,当第一校验值和第二校验值不同时,就可以说,元数据库存在元数据丢失。目前,可以根据CRC(Cyclic Redundancy Check)校验算法或其他校验算法来获得校验值。In an embodiment of the present application, each time the metadata database is updated, a first check value is obtained, and a second check value may be obtained again before the next time the metadata is stored, when the first check is performed. When the value is different from the second check value, it can be said that the metabase has metadata loss. Currently, the check value can be obtained according to a CRC (Cyclic Redundancy Check) check algorithm or other check algorithm.
在本申请的一个实施例中,当确定元数据库存在元数据丢失时,可以根据所有键的值中存储的第一关键字和第二关键字来获得键的值中已存储文件的标识、数据量等元数据信息,进而根据获得的元数据信息,更新元数据库,保证了元数据库中元数据的恢复,避免了文件损失。In an embodiment of the present application, when it is determined that the metabase has metadata loss, the identifier and data of the stored file in the value of the key may be obtained according to the first keyword and the second keyword stored in the values of all the keys. The amount of metadata information, and then the metadata database is updated according to the obtained metadata information, which ensures the recovery of the metadata in the metadata database and avoids file loss.
需要说明的是,步骤S105可以发生在步骤S101、S102、S103和S104中的任一步骤之前,也可以发生在步骤S101、S102、S103和S104中的任一步骤之后,还可以与步骤S101、S102、S103和S104中的任一步骤同时发生,本申请实例对此不进行限定。It should be noted that step S105 may occur before any of steps S101, S102, S103, and S104, and may also occur after any of steps S101, S102, S103, and S104, and may also be followed by step S101. Any of the steps S102, S103, and S104 occur at the same time, which is not limited by the examples in the present application.
应用图4所示实施例,存储终端在预设的元数据库存在元数据丢失的情况下,从各个键中读取数据时,根据预设的存储格式获得已存储文件的标识、已存储文件的数据量,根据所有键的值中存储的第一关键字和第二关键字,获得该已存储文件在该键的值中的偏移量,根据获得信息更新预设的元数据库,能够有效地恢复元数据库中的元数据,避免了文件损失。Applying the embodiment shown in FIG. 4, the storage terminal obtains the identifier of the stored file and the stored file according to the preset storage format when the metadata is lost from the preset key database. The amount of data, according to the first keyword and the second keyword stored in the values of all the keys, obtaining the offset of the stored file in the value of the key, and updating the preset metabase according to the obtained information, can effectively Restore metadata in the metabase to avoid file loss.
参考图5,图5为本申请实施例提供的另一种文件存储方法的流程示意图,应用于存储终端,该方法中,步骤S105可以包括如下步骤:Referring to FIG. 5, FIG. 5 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal. In the method, step S105 may include the following steps:
S1051:在预设的元数据库存在元数据丢失的情况下,获得元数据丢失的文件的第二文件标识; S1051: Obtain a second file identifier of the file in which the metadata is lost in the case that the metadata of the preset metabase is lost.
在本申请的一个实施例中,元数据库中丢失的元数据可能仅仅只是一小部分,此时,若全部更新元数据库中存储的元数据,将会增加存储终端的工作量,并且元数据的恢复速度慢。若只更新元数据库中丢失的元数据,将会大大减少存储终端的工作量,并且元数据的恢复速度快。In one embodiment of the present application, the metadata lost in the metabase may be only a small part. In this case, if all the metadata stored in the metabase is updated, the workload of the storage terminal will be increased, and the metadata is The recovery speed is slow. If only the missing metadata in the metabase is updated, the workload of the storage terminal will be greatly reduced, and the metadata recovery speed will be fast.
一般地,当存储终端针对某一文件进行读取时,不能够读取到,则可以认为该文件在元数据库中的元数据丢失,进而获得该文件的第二文件标识。在本申请的一种实现方式中,该文件的第二文件标识可以从读取文件时的读取请求中获得。Generally, when the storage terminal is unable to read the file for reading, the metadata of the file in the metadata database may be considered to be lost, thereby obtaining the second file identifier of the file. In one implementation of the present application, the second file identification of the file can be obtained from a read request when the file is read.
S1052:根据丢失的文件的第二文件标识,从所有键的值中获得包含第二文件标识的目标数据段;S1052: Obtain a target data segment that includes the second file identifier from the values of all the keys according to the second file identifier of the lost file;
在本申请的一个实施例中,上述根据丢失的文件的第二文件标识,从所有键的值存储的文件中获得包含第二标识的目标数据段,可以包括:In an embodiment of the present application, the obtaining, according to the second file identifier of the lost file, the target data segment that includes the second identifier from the file stored by the value of all the keys may include:
S1、根据第二文件标识,获得包含第二文件标识的键K;S1, according to the second file identifier, obtain a key K containing the second file identifier;
一般地,在所有键的值中读取第一关键字,进而根据第一关键字确定对应的文件标识长度,再根据文件标识长度确定出文件标识,从确定的文件标识中获得与第二文件标识相同的文件标识及该文件标识对应的键,这里所获得键为包含第二文件标识的键。Generally, the first keyword is read in the value of all the keys, and then the corresponding file identifier length is determined according to the first keyword, and then the file identifier is determined according to the file identifier length, and the second file is obtained from the determined file identifier. The same file identifier and the key corresponding to the file identifier are identified, and the key obtained here is the key containing the second file identifier.
需要说明的是,上述键K可以是多个键,也可以仅仅为一个键,其中,上述键K为多个键的情况下,说明一个文件存储在多个键中。It should be noted that the above-mentioned key K may be a plurality of keys, or may be only one key. When the above-mentioned key K is a plurality of keys, it is explained that one file is stored in a plurality of keys.
S2、判断键K的值中第二文件标识之后是否存储有第一关键字,若为是,则执行步骤S3,若为否,则执行步骤S4;S2, determining whether the first key is stored in the value of the key K after the second file identification, if yes, proceeding to step S3, if not, executing step S4;
一般地,存储一个文件的标识、数据量和该文件本身的顺序可以为:先存储该文件的标识,再存储该文件的数据量和该文件本身,第一关键字为存储一个文件的数据段起始存储位置。如图6所示,图6为本申请实施例提供的一种文件存储排布示意图。从图6中可以知,名字为Key1的键的值中存储了2个文件,file1后面存储了file2,而file2后面未存储文件,因此,与file1对应的第一关键字A(TAG_FILE_NAME)和与file2对应的第一关键字B(TAG_FILE_NAME)间的空间为存储file1的数据段,与file2对应的第一关键 字B至名字为Key1的键的值的末尾存储位置间的空间为存储file2的数据段。由上可知,只有知道文件标识后是否包含第一关键字,也就是说,只有知道该文件后是否存储了其他文件,才能知道如何确定存储一个文件的数据段,而每一文件都对应一个关键字,因此,需要判断第二文件标识之后是否存储有第一关键字。Generally, the identifier of the file, the amount of data, and the order of the file itself may be: first store the identifier of the file, then store the data amount of the file and the file itself, and the first keyword is a data segment storing a file. Starting storage location. As shown in FIG. 6, FIG. 6 is a schematic diagram of a file storage arrangement according to an embodiment of the present application. As can be seen from FIG. 6, two files are stored in the value of the key named Key1, and file2 is stored after file1, and no file is stored after file2. Therefore, the first keyword A (TAG_FILE_NAME) corresponding to file1 and The space between the first key B (TAG_FILE_NAME) corresponding to file2 is the data segment storing file1, and the first key corresponding to file2 The space between the word B and the end of the value of the key named Key1 is the data segment in which file2 is stored. It can be seen from the above that only knowing whether the file identifier contains the first keyword, that is, only knowing whether the file is stored after the file, can know how to determine the data segment storing a file, and each file corresponds to a key Word, therefore, it is necessary to determine whether the first keyword is stored after the second file identification.
S3、获得键K的值中第二文件标识之后与第二文件标识最近的第一关键字W1,并确定第一关键字W2和第一关键字W1间的数据段为目标数据段,其中,第一关键字W2为:键K的值中第二文件标识之前且与第二文件标识最近的第一关键字;S3, obtaining a first keyword W1 that is the closest to the second file identifier after the second file identifier in the value of the key K, and determining that the data segment between the first keyword W2 and the first keyword W1 is the target data segment, where The first keyword W2 is: a first keyword in the value of the key K before the second file identifier and closest to the second file identifier;
一般地,第一关键字为存储一个文件的数据段起始存储位置,一个文件标识对应一个第一关键字,两个相邻的第一关键字之间的空间为一个数据段,这里,文件标识对应第一关键字为:该文件标识之前且与该文件标识最近的第一关键字。在确定了目标数据段后,就可以根据该目标数据段中存储的第一关键字获得文件标识长度,再根据文件标识长度,确定文件标识;并且还可以根据该目标数据段中存储的第二关键字获得该文件的数据量,进而获得该文件。这里,文件标识和该文件的数据量为元数据,这样就可以根据在键的值中获得的元数据来恢复元数据库中的元数据了。Generally, the first keyword is a data segment starting storage location for storing a file, a file identifier corresponds to a first keyword, and a space between two adjacent first keywords is a data segment, where the file The identifier corresponding to the first keyword is: the first keyword before the file identifier and closest to the file identifier. After the target data segment is determined, the file identifier length may be obtained according to the first keyword stored in the target data segment, and then the file identifier is determined according to the file identifier length; and the second identifier may be stored according to the target data segment. The keyword gets the amount of data for the file and gets the file. Here, the file identifier and the data amount of the file are metadata, so that the metadata in the metadata database can be restored according to the metadata obtained in the value of the key.
S4、确定第一关键字W2与键K的值的末尾存储位置之间的数据段为目标数据段。S4. Determine a data segment between the first keyword W2 and the end storage location of the value of the key K as the target data segment.
一般地,在一个文件标识后不存在第一关键字,说明该文件后未存储文件,因此,可以确定该文件标识对应的第一关键字W2与该文件标识所在键K的值的末尾存储位置之间的数据段为目标数据段。Generally, after the file is identified, the first keyword does not exist, and the file is not stored after the file is deleted. Therefore, the first keyword W2 corresponding to the file identifier and the last storage location of the value of the key K where the file identifier is located may be determined. The data segment between them is the target data segment.
S1053:根据目标数据段中存储的丢失的文件的第二文件标识和丢失的文件的数据量,更新预设的元数据库。S1053: Update the preset metabase according to the second file identifier of the lost file stored in the target data segment and the data amount of the lost file.
应用图5所示实施例,存储终端只需要获得元数据丢失的文件的第二文件标识,根据丢失的文件的第二文件标识,从所有键的值中存储的文件中获得包含第二标识的目标数据段,最后根据目标数据段中存储的丢失的文件的第二文件标识和丢失的文件的数据量,更新预设的元数据库就可以了,减少了 存储终端的工作量,提高了元数据库更新的效率。Applying the embodiment shown in FIG. 5, the storage terminal only needs to obtain the second file identifier of the file whose metadata is lost, and obtain the second identifier from the file stored in the value of all the keys according to the second file identifier of the lost file. The target data segment is finally updated according to the second file identifier of the lost file stored in the target data segment and the data amount of the lost file, and the default metadata database is updated, which is reduced. The workload of the storage terminal improves the efficiency of the metadata database update.
参考图7,图7为本申请实施例提供的另一种文件存储方法的流程示意图,应用于存储终端,该方法中,步骤S103可以包括如下步骤:Referring to FIG. 7, FIG. 7 is a schematic flowchart of another file storage method according to an embodiment of the present disclosure, which is applied to a storage terminal. In the method, step S103 may include the following steps:
S1031:获得目标键的值中存储的第一关键字和第二关键字;S1031: Obtain a first keyword and a second keyword stored in a value of the target key;
在本申请的一个实施例中,按照TLV格式存储的文件中TAG和LENGTH占用的字节数为固定大小的,因此只需目标键的值中存储的第一关键字和第二关键字(也就是TAG),就可以根据第一关键字和第二关键字的个数以及与第一关键字对应的文件标识长度和第二关键字对应的数据量(也就是LENGTH),确定出该待存储文件在目标键的值中的偏移量。In one embodiment of the present application, the number of bytes occupied by the TAG and LENGTH in the file stored in the TLV format is a fixed size, so only the first keyword and the second keyword stored in the value of the target key are required (also That is, TAG), it is determined according to the number of the first keyword and the second keyword and the file identifier length corresponding to the first keyword and the data amount corresponding to the second keyword (ie, LENGTH), to determine the to-be-stored The offset of the file in the value of the target key.
S1032:根据所获得第一关键字和所获得第二关键字,计算待存储文件在目标键的值中的偏移量;S1032: Calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in the value of the target key;
根据图6所示,例如,TAG和LENGTH占用的字节数均为4Kbytes,file1的标识长度为10Kbytes,file1的数据量为100Kbytes,file2的标识长度为12Kbytes,file2的数据量为200Kbytes,file1和file2的存储顺序为:先存储file1再存储file2,此时获得的file1和file2的元数据如表1所示。According to FIG. 6, for example, the number of bytes occupied by TAG and LENGTH is 4Kbytes, the identifier length of file1 is 10Kbytes, the data amount of file1 is 100Kbytes, the identification length of file2 is 12Kbytes, the data volume of file2 is 200Kbytes, file1 and The storage order of file2 is as follows: first store file1 and then store file2. The metadata of file1 and file2 obtained at this time are shown in Table 1.
表1Table 1
Figure PCTCN2017073080-appb-000001
Figure PCTCN2017073080-appb-000001
一般地,file1和file2在键的值中的偏移量通过以下方式计算得到:在向名字为Key1的目标键的值中存储file1时,该目标键的值中为空,此时,可以确定,该目标键的值的起始存储位置至file1文件的文件头之间有1个第一关键字和1个第二关键字(此为预设的存储格式TLV自身携带的第一关键字和所获得第二关键字),也就是有2个TAG,对应的有2个LENGTH,从LENGTH中可以获得file1的标识长度为10Kbytes、file1的数据量为100Kbytes,因此,可以确定file1在Key1的值中的偏移量为:2*4Kbytes(2个TAG占用的字节数)+2*4Kbytes (2个LENGTH占用的字节数)+10Kbytes(file1的标识占用的字节数)=8Kbytes+8Kbytes+10Kbytes=26Kbytes;另外,在向名字为Key1的目标键的值中存储file2时,该目标键的值中存储了file1,可以获得1个第一关键字和1个第二关键字,另外还包含1个第一关键字和1个第二关键字(此为预设的存储格式TLV自身携带的第一关键字和所获得第二关键字),也就是有4个TAG,对应的有4个LENGTH,从LENGTH中可以获得file1的标识长度为10Kbytes、file1的数据量为100Kbytes、file2的标识长度为12Kbytes、file2的数据量为200Kbytes,因此,可以确定file2在Key1的值中的偏移量为:4*4Kbytes(2个TAG占用的字节数)+4*4Kbytes(2个LENGTH占用的字节数)+10Kbytes(file1的标识占用的字节数)+100Kbytes(file1占用的字节数)+12Kbytes(file2的标识占用的字节数)=16Kbytes+16Kbytes+10Kbytes+100Kbytes+12Kbytes=154Kbytes。Generally, the offset of file1 and file2 in the value of the key is calculated by storing the file1 in the value of the target key named Key1, the value of the target key is empty, and at this time, it can be determined The starting storage location of the value of the target key has a first keyword and a second keyword between the file headers of the file1 file (this is the first keyword and the default storage format carried by the TLV itself) The obtained second keyword), that is, there are 2 TAGs, corresponding to 2 LENGTH, from LENGTH, the file length of file1 can be 10Kbytes, and the data amount of file1 is 100Kbytes. Therefore, the value of file1 at Key1 can be determined. The offset in the is: 2 * 4Kbytes (the number of bytes occupied by 2 TAG) + 2 * 4Kbytes (2 bytes occupied by LENGTH) +10Kbytes (the number of bytes occupied by the file1 identifier) = 8Kbytes + 8Kbytes + 10Kbytes = 26Kbytes; in addition, when storing file2 in the value of the target key named Key1, the target The file1 is stored in the value of the key, and one first keyword and one second keyword are obtained, and one first keyword and one second keyword are further included (this is the preset storage format TLV itself). The first keyword carried and the obtained second keyword), that is, there are 4 TAGs, corresponding to 4 LENGTH, and the file length of file1 is 10Kbytes, the data amount of file1 is 100Kbytes, and file2 is obtained from LENGTH. The identifier length is 12Kbytes, and the data volume of file2 is 200Kbytes. Therefore, it can be determined that the offset of file2 in the value of Key1 is: 4*4Kbytes (the number of bytes occupied by 2 TAGs) + 4*4Kbytes (2 LENGTH occupations) Bytes) +10Kbytes (the number of bytes occupied by the file1 identifier) +100Kbytes (the number of bytes occupied by file1) +12Kbytes (the number of bytes occupied by the identifier of file2)=16Kbytes+16Kbytes+10Kbytes+100Kbytes+12Kbytes= 154Kbytes.
S1033:根据计算得到的偏移量,确定待存储文件的待存储元数据;S1033: Determine, according to the calculated offset, the metadata to be stored of the file to be stored;
在本申请的一个实施例中,文件在键的值中的偏移量也是文件的元数据的一部分,以便于存储终端根据偏移量快速获得该文件的存储位置。In one embodiment of the present application, the offset of the file in the value of the key is also part of the metadata of the file, so that the storage terminal quickly obtains the storage location of the file according to the offset.
一般地,在获得了待存储文件在目标键的值中的偏移量后,结合第一文件标识和待存储文件的数据量确定出待存储文件的元数据。Generally, after obtaining the offset of the file to be stored in the value of the target key, the metadata of the file to be stored is determined in combination with the first file identifier and the data amount of the file to be stored.
应用图7所示实施例,存储终端获得目标键的值中存储的第一关键字和第二关键字,根据所获得第一关键字和所获得第二关键字,计算待存储文件在目标键的值中的偏移量,并根据计算得到的偏移量,确定待存储文件的待存储元数据。这里,根据目标键的值中存储的第一关键字和第二关键字计算文件的偏移量,进而确定待存储文件的待存储元数据,而不必一一统计待存储文件的存储位置与目标键的值的起始存储位置之间的数据量,来确定文件的偏移量,元数据的确定更为快速、方便。Applying the embodiment shown in FIG. 7, the storage terminal obtains the first keyword and the second keyword stored in the value of the target key, and calculates the file to be stored in the target key according to the obtained first keyword and the obtained second keyword. The offset in the value, and based on the calculated offset, determine the metadata to be stored of the file to be stored. Here, the offset of the file is calculated according to the first keyword and the second keyword stored in the value of the target key, thereby determining the metadata to be stored of the file to be stored, without having to count the storage location and target of the file to be stored one by one. The amount of data between the starting storage locations of the values of the keys to determine the offset of the file, the determination of the metadata is faster and more convenient.
参考图8,图8为本申请实施例提供的一种文件存储装置的结构示意图,应用于存储终端,该装置可以包括:存储请求接收模块801、信息确定模块802、元数据获得模块803和数据存储模块804;Referring to FIG. 8, FIG. 8 is a schematic structural diagram of a file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal, and the device may include: a storage request receiving module 801, an information determining module 802, a metadata obtaining module 803, and data. Storage module 804;
其中,存储请求接收模块801,用于接收针对待存储文件的存储请求;The storage request receiving module 801 is configured to receive a storage request for a file to be stored;
信息确定模块802,用于获得待存储文件的第一文件标识和待存储文件的 数据量,并确定用于存储待存储文件的目标键;The information determining module 802 is configured to obtain a first file identifier of the file to be stored and a file to be stored. The amount of data, and determine the target key for storing the file to be stored;
元数据获得模块803,用于根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据;The metadata obtaining module 803 is configured to obtain, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
数据存储模块804,用于按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中,其中,预设的元数据库,用于存储文件的元数据。The data storage module 804 is configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format, and store the to-be-stored The metadata is stored in a preset metabase, wherein a preset metabase is used to store metadata of the file.
应用图8所示实施例,存储终端在接收到针对待存储文件的存储请求后,获得待存储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键,根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据,按照预设的存储格式,将第一文件标识、数据量和待存储文件存储至目标键中,并将该待存储元数据存储至预设的元数据库中。这样,在元数据库存在元数据丢失的情况下,从一个键中读取数据时,就可以根据预设的存储格式确定出键的值中已存储文件的第一文件标识、数据量以及该已存储文件在该键的值中的偏移量,结合该键的名字,确定出该已存储文件的元数据,进而根据该元数据来恢复元数据库中的元数据,保证了元数据的恢复,避免文件的损失。Applying the embodiment shown in FIG. 8 , after receiving the storage request for the file to be stored, the storage terminal obtains the first file identifier of the file to be stored and the data amount of the file to be stored, and determines a target key for storing the file to be stored. According to the target key, the metadata to be stored when the file to be stored is stored according to the preset storage format is obtained, and the first file identifier, the data volume, and the file to be stored are stored in the target key according to the preset storage format, and The metadata to be stored is stored in a preset metabase. In this way, in the case that the metadata is lost in the metadata database, when the data is read from a key, the first file identifier, the data amount, and the amount of the stored file in the value of the key can be determined according to a preset storage format. The offset of the stored file in the value of the key, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata. Avoid the loss of documents.
参考图9,图9为本申请实施例提供的另一种文件存储装置的结构示意图,应用于存储终端,该装置中,数据存储模块804可以包括:文件标识存储子模块8041和元数据存储子模块8042;Referring to FIG. 9, FIG. 9 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal. In the device, the data storage module 804 may include: a file identifier storage submodule 8041 and a metadata storage device. Module 8042;
文件存储子模块8041,用于按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中;a file storage sub-module 8041, configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format;
元数据存储子模块8042,用于将所述待存储元数据存储至预设的元数据库中;a metadata storage sub-module 8042, configured to store the to-be-stored metadata into a preset metadata database;
其中,文件存储子模块8041,包括:文件标识存储单元8041a和文件存储单元8041b;The file storage submodule 8041 includes: a file identifier storage unit 8041a and a file storage unit 8041b;
文件标识存储单元8041a,用于按照第一关键字、文件标识长度和第一文件标识的顺序,将第一关键字、文件标识长度和第一文件标识存储至目标键 的值中,其中,第一关键字为针对文件标识的关键字,文件标识长度为第一文件标识占用的字节数;The file identifier storage unit 8041a is configured to store the first keyword, the file identifier length, and the first file identifier to the target key according to the first keyword, the file identifier length, and the first file identifier. The value of the first keyword is a keyword for the file identifier, and the file identifier length is the number of bytes occupied by the first file identifier;
文件存储单元8041b,用于按照第二关键字、数据量和待存储文件的顺序,将第二关键字、数据量和待存储文件存储至目标键的值中,其中,第二关键字为针对文件的关键字。The file storage unit 8041b is configured to store the second keyword, the data amount, and the file to be stored in the value of the target key according to the second keyword, the data amount, and the order of the file to be stored, where the second keyword is for The keyword of the file.
应用图9所示实施例,存储终端按照第一关键字、文件标识长度和待存储文件的第一文件标识的顺序,将第一关键字、文件标识长度和待存储文件的第一文件标识存储至目标键的值中,并按照第二关键字、待存储文件的数据量和待存储文件的顺序,将第二关键字、数据量和待存储文件存储至目标键的值中,将待存储元数据存储至预设的元数据库中。这样在元数据库存在元数据丢失的情况下,仍然可以根据按照预定存储格式存储在键的值中的文件的标识和数据量,确定读取到的数据是属于哪一文件的,有效地避免了文件的损失。Applying the embodiment shown in FIG. 9 , the storage terminal stores the first keyword, the file identifier length, and the first file identifier of the file to be stored according to the first keyword, the file identifier length, and the first file identifier of the file to be stored. Up to the value of the target key, and storing the second keyword, the data amount, and the file to be stored in the value of the target key according to the second keyword, the data amount of the file to be stored, and the order of the file to be stored, to be stored The metadata is stored in a preset metabase. In this way, in the case that the metadata loss of the metadata database, it is still possible to determine which file the read data belongs to according to the identifier and the data amount of the file stored in the value of the key according to the predetermined storage format, which effectively avoids Loss of documents.
参考图10,图10为本申请实施例提供的另一种文件存储装置的结构示意图,应用于存储终端,该装置还可以包括:元数据库更新模块805;FIG. 10 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal, and the device may further include: a metabase update module 805;
这里,元数据库更新模块805,用于:Here, the metabase update module 805 is configured to:
在预设的元数据库存在元数据丢失的情况下,根据所有键的值中存储的第一关键字和第二关键字,更新预设的元数据库。In the case where the metadata of the preset metabase is lost, the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
应用图10所示实施例,存储终端在在预设的元数据库存在元数据丢失的情况下,从各个键中读取数据时,根据预设的存储格式获得已存储文件的标识、已存储文件的数据量,根据所有键的值中存储的第一关键字和第二关键字,确定各个已存储文件在各个键的值中的偏移量,根据获得信息更新预设的元数据库,能够有效地恢复元数据库中的元数据,避免了文件损失。Applying the embodiment shown in FIG. 10, the storage terminal obtains the identifier of the stored file and the stored file according to the preset storage format when the data is read from each key in the case that the metadata is lost in the preset metabase. The amount of data, according to the first keyword and the second keyword stored in the values of all the keys, determine the offset of each stored file in the value of each key, and update the preset metabase according to the obtained information, which can be effective Restore metadata in the metabase to avoid file loss.
参考图11,图11为本申请实施例提供的另一种文件存储装置的结构示意图,应用于存储终端,该装置中,元数据库更新模块805可以包括:文件标识获得子模块8051、目标数据段确定子模块8052和元数据库更新子模块8053;Referring to FIG. 11 , FIG. 11 is a schematic structural diagram of another file storage device according to an embodiment of the present disclosure, which is applied to a storage terminal. In the device, the meta-database update module 805 may include: a file identifier obtaining sub-module 8051 and a target data segment. Determining submodule 8052 and metabase update submodule 8053;
其中,文件标识获得子模块8051,用于在预设的元数据库存在元数据丢失的情况下,获得元数据丢失的文件的第二文件标识; The file identifier obtaining sub-module 8051 is configured to obtain a second file identifier of the file in which the metadata is lost if the metadata of the preset meta-database is lost.
目标数据段确定子模块8052,用于根据第二文件标识,从所有键的值中获得包含第二文件标识的目标数据段;a target data segment determining sub-module 8052, configured to obtain, according to the second file identifier, a target data segment that includes the second file identifier from values of all the keys;
元数据库更新子模块8053,用于根据目标数据段中存储的第二文件标识和数据量,更新预设的元数据库。The metabase update submodule 8053 is configured to update the preset metabase according to the second file identifier and the amount of data stored in the target data segment.
在本申请的一种实现方式中,上述目标数据段确定子模块8052可以包括:键获得单元、关键字判断单元、第一目标数据段确定单元和第二目标数据段确定单元(图11中未示出);In an implementation manner of the present application, the target data segment determining submodule 8052 may include: a key obtaining unit, a keyword determining unit, a first target data segment determining unit, and a second target data segment determining unit (not shown in FIG. 11 show);
其中,键获得单元,用于根据第二文件标识,获得包含第二文件标识的键K;The key obtaining unit is configured to obtain, according to the second file identifier, a key K that includes the second file identifier;
关键字判断单元,用于判断键K的值中第二文件标识之后是否存储有第一关键字,若为是,则触发第一目标数据段确定单元,若为否,则触发第二目标数据段确定单元;a keyword determining unit, configured to determine whether a first keyword is stored after the second file identifier in the value of the key K, and if yes, triggering the first target data segment determining unit, and if not, triggering the second target data Segment determination unit;
第一目标数据段确定单元,用于获得键K的值中第二文件标识之后与第二文件标识最近的第一关键字W1,并确定第一关键字W2和第一关键字W1间的数据段为目标数据段,其中,第一关键字W2为:键K的值中第二文件标识之前且与第二文件标识最近的第一关键字;a first target data segment determining unit, configured to obtain a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determine data between the first keyword W2 and the first keyword W1 The segment is a target data segment, where the first keyword W2 is: a first keyword in the value of the key K before the second file identifier and closest to the second file identifier;
第二目标数据段确定单元,用于确定第一关键字W2与键K的值末尾存储位置间的数据段为目标数据段。The second target data segment determining unit is configured to determine the data segment between the first keyword W2 and the storage location at the end of the value of the key K as the target data segment.
应用图11所示实施例,存储终端只需要获得元数据丢失的文件的第二文件标识,根据丢失的文件的第二文件标识,从所有键的值中存储的文件中获得包含第二标识的目标数据段,最后根据目标数据段中存储的丢失的文件的第二文件标识和丢失的文件的数据量,更新预设的元数据库就可以了,减少了存储终端的工作量,提高了元数据库更新的效率。Applying the embodiment shown in FIG. 11, the storage terminal only needs to obtain the second file identifier of the file whose metadata is lost, and obtain the second identifier from the file stored in the value of all the keys according to the second file identifier of the lost file. The target data segment finally updates the preset metabase according to the second file identifier of the lost file stored in the target data segment and the data amount of the lost file, thereby reducing the workload of the storage terminal and improving the metabase. Updated efficiency.
参考图12,图12为本申请实施例提供的另一种文件存储装置的结构示意图,应用于存储终端,该装置中,元数据获得模块803,可以包括:关键字获得子模块8031、偏移量计算子模块8032、元数据确定子模块8033;Referring to FIG. 12, FIG. 12 is a schematic structural diagram of another file storage apparatus according to an embodiment of the present disclosure, which is applied to a storage terminal. In the apparatus, the metadata obtaining module 803 may include: a keyword obtaining submodule 8031, and an offset. a quantity calculation sub-module 8032, a metadata determination sub-module 8033;
其中,关键字获得子模块8031,用于获得所述目标键的值中存储的第一 关键字和第二关键字;The keyword obtaining submodule 8031 is configured to obtain the first stored in the value of the target key. Keyword and second keyword;
偏移量计算子模块8032,用于根据所获得第一关键字和所获得第二关键字,计算待存储文件在目标键的值中的偏移量;The offset calculation sub-module 8032 is configured to calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in the value of the target key;
元数据确定子模块8033,用于根据计算得到的偏移量,确定待存储文件的待存储元数据。The metadata determining sub-module 8033 is configured to determine metadata to be stored of the file to be stored according to the calculated offset.
应用图12所示实施例,存储终端获得目标键的值中存储的第一关键字和第二关键字,根据所获得第一关键字和所获得第二关键字,计算待存储文件在目标键的值中的偏移量,并根据计算得到的偏移量,确定待存储文件的待存储元数据。这里,根据目标键的值中存储的第一关键字和第二关键字计算文件的偏移量,进而确定待存储文件的待存储元数据,而不必一一统计待存储文件的存储位置与目标键的值的起始存储位置之间的数据量,来确定文件的偏移量,元数据的确定更为快速、方便。Applying the embodiment shown in FIG. 12, the storage terminal obtains the first keyword and the second keyword stored in the value of the target key, and calculates the file to be stored in the target key according to the obtained first keyword and the obtained second keyword. The offset in the value, and based on the calculated offset, determine the metadata to be stored of the file to be stored. Here, the offset of the file is calculated according to the first keyword and the second keyword stored in the value of the target key, thereby determining the metadata to be stored of the file to be stored, without having to count the storage location and target of the file to be stored one by one. The amount of data between the starting storage locations of the values of the keys to determine the offset of the file, the determination of the metadata is faster and more convenient.
本申请实施例提供了一种存储终端,所述存储终端包括:壳体、处理器、存储器、电路板和电源电路,其中,所述电路板安置在所述壳体围成的空间内部,所述处理器和所述存储器设置在所述电路板上;所述电源电路,用于为所述存储终端的各个电路或器件供电;所述存储器用于存储可执行程序代码;所述处理器通过运行所述存储器中存储的可执行程序代码,以执行以下步骤:The embodiment of the present application provides a storage terminal, including: a casing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is disposed inside a space enclosed by the casing, The processor and the memory are disposed on the circuit board; the power supply circuit is configured to supply power to each circuit or device of the storage terminal; the memory is configured to store executable program code; Executing executable program code stored in the memory to perform the following steps:
接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
应用本申请实施例,存储终端在接收到针对待存储文件的存储请求后, 获得待存储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键,根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据,按照预设的存储格式,将第一文件标识、数据量和待存储文件存储至目标键中,并将该待存储元数据存储至预设的元数据库中。这样,在元数据库存在元数据丢失的情况下,就可以根据预设的存储格式确定出键的值中已存储文件的第一文件标识、数据量以及该已存储文件在该键的值中的偏移量,结合该键的名字,确定出该已存储文件的元数据,进而根据该元数据来恢复元数据库中的元数据,保证了元数据的恢复,避免文件的损失。Applying the embodiment of the present application, after receiving the storage request for the file to be stored, the storage terminal Obtaining a first file identifier of the file to be stored and a data volume of the file to be stored, and determining a target key for storing the file to be stored, and obtaining metadata to be stored when the file to be stored is stored according to a preset storage format according to the target key And storing the first file identifier, the data volume, and the file to be stored in the target key according to the preset storage format, and storing the to-be-stored metadata in a preset metabase. In this way, in the case that the metadata loss of the metadata database, the first file identifier, the data amount of the stored file in the value of the key, and the stored file in the value of the key may be determined according to a preset storage format. The offset, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding file loss.
该存储终端以多种形式存在,包括但不限于:The storage terminal exists in various forms including, but not limited to:
(1)移动通信设备:这类设备的特点是具备移动通信功能,并且以提供话音、数据通信为主要目标。这类终端包括:智能手机(例如iPhone)、多媒体手机、功能性手机,以及低端手机等。(1) Mobile communication devices: These devices are characterized by mobile communication functions and are mainly aimed at providing voice and data communication. Such terminals include: smart phones (such as iPhone), multimedia phones, functional phones, and low-end phones.
(2)超移动个人计算机设备:这类设备属于个人计算机的范畴,有计算和处理功能,一般也具备移动上网特性。这类终端包括:PDA、MID和UMPC设备等,例如iPad。(2) Ultra-mobile personal computer equipment: This type of equipment belongs to the category of personal computers, has computing and processing functions, and generally has mobile Internet access. Such terminals include: PDAs, MIDs, and UMPC devices, such as the iPad.
(3)便携式娱乐设备:这类设备可以显示和播放多媒体内容。该类设备包括:音频、视频播放器(例如iPod),掌上游戏机,电子书,以及智能玩具和便携式车载导航设备。(3) Portable entertainment devices: These devices can display and play multimedia content. Such devices include: audio, video players (such as iPod), handheld game consoles, e-books, and smart toys and portable car navigation devices.
(4)服务器:提供计算服务的设备,服务器的构成包括处理器、硬盘、内存、系统总线等,服务器和通用的计算机架构类似,但是由于需要提供高可靠的服务,因此在处理能力、稳定性、可靠性、安全性、可扩展性、可管理性等方面要求较高。(4) Server: A device that provides computing services. The server consists of a processor, a hard disk, a memory, a system bus, etc. The server is similar to a general-purpose computer architecture, but because of the need to provide highly reliable services, processing power and stability High reliability in terms of reliability, security, scalability, and manageability.
(5)其他具有数据交互功能的电子装置。(5) Other electronic devices with data interaction functions.
本申请实施例提供了一种可执行程序代码,所述可执行程序代码用于在运行时执行以下步骤:An embodiment of the present application provides an executable program code for performing the following steps at runtime:
接收针对待存储文件的存储请求; Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
应用本申请实施例,在接收到针对待存储文件的存储请求后,获得待存储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键,根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据,按照预设的存储格式,将第一文件标识、数据量和待存储文件存储至目标键中,并将该待存储元数据存储至预设的元数据库中。这样,在元数据库存在元数据丢失的情况下,就可以根据预设的存储格式确定出键的值中已存储文件的第一文件标识、数据量以及该已存储文件在该键的值中的偏移量,结合该键的名字,确定出该已存储文件的元数据,进而根据该元数据来恢复元数据库中的元数据,保证了元数据的恢复,避免文件的损失。Applying the storage request for the file to be stored, obtaining the first file identifier of the file to be stored and the data amount of the file to be stored, and determining a target key for storing the file to be stored, according to the target key. And obtaining the to-be-stored metadata when the file to be stored is stored according to the preset storage format, storing the first file identifier, the data volume, and the file to be stored in the target key according to the preset storage format, and storing the to-be-stored element The data is stored in a preset metabase. In this way, in the case that the metadata loss of the metadata database, the first file identifier, the data amount of the stored file in the value of the key, and the stored file in the value of the key may be determined according to a preset storage format. The offset, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding file loss.
本申请实施例提供了一种存储介质,所述存储介质用于存储可执行程序代码,所述可执行程序代码被运行以执行以下步骤:Embodiments of the present application provide a storage medium for storing executable program code, the executable program code being executed to perform the following steps:
接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
应用本申请实施例,在接收到针对待存储文件的存储请求后,获得待存 储文件的第一文件标识和待存储文件的数据量,并确定用于存储待存储文件的目标键,根据目标键,获得待存储文件按照预设的存储格式存储时的待存储元数据,按照预设的存储格式,将第一文件标识、数据量和待存储文件存储至目标键中,并将该待存储元数据存储至预设的元数据库中。这样,在元数据库存在元数据丢失的情况下,就可以根据预设的存储格式确定出键的值中已存储文件的第一文件标识、数据量以及该已存储文件在该键的值中的偏移量,结合该键的名字,确定出该已存储文件的元数据,进而根据该元数据来恢复元数据库中的元数据,保证了元数据的恢复,避免文件的损失。After the storage request for the file to be stored is received, the application is obtained. And storing the first file identifier of the file and the data volume of the file to be stored, and determining a target key for storing the file to be stored, and obtaining the metadata to be stored when the file to be stored is stored according to the preset storage format according to the target key, according to the target key The preset storage format stores the first file identifier, the data volume, and the file to be stored in the target key, and stores the to-be-stored metadata in a preset metabase. In this way, in the case that the metadata loss of the metadata database, the first file identifier, the data amount of the stored file in the value of the key, and the stored file in the value of the key may be determined according to a preset storage format. The offset, combined with the name of the key, determines the metadata of the stored file, and then restores the metadata in the metadata database according to the metadata, thereby ensuring recovery of the metadata and avoiding file loss.
对于装置、存储终端、可执行程序代码和存储介质实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。For the device, the storage terminal, the executable program code and the storage medium embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should be noted that, in this context, relational terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply such entities or operations. There is any such actual relationship or order between them. Furthermore, the term "comprises" or "comprises" or "comprises" or any other variations thereof is intended to encompass a non-exclusive inclusion, such that a process, method, article, or device that comprises a plurality of elements includes not only those elements but also Other elements, or elements that are inherent to such a process, method, item, or device. An element that is defined by the phrase "comprising a ..." does not exclude the presence of additional equivalent elements in the process, method, item, or device that comprises the element.
本领域普通技术人员可以理解实现上述方法实施方式中的全部或部分步骤是可以通过程序来指令相关的硬件来完成,所述的程序可以存储于计算机可读取存储介质中,这里所称得的存储介质,如:ROM/RAM、磁碟、光盘等。One of ordinary skill in the art can understand that all or part of the steps in implementing the above method embodiments can be completed by a program to instruct related hardware, and the program can be stored in a computer readable storage medium, which is referred to herein. Storage media such as ROM/RAM, disk, CD, etc.
以上所述仅为本申请的较佳实施例而已,并非用于限定本申请的保护范围。凡在本申请的精神和原则之内所作的任何修改、等同替换、改进等,均包含在本申请的保护范围内。 The above description is only the preferred embodiment of the present application, and is not intended to limit the scope of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application are included in the scope of the present application.

Claims (15)

  1. 一种文件存储方法,应用于存储终端,其特征在于,所述方法包括:A file storage method is applied to a storage terminal, and the method includes:
    接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
    获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
    根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
    按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
  2. 根据权利要求1所述的方法,其特征在于,所述按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,包括:The method according to claim 1, wherein the storing the first file identifier, the data amount, and the file to be stored to a value of the target key according to the preset storage format Including:
    按照第一关键字、文件标识长度和所述第一文件标识的顺序,将所述第一关键字、所述文件标识长度和所述第一文件标识存储至所述目标键的值中,其中,所述第一关键字为针对文件标识的关键字,所述文件标识长度为所述第一文件标识占用的字节数;And storing, in the order of the first keyword, the file identifier length, and the first file identifier, the first keyword, the file identifier length, and the first file identifier into a value of the target key, where The first keyword is a keyword that is identified by the file, and the file identifier length is a number of bytes occupied by the first file identifier.
    按照第二关键字、所述数据量和所述待存储文件的顺序,将所述第二关键字、所述数据量和所述待存储文件存储至所述目标键的值中,其中,所述第二关键字为针对文件的关键字。And storing, in the order of the second keyword, the data amount, and the file to be stored, the second keyword, the data amount, and the file to be stored in a value of the target key, where The second keyword is a keyword for the file.
  3. 根据权利要求2所述的方法,其特征在于,所述方法还包括:The method of claim 2, wherein the method further comprises:
    在所述预设的元数据库存在元数据丢失的情况下,根据所有键的值中存储的所述第一关键字和所述第二关键字,更新所述预设的元数据库。In the case that the preset metabase has metadata loss, the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
  4. 根据权利要求3所述的方法,其特征在于,所述根据所有键的值中存储的所述第一关键字和所述第二关键字,更新所述预设的元数据库,包括:The method according to claim 3, wherein the updating the preset metadata database according to the first keyword and the second keyword stored in values of all the keys comprises:
    获得元数据丢失的文件的第二文件标识; Obtaining a second file identifier of the file in which the metadata is lost;
    根据所述第二文件标识,从所有键的值中获得包含所述第二文件标识的目标数据段;Obtaining, according to the second file identifier, a target data segment that includes the second file identifier from values of all keys;
    根据所述目标数据段中存储的所述第二文件标识和所述数据量,更新所述预设的元数据库。Updating the preset metabase according to the second file identifier and the data amount stored in the target data segment.
  5. 根据权利要求4所述的方法,其特征在于,所述根据所述第二文件标识,从所有键的值中获得包含所述第二文件标识的目标数据段,包括:The method according to claim 4, wherein the obtaining, according to the second file identifier, the target data segment including the second file identifier from the values of all the keys comprises:
    根据所述第二文件标识,获得包含所述第二文件标识的键K;Obtaining, according to the second file identifier, a key K including the identifier of the second file;
    判断所述键K的值中所述第二文件标识之后是否存储有第一关键字;Determining whether the first keyword is stored after the second file identifier in the value of the key K;
    若为是,则获得所述键K的值中所述第二文件标识之后与所述第二文件标识最近的第一关键字W1,并确定第一关键字W2和所述第一关键字W1间的数据段为目标数据段,其中,所述第一关键字W2为:所述键K的值中所述第二文件标识之前且与所述第二文件标识最近的第一关键字;If yes, obtaining a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determining the first keyword W2 and the first keyword W1 The data segment is a target data segment, wherein the first keyword W2 is: a first keyword that is before the second file identifier and is closest to the second file identifier in the value of the key K;
    若为否,则确定所述第一关键字W2与所述键K的值末尾存储位置间的数据段为目标数据段。If not, it is determined that the data segment between the first keyword W2 and the storage location at the end of the value of the key K is the target data segment.
  6. 根据权利要求2所述的方法,其特征在于,所述根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据,包括:The method according to claim 2, wherein the obtaining, according to the target key, the metadata to be stored when the file to be stored is stored according to a preset storage format comprises:
    获得所述目标键的值中存储的第一关键字和第二关键字;Obtaining a first keyword and a second keyword stored in a value of the target key;
    根据所获得第一关键字和所获得第二关键字,计算所述待存储文件在所述目标键的值中的偏移量;Calculating an offset of the file to be stored in a value of the target key according to the obtained first keyword and the obtained second keyword;
    根据计算得到的偏移量,确定所述待存储文件的待存储元数据。The metadata to be stored of the file to be stored is determined according to the calculated offset.
  7. 一种文件存储装置,应用于存储终端,其特征在于,所述装置包括:存储请求接收模块、信息确定模块、元数据获得模块和数据存储模块;A file storage device is applied to a storage terminal, and the device includes: a storage request receiving module, an information determining module, a metadata obtaining module, and a data storage module;
    其中,所述存储请求接收模块,用于接收针对待存储文件的存储请求;The storage request receiving module is configured to receive a storage request for a file to be stored;
    所述信息确定模块,用于获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;The information determining module is configured to obtain a first file identifier of the file to be stored and a data amount of the file to be stored, and determine a target key for storing the file to be stored;
    所述元数据获得模块,用于根据所述目标键,获得所述待存储文件按照 预设的存储格式存储时的待存储元数据;The metadata obtaining module is configured to obtain, according to the target key, the file to be stored according to the Metadata to be stored when the preset storage format is stored;
    所述数据存储模块,用于按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。The data storage module is configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format, and store the The storage metadata is stored in a preset metabase.
  8. 根据权利要求7所述的装置,其特征在于,所述数据存储模块,包括:The device according to claim 7, wherein the data storage module comprises:
    文件存储子模块,用于按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中;a file storage submodule, configured to store the first file identifier, the data amount, and the to-be-stored file into a value of the target key according to the preset storage format;
    元数据存储子模块,用于将所述待存储元数据存储至预设的元数据库中;a metadata storage submodule, configured to store the to-be-stored metadata into a preset metadata database;
    所述文件存储子模块,包括:文件标识存储单元和文件存储单元;The file storage submodule includes: a file identifier storage unit and a file storage unit;
    其中,所述文件标识存储单元,用于按照第一关键字、文件标识长度和所述第一文件标识的顺序,将所述第一关键字、所述文件标识长度和所述第一文件标识存储至所述目标键的值中,其中,所述第一关键字为针对文件标识的关键字,所述文件标识长度为所述第一文件标识占用的字节数;The file identifier storage unit is configured to: the first keyword, the file identifier length, and the first file identifier according to a first keyword, a file identifier length, and an order of the first file identifier And storing, in the value of the target key, where the first keyword is a keyword for a file identifier, where the file identifier length is a number of bytes occupied by the first file identifier;
    所述文件存储单元,用于按照第二关键字、所述数据量和所述待存储文件的顺序,将所述第二关键字、所述数据量和所述待存储文件存储至所述目标键的值中,其中,所述第二关键字为针对文件的关键字。The file storage unit, configured to store the second keyword, the data amount, and the file to be stored to the target according to a second keyword, the data amount, and an order of the file to be stored The value of the key, wherein the second keyword is a keyword for a file.
  9. 根据权利要求8所述的装置,其特征在于,所述装置还包括:元数据库更新模块,用于:The device according to claim 8, wherein the device further comprises: a metabase update module, configured to:
    在所述预设的元数据库存在元数据丢失的情况下,根据所有键的值中存储的所述第一关键字和所述第二关键字,更新所述预设的元数据库。In the case that the preset metabase has metadata loss, the preset metabase is updated according to the first keyword and the second keyword stored in the values of all the keys.
  10. 根据权利要求9所述的装置,其特征在于,所述元数据库更新模块,包括:文件标识获得子模块、目标数据段确定子模块和元数据库更新子模块;The apparatus according to claim 9, wherein the metabase update module comprises: a file identifier obtaining submodule, a target data segment determining submodule, and a metabase updating submodule;
    其中,所述文件标识获得子模块,用于在所述预设的元数据库存在元数据丢失的情况下,获得元数据丢失的文件的第二文件标识;The file identifier obtaining submodule is configured to obtain a second file identifier of the file with the metadata lost in the case that the metadata of the preset metabase is lost;
    所述目标数据段确定子模块,用于根据所述第二文件标识,从所有键的值中获得包含所述第二文件标识的目标数据段; The target data segment determining submodule is configured to obtain, according to the second file identifier, a target data segment that includes the second file identifier from values of all keys;
    所述元数据库更新子模块,用于根据所述目标数据段中存储的所述第二文件标识和所述数据量,更新所述预设的元数据库。The meta-database update sub-module is configured to update the preset meta-database according to the second file identifier and the data amount stored in the target data segment.
  11. 根据权利要求10所述的装置,其特征在于,所述目标数据段确定子模块,包括:键获得单元、关键字判断单元、第一目标数据段确定单元和第二目标数据段确定单元;The apparatus according to claim 10, wherein the target data segment determining submodule comprises: a key obtaining unit, a keyword determining unit, a first target data segment determining unit, and a second target data segment determining unit;
    其中,所述键获得单元,用于根据所述第二文件标识,获得包含所述第二文件标识的键K;The key obtaining unit, configured to obtain, according to the second file identifier, a key K that includes the second file identifier;
    所述关键字判断单元,用于判断所述键K的值中所述第二文件标识之后是否存储有第一关键字,若为是,则触发所述第一目标数据段确定单元,若为否,则触发所述第二目标数据段确定单元;The keyword determining unit is configured to determine whether the first keyword is stored after the second file identifier in the value of the key K, and if yes, triggering the first target data segment determining unit, if No, the second target data segment determining unit is triggered;
    所述第一目标数据段确定单元,用于获得所述键K的值中所述第二文件标识之后与所述第二文件标识最近的第一关键字W1,并确定第一关键字W2和所述第一关键字W1间的数据段为目标数据段,其中,所述第一关键字W2为:所述键K的值中所述第二文件标识之前且与所述第二文件标识最近的第一关键字;The first target data segment determining unit is configured to obtain a first keyword W1 that is closest to the second file identifier after the second file identifier in the value of the key K, and determine the first keyword W2 and The data segment between the first keywords W1 is a target data segment, wherein the first keyword W2 is: the value of the key K is before the second file identifier and is closest to the second file identifier First keyword
    所述第二目标数据段确定单元,用于确定所述第一关键字W2与所述键K的值末尾存储位置间的数据段为目标数据段。The second target data segment determining unit is configured to determine a data segment between the first keyword W2 and a storage location at the end of the value of the key K as a target data segment.
  12. 根据权利要求8所述的装置,其特征在于,所述元数据获得模块,包括:关键字获得子模块、偏移量计算子模块和元数据确定子模块;The apparatus according to claim 8, wherein the metadata obtaining module comprises: a keyword obtaining submodule, an offset calculating submodule, and a metadata determining submodule;
    其中,所述关键字获得子模块,用于获得所述目标键的值中存储的第一关键字和第二关键字;The keyword obtaining submodule, configured to obtain a first keyword and a second keyword stored in a value of the target key;
    所述偏移量计算子模块,用于根据所获得第一关键字和所获得第二关键字,计算所述待存储文件在所述目标键的值中的偏移量;The offset calculation submodule is configured to calculate, according to the obtained first keyword and the obtained second keyword, an offset of the file to be stored in a value of the target key;
    所述元数据确定子模块,用于根据计算得到的偏移量,确定所述待存储文件的待存储元数据。The metadata determining submodule is configured to determine metadata to be stored of the file to be stored according to the calculated offset.
  13. 一种存储终端,其特征在于,所述存储终端包括:壳体、处理器、存储器、电路板和电源电路,其中,所述电路板安置在所述壳体围成的空间 内部,所述处理器和所述存储器设置在所述电路板上;所述电源电路,用于为所述存储终端的各个电路或器件供电;所述存储器用于存储可执行程序代码;所述处理器通过运行所述存储器中存储的可执行程序代码,以执行以下步骤:A storage terminal, comprising: a housing, a processor, a memory, a circuit board, and a power supply circuit, wherein the circuit board is disposed in a space enclosed by the housing Internally, the processor and the memory are disposed on the circuit board; the power supply circuit is configured to supply power to each circuit or device of the storage terminal; the memory is configured to store executable program code; The processor performs the following steps by running executable program code stored in the memory:
    接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
    获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
    根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
    按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
  14. 一种可执行程序代码,其特征在于,所述可执行程序代码用于在运行时执行以下步骤:An executable program code, wherein the executable program code is configured to perform the following steps at runtime:
    接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
    获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
    根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
    按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
  15. 一种存储介质,其特征在于,所述存储介质用于存储可执行程序代码,所述可执行程序代码被运行以执行以下步骤:A storage medium, characterized in that the storage medium is for storing executable program code, the executable program code being executed to perform the following steps:
    接收针对待存储文件的存储请求;Receiving a storage request for a file to be stored;
    获得所述待存储文件的第一文件标识和所述待存储文件的数据量,并确 定用于存储所述待存储文件的目标键;Obtaining a first file identifier of the file to be stored and a data amount of the file to be stored, and determining a target key for storing the file to be stored;
    根据所述目标键,获得所述待存储文件按照预设的存储格式存储时的待存储元数据;Obtaining, according to the target key, metadata to be stored when the file to be stored is stored according to a preset storage format;
    按照所述预设的存储格式,将所述第一文件标识、所述数据量和所述待存储文件存储至所述目标键的值中,并将所述待存储元数据存储至预设的元数据库中。 And storing, according to the preset storage format, the first file identifier, the data amount, and the to-be-stored file into a value of the target key, and storing the to-be-stored metadata to a preset In the metabase.
PCT/CN2017/073080 2016-04-14 2017-02-08 File storage method and device WO2017177752A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610230618.6A CN107301177B (en) 2016-04-14 2016-04-14 File storage method and device
CN201610230618.6 2016-04-14

Publications (1)

Publication Number Publication Date
WO2017177752A1 true WO2017177752A1 (en) 2017-10-19

Family

ID=60041372

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/073080 WO2017177752A1 (en) 2016-04-14 2017-02-08 File storage method and device

Country Status (2)

Country Link
CN (1) CN107301177B (en)
WO (1) WO2017177752A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110659334A (en) * 2019-09-20 2020-01-07 浪潮电子信息产业股份有限公司 Metadata path information access method, device, equipment and readable storage medium
CN110968549A (en) * 2019-11-18 2020-04-07 Oppo(重庆)智能科技有限公司 File storage method and device, electronic equipment and medium
CN112416858A (en) * 2020-11-09 2021-02-26 深圳市珍爱捷云信息技术有限公司 Document storage method and device, electronic equipment and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110173162A1 (en) * 2010-01-14 2011-07-14 Anderson Eric A Scrubbing procedure for a data storage system
CN103186668A (en) * 2013-03-11 2013-07-03 北京京东世纪贸易有限公司 Method and device for processing data as well as data storage system based on key value data base
CN103853714A (en) * 2012-11-28 2014-06-11 中国移动通信集团河南有限公司 Data processing method and device
CN103902479A (en) * 2014-03-27 2014-07-02 浪潮电子信息产业股份有限公司 Quick reconstruction mechanism for metadata cache on basis of metadata log

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8325924B2 (en) * 2009-02-19 2012-12-04 Microsoft Corporation Managing group keys
CN103327052B (en) * 2012-03-22 2018-04-03 深圳市腾讯计算机系统有限公司 Date storage method and system and data access method and system
CN103595797B (en) * 2013-11-18 2017-01-18 上海爱数信息技术股份有限公司 Caching method for distributed storage system
CN103699585B (en) * 2013-12-06 2017-04-19 华为技术有限公司 Methods, devices and systems for file metadata storage and file recovery
CN104156278B (en) * 2014-08-01 2017-06-27 江苏大学 A kind of FileVersion control system and its method
CN104239438B (en) * 2014-08-29 2017-11-10 北京大学深圳研究生院 File information storage method and fileinfo reading/writing method based on separation storage

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110173162A1 (en) * 2010-01-14 2011-07-14 Anderson Eric A Scrubbing procedure for a data storage system
CN103853714A (en) * 2012-11-28 2014-06-11 中国移动通信集团河南有限公司 Data processing method and device
CN103186668A (en) * 2013-03-11 2013-07-03 北京京东世纪贸易有限公司 Method and device for processing data as well as data storage system based on key value data base
CN103902479A (en) * 2014-03-27 2014-07-02 浪潮电子信息产业股份有限公司 Quick reconstruction mechanism for metadata cache on basis of metadata log

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110659334A (en) * 2019-09-20 2020-01-07 浪潮电子信息产业股份有限公司 Metadata path information access method, device, equipment and readable storage medium
CN110968549A (en) * 2019-11-18 2020-04-07 Oppo(重庆)智能科技有限公司 File storage method and device, electronic equipment and medium
CN110968549B (en) * 2019-11-18 2024-03-29 Oppo(重庆)智能科技有限公司 File storage method, device, electronic equipment and medium
CN112416858A (en) * 2020-11-09 2021-02-26 深圳市珍爱捷云信息技术有限公司 Document storage method and device, electronic equipment and computer readable storage medium

Also Published As

Publication number Publication date
CN107301177B (en) 2020-02-18
CN107301177A (en) 2017-10-27

Similar Documents

Publication Publication Date Title
CN112765271B (en) Block chain transaction index storage method and device, computer equipment and medium
US9552382B2 (en) Reference counter integrity checking
WO2017201977A1 (en) Data writing and reading method and apparatus, and distributed object storage cluster
WO2019085474A1 (en) Calculation engine implementing method, electronic device, and storage medium
WO2017185616A1 (en) File storage method and electronic equipment
US20190286852A1 (en) Verification of data set components using digitally signed probabilistic data structures
WO2020211236A1 (en) Read-write conflict resolution method and apparatus employing b+ tree and storage medium
WO2017032312A1 (en) Method and apparatus for presenting to-be-cleaned data, and electronic device
WO2017118171A1 (en) Data migration method and apparatus
WO2017177752A1 (en) File storage method and device
US11138164B1 (en) Alter table implementation details with schema versioning
US20200065074A1 (en) Devices, systems, and methods of program identification, isolation, and profile attachment
CN109597707B (en) Clone volume data copying method, device and computer readable storage medium
CN110347900B (en) Keyword importance calculation method, device, server and medium
CN112559913B (en) Data processing method, device, computing equipment and readable storage medium
US8527478B1 (en) Handling bulk and incremental updates while maintaining consistency
CN112363814A (en) Task scheduling method and device, computer equipment and storage medium
JP6788002B2 (en) Data storage methods and devices for mobile devices
WO2019071907A1 (en) Method for identifying help information based on operation page, and application server
US11126520B2 (en) Skew detector for data storage system
US20170169044A1 (en) Property retrieval apparatus, method and system
CN109542860B (en) Service data management method based on HDFS and terminal equipment
WO2018094689A1 (en) Method, apparatus and device for improving browsing experience
CN110636042B (en) Method, device and equipment for updating verified block height of server
US11132401B1 (en) Distributed hash table based logging service

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17781728

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 17781728

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 17781728

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 03/05/2019)

122 Ep: pct application non-entry in european phase

Ref document number: 17781728

Country of ref document: EP

Kind code of ref document: A1