Method and device for storing data in solid state disk

文档序号:923452 发布日期:2021-03-02 浏览:4次 中文

阅读说明:本技术 一种固态硬盘存储数据的方法和设备 (Method and device for storing data in solid state disk ) 是由 张博 于 2020-11-13 设计创作,主要内容包括:本发明提供了一种固态硬盘存储数据的方法和设备,该方法包括:响应于接收到存储数据的指令,将待存储的数据拆分成若干个字段并统计字段的数量;将字段的数量与固态硬盘的通道数量进行对比;响应于字段的数量大于通道数量,将拆分成的字段按照顺序依次循环写入固态硬盘的各个通道中。通过使用本发明的方案,能够能有效地提升读写性能,对于行和列均会作为索引的数据库需求,能极大的降低查询的复杂度,数据查询不需要返回全部字段的内容,大幅度提升查询和读取性能。(The invention provides a method and equipment for storing data in a solid state disk, wherein the method comprises the following steps: in response to receiving an instruction for storing data, splitting the data to be stored into a plurality of fields and counting the number of the fields; comparing the number of the fields with the number of channels of the solid state disk; and responding to the fact that the number of the fields is larger than the number of the channels, and sequentially and circularly writing the split fields into the channels of the solid state disk. By using the scheme of the invention, the read-write performance can be effectively improved, the query complexity can be greatly reduced for the database requirement that both rows and columns can be used as indexes, the contents of all fields do not need to be returned for data query, and the query and read performance is greatly improved.)

1. A method for storing data in a solid state disk is characterized by comprising the following steps:

in response to receiving an instruction for storing data, splitting the data to be stored into a plurality of fields and counting the number of the fields;

comparing the number of the fields with the number of channels of the solid state disk;

and in response to the fact that the number of the fields is larger than the number of the channels, sequentially and circularly writing the split fields into the channels of the solid state disk.

2. The method of claim 1, further comprising:

and in response to that the number of the fields is smaller than the number of the channels, writing each of the split fields into different channels of the solid state disk respectively.

3. The method of claim 1, further comprising:

comparing the number of fields written in a single channel to the number of LUNs in the single channel;

in response to the number of fields written in the single channel being greater than the number of LUNs in the single channel, sequentially and cyclically writing the fields written in the single channel in the LUNs in sequence.

4. The method of claim 1, further comprising:

recording data information of data to be stored;

recording the physical address of the channel of the solid state disk, which is stored by the split field;

and drawing the data information and the physical address into a database.

5. The method of claim 4, wherein the data information comprises a user ID, a field name, a field type, and a field length.

6. An apparatus for storing data in a solid state disk, the apparatus comprising:

the splitting module is configured to split the data to be stored into a plurality of fields and count the number of the fields in response to receiving the instruction for storing the data;

the comparison module is configured to compare the number of the fields with the number of channels of the solid state disk;

and the writing module is configured to respond that the number of the fields is larger than the number of the channels, and sequentially and circularly write the split fields into the channels of the solid state disk in sequence.

7. The device of claim 6, further comprising a storage module configured to:

and in response to that the number of the fields is smaller than the number of the channels, writing each of the split fields into different channels of the solid state disk respectively.

8. The device of claim 6, further comprising a comparison module configured to:

comparing the number of fields written in a single channel to the number of LUNs in the single channel;

in response to the number of fields written in the single channel being greater than the number of LUNs in the single channel, sequentially and cyclically writing the fields written in the single channel in the LUNs in sequence.

9. The device of claim 6, further comprising a rendering module configured to:

recording data information of data to be stored;

recording the physical address of the channel of the solid state disk, which is stored by the split field;

and drawing the data information and the physical address into a database.

10. The apparatus of claim 9, wherein the data information comprises a user ID, a field name, a field type, and a field length.

Technical Field

The field relates to the field of computers, and more particularly to a method and apparatus for storing data in a solid state disk.

Background

