CN113934362A - Data storage method and device, computer equipment and storage medium - Google Patents

Data storage method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN113934362A
CN113934362A CN202010676941.2A CN202010676941A CN113934362A CN 113934362 A CN113934362 A CN 113934362A CN 202010676941 A CN202010676941 A CN 202010676941A CN 113934362 A CN113934362 A CN 113934362A
Authority
CN
China
Prior art keywords
data
memory
file
memory block
written back
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202010676941.2A
Other languages
Chinese (zh)
Inventor
凌国
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202010676941.2A priority Critical patent/CN113934362A/en
Publication of CN113934362A publication Critical patent/CN113934362A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/064Management of blocks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0619Improving the reliability of storage systems in relation to data integrity, e.g. data losses, bit errors
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device

Abstract

The application relates to a data storage method, a data storage device, computer equipment and a storage medium. The method comprises the following steps: acquiring the memory occupation amount of the memory block; when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine data to be written back in the memory block; acquiring check data corresponding to the data to be written back; writing the check data into a file header of a target file, instantly calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read. By adopting the method, the data to be written back can be written into the file immediately, so that the integrity of the written back data in the written file is improved, and the damage rate of the data in the process of writing back can be effectively reduced.

Description

Data storage method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data storage method and apparatus, a computer device, and a storage medium.
Background
With the rapid development of internet technology, a large amount of data can be processed by various application programs, operating systems, and the like to implement various functions. In data processing, I/O operations, i.e., read operations and/or write operations, are often involved with memory and disk files, etc.
In the current mode, data is usually written into a memory for caching and then written back to a disk file, so as to improve the data read-write performance. However, this approach is typically used by the operating system to determine when to write back data in the memory mapped file, which may not be timely. If the device is powered off or restarted, file damage or data loss may occur.
Disclosure of Invention
Therefore, it is necessary to provide a data storage method, an apparatus, a computer device and a storage medium for solving the above technical problems, which can immediately and effectively write data to be written back into a file, thereby improving the integrity of the write-back data written into the file, and thus effectively reducing the damage rate during the write-back of the data.
A method of data storage, the method comprising:
acquiring the memory occupation amount of the memory block;
when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine data to be written back in the memory block;
acquiring check data corresponding to the data to be written back;
writing the check data into a file header of a target file, instantly calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file;
and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
A data storage device, the device comprising:
the data acquisition module is used for acquiring the memory occupation amount of the memory block;
the data reforming module is configured to perform data reforming on the memory block when the memory occupancy of the memory block reaches a memory threshold, so as to determine data to be written back in the memory block;
the data acquisition module is further used for acquiring check data corresponding to the data to be written back;
the data write-back module is used for writing the check data into a file header of a target file, immediately calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
In one embodiment, the data obtaining module is further configured to obtain a data write request triggered by an application program when the application program writes data to a memory block; the data writing request is used for requesting to write data into the memory block based on the memory mapping file; and analyzing the memory mapping file according to the data writing request to obtain the memory occupation amount of the memory block.
In one embodiment, the memory data in the memory block includes key-value pairs, where the key-value pairs include keys and corresponding values; the data reforming module is further configured to perform deduplication processing on the key value pairs in the memory blocks based on the keys of the key value pairs in the memory blocks, so as to obtain valid data in the memory blocks; and determining the valid data as the data to be written back in the memory block.
In one embodiment, the data reforming module is further configured to obtain an operation record of the memory data in the memory block; according to the operation record, the latest value of the value corresponding to the key word of the key value pair in the memory block after operation is screened out from the memory data; and determining the key word and the corresponding latest value as valid data in the memory block.
In one embodiment, the data obtaining module is further configured to determine a memory occupation value corresponding to the data to be written back; encoding the data to be written back to obtain a check code corresponding to the data to be written back; and generating check data corresponding to the data to be written back based on the memory occupation value and the check code.
In one embodiment, the data write-back module is further configured to immediately call a system function for synchronizing the memory data and the file data after the check data is successfully written into the file header of the target file; determining function parameters corresponding to the system functions based on the data to be written back in the memory blocks; and performing synchronous operation on the data to be written back in the memory block through the system function and the corresponding function parameter so as to write back the data to be written back to the target file.
In one embodiment, the data write-back module is further configured to determine a data sequence and a mapping region of data to be written back in the memory block based on a memory mapping file; and synchronizing the data to be written back to a storage position corresponding to the mapping area in the target file according to the data sequence through the system function and the corresponding function parameter.
In one embodiment, the data storage device further includes a data caching module, configured to obtain a data reading request triggered by an application program when the application program reads data from a target file; according to the data reading request, caching file data corresponding to the data reading request in the target file to the memory block based on a memory mapping file.
In one embodiment, the data storage device further includes a data write module, configured to obtain a write lock of the memory mapped file through a key-value pair storage component; and writing file data into the memory block based on the write lock of the memory mapping file, and releasing the write lock when the writing of the file data is finished.
In one embodiment, the key-value pair storage component is a memory-mapping-based cross-process storage component, and is configured to access key-value pairs corresponding to running processes simultaneously, so as to read the accessed key-value pairs.
In one embodiment, the data storage device further comprises a data reading module, configured to obtain a data reading request triggered by the application program when the application program reads data from the target file again; determining data to be accessed according to the data reading request, and acquiring verification data corresponding to the data to be accessed from a file header of the target file; based on the check data, carrying out data integrity check on the data to be accessed; and after the data integrity check is passed, caching the data to be accessed in the target file to the memory block, and reading the data to be accessed from the memory block.
In one embodiment, the data reading module is further configured to read, through a data storage component, a key-value pair corresponding to data to be accessed in the target file; caching the key value pair corresponding to the data to be accessed into a hash table of the memory block according to the memory sequence of the memory block; and reading a key value pair corresponding to the data to be accessed from a hash table of the memory block based on the data reading request.
A computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
acquiring the memory occupation amount of the memory block;
when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine data to be written back in the memory block;
acquiring check data corresponding to the data to be written back;
writing the check data into a file header of a target file, instantly calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file;
and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
acquiring the memory occupation amount of the memory block;
when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine data to be written back in the memory block;
acquiring check data corresponding to the data to be written back;
writing the check data into a file header of a target file, instantly calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file;
and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
According to the data storage method, the data storage device, the computer equipment and the storage medium, when the application program needs to write data into the memory, the memory occupation amount of the memory block is obtained; and when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine the data to be written back in the memory block and determine the check data corresponding to the data to be written back. And further writing the verification data into a file header of the target file for data integrity verification when the data in the target file is read so as to ensure the integrity of the data. By calling the system function for synchronizing the memory data and the file data in real time, the data to be written back can be effectively written into the file in real time, so that the integrity of the written back data written into the file is improved, and the damage rate and the loss rate of the data in the process of writing back can be effectively reduced.
Drawings
FIG. 1 is a diagram of an exemplary data storage system;
FIG. 2 is a schematic flow chart diagram illustrating a data storage method according to one embodiment;
FIG. 3 is a diagram of storing key values in memory blocks, in one embodiment;
FIG. 4 is a schematic flow chart diagram of a data storage method in another embodiment;
FIG. 5 is a flowchart illustrating the steps of reading data in one embodiment;
FIG. 6 is a flow diagram illustrating a method for storing data in accordance with an exemplary embodiment;
FIG. 7 is a block diagram of a data storage device in one embodiment;
FIG. 8 is a block diagram of a data storage device in another embodiment;
FIG. 9 is a block diagram of a data storage device in yet another embodiment;
FIG. 10 is a diagram showing an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The data storage method provided by the application can be applied to the application environment shown in fig. 1. The application environment in fig. 1 is based on the running environment in the computer device. The computer equipment comprises a disk and a memory, wherein the disk comprises a data storage structure corresponding to a disk file, and the memory comprises a memory block based on memory mapping. When an application program needs to write data into a memory, an operating system acquires the memory occupation amount of a memory block; when the memory occupation amount of the memory block reaches a memory threshold value, the operating system carries out data reformation on the memory block so as to determine the data to be written back in the memory block and determine the check data corresponding to the data to be written back. The operating system further writes the check data into a file header of the target file to ensure the integrity of the data. And immediately calling a system function for synchronizing the memory data and the file data so as to immediately write back the data to be written back to the target file. The computer device may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices.
In one embodiment, as shown in fig. 2, a data storage method is provided, which is described by taking the method as an example applied to a computer device, and comprises the following steps:
s202, the memory occupation amount of the memory block is obtained.
The memory is one of the important components in the computer, and is also called as an internal memory and a main memory, and is a bridge for the external memory to communicate with a Central Processing Unit (CPU). The operation of the memory also determines the stable operation of the computer device. The memory block is a memory space in the memory. The memory occupied capacity refers to the currently occupied capacity in the memory block.
All programs in the computer device are executed in the memory, and the functions of the programs are to temporarily store operation data in the CPU and data exchanged with an external storage such as a hard disk. When the computer equipment is in operation, the operating system transfers data to be operated to the CPU from the memory for operation, the CPU transmits the result after the operation is finished, and the operating system of the computer equipment writes the required data into the memory in the process of operating the application program of the computer equipment. Specifically, an application program running in the computer device applies for a memory space of a mapping file to an operating system, writes required data into the mapped memory space, and the application program is responsible for writing data into a memory, and the operating system completes write-back from the memory to the file, so as to achieve the effect of permanent storage.
When the computer equipment writes data into the memory block, firstly, the memory occupied amount of the memory block is obtained to judge whether the capacity of the memory block can ensure that the data is successfully written.
S204, when the memory occupation amount of the memory block reaches a memory threshold value, performing data reforming on the memory block to determine the data to be written back in the memory block.
Wherein, the write-back refers to updating the multidimensional data set unit value, the member or the member attribute value. The operating system and the application program on the platform need to write temporary data to the disk when running. In the write-back state, data is written to disk only when it is to be evicted from the cache in memory. As the data read by main memory increases, it is necessary to write back the data from the cache to the disk file and write the data updated during operation to the cache. The data to be written back refers to the part of the memory block that needs to be written back to the disk file.
For example, when new data is not sufficiently written in the memory block, it is determined that the memory occupancy of the memory block reaches the memory threshold. The computer device performs data reforming on the memory block to determine the data to be written back in the memory block, so that there is enough space in the memory block to write new memory data.
Specifically, after the computer device obtains the memory occupancy amount of the memory block, when it is identified that the memory occupancy amount of the memory block reaches the memory threshold, it indicates that data in the memory block needs to be written back at this time, so as to vacate a sufficient memory space in the memory block for writing new data. The computer device carries out data reforming on the memory block, and then determines data to be written back in the memory block according to the reformed data. The data to be written back may be all the memory data reformed in the memory block, or may be a specified part of the memory data, for example, a part of the memory data that needs to be written back may be specified according to the data capacity or the storage time point.
In one embodiment, after the computer device performs data reformation on the memory data in the memory block, the memory occupancy of the memory block still reaches the memory threshold, which indicates that the memory space of the memory block is still insufficient. The computer device doubles the memory capacity of the memory block until the memory space of the memory block is sufficient for writing new data.
And S206, acquiring the check data corresponding to the data to be written back.
The data check is a verification operation performed to ensure the integrity of the data. Usually, a designated algorithm is used to calculate a check value for the original data, and the receiver calculates a check value once using the same algorithm, and if the check values obtained by the two calculations are the same, it indicates that the data is complete. For example, the data check may include parity check, crc (cyclic Redundancy check) cyclic Redundancy check, MD5 check, and data signature.
The check data corresponding to the data to be written back represents check data obtained after data check processing is performed on the data to be written back. Each item of data to be written back in the data to be written back respectively comprises a corresponding item of check data so as to respectively carry out data integrity check on each item of specific data.
The check data corresponding to the data to be written back may only include the check code of the data to be written back. In another embodiment, the check data may also include a memory size and a check code of the data to be written back.
Specifically, the computer device performs data check calculation on the data to be written back, so that a check code corresponding to the data to be written back can be obtained, and the check code obtained through calculation is used as check data of the data to be written back. Therefore, when the part of data to be written back is read subsequently, the data integrity check can be effectively carried out on the data to be written back.
S208, writing the check data into a file header of the target file, immediately calling a system function for synchronizing the memory data and the file data, and writing the data to be written back to the target file; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
The target file refers to a disk file in computer equipment, and is a data storage structure for organizing, storing and naming file data. There exists a corresponding file system in the computer system, which is the format for storing information on the hard disk, and specifies various standards and mechanisms for operating and processing files by the computer device. The stored information in the disk file is not influenced by factors such as power failure and the like.
Files in the disk are usually stored in the form of files, and the disk files usually include a file header and a block table structure. Wherein, the total number of data in the block table structure is specified by data in the file header, the data in the file header defines the alignment value of the disk block for mapping the storage position of the data in the file, and each block is stored from the offset position of the multiple of the alignment value.
The system function for synchronizing the memory data and the file data means that the function can be called to achieve consistency between the contents of the disk file and the contents of the shared memory area, that is, to achieve synchronous operation between the memory data in the memory and the file data in the disk file. For example, the system function may be a refresh change function, i.e., msync () function.
Specifically, after obtaining the check data of the data to be written back, the computer device writes the check data corresponding to the data to be written back into the file header of the target file in the disk. After the verification data is successfully written into the file header of the target file, the computer device immediately calls a system function for synchronizing the memory data and the file data, and synchronizes the data to be written back in the memory block to the target file of the disk through the system function, so that the data to be written back can be immediately and effectively written back to the target file.
Further, after the computer device writes the data to be written back in the memory block back to the target file of the disk, the check data in the file header is used for performing data integrity check when reading the data in the target file. Specifically, when the computer device accesses the part of data again, the check data corresponding to the part of data to be accessed in the file header is read first, and the check result is obtained by analyzing the check data, so that the check result can judge the integrity of the data to be accessed, which needs to be obtained. And when the verification result of the data to be accessed is determined to be data integrity, reading the corresponding data to be accessed from the file, thereby ensuring the integrity of the data.
In the data storage method, when an application program of the computer equipment needs to write data into the memory, the memory occupation amount of the memory block is obtained; and when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine the data to be written back in the memory block and determine the check data corresponding to the data to be written back. The computer equipment further writes the verification data into a file header of the target file, and is used for carrying out data integrity verification when the data in the target file is read so as to ensure the integrity of the data; the computer equipment calls a system function for synchronizing the memory data and the file data in real time and writes the data to be written back to the target file, so that the data to be written back can be effectively written into the file in real time, the integrity of the data written back in the file is improved, and the damage rate and the loss rate of the data in the write back process can be effectively reduced.
In one embodiment, the obtaining the memory occupancy of the memory block includes: when an application program writes data into a memory block, acquiring a data writing request triggered by the application program; the data writing request is used for requesting to write data into the memory block based on the memory mapping file; and analyzing the memory mapping file according to the data writing request to obtain the memory occupation amount of the memory block.
The memory mapping file refers to a mapping from a file to a memory, so that an application program processes the file as accessing the memory. The computer device may pre-construct the memory mapping file according to a preset rule. The memory mapping file is responsible for a memory management program of the operating system, so that the application program only needs to write the content into the memory and is handed over to the operating system to complete the write-back operation from the memory to the file, and the data loss possibly caused by program exit cannot be caused.
The operating system provides functions that allow an application to map files to a process. Memory mapped files are similar to virtual memory in that a region of address space can be reserved by a memory mapped file, with physical storage committed to this region, the physical storage mapped by the memory file being from a file already on disk, and the file needs to be mapped first before the file can be operated on. Specifically, the memory mapping file may be pre-constructed through a memory mapping function. For example, a mmap () function may be used to map file data into a memory through the mmap () function, and the mmap () system calls the function to realize memory sharing between processes through mapping the same common file.
And when the application program runs, applying the memory space of the mapping file to the operating system, and distributing the memory space to the application program by the operating system. The memory space allocated by the operating system may be composed of memory blocks, each memory block may be represented by a memory start address + a memory offset, and shared data written by a process to a memory mapping file may occupy one memory block or several memory blocks.
When an application program running in the computer device writes data into a memory block, the application program initiates a data write request to the memory. The computer device detects the memory occupancy of the memory block at this time to determine whether data write back processing is required. Specifically, the computer device analyzes the memory mapping file to obtain a mapping relationship between the file and the memory, so as to determine data mapped in the memory block, for example, shared data read in the memory block by each process, and thus, the memory occupancy of the data in the current memory block can be determined.
In this embodiment, when the application writes data into the memory block, it is determined whether to perform data write-back processing, so that the data in the memory can be written back in time. Rather than the operating system determining when to write back the data completely, the operating system may determine when to write back the data if it is determined to write back the data in a non-timely manner. By calling the system function for synchronizing the memory data and the file data in real time, the data to be written back can be written into the file in real time and effectively, and therefore the damage rate and the loss rate of the file data in the process of writing back can be reduced effectively.
In one embodiment, the memory data in the memory block includes key-value pairs, which include keys and corresponding values; performing data reforming on the memory block to determine data to be written back in the memory block, including: based on the key words of the key value pairs in the memory blocks, carrying out duplication removal processing on the key value pairs in the memory blocks to obtain effective data in the memory blocks; and determining the valid data as the data to be written back in the memory block.
The key-value pair storage is a simpler organization form of the database, namely a key-value pair. key is a key and value is a value, also known as a key-key value pair. Wherein a key, i.e. a key, refers to the number of the stored data value; the corresponding value refers to the data to be stored. The data is stored according to key value pairs, and corresponding values can be read, stored and updated by accessing the specified keys.
When the computer equipment carries out data reforming on the memory data in the memory block, carrying out data reforming according to the key value of the memory data. Specifically, the computer device determines whether a duplicate or redundant value exists in a value corresponding to a key according to the key of each key-value pair in the memory block. And if the repeated or redundant value exists, performing deduplication processing on the corresponding key word and the corresponding value according to the key word. And the computer equipment determines the valid data as the data to be written back in the memory block so as to write back the data.
In this embodiment, by performing the reforming processing on the memory data in the memory block, the invalid data in the memory block can be effectively cleared, so as to accurately perform the write-back processing on the valid data, thereby ensuring the validity and accuracy of the data to be written back in the memory block.
In one embodiment, the performing deduplication processing on key-value pairs in a memory block based on keys of the key-value pairs in the memory block to obtain valid data in the memory block includes: acquiring operation records of memory data in the memory block; according to the operation record, screening out the latest value of the value corresponding to the key word of the key value pair in the memory block after operation from the memory data; the key and the corresponding latest value are determined as valid data in the memory block.
The operation record refers to an operation trace of the memory data in the memory block, and the operation record may include recorded data of operation modes such as adding, deleting, modifying, and searching data.
Specifically, the computer device may obtain an operation record of the memory data in the memory block during the data reforming process of the memory data in the memory block. The operation records reflect which operation processing is performed on the accessed memory data by the user in the running process of the application program. The computer equipment can identify effective data in the memory data according to the operation record. Since the operation records reflect all records of the memory data, there may be duplicate or redundant data in the memory data after the operation. And the computer equipment screens out the latest value of the value corresponding to the key word of the key value pair in the memory block after operation from the memory data according to the operation record, and determines the key word and the corresponding latest value as effective data in the memory block, thereby effectively filtering out repeated or redundant data in the memory block.
Fig. 3 is a diagram illustrating key values stored in memory blocks in one embodiment. Referring to fig. 3, key1 and value1 are one key-value pair, and key2 and value2, key1 and value11, and key1 and value12 are key-value pair data respectively responding to. The key1 corresponds to three pieces of key-value pair data, and the value12 is the latest value corresponding to the key1 after operation, so that after data reformation, only the latest key of the key1 and the value12 and the corresponding latest value are reserved, and the key-value pair is determined as valid data.
For example, when data is updated, if a new data insertion manner is adopted, for the same key, there may be several key values in the memory, and only the last key value in the memory is the latest and valid key value, so that when a read operation is performed, only the last key value is taken as valid data. That is, when data is read, for any key, if a plurality of key values corresponding to the key are stored in the memory mapping file, the key value with the largest memory offset is read as the key value corresponding to the key.
And after the insertion or updating operation of the application program is completed, the computer device takes the last written value of each key as a valid value and then writes all valid key-value key value pairs back to the disk file. Therefore, invalid key-value key value pair data can be effectively removed, and corresponding memory space can be vacated in the memory block.
In this embodiment, by performing a reforming process on the memory data in the memory block, the keyword and the corresponding latest value are determined as valid data in the memory block, so that repeated or redundant data in the memory block can be effectively filtered, and thus the write-back process can be further performed on the valid data accurately.
In one embodiment, obtaining the check data corresponding to the data to be written back includes: determining a memory occupation numerical value corresponding to data to be written back; encoding data to be written back to obtain a check code corresponding to the data to be written back; and generating check data corresponding to the data to be written back based on the memory occupation value and the check code.
The memory occupation value refers to the memory size of each item of data, that is, the size of the data, that is, the number of bytes occupied by the data.
When the computer device writes back data to be written back in the memory block, a memory occupation value corresponding to the data to be written back needs to be calculated. The computer equipment further encodes the data to be written back so as to calculate a check code corresponding to the data to be written back. Specifically, the computer device may encode the data to be written back by using a CRC32 cyclic redundancy check method, calculate to obtain a corresponding CRC32 check value, and use the CRC32 check value as a check code corresponding to the data to be written back.
After the computer equipment calculates the memory occupation data and the check code corresponding to the data to be written back, the memory occupation value and the check code are jointly used as the check data corresponding to the data to be written back, and therefore the check data corresponding to the data to be written back is generated.
In this embodiment, the memory occupancy value and the check code are determined as the check data corresponding to the data to be written back, so that the check data corresponding to the data to be written back is written into the file header of the target file, and thus the storage location of the data to be written back in the target file can be effectively mapped, and the data can be effectively guaranteed to be successfully written back into the target file.
In one embodiment, writing the verification data into a header of the target file, and immediately calling a system function for synchronizing the memory data and the file data, and writing back the data to be written back to the target file includes: after the verification data is successfully written into the file header of the target file, immediately calling a system function for synchronizing the memory data and the file data; determining function parameters corresponding to system functions based on data to be written back in the memory blocks; and performing synchronous operation on the data to be written back in the memory block through the system function and the corresponding function parameter so as to write back the data to be written back to the target file.
The system function for synchronizing the memory data and the file data further comprises corresponding function parameters. The function parameters corresponding to the system function can be configured in advance, and can also be configured according to the attribute of the data to be written back during calling, so that the system function can be effectively called, and the synchronous operation of the memory data and the file data can be accurately realized. For example, the function parameters may include parameters such as a memory region returned during memory mapping, a length specified during memory mapping, and a synchronization method between a memory and a disk.
After the computer equipment acquires the check data corresponding to the data to be written back, the check data corresponding to the data to be written back is written into a file header of a target file for verifying the integrity of the data so as to ensure the integrity and the validity of the data written into the file.
When the check data corresponding to the data to be written back is successfully written into the file header of the target file, the computer device immediately calls a system function for synchronizing the memory data and the file data, and determines a function parameter corresponding to the system function according to the data to be written back. The function parameters can be automatically configured by an operating system according to the attribute information of the data to be written back. The computer device further synchronizes the data to be written back in the memory block to the target file by calling the system function and the corresponding function parameter, so that the synchronous operation of the memory data and the file data is realized, and the data to be written back can be immediately and effectively written back to the target file.
In this embodiment, after the data to be written back in the memory block is determined, and the check data of the data to be written back is written into the file header of the target file, the system function for synchronizing the memory data and the file data is called immediately, and the data to be written back is synchronized into the target file, so that the data to be written back can be effectively written back into the target file in time, the integrity of the data to be written back in the file is effectively improved, and the damage rate of the file data is effectively reduced.
In one embodiment, the synchronizing operation is performed on the data to be written back in the memory block through the system function and the corresponding function parameter to write back the data to be written back to the target file, and the method includes: determining a data sequence and a mapping area of data to be written back in a memory block based on a memory mapping file; and synchronizing the data to be written back to a storage position corresponding to the mapping area in the target file according to the data sequence through the system function and the corresponding function parameter.
The data sequence refers to a sequence of corresponding memory locations of the memory data in the memory block, and the data sequence may be a sequence obtained by performing data reformation on the memory data in the memory block. The mapping region refers to a mapping position region of file data and memory data, and refers to one-to-one correspondence between the position of a file on a disk and a same region in a process logic address space. When the memory mapping file is constructed, the related data structure and the mapping area are established and initialized.
The memory reforming serial number stored in the memory mapping file can be a first memory reforming serial number, and the memory reforming serial number cached in the process can be a second memory reforming serial number. After the data in the memory block is reformed, the memory reforming sequence number is incremented. Thus, each process can determine whether other processes trigger memory reforming by comparing the first memory reforming sequence number with the second memory reforming sequence number.
In one embodiment, when the process finds that the memory is reset, the data synchronization operation of the process can be triggered. Specifically, each process may compare the cached second memory reforming serial number with the cached first memory reforming serial number, and reload all shared data stored in the memory mapped file into the cache if the second memory reforming serial number is different from the first memory reforming serial number.
And when the computer equipment performs synchronous operation on the data to be written back through a system function for synchronizing the memory data and the file data, determining a data sequence and a mapping area of the data to be written back according to the memory mapping file. And further synchronizing the data to be written back to a storage position corresponding to the mapping area in the target file according to the data sequence.
In this embodiment, the data to be written back is synchronized to the storage location corresponding to the mapping region in the target file according to the data sequence by the system function for synchronizing the memory data and the file data, so that the data to be written back can be accurately and effectively written back to the corresponding file region from the memory region.
In an embodiment, as shown in fig. 4, another data storage method is provided, which specifically includes the following steps:
s402, when the application program reads data from the target file, acquiring a data reading request triggered by the application program.
S404, according to the data reading request, caching file data corresponding to the data reading request in the target file to a memory block based on the memory mapping file.
S406, the memory occupation amount of the memory block is obtained.
S408, when the memory occupation amount of the memory block reaches a memory threshold value, performing data reforming on the memory block to determine the data to be written back in the memory block.
S410, check data corresponding to the data to be written back are obtained.
S412, writing the check data into a file header of the target file, immediately calling a system function for synchronizing the memory data and the file data, and writing the data to be written back to the target file; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
The data reading request refers to a reading request triggered by an application program requesting to read data from a disk file through an operating system when the computer device runs the application program.
When an application program accesses file data, an operating system of computer equipment firstly maps data to be accessed from a file system structure based on a data reading request triggered by the application program, and calls the data to be accessed from a disk into a memory according to byte offset of the data to be accessed.
Specifically, the operating system of the computer device determines data attribute information such as byte offset, data length, and data position of the data to be accessed according to the data reading request, and can find the physical address of the data to be accessed in the disk file through the memory mapping file. And the operating system sends an instruction to the disk, reads out the corresponding data to be accessed from the disk, and maps the data to be accessed to the corresponding memory area in the corresponding memory block according to the data attribute information, so that the data to be accessed is cached in the memory.
And after the application program accesses the data or writes the data into the memory, when the progress of the computer equipment writes the data into the memory again, acquiring the memory occupation amount of the memory block. And when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine the data to be written back in the memory block, and further performing write back on the data to be written back in the memory block.
In this embodiment, when the application program accesses data in operation, the operating system first caches the data to be accessed from the disk into the memory, so that the application program directly reads the corresponding data to be accessed from the memory, thereby effectively improving the data access efficiency.
In one embodiment, according to a data reading request, caching file data corresponding to the data reading request in a target file to a memory block based on a memory mapping file, and obtaining a write lock of the memory mapping file through a key value pair storage component; and writing the file data into the memory block based on the write lock of the memory mapping file, and releasing the write lock when the writing of the file data is finished.
The key-value pair storage component is a data storage component for storing key-value pairs, and may be, for example, an MMKV component, and can enable simultaneous access to multiple processes.
File locks are a technique for implementing synchronization restrictions of access to multiple processes, and are classified into shared locks (also called read locks) and mutually exclusive locks (also called write locks). When a process adds a mutual exclusion lock to a certain area of a file, other processes must wait for the process to unlock to obtain the access authority of the file area; when a process adds a shared lock to a certain area of a file, other processes can obtain the shared lock of the area but cannot obtain a mutual exclusion lock.
And mapping the file data to the memory by an operating system of the computer equipment so as to write the data into the memory block through the key value pair storage component when the data is written into the memory block.
Specifically, when the application program writes data into the memory block corresponding to the memory mapping file in the running process, the application program applies for the memory space of the mapping file from the operating system, and the operating system allocates the memory space to the application program. Before writing data into a memory mapping file, a process in an application program needs to apply for a write lock of the memory mapping file to an operating system first, that is, the memory mapping file is added with a write lock, after the operating system receives a request of the process, a memory block corresponding to an operating area applied by the process can be identified as a write operation, if other processes apply for a read lock or a write lock to the same area to the operating system during the process writing data, the operating system rejects the application until the previous process releases the write lock of the area. That is to say, after a process obtains a write lock of a certain area in the memory mapped file, other processes need to wait for the process to unlock to obtain an access right of the corresponding area, that is, a read lock or a write lock of the area can be obtained.
After obtaining the write lock of a certain operation region of the memory mapped file, the process may write the shared data into the memory mapped file. If the process fails to acquire the write lock of an operation area of the memory mapping file, it indicates that other processes acquire the write lock or the read lock of the area, and the process needs to wait for the other processes to release the write lock of the area and then apply for acquiring the write lock of the area from the system. After the process completes the data writing operation to a certain area of the memory mapping file, the corresponding write lock is released, so that other processes can access the area.
When writing the shared data into the memory mapping file, the shared data may be sequentially inserted into the memory mapping file according to the sequence of writing the shared data. The newly added data is sequentially written into the memory according to the increasing sequence of the memory offset.
In this embodiment, the key-value pair storage component writes file data into the memory block based on the memory mapped file and the file lock, so that the data can be efficiently written into the memory.
In one embodiment, the key-value pair storage component is a memory-mapping-based cross-process storage component, and is configured to access key-value pairs corresponding to running processes simultaneously, so as to read the accessed key-value pairs.
The key-value pair storage component may also be a memory mapping-based cross-process storage component, for example, may be an MMKV component, and the MMKV component is a key-value component based on mmap memory mapping. The storage component can be accessed by a plurality of processes at the same time, and the data update generated by one process can be effective to a plurality of processes at the same time. Therefore, the key value pairs corresponding to the running processes can be accessed simultaneously, and the accessed key value pairs are read.
In the embodiment, the cross-process storage assembly based on the memory mapping is adopted for data reading, so that the multi-process data access operation can be supported, and the data reading efficiency is effectively improved.
In one embodiment, after the data to be written back is written back to the target file, the data storage method further includes: when the application program reads data from the target file again, acquiring a data reading request triggered by the application program; determining data to be accessed according to the data reading request, and acquiring verification data corresponding to the data to be accessed from a file header of a target file; based on the check data, carrying out data integrity check on the data to be accessed; and after the data integrity check is passed, caching the data to be accessed in the target file into the memory block, and reading the data to be accessed from the memory block.
And the verification data is used for verifying the integrity of the data when the corresponding data is accessed again so as to verify the integrity and the validity of the part of data.
After the memory data in the memory block is written back to the disk file, when the application program accesses the data again, the operating system still calls the data to be accessed from the disk to the memory first, so as to cache the data to be accessed into the memory. And the application program reads the corresponding data to be accessed from the memory.
Specifically, when an operating system of the computer device reads data to be accessed from a target file of a disk, a data reading request triggered by an application program, and after determining the data to be accessed according to the data reading request, the operating system in the computer device first obtains verification data corresponding to the data to be accessed from a file header of the target file. And the computer equipment further performs data integrity correction on the data to be accessed according to the check data so as to judge whether the data to be accessed is complete. When the data integrity check is passed, it indicates that the part of the data to be accessed is complete and accurate.
The computer device further caches the data to be accessed in the target file to the memory block, so that when the application program reads the data to be accessed, the application program can directly and quickly read the required data to be accessed from the memory block.
In this embodiment, the check data corresponding to the data to be written back is written into the file header of the target file, so that when the computer device accesses the data again, the integrity of the data can be effectively checked, thereby effectively ensuring the integrity of the data.
In an embodiment, as shown in fig. 5, a schematic flow chart of a step of reading data in an embodiment specifically includes the following steps:
s502, when the application program reads the data from the target file again, acquiring a data reading request triggered by the application program.
S504, determining the data to be accessed according to the data reading request, and acquiring the verification data corresponding to the data to be accessed from the file header of the target file.
S506, based on the check data, data integrity check is carried out on the data to be accessed.
And S508, after the data integrity is verified, reading the key value pair corresponding to the data to be accessed in the target file through the data storage component.
And S510, caching the key value pair corresponding to the data to be accessed into the hash table of the memory block according to the memory sequence of the memory block.
S512, based on the data reading request, reading a key value pair corresponding to the data to be accessed from the hash table of the memory block.
The memory sequence is an organization mode of data in the memory space, that is, a data sequence created when data is written into the memory.
When an application program process in the computer equipment accesses data, firstly, corresponding data to be accessed in a target file is determined according to a mapping relation corresponding to a memory mapping file, and data integrity correction is carried out on the data to be accessed according to verification data. After the verification is passed, the computer equipment reads the key value pair corresponding to the data to be accessed in the target file through the built data storage assembly, and caches the data to be accessed in the target file to the memory block. When the operating system of the computer device caches the data to be accessed to the memory, a memory sequence of the data to be accessed in the memory is created according to the current storage condition of the memory block, and then the key value pair corresponding to the data to be accessed is cached to the hash table of the memory block according to the memory sequence of the memory block.
Further, for a data reading request triggered by the application program, the application program may directly read the key value pair corresponding to the data to be accessed from the hash table of the memory block. Because the access speed of the data in the memory is higher than that of the disk file, the application program can quickly and effectively read the data from the memory when running.
For example, when an application program process in the computer device reads data for the first time after starting, the whole file data mmap to be accessed is first mapped to the memory, that is, the file data mmap is mapped to the memory. And then, carrying out data integrity check according to the check data of the file data, namely the memory size and the CRC32 check code. And if the verification is passed, reading each key-value key value pair corresponding to the file data according to the memory sequence, and caching the key-value key value pair into a hash table of the memory.
When the application program accesses each key-value data subsequently, the corresponding key-value pair is directly found from the hash table. Before the data cached in the memory block is written back to the disk file, if the application program accesses the corresponding key-value data again, the corresponding key-value pair can still be directly found from the hash table to read the required data.
In this embodiment, after verifying the check data of the data to be accessed, the check data is cached in the hash table of the memory, so that the application program directly accesses the required data from the hash table of the memory block when reading the data, and thus the required complete data can be obtained efficiently by fast reading.
In a specific embodiment, as shown in fig. 6, a specific data storage method is provided, which includes the following steps:
s602, when an application program writes data into a memory block, acquiring a data writing request triggered by the application program; the data write request is used for requesting to write data into the memory block based on the memory mapping file.
S604, analyzing the memory mapping file according to the data writing request, and obtaining the memory occupation amount of the memory block.
S606, when the memory occupation amount of the memory block reaches a memory threshold value, based on the operation record of obtaining the memory data in the memory block; the memory data in the memory block includes key-value pairs including keys and corresponding values.
S608, according to the operation record, the latest value after the operation of the value corresponding to the key word of the key value pair in the memory block is screened out from the memory data.
S610, determining the key word and the corresponding latest value as valid data in the memory block.
S612, determining a memory occupation value corresponding to the data to be written back.
And S614, encoding the data to be written back, and obtaining the check code corresponding to the data to be written back.
And S616, generating verification data corresponding to the data to be written back based on the memory occupation value and the verification code.
S618, after the verification data is successfully written into the file header of the target file, immediately calling a system function for synchronizing the memory data and the file data; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
S620, determining function parameters corresponding to the system function based on the data to be written back in the memory block.
S622, determining a data sequence and a mapping region of the data to be written back in the memory block based on the memory mapping file.
And S624, synchronizing the data to be written back to a storage position corresponding to the mapping area in the target file according to the data sequence through the system function and the corresponding function parameter.
In this embodiment, when an application program of a computer device needs to write data into a memory, the memory occupancy of a memory block is obtained; when the memory occupation amount of the memory block reaches a memory threshold value, data to be written back in the memory block is determined and check data corresponding to the data to be written back is determined by carrying out data reformation on the memory block. The computer equipment further writes the check data into a file header of the target file, synchronizes the data to be written back to the target file by instantly calling a system function for synchronizing the memory data and the file data, so that the data to be written back can be instantly and effectively written into the file, the integrity of the data to be written back in the file is improved, and the damage rate of the file can be effectively reduced.
The application also provides an application scenario applying the data storage method. Specifically, the application of the data storage method in the application scenario is as follows:
the computer equipment is internally provided with an Android operating system and an Android application program, and the Android application program runs a corresponding process through the Android operating system to access data and write in or read out the data.
When the Android application program writes data into the memory, the memory space of the mapping file is applied to the Android operating system, the Android operating system allocates the memory space to the application program, all processes in the Android application program share the memory space allocated by the Android operating system, and each process can write data into the memory space allocated by the Android operating system or read data from the memory space, so that the support of multi-process data access is realized.
Further, in the process that the Android application program writes data into the memory, the memory occupation amount of the memory block is also obtained; when the memory occupation amount of the memory block reaches a memory threshold value, an Android operating system of the computer device performs data reformation on the memory block to determine data to be written back in the memory block, and acquires check data corresponding to the data to be written back. And the Android operating system further writes the verification data into a file header of the target file, wherein the verification data in the file header is used for verifying the integrity of the data when the data in the target file is read. The Android operating system immediately calls a system function for synchronizing the memory data and the file data to immediately write back the data to be written back to the target file, so that the data can be effectively ensured to be immediately and completely written back to the target file, the integrity of the written-back data in the written-in file is effectively improved, and the damage rate of the data in the write-back process can be effectively reduced.
The application further provides an application scenario applying the data storage method. Specifically, the application of the data storage method in the application scenario is as follows:
the computer equipment is provided with an iOS operating system and an iOS application program, and the iOS application program runs a corresponding process through the iOS operating system to access data and realize the writing or reading of the data.
When the iOS application program writes data into the memory, the iOS operating system is applied for the memory space of the mapping file, the iOS operating system is allocated to the application program, all processes in the iOS application program share the memory space allocated by the iOS operating system, and each process can write data into the memory space allocated by the iOS operating system or read data from the memory space, so that the support of multi-process data access is realized.
Further, in the process that the iOS application program writes data into the memory, the memory occupation amount of the memory block is also obtained; when the memory occupation amount of the memory block reaches a memory threshold value, the iOS operating system of the computer device performs data reformation on the memory block to determine the data to be written back in the memory block, and acquires check data corresponding to the data to be written back. And the iOS operating system further writes the verification data into a file header of the target file, wherein the verification data in the file header is used for performing data integrity verification when the data in the target file is read. The iOS operates the system and immediately calls a system function for synchronizing the memory data and the file data so as to immediately write back the data to be written back to the target file, thereby effectively ensuring that the data is immediately and completely written back to the target file, effectively improving the integrity of the written back data in the written file, and further effectively reducing the damage rate of the data in the process of writing back.
It should be understood that although the steps in the flowcharts of fig. 2, 4, 5, and 6 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2, 4, 5, and 6 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least some of the other steps.
In one embodiment, as shown in fig. 7, a data storage device 700 is provided, which may be a part of a computer device using software modules or hardware modules, or a combination of the two modules, and specifically includes: a data acquisition module 702, a data reforming module 704, and a data write-back module 706, wherein:
a data obtaining module 702, configured to obtain a memory occupancy amount of the memory block;
a data reforming module 704, configured to reform data of the memory block when the memory occupancy of the memory block reaches a memory threshold, so as to determine data to be written back in the memory block;
the data obtaining module 702 is further configured to obtain check data corresponding to the data to be written back;
the data write-back module 706 is configured to write the check data into a file header of the target file, immediately call a system function for synchronizing the memory data and the file data, and write back the data to be written back to the target file; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
In one embodiment, the data obtaining module 702 is further configured to obtain a data write request triggered by an application when the application writes data to a memory block; the data writing request is used for requesting to write data into the memory block based on the memory mapping file; and analyzing the memory mapping file according to the data writing request to obtain the memory occupation amount of the memory block.
In one embodiment, the memory data in the memory block includes key-value pairs, which include keys and corresponding values; the data reforming module 704 is further configured to perform deduplication processing on key values in the memory block based on the key words of the key values in the memory block, so as to obtain valid data in the memory block; and determining the valid data as the data to be written back in the memory block.
In one embodiment, the data reforming module 706 is further configured to obtain an operation record of the memory data in the memory block; according to the operation record, screening out the latest value of the value corresponding to the key word of the key value pair in the memory block after operation from the memory data; the key and the corresponding latest value are determined as valid data in the memory block.
In one embodiment, the data obtaining module 702 is further configured to determine a memory usage value corresponding to data to be written back; encoding data to be written back to obtain a check code corresponding to the data to be written back; and generating check data corresponding to the data to be written back based on the memory occupation value and the check code.
In one embodiment, the data write-back module 706 is further configured to immediately call a system function for synchronizing the memory data and the file data after the check data is successfully written into the file header of the target file; determining function parameters corresponding to system functions based on data to be written back in the memory blocks; and performing synchronous operation on the data to be written back in the memory block through the system function and the corresponding function parameter so as to write back the data to be written back to the target file.
In one embodiment, the data write-back module 706 is further configured to determine a data sequence and a mapping region of data to be written back in the memory block based on the memory mapping file; and synchronizing the data to be written back to a storage position corresponding to the mapping area in the target file according to the data sequence through the system function and the corresponding function parameter.
In an embodiment, the data storage device further includes a data caching module, configured to obtain a data reading request triggered by the application program when the application program reads data from the target file; according to the data reading request, caching file data corresponding to the data reading request in the target file to the memory block based on the memory mapping file.
In an embodiment, as shown in fig. 8, the data storage device 700 further includes a data writing module 701, configured to obtain a write lock of the memory mapped file through the key-value pair storage component; and writing the file data into the memory block based on the write lock of the memory mapping file, and releasing the write lock when the writing of the file data is finished.
In one embodiment, the key-value pair storage component is a memory-mapping-based cross-process storage component, and is configured to access key-value pairs corresponding to running processes simultaneously, so as to read the accessed key-value pairs.
In one embodiment, as shown in fig. 9, the data storage device 700 further includes a data reading module 708, configured to obtain a data reading request triggered by the application program when the application program reads data from the target file again; determining data to be accessed according to the data reading request, and acquiring verification data corresponding to the data to be accessed from a file header of a target file; based on the check data, carrying out data integrity check on the data to be accessed; and after the data integrity check is passed, caching the data to be accessed in the target file into the memory block, and reading the data to be accessed from the memory block.
In one embodiment, the data reading module 708 is further configured to read, through the data storage component, a key-value pair corresponding to data to be accessed in the target file; caching the key value pair corresponding to the data to be accessed into a hash table of the memory block according to the memory sequence of the memory block; and reading a key value pair corresponding to the data to be accessed from the hash table of the memory block based on the data reading request.
For specific limitations of the data storage device, reference may be made to the above limitations of the data storage method, which are not described herein again. The various modules in the data storage device described above may be implemented in whole or in part by software, hardware, and combinations thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 10. The computer device includes a processor, a memory, a communication interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless communication can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a data storage method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 10 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is further provided, which includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above method embodiments when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, in which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method embodiments.
In one embodiment, a computer program product or computer program is provided that includes computer instructions stored in a computer-readable storage medium. The computer instructions are read by a processor of a computer device from a computer-readable storage medium, and the computer instructions are executed by the processor to cause the computer device to perform the steps in the above-mentioned method embodiments.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical storage, or the like. Volatile Memory can include Random Access Memory (RAM) or external cache Memory. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (15)

