CN115048457A - Processing method and device for state data based on block chain and storage medium - Google Patents

Processing method and device for state data based on block chain and storage medium Download PDF

Info

Publication number
CN115048457A
CN115048457A CN202210648649.9A CN202210648649A CN115048457A CN 115048457 A CN115048457 A CN 115048457A CN 202210648649 A CN202210648649 A CN 202210648649A CN 115048457 A CN115048457 A CN 115048457A
Authority
CN
China
Prior art keywords
state data
block number
queue
target
task
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
CN202210648649.9A
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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202210648649.9A priority Critical patent/CN115048457A/en
Publication of CN115048457A publication Critical patent/CN115048457A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/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
    • 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/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Accounting & Taxation (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Finance (AREA)
  • Computing Systems (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a processing method and device of state data based on a block chain and a storage medium. The application relates to the technical field of block chains, and the method comprises the following steps: acquiring a data processing task through a target node in a block chain; when the data processing task is a state data writing task, storing state data to be written into a state database of the target node, and adding a block number corresponding to the state data to be written into a first queue of the target node; when the data processing task is a state data reading task, determining a block number corresponding to state data of a current version of a block chain to obtain a target block number, and judging whether the target block number exists in a first queue of a target node or not; and reading the state data corresponding to the target block number from the state database of the target node under the condition that the target block number exists in the first queue. By the method and the device, the problem of low state data reading and writing efficiency in the related technology is solved.

Description

Processing method, device and storage medium for state data based on block chain
Technical Field
The present application relates to the field of blockchain technologies, and in particular, to a method and an apparatus for processing state data based on a blockchain, and a storage medium.
Background
When a block chain creates or modifies a block, the update of state data is triggered, and in the related art, only the state data of the latest version is recorded in the block chain state database when the state data is updated. That is, each time a block is executed at a block node to update state data in the state database, the state data of the latest version overwrites the state data of the historical version.
After the state data are recorded in the state database of the block chain, the state data can be read and written from the state database, because the operation of writing the state data can change the state data, if the state data are read or written at the same time, the problem that the read state data are inconsistent with the state data currently stored in the state database can occur, in order to solve the problem, a lock synchronization technology is adopted in the related technology, namely, in order to ensure that each transaction of the block chain is simulated and executed, the read state data are consistent, and after a transaction simulator is obtained by a block chain node, a read lock is added to the state database; at the same time, when the block is executed by the block chain node to write the state data, the state database is added with a write lock.
However, the lock synchronization technology enables the state database to be locked for a long time, reading state data and submitting state data cannot be executed in parallel, the reading and writing efficiency of the state data of the block chain is reduced, and the reading and writing efficiency of the state data is reduced particularly obviously when a large number of transactions are executed concurrently.
Aiming at the problem of low state data read-write efficiency in the related technology, no effective solution is provided at present.
Disclosure of Invention
The application provides a processing method and device of state data based on a block chain and a storage medium, which are used for solving the problem of low read-write efficiency of the state data in the related technology.
According to one aspect of the application, a processing method of state data based on a block chain is provided. The method comprises the following steps: acquiring a data processing task through a target node in a block chain; when the data processing task is a state data writing task, storing state data to be written into a state database of a target node, and adding a block number corresponding to the state data to be written into a first queue of the target node, wherein the block number is a number corresponding to a block triggering updating of the state data; when the data processing task is a state data reading task, determining a block number corresponding to state data of a current version of a block chain to obtain a target block number, and judging whether the target block number exists in a first queue of a target node or not; and reading the state data corresponding to the target block number from the state database of the target node under the condition that the target block number exists in the first queue.
Optionally, adding the block number corresponding to the status data to be written to the first queue of the target node includes: determining the initial reference times of the block numbers corresponding to the state data to be written, wherein the initial reference times are used for indicating that the state data corresponding to the block numbers are not referred by the state data reading task; and combining the initial reference times and the block numbers into a snapshot, and storing the snapshot at the tail of the first queue.
Optionally, after determining whether the target block number exists in the first queue of the target node, the method further includes: under the condition that the target block number does not exist in the first queue, determining the initial reference times of the target block number, wherein the initial reference times are used for indicating that the state data corresponding to the target block number is not referred by the state data reading task; and combining the reference times and the target block number into a snapshot, and storing the snapshot at the tail of the first queue.
Optionally, before reading the status data corresponding to the target block number from the status database of the target node, the method further includes: adjusting the initial reference times of the snapshot where the target block number is located to obtain first reference times, wherein the first reference times are used for indicating that state data corresponding to the snapshot are referred by a state data reading task; after reading the state data corresponding to the target block number from the state database of the target node, the method further includes: and adjusting the first reference times to obtain second reference times, wherein the second reference times are used for indicating that the state data corresponding to the snapshot are completely referenced by the state data reading task.
Optionally, after the first number of times of reference is adjusted to obtain the second number of times of reference, the method further includes: judging whether the second reference times of the snapshot are equal to the initial reference times or not; in the event that the second number of references equals the initial number of references, the snapshot is moved from the first queue to the second queue.
Optionally, after moving the snapshot from the first queue to the second queue, the method further comprises: determining the block number of the snapshot in the second queue to obtain a failure block number; and deleting the snapshots in the second queue, and deleting the state data corresponding to the number of the failed block from the state database.
Optionally, the status data reading task is triggered by the transaction task, and after the status data corresponding to the target block number is read from the status database of the target node, the method further includes: executing the transaction task according to the state data corresponding to the target block number to obtain an execution result; and creating a state data writing task according to the execution result.
According to another aspect of the present application, there is provided a processing apparatus for processing state data based on a blockchain. The device includes: the acquisition unit is used for acquiring a data processing task through a target node in a block chain; the first data processing unit is used for storing the state data to be written into a state database of the target node and adding a block number corresponding to the state data to be written into a first queue of the target node when the data processing task is a state data writing task, wherein the block number is a number corresponding to a block triggering updating of the state data; the second data processing unit is used for determining a block number corresponding to the state data of the current version of the block chain when the data processing task is a state data reading task, obtaining a target block number, and judging whether the target block number exists in the first queue of the target node or not; and the reading unit is used for reading the state data corresponding to the target block number from the state database of the target node under the condition that the target block number exists in the first queue.
According to another aspect of the embodiments of the present invention, there is also provided a computer storage medium for storing a program, where the program, when executed, controls an apparatus in which the computer storage medium is located to execute a processing method based on state data of a block chain.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including one or more processors and a memory; the memory has stored therein computer readable instructions, and the processor is configured to execute the computer readable instructions, wherein the computer readable instructions are executed to perform a processing method based on state data of the blockchain.
Through the application, the following steps are adopted: acquiring a data processing task through a target node in a block chain; when the data processing task is a status data writing task, storing status data to be written into a status database of the target node, and adding a block number corresponding to the status data to be written into a first queue of the target node, wherein the block number is a number corresponding to a block triggering updating of the status data; when the data processing task is a state data reading task, determining a block number corresponding to state data of a current version of a block chain to obtain a target block number, and judging whether the target block number exists in a first queue of a target node or not; under the condition that the target block number exists in the first queue, the state data corresponding to the target block number is read from the state database of the target node, and the problem of low state data reading and writing efficiency in the related technology is solved. By keeping the historical version of the state data, when the block chain simultaneously carries out the read-write operation of the state data, the state data of the corresponding version is read, the write-in of the state data is not influenced, and the effect of improving the read-write efficiency of the state data is further achieved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this application, illustrate embodiments of the application and, together with the description, serve to explain the application and are not intended to limit the application. In the drawings:
fig. 1 is a first flowchart of a processing method for block chain-based status data according to an embodiment of the present application;
fig. 2 is a second flowchart of a processing method for block chain-based status data according to an embodiment of the present application;
fig. 3 is a schematic diagram of a processing apparatus for processing state data based on a block chain according to an embodiment of the present application;
fig. 4 is a schematic diagram of an electronic device provided according to an embodiment of the present application.
Detailed Description
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.
In order to make the technical solutions better understood by those skilled in the art, 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 partial embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It should be understood that the data so used may be interchanged under appropriate circumstances such that embodiments of the application described herein may be used. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be noted that, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for presentation, analyzed data, etc.) referred to in the present disclosure are information and data authorized by the user or sufficiently authorized by each party.
For convenience of description, some terms or expressions referred to in the embodiments of the present application are explained below:
and (3) transaction simulation execution: and in the block chain endorsement stage, the Peer node performs transaction simulation execution, and the transaction simulation execution needs to acquire a transaction simulator. When the transaction simulator simulates and executes the transaction, the transaction result is not really written into the state database, but the results obtained by checking, adding and deleting the transaction are put into a read-write set. The read-write set is committed to the state database only when the Peer node executes the block.
According to an embodiment of the application, a processing method of state data based on a block chain is provided.
Fig. 1 is a first flowchart of a processing method for state data based on a block chain according to an embodiment of the present application. As shown in fig. 1, the method comprises the steps of:
and step S102, acquiring a data processing task through a target node in the block chain.
Specifically, the target node is a Peer node on the blockchain, and the data processing task includes a status data writing task and a status data reading task.
Step S104, when the data processing task is a status data writing task, storing the status data to be written into a status database of the target node, and adding a block number corresponding to the status data to be written into a first queue of the target node, wherein the block number is a number corresponding to a block triggering updating of the status data.
Specifically, the data writing task is a task of updating state data when the Peer node executes a block, the state data to be written refers to the state data of the latest version obtained from the executed block, the state database is a database storing the state data of the target node, the block number corresponding to the state data to be written is the block number of the executed block, the first queue is a snapshot queue stored on the target node, and when the state data to be written is stored in the state database, the block number corresponding to the state data to be written is added to the first queue, so that the block number can be obtained from the first queue in the following process, and the corresponding state data can be indexed from the state database.
For example, table 1 is a specific case of the status data stored in the status database of the target node, and as shown in table 1, Key is a primary Key of the status data in the status database, the status data in table 1 are all status data with a primary Key of 1, the value of the corresponding status data when the block number of the executed block is 1, the value of the corresponding status data when the block number of the executed block is 2 is 10, the value of the corresponding status data when the block number of the executed block is 3 is 100, and when the status data is newly added to the status database, the old data is not overwritten with the new data, but the latest version of the status data is written into the database.
TABLE 1
Figure BDA0003687036340000051
Step S106, when the data processing task is a status data reading task, determining a block number corresponding to the status data of the current version of the block chain, obtaining a target block number, and judging whether the target block number exists in the first queue of the target node.
Specifically, the state data reading task is a task of reading state data in a state database on a Peer node when the Peer node performs transaction simulation in a block chain endorsement stage, and a target block number is the state data of the latest version in the state database of the Peer node, that is, the state data with the largest block number.
In step S108, when the target block number exists in the first queue, the status data corresponding to the target block number is read from the status database of the target node.
Specifically, under the condition that the state data corresponding to the target block number is stored in the state database, the target block number may not be added to the first queue, so that whether the target block number exists in the first queue or not needs to be judged before the state data is read, and under the condition that the target block number is read, the corresponding state data is obtained, so that the efficiency of obtaining the state data is improved compared with the mode that the state data is directly inquired from the state database.
According to the processing method based on the state data of the block chain, the data processing task is obtained through the target node in the block chain; when the data processing task is a state data writing task, storing state data to be written into a state database of a target node, and adding a block number corresponding to the state data to be written into a first queue of the target node, wherein the block number is a number corresponding to a block triggering updating of the state data; when the data processing task is a state data reading task, determining a block number corresponding to state data of a current version of a block chain to obtain a target block number, and judging whether the target block number exists in a first queue of a target node or not; under the condition that the target block number exists in the first queue, the state data corresponding to the target block number is read from the state database of the target node, and the problem of low state data reading and writing efficiency in the related technology is solved. By keeping the historical version of the state data, when the block chain simultaneously carries out the read-write operation of the state data, the state data of the corresponding version is read, the write-in of the state data is not influenced, and the effect of improving the read-write efficiency of the state data is further achieved.
In order to store state data of different versions in a state database, optionally, in the method for processing state data based on a block chain provided in this embodiment of the present application, adding a block number corresponding to the state data to be written to a first queue of a target node includes: determining the initial reference times of the block numbers corresponding to the state data to be written, wherein the initial reference times are used for indicating that the state data corresponding to the block numbers are not referenced by the state data reading task; and combining the initial reference times and the block numbers into a snapshot, and storing the snapshot at the tail of the first queue.
Specifically, the initial reference number is 0, which represents that the state data to be written has not been read by the transaction simulation execution, and when the state data of each version is written into the state database, a snapshot is stored on the Peer node to the first queue, and an element data structure of the snapshot is defined as: block number, type numeric and reference count, type numeric. Each snapshot is stored at the end of the first queue as it is created. The storage position of the state data of each version is recorded by creating the snapshot, so that the state data of the required version can be quickly positioned when the state data is read, and the efficiency of reading the state data is improved.
Optionally, in the processing method of state data based on a block chain provided in this embodiment of the present application, after determining whether a target block number exists in a first queue of a target node, the method further includes: under the condition that the target block number does not exist in the first queue, determining the initial reference times of the target block number, wherein the initial reference times are used for indicating that the state data corresponding to the target block number is not referred by the state data reading task; and combining the reference times and the target block number into a snapshot, and storing the snapshot at the tail of the first queue.
Specifically, when reading the status data, a snapshot of the target block number may not be created yet, and at this time, a snapshot corresponding to the target block number needs to be created. By creating a new block number for the target block number without creating the snapshot, the state data corresponding to the target block number can be quickly positioned when the state data is read next time, so that the efficiency of reading the state data is improved.
Optionally, in the processing method for state data based on a block chain provided in the embodiment of the present application, before reading the state data corresponding to the target block number from the state database of the target node, the method further includes: adjusting the initial reference times of the snapshot where the target block number is located to obtain first reference times, wherein the first reference times are used for indicating that state data corresponding to the snapshot are referred by a state data reading task; after reading the state data corresponding to the target block number from the state database of the target node, the method further includes: and adjusting the first reference times to obtain second reference times, wherein the second reference times are used for indicating that the state data corresponding to the snapshot are completely referenced by the state data reading task.
Specifically, the first reference number refers to the number of references obtained by adjusting the initial reference number 0 corresponding to the snapshot, the reference number of the snapshot is increased once every time the snapshot is called for each transaction, the second reference number refers to the number of references obtained by adjusting the first reference number corresponding to the snapshot, and the reference number of the snapshot is decreased once after each transaction for calling the snapshot is finished. The condition that the state data corresponding to the snapshot is called is represented by adjusting the reference times, so that the invalid state data can be obtained in time, and the invalid state data is cleaned to reduce the memory pressure of the state database.
For example, the type of the state data corresponding to the snapshot a is 1, the state data is 10, the block number is 2, the initial reference number of times of the snapshot a when being created is 0, when the Peer node performs X transaction simulation execution, the state data corresponding to the snapshot a is called, at this time, the first reference number of times of the snapshot a is 1, and after the X transaction simulation execution is finished, the second reference number of times of the snapshot a is 0.
Optionally, in the processing method of state data based on a blockchain provided in this embodiment of the present application, after adjusting the first number of times of reference and obtaining the second number of times of reference, the method further includes: judging whether the second reference times of the snapshot are equal to the initial reference times or not; in the event that the second number of references equals the initial number of references, the snapshot is moved from the first queue to the second queue.
Specifically, whether the reference frequency corresponding to the snapshot is 0 after the transaction simulation execution is finished is judged, and when the reference frequency is changed to 0, the state data corresponding to the snapshot is not called any more and belongs to invalid state data, so that the snapshot is moved to a second queue, the second queue is a snapshot to-be-destroyed queue, and the queue is used for marking state data which can be cleaned. And marking the state data which can be cleaned by moving the invalid state data to the snapshot queue to be destroyed, so as to prepare for saving the storage space of the state data database.
After the second queue is obtained, corresponding state data in the second queue may be cleared, and optionally, in the processing method for state data based on a block chain provided in this embodiment of the present application, after the snapshot is moved from the first queue to the second queue, the method further includes: determining the block number of the snapshot in the second queue to obtain a failure block number; and deleting the snapshots in the second queue, and deleting the state data corresponding to the number of the failed block from the state database.
Specifically, the block number of the snapshot in the snapshot to-be-destroyed queue is the invalid block number, and the state data corresponding to the invalid block number is not read, so that the state data corresponding to the invalid block number is deleted from the state database, and the snapshot in the snapshot to-be-destroyed queue is also deleted. And the state database is cleaned by deleting the snapshots in the snapshot to-be-destroyed queue and the state data corresponding to the invalid block number, so that the storage space of the state database is saved.
Optionally, in the processing method for state data based on a block chain provided in an embodiment of the present application, the state data reading task is triggered by a transaction task, and after reading the state data corresponding to the target block number from the state database of the target node, the method further includes: executing the transaction task according to the state data corresponding to the target block number to obtain an execution result; and creating a state data writing task according to the execution result.
Specifically, after the state data is read, the transaction task is executed according to the state data, an execution result is obtained and stored in a cache of the Peer node, and when the execution result achieves consensus on each node of the block chain, a new state data write-in task is created according to the execution result in the cache. The task completes the version update of the state data by creating new state data.
According to another embodiment of the present application, a method for processing state data based on a block chain is provided.
Fig. 2 is a flowchart ii of a processing method based on state data of a block chain according to an embodiment of the present application. As shown in fig. 2, the method comprises the steps of:
in step S201, when the transaction simulation execution starts, a current block number (recorded as H) is obtained, the block number H is recorded in the block number snapshot queue, and a snapshot object corresponding to the block number H is recorded by using a pointer, and a reference count of a snapshot corresponding to the block number H is 1.
Step S202, in the transaction simulation execution process, acquiring status data during the transaction simulation execution, and querying a value of the status data of the specified version by using a GetState (version) method, where the version value is a block number H. The GetState (key, version) method is to query the status database for status data with the block number less than or equal to the version, which has the largest block number.
In step S203, when the transaction simulation is finished, the reference count of the block number snapshot object pointed by the transaction is decremented by 1. If the reference count is not 0, the processing is not continued; if the reference count is 0, the block number is added to the end of the block number to destroy queue.
In step S204, the historical version of the status data is recorded in the status database, and the version is the block number of the updated status data.
Step S205, establishing a cleaning thread without reference state data version, taking the block number to be destroyed from the block number to be destroyed queue at regular time, and quitting deleting under the condition that the state data only has one version; under the condition that the state data has a plurality of versions, if the version of the state data is greater than the number of the block to be destroyed, deleting the state data of which all the versions are less than or equal to the number of the block to be destroyed in the state database; and if the version of the state data does not exist, deleting the state data of which the version is smaller than the number of the block to be destroyed in the state database.
Compared with the original method for synchronizing the concurrent reading and writing of the state data through the lock, the method for processing the state data based on the block chain can remove the locking of the time length of the read-write state data and improve the concurrent reading and writing efficiency of the block chain state data.
It should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer-executable instructions and that, although a logical order is illustrated in the flowcharts, in some cases, the steps illustrated or described may be performed in an order different than presented herein.
The embodiment of the present application further provides a processing apparatus based on state data of a block chain, and it should be noted that the processing apparatus based on state data of a block chain according to the embodiment of the present application may be used to execute the processing method for state data based on a block chain provided in the embodiment of the present application. The following describes a processing apparatus based on state data of a block chain according to an embodiment of the present application.
Fig. 3 is a schematic diagram of a processing apparatus based on state data of a blockchain according to an embodiment of the present application. As shown in fig. 3, the apparatus includes:
an obtaining unit 301, configured to obtain a data processing task through a target node in a block chain;
the first data processing unit 302 is configured to, when the data processing task is a status data writing task, store the status data to be written into a status database of the target node, and add a block number corresponding to the status data to be written into a first queue of the target node, where the block number is a number corresponding to a block that triggers updating of the status data;
a second data processing unit 303, configured to determine, when the data processing task is a status data reading task, a block number corresponding to status data of a current version of the block chain, obtain a target block number, and determine whether a target block number exists in a first queue of a target node;
a reading unit 304, configured to, in a case that the target block number exists in the first queue, read status data corresponding to the target block number from a status database of the target node.
According to the processing device for state data based on a block chain provided by the embodiment of the application, a data processing task is acquired through a target node in the block chain by an acquisition unit 301; the first data processing unit 302, when the data processing task is a status data writing task, stores the status data to be written into a status database of the target node, and adds a block number corresponding to the status data to be written into a first queue of the target node, where the block number is a number corresponding to a block that triggers updating of the status data; the second data processing unit 303, when the data processing task is a status data reading task, determines a block number corresponding to the status data of the current version of the block chain to obtain a target block number, and determines whether the target block number exists in the first queue of the target node; the reading unit 304 reads the state data corresponding to the target block number from the state database of the target node under the condition that the target block number exists in the first queue, so as to solve the problem of low read-write efficiency of the state data in the related art.
Optionally, in the processing apparatus based on state data of a block chain provided in this embodiment of the present application, the first data processing unit 302 includes: the first determining module is used for determining the initial reference times of the block numbers corresponding to the state data to be written, wherein the initial reference times are used for indicating that the state data corresponding to the block numbers are not referred by the state data reading task; and the first storage module is used for combining the initial reference times and the block numbers into a snapshot and storing the snapshot at the tail of the first queue.
Optionally, in the processing apparatus based on state data of a block chain provided in this embodiment of the present application, the second data processing unit 303 includes: the second determining module is used for determining the initial reference times of the target block number under the condition that the target block number does not exist in the first queue, wherein the initial reference times are used for indicating that the state data corresponding to the target block number is not referred by the state data reading task; and the second storage module is used for combining the reference times and the target block number into a snapshot and storing the snapshot at the tail of the first queue.
Optionally, in the apparatus for processing state data based on a block chain provided in this embodiment of the present application, the apparatus further includes: the first adjusting unit is used for adjusting the initial reference times in the snapshot where the target block number is located to obtain first reference times, wherein the first reference times are used for indicating that the state data corresponding to the snapshot are referred by the state data reading task; the device also includes: and the second adjusting unit is used for adjusting the first reference times to obtain second reference times, wherein the second reference times are used for indicating that the state data corresponding to the snapshot is completely referenced by the state data reading task.
Optionally, in the apparatus for processing state data based on a block chain provided in this embodiment of the present application, the apparatus further includes: a judging unit, configured to judge whether the second reference number of times of the snapshot is equal to the initial reference number of times; and the moving unit is used for moving the snapshot from the first queue to the second queue under the condition that the second reference times is equal to the initial reference times.
Optionally, in the apparatus for processing state data based on a block chain provided in this embodiment of the present application, the apparatus further includes: a failure block determining unit, configured to determine a block number of the snapshot in the second queue to obtain a failure block number; and the deleting unit is used for deleting the snapshot in the second queue and deleting the state data corresponding to the invalid block number from the state database.
Optionally, in the apparatus for processing state data based on a block chain provided in this embodiment of the present application, the apparatus further includes: the acquisition unit is used for executing the transaction task according to the state data corresponding to the target block number to obtain an execution result; and the creating unit is used for creating the state data writing task according to the execution result.
The above processing device based on state data of a block chain includes a processor and a memory, the above acquiring unit 301, the first data processing unit 302, the second data processing unit 303, the reading unit 304, and the like are all stored in the memory as program units, and the processor executes the above program units stored in the memory to implement corresponding functions.
The processor comprises a kernel, and the kernel calls the corresponding program unit from the memory. One or more kernels can be set, and the read-write efficiency of the state data is improved by adjusting kernel parameters.
The memory may include volatile memory in a computer readable medium, Random Access Memory (RAM) and/or nonvolatile memory such as Read Only Memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
The embodiment of the application also provides a computer storage medium, wherein the computer storage medium is used for storing the program, and the program controls the device where the computer storage medium is located to execute the processing method based on the state data of the block chain when running.
As shown in fig. 4, an electronic device 401 includes a processor, a memory, and a program stored in the memory and executable on the processor, where the processor executes the program to implement the following steps: processing of state data based on block chains. The device herein may be a server, a PC, a PAD, a mobile phone, etc.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or apparatus that comprises the element.
The above are merely examples of the present application and are not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (10)

1. A processing method of state data based on a block chain is characterized by comprising the following steps:
acquiring a data processing task through a target node in a block chain;
when the data processing task is a state data writing task, storing state data to be written into a state database of the target node, and adding a block number corresponding to the state data to be written into a first queue of the target node, wherein the block number is a number corresponding to a block triggering updating of the state data;
when the data processing task is a state data reading task, determining a block number corresponding to the state data of the current version of the block chain to obtain a target block number, and judging whether the target block number exists in a first queue of the target node;
and reading the state data corresponding to the target block number from the state database of the target node under the condition that the target block number exists in the first queue.
2. The method of claim 1, wherein adding the block number corresponding to the status data to be written to the first queue of the target node comprises:
determining the initial reference times of the block number corresponding to the state data to be written, wherein the initial reference times are used for indicating that the state data corresponding to the block number is not referred by the state data reading task;
and combining the initial reference times and the block numbers into a snapshot, and storing the snapshot at the tail of the first queue.
3. The method of claim 1, wherein after determining whether the target block number exists in the first queue of the target node, the method further comprises:
determining the initial reference times of the target block number under the condition that the target block number does not exist in the first queue, wherein the initial reference times are used for indicating that the state data corresponding to the target block number is not referred by the state data reading task;
and combining the reference times and the target block number into a snapshot, and storing the snapshot at the tail of the first queue.
4. The method of claim 1, wherein before reading the status data corresponding to the target block number from the status database of the target node, the method further comprises:
adjusting the initial reference times in the snapshot where the target block number is located to obtain first reference times, wherein the first reference times are used for indicating that the state data corresponding to the snapshot is referred to by the state data reading task;
after reading the status data corresponding to the target block number from the status database of the target node, the method further comprises:
and adjusting the first reference times to obtain second reference times, wherein the second reference times are used for indicating that the state data corresponding to the snapshot is completely referenced by the state data reading task.
5. The method of claim 4, wherein after adjusting the first number of references to obtain a second number of references, the method further comprises:
judging whether the second reference times of the snapshot are equal to the initial reference times or not;
moving the snapshot from the first queue to a second queue if the second number of references equals the initial number of references.
6. The method of claim 5, wherein after moving the snapshot from the first queue to a second queue, the method further comprises:
determining the block number of the snapshot in the second queue to obtain a failure block number;
and deleting the snapshot in the second queue, and deleting the state data corresponding to the number of the failed block from the state database.
7. The method according to claim 1, wherein the status data reading task is triggered by a transaction task, and after the status data corresponding to the target block number is read from the status database of the target node, the method further comprises:
executing the transaction task according to the state data corresponding to the target block number to obtain an execution result;
and creating a state data writing task according to the execution result.
8. An apparatus for processing state data based on a blockchain, comprising:
the acquisition unit is used for acquiring a data processing task through a target node in a block chain;
the first data processing unit is used for storing state data to be written into a state database of the target node and adding a block number corresponding to the state data to be written into a first queue of the target node when the data processing task is a state data writing task, wherein the block number is a number corresponding to a block triggering updating of the state data;
the second data processing unit is used for determining a block number corresponding to the state data of the current version of the block chain when the data processing task is a state data reading task, obtaining a target block number, and judging whether the target block number exists in a first queue of the target node or not;
a reading unit, configured to read, when the target block number exists in the first queue, status data corresponding to the target block number from a status database of the target node.
9. A computer storage medium, characterized in that the computer storage medium is used for storing a program, wherein the program controls a device in which the computer storage medium is located to execute the processing method based on state data of a block chain according to any one of claims 1 to 7 when running.
10. An electronic device comprising one or more processors and memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of processing blockchain based state data of any one of claims 1 to 7.
CN202210648649.9A 2022-06-09 2022-06-09 Processing method and device for state data based on block chain and storage medium Pending CN115048457A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210648649.9A CN115048457A (en) 2022-06-09 2022-06-09 Processing method and device for state data based on block chain and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210648649.9A CN115048457A (en) 2022-06-09 2022-06-09 Processing method and device for state data based on block chain and storage medium

Publications (1)

Publication Number Publication Date
CN115048457A true CN115048457A (en) 2022-09-13

Family

ID=83161391

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210648649.9A Pending CN115048457A (en) 2022-06-09 2022-06-09 Processing method and device for state data based on block chain and storage medium

Country Status (1)

Country Link
CN (1) CN115048457A (en)

Similar Documents

Publication Publication Date Title
CN107391628B (en) Data synchronization method and device
CN110046029A (en) Data processing method and device applied to multi-level buffer in cluster
CN112084161B (en) Database-based data processing method and device and readable storage medium
CN109614055B (en) Snapshot creating method and device, electronic equipment and machine-readable storage medium
EP3089051B1 (en) Database rollback using wal
CN110704463A (en) Local caching method and device for common data, computer equipment and storage medium
CN112182010B (en) Dirty page refreshing method and device, storage medium and electronic equipment
CN111897493B (en) Storage space management method and device, electronic equipment and storage medium
CN110019063B (en) Method for computing node data disaster recovery playback, terminal device and storage medium
CN114528127A (en) Data processing method and device, storage medium and electronic equipment
CN107609011B (en) Database record maintenance method and device
CN108271420B (en) Method for managing files, file system and server system
US20160259727A1 (en) Method, apparatus, and system for data caching
CN117472647A (en) Database transaction rollback method and device
CN115048457A (en) Processing method and device for state data based on block chain and storage medium
CN114924911B (en) Method, device, equipment and storage medium for backing up effective data of Windows operating system
CN116339626A (en) Data processing method, device, computer equipment and storage medium
US12093234B2 (en) Data processing method, apparatus, electronic device, and computer storage medium
WO2017058148A1 (en) Executing transactions based on success or failure of the transactions
CN115421856A (en) Data recovery method and device
CN114116676A (en) Data migration method and device, electronic equipment and computer readable storage medium
US10102052B2 (en) Dumping resources
CN113722623A (en) Data processing method and device, electronic equipment and storage medium
CN111858487A (en) Data updating method and device
CN112699129A (en) Data processing system, method and device

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