A Solid State Disk (SSD) is a device used to store user data. The solid state disk is composed of modules such as a controller and a storage medium NAND (flash memory). Firmware (embedded software running on the controller) is run in the controller to control resources, store and schedule user data, maintain NAND equipment and the like. NAND is a storage medium and is a chip, and a solid state disk often has a plurality of NAND particles therein. The solid state disk can provide high concurrent read-write performance because the solid state disk is internally provided with a plurality of storage units which can be operated in parallel, when each storage unit is used for reading and writing, other storage units can respond to other read-write requests, and a plurality of storage units are arranged in one NAND particle.

A database is a software structure used to store user data. And an adding, deleting, modifying and searching interface is provided for a user. The user may be allowed to store new data, delete old data, modify stored data, and query for existing data. The database can be divided into a row database and a column database according to the implementation principle. A user often stores a piece of information (referred to as a record) in a plurality of fields. The plurality of pieces of information are stored in the database and can be regarded as a two-dimensional table. The structure of the database is a row structure if one record is stored together and a column structure if fields are stored together. In general, databases are either row-structured or column-structured. For the row structure database, when a user needs to index a column, it is easy to obtain the entire contents of the record, but not easy to obtain the entire contents of the field. Therefore, when there is a need to index according to both the column and the row, two data sets are often stored, corresponding to the row index and the column index respectively.

Disclosure of Invention

In view of this, an object of the embodiments of the present invention is to provide a method and an apparatus for storing data in a solid state disk, which can effectively improve read-write performance, greatly reduce query complexity for a database requirement that rows and columns are both used as indexes, and greatly improve query and read performance without returning contents of all fields for data query.

In view of the above object, an aspect of the embodiments of the present invention provides a method for a solid state disk to store data, including the following steps:

in response to receiving an instruction for storing data, splitting the data to be stored into a plurality of fields and counting the number of the fields;

comparing the number of the fields with the number of channels of the solid state disk;

and responding to the fact that the number of the fields is larger than the number of the channels, and sequentially and circularly writing the split fields into the channels of the solid state disk.

According to an embodiment of the present invention, further comprising:

and respectively writing each split field into different channels of the solid state disk in response to the fact that the number of the fields is smaller than the number of the channels.

According to an embodiment of the present invention, further comprising:

comparing the number of fields written in a single channel with the number of LUNs in the single channel;

and in response to the number of the fields written into the single channel being larger than the number of the LUNs in the single channel, sequentially and circularly writing the fields written into the single channel into the LUNs in sequence.

According to an embodiment of the present invention, further comprising:

recording data information of data to be stored;

recording the physical address of the channel for storing the split field to the solid state disk;

and drawing the data information and the physical address into a database.

According to one embodiment of the present invention, the data information includes a user ID, a field name, a field type, and a field length.

In another aspect of the embodiments of the present invention, there is also provided an apparatus for storing data in a solid state disk, where the apparatus includes:

the splitting module is configured to split the data to be stored into a plurality of fields and count the number of the fields in response to receiving the instruction for storing the data;

the comparison module is configured to compare the number of the fields with the number of the channels of the solid state disk;

and the writing module is configured to respond that the number of the fields is larger than the number of the channels, and sequentially and circularly write the split fields into the channels of the solid state disk in sequence.

According to an embodiment of the present invention, the apparatus further comprises a storage module configured to:

and respectively writing each split field into different channels of the solid state disk in response to the fact that the number of the fields is smaller than the number of the channels.

According to an embodiment of the present invention, the apparatus further comprises a comparison module configured to:

comparing the number of fields written in a single channel with the number of LUNs in the single channel;

and in response to the number of the fields written into the single channel being larger than the number of the LUNs in the single channel, sequentially and circularly writing the fields written into the single channel into the LUNs in sequence.

According to an embodiment of the invention, the system further comprises a rendering module configured to:

recording data information of data to be stored;

recording the physical address of the channel for storing the split field to the solid state disk;

and drawing the data information and the physical address into a database.

According to one embodiment of the present invention, the data information includes a user ID, a field name, a field type, and a field length.

