CN112527825B - Data storage method and device and computer equipment - Google Patents

Data storage method and device and computer equipment Download PDF

Info

Publication number
CN112527825B
CN112527825B CN201910886117.7A CN201910886117A CN112527825B CN 112527825 B CN112527825 B CN 112527825B CN 201910886117 A CN201910886117 A CN 201910886117A CN 112527825 B CN112527825 B CN 112527825B
Authority
CN
China
Prior art keywords
block
transaction log
transaction
data
relational database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910886117.7A
Other languages
Chinese (zh)
Other versions
CN112527825A (en
Inventor
王鑫
李华敬
张翘楚
毕凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Bilibili Technology Co Ltd
Original Assignee
Shanghai Bilibili Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Bilibili Technology Co Ltd filed Critical Shanghai Bilibili Technology Co Ltd
Priority to CN201910886117.7A priority Critical patent/CN112527825B/en
Publication of CN112527825A publication Critical patent/CN112527825A/en
Application granted granted Critical
Publication of CN112527825B publication Critical patent/CN112527825B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Abstract

The invention discloses a data storage method, a data storage device and computer equipment, and belongs to the technical field of data storage. The data storage method of the invention comprises the following steps: monitoring generation of blocks in a block chain in real time, and acquiring a first transaction log in a first block when the generation of the first block is monitored; storing the first transaction log in a relational database; when the generation of a second block is monitored, judging whether the first block in the block chain changes or not, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1; and if the first block is changed, acquiring a second transaction log from the changed first block in the block chain, and updating the first transaction log according to the second transaction log. The scheme can improve the query efficiency and ensure the accuracy of the data stored in the relational database.

Description

Data storage method and device and computer equipment
Technical Field
The present invention relates to the field of computer systems, and in particular, to a data storage method, apparatus, and computer device.
Background
In the block chain technology, data are stored in blocks, and are sequentially generated one by one according to a time sequence and connected into a chain, and each block records transaction information generated at a corresponding time.
However, in the current market, the query for the data stored in the block chain is mostly concentrated on querying a single block, that is, after a query request is initiated, a user can only query in a specified block, and if the user needs to query the blocks in the entire block chain, the user needs to initiate multiple query requests, which seriously affects the efficiency of querying the data.
Disclosure of Invention
Aiming at the problem of low query efficiency in querying a block in the prior art, a data storage method, a data storage device, computer equipment and a computer readable storage medium are provided to improve the data query efficiency.
The invention provides a data storage method, which comprises the following steps:
monitoring generation of blocks in a block chain in real time, and acquiring a first transaction log in a first block when generation of the first block is monitored;
storing the first transaction log in a relational database;
when the generation of a second block is monitored, judging whether the first block in the block chain changes or not, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1;
and if the first block is changed, acquiring a second transaction log from the changed first block in the block chain, and updating the first transaction log according to the second transaction log.
Optionally, the method further comprises:
the first transaction log is generated by a log burial point created in the smart contract during execution of the smart contract.
Optionally, the step of storing the first transaction log in a relational database comprises:
cleaning the first transaction log to obtain a third transaction log of a preset type;
storing the third transaction log in the relational database.
Optionally, the step of storing the third transaction log in the relational database comprises:
converting the third transaction log into a structured query statement;
inserting the structured query statement into the relational database.
Alternatively,
the step of determining whether the first block in the block chain is changed includes:
and judging whether the hash value of the first block in the block chain changes or not.
Optionally, the data storage method further includes:
receiving a transaction inquiry request initiated by external equipment;
and inquiring the relational database based on the transaction inquiry request and returning an inquiry result matched with the transaction inquiry request to the external equipment.
Optionally, the data storage method further includes:
receiving a data verification request initiated by external equipment;
querying the relational database based on the data verification request to obtain a first query result matched with the data verification request;
querying the block chain based on the data verification request to obtain a second query result matched with the data verification request;
and determining a data verification result according to the first query result and the second query result.
The present invention also provides a data storage device comprising:
the monitoring module is used for monitoring the generation of blocks in the block chain in real time;
the acquisition module is used for acquiring a first transaction log in a first block when the generation of the first block is monitored;
the storage module is used for storing the first transaction log into a relational database;
the judging module is used for judging whether the first block in the block chain changes or not when the generation of a second block is monitored, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1;
and the updating module is used for acquiring a second transaction log from the changed first block in the block chain if the first block is changed, and updating the first transaction log according to the second transaction log.
The invention also provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the above method when executing the computer program.
The invention also provides a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method.
The beneficial effects of the above technical scheme are that:
in the technical scheme, the generation of blocks in a block chain is monitored in real time, and when the generation of a first block is monitored, a first transaction log in the first block is obtained; storing the first transaction log in a relational database; when generation of a second block is monitored, judging whether the first block in the block chain changes or not, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1; and if the first block is changed, acquiring a second transaction log from the changed first block in the block chain, and updating the first transaction log according to the second transaction log. According to the scheme, the transaction information in the block is stored in the relational database, so that the transaction data can be queried through a structured query statement, and the query efficiency can be improved.
Drawings
FIG. 1 is a block diagram of one embodiment of a system block diagram of a data store according to the present invention;
FIG. 2 is a flow chart of an embodiment of a data storage method according to the present invention;
FIG. 3 is a flowchart detailing the step of storing the first transaction log in the relational database of FIG. 2 according to the present invention;
FIG. 4 is a flowchart detailing the step of FIG. 3 of storing the third transaction log in a relational database in accordance with the present invention;
FIG. 5 is a flow chart of another embodiment of a data storage method according to the present invention;
FIG. 6 is a flow chart of another embodiment of a data storage method according to the present invention;
FIG. 7 is a block diagram of one embodiment of a data storage device according to the present invention;
fig. 8 is a schematic diagram of a hardware structure of a computer device executing a data storage method according to an embodiment of the present invention.
Detailed Description
The advantages of the invention are further illustrated in the following description of specific embodiments in conjunction with the accompanying drawings.
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. The following description refers to the accompanying drawings in which the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
The terminology used in the present disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in this disclosure and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present disclosure. The word "if," as used herein, may be interpreted as "at \8230; \8230when" or "when 8230; \823030when" or "in response to a determination," depending on the context.
In the description of the present invention, it should be understood that the numerical references before the steps do not identify the order of performing the steps, but merely serve to facilitate the description of the present invention and to distinguish each step, and thus should not be construed as limiting the present invention.
Referring to fig. 1, fig. 1 is a schematic diagram illustrating an application environment of a data storage method according to an embodiment of the present application. In an exemplary embodiment, the computer devices 2 (block chain nodes) may store data to the data storage 4 via the network 6, the data storage 4 storing data via a relational database. The computer device 2 may be an electronic device having a data transmission function, such as a server, a mobile phone, a tablet personal computer (tablet personal computer), a laptop computer (laptop computer), and the like, and the computer device 2 has a plurality of devices, and the specific number is not limited in this embodiment. The data storage device 4 may be an electronic device with a data receiving function, such as a server, a set-top box, a mobile phone, a tablet personal computer, a laptop computer, a smart television, and the like, and the number of the data storage devices 4 may be one or more, and is not limited in this embodiment. The network 6 may be the internet.
Example one
Fig. 2 schematically shows a flowchart of a data storage method according to a first embodiment of the present application. It is to be understood that the flow charts in the embodiments of the present method are not intended to limit the order in which the steps are performed. The following description is made by way of example with the computer device 2 as the execution subject.
As shown in fig. 2, the data storage method includes steps S20 to S23, in which:
step S20, monitoring the generation of blocks in a block chain in real time, and acquiring a first transaction log in a first block when the generation of the first block is monitored;
specifically, the yield of the block can be monitored by monitoring the block chain in real time or in a timed manner. For example, whether a new block is generated in the block chain may be monitored by a block generation monitoring program, and when it is monitored that the first block is generated in the block chain, a first transaction log in the first block is obtained. In an embodiment, the first transaction log in the first block may be obtained through a block event log query interface, which is preferably a Remote Procedure Call Protocol (RPC) interface of an underlying platform. And acquiring and analyzing the block information of the block chain through the interface to acquire the first transaction log. Among other things, the RPC interface is a protocol that requests services from a remote computer program over a network without knowledge of the underlying network technology. The remote procedure call procedure is that a client sends out a request for executing a plurality of procedures to a server, and the execution result is returned to the client by using the parameters provided by the client.
In this embodiment, the first transaction log records transaction/operation details of a time period, where the transaction/operation details may be all transaction/operation details stored in the current block, and may also be transaction/operation details required by the user.
In an exemplary embodiment, when the first transaction log is the transaction/operation details required by the user, a log buried point can be created in the smart contract in advance to realize the acquisition of the required data in the block chain. The intelligent contract in this embodiment is a computer protocol intended to propagate, verify or execute contracts in an informational manner. Smart contracts allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible. The intelligent contracts are preferably service programs written in the solid language and implementing specific logic, and are issued on the blockchain in a binary mode so that the contract participants can execute calls and obtain results on the blockchain at a certain time point. The blockchain in this embodiment may be a federation chain, a public chain, or a private chain, and is not limited in this embodiment.
When a log burying point is created in the intelligent contract, the log burying point is triggered to be executed correspondingly in the executing process of the intelligent contract, and the first transaction log can be generated through the log burying point created in the intelligent contract. The content of the first transaction log is specifically determined according to data required to be collected by log burial points, and a plurality of log burial points can be created in one intelligent contract, for example, a recharge log burial point, a consumption log burial point and an order log burial point can be found in the intelligent contract if the transaction logs of recharge, consumption, orders and the like of a user need to be collected.
The log burying point is a professional term in the field of data acquisition, and specifically refers to a related technology and an implementation process thereof for capturing, processing and sending specific user behaviors or events by adopting a log creating mode.
And S21, storing the first transaction log into a relational database.
Specifically, a relational database refers to a database that uses a relational model to organize data, and stores data in rows and columns for a user to understand, where a series of rows and columns of the relational database are called tables, and a group of tables constitutes the database. A user retrieves data in a database by a query, which is an executable code that defines certain areas in the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and relations between them.
In this embodiment, the relational database may be an Oracle database, a DB2 database, a MySQL database, or the like.
In an exemplary embodiment, referring to fig. 3, the step of storing the first transaction log in a relational database includes S30 to S31, wherein:
and step S30, cleaning the first transaction log to obtain a third transaction log of a preset type.
Specifically, the preset type of third transaction log is data of a type required by a service party, for example, the service party only needs balance data, and the content of the first transaction log includes some other data besides the balance data, for example, order data, recharge data, and the like, and in order to obtain the preset type of third transaction log, the first transaction log needs to be cleaned first. In this embodiment, the cleaning of the first transaction log refers to extracting data required by the service party from the first transaction log, that is, extracting the third transaction log from the first transaction log.
Step S31, storing the third transaction log in the relational database.
Specifically, after the third transaction log is obtained, the third transaction log may be stored in the relational database, so that the user may conveniently query the transaction/operation details.
In an exemplary embodiment, referring to fig. 4, the step of storing the first transaction log in a relational database includes S40 to S41, wherein:
and step S40, converting the third transaction log into a structured query statement.
Step S41, inserting the structured query statement into the relational database.
Specifically, after the third transaction log is obtained, in order to store the third transaction log into the relational database, the third transaction log needs to be converted into a structured query statement, that is, into a corresponding SQL statement, and then the third transaction log is stored into the relational database through the SQL statement.
It can be understood that, in order to store the third transaction log into the relational database through the SQL statement, different data tables need to be designed in the relational database in advance according to different event logs in the third transaction log, so that the same event log can be recorded into the same data table.
Step S22, when it is monitored that a second block is generated, determining whether the first block in the block chain changes.
Specifically, the generation of the block is monitored in real time, and when it is monitored that the second block is generated, whether the first block in the block chain changes or not is judged, that is, whether a block corresponding to the previously monitored first block in the block chain is the same as the first block or not is judged. In this embodiment, the second block is the nth block after the first block, and N is an integer greater than or equal to 1, that is, if the first block is block No. 1, the second block is block No. (1 + N). Preferably, N =6.
For example, assuming that the first block is block 5 and the second block is block 11, when block 11 is detected in the block chain, block 5 is obtained from the current block chain, and then the obtained block 5 in the current block chain is compared with the block 5 generated by the previous detection, so as to determine whether the block 5 in the current block chain and the block 5 generated by the previous detection are changed, and thus whether the block chain is forked can be determined.
Since when a block chain generates a bifurcation, the block in the bifurcation will be different from the block in the main chain. In this embodiment, whether the first block is in a split state is determined by determining whether the first block is the same as a block corresponding to the first block in a current block chain by returning when the generation of the second block is monitored.
In an exemplary embodiment, the step of determining whether the first block in the block chain is changed includes:
and judging whether the hash value of the first block in the block chain changes or not.
Specifically, when it is detected that the second block is generated, a hash value of the first block in the current block chain is obtained, that is, a hash value of a block corresponding to the previously monitored first block number is obtained from the current block chain, for example, if the first block is a block No. 5 and the second block is a block No. 11, when it is detected that the block No. 11 is generated, the block No. 5 in the current block chain is found, and then a hash value of the block No. 5 in the block chain is obtained, assuming that the hash value is X. In addition, the hash value of the first chunk is also obtained, assuming that the hash value of the first chunk is Y. After the hash value X of the block 5 in the blockchain and the hash value Y of the first block are obtained, the hash value X and the hash value Y are compared to determine whether the two hash values are the same, if the hash value X = the hash value Y, it is determined that the hash value of the first block in the blockchain has not changed, and if the hash value X is not equal to the hash value Y, it is determined that the hash value of the first block in the blockchain has changed, that is, when the first block in the preceding blockchain has been updated. In a specific determination process, the hash value of the previously monitored first chunk may be obtained from the relational database, or may be obtained from other chunk chain nodes, which is not limited in this embodiment.
In an exemplary embodiment, whether the first block in the block chain is changed may be further determined by comparing a block number of a block in the block chain corresponding to the previously monitored first block with a block number of the first block, or may be determined by comparing logs of all transaction types of a block in the block chain corresponding to the previously monitored first block with logs of all transaction types of the first block.
Step S23, if the first block changes, obtaining a second transaction log from the changed first block in the block chain, and updating the first transaction log according to the second transaction log.
Specifically, when it is determined that the first block is changed, the second transaction log is obtained again from a block corresponding to the previously monitored first block in the current blockchain. In this embodiment, the second transaction log has the same data type as the first transaction log, and only has a different transaction amount. That is, if the first transaction log includes the data of the user's charge, consumption and order, the second transaction log will also include the data of the user's charge, consumption and order. The only difference between the two is that the first transaction log may include the user's 3 load data, 2 consumption data, and 5 order data, while the second transaction log may include only the user's 4 load data, 2 consumption data, and 7 order data.
After the second transaction log is obtained, the second transaction log is updated to the first transaction log stored in the relational database, that is, the first transaction log stored in the relational database is replaced by the second transaction log.
It should be noted that, in this embodiment, after the replacement of the second transaction log in the block corresponding to the previously monitored first block in the block chain with the first transaction log in the first block is completed, the transaction logs in each block between the first block and the second block are continuously obtained, and then the obtained transaction logs are updated to the transaction logs stored in the relational database.
For example, if the first block is the 5 th block and the second block is the 11 th block, after the second transaction log in the 5 th block in the current block chain is updated to the first transaction log stored in the relational database, the transaction logs in the 6 th block, the 7 th block, the 8 th block, the 9 th block and the 10 th block in the current block chain are continuously obtained, and then the obtained transaction log is replaced with the transaction log stored in the relational database.
In the embodiment, the generation of blocks in a block chain is monitored in real time, and when the generation of a first block is monitored, a first transaction log in the first block is obtained; storing the first transaction log in a relational database; when the generation of a second block is monitored, judging whether the first block in the block chain changes or not, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1; and if the first block is changed, acquiring a second transaction log from the changed first block in the block chain, and updating the first transaction log according to the second transaction log. According to the scheme, the transaction information in the block is stored in the relational database, so that the transaction data can be queried through a structured query statement, the query efficiency can be improved, meanwhile, whether the block chain is branched or not is judged when the transaction information in the block is stored, and the data stored in the relational database is updated when the branch is generated, so that the accuracy of the data stored in the relational database is ensured.
Example two
Fig. 5 schematically shows a flowchart of a data storage method according to the second embodiment of the present application. The data storage method may further include steps S50 to S51, in which:
step S50, receiving a transaction inquiry request initiated by an external device.
And S51, inquiring the relational database and returning an inquiry result matched with the transaction inquiry request to the external equipment based on the transaction inquiry request.
Specifically, the transaction query request is used to query data required by the user, for example, recharge data in a certain time period, order data in a certain time period, and the like of the user may be queried. The transaction query request is issued in the form of an SQL statement.
When a user needs to query transaction details/operations stored in each block in the block chain, a transaction query request can be sent through an external device to directly query data required by the user in the relational database.
In this embodiment, when a transaction query request initiated by an external device is received, whether a result meeting the query request exists in the relational database is queried based on the transaction query request, and if the result meeting the query request exists, a query result matched with the query request is returned to the external device, so that the query of the external device on the block data in the block chain is realized.
EXAMPLE III
Fig. 6 schematically shows a flowchart of a data storage method according to a third embodiment of the present application. The data storage method may further include steps S60 to S63, wherein:
step S60, receiving a data verification request initiated by an external device.
Specifically, the data verification request is a request initiated for verifying data, for example, since the transaction log stored in the relational database is centralized database data, the stored data may be artificially tampered, and therefore, a user may think that the data stored in the relational database does not match an actual transaction situation, and when the user challenges the data stored in the relational database, the user may initiate the data verification request through an external device. In this embodiment, the data check request carries a block number of the block to be queried or a hash value of the block to be queried.
And S61, inquiring the relational database based on the data verification request to obtain a first inquiry result matched with the data verification request.
Specifically, after a data verification request initiated by an external device is received, the relational database is queried based on the data verification request to obtain a matched first query result.
In an exemplary embodiment, when querying the relational database, the relational database is queried according to the block number and/or the hash value carried in the data check request, so as to obtain the transaction details/operations in the corresponding block.
It can be understood that, when the transaction log is obtained and recorded in the relational database, the hash value and/or the block number of the block where the corresponding transaction log is located are recorded at the same time.
Step S62, based on the data verification request, querying the block chain to obtain a second query result matching the data verification request.
Specifically, after receiving a data verification request initiated by an external device, the block chain is also queried according to the data verification request, so that a second query result matched with the data verification request is obtained from the block chain.
In an exemplary embodiment, when querying the block chain, the block chain is queried according to the block number and/or the hash value carried in the data check request, so as to find the block corresponding to the data check request from the block chain, and after finding the corresponding block, the transaction log in the block is obtained, that is, the second query result is obtained.
And S63, determining a data verification result according to the first query result and the second query result.
Specifically, after the first query result and the second query result are obtained through querying, the first query result and the second query result are compared to determine whether the first query result and the second query result are the same, and then the data verification result is obtained according to the comparison result.
In an exemplary embodiment, in the process of comparing the first query result with the second query result, whether the hash value of the to-be-verified block in the block chain is consistent with the hash value of the block stored in the relational database may be compared, and if not, it may be directly determined that the data verification result indicates that the data stored in the relational database is tampered. If the hash value of the block to be verified in the block chain is consistent with the hash value of the block stored in the relational database, whether the transaction log in the block to be verified in the block chain is consistent with the transaction log stored in the relational database can be further compared, if so, the data can be determined to be consistent, namely, the data verification result is that the data is not tampered, and if not, the data can be determined to be tampered, namely, the data verification result is that the data is tampered.
In the embodiment, when the user asks for the data in the relational database, the data stored in the relational database can be verified through the decentralized data on the block chain, so that data transparency is realized, and the reliability is improved.
Example four
Fig. 7 schematically illustrates a block diagram of a data storage device according to a fifth embodiment of the present application, which may be partitioned into one or more program modules, stored in a storage medium, and executed by one or more processors to implement the embodiments of the present application. The program modules referred to in the embodiments of the present application refer to a series of computer program instruction segments capable of performing specific functions, and are more suitable for describing the execution process of the video processing system in the storage medium than the program itself.
As shown in fig. 7, the data storage device 700 may include a monitoring module 701, an obtaining module 702, a storing module 703, a determining module 704, and an updating module 705, where:
a monitoring module 701 for monitoring generation of blocks in a block chain in real time.
The obtaining module 702 is configured to obtain a first transaction log in a first block when it is monitored that the first block is generated.
Specifically, the monitoring module 701 monitors the blockchain in real time or in a timed manner, so that the yield of the block can be monitored. For example, whether a new block is generated in the block chain may be monitored by a block generation monitoring program, and when it is monitored that the first block is generated in the block chain, the obtaining module 702 obtains the first transaction log in the first block. In an embodiment, the first transaction log in the first block may be obtained through a block event log query interface, which is preferably a Remote Procedure Call Protocol (RPC) interface of an underlying platform. And acquiring and analyzing the block information of the block chain through the interface to acquire the first transaction log. Among other things, the RPC interface is a protocol that requests services from a remote computer program over a network without knowledge of the underlying network technology. The remote procedure call procedure is that a client sends out a request for executing a plurality of procedures to a server, and the execution result is returned to the client by using the parameters provided by the client.
In this embodiment, the first transaction log records transaction/operation details of a time period, where the transaction/operation details may be all transaction/operation details stored in the current block, and may also be transaction/operation details required by the user.
In an exemplary embodiment, when the first transaction log is transaction/operation details required by the user, a log burial point can be created in the intelligent contract in advance to realize the acquisition of the required data in the block chain. The intelligent contract in this embodiment is a computer protocol intended to propagate, verify or execute contracts in an informational manner. Smart contracts allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible. The intelligent contracts are preferably service programs written in a solid language which implement specific logic and are issued on the blockchain in a binary manner so that the contract participants can execute calls and obtain results on the blockchain at a certain time point. The blockchain in this embodiment may be a federation chain, a public chain, or a private chain, and is not limited in this embodiment.
When a log burying point is created in the intelligent contract, the log burying point is triggered to be executed correspondingly in the executing process of the intelligent contract, and the first transaction log can be generated through the log burying point created in the intelligent contract. The content of the first transaction log is specifically determined according to data required to be collected by log burial points, and a plurality of log burial points can be created in one intelligent contract, for example, a recharge log burial point, a consumption log burial point and an order log burial point can be found in the intelligent contract if the transaction logs of recharge, consumption, orders and the like of a user need to be collected.
The log burying point is a professional term in the field of data acquisition, and specifically refers to a related technology and an implementation process thereof for capturing, processing and sending specific user behaviors or events by adopting a log creating mode.
A storage module 703, configured to store the first transaction log in a relational database.
Specifically, a relational database refers to a database that uses a relational model to organize data, and stores data in rows and columns for a user to understand, and a series of rows and columns of the relational database are called tables, and a group of tables constitutes the database. A user retrieves data in a database by a query, which is an executable code that defines certain areas in the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and relations between them.
In this embodiment, the relational database may be an Oracle database, a DB2 database, a MySQL database, or the like.
In an exemplary embodiment, the storage module 703 is further configured to clean the first transaction log to obtain a third transaction log of a preset type.
Specifically, the preset type of third transaction log is data of a type required by a service party, for example, the service party only needs balance data, and the content of the first transaction log includes some other data besides the balance data, for example, order data, recharge data, and the like, and in order to obtain the preset type of third transaction log, the first transaction log needs to be cleaned first. In this embodiment, the cleaning of the first transaction log refers to extracting data required by the service party from the first transaction log, that is, extracting the third transaction log from the first transaction log.
The storage module 703 is further configured to store the third transaction log in the relational database.
Specifically, after the third transaction log is obtained, the third transaction log may be stored in the relational database, so that the user may conveniently query the transaction/operation details.
In an exemplary embodiment, the storage module 703 is further configured to convert the third transaction log into a structured query statement and to insert the structured query statement into the relational database.
Specifically, after the third transaction log is obtained, in order to store the third transaction log in the relational database, the third transaction log needs to be converted into a structured query statement, that is, into a corresponding SQL statement, and then the third transaction log is stored in the relational database through the SQL statement.
It can be understood that, in order to store the third transaction log in the relational database through the SQL statement, different data tables need to be designed in the relational database in advance according to different event logs in the third transaction log, so that the same event log can be recorded in the same data table.
The determining module 704 is configured to determine whether the first block in the block chain changes when it is monitored that the second block is generated.
Specifically, the generation of the block is monitored in real time, and when the generation of the second block is monitored, whether the first block in the block chain changes or not is judged, that is, whether the block corresponding to the previously monitored first block in the block chain is the same as the first block or not is judged. In this embodiment, the second block is the nth block after the first block, and N is an integer greater than or equal to 1, that is, if the first block is block No. 1, the second block is block No. (1 + N). Preferably, N =6.
For example, assuming that the first block is block 5 and the second block is block 11, when block 11 is detected in the block chain, block 5 is obtained from the current block chain, and then the obtained block 5 in the current block chain is compared with the block 5 generated by the previous detection, so as to determine whether the block 5 in the current block chain and the block 5 generated by the previous detection are changed, and thus whether the block chain is forked can be determined.
Since when a block chain generates a bifurcation, the block in the bifurcation will be different from the block in the main chain. In this embodiment, whether the first block is in a split state is determined by determining whether the first block is the same as a block corresponding to the first block in a current block chain by returning when the generation of the second block is monitored.
In an exemplary embodiment, the determining module 704 is further configured to determine whether a hash value of the first chunk in the chunk chain changes.
Specifically, when it is detected that the second block is generated, a hash value of the first block in the current block chain is obtained, that is, a hash value of a block corresponding to the previously monitored first block number is obtained from the current block chain, for example, if the first block is a block No. 5 and the second block is a block No. 11, when it is detected that the block No. 11 is generated, the block No. 5 in the current block chain is found, and then a hash value of the block No. 5 in the block chain is obtained, assuming that the hash value is X. In addition, the hash value of the first chunk is also obtained, assuming that the hash value of the first chunk is Y. After the hash value X of the block 5 in the block chain and the hash value Y of the first block are obtained, the hash value X and the hash value Y are compared to determine whether the two hash values are the same, if the hash value X = the hash value Y, it is determined that the hash value of the first block in the block chain has not changed, and if the hash value X is not equal to the desired value Y, it is determined that the hash value of the first block in the block chain has changed, that is, when the first block in the previous block chain has been updated. In a specific determination process, the previously monitored hash value of the first chunk may be obtained from the relational database, or may be obtained from other chunk chain nodes, which is not limited in this embodiment.
In an exemplary embodiment, whether the first block in the block chain is changed may be further determined by comparing a block number of a block in the block chain corresponding to the previously monitored first block with a block number of the first block, or may be determined by comparing logs of all transaction types of the block in the block chain corresponding to the previously monitored first block with logs of all transaction types of the first block.
An updating module 705, configured to obtain a second transaction log from the changed first block in the block chain if the first block is changed, and update the first transaction log according to the second transaction log.
Specifically, when it is determined that the first block is changed, the second transaction log is obtained again from a block corresponding to the previously monitored first block in the current blockchain. In this embodiment, the second transaction log has the same data type as the first transaction log, and only differs from the first transaction log in the number of transactions involved. That is, if the first transaction log includes the data of the user's charge, consumption and order, the second transaction log will also include the data of the user's charge, consumption and order. The only difference is that the first transaction log may include the user's 3 load data, 2 consumption data, and 5 order data, while the second transaction log may include only the user's 4 load data, 2 consumption data, and 7 order data.
After the second transaction log is obtained, the second transaction log is updated to the first transaction log stored in the relational database, that is, the first transaction log stored in the relational database is replaced by the second transaction log.
It should be noted that, in this embodiment, after the replacement of the second transaction log in the block corresponding to the previously monitored first block in the block chain with the first transaction log in the first block is completed, the transaction logs in each block between the first block and the second block are continuously obtained, and then the obtained transaction logs are updated to the transaction logs stored in the relational database.
For example, if the first block is the 5 th block and the second block is the 11 th block, after the second transaction log in the 5 th block in the current block chain is updated to the first transaction log stored in the relational database, the transaction logs in the 6 th block, the 7 th block, the 8 th block, the 9 th block and the 10 th block in the current block chain are continuously obtained, and then the obtained transaction log is replaced with the transaction log stored in the relational database.
In the embodiment, the generation of the block is monitored in real time, and when the generation of the first block is monitored, a first transaction log in the first block is obtained; storing the first transaction log in a relational database; when the generation of a second block is monitored, judging whether the block corresponding to the first block in a block chain is the same as the first block or not, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1; and if the difference is not the same, acquiring a second transaction log from a block corresponding to the first block in the block chain, and updating the first transaction log by adopting the acquired second transaction log. According to the scheme, the transaction information in the block is stored in the relational database, so that the transaction data can be queried through a structured query statement, the query efficiency can be improved, meanwhile, whether the block chain is branched or not is judged when the transaction information in the block is stored, and the data stored in the relational database is updated when the branch is generated, so that the accuracy of the data stored in the relational database is ensured.
In an exemplary embodiment, as shown in fig. 7, the data storage device 700 may further include a receiving module 706, and a querying module 707.
The receiving module 706 is configured to receive a transaction query request initiated by an external device; and an inquiring module 707, configured to inquire the relational database based on the transaction inquiring request, and return an inquiring result matching the transaction inquiring request to the external device.
Specifically, the transaction query request is used to query data required by the user, for example, recharging data in a certain time period, order data in a certain time period, and the like, of the user may be queried. The transaction query request is issued in the form of an SQL statement.
When a user needs to query the transaction details/operations stored in each block in the block chain, a transaction query request can be sent through an external device to directly query the data required by the user in the relational database.
In this embodiment, when the receiving module 706 receives a transaction query request initiated by an external device, the querying module 707 queries whether a result satisfying the query request exists in the relational database based on the transaction query request, and if so, returns a query result matched with the query request to the external device, thereby implementing query of the external device on block data in a block chain.
In an exemplary embodiment, as shown in FIG. 7, the data storage device 700 may further include a determination module 708.
The receiving module 706 is further configured to receive a data verification request initiated by an external device.
Specifically, the data verification request is a request initiated for verifying data, for example, since the transaction log stored in the relational database is centralized database data, the stored data may be tampered by a human, and therefore, a user may consider that the data stored in the relational database does not conform to an actual transaction condition, and when the user challenges the data stored in the relational database, the user may initiate the data verification request through an external device. In this embodiment, the data check request carries a block number of the block to be queried or a hash value of the block to be queried.
The querying module 707 is further configured to query the relational database based on the data verification request to obtain a first query result matching the data verification request.
Specifically, after a data verification request initiated by an external device is received, the relational database is queried based on the data verification request to obtain a matched first query result.
In an exemplary embodiment, when querying the relational database, the relational database is queried according to the block number and/or the hash value carried in the data check request, so as to obtain the transaction details/operations in the corresponding block.
It can be understood that, when the transaction log is obtained and recorded in the relational database, the hash value and/or the block number of the block where the corresponding transaction log is located are recorded at the same time.
The querying module 707 is further configured to query the block chain based on the data check request to obtain a second query result matching the data check request.
Specifically, after receiving a data verification request initiated by an external device, the block chain is also queried according to the data verification request, so that a second query result matched with the data verification request is obtained from the block chain.
In an exemplary embodiment, when querying the block chain, the block chain is queried according to the block number and/or the hash value carried in the data verification request, so as to find a block corresponding to the data verification request from the block chain, and after finding the corresponding block, obtain the transaction log in the block, that is, obtain the second query result.
A determining module 708, configured to determine a data verification result according to the first query result and the second query result.
Specifically, after the first query result and the second query result are obtained through querying, the first query result and the second query result are compared to determine whether the first query result and the second query result are the same, and then the data verification result is obtained according to the comparison result.
In an exemplary embodiment, in the process of comparing according to the first query result and the second query result, whether the hash value of the to-be-verified block in the block chain is consistent with the hash value of the block stored in the relational database may be compared, and if not, it may be directly determined that the data verification result is that the data stored in the relational database is tampered. If the hash value of the block to be verified in the block chain is consistent with the hash value of the block stored in the relational database, whether the transaction log in the block to be verified in the block chain is consistent with the transaction log stored in the relational database can be further compared, if so, the data can be determined to be consistent, namely, the data verification result is that the data is not tampered, and if not, the data can be determined to be tampered, namely, the data verification result is that the data is tampered.
In the embodiment, when the user asks for the data in the relational database, the data stored in the relational database can be verified through the decentralized data on the block chain, so that data transparency is realized, and the reliability is improved.
EXAMPLE five
Fig. 8 schematically shows a hardware architecture diagram of a computer device suitable for implementing the data storage method according to a fifth embodiment of the present application. In the present embodiment, the computer device 2 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a command set in advance or stored. For example, the server may be a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server, or a cabinet server (including an independent server or a server cluster composed of multiple servers). As shown in fig. 8, the computer device 2 includes at least, but is not limited to: memory 810, processor 820, and network interface 830 may be communicatively linked to each other by a system bus. Wherein:
the memory 810 includes at least one type of computer-readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage 810 may be an internal storage module of the computer device 2, such as a hard disk or a memory of the computer device 2. In other embodiments, the memory 810 may also be an external storage device of the computer device 2, such as a plug-in hard disk provided on the computer device 2, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Of course, memory 810 may also include both internal and external memory modules of computer device 2. In this embodiment, the memory 810 is generally used for storing an operating system installed in the computer device 2 and various types of application software, such as program codes of a data storage method. In addition, the memory 810 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 820 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 820 is generally used for controlling the overall operation of the computer device 2, such as performing control and processing related to data interaction or communication with the computer device 2. In this embodiment, the processor 820 is used to execute program codes stored in the memory 810 or process data.
Network interface 830 may include a wireless network interface or a wired network interface, and network interface 830 is typically used to establish communication links between computer device 2 and other computer devices. For example, the network interface 830 is used to connect the computer device 2 with an external terminal through a network, establish a data transmission channel and a communication link between the computer device 2 and the external terminal, and the like. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, bluetooth (Bluetooth), or Wi-Fi.
It is noted that fig. 8 only shows a computer device having components 810-830, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead.
In this embodiment, the data storage method stored in the memory 810 can be further divided into one or more program modules, and executed by one or more processors (in this embodiment, the processor 820) to complete the present invention.
Example six
The present embodiment also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the data storage method in the embodiments.
In this embodiment, the computer-readable storage medium includes a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the computer readable storage medium may be an internal storage unit of the computer device, such as a hard disk or a memory of the computer device. In other embodiments, the computer readable storage medium may be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the computer device. Of course, the computer-readable storage medium may also include both internal and external storage devices of the computer device. In the present embodiment, the computer-readable storage medium is generally used for storing an operating system and various types of application software installed in the computer device, for example, the program codes of the data storage method in the embodiment, and the like. Further, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.
It will be apparent to those skilled in the art that the modules or steps of the embodiments of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method of storing data, comprising:
monitoring generation of blocks in a block chain in real time, and acquiring a first transaction log in a first block when the generation of the first block is monitored;
storing the first transaction log in a relational database;
when the generation of a second block is monitored, judging whether the first block in the block chain changes or not, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1;
if the first block changes, acquiring a second transaction log from the changed first block in the block chain, and updating the first transaction log according to the second transaction log;
and after the first transaction log is updated according to the second transaction log, acquiring the transaction log in each block between the first block and the second block from the block chain, and updating the acquired transaction log to the transaction log stored in the relational database.
2. The data storage method of claim 1, further comprising:
the first transaction log is generated by a log burial point created in the smart contract during execution of the smart contract.
3. The data storage method of claim 1, wherein the step of storing the first transaction log in a relational database comprises:
cleaning the first transaction log to obtain a third transaction log of a preset type;
storing the third transaction log in the relational database.
4. The data storage method of claim 3, wherein the step of storing the third transaction log in the relational database comprises:
converting the third transaction log into a structured query statement;
inserting the structured query statement into the relational database.
5. The data storage method of claim 4, wherein the step of determining whether the first block in the block chain is changed comprises:
and judging whether the hash value of the first block in the block chain changes or not.
6. The data storage method of any of claims 1 to 5, further comprising:
receiving a transaction inquiry request initiated by external equipment;
and inquiring the relational database based on the transaction inquiry request and returning an inquiry result matched with the transaction inquiry request to the external equipment.
7. The data storage method of any of claims 1 to 5, further comprising:
receiving a data verification request initiated by external equipment;
querying the relational database based on the data verification request to obtain a first query result matched with the data verification request;
querying the block chain based on the data verification request to obtain a second query result matched with the data verification request;
and determining a data verification result according to the first query result and the second query result.
8. A data storage device, comprising:
the monitoring module is used for monitoring the generation of blocks in the block chain in real time;
the acquisition module is used for acquiring a first transaction log in a first block when the generation of the first block is monitored;
the storage module is used for storing the first transaction log into a relational database;
the judging module is used for judging whether the first block in the block chain changes or not when the generation of a second block is monitored, wherein the second block is the Nth block behind the first block, and N is an integer greater than or equal to 1;
the updating module is used for acquiring a second transaction log from the changed first block in the block chain if the first block is changed, and updating the first transaction log according to the second transaction log;
and the updating module is further configured to obtain the transaction logs in each block between the first block and the second block from the block chain after the first transaction log is updated according to the second transaction log, and update the obtained transaction logs to the transaction logs stored in the relational database.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the data storage method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that: the computer program when executed by a processor implements the steps of the data storage method of any one of claims 1 to 7.
CN201910886117.7A 2019-09-19 2019-09-19 Data storage method and device and computer equipment Active CN112527825B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910886117.7A CN112527825B (en) 2019-09-19 2019-09-19 Data storage method and device and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910886117.7A CN112527825B (en) 2019-09-19 2019-09-19 Data storage method and device and computer equipment

Publications (2)

Publication Number Publication Date
CN112527825A CN112527825A (en) 2021-03-19
CN112527825B true CN112527825B (en) 2022-12-06

Family

ID=74974077

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910886117.7A Active CN112527825B (en) 2019-09-19 2019-09-19 Data storage method and device and computer equipment

Country Status (1)

Country Link
CN (1) CN112527825B (en)

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180349896A1 (en) * 2017-06-05 2018-12-06 Mastercard International Incorporated Method and system for anonymization of electronic transactions via blockchain
US11797995B2 (en) * 2017-12-04 2023-10-24 Mastercard International Incorporated Method and system for risk scoring anonymized transactions
US11468444B2 (en) * 2017-12-18 2022-10-11 Mastercard International Incorporated Method and system for bypassing merchant systems to increase data security in conveyance of credentials
US20190188657A1 (en) * 2017-12-19 2019-06-20 Mastercard International Incorporated Method and system for outside guarantees for a blockchain transaction
CN108647361B (en) * 2018-05-21 2021-12-03 中国工商银行股份有限公司 Data storage method, device and system based on block chain
CN109002527B (en) * 2018-07-13 2020-12-01 江苏开放大学(江苏城市职业学院) Block chain-based network examination system and method for managing network examination
CN109190410B (en) * 2018-09-26 2020-05-19 华中科技大学 Log behavior auditing method based on block chain in cloud storage environment
CN109726229B (en) * 2018-11-30 2023-10-10 深圳市元征科技股份有限公司 Block chain data storage method and device
CN109992624B (en) * 2019-03-15 2024-03-22 深圳前海微众银行股份有限公司 Synchronous storage method and device for Block chain and computer equipment

Also Published As

Publication number Publication date
CN112527825A (en) 2021-03-19

Similar Documents

Publication Publication Date Title
US9298775B2 (en) Changing the compression level of query plans
CN105049287A (en) Log processing method and log processing devices
WO2021036449A1 (en) Dimension data processing method and apparatus, computer device, and storage medium
US20120005188A1 (en) Techniques for recommending parallel execution of sql statements
CN111737227B (en) Data modification method and system
US10540352B2 (en) Remote query optimization in multi data sources
CN111046041A (en) Data processing method and device, storage medium and processor
CN105446824B (en) Table increment acquisition methods and long-distance data backup method
CN103678591A (en) Device and method for automatically executing multi-service receipt statistical treatment
CN112487075B (en) Method for integrating relational database data conversion operators and non-relational database data conversion operators
CN112527825B (en) Data storage method and device and computer equipment
CN115827646B (en) Index configuration method and device and electronic equipment
CN107526816B (en) Stream distribution record storage method and device and electronic equipment
CN111427950A (en) Data transmitting and receiving method, corresponding device, equipment and storage medium
CN113419896A (en) Data recovery method and device, electronic equipment and computer readable medium
CN112579705A (en) Metadata acquisition method and device, computer equipment and storage medium
CN114510534B (en) Data synchronization method, device, equipment and storage medium
CN112732704B (en) Data processing method, device and storage medium
CN110019352B (en) Method and apparatus for storing data
CN116795835A (en) Correlation query method and device
CN115994192A (en) Method, device and system for realizing elastic search in relational database search system
CN111083197A (en) Report scheduling method and device
CN116244334A (en) Query method, device, equipment and storage medium of medical data
CN114817338A (en) Data processing method and device, electronic equipment and computer readable storage medium
CN115934459A (en) Buried point data processing method and device, computer equipment and storage medium

Legal Events

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