1. A method of data storage, the method comprising:
acquiring the memory occupation amount of the memory block;
when the memory occupation amount of the memory block reaches a memory threshold value, performing data reformation on the memory block to determine data to be written back in the memory block;
acquiring check data corresponding to the data to be written back;
writing the check data into a file header of a target file, instantly calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file;
and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
2. The method according to claim 1, wherein the obtaining the memory occupancy of the memory block comprises:
when an application program writes data into a memory block, acquiring a data writing request triggered by the application program; the data writing request is used for requesting to write data into the memory block based on the memory mapping file;
and analyzing the memory mapping file according to the data writing request to obtain the memory occupation amount of the memory block.
3. The method according to claim 1, wherein the memory data in the memory blocks comprises key-value pairs, the key-value pairs comprising keys and corresponding values;
the performing data reforming on the memory block to determine the data to be written back in the memory block includes:
based on the key words of the key value pairs in the memory blocks, carrying out deduplication processing on the key value pairs in the memory blocks to obtain effective data in the memory blocks;
and determining the valid data as the data to be written back in the memory block.
4. The method according to claim 3, wherein the performing deduplication processing on the key-value pairs in the memory block based on the keys of the key-value pairs in the memory block to obtain valid data in the memory block includes:
acquiring an operation record of memory data in the memory block;
according to the operation record, the latest value of the value corresponding to the key word of the key value pair in the memory block after operation is screened out from the memory data;
and determining the key word and the corresponding latest value as valid data in the memory block.
5. The method according to claim 1, wherein the obtaining of the check data corresponding to the data to be written back comprises:
determining a memory occupation numerical value corresponding to the data to be written back;
encoding the data to be written back to obtain a check code corresponding to the data to be written back;
and generating check data corresponding to the data to be written back based on the memory occupation value and the check code.
6. The method according to claim 1, wherein writing the check data into a header of a target file and immediately calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file comprises:
after the verification data is successfully written into the file header of the target file, immediately calling a system function for synchronizing the memory data and the file data;
determining function parameters corresponding to the system functions based on the data to be written back in the memory blocks;
and performing synchronous operation on the data to be written back in the memory block through the system function and the corresponding function parameter so as to write back the data to be written back to the target file.
7. The method according to claim 6, wherein the synchronizing the data to be written back in the memory block through the system function and the corresponding function parameter to write back the data to be written back to the target file comprises:
determining a data sequence and a mapping area of data to be written back in the memory block based on a memory mapping file;
and synchronizing the data to be written back to a storage position corresponding to the mapping area in the target file according to the data sequence through the system function and the corresponding function parameter.
8. The method of claim 1, wherein before the writing the data to be written back to the target file, the method further comprises:
when an application program reads data from a target file, acquiring a data reading request triggered by the application program;
according to the data reading request, caching file data corresponding to the data reading request in the target file to the memory block based on a memory mapping file.
9. The method of claim 1, further comprising:
obtaining a write lock of the memory mapping file through a key value pair storage component;
and writing file data into the memory block based on the write lock of the memory mapping file, and releasing the write lock when the writing of the file data is finished.
10. The method according to claim 9, wherein the key-value pair storage component is a memory-mapping-based cross-process storage component, and is configured to access key-value pairs corresponding to the running processes simultaneously, so as to read the accessed key-value pairs.
11. The method according to any one of claims 1 to 10, wherein after the writing back the data to be written back to the target file, the method further comprises:
when the application program reads data from the target file again, acquiring a data reading request triggered by the application program;
determining data to be accessed according to the data reading request, and acquiring verification data corresponding to the data to be accessed from a file header of the target file;
based on the check data, carrying out data integrity check on the data to be accessed;
and after the data integrity check is passed, caching the data to be accessed in the target file to the memory block, and reading the data to be accessed from the memory block.
12. The method according to claim 11, wherein the caching the data to be accessed in the target file to the memory block and reading the data to be accessed from the memory block includes:
reading a key value pair corresponding to data to be accessed in the target file through a data storage component;
caching the key value pair corresponding to the data to be accessed into a hash table of the memory block according to the memory sequence of the memory block;
and reading a key value pair corresponding to the data to be accessed from a hash table of the memory block based on the data reading request.
13. A data storage device, characterized in that the device comprises:
the data acquisition module is used for acquiring the memory occupation amount of the memory block;
the data reforming module is configured to perform data reforming on the memory block when the memory occupancy of the memory block reaches a memory threshold, so as to determine data to be written back in the memory block;
the data acquisition module is further used for acquiring check data corresponding to the data to be written back;
the data write-back module is used for writing the check data into a file header of a target file, immediately calling a system function for synchronizing memory data and file data, and writing the data to be written back to the target file; and the verification data in the file header is used for performing data integrity verification when the data in the target file is read.
14. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any of claims 1 to 12.
15. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 12.
CN202010676941.2A 2020-07-14 2020-07-14 Data storage method and device, computer equipment and storage medium Pending CN113934362A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010676941.2A CN113934362A (en) 2020-07-14 2020-07-14 Data storage method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010676941.2A CN113934362A (en) 2020-07-14 2020-07-14 Data storage method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113934362A true CN113934362A (en) 2022-01-14

