Disclosure of Invention
An object of the present disclosure is to provide a data manipulation method, apparatus, storage medium, and blockchain system to solve the above technical problems.
To achieve the above object, in a first aspect, the present disclosure provides a data manipulation method applied to a blockchain node in a blockchain network, the method including:
Responding to an operation request initiated to a database corresponding to the blockchain node, and checking whether an initiator of the operation request has corresponding database operation authority;
Executing corresponding database operation on the database under the condition that the authority verification is passed;
and after the database operation is completed, encapsulating the operation record of the database operation into a transaction, and broadcasting the transaction to other block chain link points in the block chain network so that other block chain nodes record the transaction on a block chain after consensus the transaction.
Optionally, the method further comprises rolling back the database operation performed on the database in case the transaction consensus fails.
Optionally, the performing a corresponding database operation on the database includes:
Determining a preset conflict detection rule base, wherein the conflict detection rule base comprises a plurality of inhibition rules, and the inhibition rules are used for indicating the forbidden operation corresponding to the data table in the database;
decomposing the database operation into a plurality of atomic level operations on a data table in the database;
Performing conflict detection on the plurality of atomic level operations according to the conflict detection rule base;
Generating a linear operation flow according to atomic-level operations which do not conflict with forbidden rules in the conflict detection rule base in the atomic-level operations;
And executing each atomic-level operation in the linear operation flow on the database corresponding to the blockchain node in sequence.
Optionally, the method further comprises:
determining a preset operation transfer rule base, wherein the operation transfer rule base comprises a plurality of transfer rules, and each transfer rule is used for indicating a processing strategy when the corresponding operation fails to be executed;
And the step of sequentially executing each atomic-level operation in the linear operation flow on the database corresponding to the blockchain node comprises the following steps:
Determining a target transfer rule corresponding to the atomic-level operation in the operation transfer rule base under the condition that the atomic-level operation in the linear operation flow fails to be executed;
responding to the processing strategy in the target transfer rule.
Optionally, the method further comprises:
determining a data aggregation plan, wherein the data aggregation plan is used for indicating a triggering condition of a data aggregation operation, at least one source data table corresponding to the data aggregation operation and a target relation mode corresponding to the data aggregation operation;
when the triggering condition is determined to be met, extracting an operation record corresponding to the source data table from a blockchain, and restoring the corresponding source data table according to the operation record;
aggregating the at least one restored source data table to the target relation mode to obtain an aggregation table;
Broadcasting the aggregate table to other blockchain link points in the blockchain network to enable other blockchain nodes to record the aggregate table onto a blockchain after consensus of the aggregate table.
Optionally, the aggregating the at least one restored source data table into the target relationship mode to obtain an aggregate table, including:
Constructing an aggregation table with the target relation mode, wherein the target relation mode comprises a table structure and a table field, and the table field comprises a primary key and a non-primary key attribute;
Establishing a mapping relation between the non-primary key attribute of each source data table and the non-primary key attribute of the aggregation table;
determining a main key mediation table, wherein the main key mediation table is used for mapping the main keys of each source data table to the main keys of the main key mediation table respectively;
For each source data table, naturally connecting the source data table with the main key mediation table to obtain a corresponding intermediate data table;
According to the set first projection condition and the intermediate data table, performing corresponding projection operation on the source data table, and according to the mapping relation between the source data table and the aggregation table, mapping the projection operation result into a table item of the aggregation table to obtain target data;
And carrying out merging operation on the target data corresponding to each source data table, and writing the merging operation result into the aggregation table.
Optionally, the method further comprises:
Constructing a history table with the same relation mode as the aggregation table;
Performing corresponding projection operation on the aggregation table according to the set second projection conditions to obtain data to be migrated;
migrating the data to be migrated to the history table;
the history table is broadcast to other blockchain link points in the blockchain network such that other blockchain nodes record the history table onto a blockchain after consensus of the history table.
In a second aspect, the present disclosure provides a data manipulation device configured for a blockchain node in a blockchain network, the device comprising:
The authority verification module is used for responding to an operation request initiated to the database corresponding to the blockchain node and verifying whether an initiator of the operation request has corresponding database operation authority;
the database operation module is used for executing corresponding database operation on the database under the condition that the authority verification passes;
And the record uplink module is used for packaging the operation record of the database operation into a transaction after the database operation is completed, and broadcasting the transaction to other block chain link points in the block chain network so that other block chain nodes record the transaction on a block chain after the transaction is commonly known.
In a third aspect, the present disclosure provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the method of the first aspect.
In a fourth aspect, the present disclosure provides a blockchain system, including a blockchain network composed of a plurality of blockchain nodes, each of the blockchain nodes being provided with a data center service module, in which an intelligent contract is deployed, and the blockchain node is configured to execute the intelligent contract in the data center service module, so as to implement the method of the first aspect.
By the technical scheme, the authority verification is carried out on the corresponding database operation authority of the initiator of the operation request, so that the control of data access is realized, and all the operations executed on the database are recorded on the blockchain, so that the upper layer application cannot easily tamper the data in the database, and the method has the effects of traceability and non-tamper of the data center. In addition, the conventional database has the defect of poor disaster recovery capability, in the scheme, because all operations on the database are stored on the blockchain, all blockchain nodes can inquire operation records of all data tables in each database from the blockchain, all the data tables in storage can be obtained according to the operation records, and each blockchain node can obtain the data tables in storage in global consistency, so that the disaster recovery capability of the database is improved, and the method can be effectively compatible with heterogeneous databases.
In addition, considering that the efficiency of the blockchain network for consensus on the transaction is lower, the scheme adopts a mode of firstly warehousing and then consensus, the blockchain node is preferentially ensured to have the performance of a database level, the database operation can be completed in time, and on the basis, the operation record is subjected to consensus uplink, so that other external service systems which interact with the database are ensured not to be influenced.
Additional features and advantages of the present disclosure will be set forth in the detailed description which follows.
Detailed Description
Specific embodiments of the present disclosure are described in detail below with reference to the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating and illustrating the disclosure, are not intended to limit the disclosure.
It should be noted that, all actions for acquiring signals, information or data in the present disclosure are performed under the condition of conforming to the corresponding data protection rule policy of the country of the location and obtaining the authorization given by the owner of the corresponding device.
The embodiment of the disclosure provides a data operation method, which achieves the purposes of traceability and non-falsification of data by introducing the characteristics of trusted block chain consensus, decentralization and tamper resistance into a data center station and storing all operation records of a database on a block chain. To achieve the above object, a blockchain network is first constructed, a plurality of blockchain nodes are included in the blockchain network, and the following data operation methods provided by the embodiments of the present disclosure are implemented according to the constructed blockchain network.
FIG. 1 illustrates a flow chart of a data manipulation method provided by an exemplary embodiment, the method being applied to a blockchain node in a blockchain network, as shown in FIG. 1, the method comprising:
S110, responding to an operation request initiated to the database corresponding to the block chain link point, and checking whether an initiator of the operation request has corresponding database operation authority.
Each block link point in the block chain network is provided with a corresponding database for storing data, and databases used between different block chain nodes may be the same or different, for example, a database used by one block chain node is MySQL, and a database used by another block chain node is a document database. In the above steps, in response to an operation request initiated to a database local to a blockchain node, it is first checked whether an initiator of the operation request has corresponding database operation authority.
In specific implementation, an intelligent contract is deployed on the blockchain node, and the operation of checking whether the initiator of the operation request has corresponding database operation authority is completed through the intelligent contract.
Optionally, the corresponding database operation authority comprises whether the initiator has a service authority for performing corresponding operation on the database and whether the initiator has a data authority for performing operation on a data table to be operated. Under the condition that the initiator has corresponding service authority and data authority, the initiator is determined to have corresponding database operation authority on the database.
Illustratively, the operation request is for requesting writing of a piece of data to the data table a in the database, and in the above step, it is necessary to check whether the initiator has a service authority to write to the database and whether it has a data authority to operate on the data table a.
In concrete implementation, a service authority check intelligent contract and a data authority check intelligent contract are deployed on the blockchain node, whether an initiator has service authority for performing corresponding operation on a database is checked through the service authority check intelligent contract, and whether the initiator has data authority for performing operation on a data table to be operated is checked through the data authority check intelligent contract.
In the present disclosure, the rights verification method needs to be combined with the blockchain, and a rights verification method applicable to the blockchain network may be used, for example, a rights verification method based on CA (CERTIFICATE AUTHORITY ) and/or a rights verification method based on distributed digital identity may be adopted.
Based on the authority verification mode of the CA, registering the public key certificate of the authorized party on the blockchain, attaching a private key signature result to the received operation request, and performing authority verification according to the private key signature result by the corresponding authority verification intelligent contract.
Based on the authority verification mode of the distributed digital identity, the digital identity information of the authorizer is stored on a blockchain, and an initiator initiates an operation request to a database in a distributed digital identity certificate mode, wherein the certificate comprises request content, the identity information of the initiator, a time stamp, a signature and signature verification algorithm information. After receiving the operation request, the corresponding authority check intelligent contract finds the signature verification public key to be used from the distributed digital identity information on the chain according to the identity information of the initiator and the signature verification algorithm information, verifies the signature and performs authority check by combining with the timestamp.
The service authority check intelligent contract can adopt any one of the authority check modes to check the service authority of the initiator, and correspondingly, the data authority check intelligent contract can also adopt any one of the authority check modes to check the service authority of the initiator.
And S120, executing corresponding database operation on the database under the condition that the authority verification is passed.
And under the condition that the initiator of the operation request is verified to have corresponding database operation authority, executing the database operation requested to be executed by the operation request on the database corresponding to the blockchain node.
And S130, after the database operation is completed, the operation record of the database operation is packaged into a transaction, and the transaction is broadcasted to other block chain link points in the block chain network, so that other block chain nodes record the transaction on the block chain after consensus the transaction.
After the database operation is completed, the operation record of the database operation is packaged into a transaction, the transaction is broadcasted to other block chain link points in the block chain network, all block chain nodes in the block chain network carry out consensus on the transaction, and after the consensus, the transaction is recorded on the block chain, so that the uplink of the operation record is completed. After the operation records are up-linked, all blockchain nodes can query each blockchain node for all operation records for the respective database from the blockchain.
Illustratively, assume that the current database operation of blockchain node 1 is writing a piece of data named Zhang Sanand ID card number xxxx into data table A in the local database. After the operation of the database is completed, a piece of data of Zhang San and xxxx is newly added in a data table A in the database, meanwhile, the operation record of the operation of the database is recorded on a blockchain, other blockchain nodes can read the operation record of 'Zhang San and an identity card number xxxx' from the blockchain to write a piece of data in the data table A.
In the event that the transaction consensus fails, the database operations described above that are performed on the database need to be rolled back to ensure consistency of the operations on the database with the operation records maintained on the blockchain.
It can be understood that in the above scheme, since the authority check is performed on the corresponding database operation authority of the initiator of the operation request, the control of data access is realized, and all the operations executed on the database are recorded on the blockchain, so that the upper layer application cannot easily tamper the data in the database, and the method has the effects of traceability and non-tamper of the data center. In addition, the conventional database has the defect of poor disaster recovery capability, in the scheme, because all operations on the database are stored on the blockchain, all blockchain nodes can inquire operation records of all data tables in each database from the blockchain, all the data tables in storage can be obtained according to the operation records, and each blockchain node can obtain the data tables in storage in global consistency, so that the disaster recovery capability of the database is improved, and the method can be effectively compatible with heterogeneous databases.
In addition, considering that the efficiency of the blockchain network for consensus on the transaction is lower, the scheme adopts a mode of firstly warehousing and then consensus, the blockchain node is preferentially ensured to have the performance of a database level, the database operation can be completed in time, and on the basis, the operation record is subjected to consensus uplink, so that other external service systems which interact with the database are ensured not to be influenced.
Optionally, fig. 2 shows a flowchart of a specific embodiment of performing the corresponding database operation on the database in step S120, as shown in fig. 2, where step S120 includes:
S210, determining a preset conflict detection rule base, wherein the conflict detection rule base comprises a plurality of inhibition rules, and each inhibition rule respectively indicates the forbidden operation corresponding to the data table in the database.
A conflict detection rule base is established in advance, the conflict detection rule base comprises a plurality of inhibition rules, each inhibition rule respectively indicates an inhibited operation corresponding to a data table in the database, the inhibited operation represents an atomic-level operation on the data table, and the atomic-level operation comprises table establishment, table connection, projection operation, merging operation, data writing, data deleting, data updating and data reading.
Illustratively, a conflict detection rule base p= { P1, P2,..pn }, pi, represents one prohibition rule, e.g., P1 corresponds to the prohibition rule "data table a is prohibited from being written".
S220, decomposing the database operation into a plurality of atomic-level operations of a data table in the database.
The operation request requests a corresponding database operation, illustratively, to write one of the data of data table B into data table a. The database operation is decomposed into a plurality of atomic level operations aiming at the data table in the database, and the plurality of atomic level operations comprise an atomic level operation 1 for reading one piece of data in the data table B and an atomic level operation 2 for writing the read data in the data table B into the data table A.
S230, performing conflict detection on the plurality of atomic level operations according to the conflict detection rule base.
S240, generating a linear operation flow according to the atomic-level operation which does not conflict with the forbidden rules in the conflict detection rule base in the atomic-level operations.
And when the resolved operation at the atomic level belongs to an operation forbidden by a certain forbidden rule in the conflict detection rule base, determining that the operation at the atomic level collides with the forbidden rule in the conflict detection rule base. And screening out atomic-level operations which conflict with forbidden rules in a conflict detection rule base in the plurality of atomic-level operations after conflict detection of each atomic-level operation is completed, and combining the rest atomic-level operations which do not conflict with the forbidden rules in the conflict detection rule base into a linear operation flow.
Illustratively, if the prohibition rule p1 in the conflict detection rule base is "data table a is prohibited from being written", and the resolved certain atomic level operation includes "writing the data in the read data table B into the data table a", it is determined that the atomic level operation conflicts with the prohibition rule p1 in the conflict detection rule base.
S250, each atomic-level operation in the linear operation flow is sequentially executed on the database.
After the linear operation flow is obtained, each atomic-level operation in the linear operation flow is sequentially executed on the database corresponding to the blockchain node.
Optionally, considering that in the above steps, there may be a case where an operation fails in the process of executing each atomic level operation, an operation transfer rule base is pre-established, where the operation transfer rule base includes a plurality of transfer rules, each of the transfer rules indicating a processing policy when the corresponding operation fails to execute.
The operation transfer rule in the operation transfer rule base includes, but is not limited to, (1) a table establishment failure, (2) a table connection failure, (3) a projection operation failure, (2) a save operation recorded as a to-be-processed state, (4) a parallel operation failure, (4) a save operation recorded as a to-be-processed state, (5) a data writing failure, (5) a rollback operation, (6) a data deletion failure, (7) a rollback operation, (8) a data reading failure, (8) a skip operation and a next operation in the linear operation stream. Of course, the above listed transfer rules are only one example and do not represent that in actual situations it is necessary to set up according to such rules.
And in the process of sequentially executing each atomic level operation in the linear operation flow on the database corresponding to the blockchain node, continuing to execute the next atomic level operation in the linear operation flow under the condition that the atomic level operation in the linear operation flow is successfully executed, and determining a target transfer rule corresponding to the atomic level operation which fails to be executed in the operation transfer rule base according to the operation transfer rule base under the condition that the atomic level operation in the linear operation flow fails to be executed, and then responding to a processing strategy in the target transfer rule. For example, when the data read operation of the data table B in the linear operation flow is performed, if the data read operation fails, the present operation is skipped and the next operation in the linear operation flow is performed in response to the corresponding processing policy.
After the linear operation flow is executed, the block link point encapsulates the operation record of the database into a transaction and stores the transaction record on a block chain.
Optionally, after receiving the operation request, the blockchain link point first checks whether the local data table is consistent with the data table recorded on the blockchain, if not, the data table needs to be restored by the corresponding block on the blockchain, and if the corresponding block is locally missing by the blockchain node, the block is synchronized from other blockchain nodes in the blockchain network.
Further, considering that all parties of different blockchain nodes may have larger service differences, that is, databases used by different blockchain nodes are different, for example, a database used by a certain blockchain node is MySQL, and a database used by another blockchain node is a document type database, which will cause multi-source heterogeneous of data, so that unified operation and management of data are difficult to realize, and difficulty is caused to development of upper layer application.
To solve the problem of multi-source heterogeneous data, fig. 3 shows a flowchart of a data operation method according to an exemplary embodiment, and as shown in fig. 3, the method includes:
S310, determining a data aggregation plan, wherein the data aggregation plan is used for indicating the triggering condition of the data aggregation operation, at least one source data table corresponding to the data aggregation operation and a target relation mode corresponding to the data aggregation operation.
A data aggregation plan is pre-established, and the data aggregation plan is used for indicating a triggering condition of a data aggregation operation, at least one source data table corresponding to the data aggregation operation and a target relation mode corresponding to the data aggregation operation. The trigger condition may be an event type trigger condition or a time type trigger condition.
For time-based trigger conditions, for example, a certain data aggregation is defined as that data aggregation operation is performed on the source data table a and the source data table B once every other week (trigger conditions).
For event type triggering conditions, for example, a certain data aggregation rule is that every time the source data table A is updated or every hundred thousand pieces of data (triggering conditions) are added to the source data table A, the data aggregation operation is performed on the source data table A and the source data table B.
And S320, when the trigger condition is determined to be met, extracting the operation record corresponding to the source data table from the blockchain, and restoring the corresponding source data table according to the extracted operation record.
The following description will take at least one source data table in the data aggregation plan as a source data table a and a source data table B, respectively, as an example. Because the operation records of all the data tables are stored in the blockchain, the operation records comprise a plurality of operation records of the source data table A, a plurality of operation records of the source data table B, a plurality of operation records of the source data table C and the like, when the trigger condition in the data aggregation plan is determined to be met, the operation records of the source data table A and the operation records of the source data table B are extracted from the blockchain, the corresponding source data table A is restored according to the operation records of the source data table A, and the corresponding source data table B is restored according to the operation records of the source data table B.
S330, aggregating the restored source data table to the target relation mode to obtain an aggregation table.
S340, broadcasting the aggregation table to other block chain nodes in the block chain network so that the other block chain nodes record the aggregation table on the block chain after consensus the aggregation table.
It will be appreciated that before the present solution is adopted, the data tables are stored in different databases respectively, and due to the different databases, the data tables cannot be operated uniformly, after the present solution is adopted, and aggregating the related source data table into a unified target relation mode according to the data aggregation plan to obtain an aggregation table, so that all the blockchain nodes can operate the aggregation table only by using a unified operation instruction, and the operational uniformity is realized.
Optionally, fig. 4 shows a flowchart of a specific implementation manner of obtaining the aggregation table in the step S330 provided in an exemplary embodiment, and as shown in fig. 4, the step S330 includes:
S410, constructing an aggregation table with a target relation mode, wherein the target relation mode comprises a table structure and a table field, and the table field comprises a primary key and non-primary key attributes.
And constructing an aggregation table with a target relation mode, wherein the constructed aggregation table is an initial aggregation table. The target relation mode comprises a table structure and a table field, the table field comprises a primary key and a non-primary key attribute, and each attribute field is defined according to business services required to be provided by the data center.
Optionally, the table field of the aggregate table includes a primary key, a non-primary key attribute, and a time field, which may be used to represent the last update time of the corresponding data or other time information. Similarly, the table field of each source data table also includes primary key and non-primary key attributes, and optionally, a time field.
The aggregate table is denoted current, the source data table a is denoted sourceA, and the source data table B is denoted sourceB, and there are:
sourceA={akey,z1,z2,z3,...,time};
sourceB={bkey,g1,g2,g3,...,time};
current={key,att1,att2,att3...time};
Wherein akey is a primary key of the source data table a, z1, z2, z3 are non-primary key attributes of the source data table a, bkey is a primary key of the source data table B, g1, g2, g3 are non-primary key attributes of the source data table B, key is a primary key of the aggregation table, att1, att2, att3 are non-primary key attributes of the aggregation table, and time is a time field.
S420, establishing a mapping relation between the non-primary key attribute of each source data table and the non-primary key attribute of the aggregation table.
It will be appreciated that a mapping relationship between the non-primary key attributes of each source data table and the non-primary key attributes of the aggregate table needs to be established to determine which entry of the source data table should be populated onto which entry of the aggregate table. According to the above example, the following mapping relationship may be established:
att1←(z1,g1);
att2←(z2,g2);
att3←(z3,g3)。
s430, determining a main key mediation table, wherein the main key mediation table is used for mapping the main keys of each source data table to the main keys of the main key mediation table respectively.
The difference of the data primary keys extracted from the source data table a and the source data table B affects the unification of the relationship patterns, and data mediation is a process of unifying the data primary key forms, so that it is necessary to establish a primary key mediation table for each source data table. The primary key of the original relation mode of each source data table is mapped to the primary key of the target relation mode of the aggregation table through defining a primary key mediation table.
Illustratively, according to the above example, the key mediation table is:
conc={ckey,akey,bkey};
Where ckey is the primary key of the primary key mediation table.
S440, for each source data table, naturally connecting the source data table with the main key mediation table to obtain a corresponding intermediate data table.
Illustratively, according to the above example, for the source data table a, the source data table a and the key mediation table are naturally connected to obtain an intermediate data table corresponding to the source data table a, denoted by TempA, and for the source data table B, the source data table B and the key mediation table are naturally connected to obtain an intermediate data table corresponding to the source data table B, denoted by TempB.
Wherein TempA ++ sourceA fact coc;
Wherein TempB ++ sourceB fact coc;
wherein infinity is a natural connector.
S450, performing corresponding projection operation on the source data table according to the set first projection condition and the corresponding intermediate data table.
S460, mapping the result of projection operation into the table item of the aggregation table according to the mapping relation between the source data table and the aggregation table, and obtaining the target data.
And for each source data table, carrying out projection operation on the source data table according to the set first projection condition and the intermediate data table corresponding to the source data table, and mapping the projection operation result into the table item of the aggregation table according to the mapping relation between the source data table and the aggregation table to obtain the target data corresponding to the source data table.
Illustratively, according to the above example, the target data corresponding to the source data table a is denoted as dataA, and the target data corresponding to the source data table B is denoted as dataB, then there are:
dataA←π(sourceA)(TempA);
dataB←π(sourceB)(TempB);
Where pi is the projection operator.
As an example, the projection operation represented by dataa≡pi (sourceA) (TempA) is:
And determining TempA fields meeting the conditions according to the first projection conditions, and determining sourceA data projection aiming at the fields meeting the conditions in TempA to obtain required data.
S470, performing merging operation on the target data corresponding to each source data table, and writing the merging operation result into the aggregation table.
After the above steps, the obtained target data dataA and dataB are data in the same relationship mode, so that only the simple and operation of the target data dataA and dataB is needed, and the result of the and operation is written into the aggregation table. The polymerization table obtained is:
current←dataA∪dataB
or the resulting polymerization table is:
current←current∪dataA∪dataB
In an alternative embodiment, in the steps S410 to S470, only when the data aggregation operation for the new target relationship mode is executed, an aggregation table is newly constructed, and if the data aggregation operation is initiated for multiple times for the same target relationship mode, the subsequent data aggregation operation does not need to construct a new aggregation table, but directly updates the aggregation result into the originally constructed aggregation table.
With the continuous progress of data aggregation operation, more and more data are in the aggregation table, so that old data with low value in the aggregation table need to be timely migrated to other tables for data archiving.
Optionally, fig. 5 shows a flowchart of a data operation method provided in an exemplary embodiment, as shown in fig. 5, where the method includes:
s510, constructing a history table with the same relation mode as the aggregation table.
Wherein the same relationship pattern indicates that the history table and the aggregate table have the same table structure and the same table field. Step S510 may be performed simultaneously with step S410, i.e., simultaneously building an aggregate table and a history table having the same target relationship pattern.
S520, performing corresponding projection operation on the aggregation table according to the set second projection conditions to obtain data to be migrated.
And performing corresponding projection operation on the aggregation table according to the set second projection condition to obtain data dataOld to be migrated.
Wherein dataOld +.pi (current) (time).
It will be appreciated that which data is defined as old data that needs to be migrated is defined by the second projection condition, e.g. data one year old or data one month old.
As an example, the projection operation represented by dataOld +.pi (current) (time) is:
And determining the data of which the time information in the current meets the second projection condition according to the second projection condition and the time field time in the current, so as to obtain the required data.
S530, the data to be migrated is migrated to a history table.
After determining the data to be migrated dataOld, the migration of the data to be migrated dataOld from the aggregate table current to the history table history is as follows:
current←current–dataOld;
history←dataOld;
Or the following steps:
history←history∪dataOld。
S540, the history table is broadcast to other blockchain nodes in the blockchain network, so that the other blockchain nodes record the history table on the blockchain after consensus of the history table.
Through the steps, old data can be timely migrated to the history table history, and the function of data archiving is achieved.
In an exemplary embodiment of the present disclosure, there is further provided a blockchain system, where the blockchain system includes a blockchain network including a plurality of blockchain nodes, each blockchain node is provided with a data-in-process service module, in which an intelligent contract is deployed in the data-in-process service module, and each blockchain node is configured to execute the intelligent contract in the data-in-process service module, so as to implement each step of the data operation method provided in the foregoing method embodiment.
It will be appreciated that the services of the data center are implemented by intelligent contracts, i.e., services of the data center can be implemented on the blockchain system by intelligent contracts deployed on each blockchain node.
Fig. 6 shows a schematic diagram of implementing a data center service based on the above-described blockchain system. As shown in FIG. 6, the blockchain system includes a blockchain network composed of a plurality of blockchain nodes, each blockchain node has its own corresponding database for storing data, and the databases used between different blockchain nodes may be the same or different, for example, the database used by one blockchain node is MySQL, and the database used by another blockchain node is a document-type database.
Services of the data center include, but are not limited to, data authorization management, service authorization management, data development planning, and data aggregation planning.
In concrete implementation, each blockchain node is provided with a data center business module, and the data center business module is provided with a corresponding data authority check intelligent contract, a service authority check intelligent contract, a data development intelligent contract and a data aggregation intelligent contract.
The service right check intelligent contract is used for checking whether an initiator of the operation request has service right for carrying out corresponding operation on the database after receiving the operation request, the data right check intelligent contract is used for checking whether the initiator has data right for carrying out operation on a data table to be operated after receiving the operation request, the data development intelligent contract is used for managing a conflict detection rule base and an operation transfer rule base, after determining that the right check of the service right check intelligent contract and the data right check intelligent contract passes, corresponding database operation is carried out on the data base according to the conflict detection rule base and the operation transfer rule base, the data aggregation intelligent contract is used for managing a data aggregation plan, and after determining that the triggering condition in the data aggregation plan is met, corresponding data aggregation operation is carried out on a relevant source data table in the data aggregation plan.
In the above-mentioned blockchain system, the blockchain technology is used to realize data aggregation, the blockchain is combined with the database, the operation on the database is stored on the chain, the intelligent contract is used to realize the middle station service, the control and planning tasks of data access are performed on the chain, the characteristics of trusted, decentralised and non-tamperable blockchain consensus are introduced into the middle station of the data, and the data security is effectively improved.
The detailed steps of the data manipulation method implemented by each blockchain node in executing the smart contract in relation to the blockchain system in the above embodiments have been described in detail in relation to the embodiments of the method, and will not be described in detail herein.
In an exemplary embodiment of the present disclosure, there is also provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the data manipulation method provided in the foregoing embodiment.
In an exemplary embodiment of the present disclosure, a data manipulation device is also provided that is configured at a blockchain node in a blockchain network. Fig. 7 shows a block diagram of the data manipulation device, as shown in fig. 7, the device 600 comprises:
The permission checking module 610 is configured to check, in response to an operation request initiated to a database corresponding to the blockchain node, whether an initiator of the operation request has a corresponding database operation permission;
A database operation module 620, configured to perform a corresponding database operation on the database if the authority verification passes;
and the record uplink module 630 is configured to encapsulate an operation record of the database operation into a transaction after the database operation is completed, and broadcast the transaction to other blockchain link points in the blockchain network, so that the other blockchain nodes record the transaction onto a blockchain after consensus the transaction.
Optionally, the apparatus 600 further comprises a consensus failure handling module for rollback the database operation performed on the database in case the transaction consensus fails.
Optionally, the database operation module 620 includes:
the conflict rule determining module is used for determining a preset conflict detection rule base, wherein the conflict detection rule base comprises a plurality of prohibition rules, and the prohibition rules are used for indicating prohibited operations corresponding to data tables in the database;
An operation decomposition module for decomposing the database operation into a plurality of atomic level operations on a data table in the database;
The conflict detection module is used for carrying out conflict detection on the plurality of atomic-level operations according to the conflict detection rule base;
An operation flow generating module, configured to generate a linear operation flow according to an atomic-level operation that does not collide with a prohibition rule in the conflict detection rule base in the plurality of atomic-level operations;
And the operation execution module is used for sequentially executing each atomic-level operation in the linear operation flow on the database corresponding to the blockchain node.
Optionally, the apparatus 600 further includes a transfer rule determining module, configured to determine a preset operation transfer rule base, where the operation transfer rule base includes a plurality of transfer rules, and each transfer rule is used to indicate a processing policy when the corresponding operation fails to execute.
The operation executing module is used for determining a target transfer rule corresponding to the atomic-level operation in the operation transfer rule base under the condition that the execution of the atomic-level operation in the linear operation flow fails, and responding to the processing strategy in the target transfer rule.
Optionally, the apparatus 600 further includes:
The aggregation plan determining module is used for determining a data aggregation plan, wherein the data aggregation plan is used for indicating a triggering condition of data aggregation operation, at least one source data table corresponding to the data aggregation operation and a target relation mode corresponding to the data aggregation operation;
the data table restoring module is used for extracting an operation record corresponding to the source data table from the blockchain when the triggering condition is determined to be met, and restoring the corresponding source data table according to the operation record;
The data aggregation module is used for aggregating the restored at least one source data table into the target relation mode to obtain an aggregation table;
and the aggregation table uplink module is used for broadcasting the aggregation table to other blockchain link points in the blockchain network so that other blockchain nodes record the aggregation table on a blockchain after consensus of the aggregation table.
Optionally, the data aggregation module includes:
the aggregation table construction module is used for constructing an aggregation table with the target relation mode, wherein the target relation mode comprises a table structure and a table field, and the table field comprises a primary key and a non-primary key attribute;
The attribute mapping module is used for establishing a mapping relation between the non-primary key attribute of each source data table and the non-primary key attribute of the aggregation table;
The main key mediation module is used for determining a main key mediation table, and the main key mediation table is used for mapping the main key of each source data table to the main key of the main key mediation table respectively;
The data mediation module is used for naturally connecting the source data table with the main key mediation table aiming at each source data table to obtain a corresponding intermediate data table;
the first projection module is used for carrying out corresponding projection operation on the source data table according to the set first projection condition and the intermediate data table, and mapping the projection operation result into the table item of the aggregation table according to the mapping relation between the source data table and the aggregation table to obtain target data;
And the aggregation table obtaining module is used for carrying out the merging operation on the target data corresponding to each source data table and writing the merging operation result into the aggregation table.
Optionally, the apparatus 600 further includes:
the history table construction module is used for constructing a history table with the same relation mode with the aggregation table;
the second projection module is used for carrying out corresponding projection operation on the aggregation table according to the set second projection condition to obtain data to be migrated;
The data migration module is used for migrating the data to be migrated to the history table;
And the history table uplink module is used for broadcasting the history table to other block link points in the block chain network so that other block chain nodes record the history table on a block chain after consensus of the history table.
The specific manner in which the various modules perform the operations in the apparatus of the above embodiments have been described in detail in connection with the embodiments of the method, and will not be described in detail herein.
The preferred embodiments of the present disclosure have been described in detail above with reference to the accompanying drawings, but the present disclosure is not limited to the specific details of the embodiments described above, and various simple modifications may be made to the technical solutions of the present disclosure within the scope of the technical concept of the present disclosure, and all the simple modifications belong to the protection scope of the present disclosure.
In addition, the specific features described in the foregoing embodiments may be combined in any suitable manner, and in order to avoid unnecessary repetition, the present disclosure does not further describe various possible combinations.
Moreover, any combination between the various embodiments of the present disclosure is possible as long as it does not depart from the spirit of the present disclosure, which should also be construed as the disclosure of the present disclosure.