The invention has the following beneficial technical effects: according to the method for storing data in the solid state disk, provided by the embodiment of the invention, the data to be stored is divided into a plurality of fields and the number of the fields is counted by responding to the received instruction for storing the data; comparing the number of the fields with the number of channels of the solid state disk; the technical scheme that the split fields are sequentially and circularly written into the channels of the solid state disk in sequence in response to the fact that the number of the fields is larger than that of the channels can effectively improve the read-write performance, greatly reduce the query complexity for the database requirement that rows and columns can serve as indexes, avoid returning the contents of all the fields for data query, and greatly improve the query and read performance.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other embodiments can be obtained by using the drawings without creative efforts.

Fig. 1 is a schematic flow chart of a method for storing data in a solid state disk according to an embodiment of the present invention;

fig. 2 is a schematic diagram of an apparatus for storing data in a solid state disk according to an embodiment of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the present invention more apparent, the following embodiments of the present invention are described in further detail with reference to the accompanying drawings.

In view of the foregoing, in a first aspect of the embodiments of the present invention, an embodiment of a method for storing data in a solid state disk is provided. Fig. 1 shows a schematic flow diagram of the method.

As shown in fig. 1, the method may include the steps of:

s1, responding to the received instruction of storing data, dividing the data to be stored into a plurality of fields and counting the number of the fields, dividing the data to be stored of a user into a plurality of fields according to any rule, and then counting how many fields the data are divided into in total, wherein the data can be a comprehensive data structure, not only a number or a character string, but also an image, audio, a composite data structure and the like, for example, the data is used for the field of image retrieval, the user can use images of different thumbnails and the types of the images as the stored data, and each field is no longer a few bytes but has a larger capacity;

s2, comparing the number of the fields with the number of the channels of the solid state disk, wherein the solid state disk comprises a plurality of channels, each channel comprises a plurality of LUNs, each LUN comprises a plurality of blocks, the divided fields are stored in the plurality of channels of the solid state disk, and if the number of the channels is more than the number of the fields, each field is independently stored in the LUN of one channel;

s3, responding to the fact that the number of the fields is larger than the number of the channels, sequentially and circularly writing the split fields into the channels of the solid state disk, if the number of the fields exceeds the number of the channels, putting the fields into the channels in turn, for example, 1000 fields are stored, only 16 channels exist in the system, then the field 0, the field 16 and the field 32 … of the data are written into the channel 0, the field 1, the field 17 and the field 33 … are written into the channel 1, and the like.

By the technical scheme, the read-write performance can be effectively improved, the query complexity can be greatly reduced for the database requirement that both rows and columns can be used as indexes, the contents of all fields do not need to be returned for data query, and the query and read performance is greatly improved.

In a preferred embodiment of the present invention, the method further comprises:

and respectively writing each split field into different channels of the solid state disk in response to the fact that the number of the fields is smaller than the number of the channels. If the number of fields is less than the number of channels, then each field is stored separately in one channel, i.e., each channel stores a unique one field of the data.

In a preferred embodiment of the present invention, the method further comprises:

comparing the number of fields written in a single channel with the number of LUNs in the single channel;

and in response to the number of the fields written into the single channel being larger than the number of the LUNs in the single channel, sequentially and circularly writing the fields written into the single channel into the LUNs in sequence. Because the middle storage unit in the solid state disk hardware is also of a two-dimensional structure and is divided into a plurality of Logical Units (LUNs), and each LUN has a plurality of blocks, when the number of fields of a user is less than the number of LUNs, each field exclusively occupies one LUN, and when the number of fields exceeds the number of LUNs, a plurality of uniform fields share one LUN, and the LUNs can be circularly written in the above manner, or the number of fields that can be stored in each LUN can be calculated, and then the fields are randomly stored in the LUNs according to the number.

In a preferred embodiment of the present invention, the method further comprises:

recording data information of data to be stored;

recording the physical address of the channel for storing the split field to the solid state disk;

and drawing the data information and the physical address into a database.

