CN109857727B - Local database reconstruction method, device and storage medium - Google Patents

Local database reconstruction method, device and storage medium Download PDF

Info

Publication number
CN109857727B
CN109857727B CN201910157804.5A CN201910157804A CN109857727B CN 109857727 B CN109857727 B CN 109857727B CN 201910157804 A CN201910157804 A CN 201910157804A CN 109857727 B CN109857727 B CN 109857727B
Authority
CN
China
Prior art keywords
local database
transaction
block
executing
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
CN201910157804.5A
Other languages
Chinese (zh)
Other versions
CN109857727A (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.)
Hangzhou Fuzamei Technology Co Ltd
Original Assignee
Hangzhou Fuzamei 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 Hangzhou Fuzamei Technology Co Ltd filed Critical Hangzhou Fuzamei Technology Co Ltd
Priority to CN201910157804.5A priority Critical patent/CN109857727B/en
Publication of CN109857727A publication Critical patent/CN109857727A/en
Application granted granted Critical
Publication of CN109857727B publication Critical patent/CN109857727B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a local database reconstruction method, equipment and a storage medium, wherein the method comprises the following steps: detecting whether the version of the local database is updated: if so, the transaction of all blocks on the first blockchain is re-executed in order of block height to reconstruct the local database. The invention can detect whether the database version number is updated or not by configuring the version number for the local database, if so, the transaction in the block is executed again according to the sequence from low to high of the block height to reconstruct the local database, thereby ensuring that the actual results of the current block chain version exist in the local database and greatly improving the efficiency of reconstructing the database.

Description

