Data writing method, data query method, device and equipment
By writing the data to be written into multiple sub-data blocks according to the data source identifier in the data node and generating an index file, the problem of low data query efficiency in the data storage system is solved and fast data query is achieved.
Patent Information
- Application Number
- CN201811331057.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-11-09
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2038-11-09
AI Technical Summary
In data storage systems, as the amount of data increases, data query efficiency becomes low, and a large number of queries are required to determine the target data node where the data to be queried is located.
By storing the data to be written in the first data block of the memory in the data node, and after the first data block is full, write it to the sub-data block of the second data block of the persistent disk according to the data source identifier. , and generate an index file to record the mapping relationship between each data source identifier and sub-data blocks for quick query.
The efficiency of data query is improved, enabling the data storage system to quickly query data based on storing large amounts of data.
Smart Images

Figure CN111241088B
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of storage, and in particular to a data writing method, a data query method, a device and an apparatus. Background Art
[0002] Currently, in many data storage systems, a large amount of data needs to be stored, and frequent data writing operations and data query operations need to be performed.
[0003] In the prior art, in order to enable a data storage system to store a large amount of data, multiple data nodes are usually deployed in the data storage system, and the multiple data nodes perform data storage and data reading and writing. In actual application, when writing data, usually one data node is selected from multiple storage nodes for data storage, and the identification of the data stored in each data node is recorded. When querying data, the target data node is determined according to the identification of the data stored in each data node and the identification of the data to be queried, and the data to be queried is obtained from the target data node.
[0004] However, in the above process, when the amount of data stored in the data storage system is large, a large number of data queries are required to determine the target data node where the data to be queried is located, resulting in low efficiency of data query. Summary of the invention
[0005] The embodiments of the present invention provide a data writing method, a data query method, a device and an apparatus, which can quickly perform data query while ensuring that a data storage system can store a large amount of data.
[0006] In a first aspect, an embodiment of the present invention provides a data writing method, which is applied to a data node, and the method includes:
[0007] Receiving the data to be written and the data source identifier of the data to be written sent by the gateway;
[0008] Writing the data to be written and the data source identifier into a first data block in the memory of the data node;
[0009] After the first data block is full, the data in the first data block is written into a sub-data block of a second data block of the data node according to a data source identifier in the first data block, the second data block is located in a persistent disk of the data node, and the second data block includes multiple sub-data blocks.
[0010] In a possible implementation manner, writing the data in the first data block into a sub-data block of the second data block of the data node according to the data source identifier in the first data block includes:
[0011] determining at least one data source identifier included in the first data block;
[0012] Determining data corresponding to each data source identifier in the first data block;
[0013] The data corresponding to each data source identifier is sequentially written into the sub-data block of the second data block.
[0014] In another possible implementation manner, after sequentially writing the data corresponding to each data source identifier into the sub-data block of the second data block, the method further includes:
[0015] generating an index file of the second data block;
[0016] The index file includes a first mapping relationship between each data source identifier in the second data block and a sub-data block, and a second mapping relationship between each data tag included in the data source identifier in the second data block and a sub-data block.
[0017] In another possible implementation, the index file further includes a storage location of a first mapping relationship corresponding to each data source identifier in the index file, and a storage location of a second mapping relationship corresponding to each data tag in the index file.
[0018] In a second aspect, an embodiment of the present invention provides a data writing method, which is applied to a gateway, and the method includes:
[0019] receiving a data writing request, wherein the data writing request includes data to be written and a data source identifier of the data to be written;
[0020] Determine the target data node corresponding to the data to be written according to the data source identifier;
[0021] The data to be written and the data source identifier are sent to the target data node, and the target data node is used to store the data to be written in the target data node according to the data source identifier.
[0022] In a possible implementation manner, determining the target data node corresponding to the to-be-written data according to the data source identifier includes:
[0023] Determine whether the cache includes the data node identifier corresponding to the data source identifier;
[0024] If yes, determining the data node indicated by the data node identifier corresponding to the data source identifier in the cache as the target data node;
[0025] If not, determine whether the routing information database includes the data node identifier corresponding to the data source identifier. If so, determine the data node indicated by the data node identifier corresponding to the data source identifier in the routing information database as the target data node; if not, determine the target data node based on the remaining capacity of each data node in the distributed storage system.
[0026] In another possible implementation, sending the to-be-written data to the target data node includes:
[0027] Storing the data to be written and the data source identifier in a message queue;
[0028] Acquire the to-be-written data and the data source identifier in the message queue through an idle thread among multiple threads;
[0029] The to-be-written data and the data source identifier are sent to the target data node through the idle thread.
[0030] In a third aspect, an embodiment of the present invention provides a data query method, which is applied to a data node, and the method includes:
[0031] Receiving a first data query condition sent by a gateway;
[0032] Determine a target data block in the data node according to the first data query condition;
[0033] Determine a target sub-data block according to the first data query condition and an index file of the target data block, wherein the index file includes a first mapping relationship between each data source identifier in the target data block and the sub-data block, and a second mapping relationship between each data tag in the data source identifier in the target data block and the sub-data block;
[0034] Target data is determined in the target sub-data block, and the target data is sent to the gateway.
[0035] In a possible implementation manner, determining the target sub-data block according to the first data query condition and the index file of the target data block includes:
[0036] Determining whether the first data query condition includes a first data source identifier;
[0037] If yes, obtaining a first mapping relationship corresponding to the first data source identifier, and determining the sub-data block in the first mapping relationship corresponding to the first data source identifier as the target sub-data block;
[0038] If not, obtain at least one first data tag included in the first data query condition, obtain the second mapping relationship corresponding to each first data tag, and determine the target sub-data block according to the second mapping relationship corresponding to each first data tag.
[0039] In another possible implementation, the index file further includes a storage position of the first mapping relationship corresponding to each data source identifier in the index file; and obtaining the first mapping relationship corresponding to the first data source identifier includes:
[0040] Obtain a first storage position of a first mapping relationship corresponding to the first data source identifier in the index file;
[0041] A first mapping relationship corresponding to the first data source identifier is obtained in the first storage location.
[0042] In another possible implementation, the index file further includes a storage position of the second mapping relationship corresponding to each data tag in the index file; and obtaining the second mapping relationship corresponding to each first data tag includes:
[0043] Obtain a second mapping relationship corresponding to each first data tag at a second storage location in the index file;
[0044] A second mapping relationship corresponding to each first data tag is obtained in the second storage location.
[0045] In another possible implementation, determining the target sub-data block according to the second mapping relationship corresponding to each first data tag includes:
[0046] The sub-data blocks included in the second mapping relationship corresponding to each first data tag are determined as the target sub-data blocks.
[0047] In a fourth aspect, an embodiment of the present invention provides a data query method, which is applied to a gateway, and the method includes:
[0048] receiving a data query request, wherein the data query request includes a first data query condition;
[0049] Determine a target data node corresponding to the first data query condition;
[0050] Sending the first data query condition to the target data node, the target data node is used to determine the target data according to the first query condition;
[0051] Receive the target data sent by the target data node.
[0052] In a possible implementation manner, determining the target data node corresponding to the first data query condition includes:
[0053] Extracting a second data query condition from the first data query condition, where the second data query condition is a data query condition included in the preset corresponding relationship, where the preset corresponding relationship includes multiple data query conditions and an identifier of a data node corresponding to each data query condition;
[0054] The target data node is determined according to the second data query condition and the preset corresponding relationship.
[0055] In a fifth aspect, an embodiment of the present invention provides a data writing device, characterized in that it includes a receiving module and a writing module, wherein:
[0056] The receiving module is used to receive the data to be written and the data source identifier of the data to be written sent by the gateway;
[0057] The writing module is used to write the data to be written and the data source identifier into the first data block in the memory of the data node;
[0058] The writing module is also used to, after the first data block is full, write the data in the first data block into a sub-data block of a second data block of the data node according to a data source identifier in the first data block, the second data block being located in a persistent disk of the data node, and the second data block including multiple sub-data blocks.
[0059] In a possible implementation manner, the writing module is specifically used for:
[0060] determining at least one data source identifier included in the first data block;
[0061] Determining data corresponding to each data source identifier in the first data block;
[0062] The data corresponding to each data source identifier is sequentially written into the sub-data block of the second data block.
[0063] In another possible implementation, the device further includes a generating module, wherein:
[0064] The generating module is used for generating an index file of the second data block after the writing module writes the data corresponding to each data source identifier into the sub-data block of the second data block in sequence;
[0065] The index file includes a first mapping relationship between each data source identifier in the second data block and a sub-data block, and a second mapping relationship between each data tag included in the data source identifier in the second data block and a sub-data block.
[0066] In another possible implementation, the index file further includes a storage location of a first mapping relationship corresponding to each data source identifier in the index file, and a storage location of a second mapping relationship corresponding to each data tag in the index file.
[0067] In a sixth aspect, an embodiment of the present invention provides a data writing device, comprising a receiving module, a determining module and a sending module, wherein:
[0068] The receiving module is used to receive a data writing request, wherein the data writing request includes the data to be written and the data source identifier of the data to be written;
[0069] The determination module is used to determine the target data node corresponding to the data to be written according to the data source identifier;
[0070] The sending module is used to send the data to be written and the data source identifier to the target data node, and the target data node is used to store the data to be written in the target data node according to the data source identifier.
[0071] In another possible implementation, the determining module is specifically configured to:
[0072] Determine whether the cache includes the data node identifier corresponding to the data source identifier;
[0073] If yes, determining the data node indicated by the data node identifier corresponding to the data source identifier in the cache as the target data node;
[0074] If not, determine whether the routing information database includes the data node identifier corresponding to the data source identifier. If so, determine the data node indicated by the data node identifier corresponding to the data source identifier in the routing information database as the target data node; if not, determine the target data node based on the remaining capacity of each data node in the distributed storage system.
[0075] In another possible implementation, the sending module is specifically configured to:
[0076] Storing the data to be written and the data source identifier in a message queue;
[0077] Acquire the to-be-written data and the data source identifier in the message queue through an idle thread among the multiple threads;
[0078] The to-be-written data and the data source identifier are sent to the target data node through the idle thread.
[0079] In a seventh aspect, an embodiment of the present invention provides a data query device, comprising a receiving module, a first determining module, a second determining module, a third determining module and a sending module, wherein:
[0080] The receiving module is used to receive the first data query condition sent by the gateway;
[0081] The first determination module is used to determine a target data block in the data node according to the first data query condition;
[0082] The second determination module is used to determine the target sub-data block according to the first data query condition and the index file of the target data block, wherein the index file includes a first mapping relationship between each data source identifier in the target data block and the sub-data block, and a second mapping relationship between each data tag in the data source identifier in the target data block and the sub-data block;
[0083] The third determination module is used to determine the target data in the target sub-data block;
[0084] The sending module is used to send the target data to the gateway.
[0085] In a possible implementation manner, the second determining module is specifically configured to:
[0086] Determining whether the first data query condition includes a first data source identifier;
[0087] If yes, obtaining a first mapping relationship corresponding to the first data source identifier, and determining the sub-data block in the first mapping relationship corresponding to the first data source identifier as the target sub-data block;
[0088] If not, obtain at least one first data tag included in the first data query condition, obtain the second mapping relationship corresponding to each first data tag, and determine the target sub-data block according to the second mapping relationship corresponding to each first data tag.
[0089] In another possible implementation manner, the index file further includes a storage location of the first mapping relationship corresponding to each data source identifier in the index file; and the second determining module is specifically configured to:
[0090] Obtain a first storage position of a first mapping relationship corresponding to the first data source identifier in the index file;
[0091] A first mapping relationship corresponding to the first data source identifier is obtained in the first storage location.
[0092] In another possible implementation, the index file further includes a storage location of the second mapping relationship corresponding to each data tag in the index file; and the second determination module is specifically configured to:
[0093] Obtain a second mapping relationship corresponding to each first data tag at a second storage location in the index file;
[0094] A second mapping relationship corresponding to each first data tag is obtained in the second storage location.
[0095] In another possible implementation manner, the second determining module is specifically configured to:
[0096] The sub-data blocks included in the second mapping relationship corresponding to each first data tag are determined as the target sub-data blocks.
[0097] In an eighth aspect, an embodiment of the present invention provides a data query device, including a receiving module, a determining module and a sending module, wherein:
[0098] The receiving module is used to receive a data query request, wherein the data query request includes a first data query condition;
[0099] The determination module is used to determine the target data node corresponding to the first data query condition;
[0100] The sending module is used to send the first data query condition to the target data node, and the target data node is used to determine the target data according to the first query condition;
[0101] The receiving module is further used to receive the target data sent by the target data node.
[0102] In a possible implementation manner, the determining module is specifically configured to:
[0103] Extracting a second data query condition from the first data query condition, where the second data query condition is a data query condition included in the preset corresponding relationship, where the preset corresponding relationship includes multiple data query conditions and an identifier of a data node corresponding to each data query condition;
[0104] The target data node is determined according to the second data query condition and the preset corresponding relationship.
[0105] In a ninth aspect, an embodiment of the present invention provides a data node, including a processor, wherein the processor is coupled to a memory, wherein:
[0106] The memory is used to store computer programs;
[0107] The processor is used to execute the computer program stored in the memory to implement the data writing method described in any one of the first aspects above.
[0108] In a tenth aspect, an embodiment of the present invention provides a gateway, comprising: a processor, the processor is coupled to a memory, wherein:
[0109] The memory is used to store computer programs;
[0110] The processor is used to execute the computer program stored in the memory to implement the data writing method described in any one of the second aspects above.
[0111] In an eleventh aspect, an embodiment of the present invention provides a data node, a processor, wherein the processor is coupled to a memory, wherein:
[0112] The memory is used to store computer programs;
[0113] The processor is used to execute the computer program stored in the memory to implement the data query method described in any one of the third aspects above.
[0114] In a twelfth aspect, an embodiment of the present invention provides a gateway, comprising: a processor, the processor is coupled to a memory, wherein:
[0115] The memory is used to store computer programs;
[0116] The processor is used to execute the computer program stored in the memory to implement the data query method described in any one of the fourth aspects above.
[0117] In a thirteenth aspect, an embodiment of the present invention provides a readable storage medium, comprising a program or instructions. When the program or instructions are run on a computer, the data writing method as described in any one of the first aspects above is executed.
[0118] In a fourteenth aspect, an embodiment of the present invention provides a readable storage medium, characterized in that it includes a program or instructions. When the program or instructions are run on a computer, the data writing method as described in any one of the second aspects is executed.
[0119] In a fifteenth aspect, an embodiment of the present invention provides a readable storage medium, comprising a program or instructions. When the program or instructions are run on a computer, the data query method as described in any one of the third aspects is executed.
[0120] In the sixteenth aspect, an embodiment of the present invention provides a readable storage medium, including a program or an instruction. When the program or the instruction runs on a computer, the data query method as described in any one of the fourth aspects is executed.
[0121] The data writing method, data query method, device and equipment provided by the embodiment of the present invention, when the terminal device writes the data to be written to the data storage system, the gateway first determines the target data node according to the routing information in the routing information database, and sends the data to be written to the target data node. The target data node first stores the data to be written in the first data block of the memory, and after the first data block is full, the data in the first data block is written into the sub-data block of the second data block of the target data node according to the data source identifier in the first data block. As can be seen from the above, the persistent storage space of the target data node includes multiple second data blocks, each of which includes multiple sub-data blocks, and the target data node writes the data in the first data block into the sub-data block of the second data block according to the data source identifier in the first data block, so that the data can be stored regularly and hierarchically in the target data node, so that the target data node can quickly find the data to be queried. Further, the data nodes and gateways in the data storage system shown in the present application can be expanded according to actual needs, so that the data storage system can store a large amount of data, so that it can be ensured that the data query can be quickly performed on the basis of the data storage system being able to store a large amount of data. BRIEF DESCRIPTION OF THE DRAWINGS
[0122] In order to more clearly illustrate the embodiments of the present invention 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, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0123] Figure 1 An architectural diagram of a data storage system provided by an embodiment of the present invention;
[0124] Figure 2 Schematic diagram of a data writing method provided by an embodiment of the present invention Figure 1 ;
[0125] Figure 2A A schematic diagram of a data block in a data node provided by an embodiment of the present invention;
[0126] Figure 3 Schematic diagram of a data writing method provided by an embodiment of the present invention Figure 2 ;
[0127] Figure 4 Schematic diagram of the process of the data query method provided by the embodiment of the present invention Figure 1 ;
[0128] Figure 5A schematic diagram of the structure of a data writing device provided by an embodiment of the present invention;
[0129] Figure 6 A schematic diagram of the structure of another data writing device provided by an embodiment of the present invention;
[0130] Figure 7 A schematic diagram of the structure of another data writing device provided by an embodiment of the present invention;
[0131] Figure 8 A schematic diagram of the structure of a data query device provided by an embodiment of the present invention;
[0132] Fig. 9 A schematic diagram of the structure of another data query device provided by an embodiment of the present invention;
[0133] Fig.10 A schematic diagram of the hardware structure of a data node provided by an embodiment of the present invention;
[0134] Fig.11 A schematic diagram of the hardware structure of a gateway provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0135] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0136] Figure 1 This is an architecture diagram of the data storage system provided by an embodiment of the present invention. Figure 1 The data storage system includes multiple gateways (respectively recorded as gateway 101-1, gateway 101-2, ..., gateway 101-M), at least one routing information database 102, multiple master data nodes (respectively recorded as master data node 103-1, master data node 103-2, ..., master data node 103-N), and slave data nodes corresponding to each master data node (respectively recorded as slave data node 104-1, slave data node 104-2, ..., slave data node 104-N). The terminal device 105 can write data and / or query data in the data storage system.
[0137] Optionally, the number of gateways, the number of routing information databases, the number of master data nodes, and the number of slave data nodes included in the data storage system may be determined according to actual needs.
[0138] Optionally, one gateway may correspond to some of the master data nodes. The correspondence between the gateway and the master data nodes may be set according to actual needs.
[0139] Optionally, when there are multiple routing information databases, one routing information database may correspond to some gateways. The corresponding relationship between the routing information database and the gateway may be set according to actual needs.
[0140] Optionally, the terminal device 105 may be a data source device for writing data into the data storage system. The terminal device 105 may be a client for querying data in the data storage system. The terminal device 105 may also both write data into the data storage system and read data from the data storage system.
[0141] It should be noted that Figure 1 The architecture of the data storage system is merely illustrated in an exemplary form, and is not intended to limit the architecture of the data storage system. In actual application, the data storage system may be configured according to actual needs, and the embodiments of the present invention do not specifically limit this.
[0142] In the present application, when a terminal device writes data to a data storage system, the gateway first determines the corresponding master data node based on the routing information in the routing information database, and sends the data to be written to the corresponding master data node. The master data node includes multiple data blocks, each data block also includes multiple sub-data blocks, and a corresponding index file. The master data node stores the data to be stored in the corresponding sub-data block according to the data source identifier of the data to be stored, and records it in the index file. When the terminal device performs a data query, the gateway first determines the corresponding master data node based on the query conditions, and then the master data node further searches for the data to be queried based on the data query conditions. Since the master data node includes data blocks, and the data blocks include sub-data blocks and index files, based on this storage structure, the group data node can quickly query the data to be queried based on the query conditions and index files, thereby improving the data query efficiency.
[0143] The technical solution shown in the present application is described in detail below through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar contents will not be repeatedly described in different embodiments.
[0144] It should be noted that, in the embodiments of the present invention, unless otherwise specified, the data nodes described are Figure 1 The master data node in an embodiment.
[0145] Figure 2 Schematic diagram of a data writing method provided by an embodiment of the present invention Figure 1 . See Figure 2, the method may include:
[0146] S201. The terminal device sends a data write request to the gateway.
[0147] The data writing request includes the data to be written and the data source identifier of the data to be written.
[0148] Optionally, the terminal device is used for a mobile phone, a computer, an industrial device, etc. For example, the industrial device may be a satellite, a traffic camera, etc.
[0149] Of course, in actual application, the type of terminal equipment can be set according to actual needs, and the embodiment of the present invention does not specifically limit this.
[0150] Optionally, the data source identifier is used to indicate a device generating data to be written and a type of data to be written.
[0151] Optionally, the data source identifier may include multiple data tags.
[0152] Optionally, the data tag in the data source identifier may include: device type, device identifier, and data type.
[0153] Of course, the data tag in the data source identifier may also include other data tags, which are not specifically limited in the embodiment of the present invention.
[0154] For example, a data source identifier may be: satellite, Dongfanghong-1, temperature, wherein "satellite", "Dongfanghong-1", and "temperature" are all data labels in the data source identifier.
[0155] For example, assuming that the data source identifier of the data to be written is: satellite, Dongfanghong-1, temperature, it means that the data to be written is the temperature collected by Dongfanghong-1, and Dongfanghong-1 is a satellite.
[0156] Optionally, the data writing request may also include the generation time of the data to be written.
[0157] S202: The gateway determines the target data node corresponding to the data to be written according to the data source identifier.
[0158] Optionally, the target data node corresponding to the data to be written may be determined by the following feasible implementation methods:
[0159] If the cache of the gateway includes the data node identifier corresponding to the data source identifier, the data node indicated by the data node identifier corresponding to the data source identifier in the cache is determined as the target data node.
[0160] If the gateway cache does not include the data node identifier corresponding to the data source identifier, it is determined whether the routing information database includes the data node identifier corresponding to the data source identifier. If so, the data node indicated by the data node identifier corresponding to the data source identifier in the routing information database is determined as the target data node; if not, the target data node is determined based on the remaining capacity of each data node in the distributed storage system.
[0161] Optionally, the routing information database is used to store routing information, and the routing information can be the corresponding relationship between the data source identifier and the data node. The routing information stored in the routing information database is updated periodically. For example, the routing information in the routing information database is updated once a day. For example, the routing information in the routing information database can be deleted at a preset time.
[0162] Initially, the routing information database does not include routing information (the correspondence between the data source identifier and the data node), and the gateway cache does not include the correspondence between the data source identifier and the data node. Therefore, initially, the gateway needs to determine the target data node based on the remaining capacity of each data node in the distributed storage system.
[0163] Optionally, the gateway may determine a data node with the largest remaining capacity among the data nodes as the target data node.
[0164] After the gateway determines the target data node corresponding to the data to be written, it can determine the correspondence between the data source identifier corresponding to the data to be written and the target data node, and store the correspondence in the gateway's cache and in the routing information database.
[0165] Optionally, after the gateway stores the corresponding relationship in the routing information database, other gateways may obtain the corresponding relationship from the routing information database.
[0166] S203: The gateway sends the data to be written and the data source identifier of the data to be written to the target data node.
[0167] Optionally, the gateway may also send the generation time of the data to be written to the target data node.
[0168] Optionally, the gateway may send the data to be written and the data source identifier to the target data node through the following feasible implementation method: storing the data to be written and the data source identifier in a message queue; obtaining the data to be written and the data source identifier in the message queue through an idle thread among multiple threads; and sending the data to be written and the data source identifier to the target data node through the idle thread.
[0169] Optionally, the gateway may store the data to be written and the data source identifier at the end of the message queue.
[0170] Optionally, the gateway includes multiple threads, and the multiple threads can process the data in the message queue in parallel. That is, when there is an idle thread among the multiple threads, the idle thread processes the data at the head of the message queue. After processing a piece of data in the message queue, the data is deleted from the message queue.
[0171] Optionally, when the data to be written and the data source identifier are at the head of the message queue, the data to be written and the data source identifier at the head of the queue are processed by an idle thread, that is, the data to be written and the data source identifier are sent to the target data node by the idle thread.
[0172] Optionally, the gateway may include a read loop and a write loop, and the gateway may exchange data with a terminal device or a data node through the read loop and the write loop.
[0173] The following is an explanation of the process of the gateway interacting with the target data node through a read cycle and a write cycle: there is a network connection between the gateway and the target data node. When the gateway needs to send data to the target data node, the gateway writes the data to be sent to the network connection through a write cycle to send data to the target data node. When the gateway needs to receive data sent by the target data node, the gateway reads the data from the network connection through a read cycle.
[0174] In the above process, since the read cycle and the write cycle are independent of each other and can be executed in parallel, the gateway has a higher data processing efficiency.
[0175] S204: The target data node stores the data to be written and the data source identifier in the first data block in the memory of the target data node.
[0176] Optionally, the target data node may also write the generation time of the data to be written into the first data block.
[0177] Optionally, the target data node may write the data to be written and the data source identifier into any free position in the first data block.
[0178] Optionally, the data source identifier and the data to be written may be written into the first data block in the form of a key-value pair, where the data source identifier is the key and the data to be written is the value.
[0179] Optionally, the key in the key-value pair may also include the generation time of the data to be written.
[0180] It should be noted that the data source identifier and the data to be written may also be written into the first data block in other forms, which is not specifically limited in the embodiment of the present invention.
[0181] In the embodiment of the present invention, the memory of the data node includes a first data block, and the persistent disk of the data node includes multiple second data blocks. Figure 2A A detailed description of the data blocks included in the data node.
[0182] Figure 2A A schematic diagram of a data block in a data node provided by an embodiment of the present invention. Figure 2A The data node includes a memory, the memory includes a first data block, the data node also includes a persistent disk, and the persistent disk includes multiple second data blocks.
[0183] Optionally, the sizes of the first data block and the second data block may be the same or different.
[0184] Optionally, the first data block and the second data block are both used to store data of a preset duration. For example, the first data block and the second data block are both used to store 2 hours of data.
[0185] Optionally, after the first data block is full, or after the first data block stores data for a preset time period, a new second data block is created in the persistent disk, and the data in the first data block is stored in the newly created second data block.
[0186] S205 . After the first data block is fully written, the target data node writes the data in the first data block into a sub-data block of the second data block of the data node according to the data source identifier in the first data block.
[0187] The second data block is located in the persistent disk of the data node, and the second data block includes multiple sub-data blocks.
[0188] It should be noted that the first data block is full means that there are no redundant storage controls in the first data block, or data of a preset time length is stored in the first data block.
[0189] Optionally, the size of the second data block is the same as the size of the first data block.
[0190] Optionally, the data in the first data block and the time at which the data is generated may be written into a sub-data block of the second data block.
[0191] Optionally, the target data node may determine at least one data source identifier included in the first data block, determine data corresponding to each data source identifier in the first data block, and write the data corresponding to each data source identifier into a sub-data block of the second data block in sequence.
[0192] For example, suppose that the first data block includes three data source identifiers, which are respectively recorded as data source identifier 1, data source identifier 2 and data source identifier 3, and suppose that the second data block includes 10 sub-data blocks, which are respectively recorded as sub-data block 1, sub-data block 2, ..., sub-data block 10. Then the target data node first writes the data corresponding to data source identifier 1 into sub-data block 1. After sub-data block 1 is full, the target data node continues to write the data corresponding to data source identifier 1 into sub-data block 2, and so on, until all the data corresponding to data source identifier 1 are written into the sub-data blocks. Suppose that the data corresponding to data source identifier 1 is written into sub-data block 1, sub-data block 2 and sub-data block 3, and the data corresponding to data source identifier 1 occupies part of the storage space of sub-data block 3. Then, the data corresponding to data source identifier 2 is written from the remaining storage space of sub-data block 3, and so on, until all the data corresponding to data source identifiers 1 to data source identifiers 3 are written into the sub-data blocks.
[0193] For example, the data source identifiers corresponding to the data stored in each sub-data block in the second data block may be as shown in Table 1:
[0194] Table 1
[0195]
[0196] The data writing method provided by the embodiment of the present invention, when the terminal device writes the data to be written to the data storage system, the gateway first determines the target data node according to the routing information in the routing information database, and sends the data to be written to the target data node. The target data node first stores the data to be written in the first data block of the memory, and after the first data block is full, the data in the first data block is written into the sub-data block of the second data block of the target data node according to the data source identifier in the first data block. As can be seen from the above, the persistent storage space of the target data node includes multiple second data blocks, each of which includes multiple sub-data blocks, and the target data node writes the data in the first data block into the sub-data block of the second data block according to the data source identifier in the first data block, so that the data can be stored regularly and hierarchically in the target data node, so that the target data node can quickly find the data to be queried. Further, the data nodes and gateways in the data storage system shown in the present application can be expanded according to actual needs, so that the data storage system can store a large amount of data, so that data query can be quickly performed on the basis of ensuring that the data storage system can store a large amount of data.
[0197] exist Figure 2 Based on the embodiment shown below, by Figure 3 The embodiment shown, Figure 2 The illustrated embodiment is described in further detail.
[0198] Figure 3 Schematic diagram of a data writing method provided by an embodiment of the present invention Figure 2 .exist Figure 2 Based on the examples shown, see Figure 3 , the method may include:
[0199] S301. The terminal device sends a data write request to the gateway.
[0200] The data writing request includes the data to be written and the data source identifier of the data to be written.
[0201] S302: The gateway determines the target data node corresponding to the data to be written according to the data source identifier.
[0202] S303: The gateway sends the data to be written and the data source identifier to the target data node.
[0203] S304: The target data node stores the data to be written into the first data block in the memory of the data node.
[0204] It should be noted that the execution process of S301-S304 can refer to the execution process of S201-S204, and will not be repeated here.
[0205] S305: After the first data block is fully written, the target data node determines at least one data source identifier included in the first data block.
[0206] Optionally, the at least one data source identifier refers to all data source identifiers stored in the first data block.
[0207] S306: The target data node determines the data corresponding to each data source identifier in the first data block.
[0208] S307: The target data node writes the data corresponding to each data source identifier into the sub-data block of the second data block in turn.
[0209] Optionally, the addresses of the sub-data blocks of the second data block are continuous, that is, the storage spaces of the sub-data blocks of the second data block are adjacent.
[0210] Optionally, the data corresponding to each data source identifier may be written into the sub-data blocks of the second data block in order from small to large addresses of the sub-data blocks.
[0211] For example, data is first written to the first sub-data block. After the first sub-data block is full, data is written to the second sub-data block. After the second sub-data block is full, data is written to the third sub-data block, and so on, until the data corresponding to the data source identifier is written to the sub-data block of the second data block.
[0212] Optionally, the data corresponding to each data source identifier may be written into the sub-data block of the second data block in sequence according to a preset order of the data source identifiers.
[0213] For example, all data corresponding to the first data source identifier is first written into the sub-data block of the second data block, and then all data corresponding to the second data source identifier is written into the sub-data block of the second data block, and so on, until the data corresponding to the data source identifier is written into the sub-data block of the second data block.
[0214] S308. The target data node generates an index file for the second data block.
[0215] Optionally, the target data node may also generate metadata information of the second data block.
[0216] Optionally, the metadata information includes the start time and end time of the data in the second data block; optionally, the start time refers to the earliest time of the generation time of the data in the second data block, and the end time refers to the latest time of the generation time of the data in the second data block.
[0217] Optionally, the metadata information may further include other contents, for example, the metadata information may further include the number of data included in the second data block, etc.
[0218] Of course, in actual application, the content included in the metadata information can be set according to actual needs, and the embodiment of the present invention does not specifically limit this.
[0219] Optionally, the index file includes a first mapping relationship between each data source identifier in the second data block and the sub-data block, and a second mapping relationship between each data tag included in the data source identifier in the second data block and the sub-data block.
[0220] Optionally, the index file may further include a storage position of a first mapping relationship corresponding to each data source identifier in the index file, and a storage position of a second mapping relationship corresponding to each data tag in the index file.
[0221] For example, assuming that the data source identifiers corresponding to the data stored in each sub-data block in the second data block can be as shown in Table 1, the first mapping relationship can be as shown in Table 2:
[0222] Table 2
[0223] Data source identifier Identifier of the sub-block Data source identifier 1 Sub-block 1, Sub-block 2, Sub-block 3 Data source identifier 2 Sub-block 3, Sub-block 4, Sub-block 5, Sub-block 6 Data source identifier 3 Sub-block 7, Sub-block 8, Sub-block 9
[0224] For example, assuming that data source identification 1 includes data tag 1, data tag 2, and data tag 3, data source identification 2 includes data tag 1, data tag 2, and data tag 4, and data source identification 3 includes data tag 1, data tag 5, and data tag 6, the second mapping relationship may be as shown in Table 3:
[0225] Table 3
[0226] Data label identification Identifier of the sub-block Data Label 1 Sub-block 1-Sub-block 9 Data Label 2 Sub-block 1-Sub-block 6 Data Label 3 Sub-block 1-Sub-block 3 Data Label 4 Sub-block 3-Sub-block 6 Data Label 5 Sub-block 7-Sub-block 9 Data Label 6 Sub-block 7-Sub-block 9
[0227] exist Figure 3 In the illustrated embodiment, since an index file of the second data block is generated, when the terminal device performs a data query, the data storage system can perform a data query according to the index file, thereby further improving the data query efficiency.
[0228] In the above Figure 2-Figure 3 Based on the data writing method shown in the figure, data query can be realized through the following feasible implementation methods. For details, see Figure 4-Figure 5 The embodiment shown.
[0229] Figure 4 Schematic diagram of the process of the data query method provided by the embodiment of the present invention Figure 1 . See Figure 4 , the method may include:
[0230] S401. The terminal device sends a data query request to the gateway.
[0231] The data query request includes a first data query condition.
[0232] Optionally, the first data query condition may include at least one of a data source identifier, a data tag, and a time range.
[0233] Of course, the first query condition may also include other conditions, which are not specifically limited in the embodiment of the present invention.
[0234] S402: The gateway determines a target data node corresponding to the first data query condition.
[0235] Optionally, the gateway may determine the target data node according to part of the query conditions in the first data query condition.
[0236] Optionally, the gateway may extract the second data query condition from the first data query condition, and determine the target data node based on the second data query condition and a preset correspondence relationship; wherein the second data query condition is a data query condition included in the preset correspondence relationship, and the preset correspondence relationship includes multiple data query conditions and the identifier of the data node corresponding to each data query condition.
[0237] Optionally, the second data query condition may be a generation time range of the data to be queried. Accordingly, the gateway may determine the target data node according to the second data query condition and metadata information of each data node.
[0238] S403: The gateway sends a first data query condition to the target data node.
[0239] Optionally, the gateway may send a data query request to the target data node, and carry the first data query condition in the data query request.
[0240] It should be noted that the data query request sent by the gateway to the target data node may be the same as or different from the data query request sent by the terminal device to the gateway.
[0241] S404: The target data node determines a target data block in the data node according to the first data query condition.
[0242] Optionally, the gateway may determine the target data node according to part of the query conditions in the first data query condition.
[0243] Optionally, the gateway may extract a third data query condition from the first data query condition, and determine the target data node based on the third data query condition and the first preset correspondence; wherein the third data query condition is the data query condition included in the first preset correspondence, and the preset correspondence includes multiple data query conditions and an identifier of a target data block corresponding to each data query condition.
[0244] S405: The target data node determines the target sub-data block according to the first data query condition and the index file of the target data block.
[0245] The index file includes a first mapping relationship between each data source identifier in the target data block and the sub-data block, and a second mapping relationship between each data tag in the data source identifier in the target data block and the sub-data block.
[0246] Optionally, the target data node may determine the sub-target data block by the following feasible implementation method: determine whether the first data query condition includes the first data source identifier; if so, obtain the first mapping relationship corresponding to the first data source identifier, and determine the sub-data block in the first mapping relationship corresponding to the first data source identifier as the target sub-data block. If not, obtain at least one first data tag included in the first data query condition, obtain the second mapping relationship corresponding to each first data tag, and determine the target sub-data block according to the second mapping relationship corresponding to each first data tag.
[0247] Optionally, the index file also includes the storage position of the first mapping relationship corresponding to each data source identifier in the index file. Accordingly, the target data node can obtain the first storage position of the first mapping relationship corresponding to the first data source identifier in the index file, and obtain the first mapping relationship corresponding to the first data source identifier in the first storage position.
[0248] Optionally, the index file also includes the storage location of the second mapping relationship corresponding to each data tag in the index file. Accordingly, the target data node can obtain the second storage location of the second mapping relationship corresponding to each first data tag in the index file, and obtain the second mapping relationship corresponding to each first data tag in the second storage location.
[0249] Optionally, the target data node may determine the sub-data blocks included in the second mapping relationship corresponding to each first data tag as the target sub-data blocks.
[0250] For example, assuming that the first data query condition includes data source identifier 2, and the first mapping relationship is shown in Table 2, it is determined that the target sub-data blocks include: sub-data block 3, sub-data block 4, sub-data block 5, sub-data block 6
[0251] For example, assuming that the first data query condition includes data tag 2 and data tag 4, the second mapping relationship is shown in Table 3. Since data tag 2 corresponds to sub-data block 1-sub-data block 6, and data tag 4 corresponds to sub-data block 3-sub-data block 6, it can be determined that the target sub-data blocks are: sub-data block 3, sub-data block 4, sub-data block 5, and sub-data block 6.
[0252] S406: The target data node determines the target data in the target sub-data block.
[0253] Optionally, the data in the target sub-data block may be stored in the form of TV, wherein T represents the generation time of the data, and V represents the data.
[0254] Optionally, the stored T may be compressed using a delta-delta compression algorithm, and the stored V may be compressed using a xor compression algorithm.
[0255] Correspondingly, the target data node may determine the target data in the target sub-data block according to the time range in the first data query condition.
[0256] It should be noted that if the first data query condition does not include a time range, all data in the target sub-data block may be determined as target data.
[0257] It should also be noted that the target data node can also process the data in the target sub-data block to determine the target data. For example, assuming that the terminal device needs to request the number of data that meets the first data query condition, the target data node can count the number of target data included in the target sub-data block to determine the target data.
[0258] S407: The target data node sends the target data to the gateway.
[0259] S408: The gateway sends target data to the terminal device.
[0260] exist Figure 4 In the illustrated embodiment, when the terminal device performs a data query, the gateway first determines the target data node based on the first data query condition, and then the target data node further searches for the data to be queried based on the first data query condition. Since the target data node includes data blocks, and the data blocks include sub-data blocks and index files, based on this storage structure, the group data node can quickly query and obtain the data to be queried based on the first data query condition and the index file, thereby improving data query efficiency.
[0261] Below, through specific examples, Figure 4 The methods shown in the examples are described in detail.
[0262] For example, assuming that the terminal device needs to find the total number of requests (http_requests_total) between 13:00 and 13:23 on July 16, 2018, where data tag 1 (method) is POST and data tag 2 (status) is 200, the terminal device sends a data query request to the gateway, and the first data query condition included in the data query request is: 13:00 to 13:23 on July 16, 2018, method=POST, status=200, metricName=http_requests_total.
[0263] The gateway determines that the target data node is data node 1 based on metricName=http_requests_total in the first data query condition and July 16, 2018, as well as the start time and end time in the metadata information of each data node. The gateway then sends the above-mentioned first data query condition to data node 1.
[0264] Data node 1 determines that the target data block is data block 1 according to 13:00-13:20 in the first data query condition, and then data node 1 determines sub-data block 1, sub-data block 2, and sub-data block 3 according to metricName=http_requests_total and method=POST. Data node 1 determines sub-data block 2, sub-data block 3, and sub-data block 4 according to metricName=http_requests_total and status=200, and then data node 1 determines sub-data block 2 and sub-data block 3 as target sub-data blocks, and counts the http request data volume included in sub-data block 2 and sub-data block 3, and sends the counted http request data volume to the gateway, and the gateway sends the http request data volume to the terminal device.
[0265] Based on any of the above embodiments, a slave data node may be set for each data node (hereinafter referred to as the master node). The slave data node may back up the data in the master data node so that after the master data node fails, the slave data node may take over the work of the master data node.
[0266] Optionally, two connections may be included between the slave data node and the master data node. The master data node may send incremental data to the slave data node through one connection, and the master data node may send historical data to the slave data node through another connection.
[0267] Optionally, a temporary cache can also be set in the master data node. When the connection between the master data node and the slave data node is disconnected, the master data node can cache the data to be sent to the slave data node in the temporary cache. When the master data node and the slave data node restore the connection, the master data node sends the data in the temporary cache to the slave data node.
[0268] Optionally, when the master data node fails, the gateway can switch the slave data node corresponding to the master data node to the master data node. Optionally, the heartbeat of the master data node can be detected. If the heartbeat of the master data node is not detected within a preset time, it is determined that the master data node fails, and the slave data node corresponding to the master data node is switched to the master data node.
[0269] Figure 5 A schematic diagram of the structure of a data writing device provided by an embodiment of the present invention. Figure 5 The data writing device 10 may include a receiving module 11 and a writing module 12, wherein:
[0270] The receiving module 11 is used to receive the data to be written and the data source identifier of the data to be written sent by the gateway;
[0271] The writing module 12 is used to write the data to be written and the data source identifier into the first data block in the memory of the data node;
[0272] The writing module 12 is also used to, after the first data block is full, write the data in the first data block into a sub-data block of a second data block of the data node according to a data source identifier in the first data block, the second data block being located in the persistent disk of the data node, and the second data block including multiple sub-data blocks.
[0273] The data writing device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be described in detail here.
[0274] In a possible implementation manner, the writing module 12 is specifically used for:
[0275] determining at least one data source identifier included in the first data block;
[0276] Determining data corresponding to each data source identifier in the first data block;
[0277] The data corresponding to each data source identifier is sequentially written into the sub-data block of the second data block.
[0278] Figure 6 A schematic diagram of the structure of another data writing device provided by an embodiment of the present invention. Figure 5 Based on the examples shown, see Figure 6 The device 10 further includes a generating module 13, wherein:
[0279] The generating module 13 is used for generating an index file of the second data block after the writing module 12 writes the data corresponding to each data source identifier into the sub-data block of the second data block in sequence;
[0280] The index file includes a first mapping relationship between each data source identifier in the second data block and a sub-data block, and a second mapping relationship between each data tag included in the data source identifier in the second data block and a sub-data block.
[0281] In another possible implementation, the index file further includes a storage location of a first mapping relationship corresponding to each data source identifier in the index file, and a storage location of a second mapping relationship corresponding to each data tag in the index file.
[0282] The data writing device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be described in detail here.
[0283] Figure 7 A structural diagram of another data writing device provided by an embodiment of the present invention. Figure 7 The data writing device 20 may include a receiving module 21, a determining module 22 and a sending module 23, wherein:
[0284] The receiving module 21 is used to receive a data writing request, wherein the data writing request includes the data to be written and the data source identifier of the data to be written;
[0285] The determination module 22 is used to determine the target data node corresponding to the data to be written according to the data source identifier;
[0286] The sending module 23 is used to send the data to be written and the data source identifier to the target data node, and the target data node is used to store the data to be written in the target data node according to the data source identifier.
[0287] The data writing device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be described in detail here.
[0288] In a possible implementation manner, the determining module 22 is specifically configured to:
[0289] Determine whether the cache includes the data node identifier corresponding to the data source identifier;
[0290] If yes, determining the data node indicated by the data node identifier corresponding to the data source identifier in the cache as the target data node;
[0291] If not, determine whether the routing information database includes the data node identifier corresponding to the data source identifier. If so, determine the data node indicated by the data node identifier corresponding to the data source identifier in the routing information database as the target data node; if not, determine the target data node based on the remaining capacity of each data node in the distributed storage system.
[0292] In another possible implementation, the sending module 23 is specifically configured to:
[0293] Storing the data to be written and the data source identifier in a message queue;
[0294] Acquire the to-be-written data and the data source identifier in the message queue through an idle thread among the multiple threads;
[0295] The to-be-written data and the data source identifier are sent to the target data node through the idle thread.
[0296] The data writing device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be described in detail here.
[0297] Figure 8 A schematic diagram of the structure of a data query device provided by an embodiment of the present invention. Figure 8 The data query device 30 may include a receiving module 31, a first determining module 32, a second determining module 33, a third determining module 34 and a sending module 35, wherein:
[0298] The receiving module 31 is used to receive the first data query condition sent by the gateway;
[0299] The first determination module 32 is used to determine a target data block in the data node according to the first data query condition;
[0300] The second determination module 33 is used to determine the target sub-data block according to the first data query condition and the index file of the target data block, wherein the index file includes a first mapping relationship between each data source identifier in the target data block and the sub-data block, and a second mapping relationship between each data tag in the data source identifier in the target data block and the sub-data block;
[0301] The third determination module 34 is used to determine the target data in the target sub-data block;
[0302] The sending module 35 is used to send the target data to the gateway.
[0303] The data query device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0304] In a possible implementation manner, the second determining module 33 is specifically configured to:
[0305] Determining whether the first data query condition includes a first data source identifier;
[0306] If yes, obtaining a first mapping relationship corresponding to the first data source identifier, and determining the sub-data block in the first mapping relationship corresponding to the first data source identifier as the target sub-data block;
[0307] If not, obtain at least one first data tag included in the first data query condition, obtain the second mapping relationship corresponding to each first data tag, and determine the target sub-data block according to the second mapping relationship corresponding to each first data tag.
[0308] In another possible implementation manner, the index file further includes a storage location of the first mapping relationship corresponding to each data source identifier in the index file; and the second determining module 33 is specifically configured to:
[0309] Obtain a first storage position of a first mapping relationship corresponding to the first data source identifier in the index file;
[0310] A first mapping relationship corresponding to the first data source identifier is obtained in the first storage location.
[0311] In another possible implementation manner, the index file further includes a storage location of the second mapping relationship corresponding to each data tag in the index file; the second determination module 33 is specifically configured to:
[0312] Obtain a second mapping relationship corresponding to each first data tag at a second storage location in the index file;
[0313] A second mapping relationship corresponding to each first data tag is obtained in the second storage location.
[0314] In another possible implementation manner, the second determining module 33 is specifically configured to:
[0315] The sub-data blocks included in the second mapping relationship corresponding to each first data tag are determined as the target sub-data blocks.
[0316] The data query device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0317] Fig. 9 A schematic diagram of the structure of another data query device provided by an embodiment of the present invention. Fig. 9 The data query device 40 may include a receiving module 41, a determining module 42 and a sending module 43, wherein:
[0318] The receiving module 41 is used to receive a data query request, where the data query request includes a first data query condition;
[0319] The determination module 42 is used to determine the target data node corresponding to the first data query condition;
[0320] The sending module 43 is used to send the first data query condition to the target data node, and the target data node is used to determine the target data according to the first query condition;
[0321] The receiving module 41 is further configured to receive the target data sent by the target data node.
[0322] The data query device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0323] In a possible implementation manner, the determining module 42 is specifically configured to:
[0324] Extracting a second data query condition from the first data query condition, where the second data query condition is a data query condition included in the preset corresponding relationship, where the preset corresponding relationship includes multiple data query conditions and an identifier of a data node corresponding to each data query condition;
[0325] The target data node is determined according to the second data query condition and the preset corresponding relationship.
[0326] The data query device provided in the embodiment of the present invention can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0327] Fig.10 The hardware structure diagram of the data node provided by the embodiment of the present invention is shown in FIG. Fig.10 As shown, the data node 50 includes: at least one processor 51 and a memory 52. Optionally, the data node 50 also includes a communication component 53. The processor 51, the memory 52 and the communication component 53 are connected via a bus 54.
[0328] In the specific implementation process, at least one processor 51 executes the computer-executable instructions stored in the memory 52, so that at least one processor 51 executes the method shown in the above method embodiment. Optionally, the processor 51 can execute the execution steps of the data node in the above method embodiment.
[0329] The communication component 53 can exchange data with other components (such as terminal equipment or gateway).
[0330] The specific implementation process of the processor 51 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0331] Fig.11 The hardware structure diagram of the gateway provided in the embodiment of the present invention is shown in FIG. Fig.11 As shown, the gateway 60 includes: at least one processor 61 and a memory 62. Optionally, the gateway 60 also includes a communication component 63. The processor 61, the memory 62 and the communication component 63 are connected via a bus 64.
[0332] In the specific implementation process, at least one processor 61 executes the computer-executable instructions stored in the memory 62, so that at least one processor 61 executes the method shown in the above method embodiment. Optionally, the processor 61 can execute the execution steps of the gateway in the above method embodiment.
[0333] The communication component 63 can exchange data with other components (such as terminal devices or data nodes).
[0334] The specific implementation process of the processor 61 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0335] In the above Figure 10-11 In the illustrated embodiment, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0336] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage.
[0337] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0338] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the method shown in the method embodiment described above is implemented.
[0339] The computer-readable storage medium mentioned above can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0340] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0341] The division of the units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, which may be electrical, mechanical or other forms.
[0342] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0343] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0344] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0345] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0346] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the embodiments of the present invention have been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the embodiments of the present invention.
Claims
1. A data writing method, It is characterized in that Applied to a data node, the method comprises: Receiving the data to be written and the data source identifier of the data to be written sent by the gateway; Writing the data to be written and the data source identifier into a first data block in the memory of the data node; After the first data block is fully written, determining at least one data source identifier included in the first data block; Determining data corresponding to each data source identifier in the first data block; Writing the data corresponding to each data source identifier into a sub-data block of a second data block of the data node in sequence, where the second data block is located in a persistent disk of the data node, and the second data block includes a plurality of sub-data blocks; the addresses of the sub-data blocks of the second data block are continuous; The data node is determined as follows: If the cache of the gateway includes the data node identifier corresponding to the data source identifier, the gateway determines the data node indicated by the data node identifier in the cache as the data node; If the data node identifier is not included in the cache of the gateway, the gateway determines whether the data node identifier is included in the routing information database. If so, the data node indicated by the data node identifier in the routing information database is determined as the data node; if not, the data node is determined according to the remaining capacity of each data node in the distributed storage system.
2. The method according to claim 1, It is characterized in that After the data corresponding to each data source identifier is sequentially written into the sub-data block of the second data block, the method further includes: generating an index file of the second data block; The index file includes a first mapping relationship between each data source identifier in the second data block and a sub-data block, and a second mapping relationship between each data tag included in the data source identifier in the second data block and a sub-data block.
3. The method according to claim 2, It is characterized in that The index file also includes a storage location of a first mapping relationship corresponding to each data source identifier in the index file, and a storage location of a second mapping relationship corresponding to each data tag in the index file.
4. A data query method, It is characterized in that Applied to a data node, the method comprises: Receiving a first data query condition sent by a gateway; According to the first data query condition, determining a target data block in the data node, wherein the target data block stores data written by the data writing method according to any one of claims 1 to 3 above; Determine a target sub-data block according to the first data query condition and an index file of the target data block, wherein the index file includes a first mapping relationship between each data source identifier in the target data block and the sub-data block, and a second mapping relationship between each data tag in the data source identifier in the target data block and the sub-data block; Target data is determined in the target sub-data block, and the target data is sent to the gateway.
5. The method according to claim 4, It is characterized in that The step of determining the target sub-data block according to the first data query condition and the index file of the target data block includes: Determining whether the first data query condition includes a first data source identifier; If yes, obtaining a first mapping relationship corresponding to the first data source identifier, and determining the sub-data block in the first mapping relationship corresponding to the first data source identifier as the target sub-data block; If not, obtain at least one first data tag included in the first data query condition, obtain the second mapping relationship corresponding to each first data tag, and determine the target sub-data block according to the second mapping relationship corresponding to each first data tag.
6. The method according to claim 5, It is characterized in that The index file also includes a storage location of the first mapping relationship corresponding to each data source identifier in the index file; and obtaining the first mapping relationship corresponding to the first data source identifier includes: Obtain a first storage position of a first mapping relationship corresponding to the first data source identifier in the index file; A first mapping relationship corresponding to the first data source identifier is obtained in the first storage location.
7. The method according to claim 5, It is characterized in that The index file also includes a storage location of the second mapping relationship corresponding to each data tag in the index file; and obtaining the second mapping relationship corresponding to each first data tag includes: Obtain a second mapping relationship corresponding to each first data tag at a second storage location in the index file; A second mapping relationship corresponding to each first data tag is obtained in the second storage location.
8. The method according to claim 5, It is characterized in that The determining the target sub-data block according to the second mapping relationship corresponding to each first data tag includes: The sub-data blocks included in the second mapping relationship corresponding to each first data tag are determined as the target sub-data blocks.
9. A data writing device, It is characterized in that It includes a receiving module and a writing module, wherein: The receiving module is used to receive the data to be written and the data source identifier of the data to be written sent by the gateway; The writing module is used to write the data to be written and the data source identifier into the first data block in the memory of the data node; The writing module is further used to, after the first data block is fully written, write the data in the first data block into a sub-data block of a second data block of the data node according to a data source identifier in the first data block, the second data block being located in a persistent disk of the data node, the second data block including a plurality of sub-data blocks; and the addresses of the sub-data blocks of the second data block being continuous; The writing module is specifically used for: determining at least one data source identifier included in the first data block; Determining data corresponding to each data source identifier in the first data block; Writing the data corresponding to each data source identifier into the sub-data block of the second data block in sequence; The data node is determined as follows: If the cache of the gateway includes the data node identifier corresponding to the data source identifier, the gateway determines the data node indicated by the data node identifier in the cache as the data node; If the data node identifier is not included in the cache of the gateway, the gateway determines whether the data node identifier is included in the routing information database. If so, the data node indicated by the data node identifier in the routing information database is determined as the data node; if not, the data node is determined according to the remaining capacity of each data node in the distributed storage system.
10. A data query device, It is characterized in that It includes a receiving module, a first determining module, a second determining module, a third determining module and a sending module, wherein: The receiving module is used to receive the first data query condition sent by the gateway; The first determination module is used to determine a target data block in a data node according to the first data query condition, wherein the target data block stores data written by the data writing method according to any one of claims 1 to 3 above; The second determination module is used to determine the target sub-data block according to the first data query condition and the index file of the target data block, wherein the index file includes a first mapping relationship between each data source identifier in the target data block and the sub-data block, and a second mapping relationship between each data tag in the data source identifier in the target data block and the sub-data block; The third determination module is used to determine the target data in the target sub-data block; The sending module is used to send the target data to the gateway.
11. A data node, It is characterized in that comprising a processor coupled to a memory, wherein: The memory is used to store computer programs; The processor is used to execute the computer program stored in the memory to implement the data writing method according to any one of claims 1 to 3.
12. A data node, It is characterized in that A processor coupled to a memory, wherein: The memory is used to store computer programs; The processor is used to execute the computer program stored in the memory to implement the data query method according to any one of claims 4 to 8.
13. A readable storage medium, It is characterized in that The method comprises a program or an instruction. When the program or the instruction is run on a computer, the data writing method according to any one of claims 1 to 3 is executed.
14. A readable storage medium, It is characterized in that It comprises a program or an instruction. When the program or the instruction is run on a computer, the data query method as described in any one of claims 4 to 8 is executed.
