Method, device, equipment and storage medium for random reading and writing data
By dynamically dividing write data and selecting appropriate storage space, the problems of storage space waste and large index volume in random write scenarios are solved, and storage efficiency is improved.
Patent Information
- Application Number
- CN202411875667.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2044-12-18
AI Technical Summary
In existing random write scenarios, the fixed-size storage space allocation method results in wasted storage space or a large index volume, and cannot effectively manage the storage efficiency of small and large files.
By determining the offset and amount of the current write data, it is dynamically divided into the first write data and the second write data, and written into the zone storage space and region storage space respectively. The region storage space consists of multiple continuous zone storage spaces, and the appropriate storage space is selected according to the write range.
It achieves reasonable allocation of storage space, reduces storage space waste and index volume, and improves storage efficiency.
Smart Images

Figure CN119806411B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed storage technology, and in particular to a method, apparatus, device, and storage medium for random reading and writing of data. Background Art
[0002] Currently, in random write scenarios, a fixed-size storage space is typically allocated for data to be written. There are two main methods for allocating fixed-size storage space: one is to divide the underlying disk space into large blocks for allocation. In this method, in random write scenarios, if the final written file is a small file, the small file will occupy a large amount of space, resulting in wasted space. The other method is to switch the underlying disk space to very small blocks for allocation. This method is too fine-grained. In random write scenarios, if the final written file is a large file, it will result in a large index volume, low positioning efficiency, and complex management. Summary of the Invention
[0003] The main purpose of this application is to provide a random reading and writing data method, device, equipment and storage medium, aiming to solve the technical problem that the related random reading and writing data method allocates a fixed size of storage space to store data to be written, resulting in space waste and a large amount of indexes.
[0004] To achieve the above objectives, the present application provides a random data reading and writing method, the random data reading and writing method comprising:
[0005] In the process of writing file data in the target file into the storage pool, determining a current write offset and a current write data amount corresponding to the current write data, and calculating a current data write range of the current write data according to the current write offset and the current write data amount;
[0006] Dividing the currently written data into first written data and / or second written data, wherein the current data writing range of the first written data is within the file writing range corresponding to the small file, and the current data writing range of the second written data is within the file writing range corresponding to the large file;
[0007] The first write data is written into a zone storage space in the storage pool, and / or the second write data is written into a region storage space in the storage pool, where the region storage space includes a plurality of continuous zone storage spaces.
[0008] Optionally, before writing the first write data into the zone storage space in the storage pool and / or before writing the second write data into the region storage space in the storage pool, the method further includes:
[0009] Determine the zone index / region index corresponding to the current data write range based on the correspondence between the data write range and the zone index / region index;
[0010] Searching for the presence of the zone index / region index in the storage space index list corresponding to the target file;
[0011] If the zone index / region index is not found, allocating the zone storage space / region storage space corresponding to the zone index / region index to the target file in the storage pool;
[0012] Writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, includes:
[0013] Writing the first write data into the zone storage space corresponding to the zone index in the storage pool, and / or writing the second write data into the region storage space corresponding to the region index in the storage pool;
[0014] After writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, the method further includes:
[0015] The zone index / region index is stored in the storage space index list corresponding to the target file.
[0016] Optionally, after searching for the zone index / region index in the storage space index list corresponding to the target file, the method further includes:
[0017] If the zone index / region index is found, it is determined that a corresponding zone storage space / region storage space has been allocated for the zone index / region index in the storage pool;
[0018] The first write data is written into the zone storage space corresponding to the zone index in the storage pool, and / or the second write data is written into the region storage space corresponding to the region index in the storage pool.
[0019] Optionally, writing the first write data into a zone storage space corresponding to the zone index in the storage pool, and / or writing the second write data into a region storage space corresponding to the region index in the storage pool, includes:
[0020] Determine a first write position / second write position of the first write data / second write data in the zone storage space / region storage space according to a current data write range corresponding to the first write data / second write data and a data write range corresponding to the zone index / region index;
[0021] The first write data is written to the zone storage space corresponding to the zone index in the storage pool according to the first write position, and / or the second write data is written to the region storage space corresponding to the region index in the storage pool according to the second write position.
[0022] Optionally, after writing the first write data into the zone storage space in the storage pool and / or writing the second write data into the region storage space in the storage pool, the method further includes:
[0023] In a process of reading file data of the target file from the storage pool, determining a current read offset and a current read data amount corresponding to the currently read data;
[0024] Calculating a current data reading range of the currently read data according to the current reading offset and the currently read data amount;
[0025] According to the correspondence between the data reading range and the zone index / region index, searching the storage space index list corresponding to the target file for the target zone index / region index corresponding to the current data reading range;
[0026] Searching the storage pool for a target zone storage space / target region storage space corresponding to the target zone index / target region index;
[0027] The currently read data is read from the target zone storage space / target region storage space.
[0028] Optionally, after dividing the current write data into first write data and / or second write data, the method further includes:
[0029] Acquire a current partitioning mode of the currently written data, and set a size attribute value of the target file according to the current partitioning mode;
[0030] The searching, according to the correspondence between the data reading range and the zone index / region index, for the target zone index / target region index corresponding to the current data reading range in the storage space index list corresponding to the target file, includes:
[0031] Determine the index list type of the storage space index list corresponding to the target file according to the size attribute value;
[0032] According to the correspondence between the index list type and the data reading range and the zone index / region index, the target zone index / target region index corresponding to the current data reading range is searched in the storage space index list corresponding to the target file.
[0033] Optionally, the method further includes:
[0034] In the process of writing file data of the target file into the storage pool, obtaining a writing mode of first writing data of the target file;
[0035] If the writing mode of the first-write data is to write the first-write data into the region storage space in the storage pool, the current-write data is written into the region storage space in the storage pool.
[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a random data read and write device, the random data read and write device comprising:
[0037] a range determination module, configured to determine, during a process of writing file data in a target file into a storage pool, a current write offset and a current write data amount corresponding to the current write data, and calculate a current data write range of the current write data based on the current write offset and the current write data amount;
[0038] a data division module, configured to divide the currently written data into first written data and / or second written data, wherein the current data writing range of the first written data is within the file writing range corresponding to the small file, and the current data writing range of the second written data is within the file writing range corresponding to the large file;
[0039] A data writing module is used to write the first write data into the zone storage space in the storage pool, and / or write the second write data into the region storage space in the storage pool, where the region storage space includes multiple continuous zone storage spaces.
[0040] In addition, to achieve the above-mentioned purpose, the present application also proposes a random read and write data device, which includes a memory, a processor, and a random read and write data program stored in the memory and runnable on the processor, and the random read and write data program is configured to implement the random read and write data method described above.
[0041] In addition, to achieve the above objectives, the present application also proposes a storage medium, on which a random read and write data program is stored. When the random read and write data program is executed by a processor, the random read and write data method described above is implemented.
[0042] One or more technical solutions proposed in this application have at least the following technical effects:
[0043] In the present application, disclosed is a method of determining a current write offset and a current write data amount corresponding to the current write data in a process of writing file data in a target file into a storage pool, calculating a current data write range of the current write data based on the current write offset and the current write data amount, dividing the current write data into first write data and / or second write data, wherein the current data write range of the first write data is within the file write range corresponding to the small file, and the current data write range of the second write data is within the file write range corresponding to the large file, writing the first write data into a zone storage space in the storage pool, and / or writing the second write data into a region storage space in the storage pool, wherein the region storage space includes multiple continuous zone storage spaces; because the present application can determine the current write range corresponding to the current write data based on the current write offset and the current write data amount corresponding to the current write data in a random write scenario, and divide the current write data based on the current write range, dynamically selecting storage spaces of different sizes to write the data, thereby achieving reasonable allocation of storage space, thereby reducing storage space waste, and reducing the amount of indexes generated after file writing. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0046] Figure 1 This is a flow chart of the first embodiment of the random data reading and writing method of the present application;
[0047] Figure 2 This is a flow chart of a second embodiment of the random data reading and writing method of the present application;
[0048] Figure 3 This is a flow chart of a third embodiment of the random data reading and writing method of the present application;
[0049] Figure 4 This is a schematic diagram of the module structure of the random data reading and writing device according to an embodiment of the present application;
[0050] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the random reading and writing data method in the embodiment of the present application.
[0051] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0052] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.
[0053] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0054] The application scenario of the embodiment of the present application can be a random read and write data scenario, wherein random read and write data can mean that the user can choose to read and write data from any position of the file at any time. For example, the user can insert a text at the 100th byte of the file without having to write the entire file from the beginning. Since the user can open, read, write, append or modify data from any position of the file, the size of the file can change dynamically during use, which means that the final file size is unknown when the file is started.
[0055] For ease of understanding, the following examples are given, but this application is not limited. As an example, suppose that a user uploads an empty file (i.e., the target file) to a distributed storage system for storage, and then changes the data to save it in real time (such as in a Linux system, an empty file (with size but no content) can be generated by truncate). The user can enter text data at any time, can start entering from the beginning of the file, or can jump to a certain position in the file to insert text, or delete some existing text. For example, the user may first enter "The weather is very good today", then jump to the beginning of the file and insert "April 1, 2023:", and then jump to the end of the file and add "Went for a walk in the park." In this process, the size of the file continues to change with the user's input. Each time the user enters or deletes text, the size of the file will increase or decrease accordingly. Since the user can stop editing and save the file at any time, or continue editing the file at some point in the future, the final size of the file cannot be determined during the editing process.
[0056] Currently, in random read and write data scenarios, the relevant random read and write data methods usually allocate a fixed-size storage space to the data to be written. There are two main methods for allocating fixed-size storage space:
[0057] The first approach is to divide the underlying disk space into large blocks for allocation, such as the Hadoop Distributed File System (HDFS). This approach primarily divides the underlying disk into large blocks, so that when large files are written continuously, they can directly occupy the large blocks. The advantage is that the storage addresses are continuous and there are fewer index records. However, in random write scenarios, if the final file written is a small file, this approach will cause the small file to occupy a large amount of space, resulting in space waste. This is because the allocation unit is blocks, and when a small file is written, it is initially allocated a large block. Only when this file is no longer in use can other files continue to use it, resulting in a situation where small files occupy a large amount of space.
[0058] The second approach is to divide the underlying disk space into very small blocks for allocation, such as RAID 2.0+. This approach primarily divides the disk space into very small blocks, for example, 64KB blocks. This prevents space waste for small, random files and improves concurrent write efficiency. However, this approach divides the space too finely. In random write scenarios, if the final written file is large, the indexing volume will be large, resulting in low positioning efficiency and complex management.
[0059] Therefore, in order to overcome the above-mentioned defects, the present application provides a solution, which includes: in the process of writing file data in the target file into the storage pool, determining the current write offset and the current write data amount corresponding to the current write data, and calculating the current data write range of the current write data based on the current write offset and the current write data amount, dividing the current write data into first write data and / or second write data, wherein the current data write range of the first write data is located within the file write range corresponding to the small file, and the current data write range of the second write data is located within the file write range corresponding to the large file, writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, the region storage space including multiple continuous zone storage spaces.
[0060] Since the present application can determine the current write range corresponding to the current write data according to the current write offset and the current write data amount corresponding to the current write data in a random write scenario, and divide the current write data according to the current write range, dynamically select storage spaces of different sizes to write data, thereby achieving a reasonable allocation of storage space, thereby reducing storage space waste and reducing the amount of indexes generated after the file is written.
[0061] It should be noted that the execution subject of this embodiment can be a random read and write data device with data processing, network communication and program running functions, such as a distributed storage system, etc., or other electronic devices that can achieve the same or similar functions. This embodiment does not impose any restrictions on this.
[0062] Based on this, the embodiment of the present application provides a random reading and writing data method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the random data reading and writing method of the present application.
[0063] In a first embodiment, the random data reading and writing method includes:
[0064] Step S10: In the process of writing file data in the target file into the storage pool, determine the current write offset and the current write data amount corresponding to the current write data, and calculate the current data write range of the current write data based on the current write offset and the current write data amount.
[0065] It should be understood that in order to accurately identify the position of the currently written data in the target file, a basis is provided for subsequent data partitioning and storage. In this embodiment, in the process of writing the file data in the target file to the storage pool, the current data write range of the currently written data is calculated based on the current write offset and the current write data amount. Among them, the target file can refer to the file to be stored, and the data of the target file will be written to the storage pool. The target file can be any type of data file (such as text, pictures, and videos, etc.), and this embodiment does not limit this. The storage pool can refer to a logical storage space composed of multiple physical storage devices (such as hard disks, etc.) for unified management and allocation of storage resources. The currently written data can refer to the data that the user wants to write to the storage pool in the current operation. The current write offset can refer to the byte offset of the write start position corresponding to the currently written data relative to the beginning of the file. The current write data amount can refer to the data length or data size of the currently written data. The current data write range can refer to the data range determined by the current write offset and the current write data amount.
[0066] In a specific implementation, for example, in the process of writing file data in the target file into the storage pool, the current write data can be parsed to obtain the current write offset and the current write data amount corresponding to the current write data, and then the current write end position is calculated based on the current write offset and the current write data amount, and the current data write range is determined based on the current write offset and the current write end position.
[0067] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assume that a user requests to write 200KB of data starting at position 1000KB of the target file. The current write offset is 1000KB, the current write data volume is 200KB, and the current write end position is 1200KB when the current write offset and the current write end position are added together. Based on the current write offset and the current write end position, the current data write range can be determined to be [1000KB, 1200KB].
[0068] Step S20: Divide the current write data into first write data and / or second write data, wherein the current data write range of the first write data is within the file write range corresponding to the small file, and the current data write range of the second write data is within the file write range corresponding to the large file.
[0069] It should be understood that in order to facilitate the subsequent reasonable allocation of storage space, in this embodiment, the current write data is first divided into the first write data and / or the second write data. In a specific implementation, the current write data is divided into the first write data and / or the second write data by matching the current data write range of the current write data with the file write range corresponding to the small file and the file write range corresponding to the large file, respectively, and dividing the current write data into the first write data and / or the second write data according to the matching result. Among them, a small file may refer to a file whose file size does not exceed a preset threshold. A large file may refer to a file whose file size exceeds a preset threshold. The preset threshold can be pre-set, for example, the preset threshold can be pre-set to 1024KB, and this embodiment does not limit this.
[0070] For example, if the current data write range of the current write data is completely within the file write range corresponding to the small file, the current write data is divided into the first write data; if the current data write range of the current write data is completely within the file write range corresponding to the large file, the current write data is divided into the second write data; if part of the current data write range of the current write data is within the file write range corresponding to the small file and the other part is within the file write range corresponding to the large file, the current write data within the file write range corresponding to the small file is divided into the first write data, and the current write data within the file write range corresponding to the large file is divided into the second write data.
[0071] Step S30: writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, wherein the region storage space includes a plurality of continuous zone storage spaces.
[0072] It should be understood that, in order to achieve reasonable allocation of storage space, in this embodiment, the first write data is written to the zone storage space in the storage pool, and / or the second write data is written to the region storage space in the storage pool, where the region storage space includes multiple continuous zone storage spaces. In a distributed storage system, a zone storage space may refer to a specific area in a storage pool for storing small files. A region storage space may refer to an area in a storage pool for storing large files.
[0073] It can be understood that in order to avoid the situation where some storage space is not allocated and gaps appear, in this embodiment, the region storage space can be composed of multiple zone storage spaces. For example, the space size of the zone storage space is 16KB, and one region consists of 64 zones, then the space size of the region storage space is 1MB.
[0074] It should be understood that, to meet different storage requirements, the size of the zone storage space in this embodiment can be dynamically adjusted. In a specific implementation, the size of the zone storage space is calculated based on the data block size and number of data blocks in the erasure code. Erasure code (EC) is a data protection method that segments data into fragments and generates redundant data blocks through encoding. These data blocks are stored in different locations. An erasure code consists of data blocks and check blocks. The number of data blocks and check blocks in the erasure code determines the erasure code type. For example, erasure code types can include 4+2 and 8+2. The 4+2 type means that after writing four data blocks, two check blocks are generated. That is, four data blocks in the erasure code are protected by two check blocks. Within these six blocks, a maximum of two blocks can be lost. If the third block is lost, its data becomes invalid. However, if fewer than two blocks are lost, the data can be recovered regardless of any loss. The data block size and number of data blocks in the storage pool can be pre-selected by the user when creating the storage pool. For example, a user can pre-create a storage pool through the client, select the 4+2 erasure code type for the storage pool, and set the data block size to 4 KB. When writing file data from the target file to the storage pool, the user can select the target storage pool for storing the target file based on actual needs. First, the erasure code type of the target storage pool is set to 4+2. Then, based on the 4+2 type, the number of data blocks in the erasure code is set to 4, and the data block size is set to 4 KB. In this case, the zone storage space size = 4*4 KB = 16 KB.
[0075] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assume that a user uploads an empty file (i.e., the target file) to a distributed storage system for storage, and then changes the data to be saved in real time (e.g., in a Linux system, an empty file (with size but no content) can be generated by truncate), and the preset threshold is pre-set to 1024KB (i.e., the write range for small files is (0, 1024KB], and the write range for large files is (1024KB, +∞)).
[0076] 1. Assume that the user writes a line of text between 100KB and 300KB of the target file. The offset of the current data being written is 100KB, the length of the data being written is 200KB, and the range of the current data being written is [100KB, 300KB]. Since the current data writing range is completely within the file writing range corresponding to the small file, the current data being written is all classified as the first data being written and is written to the zone storage space.
[0077] 2. Assume that the user writes a line of text at the 1000-1200KB position of the target file. The offset (i.e., the current write offset) of this IO (i.e., the current write data) is 1000KB, the write length (i.e., the current write data amount) is 200KB, and the current data write range is [1000KB, 1200KB] (determined by the offset and the write length). Since part of the current data write range of the current write data is located within the file write range corresponding to the small file and part of it is located within the file write range corresponding to the large file, the current write data located within the file write range corresponding to the small file (i.e., the current write data with a current data write range of [1000KB, 1024KB]) is divided into the first write data, and the current write data located within the file write range corresponding to the large file (i.e., the current write data with a current data write range of (1024KB, 1200KB]) is divided into the second write data. The first write data is written to the zone storage space in the storage pool, and the second write data is written to the region storage space in the storage pool.
[0078] In a specific implementation, this IO can also be divided into two IOs to implement the above-mentioned separate storage steps. Specifically, it can be determined that this IO has crossed the preset threshold based on the current data write range. According to the preset threshold, this IO is divided into two IOs (one is [1000KB, 1024KB] (i.e., the first write data), and the other is (1024KB, 1200KB] (i.e., the second write data)). The first IO is written to the zone storage space in the storage pool, and the second IO is written to the region storage space in the storage pool.
[0079] 3. Assume that the user writes a line of text between 1500KB and 1700KB of the target file. The offset of this I / O (i.e., the current write data) is 1500KB, the write length (i.e., the current write data amount) is 200KB, and the current data write range is [1500KB, 1700KB]. Since the current data write range is completely within the file write range corresponding to the large file, the current write data is completely classified as the second write data and is written to the region storage space.
[0080] Furthermore, if the data that the user writes to the target file for the first time is within the file write range corresponding to the large file (i.e., the user makes a large jump when writing for the first time, and there is a lot of empty content at the front), then even if the amount of data written for the first time is not large, the target file will be treated as a large file for subsequent storage steps in this embodiment. This is because, even if there is a lot of empty content at the front, the user is very likely to fill this empty content in the future, so the target file is essentially still a large file. Therefore, in order to reduce the waste of storage space, the target file is stored in the storage method of a large file. The random reading and writing data method also includes: in the process of writing the file data in the target file to the storage pool, obtaining the writing method of the first writing data of the target file; if the writing method of the first writing data is to write the first writing data to the region storage space in the storage pool, then writing the currently written data to the region storage space in the storage pool. Among them, the first writing data can refer to the data portion of the target file that is first written to the storage pool.
[0081] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assume that a user uploads an empty file (i.e., the target file) to a distributed storage system for storage, and then changes the data to be saved in real time (e.g., in a Linux system, an empty file (with size but no content) can be generated by truncate), and the preset threshold is pre-set to 1024KB (i.e., the write range for small files is (0, 1024KB], and the write range for large files is (1024KB, +∞)).
[0082] Assume that the user first writes a line of text at the 1400-1500KB position in the target file. The offset of the first data write (i.e., the first write offset) is 1400KB, the write length (i.e., the amount of data written) is 100KB, and the first data write range is [1400KB, 1500KB]. Since the first data write range is completely within the file write range corresponding to the large file, the first data write is completely divided into the second write data and is written to the region storage space.
[0083] Assume that the user currently writes a line of text at the 300-500KB position of the target file, the offset of the current write data (i.e., the current write offset) is 300KB, the write length (i.e., the current write data amount) is 200KB, and the current data write range is [300KB, 500KB]. Even if the current data write range is completely within the file write range corresponding to the small file, since the first write data is written in the region storage space in the storage pool, the current write data is written into the region storage space in the storage pool.
[0084] In a random write scenario, this embodiment can determine the current write range corresponding to the current write data based on the current write offset and the current write data amount corresponding to the current write data, divide the current write data according to the current write range, and dynamically select storage spaces of different sizes to write data, thereby achieving reasonable allocation of storage space, thereby reducing storage space waste, and reducing the amount of indexes generated after the file is written.
[0085] Reference Figure 2 , Figure 2 This is a flow chart of the second embodiment of the random data reading and writing method of this application, based on the above Figure 1 The first embodiment shown provides a second embodiment of the random data reading and writing method of the present application.
[0086] In the second embodiment, before step S30, the method further includes:
[0087] Step S21: Determine the zone index / region index corresponding to the current data writing range according to the correspondence between the data writing range and the zone index / region index.
[0088] It should be understood that, in order to provide clear address information for data storage, in this embodiment, the zone index / region index corresponding to the current data write range is first determined based on the correspondence between the data write range and the zone index / region index. The correspondence between the data write range and the zone index / region index can be pre-set. The zone index / region index can be a unique number used to identify a zone storage space or a region storage space in a storage pool.
[0089] For ease of understanding, the following examples are given, but they do not limit the present application. As an example, assuming that the size of the zone storage space is 16KB, and one region storage space consists of 64 zone storage spaces, then the size of the region storage space is 1024KB (i.e., 1MB), and the preset threshold is pre-set to 1MB. Then the data write range corresponding to zoneid1 is (0, 16KB], the data write range corresponding to zoneid2 is (16KB, 32KB], the data write range corresponding to zoneid3 is (32KB, 48KB], and so on. The data write range corresponding to zoneid63 is (992KB, 1008KB], and zonei The data write range corresponding to d64 is (1008KB, 1024KB], the data write range corresponding to regionid1 is (1MB, 2MB], and the data write range corresponding to regionid2 is (2MB, 3MB]. Assuming that the offset (i.e., the current write offset) of this IO is 1000KB, the write length (i.e., the current amount of written data) is 200KB, and the current data write range is [1000KB, 1200KB], the zone index / region index corresponding to the current data write range is zoneid63, zoneid64, and regionid1.
[0090] Step S22: Searching for the zone index / region index in the storage space index list corresponding to the target file.
[0091] It is understood that to determine whether new storage space needs to be allocated for the currently written data, in this embodiment, a search is performed to determine whether a zone index / region index exists in the storage space index list corresponding to the target file. The storage space index list may be a zone index / region index list that records the allocated storage space for the target file.
[0092] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assuming that the storage space index list corresponding to the target file is File_id: zoneid2, zoneid2, zoneid62, zoneid63, and the zone index / region index corresponding to the current data write range is zoneid63, zoneid64, and regionid1, then zoneid63 exists in the storage space index list corresponding to the target file, indicating that the corresponding zone storage space has been allocated to zoneid63 (perhaps because data with an offset of 993KB and a length of 7KB has been written before, so the zone storage space corresponding to zoneid63 has been allocated before); zoneid64 and regionid1 do not exist in the storage space index list corresponding to the target file, indicating that the corresponding zone storage space / region storage space has not been allocated to zoneid64 and regionid1 before.
[0093] Furthermore, in order to ensure that the data can be correctly written into the allocated storage space, after step S22, it also includes: if the zone index / region index is found, it is determined that the corresponding zone storage space / region storage space has been allocated for the zone index / region index in the storage pool; the first write data is written into the zone storage space corresponding to the zone index in the storage pool, and / or the second write data is written into the region storage space corresponding to the region index in the storage pool.
[0094] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assuming that the zone index / region index corresponding to the current data write range is zoneid63, zoneid64, and regionid1, and assuming that the storage space index list corresponding to the target file is File_id: zoneid2, zoneid2, zoneid62, zoneid63, and zoneid63 exists in the storage space index list corresponding to the target file, it means that the corresponding zone storage space has been allocated for zoneid63 (perhaps because data with an offset of 993KB and a write length of 7KB has been written before, and therefore, the zone storage space corresponding to zoneid63 has been allocated before). Then, the first write data with the current data write range of [1000KB, 1008KB] is directly written to the zone storage space corresponding to zoneid63.
[0095] Step S23: If the zone index / region index is not found, the zone storage space / region storage space corresponding to the zone index / region index is allocated to the target file in the storage pool.
[0096] It is understandable that in order to ensure that there is a place for data to be written and to optimize the utilization of storage space, in this embodiment, if the zone index / region index is not found, the zone storage space / region storage space corresponding to the zone index / region index is allocated to the target file in the storage pool.
[0097] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assuming that the zone index / region index corresponding to the current data write range is zoneid63, zoneid64, and regionid1, and assuming that the storage space index list corresponding to the target file is File_id: zoneid2, zoneid2, zoneid62, zoneid63, and zoneid64 and regionid1 do not exist in the storage space index list corresponding to the target file, it means that the corresponding zone storage space / region storage space has not been allocated for zoneid64 and regionid1 before. Therefore, the zone storage space corresponding to zoneid64 and the region storage space corresponding to regionid1 are allocated to the target file in the storage pool.
[0098] In the second embodiment, step S30 includes:
[0099] Step S30': writing the first write data into the zone storage space corresponding to the zone index in the storage pool, and / or writing the second write data into the region storage space corresponding to the region index in the storage pool.
[0100] Furthermore, in order to provide a specific write location for data writing, the step S30' includes: determining the first write location / second write location of the first write data / second write data in the zone storage space / region storage space based on the current data write range corresponding to the first write data / second write data and the data write range corresponding to the zone index / region index; writing the first write data to the zone storage space corresponding to the zone index in the storage pool according to the first write location, and / or writing the second write data to the region storage space corresponding to the region index in the storage pool according to the second write location.
[0101] It should be understood that in order to provide a specific write location for data writing, in this embodiment, the write location of the data in the storage space is determined based on the current data write range corresponding to the first write data / second write data and the data write range corresponding to the zone index / region index, and the data is written to the corresponding storage space based on the determined write location.
[0102] For ease of understanding, the following examples are given, but this application is not limited. As an example, assuming that the data write range corresponding to zoneid63 is (992KB, 1008KB], the data write range corresponding to zoneid64 is (1008KB, 1024KB], and the data write range corresponding to regionid1 is (1MB, 2MB], the offset of this IO (i.e., the current write offset) is 1000KB, the write length (i.e., the current write data amount) is 200KB, and the current data write range is [1000KB, 1200KB], then the first write position includes the last 8KB storage space corresponding to zoneid63 (i.e., the zone storage space with a data write range of [1000KB, 1008KB]) and all the storage spaces corresponding to zoneid64. 16KB storage space (that is, the data write range is (1008KB, 1024KB] zone storage space), the second write location is the first 176KB storage space corresponding to regionid1 (that is, the data write range is (1024KB, 1200KB] region storage space). The first write data with the current data write range of [1000KB, 1008KB] is written to the last 8KB storage space corresponding to zoneid63, the first write data of (1008KB, 1024KB] is written to the entire 16KB storage space corresponding to zoneid64, and the second write data of (1024KB, 1200KB] is written to the first 176KB storage space corresponding to regionid1.
[0103] In the second embodiment, after step S30, the method further includes:
[0104] Step S31: storing the zone index / region index into the storage space index list corresponding to the target file.
[0105] It should be understood that in order to record the allocated storage space and facilitate subsequent data read and write operations, in this embodiment, the newly allocated zone index / region index is stored in the storage space index list corresponding to the target file.
[0106] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assuming that the size of the zone storage space is 16KB, and one region storage space consists of 64 zone storage spaces, the size of the region storage space is 1024KB (i.e., 1MB), and the preset threshold is pre-set to 1MB. The data write range corresponding to zoneid1 is (0, 16KB], the data write range corresponding to zoneid2 is (16KB, 32KB], the data write range corresponding to zoneid3 is (32KB, 48KB], and so on. The data write range corresponding to zoneid63 is (992KB, 1008KB], the data write range corresponding to zoneid64 is (1008KB, 1024KB], the data write range corresponding to regionid1 is (1MB, 2MB], and the data write range corresponding to regionid2 is (2MB, 3MB].
[0107] Assume that the offset of this IO (i.e., the current write offset) is 1000KB, the write length (i.e., the current amount of written data) is 200KB, and the current data write range is [1000KB, 1200KB]. The zone index / region index corresponding to the current data write range is zoneid63, zoneid64, and regionid1. Assume that the storage space index list corresponding to the target file is File_id: zoneid2, zoneid2, zoneid62, zoneid63.
[0108] ZoneID 63 exists in the storage space index list corresponding to the target file, indicating that the corresponding zone storage space has been allocated for ZoneID 63 before (perhaps because data with an offset of 993KB and a length of 7KB was previously written, so the zone storage space corresponding to ZoneID 63 was previously allocated). Therefore, the first write data in the current data write range [1000KB, 1008KB] is directly written to the zone storage space corresponding to ZoneID 63.
[0109] The zoneid64 and regionid1 do not exist in the storage space index list corresponding to the target file, indicating that the corresponding zone storage space and region storage space have not been allocated for zoneid64 and regionid1 before. Therefore, the zone storage space corresponding to zoneid64 and the region storage space corresponding to regionid1 are allocated to the target file in the storage pool (that is, one 16KB storage space and one 1MB storage space are allocated to the target file, and the first write data of (1008KB, 1024KB] is written to the 16KB storage space, and the first write data of (1024KB, 1200KB) is written to the 16KB storage space. B] is written into the first 176KB storage space of the 1MB storage space, and the remaining 826KB storage space is temporarily left empty until the file data in the data writing range (1200KB, 2048KB] is written, and then stored in the 826KB storage space)). The above zone index / region index (zoneid64 and regionid1) is stored in the storage space index list corresponding to the target file as File_id, forming a new File_id: zoneid3, zoneid5, zoneid9, zoneid63, zoneid64, regionid1.
[0110] When writing file data to the storage pool, this embodiment will also search the storage space index list corresponding to the target file to see whether there is a zone index / region index corresponding to the current data write range, so as to determine whether new storage space needs to be allocated for the currently written data. If the zone index / region index is not found, the zone storage space / region storage space corresponding to the zone index / region index is allocated to the target file in the storage pool, and the zone index / region index is stored in the storage space index list corresponding to the target file, so as to record the allocated storage space and facilitate subsequent data reading and writing operations.
[0111] Reference Figure 3 , Figure 3 This is a flow chart of a third embodiment of the random data reading and writing method of the present application. Based on the above embodiments, the third embodiment of the random data reading and writing method of the present application is proposed.
[0112] In the third embodiment, after step S30, the method further includes:
[0113] Step S40: in the process of reading the file data of the target file from the storage pool, determining the current read offset and the current read data amount corresponding to the currently read data.
[0114] It should be understood that in order to provide basic information for the subsequent calculation of the data reading range and the search for the target storage space, in this embodiment, in the process of reading the file data of the target file from the storage pool, the current read offset and the current read data volume corresponding to the current read data are first determined. In a specific implementation, in the process of reading the target file, the current read offset and the current read data volume corresponding to the current read data are determined according to the read request or program logic. Among them, the current read data can refer to the data block that currently needs to be read in the process of reading the target file. The current read offset can refer to the offset of the starting position of the current read data relative to the beginning of the file in the target file. The current read data volume can refer to the amount of data that needs to be read for the current read operation.
[0115] Step S50: Calculating a current data reading range of the currently read data according to the currently read offset and the currently read data amount.
[0116] It is understood that in order to clarify the specific location of the data to be read in the target file and provide a basis for subsequent search of the target storage space, in this embodiment, the current data read range of the currently read data is calculated based on the current read offset and the current read data amount. In a specific implementation, the current read offset is used as the starting point, and the current read data amount is added to obtain the current data read range. The current data read range can be determined by the current read offset and the current read data amount, and is used to represent a continuous data area in the target file.
[0117] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assuming that the current read offset is 10KB and the current data read range is 20KB, the current data read range of the current read data is [10KB, 30KB].
[0118] Step S60: searching for a target zone index / target region index corresponding to the current data reading range in the storage space index list corresponding to the target file according to the correspondence between the data reading range and the zone index / region index.
[0119] It should be understood that in order to facilitate the subsequent search for the target zone storage space / target region storage space for storing the currently read data, in this embodiment, the target zone index / target region index corresponding to the current data read range is first searched. In a specific implementation, searching for the target zone index / target region index corresponding to the current data read range in the storage space index list corresponding to the target file based on the correspondence between the data read range and the zone index / region index can be performed by using a predefined correspondence between the data read range and the zone index / region index to search for a zone or region index that matches the current data read range in the storage space index list. Among them, the target zone index / target region index can refer to the index of the zone or region corresponding to the current data read range in the storage space index list.
[0120] For ease of understanding, the following examples are given, but this application is not limited. As an example, assuming that the current data reading range of the currently read data is [10KB, 30KB], the data reading range corresponding to zoneid1 is (0, 16KB], the data reading range corresponding to zoneid2 is (16KB, 32KB], the data reading range corresponding to zoneid3 is (32KB, 48KB], and so on, the data reading range corresponding to zoneid63 is (992KB, 1008KB], the data reading range corresponding to zoneid64 is (1008KB, 1024KB], the data reading range corresponding to regionid1 is (1MB, 2MB], and the data reading range corresponding to regionid2 is (2MB, 3MB], then the target zone index / target region index corresponding to the currently read data is zoneid1 and zoneid2.
[0121] Step S70: searching the storage pool for a target zone storage space / target region storage space corresponding to the target zone index / target region index.
[0122] It will be appreciated that, to provide a direct access path for reading data, in this embodiment, the target zone storage space / target region storage space corresponding to the target zone index / target region index is searched in the storage pool. In a specific implementation, the storage space on a specific storage unit is located in the storage pool based on the target zone index / target region index. The target zone storage space / target region storage space may be the actual storage space in the storage pool corresponding to the target zone index / target region index.
[0123] Step S80: reading the current read data from the target zone storage space / target region storage space.
[0124] In a specific implementation, reading the current read data from the target zone storage space / target region storage space may be performed by utilizing a read / write interface of the storage system to read data from the found target zone storage space / target region storage space.
[0125] For ease of understanding, the following examples are given, but they do not limit the present application. As an example, assuming that the size of the zone storage space is 16KB, and one region storage space consists of 64 zone storage spaces, the size of the region storage space is 1024KB (i.e., 1MB), the current read offset of this read is 10KB, and the current data read range is 20KB, then the current data read range is [10KB, 30KB]. Assuming that the storage space index list corresponding to the target file is File_id: zoneid1, zoneid2, zoneid3, ....., zoneid64, regionid1....., the data read range corresponding to zoneid1 is (0, 16KB], and the data read range corresponding to zoneid2 is (16KB, 32KB ], the data reading range corresponding to zoneid3 is (32KB, 48KB], and so on. The data reading range corresponding to zoneid63 is (992KB, 1008KB], the data reading range corresponding to zoneid64 is (1008KB, 1024KB], the data reading range corresponding to regionid1 is (1MB, 2MB], and the data reading range corresponding to regionid2 is (2MB, 3MB]). The target zone index / target region index corresponding to the currently read data is zoneid1 and zoneid2, and the currently read data with a reading range of [10KB, 30KB] is read from the target zone storage space corresponding to zoneid1 and zoneid2.
[0126] Furthermore, in order to improve the accuracy of the target zone index / target region index, after step S20, it also includes: obtaining the current division method of the currently written data, and setting the size attribute value of the target file according to the current division method; accordingly, the step S60 includes: judging the index list type of the storage space index list corresponding to the target file according to the size attribute value; searching for the target zone index / target region index corresponding to the current data reading range in the storage space index list corresponding to the target file according to the correspondence between the index list type and the data reading range and the zone index / region index.
[0127] It should be understood that, considering that the storage space index list corresponding to the target file can be File_id: zoneid1, zoneid2, zoneid3, ....., zoneid64, regionid1.....; it can also be File_id: zoneid1, zoneid2, zoneid3, ....., it can also be File_id: regionid1, regionid2, regionid3, ..... When the type of File_id is different, the target zone index / target region index found is different. Therefore, in order to improve the accuracy of the target zone index / target region index, in this embodiment, before searching for the target zone index / target region index in the storage space index list corresponding to the target file, the type of the storage space index list will be determined, and then the target zone index / target region index will be searched in the storage space index list corresponding to the target file according to the type of the storage space index list.
[0128] In a specific implementation, when writing data, the division method of the current written data is obtained, and the size attribute value of the target file is set according to the division method. Through the size attribute value, it can be determined whether the target file is a small file or a large file, thereby determining the type of index list used for subsequent reading. Among them, the size attribute value is used to represent the value of the size attribute of the target file, which is used to distinguish whether the file is a small file or a large file. For example, the size attribute value can be 01, 10, or 11, where 01 indicates that the target file is a small file, 10 indicates that the target file is a large file, and 11 indicates that the target file is a small file when it is first written. As the file data is continuously written (that is, the amount of file data continues to increase), the subsequent target file is transformed from a small file to a large file.
[0129] When reading data, the index list type of the storage space index list corresponding to the target file is determined based on the size attribute value. Based on the correspondence between the index list type, the data reading range, and the zone index / region index, the target zone index / region index corresponding to the current data reading range is searched in the storage space index list corresponding to the target file. For example, the index list types can include the following three:
[0130] When the size attribute of the target file is 11, the index list type of the storage space index list corresponding to the target file is the first index list, which contains both the zoneid index and the regionid index:
[0131] File_id: zoneid1, zoneid2, zoneid3, ....., zoneid64, regionid1.....
[0132] When the size attribute of the target file is 01, the index list type of the storage space index list corresponding to the target file is the second index list, which only contains the zoneid index:
[0133] File_id: zoneid1, zoneid2, zoneid3, .....
[0134] When the size attribute value of the target file is 10, the index list type of the storage space index list corresponding to the target file is the third index list, which only contains the regionid index:
[0135] File_id: regionid1, regionid2, regionid3, .....
[0136] For ease of understanding, the following examples are provided, but are not intended to limit the present application. As an example, assuming the size of the zone storage space is 16KB, and one region storage space consists of 64 zone storage spaces, the size of the region storage space is 1024KB (i.e., 1MB), the current read offset is 10KB, and the current data read range is 20KB, then the current data read range is [10KB, 30KB].
[0137] Assuming that the size attribute of the target file is 11, the storage space index list corresponding to the target file is File_id: zoneid1, zoneid2, zoneid3,....., zoneid64, regionid1....., the data reading range corresponding to zoneid1 is (0, 16KB], the data reading range corresponding to zoneid2 is (16KB, 32KB], the data reading range corresponding to zoneid3 is (32KB, 48KB], and so on. The data reading range corresponding to zoneid63 is (992KB, 1008KB], the data reading range corresponding to zoneid64 is (1008KB, 1024KB], the data reading range corresponding to regionid1 is (1MB, 2MB], and the data reading range corresponding to regionid2 is (2MB, 3MB]). Then the target zone index / target region index corresponding to the currently read data is zoneid1 and zoneid2, and the currently read data with a reading range of [10KB, 30KB] is read from the target zone storage space corresponding to zoneid1 and zoneid2.
[0138] Assuming that the size attribute of the target file is 10, the storage space index list corresponding to the target file is File_id: regionid1, regionid2, regionid3,....., the data reading range corresponding to regionid1 is (1MB, 2MB], and the data reading range corresponding to regionid2 is (2MB, 3MB], then the target zone index / target region index corresponding to the currently read data is regionid1, and the currently read data with a reading range of [10KB, 30KB] is read from the target regionid storage space corresponding to regionid1.
[0139] In the process of reading file data of a target file from a storage pool, this embodiment searches for a target zone index / target region index corresponding to the current data reading range in a storage space index list corresponding to the target file according to the current data reading range of the current read data, and reads the current read data in the target zone storage space / target region storage space according to the target zone index / target region index, thereby accurately reading the specified data segment of the target file from the storage pool.
[0140] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the random data reading and writing method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0141] This application also provides a random read and write data device, please refer to Figure 4 , the random data reading and writing device includes:
[0142] A range determination module 10 is configured to determine a current write offset and a current write data amount corresponding to the current write data during the process of writing the file data in the target file into the storage pool, and calculate a current data write range of the current write data based on the current write offset and the current write data amount;
[0143] a data partitioning module 20, configured to partition the currently written data into first written data and / or second written data, wherein the current data writing range of the first written data is within the file writing range corresponding to the small file, and the current data writing range of the second written data is within the file writing range corresponding to the large file;
[0144] The data writing module 30 is configured to write the first write data into the zone storage space in the storage pool, and / or write the second write data into the region storage space in the storage pool, wherein the region storage space includes a plurality of continuous zone storage spaces.
[0145] The random data read and write device provided by this application utilizes the random data read and write method of the above-mentioned embodiment, and can resolve the technical problem that related random data read and write methods allocate a fixed amount of storage space to store data to be written, resulting in wasted space and a large number of indexes. Compared with the prior art, the beneficial effects of the random data read and write device provided by this application are the same as those of the random data read and write method provided by the above-mentioned embodiment, and the other technical features of the random data read and write device are the same as those disclosed in the above-mentioned embodiment method, and are not further described here.
[0146] The present application provides a random data read and write device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the random data read and write method in the above-mentioned embodiment one.
[0147] Reference below Figure 5, which shows a schematic diagram of the structure of a random data read / write device suitable for implementing the embodiments of the present application. The random data read / write device in the embodiments of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The random read and write data device shown is only an example and should not limit the functions and scope of use of the embodiments of the present application.
[0148] like Figure 5 As shown, the random access data device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 1002 or programs loaded from a storage device 1003 into a random access memory (RAM) 1004. RAM 1004 also stores various programs and data required for the operation of the random access data device. Processing device 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, a touch screen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage device 1003 including, for example, a magnetic tape, hard disk, etc.; and communication device 1009. The communication device 1009 can allow the random access data device to communicate with other devices wirelessly or wired to exchange data. Although the figure shows a random access data device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.
[0149] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0150] The random data read and write device provided by this application utilizes the random data read and write method of the above-mentioned embodiment, which can solve the technical problem that related random data read and write methods allocate a fixed amount of storage space to store the data to be written, resulting in wasted space and a large number of indexes. Compared with the existing technology, the beneficial effects of the random data read and write device provided by this application are the same as those of the random data read and write method provided by the above-mentioned embodiment, and the other technical features of the random data read and write device are the same as those disclosed in the method of the above-mentioned embodiment, and are not further described here.
[0151] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0152] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
[0153] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, a computer program) stored thereon, wherein the computer-readable program instructions are used to execute the random data reading and writing method in the above-mentioned embodiment.
[0154] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0155] The computer-readable storage medium may be included in a random access data read / write device, or may exist independently without being assembled into a random access data read / write device.
[0156] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the random data read and write device, the random data read and write device executes the random data read and write method.
[0157] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0158] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0159] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.
[0160] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., a computer program) for executing the above-mentioned random data read and write method. It can solve the technical problem that the related random data read and write method allocates a fixed size of storage space to store the data to be written, thereby wasting space and having a large number of indexes. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the random data read and write method provided in the above-mentioned embodiment, and will not be repeated here.
[0161] The above description is only part of the embodiments of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for random reading and writing of data, characterized in that: The random reading and writing data method comprises: In the process of writing file data in the target file into the storage pool, determining a current write offset and a current write data amount corresponding to the current write data, and calculating a current data write range of the current write data according to the current write offset and the current write data amount; Dividing the currently written data into first written data and / or second written data, wherein the current data writing range of the first written data is within the file writing range corresponding to the small file, and the current data writing range of the second written data is within the file writing range corresponding to the large file; The first write data is written into a zone storage space in the storage pool, and / or the second write data is written into a region storage space in the storage pool, where the region storage space includes a plurality of continuous zone storage spaces.
2. The random data reading and writing method according to claim 1, wherein: Before writing the first write data into the zone storage space in the storage pool, and / or before writing the second write data into the region storage space in the storage pool, the method further includes: Determine the zone index / region index corresponding to the current data write range based on the correspondence between the data write range and the zone index / region index; Searching for the presence of the zone index / region index in the storage space index list corresponding to the target file; If the zone index / region index is not found, allocating the zone storage space / region storage space corresponding to the zone index / region index to the target file in the storage pool; Writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, includes: Writing the first write data into the zone storage space corresponding to the zone index in the storage pool, and / or writing the second write data into the region storage space corresponding to the region index in the storage pool; After writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, the method further includes: The zone index / region index is stored in the storage space index list corresponding to the target file.
3. The random data reading and writing method according to claim 2, wherein: After searching the storage space index list corresponding to the target file for whether the zone index / region index exists, the method further includes: If the zone index / region index is found, it is determined that a corresponding zone storage space / region storage space has been allocated for the zone index / region index in the storage pool; The first write data is written into the zone storage space corresponding to the zone index in the storage pool, and / or the second write data is written into the region storage space corresponding to the region index in the storage pool.
4. The random data reading and writing method according to claim 2 or 3, wherein: Writing the first write data into the zone storage space corresponding to the zone index in the storage pool, and / or writing the second write data into the region storage space corresponding to the region index in the storage pool, includes: Determine a first write position / second write position of the first write data / second write data in the zone storage space / region storage space according to a current data write range corresponding to the first write data / second write data and a data write range corresponding to the zone index / region index; The first write data is written to the zone storage space corresponding to the zone index in the storage pool according to the first write position, and / or the second write data is written to the region storage space corresponding to the region index in the storage pool according to the second write position.
5. The random data reading and writing method according to any one of claims 1 to 3, characterized in that: After writing the first write data into the zone storage space in the storage pool, and / or writing the second write data into the region storage space in the storage pool, the method further includes: In a process of reading file data of the target file from the storage pool, determining a current read offset and a current read data amount corresponding to the currently read data; Calculating a current data reading range of the currently read data according to the current reading offset and the currently read data amount; According to the correspondence between the data reading range and the zone index / region index, searching the storage space index list corresponding to the target file for the target zone index / region index corresponding to the current data reading range; Searching the storage pool for a target zone storage space / target region storage space corresponding to the target zone index / target region index; The currently read data is read from the target zone storage space / target region storage space.
6. The random data reading and writing method according to claim 5, wherein: After dividing the current write data into first write data and / or second write data, the method further includes: Acquire a current partitioning mode of the currently written data, and set a size attribute value of the target file according to the current partitioning mode; The searching, according to the correspondence between the data reading range and the zone index / region index, for the target zone index / target region index corresponding to the current data reading range in the storage space index list corresponding to the target file, includes: Determine the index list type of the storage space index list corresponding to the target file according to the size attribute value; According to the correspondence between the index list type and the data reading range and the zone index / region index, the target zone index / target region index corresponding to the current data reading range is searched in the storage space index list corresponding to the target file.
7. The random data reading and writing method according to any one of claims 1 to 3, characterized in that: The method further comprises: In the process of writing file data of the target file into the storage pool, obtaining a writing mode of first writing data of the target file; If the writing mode of the first-write data is to write the first-write data into the region storage space in the storage pool, the current-write data is written into the region storage space in the storage pool.
8. A random data read and write device, characterized in that: The random data reading and writing device comprises: a range determination module, configured to determine, during a process of writing file data in a target file into a storage pool, a current write offset and a current write data amount corresponding to the current write data, and calculate a current data write range of the current write data based on the current write offset and the current write data amount; a data division module, configured to divide the currently written data into first written data and / or second written data, wherein the current data writing range of the first written data is within the file writing range corresponding to the small file, and the current data writing range of the second written data is within the file writing range corresponding to the large file; A data writing module is used to write the first write data into the zone storage space in the storage pool, and / or write the second write data into the region storage space in the storage pool, where the region storage space includes multiple continuous zone storage spaces.
9. A random read and write data device, characterized in that The random read and write data device includes: a memory, a processor, and a random read and write data program stored in the memory and runnable on the processor. When the random read and write data program is executed by the processor, the random read and write data method according to any one of claims 1 to 7 is implemented.
10. A storage medium, characterized in that: The storage medium stores a random read and write data program, which, when executed by a processor, implements the random read and write data method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Distributed object storage space allocation method and device, equipment and storage medium
CN115344210A
Data processing method and device, equipment and storage medium
CN118963644A