Local database reconstruction method, device and storage medium
Technical Field
The present application relates to the field of blockchain technologies, and in particular, to a method, device, and storage medium for local database reconstruction.
Background
With the iteration of the block chain version, the local database and the state database should be updated continuously, however, the block chain nodes are distributed in a large number, the versions are not updated in time, however, the local database is not known in common, if the versions are not updated in time, the data storage is not affected, after the versions are updated, the local database has a condition inconsistent with the data structure recorded by the current version, and the existing scheme for updating the local database is to delete the local database and the state database and start to synchronize data from the block height of 0 again. The defects of the existing scheme are as follows: since the block height is often millions of heights and also grows at any time, the method of re-synchronizing data in the system after deleting the database is time-consuming and inefficient.
Disclosure of Invention
In view of the above-mentioned shortcomings or drawbacks of the prior art, it is desirable to provide a reconstruction method, apparatus and storage medium that are efficient and require only the reconstruction of a local database.
In a first aspect, the present invention provides a method for reconstructing a local database, including:
detecting whether the version of the local database is updated:
if so, the transaction of all blocks on the first blockchain is re-executed in order of block height to reconstruct the local database.
Further, recalculating the transactions for all blocks on the first blockchain to reconstruct the local database comprises:
deleting the local database, and acquiring and executing the transaction of each block according to the sequence of the block heights from low to high;
and storing a plurality of data information generated after the calculation and execution of each transaction in a local database to reconstruct the local database.
Further, the method further comprises:
if interruption occurs in the process of executing each transaction, the system is restarted and then continues to execute each subsequent block from the height of the interrupted block.
In a second aspect, the present invention also provides an apparatus comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors to cause the one or more processors to perform a local database reconstruction method provided in accordance with embodiments of the present invention.
In a third aspect, the present invention also provides a storage medium storing a computer program that causes a computer to execute the local database reconstruction method provided according to the embodiments of the present invention.
According to the local database reconstruction method, the local database reconstruction equipment and the local database reconstruction storage medium, which are provided by various embodiments of the invention, the version number of the local database is configured, whether the database version number is updated or not is detected, and if the database version number is updated, the transactions in the blocks are re-executed according to the sequence from low to high of the block height so as to reconstruct the local database, so that the database reconstruction efficiency is greatly improved. Furthermore, the invention can only reconstruct the data stored by a certain contract when the contract is updated, and does not process other contract data which is not updated, thereby performing targeted database updating and further reducing the time for reconstructing the database.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
fig. 1 is a flowchart of a local database reconstruction method according to an embodiment of the present invention.
FIG. 2 is a flow diagram of a preferred embodiment of the method of FIG. 1.
FIG. 3 is a flow chart of a preferred embodiment of the method of FIG. 1 or FIG. 2.
Fig. 4 is a schematic structural diagram of an apparatus according to an embodiment of the present invention.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the present invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
The invention provides a technical scheme for reconstructing a local database. In the invention, the block chain database comprises a local database and a state database, the state database stores the key information of the transaction, the update is realized through block chain consensus, and under the condition that the block height is normally increased, the state database stores the actual result of the current version and generally does not need to be reconstructed; the local database is used for storing and recording auxiliary information of some transactions and is used for assisting a user to inquire required information, such as assets of the user, purchase order time, order hanging time and other related information of the user, wherein the information can be directly recorded in the local database without being known; the local database stores the data information in a key-value form, and the database is queried by providing a key value during query.
In the technical scheme of the invention, the version number is configured for the configuration file of the local database, when the version of the block chain is upgraded (such as a certain function is optimized or a certain function is added), the corresponding key value is updated or increased, and when the key is updated or increased, the version number of the configuration file is updated.
Fig. 1 is a flowchart of a local database reconstruction method according to an embodiment of the present invention.
As shown in fig. 1, in this embodiment, the present invention provides a local database reconstruction method, including:
s11, detecting whether the version of the local database is updated:
if so, the transaction of all blocks on the first blockchain is re-executed in order of block height to reconstruct the local database.
Specifically, after the system is restarted, whether the current version number b of the configuration file and the version number a (having special key value record version number information in the database and not disappearing after restarting) stored in the local database are updated or not is detected, if yes, the version number a in the local database is updated to be the current version number b, the transaction key value information on the first block chain stored in the local database is deleted, the transactions of all the blocks on the first block chain are executed again according to the sequence of the block heights from low to high, and a plurality of auxiliary information generated after the transactions are executed are stored in the local database again.
Further, the version update of the local database may be that the version number of the configuration file is increased, or the version number is changed according to other defined manners, as long as the determination of the new version and the old version can be realized according to the node identification rule.
In further embodiments, whether the local database is rebuilt, i.e., whether transactions on the blockchain are to be re-executed to regenerate the local database, is not relevant to database code updates, and if the local database version is not changed, the system will not re-execute all blocks even if the code changes; even if the code is not changed, if the local database version is changed, the system will re-execute all blocks after restarting.
The embodiment realizes the independent updating of the local database by detecting whether the version of the local database is updated or not to reconstruct the local database, does not need to synchronize data from a network again from 0, does not need to update a state database, and greatly saves the time for reconstructing the database after the version is upgraded.
FIG. 2 is a flow diagram of a preferred embodiment of the method of FIG. 1. As shown in fig. 2, in a preferred embodiment, the method further comprises:
and S12, if interruption occurs in the process of executing each transaction, the system is restarted and then continues to execute each subsequent block from the height of the interrupted block.
Specifically, when the system re-executes the transaction in the block on the first blockchain, the height information of the block after executing a certain block transaction is stored in the local database, and if the execution process is interrupted due to some reason (such as network interruption, power failure, and the like), the system is restarted, and then the system will continue to execute the block transaction of the subsequent block height from the last block height stored in the local database until the block height recorded in the status database is reached.
FIG. 3 is a flow chart of a preferred embodiment of the method of FIG. 1 or FIG. 2. As shown in fig. 3, in a preferred embodiment, recalculating the transaction for the tile on the first blockchain further comprises:
s111, acquiring updated contract names in a local database;
recalculating transactions for blocks on the first blockchain to reconstruct the local database, comprising:
and S112, deleting a plurality of pieces of data information about the contract corresponding to the contract name and stored in the local database, and acquiring and executing block transaction related to the corresponding contract according to the contract name to reconstruct the local database.
Specifically, after the system is restarted, whether a contract is updated is judged when the version of the local database configuration file is updated is detected, if yes, the updated contract name is obtained, the related data of the contract corresponding to the contract name stored in the local database is deleted according to the contract name, then the transaction related to the contract is executed from the block with the block height of 0, and a plurality of executed transaction data are stored in the local database.
In the embodiment, only one or more local databases of the updated contracts are constructed, and other un-updated contract data is not processed, so that the speed of reconstructing the database is further increased.
Fig. 4 is a schematic structural diagram of an apparatus according to an embodiment of the present invention.
As shown in fig. 4, as another aspect, the present application also provides an apparatus 300 including one or more Central Processing Units (CPUs) 301 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)302 or a program loaded from a storage section 308 into a Random Access Memory (RAM) 303. In the RAM303, various programs and data necessary for the operation of the apparatus 300 are also stored. The CPU301, ROM302, and RAM303 are connected to each other via a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
The following components are connected to the I/O interface 305: an input portion 306 including a keyboard, a mouse, and the like; an output section 307 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 308 including a hard disk and the like; and a communication section 309 including a network interface card such as a LAN card, a modem, or the like. The communication section 309 performs communication processing via a network such as the internet. A drive 310 is also connected to the I/O interface 305 as needed. A removable medium 311 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 310 as necessary, so that a computer program read out therefrom is mounted into the storage section 308 as necessary.
In particular, according to an embodiment of the present disclosure, the local database reconstruction method described in any of the above embodiments may be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing a local database reconstruction method. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 309, and/or installed from the removable medium 311.
As yet another aspect, the present application also provides a computer-readable storage medium, which may be the computer-readable storage medium included in the apparatus of the above-described embodiment; or it may be a separate computer readable storage medium not incorporated into the device. The computer readable storage medium stores one or more programs for use by one or more processors in performing the local database reconstruction method described herein.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules described in the embodiments of the present application may be implemented by software or hardware. The described units or modules may also be provided in a processor, for example, each unit may be a software program provided in a computer or a mobile intelligent device, or may be a separately configured hardware device. Wherein the designation of a unit or module does not in some way constitute a limitation of the unit or module itself.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the present application. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.

Claims (6)

1. A method for reconstructing a local database, wherein the local database is used for storing auxiliary information of a transaction, the method comprising:
detecting whether the version of the local database is updated:
if yes, the transaction of the blocks on the first blockchain is executed again in the order of block height, and the local database is reconstructed according to the auxiliary information generated after the transaction is executed.
2. The method of claim 1, wherein re-executing the transaction of the blocks on the first blockchain in order of block height, and reconstructing the local database according to the auxiliary information generated after executing the transaction comprises:
deleting the local database, and acquiring and executing the transaction of each block according to the sequence of the block heights from low to high;
and storing a plurality of auxiliary information generated after the calculation and execution of each transaction in a local database to reconstruct the local database.
3. The method of claim 2, further comprising:
if interruption occurs in the process of executing each transaction, the system is restarted and then continuously executes each subsequent block from the height of the interrupted block.
4. A method according to claim 2 or 3, further comprising, prior to said re-executing the transaction of the tile on the first blockchain:
acquiring an updated contract name in a local database;
the re-executing the transaction of the block on the first blockchain and re-constructing the local database according to the auxiliary information generated after the transaction is executed includes:
deleting a plurality of auxiliary information about the contract corresponding to the contract name stored in a local database, acquiring and executing the transaction related to the corresponding contract according to the contract name, and reconstructing the local database according to the auxiliary information generated after executing the transaction related to the corresponding contract.
5. A computer device, the device comprising:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method recited in any of claims 1-4.
6. A storage medium storing a computer program, characterized in that the program, when executed by a processor, implements the method according to any one of claims 1-4.
CN201910157804.5A 2019-03-02 2019-03-02 Local database reconstruction method, device and storage medium Active CN109857727B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910157804.5A CN109857727B (en) 2019-03-02 2019-03-02 Local database reconstruction method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910157804.5A CN109857727B (en) 2019-03-02 2019-03-02 Local database reconstruction method, device and storage medium

Publications (2)

Publication Number Publication Date
CN109857727A CN109857727A (en) 2019-06-07
CN109857727B true CN109857727B (en) 2021-05-11

Family

ID=66899614

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910157804.5A Active CN109857727B (en) 2019-03-02 2019-03-02 Local database reconstruction method, device and storage medium

Country Status (1)

Country Link
CN (1) CN109857727B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110599321B (en) * 2019-09-20 2023-09-29 腾讯科技(深圳)有限公司 Tax data processing method and device, server and storage medium
CN113852698B (en) * 2021-12-01 2022-02-08 湖南宸瀚信息科技有限责任公司 Group-collaborative block chain data synchronization system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106776894A (en) * 2016-11-29 2017-05-31 北京众享比特科技有限公司 Log database system and synchronous method
CN108985757A (en) * 2017-11-27 2018-12-11 北京京东金融科技控股有限公司 Information processing method, apparatus and system, storage medium, electronic equipment
CN109086325A (en) * 2018-06-29 2018-12-25 阿里巴巴集团控股有限公司 Data processing method and device based on block chain
CN109408551A (en) * 2018-08-06 2019-03-01 杭州复杂美科技有限公司 Data query method and system, common recognition method and system, equipment and storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6535869B1 (en) * 1999-03-23 2003-03-18 International Business Machines Corporation Increasing efficiency of indexing random-access files composed of fixed-length data blocks by embedding a file index therein
US7149761B2 (en) * 2001-11-13 2006-12-12 Tadpole Technology Plc System and method for managing the synchronization of replicated version-managed databases
US10339014B2 (en) * 2016-09-28 2019-07-02 Mcafee, Llc Query optimized distributed ledger system
KR102348418B1 (en) * 2017-07-11 2022-01-07 스월즈, 인크. Methods and apparatus for efficiently implementing a distributed database within a network

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106776894A (en) * 2016-11-29 2017-05-31 北京众享比特科技有限公司 Log database system and synchronous method
CN108985757A (en) * 2017-11-27 2018-12-11 北京京东金融科技控股有限公司 Information processing method, apparatus and system, storage medium, electronic equipment
CN109086325A (en) * 2018-06-29 2018-12-25 阿里巴巴集团控股有限公司 Data processing method and device based on block chain
CN109408551A (en) * 2018-08-06 2019-03-01 杭州复杂美科技有限公司 Data query method and system, common recognition method and system, equipment and storage medium

Also Published As

Publication number Publication date
CN109857727A (en) 2019-06-07

Similar Documents

Publication Publication Date Title
CN109271450B (en) Database synchronization method, device, server and storage medium
CN109408551B (en) Data query method and system, consensus method and system, device and storage medium
CN109359222B (en) Data storage method and system, equipment and storage medium
US8775386B2 (en) Device and method for generating copy of database
AU2013327062B2 (en) Creating validated database snapshots for provisioning virtual databases
RU2417426C2 (en) Database fragment cloning and management
US8671085B2 (en) Consistent database recovery across constituent segments
US20120158795A1 (en) Entity triggers for materialized view maintenance
US9020916B2 (en) Database server apparatus, method for updating database, and recording medium for database update program
WO2016041481A1 (en) Statement based migration for adaptively building and updating column store database from row store database based on query demands using disparate database systems
KR20150125012A (en) Managing operations on stored data units
US10303785B2 (en) Optimizing online schema processing for busy database objects
US20200364240A1 (en) Method for data synchronization in a data analysis system
CN107665219B (en) Log management method and device
CN109857727B (en) Local database reconstruction method, device and storage medium
CN106970856B (en) Data management system and method for backing up, recovering and mounting data
KR20150125010A (en) Managing operations on stored data units
CN110795447A (en) Data processing method, data processing system, electronic device, and medium
CN113760846A (en) Data processing method and device
CN109614411B (en) Data storage method, device and storage medium
US10671592B2 (en) Self-maintaining effective value range synopsis in presence of deletes in analytical databases
KR20150126667A (en) Managing operations on stored data units
US20220229821A1 (en) Data restoration using dynamic data structure altering
CN111796845B (en) Database upgrading method, state data query method, device and storage medium
JP2018085042A (en) Database management device, information processing system, database management method and database management program

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