In a preferred embodiment of the present invention, the data information includes a user ID, a field name, a field type, and a field length. The host computer can also create a database according to a data storage mode, and the addition, deletion and check of the database data can also be realized through IO data commands. If the command is implemented by an IO command, the two steps are divided, and the command word is written in the first write operation, such as adding, deleting and reading. If it is an add operation to the database, a second write operation writes the data record. If it is a read operation, the data content can be read out by sending a read command a second time. And (3) splitting the written data of the user according to the field structure in the firmware processing process of the solid state disk, and putting each field into a corresponding channel. And records a mapping table of the ID and physical address of this user data. If the user needs to index certain rows or columns, this index is also recorded. The index and the mapping table are used as meta information of the database, and are stored in an area of the SSD when the power is off, and are stored in the RAM when the power is on. When a user inquires, the physical address corresponding to the data is found based on the user ID and the index table of the physical address. And then, reading the data of the physical addresses and sending the data to the host side. When the user deletes, the meta information of the database is modified, including modifying the mapping table and the index table. Since NAND only supports erasing in block units, firmware of solid state disks performs garbage collection operations in the background.

And the index table and the mapping table of the database are stored in the RAM space of the solid state disk. When power is down, the tables are written back to the NAND region, and are reloaded into the memory when power is up next time. Generally, memory space is much smaller than NAND memory space. Therefore, when the memory is exhausted, the solid state disk reports to the host and stops receiving new write-in operation until the database is deleted to have new memory space. When the database is queried, firmware receives a query request of a user, queries an index table, and finds that the data are distributed in different rows and columns after obtaining the data. Because each LUN can be read simultaneously, firmware organizes data, so that each LUN can process read operation concurrently as much as possible, and the performance of NAND is utilized to the maximum extent. Since the NAND media do not support direct modification of stored data, if a host needs to modify a certain data record, the host should first erase and then rewrite the data record to implement the modification.

By the technical scheme, the read-write performance can be effectively improved, the query complexity can be greatly reduced for the database requirement that both rows and columns can be used as indexes, the contents of all fields do not need to be returned for data query, and the query and read performance is greatly improved.

It should be noted that, as will be understood by those skilled in the art, all or part of the processes in the methods of the above embodiments may be implemented by instructing relevant hardware through a computer program, and the above programs may be stored in a computer-readable storage medium, and when executed, the programs may include the processes of the embodiments of the methods as described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like. The embodiments of the computer program may achieve the same or similar effects as any of the above-described method embodiments.

Furthermore, the method disclosed according to an embodiment of the present invention may also be implemented as a computer program executed by a CPU, and the computer program may be stored in a computer-readable storage medium. The computer program, when executed by the CPU, performs the above-described functions defined in the method disclosed in the embodiments of the present invention.

In view of the above object, according to a second aspect of the embodiments of the present invention, there is provided an apparatus for storing data in a solid state disk, as shown in fig. 2, the apparatus 200 includes:

the splitting module is configured to split the data to be stored into a plurality of fields and count the number of the fields in response to receiving the instruction for storing the data;

the comparison module is configured to compare the number of the fields with the number of the channels of the solid state disk;

and the writing module is configured to respond that the number of the fields is larger than the number of the channels, and sequentially and circularly write the split fields into the channels of the solid state disk in sequence.

In a preferred embodiment of the present invention, the apparatus further comprises a storage module configured to:

and respectively writing each split field into different channels of the solid state disk in response to the fact that the number of the fields is smaller than the number of the channels.

In a preferred embodiment of the present invention, the apparatus further comprises a comparison module configured to:

comparing the number of fields written in a single channel with the number of LUNs in the single channel;

and in response to the number of the fields written into the single channel being larger than the number of the LUNs in the single channel, sequentially and circularly writing the fields written into the single channel into the LUNs in sequence.

In a preferred embodiment of the present invention, the system further comprises a rendering module configured to:

recording data information of data to be stored;

recording the physical address of the channel for storing the split field to the solid state disk;

and drawing the data information and the physical address into a database.

In a preferred embodiment of the present invention, the data information includes a user ID, a field name, a field type, and a field length.

The embodiments described above, particularly any "preferred" embodiments, are possible examples of implementations and are presented merely to clearly understand the principles of the invention. Many variations and modifications may be made to the above-described embodiments without departing from the spirit and principles of the technology described herein. All such modifications are intended to be included within the scope of this disclosure and protected by the following claims.

8页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种计算机用数据迁移系统及方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类