Second-level heartbeat synchronization method for block chain big databaseTechnical Field
The invention relates to the technical field of computers, in particular to a second-level heartbeat synchronization method for a large block chain database.
Background
In the blockchain system, when a database server provides services, a plurality of independent big data servers are usually deployed to cooperate in a synchronous manner, so as to ensure the accuracy, reliability and incapability of modifying data. Therefore, it becomes a challenge to quickly synchronize and store these data in multiple databases.
In the prior art, when data synchronization is performed on a plurality of independent large databases, the service of the large databases is often required to be stopped temporarily during the synchronization. When the database becomes very large and a new server needs to be added, a long time of data transmission is needed to establish the synchronized database, so that the service may be stopped for tens of minutes each time the database is synchronized, and the service can be provided only after the database synchronization is completed, which seriously affects the use of users. Therefore, the expectations of users cannot be met in a global service.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a second-level heartbeat synchronization method for a large block chain database. The invention is suitable for a plurality of independent synchronous large databases, can enable the large-capacity independent databases to achieve second-level synchronization, and is particularly suitable for data synchronization of uninterrupted and single-center-free block chain databases.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:
a second-level heartbeat synchronization method for a block chain big database comprises the following steps:
s1, defining the synchronous period T of data synchronization in the large database of block chain according to the size and transmission speed of the data stored in the large database of block chain1=2nSecond, each block chain big database can only start to synchronize according to the synchronization period when synchronizing; the n is equal to the size of the data stored in the existing blockchain big database divided by the transmission speed;
s2, defining the data in the existing block chain big database as file 0;
s3, fromsynchronization cycle 2n-1The second begins to write the file 0 in the existing block chain big database into the newly added block chain big database to 2nSecond time file 0 write is complete, will 2n-1Second-2nDefining newly added data in the existing block chain big database within second time asfile 1;
s4, from 2n-2Second begins writingfile 1 into the newly added blockchain big database to 2n-1Second time file 1 write is completed, will 2n-2Second-2n-1Defining newly added data in the existing block chain big database within second time asfile 2;
s5, and so on, from 20The file n-1 of the existing block chain big database is written into the newly added block chain big database to 21When the second file n-1 write is completed, will20Second-21Defining newly added data in the existing block chain big database within second time as file n;
s6, from 20The file n of the existing block chain big database is written into the newly added block chain big database when the file n is written, and all data in the block chain big database are synchronously finished;
s7, when data transmission error occurs in the data synchronization process, starting to perform data synchronization again from the next synchronization period; when no data transmission error occurs in the data synchronization process, putting the newly added block chain large database into operation;
and S8, after the newly added blockchain big database is put into operation, the regenerated new data is updated in the newly synchronized blockchain big database and the existing blockchain big database at the same time.
On the basis of the technical scheme, defining the actual time required for completing synchronization of the large database of the block chain as T; in step S1, the actual time T required for completing synchronization of the large database of the block chain is less than or equal to the synchronization period T1。
On the basis of the technical scheme, in the data synchronization process, the existing block chain big database does not need to stop service, and the data updating speed of the existing block chain big database is 1 time/second.
On the basis of the above technical solution, in step S3, when file 0 to file n are written into the newly added blockchain big database, it needs to be determined whether the operating system of the existing blockchain big database is consistent with the operating system of the newly added blockchain big database; if the file is consistent with the file system directory specified by the newly added large block chain database, directly writing the files 0 to n into the file system directory specified by the newly added large block chain database; and if not, converting the files 0 to the files n to enable the files 0 to the files n to be in line with the operating system of the newly added large block chain database, and writing the converted files 0 to files n into a file system directory specified by the newly added large block chain database.
On the basis of the above technical solution, in step S3, when file 0 to file n are written into the newly added blockchain big database, it needs to be determined whether the type of the configuration file of the existing blockchain big database is consistent with the type of the configuration file of the newly added blockchain big database; if the file is consistent with the file system directory specified by the newly added large block chain database, directly writing the files 0 to n into the file system directory specified by the newly added large block chain database; and if not, converting the configuration file types of the newly added large block chain database, and writing the converted files 0-file n into a file system directory specified by the newly added large block chain database.
Based on the above technical solution, in step S8, the regenerated new data will be updated in the newly added blockchain big database and the existing blockchain big database at the same time, and the updating speed is 1 time/second.
The second-level heartbeat synchronization method for the block chain big database has the following beneficial effects:
1. the time required for synchronizing the large database of the block chain at each time is at most 2 synchronization periodsnSecond, and the existing blockchain large database does not need to be out of service during database synchronization.
2. The transmission speed of the newly added large block chain database can be optimized and is synchronous with the data of each stage in the existing large block chain database.
3. And in the operation process of the block chain large database, the data updating speed is 1 time/second.
4. The invention utilizes a hierarchical synchronization mode to ensure that the large block chain database with any size can run simultaneously with the existing large block chain database, and the database updated in a second level is synchronized.
Drawings
The invention has the following drawings:
FIG. 1 is a diagram illustrating the data block partitioning and transmission time of a large database of a prior art block chain in the method of the present invention;
FIG. 2 is a schematic diagram of a data transmission time axis in a newly added large database with block chains in the method of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings.
As shown in fig. 1 and fig. 2, the second-level heartbeat synchronization method for a large block chain database according to the present invention includes the following steps:
s1, defining the synchronous period T of data synchronization in the large database of block chain according to the size and transmission speed of the data stored in the large database of block chain1=2nSecond, each block chain big database can only start to synchronize according to the synchronization period when synchronizing; the n is equal to the size of the data stored in the existing blockchain big database divided by the transmission speed;
s2, defining the data in the existing block chain big database as file 0;
s3, fromsynchronization cycle 2n-1The second begins to write the file 0 in the existing block chain big database into the newly added block chain big database to 2nSecond time file 0 write is complete, will 2n-1Second-2nDefining newly added data in the existing block chain big database within second time asfile 1;
s4, from 2n-2Second begins writingfile 1 into the newly added blockchain big database to 2n-1Second time file 1 write is completed, will 2n-2Second-2n-1Defining newly added data in the existing block chain big database within second time asfile 2;
s5, and so on, from 20The file n-1 of the existing block chain big database is written into the newly added block chain big database to 21When the second file n-1 is written, 2 is written0Second-21Defining newly added data in the existing block chain big database within second time as file n;
s6, from 20The file n of the existing block chain big database is written into the newly added block chain big database when the file n is written, and all data in the block chain big database are synchronously finished;
s7, when data transmission error occurs in the data synchronization process, starting to perform data synchronization again from the next synchronization period; when no data transmission error occurs in the data synchronization process, putting the newly added block chain large database into operation;
and S8, after the newly added blockchain big database is put into operation, the regenerated new data is updated in the newly synchronized blockchain big database and the existing blockchain big database at the same time.
On the basis of the technical scheme, defining the actual time required for completing synchronization of the large database of the block chain as T; in step S1, the actual time T required for completing synchronization of the large database of the block chain is less than or equal to the synchronization period T1。
On the basis of the technical scheme, in the data synchronization process, the existing block chain big database does not need to stop service, and the data updating speed of the existing block chain big database is 1 time/second.
On the basis of the above technical solution, in step S3, when file 0 to file n are written into the newly added blockchain big database, it needs to be determined whether the operating system of the existing blockchain big database is consistent with the operating system of the newly added blockchain big database; if the file is consistent with the file system directory specified by the newly added large block chain database, directly writing the files 0 to n into the file system directory specified by the newly added large block chain database; and if not, converting the files 0 to the files n to enable the files 0 to the files n to be in line with the operating system of the newly added large block chain database, and writing the converted files 0 to files n into a file system directory specified by the newly added large block chain database.
On the basis of the above technical solution, in step S3, when file 0 to file n are written into the newly added blockchain big database, it needs to be determined whether the type of the configuration file of the existing blockchain big database is consistent with the type of the configuration file of the newly added blockchain big database; if the file is consistent with the file system directory specified by the newly added large block chain database, directly writing the files 0 to n into the file system directory specified by the newly added large block chain database; and if not, converting the configuration file types of the newly added large block chain database, and writing the converted files 0-file n into a file system directory specified by the newly added large block chain database.
Based on the above technical solution, in step S8, the regenerated new data will be updated in the newly added blockchain big database and the existing blockchain big database at the same time, and the updating speed is 1 time/second.
Example (b):
step 1, if the data size in the existing block chain big database is 100Gb, and the data transmission speed is 200Mb/s, the prediction time required for completing the synchronization of the block chain big database is 512s, namely T1=29And second.
Step 2, defining the data in the large database of the existing block chain as file 0;
the operating system and the configuration file type of the existing block chain big database are consistent with those of the newly added block chain big database;
step 3, fromstep 28The second begins to write the file 0 of the existing block chain big database into the newly added block chain big database to 29Second time file 0 write is complete, will 28Second-29Defining newly added data in the existing block chain big database within second time asfile 1;
step 4, from 27The second begins to writefile 1 of the existing block chain big database into the newly added block chain big database to 28Second time file 1 write is completed, will 27Second-28Defining newly added data in the existing block chain big database within second time asfile 2;
step 5, analogizing fromstep 20The file 8 of the existing block chain big database is written into the newly added block chain big database from second to 21Second time file 8 write is complete, will 20Second-21Defining newly added data in the existing block chain big database within second time as file 9;
step 6, from 20The file 9 of the existing block chain big database is written into the newly added block chain big database at the beginning of the second till the file 9 is written, and all data in the block chain big database are synchronously finished;
step 7, when no data transmission error occurs in the data synchronization process of the whole block chain big database, putting the newly added block chain big database into operation;
and 8, after the newly added block chain big database is put into operation, the regenerated new data is updated in the newly synchronized block chain big database and the existing block chain big database at the updating speed of 1 time/second.
When the method of the invention is adopted to carry out synchronization of the large database of the block chain, the time required by each synchronization is at most 2nSecond, and in a blockchain big databaseThe existing blockchain large database does not need to stop service in the synchronization process. And after the synchronization of the newly added block chain big database and the existing block chain big database is completed, putting into operation, and simultaneously updating the regenerated new data in the newly synchronized block chain big database and the existing block chain big database.
The method of the invention synchronizes data according to multiple of 2 until the last 1 second data in the large database of the existing block chain is synchronized. After the data synchronization is finished, the block chain database with any size can run simultaneously with the existing block chain large database, and the block chain large database synchronization of second-level updating is realized.
Those not described in detail in this specification are within the skill of the art.