CN111444195B - Method, device and equipment for clearing indexes in block chain type account book - Google Patents

Method, device and equipment for clearing indexes in block chain type account book Download PDF

Info

Publication number
CN111444195B
CN111444195B CN202010537116.4A CN202010537116A CN111444195B CN 111444195 B CN111444195 B CN 111444195B CN 202010537116 A CN202010537116 A CN 202010537116A CN 111444195 B CN111444195 B CN 111444195B
Authority
CN
China
Prior art keywords
data
index
record
block
data block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010537116.4A
Other languages
Chinese (zh)
Other versions
CN111444195A (en
Inventor
俞本权
杨新颖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Original Assignee
Alipay Hangzhou Information 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 Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202010537116.4A priority Critical patent/CN111444195B/en
Publication of CN111444195A publication Critical patent/CN111444195A/en
Application granted granted Critical
Publication of CN111444195B publication Critical patent/CN111444195B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • 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
    • G06F16/2365Ensuring data consistency and integrity
    • 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
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures
    • 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)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Business, Economics & Management (AREA)
  • Software Systems (AREA)
  • Accounting & Taxation (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Finance (AREA)
  • Computer Hardware Design (AREA)
  • Health & Medical Sciences (AREA)
  • Development Economics (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Marketing (AREA)
  • Economics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method, a device and equipment for clearing indexes in a block chain type account book are disclosed. After the data blocks in the account book are cleared based on the instruction of the user, data records related to the business attribute of the user in the cleared data blocks are determined, and further position information of the related data records is cleared in the value of the index record, so that the consistency of the information in the account book and the index is maintained.

Description

Method, device and equipment for clearing indexes in block chain type account book
Technical Field
The embodiment of the specification relates to the technical field of information, in particular to a method, a device and equipment for clearing indexes in a block chain type account book.
Background
When a centralized database server provides services to the outside in a block-chain type account book, the account book records related data records required to be stored by related users. Meanwhile, based on the service requirement of the user, a corresponding index is created according to the service attribute of the user, so as to perform subsequent operations such as query and verification. When the account book of the user needs to be cleared, the information contained in the index of the account book needs to be cleared correspondingly at the moment so as to ensure the consistency of the information in the account book.
Disclosure of Invention
The embodiment of the application aims to provide a scheme for clearing related information in an index in a block chain type account book.
In order to solve the above technical problem, the embodiment of the present application is implemented as follows:
a clearing method of indexes in a block chain type account book is applied to a database server side for storing data through the block chain type account book, and comprises the following steps:
receiving a clearing instruction of a user, wherein the clearing instruction comprises a block height or a time point;
determining a data block needing to be cleared in the account book according to the block height or the time point, and clearing;
acquiring a service attribute corresponding to the user, and determining the position information of a data record containing the service attribute in the removed data block;
clearing the position information in the value of the index record;
the index is used for storing the corresponding relation between the service attribute and the position information, the service attribute is used as a main key in the index record of the index, the position information is used as a value, and the position information comprises the block height of the data block where the data record is located and the offset of the data block where the data record is located.
Correspondingly, an embodiment of the present specification further provides a device for clearing an index in a block chain type account book, which is applied to a database end that stores data through the block chain type account book, and includes:
the device comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving a clearing instruction of a user, and the clearing instruction comprises a block height or a time point;
the data block clearing module is used for determining and clearing the data blocks needing to be cleared in the account book according to the block height or the time point;
the determining module is used for acquiring the service attribute corresponding to the user and determining the position information of the data record containing the service attribute in the removed data block;
the position information clearing module is used for clearing the position information in the values of the index records;
the index is used for storing the corresponding relation between the service attribute and the position information, the service attribute is used as a main key in the index record of the index, the position information is used as a value, and the position information comprises the block height of the data block where the data record is located and the offset of the data block where the data record is located.
According to the scheme provided in the embodiment of the specification, after the data block in the ledger is cleared based on the instruction of the user, the data records related to the business attribute of the user in the cleared data block are determined, and further the position information of the related data records is cleared in the value of the index record, so that the consistency of the information in the ledger and the index is maintained.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of embodiments of the invention.
In addition, any one of the embodiments in the present specification is not required to achieve all of the effects described above.
Drawings
In order to more clearly illustrate the embodiments of the present specification or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments described in the embodiments of the present specification, and other drawings can be obtained by those skilled in the art according to the drawings.
FIG. 1 is a schematic diagram of a system architecture according to an embodiment of the present disclosure;
fig. 2 is a schematic flow chart of generating a blockchain ledger according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram of a block header of a data block provided in an embodiment of the present specification;
FIG. 4 is a flowchart illustrating a method for creating an index for a data record according to an embodiment of the present disclosure;
fig. 5 is a flowchart illustrating a method for clearing indexes in a block chain ledger according to an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of an apparatus for clearing indexes in a block chain type account book provided in an embodiment of the present specification;
fig. 7 is a schematic diagram of a device for configuring the method of the embodiments of the present description.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the embodiments of the present specification, the technical solutions in the embodiments of the present specification will be described in detail below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all the embodiments. All other embodiments that can be derived by one of ordinary skill in the art from the embodiments given herein are intended to be within the scope of protection.
First, a block chain type account book related to an embodiment of the present specification will be described. The database server is oriented to various organizations, and the organizations can record data generated between the organizations and third-party users (including other organizations or individuals) on the database server side for storage. As shown in fig. 1, fig. 1 is a schematic diagram of a system architecture according to an embodiment of the present disclosure. In this illustration, one enterprise may be oriented to multiple users, and each user may query the database service provider through its corresponding enterprise.
For example, the mechanism to which the database server is interfaced is a financial product company, and the data record may be a financial record of the individual user at the financial product company; alternatively, the mechanism of the interface may be a government department, wherein the data records are overhead details of public projects managed by the government department; or the mechanism for the database server to interface is a certain hospital, and the data records are medical records of patients; alternatively, the institution to which the database facilitator interfaces is a third party payment institution, the data records may be payment records of individual users through the institution, and so on.
At a centralized database server, a block chain type account book is generated as follows, as shown in fig. 2, fig. 2 is a schematic flow chart of generating a block chain type account book provided in an embodiment of the present specification, and the flow chart includes:
s201, receiving data records to be stored, and determining hash values of the data records, wherein the data records comprise service attributes.
As mentioned above, the data records to be stored here may be various consumption records of individual users of the client, or may be business results, intermediate states, operation records, and the like generated by the application server when executing the business logic based on instructions of the users. Specific business scenarios may include consumption records, audit logs, supply chains, government regulatory records, medical records, and the like.
In the embodiment of the present specification, the data record includes a service attribute, and in each mechanism that interfaces with the database server, the service attribute exists uniquely in the interfacing mechanism in general, and the service attribute is based on different service scenarios, and may include a user name, a user identification number, a driver license number, a mobile phone number, a unique item number, and the like.
For example, for a third-party payment mechanism, the data record is a consumption record of a user, and the service attribute at this time is a user identifier (including a mobile phone number, an identity card number, a user name, and the like), or a hash value obtained by performing a hash algorithm on the user identifier; alternatively, for a government agency, the data records are a running stream of costs for multiple common items, and the business attribute at this time may be a unique number for each item.
The business attributes may be stored in a designated field (e.g., a header or a trailer of the data record) in the data record, so that the business attributes of the data record may be conveniently retrieved by the database server and the user.
It should be noted that a plurality of data records may be included in the same account book. The service attributes of these data records are likely to be different. For example, when one account book is open to multiple users, the data records may originate from different users, and if the business attribute is the user identifier, it is easy to understand that different data records often include different user identifiers.
S203, when the preset blocking condition is reached, determining each data record to be written into the data block, and generating the Nth data block containing the hash value of the data block and the data record.
The preset blocking condition comprises the following steps: when the number of data records to be stored reaches a number threshold, for example, a new data block is generated every time one thousand data records are received, and one thousand data records are written into the block; alternatively, a time interval from the last blocking time reaches a time threshold, e.g., every 5 minutes, a new data block is generated, and the data records received within the 5 minutes are written into the block.
N here refers to a sequence number of the data block, that is, in the embodiment of the present specification, the data block is arranged in a block chain manner, and is arranged in sequence based on the blocking time, so that the data block has a strong timing characteristic. The block height of the data block is monotonically increased based on the sequence of the blocking time. The block height may be a sequence number, and at this time, the block height of the nth data block is N; the block height may also be generated in other ways.
When N =1, the data block at this time is the initial data block. The hash value and the block height of the initial data block are given based on a preset mode. For example, the initial data block does not contain data records, the hash value is any given hash value, and the block height blknum = 0; for another example, the trigger condition for generation of the initial data block is consistent with the trigger conditions of other data blocks, but the hash value of the initial data block is determined by hashing all of the contents in the initial data block.
When N >1, since the content and hash value of the previous data block have already been determined, at this time, the hash value of the current data block (nth data block) may be generated based on the hash value of the previous data block (i.e., nth-1 data block), for example, one possible way is to determine the hash value of each data record to be written into the nth data block, generate a mercker tree in the order of arrangement in the blocks, concatenate the root hash value of the mercker tree with the hash value of the previous data block, and generate the hash value of the current block again using the hash algorithm. For example, the hash value of the data block may be generated by concatenating the data records in the order of the data records in the block and hashing the concatenated data records to obtain the hash value of the entire data record, concatenating the hash value of the previous data block and the hash value of the entire data record, and performing a hash operation on the concatenated string.
After the user successfully uploads the data, the hash value of the corresponding data record and the hash value of the located data block can be obtained and stored, and integrity verification can be initiated based on the hash values. The specific verification method comprises the steps of recalculating the hash value of the data record and the hash value of the data block, and comparing the recalculated hash value with the locally stored hash value.
The data block generated in the above manner may include two parts, a block header and a block body. The block body can be used for storing plaintext of splicing data, or hash values of the splicing data, and the like; the block header may be used to store metadata about the data block, such as a version number of the ledger, a hash value of a previous data block, a root hash value of a merkel tree composed of the concatenated data in the data block itself, a hash value of the data block itself, a state array for recording an operated state of the concatenated data, and the like. As shown in fig. 3, fig. 3 is a schematic diagram of a block header of a data block according to an embodiment of the present disclosure.
By the above-mentioned manner of generating data blocks, each data block is determined by a hash value, and the hash value of the data block is determined by the content and the sequence of data records in the data block and the hash value of the previous data block. The user can initiate integrity verification based on the hash value of the data block at any time, and modification of any content in the data block (including modification of data record content or sequence in the data block) can cause inconsistency between the hash value of the data block calculated during verification and the hash value generated during data block generation, so that verification failure is caused, and centralized non-tampering is realized.
The integrity verification comprises integrity verification of a data block, namely, reconstructing a Mercker tree according to the hash values of data records in the data block, calculating a root hash value of the Mercker tree, recalculating the hash value of the data block according to the root hash value of the Mercker tree and the hash value of the previous data block, and performing consistency comparison with the hash value of the data block saved in advance.
The integrity verification may also include integrity verification for several consecutive data blocks, i.e. the hash value of a data block is recalculated from the root hash value of the merkel tree stored in the block header of the data block and the hash value of the previous data block and compared with the hash values of the previously stored data blocks.
Integrity verification may also include integrity verification of a certain data record. In the block chain type account book, when verifying the integrity of the data record, one way may be: and determining a data block where the data record is located, constructing a Mercker tree according to the data record in the data block, and calculating the root hash value of the current Mercker tree, so that consistency comparison can be performed with the root hash value of the Mercker tree stored in the block header, and if the root hash value is not consistent, the data record is tampered.
Another way may be that, when the user or the docking mechanism uploads the data record to the server, the user or the docking mechanism locally stores a backup copy of the data record or a hash value of the backup copy, so that the current hash value of the data record may be calculated and compared with the hash value of the backup copy for consistency, thereby implementing integrity verification.
By the above-mentioned manner of generating data blocks, each data block is determined by a hash value, and the hash value of the data block is determined by the content and the sequence of data records in the data block and the hash value of the previous data block. The user can initiate verification based on the hash value of the data block at any time, and modification of any content in the data block (including modification of data record content or sequence in the data block) can cause inconsistency between the hash value of the data block calculated during verification and the hash value generated during data block generation, so that verification failure is caused, and centralized non-tampering is realized.
As mentioned above, although these data records have strong timing characteristics when the account book is written, the data records are usually stored in a plurality of data blocks in a distributed manner for the user. For example, medical records for all patients in a hospital are sequentially uploaded in a time-generated order. For a certain user in a hospital, there may be multiple medical histories, and the time interval is relatively large, and if the hospital or the user needs to select the data record of the user from the account book, the user needs to query the account book according to the hash value of each medical record determined in the storage process, which is very inconvenient.
Based on this, embodiments of the present specification provide an index creating method for a data record, which creates an inverted index using a service attribute as a main key, facilitates service processing of a docking mechanism, and improves user experience. As shown in fig. 4, fig. 4 is a schematic flowchart of an index creating method for data records provided in an embodiment of the present specification, where the flowchart specifically includes the following steps:
s401, acquiring the service attribute in the data record.
In each mechanism for interfacing with the database server, the service attribute generally exists only in the interfacing mechanism, and the service attribute is based on different service scenes and can comprise a user name, a user identity card number, a driving license number, a mobile phone number, a unique item number and the like.
For example, for a third-party payment mechanism, the data record is a consumption record of a user, and the service attribute at this time is a user identifier (including a mobile phone number, an identity card number, a user name, and the like), or a hash value obtained by performing a hash algorithm on the user identifier; alternatively, for a government agency, the data records are a running stream of costs for multiple common items, and the business attribute at this time may be a unique number for each item.
The specific location and the obtaining mode of the service attribute may be pre-negotiated between the database server and the docking mechanism. For example, when the data record provided by the docking mechanism is a standard structured data record, the service attribute may be obtained by specifying an offset from the data record, or identifying a start position and an end position by a specific character; or, when the data records provided by the docking mechanism are unstructured data, the header containing the service attribute can be directly spliced at the head of each data record when the docking mechanism uploads the unstructured data, and the database server can directly acquire the service attribute of each data record from the header.
And S403, determining the position information of the data record in the account book, wherein the position information comprises the block height of the data block where the data record is located and the offset in the located data block.
As mentioned above, a block-chained ledger is composed of a plurality of data blocks, and a data block usually contains a plurality of data records. Therefore, in the embodiments of the present specification, the location information specifically refers to which data block in the ledger a data record is stored on, and at what location in the data block.
In the data blocks provided in the embodiments of the present specification, there are many ways to identify different data blocks, including hash values or block heights of the data blocks.
The hash value of the data block is obtained by performing hash calculation according to the hash value of the previous block and the data record of the data block, and can be used for uniquely and definitely identifying one data block. In the block chain type account book, the block height of the first data block is 0 generally, and 1 is added for each additional data block; alternatively, the blocking time of a data block may be converted to a large sequence of monotonically increasing integer data (typically 12 to 15 bits) as the block height of the data block. Thus, a data block typically has a definite block height.
For another example, in a determined data block to be written into the database, the ordering of the data records is also fixed, so that the sequence number of a data record in the data block is also clear, and when the length of the data record is a fixed unit, the sequence number can also be used to clear the position information of the data record in the data block where the data record is located. That is, the sequence number may be used to indicate the offset as well.
Meanwhile, since a plurality of data records are usually included in one data block, the data records in the data block can be identified by the address offset of each data record in the data block. Obviously, the address offset of each data record is not the same in the same data block.
Of course, since the specific format of the data block can be customized in the manner provided in the embodiments of the present specification (for example, the metadata information and remark information included in the block header of the data block, the form taken by the block height of the data block, and the like), the content of the location information may also be different in different formats, which does not form a limitation to the present solution.
S405, establishing a corresponding relation between the service attribute and the position information, and writing an index taking the service attribute as a main key and the position information as a value.
That is, the index is an inverted index. In this index, the primary key is a business attribute contained in the data record. The specific writing mode is that when the main key in the index does not contain the service attribute, an index record with the service attribute as the main key is created in the index table.
And when the primary key in the index contains the service attribute, writing the position information into the index record where the service attribute is located. Here, the writing is not overwriting, but position information is added to the value of the index record, and is present in parallel with other position information in the value of the index record.
As shown in table 1, table 1 is an exemplary index table provided in the embodiments of the present specification. The Key (primary Key) is a specific Value of the service attribute, each array of the Value part is a piece of position information, the front part of each array is high, the rear part of each array is a serial number of the data record in the data block, and a data record can be uniquely determined through the block height and the serial number. It is easy to understand that in the index table, a value corresponding to one Key may contain a plurality of location information.
Figure DEST_PATH_IMAGE001
According to the scheme provided by the embodiment of the specification, for the data record written into the account book, the service attribute of the data record and the storage position in the account book are determined, the corresponding relation between the service attribute and the storage position is established, the inverted index with the service attribute as the main key is created, the service details of the user do not need to be known, and the data record can be correspondingly counted and subsequently inquired and verified based on the service attribute from the index.
In the index table, since one service attribute may correspond to a plurality of location information (i.e., correspond to a plurality of data records), when the location information is written into the index, the location information may also be sequentially arranged according to the sequence of the data records in the account book, which is beneficial to query and verification of the user. The sequence of the data records in the ledger can be embodied by the time stamp of the data record written in the ledger (i.e. the blocking time stamp of the data block), and for the data records in the same data block, the sequence in the data block can be embodied.
The foregoing section describes a blockchain ledger and index. In practical application, as the data of the user is continuously increased, the storage space is more and more occupied, or some long-time historical data is no longer valuable to the user, the database server may also perform corresponding partial removal on the data blocks based on the user's requirement, for example, the removal on the first 100 data blocks in the ledger.
It should be noted first that the clearing does not correspond exactly to the deletion in the normal database. The clearing is to regard the initial data block of the account book to the specified data block as a whole, and remove the data block as a whole. This removal is also usually not a complete deletion, but rather a movement to a secondary storage location that can be retrieved, except that the partially cleared data blocks are no longer used in the corresponding querying, validation and accounting of the ledger.
Based on this, each time the account book is cleared, the index record in the index needs to be adjusted. As shown in fig. 5, fig. 5 is a schematic flowchart of a method for clearing indexes in a block chain type account book according to an embodiment of the present disclosure, where the method includes:
s501, receiving a clearing instruction of a user, wherein the clearing instruction comprises a block height or a time point.
For example, the user specifies the book ID and the block height, and the server determines that all data blocks before the block height are data blocks that need to be cleared based on the block height, and then clears the data blocks that are determined to need to be cleared, which may be implemented by a clear command PURGE (lgid, blkbound). Wherein "lgid" is the book ID, and "blkbound" is the block height.
For another example, the user specifies the book ID and the time point, the server determines the last generated data block before the time point based on the time point, determines the data blocks generated before the data block as the data blocks that need to be cleared, and then clears the data blocks that are determined to need to be cleared, which may be implemented by a clear command PURGE (lgid, 'timestamp'). Wherein "timestmp" is a time point.
Since the hash value of the first data block of the cleared data block chain is generated based on the hash value of the previous data block, a pseudo-initial data block needs to be generated at this time, and the hash value of the pseudo-initial data block is equal to the hash value of the determined last data block to be cleared, so that errors can be avoided when verification is performed later. The hash value of the last data block may be obtained by querying from a pre-established index, or may be obtained by sequentially calculating from the initial data block, or by querying from the data block.
And S503, determining the data block needing to be cleared in the account book according to the block height or the time point, and clearing.
Specifically, the data block high or before the time point may be determined as the data block that needs to be cleared. In practical applications, there are several embodiments as follows:
firstly, the self-increment natural number sequence in the account book is used as the block height of the data block, and at the moment, if the user inputs an instruction through the input of the block height parameter, the data block before the block height parameter which is not more than the block height parameter specified by the user can be directly determined as the data block which needs to be cleared;
secondly, the account book takes a self-increment natural number sequence as the block height of the data block, and simultaneously the block header contains a blocking timestamp, at this time, if the user includes a time point parameter through an input instruction, the blocking timestamp can be inquired in the block header, and the data block of which the blocking timestamp is before the time point parameter is determined as the data block needing to be cleared;
thirdly, the block timestamp in the account book is converted into the obtained integer data as the block height. For example, a blocking time of a data block is determined, then a symmetric encryption algorithm is adopted to convert the blocking time into integer data, the integer data is used as a block height of the data block, and the earlier the blocking time is, the smaller the integer data is.
Specifically, the integer here may be a large integer data, for example, a 13-bit large integer. Since the large integer is obtained based on time symmetric encryption, when the blocking time of the data block is needed, the blocking time can be obtained by the same symmetric decryption.
For example, after symmetric encryption, the blocking time "20 xx-01-1903: 14: 07.938576" may be converted into a large integer "1547838847938", since the integer data monotonically increases with time, "1547838847938" may be used as the block height of the data block, and if the blocking time of the next data block is "20 xx-01-1903: 16: 07.235125", it may be converted into another larger large integer "1547838848125" by using a preset symmetric encryption algorithm.
In this embodiment, if the user's erase command includes a time point, the time point parameter may be converted into the integer data in the same manner, and all data blocks before the block height does not exceed the converted integer data may be determined as data blocks to be erased.
And S505, acquiring the service attribute corresponding to the user, and determining the position information of the data record containing the service attribute in the removed data block.
The business attribute corresponding to the user may have been written into the configuration file of the account book in advance. As previously mentioned, a ledger may have multiple users available at the same time, for example, organizations a and B agree to write both accounts into the same ledger in the form of data records for later auditing. In the same ledger, organizations a and B may have different business attributes based on their business needs.
It should be noted that the uniqueness of the service attribute means that the same service attribute only has one corresponding physical interpretation, rather than the uniqueness of the service attribute in the same account book. For example, one identification number can only refer to one real person identity, but in a medical record book of a hospital, there may be a plurality of different identification numbers.
Meanwhile, even in a data block in an account book in which only one user has an operation right, not every data record will contain a business attribute. For example, when the account book is used for recording data records of buying/selling financial products and the like of a user through a third-party payment client, the business attributes may be names or numbers of one or several financial products which the user focuses on, and the other data records do not contain the business attributes.
Therefore, at this time, for the cleared data blocks, at least by traversing the data blocks, it can be determined which data records in the cleared data blocks contain the service attribute of the user. Further, the location information of the data record containing the service attribute in the removed data block can be determined. The specific content of the location information has been described above, and is not described herein again.
In another embodiment, it is not necessary to traverse the data block to obtain the location information, but only to query the index according to the service attribute, obtain the index record using the service attribute as the primary key, and filter from the values of the index record.
Specifically, based on the monotonicity of the block high, the block high that needs to be cleared may be determined according to the block high or a point in time included in the clear instruction. Since each position information in the index record value contains a block height, if the block height contained in one position information does not exceed the block height to be cleared, the position information can be known to be in the cleared data block.
Taking table 1 as an example, the user a inputs a PURGE command PURGE (lgid, 100), and PURGEs the first 100 data blocks in the account book, so as to find out that the service attribute of the user a in the account book is "0X 123456". At this time, the position information of the data record in the erased data block is "(2, 08), (2, 10)".
S507, clearing the position information in the value of the index record.
After the position information to be cleared is obtained, the index record corresponding to the service attribute can be determined, and the position information to be cleared is cleared from the value of the index record.
For the next example, the location information "(2, 08), (2, 10)" may be directly removed from the index record having "0X 123456" as the primary key in table 1. At this time, the position information included in the value is not completely cleared, and an index record with "0X 123456" as a primary key still exists.
In an embodiment, since the position information included in the value in the index record may be all cleared, if the value of the index record after clearing the position information is empty, the index record is deleted, so as to avoid the space occupied by the invalid record in the index and save resources.
According to the scheme provided in the embodiment of the specification, after the data block in the ledger is cleared based on the instruction of the user, the data records related to the business attribute of the user in the cleared data block are determined, and further the position information of the related data records is cleared in the value of the index record, so that the consistency of the information in the ledger and the index is maintained.
Correspondingly, an embodiment of the present specification further provides a clearing apparatus for an index in a block chain type account book, as shown in fig. 6, fig. 6 is a schematic structural diagram of the clearing apparatus for an index in a block chain type account book provided in the embodiment of the present specification, and the clearing apparatus includes:
a receiving module 601, configured to receive a clearing instruction of a user, where the clearing instruction includes a block height or a time point;
the data block clearing module 603 is configured to determine and clear the data block to be cleared in the account book according to the block height or the time point;
a determining module 605, configured to obtain a service attribute corresponding to the user, and determine location information of a data record containing the service attribute in the removed data block;
a position information clearing module 607 for clearing the position information in the value of the index record;
the index is used for storing the corresponding relation between the service attribute and the position information, the service attribute is used as a main key in the index record of the index, the position information is used as a value, and the position information comprises the block height of the data block where the data record is located and the offset of the data block where the data record is located.
Further, the apparatus further includes an index creating module 609, which obtains a service attribute in the data record; determining the position information of the data record in an account book; and establishing a corresponding relation between the service attribute and the position information, and writing an index which takes the service attribute as a main key and takes the position information as a value.
Further, the index creating module 609, when the primary key in the index does not include the service attribute, creates an index record in the index table, where the service attribute is used as the primary key and the position information is used as a value; and when the primary key in the index contains the service attribute, writing the position information into the value of the index record where the service attribute is located.
Further, the index creating module 609 determines a timestamp of the data record; and sequentially writing the position information of the data record into the value of the index record in the same index record according to the sequence of the time stamps.
Further, the determining module 605 determines the data block before the block high or the time point as the data block needing to be cleared.
Further, the location information clearing module 607 determines the maximum block height of the data block that needs to be cleared; determining an index record with the service attribute of the user as a main key; clearing, in the value of the index record, location information not exceeding the maximum block height.
Further, the location information clearing module 607 deletes the index record if the value of the index record after clearing the location information is null.
Further, the apparatus further includes a data block generation module 611, which receives data records to be stored, and determines a hash value of each data record, where the data records include a service attribute; when a preset blocking condition is reached, determining each data record to be written into the data block, and generating an nth data block containing the hash value of the data block and the data record, specifically comprising:
when N =1, the hash value and the block height of the initial data block are given based on a preset mode;
and when N is greater than 1, determining the hash value of the Nth data block according to the hash values of the data records to be written in the data block and the (N-1) th data block, and generating the Nth data block comprising the hash value of the Nth data block and the data records, wherein the block height of the data block is monotonically increased based on the sequence of the blocking time.
Further, in the apparatus, the preset blocking condition includes: the number of data records to be stored reaches a number threshold; alternatively, the time interval from the last chunking time reaches a time threshold.
Embodiments of the present specification also provide a computer device, which at least includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method for clearing the index shown in fig. 5 when executing the program.
Fig. 7 is a more specific hardware structure diagram of a computing device provided in an embodiment of the present specification, where the device may include: a processor 1010, a memory 1020, an input/output interface 1030, a communication interface 1040, and a bus 1050. Wherein the processor 1010, memory 1020, input/output interface 1030, and communication interface 1040 are communicatively coupled to each other within the device via bus 1050.
The processor 1010 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits, and is configured to execute related programs to implement the technical solutions provided in the embodiments of the present disclosure.
The Memory 1020 may be implemented in the form of a ROM (Read Only Memory), a RAM (Random access Memory), a static storage device, a dynamic storage device, or the like. The memory 1020 may store an operating system and other application programs, and when the technical solution provided by the embodiments of the present specification is implemented by software or firmware, the relevant program codes are stored in the memory 1020 and called to be executed by the processor 1010.
The input/output interface 1030 is used for connecting an input/output module to input and output information. The i/o module may be configured as a component in a device (not shown) or may be external to the device to provide a corresponding function. The input devices may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output devices may include a display, a speaker, a vibrator, an indicator light, etc.
The communication interface 1040 is used for connecting a communication module (not shown in the drawings) to implement communication interaction between the present apparatus and other apparatuses. The communication module can realize communication in a wired mode (such as USB, network cable and the like) and also can realize communication in a wireless mode (such as mobile network, WIFI, Bluetooth and the like).
Bus 1050 includes a path that transfers information between various components of the device, such as processor 1010, memory 1020, input/output interface 1030, and communication interface 1040.
It should be noted that although the above-mentioned device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040 and the bus 1050, in a specific implementation, the device may also include other components necessary for normal operation. In addition, those skilled in the art will appreciate that the above-described apparatus may also include only those components necessary to implement the embodiments of the present description, and not necessarily all of the components shown in the figures.
Embodiments of the present specification also provide a computer-readable storage medium on which a computer program is stored, where the computer program is executed by a processor to implement the method for clearing the index shown in fig. 5.
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 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.
From the above description of the embodiments, it is clear to those skilled in the art that the embodiments of the present disclosure can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the embodiments of the present specification may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments of the present specification.
The systems, methods, modules or units described in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the method embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to the partial description of the method embodiment for relevant points. The above-described method embodiments are merely illustrative, wherein the modules described as separate components may or may not be physically separate, and the functions of the modules may be implemented in one or more software and/or hardware when implementing the embodiments of the present specification. And part or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing is only a specific embodiment of the embodiments of the present disclosure, and it should be noted that, for those skilled in the art, a plurality of modifications and decorations can be made without departing from the principle of the embodiments of the present disclosure, and these modifications and decorations should also be regarded as the protection scope of the embodiments of the present disclosure.

Claims (17)

1. A clearing method of indexes in a block chain type account book is applied to a database server side for storing data through the block chain type account book, and comprises the following steps:
receiving a clearing instruction of a user, wherein the clearing instruction comprises a block height or a time point;
determining a data block needing to be cleared in the account book according to the block height or the time point, and clearing;
acquiring a service attribute corresponding to the user, and determining the position information of a data record containing the service attribute in the removed data block;
clearing the position information in the value of the index record;
the index is used for storing the corresponding relation between the service attribute and the position information, the service attribute is used as a main key in the index record of the index, the position information is used as a value, and the position information comprises the block height of a data block where the data record is located and the offset of the data block where the data record is located;
the index is pre-created by:
acquiring service attributes in the data records; determining the position information of the data record in an account book; and establishing a corresponding relation between the service attribute and the position information, and writing an index which takes the service attribute as a main key and takes the position information as a value.
2. The method of claim 1, writing an index with the service attribute as a primary key and the location information as a value, comprising:
when the primary key in the index does not contain the service attribute, creating an index record which takes the service attribute as the primary key and takes the position information as a value in the index;
and when the primary key in the index contains the service attribute, writing the position information into the value of the index record where the service attribute is located.
3. The method of claim 2, wherein writing the location information into the value of the index record in which the service attribute is located comprises:
determining a timestamp of the data record;
and sequentially writing the position information of the data record into the value of the index record in the same index record according to the sequence of the time stamps.
4. The method of claim 1, determining a data block in the ledger that needs to be cleared according to the block high or the time point, comprising:
and determining the data blocks which are high or are before the time point as the data blocks needing to be cleared.
5. The method of claim 1, clearing the location information in the value of the index record, comprising:
determining the maximum block height of the data block needing to be cleared;
determining an index record taking the service attribute of the user as a main key;
clearing, in the value of the index record, location information not exceeding the maximum block height.
6. The method of claim 1, clearing the location information in the value of the index record, comprising:
and if the value of the index record after the position information is cleared is empty, deleting the index record.
7. The method of claim 1, wherein at the centralized database server, the data blocks are pre-generated by:
receiving data records to be stored, and determining a hash value of each data record, wherein the data records comprise service attributes;
when a preset blocking condition is reached, determining each data record to be written into the data block, and generating an nth data block containing the hash value of the data block and the data record, specifically comprising:
when N =1, the hash value and the block height of the initial data block are given based on a preset mode;
and when N is greater than 1, determining the hash value of the Nth data block according to the hash values of the data records to be written in the data block and the (N-1) th data block, and generating the Nth data block comprising the hash value of the Nth data block and the data records, wherein the block height of the data block is monotonically increased based on the sequence of the blocking time.
8. The method of claim 7, the preset blocking condition comprising:
the number of data records to be stored reaches a number threshold; alternatively, the first and second electrodes may be,
the time interval from the last blocking instant reaches a time threshold.
9. The utility model provides a clearing device of index in block chain account book, is applied to the database end through block chain account book memory data, includes:
the device comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving a clearing instruction of a user, and the clearing instruction comprises a block height or a time point;
the data block clearing module is used for determining and clearing the data blocks needing to be cleared in the account book according to the block height or the time point;
the determining module is used for acquiring the service attribute corresponding to the user and determining the position information of the data record containing the service attribute in the removed data block;
the position information clearing module is used for clearing the position information in the values of the index records;
the index creation module is used for acquiring the service attribute in the data record; determining the position information of the data record in an account book; establishing a corresponding relation between the service attribute and the position information, and writing an index which takes the service attribute as a main key and takes the position information as a value;
the index is used for storing the corresponding relation between the service attribute and the position information, the service attribute is used as a main key in the index record of the index, the position information is used as a value, and the position information comprises the block height of the data block where the data record is located and the offset of the data block where the data record is located.
10. The apparatus according to claim 9, wherein the index creating module creates an index record with the service attribute as a primary key and the location information as a value in the index when the primary key in the index does not contain the service attribute; and when the primary key in the index contains the service attribute, writing the position information into the value of the index record where the service attribute is located.
11. The apparatus of claim 10, the index creation module to determine a timestamp of a data record; and sequentially writing the position information of the data record into the value of the index record in the same index record according to the sequence of the time stamps.
12. The apparatus of claim 9, the determination module to determine the data block that is high or prior to a point in time as the data block that needs to be cleared.
13. The apparatus of claim 9, the location information removal module to determine a maximum block height of a data block to be removed; determining an index record taking the service attribute of the user as a main key; clearing, in the value of the index record, location information not exceeding the maximum block height.
14. The apparatus according to claim 9, wherein the position information clearing module deletes the index record if the value of the index record after clearing the position information is null.
15. The apparatus according to claim 9, further comprising a data block generating module, configured to receive data records to be stored, and determine a hash value of each data record, where the data records include a service attribute; when a preset blocking condition is reached, determining each data record to be written into the data block, and generating an nth data block containing the hash value of the data block and the data record, specifically comprising:
when N =1, the hash value and the block height of the initial data block are given based on a preset mode;
and when N is greater than 1, determining the hash value of the Nth data block according to the hash values of the data records to be written in the data block and the (N-1) th data block, and generating the Nth data block comprising the hash value of the Nth data block and the data records, wherein the block height of the data block is monotonically increased based on the sequence of the blocking time.
16. The apparatus of claim 15, the preset blocking condition comprising: the number of data records to be stored reaches a number threshold; alternatively, the time interval from the last chunking time reaches a time threshold.
17. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any one of claims 1 to 8 when executing the program.
CN202010537116.4A 2020-06-12 2020-06-12 Method, device and equipment for clearing indexes in block chain type account book Active CN111444195B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010537116.4A CN111444195B (en) 2020-06-12 2020-06-12 Method, device and equipment for clearing indexes in block chain type account book

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010537116.4A CN111444195B (en) 2020-06-12 2020-06-12 Method, device and equipment for clearing indexes in block chain type account book

Publications (2)

Publication Number Publication Date
CN111444195A CN111444195A (en) 2020-07-24
CN111444195B true CN111444195B (en) 2020-10-30

Family

ID=71655545

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010537116.4A Active CN111444195B (en) 2020-06-12 2020-06-12 Method, device and equipment for clearing indexes in block chain type account book

Country Status (1)

Country Link
CN (1) CN111444195B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110399373A (en) * 2019-06-26 2019-11-01 杭州慧牧科技有限公司 A kind of block chain account book storage system, storage querying method and delet method
CN110704428A (en) * 2019-09-06 2020-01-17 深圳壹账通智能科技有限公司 Data indexing method and device for block chain, computer equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140297651A1 (en) * 2013-04-01 2014-10-02 Ori Software Development Ltd. Using hash table to retrieve leaf index blocks
US10915513B2 (en) * 2016-07-20 2021-02-09 International Business Machines Corporation Archival of data in a relational database management system using block level copy

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110399373A (en) * 2019-06-26 2019-11-01 杭州慧牧科技有限公司 A kind of block chain account book storage system, storage querying method and delet method
CN110704428A (en) * 2019-09-06 2020-01-17 深圳壹账通智能科技有限公司 Data indexing method and device for block chain, computer equipment and storage medium

Also Published As

Publication number Publication date
CN111444195A (en) 2020-07-24

Similar Documents

Publication Publication Date Title
CN110188096B (en) Index creating method, device and equipment for data record
CN110162662B (en) Verification method, device and equipment for data records in block chain type account book
CN109902086B (en) Index creation method, device and equipment
CN109902071B (en) Service log storage method, system, device and equipment
CN110162526B (en) Method, device and equipment for inquiring data records in block chain type account book
CN109951290B (en) Time service authentication method, device and equipment for chain type account book
CN110825737A (en) Index creation and data query method, device and equipment
CN111352935B (en) Index creating method, device and equipment in block chain type account book
CN110347679B (en) Data storage method, device and equipment based on receipt
CN111444196B (en) Method, device and equipment for generating Hash of global state in block chain type account book
CN110349019B (en) Verification method, device and equipment in block chain type account book
CN110837502B (en) Data storage method, device and equipment in block chain type account book
CN110061843B (en) Block height creating method, device and equipment in chain type account book
CN111046069B (en) Aggregation calculation method, device and equipment in block chain type account book
CN110008743B (en) Data attribute identification method, device and equipment in block chain type account book
CN110879687B (en) Data reading method, device and equipment based on disk storage
CN110716965B (en) Query method, device and equipment in block chain type account book
CN111046052B (en) Method, device and equipment for storing operation records in database
CN110059088B (en) Data attribute identification method, device and equipment in block chain type account book
CN110750533A (en) Data storage method, device and equipment based on multiple service attributes
CN110362570B (en) Data storage method, device and equipment
CN110059087B (en) Data attribute identification method, device and equipment in block chain type account book
CN111444194B (en) Method, device and equipment for clearing indexes in block chain type account book
CN110636042B (en) Method, device and equipment for updating verified block height of server
CN111444197B (en) Verification method, device and equipment for data records in block chain type account book

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40034079

Country of ref document: HK