Family

ID=79273837

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010676941.2A Pending CN113934362A (en) 2020-07-14 2020-07-14 Data storage method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113934362A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023232079A1 (en) * 2022-05-31 2023-12-07 上海寒武纪信息科技有限公司 Data storage method, data access method, data computing method, and related product

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023232079A1 (en) * 2022-05-31 2023-12-07 上海寒武纪信息科技有限公司 Data storage method, data access method, data computing method, and related product

Similar Documents

Publication Publication Date Title
US10983955B2 (en) Data unit cloning in memory-based file systems
CN108459826B (en) Method and device for processing IO (input/output) request
US9164676B2 (en) Storing multi-stream non-linear access patterns in a flash based file-system
US10891074B2 (en) Key-value storage device supporting snapshot function and operating method thereof
KR20080063466A (en) Flash memory management
CN113220242B (en) Storage management method, apparatus, and computer readable medium
US20240086113A1 (en) Synchronous write method and device, storage system and electronic device
CN112817962B (en) Data storage method and device based on object storage and computer equipment
US20140281125A1 (en) Systems and methods for in-place reorganization of device storage
CN113934362A (en) Data storage method and device, computer equipment and storage medium
CN111158606B (en) Storage method, storage device, computer equipment and storage medium
US9645946B2 (en) Encryption for solid state drives (SSDs)
CN113312205B (en) Data verification method and device, storage medium and computer equipment
CN107257281B (en) Method, apparatus and computer readable storage medium for NOR F L ASH storage key record
CN106250473A (en) remote sensing image cloud storage method
CN114792016A (en) Processing method and electronic equipment
CN109542872A (en) Method for reading data, device, computer equipment and storage medium
WO2021218502A1 (en) Page swapping method, storage system, and electronic device
US11513951B2 (en) System and method for improving write performance for log structured storage systems
CN113467698A (en) Writing method and device based on file system, computer equipment and storage medium
US10374637B1 (en) System and method for unbalanced load handling with distributed erasure coding
CN112015672A (en) Data processing method, device, equipment and storage medium in storage system
CN113590309B (en) Data processing method, device, equipment and storage medium
CN112181291B (en) Data write-back method and device, electronic equipment and machine-readable storage medium
CN110888823B (en) Page scanning efficiency improving method and device and computer equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination