CN112650629A - Block chain index data recovery method, device, equipment and computer storage medium - Google Patents

Block chain index data recovery method, device, equipment and computer storage medium Download PDF

Info

Publication number
CN112650629A
CN112650629A CN202011616175.7A CN202011616175A CN112650629A CN 112650629 A CN112650629 A CN 112650629A CN 202011616175 A CN202011616175 A CN 202011616175A CN 112650629 A CN112650629 A CN 112650629A
Authority
CN
China
Prior art keywords
index
database
data
index database
state
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.)
Pending
Application number
CN202011616175.7A
Other languages
Chinese (zh)
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 Qulian Technology Co Ltd
Original Assignee
Hangzhou Qulian 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 Qulian Technology Co Ltd filed Critical Hangzhou Qulian Technology Co Ltd
Priority to CN202011616175.7A priority Critical patent/CN112650629A/en
Publication of CN112650629A publication Critical patent/CN112650629A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1471Saving, restoring, recovering or retrying involving logging of persistent data for recovery
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2272Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/80Database-specific techniques

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a method, a device, equipment and a computer storage medium for recovering block chain index data; the method comprises the following steps: receiving a data operation request, and judging whether the running state of the index database is normal or not; if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database; when the index database is detected to recover normal service, the index database is adjusted to be in a synchronous state, and the data of the index database is recovered according to the operation log in the temporary database; when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state; when the index database is abnormal, automatic, accurate and perceptually-free recovery of index information in the index database is achieved.

Description

Block chain index data recovery method, device, equipment and computer storage medium
Technical Field
The present application relates to the field of blockchain technologies, and in particular, to a method, an apparatus, a device, and a computer storage medium for recovering blockchain index data.
Background
The blockchain data index is a service provided by a node for a client side to quickly retrieve a transaction related to certain service data, and is a key technology of a blockchain widely applied to a traceability scene, the blockchain data index depends on an index database, when a client side data query request is received, the index database can be queried to obtain index data, the blockchain ledger database is queried through O (1) query complexity according to the index data to obtain the transaction related to the service data, and quick response of the blockchain service transaction query is realized.
When a node enables a data index service related to business data, the node writes the index database. On one hand, the existing system has a certain mechanism to ensure atomicity of multi-database operation, that is, when one database operation has an error, the block writing is considered to be failed, and other databases which have been successfully operated are recovered to the previous state. The block data cannot be persisted, which means that the node cannot provide service normally. However, the failure of data insertion in the index database merely means that the node can no longer provide data index services related to the service data at this time, and should not affect the normal production blocks of the node and other basic services provided by the node. On the other hand, when the node starts the data index service related to the business data, the background database is used as an index database storage engine and is used as an independent process, when the node is down, the network cannot be connected or an unknown error occurs to cause insertion or deletion failure, if the block chain link points still provide the service normally at the moment, a new block chain data is generated according to the old block chain data during the abnormal period of the background database service possibly, and at the moment, the data of the index database lags behind the on-line block chain data; there may also be data rollback or data archiving of the node during the abnormal period of the background database service, and at this time, there will be dirty data in the index database.
Disclosure of Invention
The application provides a block chain index data recovery method, a block chain index data recovery device, block chain index data recovery equipment and a computer storage medium, and aims to solve the technical problems that when an existing block chain index database is in an abnormal state, a background database connected with the index database cannot respond to a data operation request, and the index database is easy to recover abnormally.
In one aspect, the present application provides a method for recovering block chain index data, where the method for recovering block chain index data includes the following steps:
receiving a data operation request, and judging whether the running state of the index database is normal or not;
if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the data of the index database according to an operation log in the temporary database;
and when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
In some embodiments of the present application, after receiving a data operation request and determining whether the running state of the index database is normal or not, the method includes:
if the index database is in a normal state, determining the type of the data operation request;
if the data operation request is a blockchain transaction query request, querying the index database, acquiring index data in the transaction query request, and querying corresponding transaction detail data from a blockchain account book according to the index data by using O (1) query complexity and outputting the data;
and if the data operation request is a block chain transaction recovery request, generating new data index information or deleting the data index information according to the transaction recovery request so as to recover the data of the index database.
In some embodiments of the present application, if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log in a preset temporary database, includes:
if the index database is in an abnormal state, judging whether the data operation request relates to restoring the index database;
if the data operation request does not relate to restoring the index database, returning an index database exception prompt;
and if the data operation request relates to restoring the index database, responding to the data operation request, acquiring an operation code and operation content associated with the data operation request, generating an operation log according to the operation code and the operation content, and storing the operation log to a preset temporary database.
In some embodiments of the present application, when it is detected that a background database connected to the index database recovers normal service, adjusting the index database to a synchronous state, and recovering data of the index database according to an operation log in the temporary database, includes:
when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state;
and querying the temporary database, and sequentially executing the operation logs according to the time sequence of the operation logs in the temporary database so as to recover the index data in the index database.
In some embodiments of the present application, the deleting the operation log in the temporary database and adjusting the index database to a normal state when the index data in the index database is recovered, includes:
when the index data in the index database is recovered, acquiring the recovered index data in the index database;
inquiring a block chain account book database according to the index data to obtain target data, and comparing the target data with index data items corresponding to the index database;
and if the target data is the same as the index data item data corresponding to the index database, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
In some embodiments of the present application, before receiving a data operation request and determining whether an operation state of an index database is normal or not, the method includes:
acquiring state information of a background database, and determining the state of the index database according to the state information;
and if the background database is in an abnormal state, adjusting the index database to be in an abnormal state.
In some embodiments of the present application, after the operation log in the temporary database is deleted and the index database is adjusted to a normal state when the index data in the index database is recovered, the method includes:
counting the abnormal service frequency of a background database connected with the index database, and comparing the abnormal service frequency with a preset threshold value; and if the abnormal service frequency of the background database is higher than a preset threshold value, outputting prompt information.
In another aspect, the present application provides a device for recovering block chain index data, including:
the request receiving module is used for receiving the data operation request and judging whether the running state of the index database is normal or not;
the generating and storing module is used for responding to the data operation request if the index database is in an abnormal state, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
the data recovery module is used for adjusting the index database to be in a synchronous state when detecting that a background database connected with the index database recovers normal service, and recovering the data of the index database according to the operation log in the temporary database;
and the state adjusting module is used for deleting the operation log in the temporary database and adjusting the index database to be in a normal state when the index data in the index database is recovered.
In another aspect, the present application further provides a device for recovering blockchain index data, where the device for recovering blockchain index data includes:
one or more processors;
a memory; and
one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the method for blockchain index data recovery.
In another aspect, the present application further provides a computer storage medium, on which a computer program is stored, where the computer program is loaded by a processor to execute the steps in the method for recovering the block chain index data.
In the embodiment of the application, a data operation request is received, and whether the running state of the index database is normal or not is judged; if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database; when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the index database according to an operation log in the temporary database; when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state; according to the embodiment of the application, automatic recovery of the index database is realized. According to the embodiment of the application, when the index database is in an abnormal state, the data operation request can be responded, the operation log is generated according to the data operation request and is stored in the temporary database, and when the index database can be normally served, the index information in the index database is recovered according to the operation log, so that the index database is quickly recovered without sensing, and the problem of recovery errors of the index database is effectively avoided.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic view of a scenario of recovering block chain index data according to an embodiment of the present disclosure;
FIG. 2 is a flowchart illustrating an embodiment of a method for recovering chunk chain index data provided in the present application;
FIG. 3 is a flowchart illustrating an embodiment of a method for recovering block chain index data, in which an index database is in a normal state;
FIG. 4 is a flowchart illustrating an embodiment of index database detection in the method for recovering block chain index data provided in the embodiment of the present application;
fig. 5 is a schematic flowchart of an embodiment of a background database exception prompt in the block chain index data recovery method provided in the embodiment of the present application;
FIG. 6 is a block chain index data recovery apparatus according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of an embodiment of a device for recovering block chain index data provided in the embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any inventive step, are within the scope of the present invention.
In the description of the present invention, it is to be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", etc. indicate orientations or positional relationships based on those shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be considered as limiting the present invention. Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first", "second", may explicitly or implicitly include one or more of the described features. In the description of the present invention, "a plurality" means two or more unless specifically defined otherwise.
In this application, the word "exemplary" is used to mean "serving as an example, instance, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. The following description is presented to enable any person skilled in the art to make and use the invention. In the following description, details are set forth for the purpose of explanation. It will be apparent to one of ordinary skill in the art that the present invention may be practiced without these specific details. In other instances, well-known structures and processes are not shown in detail to avoid obscuring the description of the invention with unnecessary detail. Thus, the present invention is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.
Embodiments of the present application provide a method, an apparatus, a device, and a computer storage medium for recovering block chain index data, which are described in detail below.
The block chain index data recovery method in the embodiment of the invention is applied to a block chain index data recovery device, the block chain index data recovery device is arranged on block chain index data recovery equipment, and the block chain index data recovery equipment is provided with one or more processors, a memory and one or more application programs, wherein the one or more application programs are stored in the memory and are configured to be executed by the processor to realize the block chain index data recovery method; the blockchain index data recovery device may be a terminal, for example, a mobile phone or a tablet computer, and may also be a server or a service cluster formed by multiple servers.
As shown in fig. 1, fig. 1 is a schematic view of a scenario of recovering blockchain index data according to an embodiment of the present invention, where the scenario of recovering blockchain index data includes a blockchain index data recovery device 100 (a blockchain index data recovery apparatus is integrated in the blockchain index data recovery device 100), and the blockchain index data recovery device 100 operates a corresponding computer storage medium for recovering blockchain index data, so as to perform a step of recovering blockchain index data.
It should be understood that the device for recovering the blockchain index data in the scenario of recovering the blockchain index data shown in fig. 1, or the apparatus included in the device for recovering the blockchain index data, does not limit the embodiment of the present invention, that is, the number of devices and the type of devices included in the scenario of recovering the blockchain index data, or the number of devices and the type of devices included in each device do not affect the overall implementation of the technical solution in the embodiment of the present invention, and can be calculated as equivalent replacements or derivatives of the technical solution claimed in the embodiment of the present invention.
The block chain index data recovery apparatus 100 according to the embodiment of the present invention is mainly configured to:
receiving a data operation request, and judging whether the running state of the index database is normal or not;
if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the data of the index database according to an operation log in the temporary database;
and when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
In this embodiment of the present invention, the device 100 for recovering block chain index data may be an independent device for recovering block chain index data, or may be a network of devices for recovering block chain index data or a cluster of devices for recovering block chain index data, for example, the device 100 for recovering block chain index data described in this embodiment of the present invention includes, but is not limited to, a computer, a network host, a single device for recovering network block chain index data, a plurality of network sets of devices for recovering block chain index data, or a cloud device formed by a plurality of devices for recovering block chain index data. Wherein, the Cloud block chain index data recovery device is composed of a large number of computers based on Cloud Computing (Cloud Computing) or a network block chain index data recovery device.
Those skilled in the art can understand that the application environment shown in fig. 1 is only one application scenario related to the present embodiment, and does not constitute a limitation on the application scenario of the present embodiment, and other application environments may further include more or less blockchain index data recovery devices than those shown in fig. 1, or a network connection relationship of the blockchain index data recovery devices, for example, only 1 blockchain index data recovery device is shown in fig. 1, and it can be understood that the scenario of blockchain index data recovery may further include one or more other blockchain index data recovery devices, which is not limited herein; the block chain index data restoring apparatus 100 may further include a memory therein.
In addition, in the scene of recovering the block chain index data, the block chain index data recovery device 100 may be provided with a display device, or the block chain index data recovery device 100 is not provided with a display device in communication connection with an external display device 200, and the display device 200 is configured to output a result of executing the block chain index data recovery method in the block chain index data recovery device. The block chain index data recovery apparatus 100 may access the background database 300, and the background database 300 stores therein information related to the recovery of the block chain index data.
The background database can be in a local memory of the block chain index data recovery device, and can also be arranged at the cloud.
It should be noted that the schematic diagram of the scenario of recovering the blockchain index data shown in fig. 1 is only an example, and the scenario of recovering the blockchain index data described in the embodiment of the present invention is for more clearly illustrating the technical solution of the embodiment of the present invention, and does not form a limitation on the technical solution provided by the embodiment of the present invention.
Based on the above scenario of recovering the block chain index data, an embodiment of a method for recovering the block chain index data is provided.
Referring to fig. 2, fig. 2 is a flowchart illustrating an embodiment of a method for recovering block chain index data in the present application, where the method for recovering block chain index data includes steps 201 and 204:
and 201, receiving a data operation request, and judging whether the running state of the index database is normal or not.
In this embodiment, the block chain index data recovery method is applied to a block chain index data recovery device, which is also called a node device, and the block chain index data recovery device is in communication connection with an index database. The type of the device for recovering block chain index data in this embodiment is not specifically limited, for example, the device for recovering block chain index data may be a terminal or a server, and this embodiment is described by taking the terminal as an example.
The index database is a storage database of data index information in a block chain, the index database can be stored in a local storage of block chain index data recovery equipment, the index database can also be stored in a cloud end, the block chain index data recovery equipment accesses the cloud end to query the index database, the block chain index data recovery equipment acquires index data by querying the index database, and queries the block chain account book database according to the index data to execute data operation, namely, the block chain account book database and the index database have relevance, and the index database needs to be synchronously recovered when the block chain account book database is recovered.
The terminal receives a data operation request, wherein the data operation request can be a data operation request related to index database or block chain ledger database recovery, such as a transaction packing blocking request, a block chain ledger rollback request or a data archiving operation request; the data operation request may also be a data operation request that does not involve index database or block chain ledger database recovery, for example, a data query request, a triggering manner of the data operation request is not specifically limited, and the data operation request may be actively triggered by a user, for example, the user clicks a "transaction" button on a terminal display interface to actively trigger the data operation request; in addition, the data operation request may also be automatically triggered by the terminal, for example, the triggering condition of the data operation request preset in the terminal is: when data are packed; the terminal monitors the transaction state information of each platform of the block chain in real time, and the terminal detects a data operation request automatically triggered when data is packaged; for another example, the triggering conditions for the data operation request preset in the terminal are as follows: when the intelligent contract is called; the terminal detects the intelligent contract calling state in real time, and when the terminal detects the intelligent contract calling, the terminal automatically triggers a data operation request.
After the terminal receives the data operation request, the terminal queries the index database, and determines whether the index database is in a Normal state, that is, in this embodiment, the index database is set to be in three states, namely, a Normal state, an Abnormal state, and a synchronous state, and the three states of the index database can be mutually converted, specifically, in this embodiment, three state identification bits are defined for the index database, which are Normal, Abnormal, and synchronizing, respectively; wherein, Normal indicates that the index database is in a Normal state, and can normally perform read-write operation on the data of the index database; the Absnormal indicates that the index database is in an Abnormal state and cannot perform read-write operation on the data of the index database; syncing indicates that the index database is performing data synchronization, and blocks the write operation of the index database.
For example, before the terminal receives an API query request related to a data index from the client, the terminal will check the state of the index database at that time, and if the index database is in a Normal state at that time, continue to execute the process, otherwise, return a prompt that the data index service is unavailable; when the state of the index database is not Normal, the terminal can still operate normally and can receive transactions from the client, generate new blocks, and provide services except for data indexing to the outside, and if new data needs to be inserted into the index database or old data needs to be deleted in the processes, the terminal records an operation log of data insertion or data deletion in the temporary database, and specifically, the operation log comprises:
and 202, if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database.
If the index database is not in a normal state, that is, the index database is in an abnormal state or a synchronous state, the terminal generates an operation log corresponding to the data operation request, and the terminal stores the operation log in a preset temporary database to restore the index database according to the operation log in the temporary database, specifically, the method includes:
(1) if the index database is in an abnormal state, judging whether the data operation request relates to restoring the index database;
(2) if the data operation request does not relate to restoring the index database, returning an index database exception prompt;
(3) and if the data operation request relates to restoring the index database, responding to the data operation request, acquiring an operation code and operation content associated with the data operation request, generating an operation log according to the operation code and the operation content, and storing the operation log to a preset temporary database.
That is, if the index database is not in a normal state, the terminal judges whether the data operation request relates to restoring the index database; for example, 1, if the data operation request is a transaction packing blocking request, a block chain ledger rollback request, or a data archiving operation request, the index database corresponding to the data operation request needs to be restored; 2. if the data operation request is a query request, the index database corresponding to the data operation request does not need to be restored.
And if the data operation request does not relate to the recovery of the index database, the terminal returns an index database exception prompt. And if the data operation request relates to the recovery index database, the terminal responds to the data operation request, acquires an operation code and operation content associated with the data operation request, generates an operation log according to the operation code and the operation content, and stores the operation log in a preset temporary database.
That is, in this embodiment, a temporary database is pre-established, the temporary database uses a lightweight Key-Value type embedded database as a storage engine, and the Key structure is as follows: prefix + current timestamp, prefix is "timestamp-". The first byte of the Value structure is an operation code, and the following bytes have different operation contents according to different operation codes.
The operation content comprises the following steps: (1) insert operation: indicating that new data is to be inserted into the index database, this operation occurs when a node generates a new chunk, with Value format: 1-bit Insert opcode + 64-bit block number + byte data to be inserted; (2) DeleteRange operation: indicating that data for a block interval is to be deleted from the index database, this operation occurs when a node performs a block rollback or block archiving. The Value format is: 1-bit deleterrange opcode + 64-bit start block number + 64-bit end block number; (3) DropDatabase operation: indicating that all online data in the index database is to be deleted, the operation occurs when the node performs ledger replacement, and the Value format is: a 1-bit opcode.
In this embodiment, a temporary database is preset to be established first, and an operation log corresponding to the data operation request is stored in the temporary database, so that when a background database connected to the index database is recovered to be normal, the terminal performs index data recovery according to the operation log stored in the temporary database, specifically:
and 203, when detecting that the background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the data of the index database according to the operation log in the temporary database.
The terminal detects the service state of a background database connected with the index database in real time, when the background database of the index database is recovered to be normal, the terminal adjusts the index database to be in a synchronous state, and the terminal recovers the index database according to an operation log in the temporary database; specifically, the method comprises the following steps:
(1) when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state;
(2) and inquiring the temporary database, and sequentially executing the operation logs according to the time sequence of the operation logs in the temporary database so as to recover the index data in the index database.
In this embodiment, when the background database of the index database is recovered to be normal, the terminal recovers the index data according to the operation log in the temporary database, so that the phenomenon that the index database and the block chain account book data are not synchronized is avoided, and the condition that the index database and the block chain account book database are not unified when the background database is abnormal is avoided.
And 204, when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
When the index data in the index database is recovered, the terminal deletes the operation log in the temporary database, so that the condition that the temporary database resources accessed by the terminal are occupied is avoided, and meanwhile, the index database is adjusted to be in a normal state by the terminal, so that the index database can quickly respond to the data operation request.
In the process of executing the block chain index data recovery method by the terminal in this embodiment, the terminal detects the background database connected to the index database in real time to adjust the state of the index database, specifically:
(1) acquiring state information of a background database, and determining the state of the index database according to the state information;
(2) and if the background database is in an abnormal state, adjusting the index database to be in an abnormal state.
The terminal acquires state information of the background database, wherein the state information comprises network state information, access flow information, data recovery information and the like, and the terminal determines the state of the background database according to the state information; for example, if the network state in the state information is abnormal, the terminal determines that the background database is in an abnormal state, and if the background database is in the abnormal state, the terminal adjusts the index database to be in the abnormal state.
For the convenience of understanding of the user, the following examples are given in this embodiment: firstly, a terminal receives a data operation request and judges the state of an index database; if the index database is in the abstract, the terminal responds to the data operation request, generates an operation log corresponding to the data operation request and stores the operation log to a preset temporary database, and the terminal pings a background database server and checks whether the background database is communicated, and if the background database cannot be communicated within 30 seconds, the terminal continues to enter the next ping; if the operation logs are successfully applied to the index database, the operation logs are deleted from the temporary database. The execution and deletion of the operation log must ensure atomicity, namely if the execution of the operation log of the index database is successful and the deletion of the operation log of the temporary database is failed, the index database rolls back the operation of the operation log and returns an error; and if the execution of the operation log of the index database fails, directly returning an error without deleting the operation log of the temporary database. If the background database has unknown errors again in the synchronization process, which causes the failure of the index database to execute the operation log, the state of the index database is changed from synchronization to Abnormal, and the data recovery process is re-entered; and if the error is other errors, such as the error returned by the temporary database storage engine, directly exiting the data recovery process and reporting an exception. The index database state is changed from Syncing to Normal only after all oplogs in the temporary database have been synchronized to the index database.
In the embodiment, a data operation request is received, and whether the running state of the index database is normal or not is judged; if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database; when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the data of the index database according to an operation log in the temporary database; when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state; according to the embodiment of the application, automatic recovery of the index database is realized. According to the embodiment of the application, when the index database is in an abnormal state, the data operation request can be responded, the operation log is generated according to the data operation request and is stored in the temporary database, the index information in the index database is recovered according to the operation log, the index database is recovered quickly without sensing, and the problem of recovery errors of the index database is effectively avoided.
Referring to fig. 3, fig. 3 is a flowchart illustrating an embodiment of the index database in a normal state in the block chain index data recovery method provided in the embodiment of the present application.
In some embodiments of the present application, the method for restoring block chain index data, in which the index database is in a normal state, specifically includes steps 301-303:
301, if the index database is in a normal state, determining the type of the data operation request.
If the index database is in a normal state, the terminal determines the type of the data operation request so that the terminal responds according to the type of the data operation request, specifically:
302, if the data operation request is a blockchain transaction query request, querying the index database, obtaining index data in the transaction query request, querying corresponding transaction detail data from a blockchain account book with O (1) query complexity according to the index data, and outputting the transaction detail data.
If the data operation request is a transaction query request, the terminal queries an index database, acquires index data in the transaction query request, queries a block chain account database according to the index data, acquires transaction detail data and outputs the transaction detail data for a user to check; in the embodiment, when the index database is normal, the terminal queries the index database to quickly respond to the transaction query operation request.
303, if the data operation request is a block chain transaction recovery request, generating new data index information or deleting data index information according to the transaction recovery request, thereby recovering the data of the index database.
And if the data operation request is a block chain transaction recovery request, the terminal recovers the block chain account book data according to the transaction recovery request, and when the block chain account book database is recovered, the terminal generates new index data in the index database or deletes old index data. That is, when the data operation request is a data rollback request, a data archiving request, or a transaction packing blocking request, the terminal determines that the data operation request is a transaction recovery request, and the terminal recovers the block chain ledger database and the index database according to the transaction recovery request.
Referring to fig. 4, fig. 4 is a flowchart illustrating an embodiment of index database detection in the block chain index data recovery method provided in the embodiment of the present application.
In some embodiments of the present application, the method for recovering block chain index data includes the following steps 401 and 403:
401, when the index data in the index database is recovered, acquiring the index data recovered in the index database.
In this embodiment, when the index data in the index database is recovered, the terminal obtains the index data recovered in the index database, and the terminal verifies the recovered index data to determine that the index database is recovered correctly, specifically:
and 402, inquiring a block chain account book database according to the index data to obtain target data, and comparing the target data with index data items corresponding to the index database.
The terminal inquires the block chain account book database according to the index data to obtain target data, compares the target data with index data items corresponding to the index database to determine whether the recovered index data are consistent with the data in the block chain account book, deletes the recovered index data in the index database if the target data are different from the index data items corresponding to the index database, and performs secondary recovery according to an operation log in the temporary database.
And 403, if the target data is the same as the index data item data corresponding to the index database, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
If the target data is the same as the index data item data corresponding to the index database, the terminal deletes the operation log in the temporary database and adjusts the index database to be in a normal state.
Referring to fig. 5, fig. 5 is a flowchart illustrating an embodiment of a background database exception prompt in the block chain index data recovery method provided in the embodiment of the present application.
In some embodiments of the present application, the method for recovering block chain index data performs authority authentication on a single user, specifically, includes steps 501 and 502:
and 501, counting the service abnormal frequency of a background database connected with the index database, and comparing the service abnormal frequency with a preset threshold value.
The method includes the steps that a terminal counts the abnormal service frequency of a background database connected with an index database, namely, the terminal counts the abnormal times of the background database connected with the index database at a unit time interval (the unit time interval can be set according to a specific scene, for example, the unit time interval is set to be one week), obtains the abnormal frequency of the background database, compares the abnormal service frequency of the terminal with a preset threshold (the preset threshold refers to a preset abnormal processing critical value, for example, the preset threshold is set to be 3 times), and does not process the abnormal service frequency of the background database if the abnormal service frequency of the background database is not higher than the preset threshold.
502, if the abnormal service frequency of the background database is higher than a preset threshold, outputting a prompt message.
If the abnormal service frequency of the background database is higher than the preset threshold value, the terminal outputs prompt information so that the user can maintain the background database corresponding to the index database according to the prompt information and frequent database abnormality is avoided.
Fig. 6 is a schematic structural diagram of an embodiment of a device for recovering block chain index data, as shown in fig. 6.
In order to better implement the method for recovering block chain index data in the embodiment of the present application, on the basis of the method for recovering block chain index data, an embodiment of the present application further provides a device for recovering block chain index data, where the device for recovering block chain index data includes:
a request receiving module 601, configured to receive a data operation request and determine whether an operation state of an index database is normal;
a generating and storing module 602, configured to respond to the data operation request if the index database is in an abnormal state, generate an operation log corresponding to the data operation request, and store the operation log in a preset temporary database;
a data recovery module 603, configured to, when it is detected that a background database connected to the index database recovers normal service, adjust the index database to a synchronous state, and recover data of the index database according to an operation log in the temporary database;
the state adjusting module 604 is configured to delete the operation log in the temporary database when the index data in the index database is completely restored, and adjust the index database to a normal state.
In some embodiments of the present application, the apparatus for recovering block chain index data includes:
if the index database is in a normal state, determining the type of the data operation request;
if the data operation request is a blockchain transaction query request, querying the index database, acquiring index data in the transaction query request, and querying corresponding transaction detail data from a blockchain account book according to the index data by using O (1) query complexity and outputting the data;
and if the data operation request is a block chain transaction recovery request, generating new data index information or deleting the data index information according to the transaction recovery request so as to recover the data of the index database.
In some embodiments of the present application, the generation saving module 602 includes:
if the index database is in an abnormal state, judging whether the data operation request relates to restoring the index database;
if the data operation request does not relate to restoring the index database, returning an index database exception prompt;
and if the data operation request relates to restoring the index database, responding to the data operation request, acquiring an operation code and operation content associated with the data operation request, generating an operation log according to the operation code and the operation content, and storing the operation log to a preset temporary database.
In some embodiments of the present application, the data recovery module 603 includes:
when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state;
and querying the temporary database, and sequentially executing the operation logs according to the time sequence of the operation logs in the temporary database so as to recover the index data in the index database.
In some embodiments of the present application, the state adjustment module 604 includes:
when the index data in the index database is recovered, acquiring the recovered index data in the index database;
inquiring a block chain account book database according to the index data to obtain target data, and comparing the target data with index data items corresponding to the index database;
and if the target data is the same as the index data item data corresponding to the index database, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
In some embodiments of the present application, the apparatus for recovering block chain index data includes:
acquiring state information of a background database, and determining the state of the index database according to the state information;
and if the background database is in an abnormal state, adjusting the index database to be in an abnormal state.
In some embodiments of the present application, the apparatus for recovering block chain index data includes:
counting the abnormal service frequency of a background database connected with the index database, and comparing the abnormal service frequency with a preset threshold value;
and if the abnormal service frequency of the background database is higher than a preset threshold value, outputting prompt information.
The block chain index data recovery device in the embodiment of the application receives a data operation request and judges whether the running state of an index database is normal or not; if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database; when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the index database according to an operation log in the temporary database; when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state; according to the embodiment of the application, automatic recovery of the index database is realized. According to the embodiment of the application, when the index database is in an abnormal state, the data operation request can be responded, the operation log is generated according to the data operation request and is stored in the temporary database, the index information in the index database is recovered according to the operation log, the index database is recovered quickly without sensing, and the problem of recovery errors of the index database is effectively avoided.
An embodiment of the present invention further provides a device for recovering chunk chain index data, as shown in fig. 7, fig. 7 is a schematic structural diagram of an embodiment of the device for recovering chunk chain index data provided in this embodiment of the present application.
The device for recovering block chain index data integrates any one of the devices for recovering block chain index data provided by the embodiments of the present invention, and the device for recovering block chain index data includes:
one or more processors;
a memory; and
one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to perform the steps of the method for recovering blockchain index data as described in any of the above embodiments of the method for recovering blockchain index data.
Specifically, the method comprises the following steps: the blockchain index data recovery apparatus may include components such as a processor 701 of one or more processing cores, memory 702 of one or more computer storage media, a power supply 703, and an input unit 704. Those skilled in the art will appreciate that the configuration of the blockchain index data recovery device shown in fig. 7 does not constitute a limitation of the blockchain index data recovery device, and may include more or fewer components than those shown, or combine some components, or a different arrangement of components. Wherein:
the processor 701 is a control center of the device for recovering the blockchain index data, connects the respective parts of the entire device for recovering the blockchain index data by using various interfaces and lines, and performs various functions and processes of the device for recovering the blockchain index data by running or executing software programs and/or modules stored in the memory 702 and calling the data stored in the memory 702, thereby performing overall monitoring of the device for recovering the blockchain index data. Optionally, processor 701 may include one or more processing cores; preferably, the processor 701 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 701.
The memory 702 may be used to store software programs and modules, and the processor 701 executes various functional applications and data processing by operating the software programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to the use of the block chain index data restoring apparatus, and the like. Further, the memory 702 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.
The device for recovering the block chain index data further comprises a power supply 703 for supplying power to each component, preferably, the power supply 703 can be logically connected with the processor 701 through a power management system, so that functions of managing charging, discharging, power consumption management and the like can be realized through the power management system. The power supply 703 may also include any component including one or more of a dc or ac power source, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and the like.
The block chain index data recovery apparatus may further include an input unit 704, and the input unit 704 may be used to receive input numeric or character information and generate a keyboard, mouse, joystick, optical or trackball signal input related to user setting and function control.
Although not shown, the block chain index data restoring apparatus may further include a display unit and the like, which are not described in detail herein. Specifically, in this embodiment, the processor 701 in the device for recovering block chain index data loads an executable file corresponding to one or more processes of an application program into the memory 702 according to the following instructions, and the processor 701 runs the application program stored in the memory 702, thereby implementing various functions as follows:
receiving a data operation request, and judging whether the running state of the index database is normal or not;
if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the index database according to an operation log in the temporary database;
and when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer storage medium and loaded and executed by a processor.
To this end, an embodiment of the present invention provides a computer storage medium, which may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like. The computer program is loaded by a processor to execute the steps of any block chain index data recovery method provided by the embodiment of the invention. For example, the computer program may be loaded by a processor to perform the steps of:
receiving a data operation request, and judging whether the running state of the index database is normal or not;
if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
when detecting that a background database connected with the index database recovers normal service, adjusting the index database to be in a synchronous state, and recovering the index database according to an operation log in the temporary database;
and when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and parts that are not described in detail in a certain embodiment may refer to the above detailed descriptions of other embodiments, and are not described herein again.
In a specific implementation, each unit or structure may be implemented as an independent entity, or may be combined arbitrarily to be implemented as one or several entities, and the specific implementation of each unit or structure may refer to the foregoing method embodiment, which is not described herein again.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
The above detailed description is provided for a block chain index data recovery method provided in the embodiments of the present application, and specific examples are applied in the present application to explain the principles and embodiments of the present invention, and the description of the above embodiments is only used to help understanding the method and the core idea of the present invention; meanwhile, for those skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (10)

1. A method for recovering blockchain index data, the method comprising:
receiving a data operation request, and judging whether the running state of the index database is normal or not;
if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
when the index database is detected to recover normal service, the index database is adjusted to be in a synchronous state, and the data of the index database is recovered according to the operation log in the temporary database;
and when the index data in the index database is recovered, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
2. The method according to claim 1, wherein after receiving the data operation request and determining whether the index database is normal or not, the method comprises:
if the index database is in a normal state, determining the type of the data operation request;
if the data operation request is a blockchain transaction query request, querying the index database, acquiring index data in the transaction query request, and querying from a blockchain account book according to the index data by using O (1) query complexity to obtain and output corresponding transaction detail data;
and if the data operation request is a block chain transaction recovery request, generating new data index information or deleting the data index information according to the transaction recovery request so as to recover the data of the index database.
3. The method for recovering block chain index data according to claim 1, wherein if the index database is in an abnormal state, responding to the data operation request, generating an operation log corresponding to the data operation request, and storing the operation log in a preset temporary database, includes:
if the index database is in an abnormal state, judging whether the data operation request relates to restoring the index database;
if the data operation request does not relate to restoring the index database, returning an index database exception prompt;
and if the data operation request relates to restoring the index database, responding to the data operation request, acquiring an operation code and operation content associated with the data operation request, generating an operation log according to the operation code and the operation content, and storing the operation log to a preset temporary database.
4. The method for recovering block chain index data according to claim 1, wherein the adjusting the index database to a synchronized state and recovering the data of the index database according to the operation log in the temporary database when detecting that the index database recovers normal service comprises:
when detecting that a background database accessed by the index database recovers normal service, adjusting the index database to be in a synchronous state;
and querying the temporary database, and sequentially executing the operation logs according to the time sequence of the operation logs in the temporary database so as to recover the index data in the index database.
5. The method for recovering block chain index data according to claim 1, wherein deleting the operation log in the temporary database and adjusting the index database to a normal state when the recovery of the index data in the index database is completed comprises:
when the index data in the index database is recovered, acquiring the recovered index data in the index database;
inquiring a block chain account book database according to the index data to obtain target data, and comparing the target data with index data items corresponding to the index database;
and if the target data is the same as the index data item data corresponding to the index database, deleting the operation log in the temporary database, and adjusting the index database to be in a normal state.
6. The method according to claim 1, wherein before receiving the data operation request and determining whether the index database is normal or not, the method comprises:
acquiring state information of a background database, and determining the state of the index database according to the state information;
and if the background database is in an abnormal state, adjusting the index database to be in an abnormal state.
7. The method for recovering data of a blockchain index according to any one of claims 1 to 6, wherein after deleting the operation log in the temporary database and adjusting the index database to a normal state when the recovery of the index data in the index database is completed, the method comprises:
counting the abnormal service frequency of a background database accessed by the index database, and comparing the abnormal service frequency with a preset threshold value;
and if the abnormal service frequency of the background database is higher than a preset threshold value, outputting prompt information.
8. A blockchain index data recovery apparatus, comprising:
the request receiving module is used for receiving the data operation request and judging whether the running state of the index database is normal or not;
the generating and storing module is used for responding to the data operation request if the index database is in an abnormal state, generating an operation log corresponding to the data operation request, and storing the operation log to a preset temporary database;
the data recovery module is used for adjusting the index database to be in a synchronous state when detecting that the background database accessed by the index database recovers normal service, and recovering the data of the index database according to the operation log in the temporary database;
and the state adjusting module is used for deleting the operation log in the temporary database and adjusting the index database to be in a normal state when the index data in the index database is recovered.
9. A blockchain index data recovery apparatus, characterized in that the blockchain index data recovery apparatus comprises:
one or more processors;
a memory; and
one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the method of blockchain index data recovery of any of claims 1 to 7.
10. A computer storage medium having a computer program stored thereon, the computer program being loaded by a processor to perform the steps in the method for recovering block chain index data according to any one of claims 1 to 7.
CN202011616175.7A 2020-12-30 2020-12-30 Block chain index data recovery method, device, equipment and computer storage medium Pending CN112650629A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011616175.7A CN112650629A (en) 2020-12-30 2020-12-30 Block chain index data recovery method, device, equipment and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011616175.7A CN112650629A (en) 2020-12-30 2020-12-30 Block chain index data recovery method, device, equipment and computer storage medium

Publications (1)

Publication Number Publication Date
CN112650629A true CN112650629A (en) 2021-04-13

Family

ID=75364403

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011616175.7A Pending CN112650629A (en) 2020-12-30 2020-12-30 Block chain index data recovery method, device, equipment and computer storage medium

Country Status (1)

Country Link
CN (1) CN112650629A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114780642A (en) * 2022-05-20 2022-07-22 北京链探科技有限公司 Block chain data processing method and device and electronic equipment
CN116010430A (en) * 2023-03-24 2023-04-25 杭州趣链科技有限公司 Data recovery method, database system, computer device, and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114780642A (en) * 2022-05-20 2022-07-22 北京链探科技有限公司 Block chain data processing method and device and electronic equipment
CN114780642B (en) * 2022-05-20 2022-08-26 北京链探科技有限公司 Block chain data processing method and device and electronic equipment
CN116010430A (en) * 2023-03-24 2023-04-25 杭州趣链科技有限公司 Data recovery method, database system, computer device, and storage medium
CN116010430B (en) * 2023-03-24 2023-06-20 杭州趣链科技有限公司 Data recovery method, database system, computer device, and storage medium

Similar Documents

Publication Publication Date Title
US11379461B2 (en) Multi-master architectures for distributed databases
WO2017177941A1 (en) Active/standby database switching method and apparatus
WO2019154394A1 (en) Distributed database cluster system, data synchronization method and storage medium
US7653668B1 (en) Fault tolerant multi-stage data replication with relaxed coherency guarantees
US7440977B2 (en) Recovery method using extendible hashing-based cluster logs in shared-nothing spatial database cluster
CN112131237B (en) Data synchronization method, device, equipment and computer readable medium
WO2021226905A1 (en) Data storage method and system, and storage medium
CN111049928B (en) Data synchronization method, system, electronic device and computer readable storage medium
CN108829787B (en) Metadata distributed system
CN105069152B (en) data processing method and device
CN112039970B (en) Distributed business lock service method, server, system and storage medium
CN112650629A (en) Block chain index data recovery method, device, equipment and computer storage medium
CN113360456B (en) Data archiving method, device, equipment and storage medium
US20210165573A1 (en) Managing Replication State for Deleted Objects
WO2018010501A1 (en) Global transaction identifier (gtid) synchronization method, apparatus and system, and storage medium
US11003550B2 (en) Methods and systems of operating a database management system DBMS in a strong consistency mode
US9330153B2 (en) System, method, and computer readable medium that coordinates between devices using exchange of log files
CN111787113B (en) Node fault processing method and device, storage medium and electronic equipment
US20180121531A1 (en) Data Updating Method, Device, and Related System
EP3896571B1 (en) Data backup method, apparatus and system
US10970177B2 (en) Methods and systems of managing consistency and availability tradeoffs in a real-time operational DBMS
CN114328749A (en) Business data processing method and device and computer readable storage medium
WO2021082925A1 (en) Transaction processing method and apparatus
CN113326251A (en) Data management method, system, device and storage medium
CN110928945B (en) Data processing method and device for database and data processing system

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