HK1245445B - Data storage and query method and device based on block chain - Google Patents
Data storage and query method and device based on block chain Download PDFInfo
- Publication number
- HK1245445B HK1245445B HK18104582.6A HK18104582A HK1245445B HK 1245445 B HK1245445 B HK 1245445B HK 18104582 A HK18104582 A HK 18104582A HK 1245445 B HK1245445 B HK 1245445B
- Authority
- HK
- Hong Kong
- Prior art keywords
- data
- business
- database
- request
- category
- Prior art date
Links
Description
技术领域Technical Field
本申请涉及计算机技术领域,尤其涉及一种基于区块链的数据存储以及查询的方法及装置。The present application relates to the field of computer technology, and in particular to a method and device for data storage and query based on blockchain.
背景技术Background Art
随着计算机技术的不断发展,区块链技术(又可以称之为分布式账本技术)作为一种新的分布式数据存储技术,由于其具备不可篡改的特性,使得存储至区块链中的数据具备公证、公信力等特点,进而使得区块链技术使用的领域越来越广泛。With the continuous development of computer technology, blockchain technology (also known as distributed ledger technology) as a new distributed data storage technology has the characteristics of being tamper-proof, which makes the data stored in the blockchain have the characteristics of notarization and credibility, making the application of blockchain technology more and more extensive.
具体地,区块链的数据存储原理可以这样理解:用户通过以太坊客户端(即一种支持区块链技术的客户端,又可以称之为区块链客户端)发起一个业务请求。该以太坊客户端可将该业务请求发送至共识网络中,由共识网络中的各区块链节点对这该业务请求进行共识。在共识网络中各区块链节点对该业务请求达成共识后,将该业务请求的数据摘要存储在各区块链节点对应的区块链中。与此同时,以太坊客户端可通过预设的智能合约中规定的数据存储格式,将该业务请求中的业务数据按照规定的数据存储格式存储在自身所对应的存储器中。Specifically, the principle of blockchain data storage can be understood as follows: a user initiates a service request through an Ethereum client (a client that supports blockchain technology, also referred to as a blockchain client). The Ethereum client then sends the service request to the consensus network, where the blockchain nodes in the consensus network reach consensus on the service request. Once the blockchain nodes in the consensus network reach consensus on the service request, they store a data summary of the service request in the blockchain corresponding to each blockchain node. Simultaneously, the Ethereum client can store the service data in the service request in its own corresponding memory according to the data storage format specified in the pre-set smart contract.
然而,为了方便后续查询该存储器中存储的数据,通常按照设定方式建立索引,以便于用户利用索引对该存储器中存储的业务数据执行查询操作。However, in order to facilitate subsequent querying of the data stored in the memory, an index is usually established in a set manner, so that the user can use the index to perform a query operation on the business data stored in the memory.
但是,在实际应用中,一旦查询业务数据所使用的查询条件与建立的索引不同(即查询条件与智能合约所规定的索引不相匹配),导致数据查询的效率较低或者查询失败。However, in actual applications, once the query conditions used to query business data are different from the established index (that is, the query conditions do not match the index specified by the smart contract), the data query efficiency will be low or the query will fail.
发明内容Summary of the Invention
本申请实施例提供一种数据存储的方法,用以解决现有技术中对区块链中存储的数据进行查询时存在的查询效率低或者查询失败的问题。The embodiments of the present application provide a data storage method to solve the problems of low query efficiency or query failure when querying data stored in a blockchain in the prior art.
本申请实施例提供了一种数据存储的方法,包括:An embodiment of the present application provides a data storage method, including:
区块链节点接收业务请求;The blockchain node receives the business request;
从所述业务请求中解析出各数据类别以及各数据类别对应的业务数据;Parsing each data category and the business data corresponding to each data category from the business request;
将解析出的业务数据按照数据类别与业务数据的对应关系存储在所述区块链节点对应的数据库中。The parsed business data is stored in the database corresponding to the blockchain node according to the correspondence between the data category and the business data.
本申请实施例提供一种数据存储的装置,用以解决现有技术中对区块链中存储的数据进行查询时存在的查询效率低或者查询失败的问题。The embodiments of the present application provide a data storage device to solve the problems of low query efficiency or query failure when querying data stored in a blockchain in the prior art.
本申请实施例提供了一种数据存储的装置,包括:An embodiment of the present application provides a data storage device, including:
接收模块,接收业务请求;Receiving module, receiving business requests;
数据解析模块,从所述业务请求中解析出各数据类别以及各数据类别对应的业务数据;A data parsing module, which parses the business request to obtain various data categories and the business data corresponding to each data category;
存储模块,将解析出的业务数据按照数据类别与业务数据的对应关系存储在所述区块链节点对应的数据库中。The storage module stores the parsed business data in the database corresponding to the blockchain node according to the correspondence between the data category and the business data.
本申请实施例提供一种数据查询的方法,用以解决现有技术中对区块链中存储的数据进行查询时存在的查询效率低或者查询失败的问题。The embodiments of the present application provide a data query method to solve the problems of low query efficiency or query failure in the prior art when querying data stored in a blockchain.
本申请实施例提供了一种数据存储的方法,包括:An embodiment of the present application provides a data storage method, including:
区块链节点接收业务数据查询请求;The blockchain node receives the business data query request;
根据所述业务数据查询请求,确定待查询的业务数据所对应的数据类别;Determining the data category corresponding to the business data to be queried according to the business data query request;
从所述区块链节点对应的数据库中,查询与所述数据类别相匹配的业务数据,所述数据库中包含有数据类别与业务数据的对应关系。Business data matching the data category is queried from a database corresponding to the blockchain node, where the database contains a correspondence between the data category and the business data.
本申请实施例提供一种数据存储的装置,用以解决现有技术中对区块链中存储的数据进行查询时存在的查询效率低或者查询失败的问题。The embodiments of the present application provide a data storage device to solve the problems of low query efficiency or query failure when querying data stored in a blockchain in the prior art.
本申请实施例提供了一种数据存储的装置,包括:An embodiment of the present application provides a data storage device, including:
请求接收模块,接收业务数据查询请求;Request receiving module, receiving business data query requests;
类别确定模块,根据所述业务数据查询请求,确定待查询的业务数据所对应的数据类别;A category determination module, which determines the data category corresponding to the business data to be queried according to the business data query request;
数据查询模块,从所述装置对应的数据库中,查询与所述数据类别相匹配的业务数据,所述数据库中包含有数据类别与业务数据的对应关系。The data query module queries the business data matching the data category from a database corresponding to the device, wherein the database contains a correspondence between the data category and the business data.
本申请实施例采用的上述至少一个技术方案能够达到以下有益效果:At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
在本申请实施例中,区块链节点在接收到用户发送的业务请求后,可从该业务请求中解析出各数据类别以及各数据类别对应的业务数据,并将解析出的业务数据按照数据类别与业务数据的对应关系存储在该区块链节点对应的数据库中。通过对业务数据的解析,可以按照数据类别与业务数据之间的对应关系,将业务数据存储至区块链节点对应的数据库中,这样,在用户查询业务数据时,可以基于数据库中的这种对应关系实现查询,避免了现有区块链中基于索引进行查询存在的问题,增加了区块链中数据查询的灵活性,有效提升数据查询效率。In an embodiment of the present application, after receiving a business request from a user, a blockchain node can parse the business request to identify each data category and the business data corresponding to each data category, and store the parsed business data in the database corresponding to the blockchain node according to the corresponding relationship between the data category and the business data. By parsing the business data, the business data can be stored in the database corresponding to the blockchain node according to the corresponding relationship between the data category and the business data. In this way, when a user queries business data, the query can be implemented based on this corresponding relationship in the database, avoiding the problems existing in index-based queries in existing blockchains, increasing the flexibility of data queries in the blockchain, and effectively improving data query efficiency.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。在附图中:The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
图1为本申请实施例提供的数据存储过程的示意图;FIG1 is a schematic diagram of a data storage process provided in an embodiment of the present application;
图2为本申请实施例提供的数据表的示意图;FIG2 is a schematic diagram of a data table provided in an embodiment of the present application;
图3为本申请实施例提供的数据存储的详细过程;FIG3 is a detailed diagram of the data storage process provided by an embodiment of the present application;
图4为本申请实施例提供的一种数据存储的装置示意图;FIG4 is a schematic diagram of a data storage device provided in an embodiment of the present application;
图5为本申请实施例提供的一种数据查询的装置示意图。FIG5 is a schematic diagram of a data query device provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
为了使本技术领域的人员更好地理解本申请中的技术方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
图1为本申请实施例提供的数据存储过程的示意图,具体包括以下步骤:FIG1 is a schematic diagram of a data storage process according to an embodiment of the present application, which specifically includes the following steps:
S101:区块链节点接收业务请求。S101: The blockchain node receives a service request.
在实际应用中,用户在进行业务处理的过程中,可向区块链节点发送业务请求。其中,这里提到的区块链节点可以是终端设备或是服务器。例如,当该区块链节点为服务器时,用户可在自己所持有的终端设备中填写业务信息,并在该终端设备上执行指定操作后,由该终端设备将用户填写的业务信息以业务请求的形式发送至该服务器中,而该服务器则可相应的接收该业务请求。In actual applications, users can send service requests to blockchain nodes during business processing. The blockchain nodes mentioned here can be terminal devices or servers. For example, when the blockchain node is a server, the user can enter business information on their terminal device and perform a specified operation on the terminal device. The terminal device then sends the business information entered by the user to the server in the form of a business request, and the server can receive the business request in response.
当区块链节点为终端设备时,用户则可在该终端设备上填写业务信息,而当该终端设备点确定用户执行了指定操作时(如用户进行了点击操作等),可根据该业务信息生成相应的业务请求,这就相当于接收到用户发送的业务请求。When the blockchain node is a terminal device, the user can fill in business information on the terminal device. When the terminal device confirms that the user has performed a specified operation (such as a click operation, etc.), a corresponding business request can be generated based on the business information, which is equivalent to receiving the business request sent by the user.
当然,上述提到的区块链节点也可以是区块链客户端(是指能够处理基于区块链技术的相关业务的客户端,如以太坊客户端等)。相应的,用户通过区块链共识网络进行业务处理时,可通过终端设备启动该区块链客户端,并在该区块链客户端所展示的界面中填写业务信息,而该区块链客户端监测到用户执行了指定操作时,则可根据用户填写的业务信息生成相应的业务请求,这就相当于接收到用户发送的业务请求。除此之外,区块链节点接收到的业务请求也可以是其他区块链节点通过广播的形式发送过来的。Of course, the blockchain nodes mentioned above can also be blockchain clients (referring to clients that can handle related services based on blockchain technology, such as Ethereum clients). Accordingly, when users conduct business processing through the blockchain consensus network, they can start the blockchain client through the terminal device and fill in the business information in the interface displayed by the blockchain client. When the blockchain client detects that the user has performed a specified operation, it can generate a corresponding business request based on the business information filled in by the user, which is equivalent to receiving the business request sent by the user. In addition, the business requests received by the blockchain node can also be sent by other blockchain nodes through broadcasting.
S102:将所述业务请求按照预设的数据格式进行转化,得到数据序列。S102: Convert the service request according to a preset data format to obtain a data sequence.
区块链节点接收到上述业务请求后,可将该业务请求按照预设的数据格式进行转化,从而得到相应的数据序列。After receiving the above business request, the blockchain node can convert the business request according to the preset data format to obtain the corresponding data sequence.
其中,在本申请实施例中,预设的数据格式包含但不限于以下几个字段:In this embodiment of the present application, the preset data format includes but is not limited to the following fields:
标识信息字段,该标识信息字段用于将各业务数据在用户层面进行区分,例如:上述业务请求中携带的用户公钥或用户身份标识号码(Identity,ID)等能够唯一标识用户的信息,便于后续能够以用户为维度进行业务数据的查询;Identification information field, which is used to distinguish various business data at the user level. For example, the user public key or user identity number (ID) carried in the above business request can uniquely identify the user, so as to facilitate subsequent business data queries based on the user dimension.
业务类型字段,该业务类型字段用于对用户的各类业务的业务数据进行区分,从而使得用户后续在进行业务数据查询的过程中,能够进一步的以业务为维度实现业务数据的查询。The business type field is used to distinguish the business data of various types of users' businesses, so that the user can further query the business data based on the business dimension during the subsequent business data query process.
除此之外,上述预设的数据格式中还规定了data字段,该data字段用于表示业务请求中的各数据类别与各业务数据的对应关系,例如,假设在一个业务请求中包含有以下data字段:姓名-小明,年龄-18,体重-130斤这些信息,在这些信息中,实际的业务数据是小明、18、130斤,而姓名、年龄、体重则是各业务数据的所述数据类别,换句话说,在本申请实施例中,该数据类别相当于key,而业务数据则相当于是value,而data字段则是key-value的数据映射集合。In addition, the above-mentioned preset data format also stipulates a data field, which is used to indicate the correspondence between each data category and each business data in the business request. For example, suppose a business request contains the following data fields: Name - Xiao Ming, Age - 18, Weight - 130 Jin. In this information, the actual business data is Xiao Ming, 18, 130 Jin, and the name, age, and weight are the data categories of each business data. In other words, in this embodiment of the present application, the data category is equivalent to the key, and the business data is equivalent to the value, and the data field is a key-value data mapping set.
基于上述说明的预设的数据格式,区块链节点在接收到用户发送的业务请求后,可根据该预设的数据格式,从该业务请求中解析出该业务请求所包含的标识信息、业务类别、data字段中的各数据类别以及各数据类别所对应的业务数据等数据内容,而后,区块链节点可将解析出的这些数据按照一定的形式进行序列化,从而得到数据序列。Based on the preset data format described above, after receiving a business request sent by a user, the blockchain node can parse the business request according to the preset data format to obtain the identification information, business category, each data category in the data field, and business data corresponding to each data category, and other data content contained in the business request. Then, the blockchain node can serialize the parsed data in a certain form to obtain a data sequence.
例如,假设区块链节点在接收到用户发送的业务请求后,通过预设的数据格式,从该业务请求中解析出的业务类型字段为:commodity,标识信息字段为:PublicKey,data字段为name:umbrella和cost:46,区块链节点将解析出的这些字段按照一定的形式进行序列化,得到数据序列:For example, suppose that after receiving a business request from a user, the blockchain node uses a preset data format to parse the business type field from the business request as commodity, the identification information field as PublicKey, and the data field as name: umbrella and cost: 46. The blockchain node serializes these parsed fields in a certain format to obtain the data sequence:
{“PublicKey.schema”:“DEFAULT”,“data”:“name:umbrella,cost:46”}。{"PublicKey.schema":"DEFAULT","data":"name:umbrella,cost:46"}.
其中,将上述业务请求按照预设的数据格式转化为数据序列的目的在于,由于在本申请实施例中,区块链节点需要将业务请求写入到区块链中,以备后续进行业务数据的验证所使用。其中,在实际应用中,区块链节点通常需要将业务请求按照一定的数据格式写入到区块链中,为此,区块链节点在接收到用户发送的业务请求后,需要将该业务请求按照预设的数据格式,转化为能够在后续过程中支持该业务请求写入到区块链中的数据格式,即数据序列,进而以数据序列的形式将该业务请求写入到区块链中,以保证后续能够根据区块链中存储的业务请求,实现对业务数据的有效验证。The purpose of converting the above-mentioned business request into a data sequence according to a preset data format is that, in the embodiment of the present application, the blockchain node needs to write the business request into the blockchain for subsequent verification of the business data. In actual applications, the blockchain node usually needs to write the business request into the blockchain according to a certain data format. To this end, after receiving the business request sent by the user, the blockchain node needs to convert the business request into a data format that can support the business request to be written into the blockchain in the subsequent process, that is, a data sequence. Then, the business request is written into the blockchain in the form of a data sequence to ensure that the business data can be effectively verified based on the business request stored in the blockchain.
需要说明的是,在本申请实施例中,区块链节点还可以从上述业务请求中解析出各数据类别以及各数据类别对应的业务数据,之后,按照预设的数据格式,将解析出的各数据类别以及各数据类别对应的业务数据进行转化,得到上述数据序列。区块链节点也可以在解析出各数据类别以及各数据类别对应的业务数据后,先将解析出的业务数据按照数据类别与业务数据的对应关系存储在该区块链节点对应的数据库(即执行步骤S103)后,而后在按照预设的数据格式,将上述业务请求中包含的各数据类别以及各数据类别对应的业务数据进行转化,得到数据序列。It should be noted that in an embodiment of the present application, the blockchain node may also parse the business data corresponding to each data category and each data category from the above-mentioned business request, and then convert the parsed data category and the business data corresponding to each data category according to a preset data format to obtain the above-mentioned data sequence. The blockchain node may also, after parsing each data category and the business data corresponding to each data category, first store the parsed business data in the database corresponding to the blockchain node according to the correspondence between the data category and the business data (i.e., execute step S103), and then convert each data category and the business data corresponding to each data category contained in the above-mentioned business request according to a preset data format to obtain a data sequence.
换句话说,在本申请实施例中,将所述业务请求按照预设的数据格式进行转化,得到数据序列这一步骤并不是一个必要的步骤。In other words, in the embodiment of the present application, converting the service request according to a preset data format to obtain a data sequence is not a necessary step.
而对于步骤S102而言,将所述业务请求按照预设的数据格式进行转化,得到数据序列中所涉及的具体实施过程并不一定是指将上述业务请求进行解析,得到各数据类别以及各数据类别对应业务数据,而后再按照预设的数据格式,将解析出的各数据类别以及各数据类别对应的业务数据进行转化,得到数据序列,数据序列的生成除了需要从业务请求中解析出的各数据类别以及各数据类别对应的业务数据外,还可通过该业务请求中的其他字段来生成,具体需要哪些字段来生成则取决于实际所要求的能够支持业务请求写入到区块链中的数据格式。As for step S102, the specific implementation process involved in converting the business request according to a preset data format to obtain a data sequence does not necessarily mean parsing the business request to obtain each data category and the business data corresponding to each data category, and then converting the parsed data categories and the business data corresponding to each data category according to the preset data format to obtain a data sequence. In addition to the data categories and the business data corresponding to each data category parsed from the business request, the data sequence can also be generated through other fields in the business request. The specific fields required for generation depend on the actual data format required to support the business request being written into the blockchain.
S103:从所述业务请求中解析出各数据类别以及各数据类别对应的业务数据。S103: parse the service request to obtain various data categories and service data corresponding to each data category.
在本申请实施例中,区块链节点在接收到上述业务请求后,可先将该业务请求通过广播的方式发送至共识网络中的其他区块链节点,以通过共识网络中的各区块链节点对该业务请求进行共识,一旦确定出该业务请求通过共识网络中各区块链节点的共识后,则各区块链节点可将该业务请求存储到自身对应的区块链中。In an embodiment of the present application, after receiving the above-mentioned business request, the blockchain node may first send the business request to other blockchain nodes in the consensus network by broadcasting, so that the business request can be reached through consensus by each blockchain node in the consensus network. Once it is determined that the business request has passed the consensus of each blockchain node in the consensus network, each blockchain node can store the business request in its corresponding blockchain.
不仅如此,在本申请实施例中,区块链节点在接收到上述业务请求后,可对该业务请求进行解析,从该业务请求中解析出该业务请求中所包含的各数据类型以及各数据类型的业务数据,并在后续过程中,将解析出的各业务数据按照各数据类型与业务数据的对应关系,存储在该区块链节点所对应的数据库中。Not only that, in an embodiment of the present application, after receiving the above-mentioned business request, the blockchain node can parse the business request, parse out the various data types and business data of each data type contained in the business request from the business request, and in the subsequent process, store the parsed business data in the database corresponding to the blockchain node according to the correspondence between each data type and the business data.
其中,本申请实施例中所提到的数据库可以是关系型数据库,这种数据存储方式不但能够实现数据的快速查找,而且不受查询条件的影响,换句话说,即使索引字段发送了变化,该数据库中存储的业务数据依然能够适应新的索引字段,而不会由于查询业务数据所使用的索引字段发生改变而对用户的业务数据查询带来影响。Among them, the database mentioned in the embodiment of the present application can be a relational database. This data storage method not only enables fast data search, but also is not affected by query conditions. In other words, even if the index field changes, the business data stored in the database can still adapt to the new index field, and will not affect the user's business data query due to changes in the index field used to query the business data.
在本申请实施例中,区块链节点在进行业务数据存储时,可将存储的业务数据按照业务类别或是标识信息进行区分,以将不同业务类型或标识信息的业务数据存储在不同的数据库中,这里便于后续用户在业务数据查询的过程中,能够以业务类别或标识信息的维度进行业务数据的精确查询。In an embodiment of the present application, when a blockchain node stores business data, it can distinguish the stored business data according to business categories or identification information, so as to store business data of different business types or identification information in different databases. This makes it convenient for subsequent users to accurately query business data based on the dimensions of business categories or identification information during the process of business data query.
基于此,区块链节点除了需要从上述业务请求中解析出各数据类别以及各数据类别所对应的业务数据外,还可解析出该业务请求中所包含的业务数据对应的业务类别以及标识信息,继而按照预设的语句格式,将解析出的各数据类别、各数据类别对应的业务数据、业务类别以及标识信息进行转化,得到数据存储语句,并在后续过程中通过执行该数据存储语句,将解析出的业务数据存储在区块链节点对应的数据库中。Based on this, in addition to parsing out the various data categories and the business data corresponding to each data category from the above-mentioned business request, the blockchain node can also parse out the business categories and identification information corresponding to the business data contained in the business request, and then convert the parsed data categories, the business data corresponding to each data category, the business categories and identification information according to the preset statement format to obtain a data storage statement, and in the subsequent process, by executing the data storage statement, the parsed business data is stored in the database corresponding to the blockchain node.
例如,区块链节点通过解析上述业务请求,确定出待存储的业务数据为shoes#12xew,158,待存储的业务数据所对应的业务类型为commodity,待存储的业务数据所对应的标识信息为PublicKey1,业务数据shoes#12xew,158分别对应的数据类别为name和cost,区块链节点可按照预设的语句格式,将解析出的业务类别、标识信息、各数据类别以及各数据类别对应的业务数据进行转换,得到相应的数据存储语句,具体形式如下:For example, by parsing the above business request, the blockchain node determines that the business data to be stored is shoes#12xew,158, the business type corresponding to the business data to be stored is commodity, the identification information corresponding to the business data to be stored is PublicKey1, and the data categories corresponding to the business data shoes#12xew,158 are name and cost respectively. The blockchain node can convert the parsed business category, identification information, each data category, and the business data corresponding to each data category according to the preset statement format to obtain the corresponding data storage statement, which is in the following form:
insert into“PublicKey1.schema:commodity”(name,cost)value(‘shoes#12xew’,‘158’)。insert into "PublicKey1.schema:commodity" (name, cost) value ('shoes#12xew', '158').
区块链节点可在后续过程中通过执行该数据存储语句,将该业务数据存储在区块链节点所对应的数据库中。The blockchain node can store the business data in the database corresponding to the blockchain node by executing the data storage statement in the subsequent process.
其中,区块链节点在解析上述业务请求的过程中,可通过预设的解析程序来实现,该解析程序中规定了所要解析的数据格式以及字段,区块链节点通过运行该解析程序,实现对上述业务请求的解析,而这里提到的解析程序可以通过区块链节点运维人员根据需要进行编译。Among them, in the process of parsing the above-mentioned business requests, the blockchain node can do so through a preset parsing program, which specifies the data format and fields to be parsed. The blockchain node parses the above-mentioned business requests by running the parsing program, and the parsing program mentioned here can be compiled by the blockchain node operation and maintenance personnel as needed.
需要说明的是,区块链节点除了可将上述业务数据按照业务类别以及标识信息的维度存储在数据库中外,若区块链节点对应单一的数据库,则可在该数据库中设置不同的数据表,每个业务类型以及标识信息都可对应有一个数据表,这样,区块链节点可将上述业务数据按照业务类别以及标识信息的划分存储在该数据库中的各数据表中。当然,数据库中除了以数据表的形式区分该业务类别以及标识信息的业务数据外,还可通过其他的形式来进行区分,在此就不进行详细举例说明了。It should be noted that, in addition to storing the aforementioned business data in a database according to business categories and identification information, if the blockchain node corresponds to a single database, different data tables can be set up in the database, with each business type and identification information corresponding to a data table. In this way, the blockchain node can store the aforementioned business data in separate data tables within the database according to business categories and identification information. Of course, in addition to using data tables to distinguish business data according to business categories and identification information, other forms of distinction can also be used in the database, which will not be explained in detail here.
需要说明的是,在本申请实施例中,区块链节点可以先执行步骤S103,再执行步骤S102;也可以是先执行步骤S102,而后执行步骤S103;还可以先执行步骤S102,再按照S103的步骤所示的方法从步骤S102得到的数据序列中解析出各数据类别以及各数据类别对应的业务数据;步骤S102与步骤S103在本申请实施例中还可以同时实施,这里不做具体限定。It should be noted that in the embodiment of the present application, the blockchain node may first execute step S103 and then execute step S102; it may also execute step S102 first and then execute step S103; it may also execute step S102 first and then parse each data category and the business data corresponding to each data category from the data sequence obtained in step S102 according to the method shown in the step S103; step S102 and step S103 may also be implemented simultaneously in the embodiment of the present application, and no specific limitation is made here.
S104:将解析出的业务数据按照数据类别与业务数据的对应关系存储在所述区块链节点对应的数据库中。S104: The parsed business data is stored in a database corresponding to the blockchain node according to the correspondence between the data category and the business data.
在本申请实施例中,区块链节点从上述业务请求中解析出各数据类别以及各数据类别对应的业务数据后,可将解析出的业务数据存储在该数据库中的各数据类别中。In an embodiment of the present application, after the blockchain node parses the various data categories and the business data corresponding to each data category from the above-mentioned business request, it can store the parsed business data in each data category in the database.
而对于不同业务类型以及标识信息对应的业务数据来说,区块链节点可根据解析出的业务类别以及标识信息,确定出与该业务类别以及标识信息对应的数据库,而后,区块链节点可将解析出的各业务数据分别存储在该数据库的各数据类别中。As for business data corresponding to different business types and identification information, the blockchain node can determine the database corresponding to the business category and identification information based on the parsed business category and identification information, and then the blockchain node can store the parsed business data in each data category of the database.
具体的,区块链节点通过上述步骤S103得到数据存储语句后,可对该数据存储语句进行执行,以确定出待存储的业务数据所对应的业务类别以及标识信息,而后,区块链节点可进一步的确定出该区块链节点是否对应有该业务类型以及标识信息所对应的数据库,若是,则区块链节点可进一步的将解析出的业务数据分别存储该数据库的各数据类别中,若否,该区块链节点则需要根据确定出的业务类型、标识信息,构建与该业务类型以及标识信息相对应的数据库,以使区块链节点将该业务数据存储在该数据库中。Specifically, after the blockchain node obtains the data storage statement through the above step S103, it can execute the data storage statement to determine the business category and identification information corresponding to the business data to be stored. Then, the blockchain node can further determine whether the blockchain node corresponds to the database corresponding to the business type and identification information. If so, the blockchain node can further store the parsed business data in each data category of the database respectively. If not, the blockchain node needs to construct a database corresponding to the business type and identification information based on the determined business type and identification information, so that the blockchain node can store the business data in the database.
当然,在本申请实施例中,若区块链节点对应单一的数据库,则可从该数据库中确定是否包含有与上述业务类别以及标识信息相对应的数据表,若是,则将解析出的各业务数据分别存储在该数据表的各数据类别中,若否,则通过预设的建表方式,构建出该业务类别以及标识信息所对应的数据表,继而将解析出的各业务数据存储在该数据表中。Of course, in the embodiment of the present application, if the blockchain node corresponds to a single database, it can be determined from the database whether it contains a data table corresponding to the above-mentioned business category and identification information. If so, the parsed business data will be stored in each data category of the data table respectively. If not, a data table corresponding to the business category and identification information will be constructed through a preset table construction method, and then the parsed business data will be stored in the data table.
例如,假设区块链节点通过执行上述数据存储语句,确定出待存储的业务数据所对应的业务类型的字段为commodity,以及用于表示标识信息的用户公钥PublicKey1(由于实际的用户公钥可能较为复杂,所以这里仅用PublicKey1进行简单的表示)。区块链节点可进一步的从自身对应的数据库中确定是否包含有标识信息为PublicKey1以及业务类型为commodity的数据表,并在确定出不存在该数据表时,根据确定出的业务类型commodity、标识信息PublicKey1以及预设的建表方式,在该数据库中构建业务类型commodity以及标识信息P ublicKey1所对应的数据表,具体的执行语句如下:For example, assume that the blockchain node determines, by executing the above data storage statement, that the business type field corresponding to the business data to be stored is commodity, and the user public key PublicKey1 used to represent the identification information (because the actual user public key may be more complex, only PublicKey1 is used here for simple representation). The blockchain node can further determine from its corresponding database whether it contains a data table with identification information PublicKey1 and business type commodity. If it is determined that the data table does not exist, it constructs a data table corresponding to the business type commodity and identification information PublicKey1 in the database based on the determined business type commodity, identification information PublicKey1, and the preset table construction method. The specific execution statement is as follows:
create table“PublicKey1.schema:commodity”if“PublicKey1.schema:commodity”not exist。create table "PublicKey1.schema:commodity" if "PublicKey1.schema:commodity" does not exist.
区块链节点通过执行上述数据存储语句从自身对应的数据库中确定(或构建)出上述业务数据所对应的数据表后,可针对该业务数据中包含的每个数据类别,确定该数据类别是否存在于该数据表中,若是,则在该数据表中构建该数据类别所对应的行或列,若否,则可根据该数据类别以及预设的建行/列方式,在该数据表中增添该数据类别所对应的行/列。After the blockchain node determines (or constructs) the data table corresponding to the above-mentioned business data from its corresponding database by executing the above-mentioned data storage statement, it can determine whether each data category contained in the business data exists in the data table. If so, it can construct the row or column corresponding to the data category in the data table. If not, it can add the row/column corresponding to the data category in the data table according to the data category and the preset row/column construction method.
继续沿用上来,区块链节点从上述数据序列中确定出的data字段为:“na me:shoes#12xew,cost:158”,其中,在该data字段中,name和cost为数据类别即,相对于key,而name和cost后面对应的业务数据则相当于value。区块链节点可针对该data字段中的每个数据类别,确定上述根据业务类型comm odity以及标识信息PublicKey1确定出的数据表中是否包含有该数据类别,若是,则不在该数据库中构建该数据类别所对应的列,若否,则可根据该数据类别以及预设的建列方式(如数据表是以行为维度构建的,则也可以使用建行方式),在该数据表中增添该数据类别对应的列,具体的执行语句如下:Continuing with the above, the data field determined by the blockchain node from the above data sequence is: "name: shoes#12xew, cost: 158", where name and cost are data categories, i.e., relative to the key, and the business data corresponding to name and cost is equivalent to the value. For each data category in the data field, the blockchain node can determine whether the data table determined based on the business type community and identification information PublicKey1 contains the data category. If so, the column corresponding to the data category is not constructed in the database. If not, the column corresponding to the data category can be added to the data table based on the data category and the preset column construction method (if the data table is constructed based on the behavioral dimension, the row construction method can also be used). The specific execution statement is as follows:
create colume“name”if“PublicKey1.schema:commodity”.“name”not exist;create column "name" if "PublicKey1.schema:commodity". "name" not exist;
create colume“cost”if“PublicKey1.schema:commodity”.“cost”not e xist。create column "cost" if "PublicKey1.schema:commodity". "cost" not e xist.
当区块链节点通过执行上述数据存储语句,在上述数据库中确定出待存储的业务数据所对应的数据类别(该数据类别可以是先前就存在于该数据库中,也可以是区块链节点通过执行上述数据存储语句后构建出的)后,可将该业务数据存储在该数据库的数据类别中。当然,若确定出待存储的业务数据所对应的数据类别存在于数据库的某一个数据表(即与上述业务类别以及标识信息相匹配的数据表)中,则区块链节点可将解析出的该业务数据存储在该数据表的数据类别中,如图2所示。When the blockchain node determines the data category corresponding to the business data to be stored in the database by executing the above-mentioned data storage statement (the data category may already exist in the database or be constructed by the blockchain node after executing the above-mentioned data storage statement), the business data may be stored in the data category of the database. Of course, if it is determined that the data category corresponding to the business data to be stored exists in a data table in the database (i.e., a data table that matches the above-mentioned business category and identification information), the blockchain node may store the parsed business data in the data category of the data table, as shown in Figure 2.
图2为本申请实施例提供的数据表的示意图。FIG2 is a schematic diagram of a data table provided in an embodiment of the present application.
在图2中,name和cost为业务数据的数据类别,PublicKey1为业务数据对应的标识信息,commodity为业务数据对应的业务类别,在每个数据类别下均记录有属于该数据类别的业务数据,这样一来,用户后续在业务数据查询的过程中,区块链节点可接收用户发送的业务数据查询请求,并进一步从该数据库中查找与该业务数据查询请求匹配的业务数据,具体查询过程可以是:区块链节点接收到该业务数据查询请求后,可先确定出该业务数据查询请求中所包含的业务类型以及标识信息,而后,区块链节点可从该数据库中确定出与该业务类型以及标识信息相匹配的数据表,继而根据该数据表中记录的数据类别与业务数据的对应关系,从该数据表中查找该业务数据查询请求中所要查询的业务数据。In Figure 2, name and cost are data categories of business data, PublicKey1 is the identification information corresponding to the business data, and commodity is the business category corresponding to the business data. Business data belonging to the data category is recorded under each data category. In this way, when the user subsequently queries business data, the blockchain node can receive the business data query request sent by the user and further search for business data matching the business data query request from the database. The specific query process can be: after the blockchain node receives the business data query request, it can first determine the business type and identification information contained in the business data query request, and then the blockchain node can determine the data table that matches the business type and identification information from the database, and then search the data table for the business data to be queried in the business data query request based on the correspondence between the data category and the business data recorded in the data table.
例如,假设区块链节点接收到的业务数据查询请求中包含有以下几个字段:PublicKey:PublicKey1、schema:commodity、name:blouse#4212v,区块链节点可从中确定出该业务数据查询请求所对应的业务类型为commodity,标识信息为PublicKey1,继而从自身对应的数据库中查找到与业务类型commodity以及标识信息PublicKey1相匹配的数据表,并根据索引字段blouse#4212v,从该数据表中查找到索引字段blouse#4212v与之对应的业务数据为211。For example, assuming that the business data query request received by the blockchain node contains the following fields: PublicKey: PublicKey1, schema: commodity, name: blouse#4212v, the blockchain node can determine that the business type corresponding to the business data query request is commodity, and the identification information is PublicKey1, and then find the data table that matches the business type commodity and identification information PublicKey1 from its corresponding database, and according to the index field blouse#4212v, find the business data corresponding to the index field blouse#4212v in the data table as 211.
当然,若是各业务数据仅通过数据类别来进行区分,则区块链节点在接收到用户发送的业务数据查询请求后,可根据该业务数据查询请求,确定出待查询的业务数据所对应的数据类别,进而从该区块链节点所对应的数据库中查询与该数据类别相匹配的业务数据。其中,对于数据类别的确定方式来说,区块链节点在接收到用户发送的业务数据查询请求后,可确定出该业务数据查询请求中包含的索引字段key,并将该索引字段key确定为待查询业务数据所对应的数据类别。Of course, if each business data is distinguished only by data category, then after receiving a business data query request from a user, the blockchain node can determine the data category corresponding to the business data to be queried based on the business data query request, and then search the database corresponding to the blockchain node for business data that matches the data category. Specifically, with respect to the method for determining the data category, after receiving a business data query request from a user, the blockchain node can determine the index field key contained in the business data query request and determine the index field key as the data category corresponding to the business data to be queried.
上述数据表不仅支持以key为索引字段查询业务数据的方式,也支持用户自建索引来查询业务数据,例如,在上述示例中,若用户需要以价格范围来进行业务数据的查询时,则可将价格范围输入到区块链节点中,而区块链节点则可根据用户输入的价格范围,从上述数据库的数据表中查询符合该价格范围的业务数据,进而将符合条件的业务数据返回给用户进行查看。The above data table not only supports querying business data using the key as the index field, but also supports users to query business data by building their own indexes. For example, in the above example, if the user needs to query business data by price range, the price range can be entered into the blockchain node. The blockchain node can then query the business data that meets the price range from the data table of the above database based on the price range entered by the user, and then return the qualified business data to the user for viewing.
在现有技术中,区块链节点存储业务数据时,需要按照智能合约所规定的数据存储格式将该业务数据写入到区块链中,与此同时,区块链节点通常默认按照这种数据存储格式将该业务数据存储在自身对应的存储器中,所以,在编写智能合约的过程中,通常需要规定区块链节点按照这种规定的数据存储格式将该业务数据存储在自身对应的存储器中,相应的,用户利用该智能合约通过区块链节点进行业务数据查询时,也需要按照固定的查询方式(如需要通过固定形式的索引字段)来从区块链节点对应的存储器中查询相应的业务数据。In the prior art, when a blockchain node stores business data, it needs to write the business data into the blockchain according to the data storage format specified by the smart contract. At the same time, the blockchain node usually stores the business data in its own corresponding memory according to this data storage format by default. Therefore, in the process of writing a smart contract, it is usually necessary to specify that the blockchain node stores the business data in its own corresponding memory according to this specified data storage format. Correspondingly, when the user uses the smart contract to query business data through the blockchain node, it is also necessary to query the corresponding business data from the memory corresponding to the blockchain node according to a fixed query method (such as through a fixed index field).
然而,在实际应用中,用户在进行业务数据查询的过程中所使用的索引字段并不唯一,这就导致了用户查询业务数据时所使用的索引字段可能并不是智能合约所规定的索引字段,而用户一旦使用了与智能合约不相符的索引字段,则区块链节点无法通过该智能合约在该区块链节点中查询到以往的业务数据。However, in actual applications, the index fields used by users when querying business data are not unique. This means that the index fields used by users when querying business data may not be the index fields specified by the smart contract. Once the user uses an index field that does not conform to the smart contract, the blockchain node cannot query previous business data in the blockchain node through the smart contract.
例如,区块链节点通过智能合约将该业务请求按照上述预设的数据存储格式存储在自身对应的存储器中时,用户后续通常只能以key为索引字段,从该存储器中进行业务数据的查询。而由于区块链节点通常是通过智能合约将各业务数据按照智能合约所规定的设定数据格式逐条进行存储的,即,并不是按照类似关系型数据库中数据表的形式存储各业务数据的,所以,当用户需要以value中记录的内容进行业务数据的查询时,该智能合约将无法有效的支持用户在区块链节点所输入的查询字段,这就导致了用户可能无法通过该智能合约,从该区块链节点对应的存储器中查询到以往的业务数据(因为以往的业务数据仅支持以key为索引字段的查询),或是需要使区块链节点按照用户所输入的查询字段,通过较长时间的遍历,才能从该区块链节点对应的存储器中查找到相应的业务数据,从而给用户带来了不便。For example, when a blockchain node stores a service request in its corresponding memory according to the aforementioned preset data storage format via a smart contract, users can subsequently only query service data from the memory using the key as the index field. However, since blockchain nodes typically store each service data item by item in the set data format specified by the smart contract through a smart contract, i.e., they do not store each service data item in a format similar to a data table in a relational database, when a user needs to query service data using the content recorded in the value, the smart contract will not be able to effectively support the query field entered by the user in the blockchain node. This may result in the user being unable to query previous service data from the blockchain node's corresponding memory through the smart contract (because previous service data only supports queries using the key as the index field), or requiring the blockchain node to perform a lengthy traversal according to the query field entered by the user before finding the corresponding service data from the blockchain node's corresponding memory, thereby causing inconvenience to the user.
而在本申请实施例中,区块链节点在接收到用户发送的业务请求后,可通过对该业务请求进行解析,确定出该业务请求中所包含的各数据类别以及各数据类别对应的业务数据,并最终将解析出的业务数据按照数据类型与业务数据的对应关系存储在该区块链节点对应的数据库中。这样一来,在用户查询业务数据时,可以基于数据库中的这种对应关系实现查询,避免了现有区块链中基于索引进行查询存在的问题,增加了区块链中数据查询的灵活性,有效提升数据查询效率。In the embodiment of the present application, after receiving a business request from a user, a blockchain node can parse the business request to determine the various data categories contained in the business request and the business data corresponding to each data category. The parsed business data is then stored in the database corresponding to the blockchain node according to the corresponding relationship between the data type and the business data. This allows users to query business data based on this corresponding relationship in the database, avoiding the problems of index-based queries in existing blockchains, increasing the flexibility of data queries in the blockchain, and effectively improving data query efficiency.
需要说明的是,在本申请实施例中,数据库中也可仅以标识信息来区分各用户之间的业务数据,而不对每个用户进行业务类型上的分类,所以,在上述过程中,区块链节点无论是构建数据库还是构建数据库中的数据表,抑或是从数据库中确定数据表,则均可通过标识信息来实现。当然,上述数据库也可仅通过业务类型对业务数据进行区分,而具体使用哪种方式来对业务数据进行区分,则取决于业务需要而定。It should be noted that in the embodiments of the present application, the database may also use only identification information to distinguish the business data between users, without classifying each user by business type. Therefore, in the above process, whether the blockchain node constructs the database, constructs a data table in the database, or determines a data table from the database, it can all be achieved through identification information. Of course, the above database may also distinguish business data only by business type, and the specific method used to distinguish business data depends on business needs.
为了能够进一步的说明上述实施例所提供的数据存储的过程,在本申请实施例中,将按照具体的执行过程对本申请所提供的数据存储方法进行进一步说明,如图3所示。In order to further illustrate the data storage process provided by the above embodiment, in the embodiment of the present application, the data storage method provided by the present application will be further described according to the specific execution process, as shown in Figure 3.
图3为本申请实施例提供的数据存储的详细过程,具体包括以下步骤:FIG3 is a detailed data storage process provided by an embodiment of the present application, which specifically includes the following steps:
S301:区块链节点接收业务请求。S301: The blockchain node receives a service request.
区块链节点可接收用户通过终端设备发送的业务请求,其中,区块链节点可以是一个终端设备,也可以是一个服务器,抑或是能够处理基于区块链技术的相关业务的客户端。A blockchain node can receive business requests sent by users through terminal devices. A blockchain node can be a terminal device, a server, or a client that can handle related businesses based on blockchain technology.
S302:对所述业务请求进行解析,确定所述业务请求中包含的各数据类别以及各数据类别对应的业务数据。S302: Parse the service request to determine the data categories contained in the service request and the service data corresponding to each data category.
区块链节点在接收到上述业务请求后,可对该业务请求进行解析,以确定出该业务请求中所包含的各数据类别以及各数据类别所对应的业务数据,其中,区块链节点可以通过预设的解析程序,对该业务请求实施解析,而这里提到的解析程序可以是区块链节点运维人员根据实际需求设置的。After receiving the above-mentioned business request, the blockchain node can parse the business request to determine the data categories contained in the business request and the business data corresponding to each data category. The blockchain node can parse the business request through a preset parsing program, and the parsing program mentioned here can be set by the blockchain node operation and maintenance personnel according to actual needs.
S303:按照预设的数据格式,将解析出的各数据类别以及各数据类别对应的业务数据进行转化,得到数据序列。S303: Convert the parsed data categories and the business data corresponding to each data category according to a preset data format to obtain a data sequence.
区块链节点从上述业务请求解析出该业务请求所包含的各数据类别以及各数据类别所对应的业务数据后,可按照预设的数据格式,将解析出的各数据类别以及各数据类别对应的业务数据进行转化,得到数据序列。其中,得到数据序列的具体过程可以是:区块链节点可将解析出的这些数据按照一定的形式进行序列化,从而得到相应的数据序列。After parsing the business request to obtain the various data categories and the business data corresponding to each data category, the blockchain node may convert the parsed data categories and the business data corresponding to each data category according to a preset data format to obtain a data sequence. The specific process of obtaining the data sequence may be: the blockchain node may serialize the parsed data according to a certain format to obtain the corresponding data sequence.
S304:将所述业务请求发送至共识网络中进行共识,并当确定所述业务请求通过所述共识后,将所述数据序列存储在所述区块链节点的区块链中。S304: Send the business request to the consensus network for consensus, and when it is determined that the business request passes the consensus, store the data sequence in the blockchain of the blockchain node.
区块链节点在接收到业务请求的同时,可将该业务请求发送至共识网络中,以使共识网络中的其他区块链节点对该业务请求进行共识,当确定该业务请求通过其他区块链节点的共识后,则可将该业务请求按照上述数据序列的形式存储在自身保存的区块链中,以备后续对业务数据进行数据验证所使用。When a blockchain node receives a business request, it can send the business request to the consensus network so that other blockchain nodes in the consensus network can reach a consensus on the business request. After determining that the business request has passed the consensus of other blockchain nodes, the business request can be stored in the form of the above-mentioned data sequence in the blockchain it saves for subsequent use in data verification of the business data.
其中,在本申请实施例中,区块链节点可以每接收到一个业务请求,即将该业务请求发送至共识网络中进行共识,也可以先接收各用户发送的各业务请求,当确定到达共识阶段时,将接收到的各业务请求打包成一个预处理块,并将该预处理块发送至共识网络中进行共识,相应的,区块链节点在接收到各用户发送的每个业务请求后,可对每个业务请求进行逐一解析,以确定出每个业务请求所包含的数据类别以及数据类别对应的业务数据,而后按照预设的数据格式,分别对每个业务请求所包含的数据类别以及数据类别对应的业务数据进行转化,得到各数据序列。Among them, in an embodiment of the present application, each time a blockchain node receives a business request, it can send the business request to the consensus network for consensus, or it can first receive each business request sent by each user, and when it is determined that the consensus stage has been reached, the received business requests will be packaged into a pre-processing block, and the pre-processing block will be sent to the consensus network for consensus. Accordingly, after receiving each business request sent by each user, the blockchain node can parse each business request one by one to determine the data category contained in each business request and the business data corresponding to the data category, and then convert the data category contained in each business request and the business data corresponding to the data category according to the preset data format to obtain each data sequence.
一旦确定出发送至共识网络中的预处理块通过共识网络中其他区块链节点的共识,则可将该预处理块中包含的各业务请求以各业务请求对应的各数据序列的形式存储在自身包含的区块链中。Once it is determined that the pre-processed block sent to the consensus network has passed the consensus of other blockchain nodes in the consensus network, the business requests contained in the pre-processed block can be stored in the blockchain contained in itself in the form of data sequences corresponding to each business request.
S305:将解析出的业务数据按照数据类别与业务数据的对应关系存储在所述区块链节点对应的数据库中。S305: The parsed business data is stored in the database corresponding to the blockchain node according to the correspondence between the data category and the business data.
区块链节点在对解析出的各数据类别以及业务数据进行转化的同时,还可将解析出的业务数据按照数据类别与业务数据的对应关系存储在该区块链节点对应的数据库中,以保证用户后续能够在该数据库中按照数据类别与业务数据的对应关系,查找到相应的业务数据。While converting the parsed data categories and business data, the blockchain node can also store the parsed business data in the database corresponding to the blockchain node according to the correspondence between the data categories and the business data, to ensure that users can subsequently find the corresponding business data in the database according to the correspondence between the data categories and the business data.
其中,区块链节点可以并行的执行上述步骤S303以及步骤S305,即,区块链节点在将解析出的各数据类别以及各数据类别对应的业务数据进行转化得到数据序列的过程中,并不影响区块链节点执行将解析出的业务数据按照数据类别与业务数据的对应关系存储在自身对应数据库中这一步骤。Among them, the blockchain node can execute the above steps S303 and S305 in parallel, that is, in the process of converting the parsed data categories and the business data corresponding to each data category into a data sequence, the blockchain node does not affect the execution of the step of storing the parsed business data in its own corresponding database according to the correspondence between the data category and the business data.
当然,区块链节点也可以在确定上述业务请求通过共识网络中其他区块链节点的共识后,则将解析出的业务数据按照数据类别与业务数据的对应关系存储在自身对应的数据库中。Of course, after determining that the above-mentioned business request has passed the consensus of other blockchain nodes in the consensus network, the blockchain node can also store the parsed business data in its own corresponding database according to the correspondence between data category and business data.
以上为本申请实施例提供的数据存储以及查询方法,基于同样的思路,本申请实施例还分别提供数据存储以及查询的装置,如图4、5所示。The above is the data storage and query method provided in the embodiment of the present application. Based on the same idea, the embodiment of the present application also provides data storage and query devices, as shown in Figures 4 and 5.
图4为本申请实施例提供的一种数据存储的装置示意图,具体包括:FIG4 is a schematic diagram of a data storage device provided in an embodiment of the present application, specifically comprising:
接收模块401,接收业务请求;Receiving module 401, receiving a service request;
数据解析模块402,从所述业务请求中解析出各数据类别以及各数据类别对应的业务数据;The data parsing module 402 parses the business request to obtain various data categories and the business data corresponding to each data category;
存储模块403,将解析出的业务数据按照数据类别与业务数据的对应关系存储在所述区块链节点对应的数据库中。The storage module 403 stores the parsed business data in the database corresponding to the blockchain node according to the correspondence between the data category and the business data.
所述装置还包括:The device further comprises:
共识模块404,按照预设的数据格式,将所述业务请求中包含的各数据类别以及各数据类别对应的业务数据进行转化,得到数据序列;利用共识网络对所述业务请求进行共识;在所述业务请求通过所述共识后,将所述数据序列存储到所述装置的区块链中。The consensus module 404 converts the data categories and the business data corresponding to each data category contained in the business request according to a preset data format to obtain a data sequence; uses a consensus network to reach a consensus on the business request; and after the business request passes the consensus, stores the data sequence in the blockchain of the device.
所述数据解析模块402,确定所述业务请求对应的业务类型和/或标识信息;The data parsing module 402 determines the service type and/or identification information corresponding to the service request;
所述存储模块403,按照预设的语句格式,将解析出的各数据类别、各数据类别对应的业务数据、业务类型和/或标识信息进行转换,得到数据存储语句;通过执行所述数据存储语句,将解析出的业务数据存储在所述数据库中。The storage module 403 converts the parsed data categories, the business data corresponding to each data category, the business type and/or identification information according to a preset statement format to obtain a data storage statement; and stores the parsed business data in the database by executing the data storage statement.
所述存储模块403,通过执行所述数据存储语句,当确定尚未查找到与所述业务类型和/或标识信息相匹配的数据库时,根据所述业务类型和/或标识信息,构建与所述业务类型和/或所述标识信息对应的数据库;将解析出的业务数据存储在构建的所述数据库中。The storage module 403 executes the data storage statement. When it is determined that a database matching the business type and/or identification information has not been found, it constructs a database corresponding to the business type and/or identification information based on the business type and/or identification information; and stores the parsed business data in the constructed database.
所述存储模块403,针对从所述数据序列解析出的每个数据类别,当确定数据库中不包含该数据类别时,在所述数据库中创建该数据类别;将该数据类别对应业务数据存储至所述数据库中。The storage module 403 creates each data category parsed from the data sequence in the database when it is determined that the data category is not included in the database; and stores the business data corresponding to the data category in the database.
图5为本申请实施例提供的一种数据查询的装置示意图,具体包括:FIG5 is a schematic diagram of a data query device provided in an embodiment of the present application, specifically comprising:
请求接收模块501,接收业务数据查询请求;Request receiving module 501, receiving a business data query request;
类别确定模块502,根据所述业务数据查询请求,确定待查询的业务数据所对应的数据类别;Category determination module 502, determining the data category corresponding to the business data to be queried according to the business data query request;
数据查询模块503,从所述装置对应的数据库中,查询与所述数据类别相匹配的业务数据,所述数据库中包含有数据类别与业务数据的对应关系。The data query module 503 queries the business data matching the data category from the database corresponding to the device, wherein the database contains the correspondence between the data category and the business data.
在本申请实施例中,区块链节点在接收到用户发送的业务请求后,可从该业务请求中解析出各数据类别以及各数据类别对应的业务数据,并将解析出的业务数据按照数据类别与业务数据的对应关系存储在该区块链节点对应的数据库中。通过对业务数据的解析,可以按照数据类别与业务数据之间的对应关系,将业务数据存储至区块链节点对应的数据库中,这样,在用户查询业务数据时,可以基于数据库中的这种对应关系实现查询,避免了现有区块链中基于索引进行查询存在的问题,增加了区块链中数据查询的灵活性,有效提升数据查询效率。In an embodiment of the present application, after receiving a business request from a user, a blockchain node can parse the business request to identify each data category and the business data corresponding to each data category, and store the parsed business data in the database corresponding to the blockchain node according to the corresponding relationship between the data category and the business data. By parsing the business data, the business data can be stored in the database corresponding to the blockchain node according to the corresponding relationship between the data category and the business data. In this way, when a user queries business data, the query can be implemented based on this corresponding relationship in the database, avoiding the problems existing in index-based queries in existing blockchains, increasing the flexibility of data queries in the blockchain, and effectively improving data query efficiency.
在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable GateArray,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware DescriptionLanguage)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(RubyHardware Description Language)等,目前最普遍使用的是VHDL(Very-High-SpeedIntegrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD through their own programming, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.
控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本申请时可以把各单元的功能在同一个或多个软件和/或硬件中实现。For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing this application, the functions of each unit can be implemented in the same or multiple software and/or hardware.
本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to the flowcharts and/or block diagrams of the methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and/or box in the flowchart and/or block diagram, as well as the combination of processes and/or boxes in the flowchart and/or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
本领域技术人员应明白,本申请的实施例可提供为方法、系统或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
本申请可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本申请,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.
以上所述仅为本申请的实施例而已,并不用于限制本申请。对于本领域技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本申请的权利要求范围之内。The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims (12)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| HK18104582.6A HK1245445B (en) | 2018-04-09 | Data storage and query method and device based on block chain |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| HK18104582.6A HK1245445B (en) | 2018-04-09 | Data storage and query method and device based on block chain |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| HK1245445A1 HK1245445A1 (en) | 2018-08-24 |
| HK1245445B true HK1245445B (en) | 2021-03-05 |
Family
ID=
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN107239479B (en) | Block chain based data storage and query method and device | |
| US11314754B2 (en) | Data processing method, apparatus, and device | |
| CN110245279B (en) | Dependency tree generation method, device, equipment and storage medium | |
| CN110134668B (en) | Data migration method, device and equipment applied to blockchain | |
| CN107562775A (en) | A kind of data processing method and equipment based on block chain | |
| CN109241026B (en) | Method, device and system for data management | |
| US12399939B2 (en) | Data processing method and apparatus, readable storage medium, and electronic device | |
| CN111309970A (en) | Data retrieval method and device, electronic equipment and storage medium | |
| WO2025130336A1 (en) | Data query method and apparatus for distributed database | |
| CN116483859A (en) | Data query method and device | |
| WO2024046015A1 (en) | Data query method and apparatus, storage medium, and electronic device | |
| CN114238345B (en) | A database processing, data query method and device | |
| CN115587107A (en) | Data updating method, device, storage medium and equipment | |
| CN116521705A (en) | A data query method, device, storage medium and electronic equipment | |
| CN110245136B (en) | Data retrieval method, device, equipment and storage equipment | |
| HK1245445B (en) | Data storage and query method and device based on block chain | |
| CN116048794A (en) | Execution method, device, storage medium and electronic equipment of a query task | |
| CN110647568B (en) | Method and device for converting graph database data into programming language data | |
| HK1245445A1 (en) | Data storage and query method and device based on block chain | |
| HK1248841B (en) | Data processing method and equipment based on blockchain | |
| CN116450669A (en) | Data query method, device, computer equipment and storage medium |