CN110874486A - Data reading method, device and equipment in block chain type account book - Google Patents

Data reading method, device and equipment in block chain type account book Download PDF

Info

Publication number
CN110874486A
CN110874486A CN201910993127.0A CN201910993127A CN110874486A CN 110874486 A CN110874486 A CN 110874486A CN 201910993127 A CN201910993127 A CN 201910993127A CN 110874486 A CN110874486 A CN 110874486A
Authority
CN
China
Prior art keywords
data
position information
block
record
data record
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.)
Granted
Application number
CN201910993127.0A
Other languages
Chinese (zh)
Other versions
CN110874486B (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.)
Ant Blockchain Technology Shanghai 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 CN201910993127.0A priority Critical patent/CN110874486B/en
Publication of CN110874486A publication Critical patent/CN110874486A/en
Application granted granted Critical
Publication of CN110874486B publication Critical patent/CN110874486B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • G06F21/6227Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database where protection concerns the structure of data, e.g. records, types, queries
    • 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

Abstract

A method, a device and equipment for reading data in a block chain type account book are disclosed. According to the scheme provided by the embodiment of the specification, when data is read in a block chain type account, a certain number of threads are generated according to related information, the obtained position information is correspondingly grouped, and the data is read by traversing and reading a plurality of threads in parallel, so that the data reading is basically completed by the plurality of threads at the same time.

Description

Data reading method, device and equipment in block chain type account book
Technical Field
The embodiment of the specification relates to the technical field of information, in particular to a data reading method, device and equipment in a block chain type account book.
Background
At a database server side providing services to the outside by using a centralized block chain type account book, if a user needs to acquire related data from the account book, the user needs to sequentially acquire related data records from each data block of the account book, and the efficiency is too low.
Based on this, there is a need for a more efficient data reading scheme in a blockchain ledger.
Disclosure of Invention
An object of the embodiments of the present application is to provide a more efficient data reading in a blockchain ledger.
In order to solve the above technical problem, the embodiment of the present application is implemented as follows:
a data reading method in a block chain type account book comprises the following steps:
receiving a data reading instruction sent by a client, wherein the reading instruction comprises a service attribute;
acquiring a position information set corresponding to the service attribute from a preset index table, wherein the position information comprises the block height of a data block where a data record is located and the offset in the data block where the data record is located;
generating M threads for collecting data records, and dividing the position information set into N mutually exclusive position information subsets, wherein the ratio of N to M is greater than a preset ratio;
traversing the group by adopting M threads, and acquiring data records corresponding to the position information in each position information subset from the block chain type account book;
and aggregating the data records, generating a data record set, and returning the data record set to the client.
Correspondingly, an embodiment of the present specification further provides a data reading apparatus in a block chain type account book, including:
the receiving module is used for receiving a data reading instruction sent by a user, wherein the reading instruction comprises a service attribute;
the position information acquisition module is used for acquiring a position information set corresponding to the service attribute from a preset index table, wherein the position information comprises the block height of a data block where a data record is located and the offset of the data block where the data record is located;
the generating module is used for generating M threads for acquiring data records and dividing the position information set into N mutually exclusive position information subsets, wherein the ratio of N to M is greater than a preset ratio;
the data record acquisition module is used for traversing the group by adopting M threads and acquiring data records corresponding to the position information in each position information subset from the block chain type account book;
and the return module is used for aggregating the data records, generating a data record set and returning the data record set to the client.
According to the scheme provided by the embodiment of the specification, when data is read in a block chain type account book, a certain number of threads are generated according to related information, the obtained position information is correspondingly grouped, and the data is read by traversing and reading a plurality of threads in parallel, so that the data reading is basically completed by the plurality of threads at the same time, and the efficiency is improved.
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 flowchart illustrating an index creating method for a data record according to an embodiment of the present disclosure;
fig. 4 is a flowchart illustrating a data record reading method according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of a data reading apparatus in a block chain ledger provided by an embodiment of this specification;
fig. 6 is a schematic structural diagram of an apparatus for configuring a method according to an embodiment of the present disclosure.
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.
The data records to be stored here may be various consumption records of individual users of the client, and also may be business results, intermediate states, operation records, and the like generated by the application server when executing 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 each mechanism that interfaces with the database server, the business attribute exists uniquely in the interfacing mechanism, and the business attribute is based on different business scenarios and may include a user name, a user identity number, a driver license number, a mobile phone number, a unique item number, a type of data record (e.g., a financial package 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 service attributes may be stored at a specified location in the data record, such as the head or tail of the data record.
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, such as converting a chunked time symmetric encryption into large integer data (e.g., 12-bit or 15-bit integers) as the block height.
When N is 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 is 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 mode is to recalculate the hash value of the data record and the hash value of the data block in the database, and compare the calculated hash values with those stored locally.
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.
When the block chained account book is verified, generally, a segment of data block is designated for continuous integrity verification, or continuous integrity verification is performed from the initial data block. The verification mode is to obtain the hash value of the previous data block, and recalculate the hash value of the data block according to the data record of the data block and the hash value of the previous data block by adopting the same algorithm as that used for generating the hash value of the data block so as to perform verification.
Based on the mode, a hard-to-tamper blockchain type account book can be obtained and used for storing data. In order to facilitate data query, embodiments of the present specification further provide an index creation method for a block chain ledger. As shown in fig. 3, fig. 3 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:
s301, in the block chain type account book, aiming at any data record, the business attribute contained in the data record is obtained.
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 S303, 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 also be used to indicate the offset of data recording in the data block.
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.
S305, establishing the corresponding relation between the service attribute and the position information, and writing an index taking the service attribute as a main key.
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 specified identification field, an index record with the specified identification field as the main key is created in the index table.
And when the primary key in the index contains the specified identification field, writing the position information into the index record in which the specified identification field is located. Here, the writing is not overwriting, but position information is added to the value of the index record, and is present in the index record in parallel with other position information.
As shown in table 1, table 1 is an exemplary index table provided in the embodiments of the present specification. The 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 a data record in the data block, and a data record can be uniquely determined through the block height and the serial number. It is easily understood that one key may correspond to a plurality of location information in the index table.
TABLE 1
Key Value
0X123456 (2,08),(2,10),(300,89),(300,999)
344X0001 (5,01),(8,22)
…… ……
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 (that is, one index record may include a plurality of location information, or one service attribute may correspond to a plurality of data records), when the location information is written into the index, the location information may 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 timestamp (i.e. the blocking timestamp of the data block) in which the data records are written in the ledger, and the sequence of the data records in the same data block can be embodied by the sequence in the data block. By sequencing the position information, corresponding data records can be obtained conveniently and sequentially when the read data records are obtained through inquiry, and user experience is improved.
After the index table is created, the status query and statistics of the service attribute can be performed based on the index table. For example, a query request is received that contains specific values of service attributes (in general, the query request may be sent in the form of instructions). The query request may come from the docking facility or from a service user of the docking facility. Thus, the database can be matched from the index table according to the specific value of the service attribute. For example, after table 1 is created, the user inputs a query command, Retrieve (0X123456, & v, FULL), that is, location information (2,08), (2,10), (300,89), (300,999) of the data record corresponding to the user "0X 123456" can be obtained from the index table, and the corresponding data record is obtained according to the location information query and returned to the user.
Specifically, the database server may read the data records sequentially according to the block height and the offset, and collectively return the data records to each user after the data records are read. Of course, multiple threads and multiple packets may be created, with each thread reading corresponding to a packet. For example, 5 threads are created, and 10000 pieces of position information are equally divided into 5 groups, one for each thread.
However, in this embodiment, an efficiency problem occurs when the data amount is large. For example, thread 1 is efficient, and takes 10 seconds to finish reading, while thread 5 is inefficient, and takes 30 seconds to finish, in this process, thread 1 needs to be idle and wait for 20 seconds, and the final server can aggregate the final result and return the data record to the user.
Based on this, an embodiment of the present disclosure provides a more efficient data record reading scheme, as shown in fig. 4, fig. 4 is a schematic flow chart of a data record reading method provided by an embodiment of the present disclosure, and the method includes:
s401, receiving a data reading instruction sent by a client, wherein the reading instruction comprises a service attribute. For example, the user inputs a data reading instruction, Retrieve (0X123456, & v, FULL), and desires to obtain the FULL traffic data corresponding to the traffic attribute "0X 123456".
S403, obtaining a location information set corresponding to the service attribute from a preset index table, where the location information includes a block height of a data block where the data record is located and an offset in the data block where the data record is located.
The location information has already been described above and will not be described in detail here. The obtained location information set should include the full amount of location information included in the service attribute, i.e., all values corresponding to one primary key in the index. The elements in the set may be in the form of arrays or vectors.
S405, generating M threads for collecting data records, and dividing the position information set into N mutually exclusive position information subsets, wherein the ratio of N to M is greater than a preset ratio.
It should be noted that, the term "mutually exclusive" means that each subset does not contain the same location information, and meanwhile, if N mutually exclusive location information subsets are combined, the location information set can be obtained. The grouping mode may be to sequentially group the elements (i.e., the position information) in the position information set to obtain each subset, or to randomly select the elements to obtain each subset. The number of elements in each subset is typically equal or similar.
Specifically, the database server may first determine the number of threads M. For example, generally, the number of physical cores of the device is larger, and the number of threads that can be provided is larger, so the number of physical cores of the database server can be directly determined as the number of threads M.
In this embodiment, in addition to considering the number of physical cores of the database server, more threads may be opened according to actual needs. It should be noted that, in this process, the larger the number of threads that are not turned on, the faster the entire data record is read.
Therefore, it is necessary to statistically obtain the average consumed time of the data record from the historical data by one thread, and fit the thread number according to the average consumed time and the physical kernel number to obtain the optimal thread number M, thereby generating M threads for acquiring the data record.
In an implementation manner, the database server may further split according to the number S of elements and the number M of threads in the location information set. For example, after determining the number of elements S and the number of threads M, directly using S/M to obtain the number of subsets N (which may be rounded if N is not a natural number), for example, if there are 10000 elements and the number of threads is 6, directly determining the number of subsets N10000/6 16666 and the number of elements in each subset is 6 to 7. Since the number of elements S is always considered to be much larger than the square of the number of threads, in this way a number N of subsets much larger than the number M of threads is generally obtained.
Further, it is also possible to directly preset the ratio for adjusting the number of subsets, for example, the preset ratio is 100, if it is determined that the number of threads is 5, at least 500 subsets need to be created. In practical applications, the predetermined ratio is usually a large value (e.g., the value is not less than 100).
Furthermore, if the number of elements in the position information set is small, it is not enough to satisfy that the ratio of N to M is greater than the preset ratio. For example, if the number of elements in the position information set is only 300, and M is 5, even if only one element in each subset can be grouped into only 300 subsets, it cannot be satisfied that the number of subsets/threads is greater than 100, in this case (the reason for this is generally that there are fewer data records to be read), the number of threads may also be reduced, for example, the number of threads is reduced to 2 or 3, so that the number of subsets/threads is greater than the preset value. Since this generally occurs because there are fewer data records to be read, reducing the number of threads is also a limited reduction in read time, and does not affect the user experience in such situations.
S407, traversing the group by adopting M threads, and acquiring data records corresponding to the position information in each position information subset from the block chain type account book.
In the foregoing manner, N subsets and M threads are obtained, and the ratio of N to M is at a larger value. At this time, multiple threads may be used to read in a traversal manner for the N subsets. The reading mode is to locate the data block according to the block height in the position information and directly locate the data record according to the offset, thereby obtaining the plaintext of the data record.
The foregoing traversal means that the location information in each subset will be read by one and only one thread. For example, one implementation may be to form N subsets into a pool of subsets, each subset having a state label 0/1, where 0 represents unprocessed and 1 represents processed. Any thread captures a subset with the state of 0 from the pool sequentially or randomly, data record reading is carried out according to position information in the subset, after reading is finished, the state label of the subset is modified to be 1 and is placed back into the pool, and the subset with the state of 1 is cleared in the pool at regular time. When no subset remains in the pool, the data read ends.
Since the number of subsets is much larger than the number of threads in the embodiments of the present specification, even if one thread is more efficient than other threads, there is still enough subset to wait for the thread to process, the thread will always be in working state, not idle state, and the plurality of threads end the processing process at substantially the same time.
And S409, aggregating the data records, generating a data record set, and returning the data record set to the client. The aggregation refers to writing the data records obtained by the threads into the same document in a plaintext mode.
According to the scheme provided by the embodiment of the specification, the multiple threads are adopted to process the multiple subset pools, even if some threads are high in efficiency and some threads are low in efficiency, no thread is in an idle state before the processing is finished, the multiple threads are adopted to perform traversing reading in parallel, the multiple threads basically complete data reading at the same time, and the efficiency is improved.
Correspondingly, an embodiment of the present specification further provides a data reading apparatus in a block chain type account book, as shown in fig. 5, fig. 5 is a schematic structural diagram of the data reading apparatus in the block chain type account book provided in the embodiment of the present specification, and the data reading apparatus includes:
a receiving module 501, configured to receive a data reading instruction sent by a user, where the data reading instruction includes a service attribute;
a location information obtaining module 503, configured to obtain, from a preset index table, a location information set corresponding to the service attribute, where the location information includes a block height of a data block where a data record is located and an offset in the data block where the data record is located;
a generating module 505, configured to generate M threads for acquiring data records, and divide the position information set into N mutually exclusive position information subsets, where a ratio of N to M is greater than a preset ratio;
the data record acquisition module 507 is used for traversing the groups by adopting M threads and acquiring data records corresponding to the position information in each position information subset from the block chain type account book;
the returning module 509 aggregates the data records, generates a data record set, and returns the data record set to the client.
Further, the generating module 505 determines the number of position information in the position information set, and determines the number N of subsets according to M and the number of position information in the set.
Further, the generating module 505 determines historical average consumed time when each thread acquires a data record corresponding to the position information in each position information subset in the historical record, determines a current thread number M according to the historical average consumed time, and generates M threads for acquiring the data record.
Further, the apparatus further includes an index generating module 511, which, in the block chain type account book, obtains a service attribute included in any data record; determining position information of the data record in the ledger, wherein the position information comprises a block height of a data block where the data record is located and an offset in the located data block; and establishing a corresponding relation between the service attribute and the position information, and writing an index taking the service attribute as a main key.
Further, the index generating module 511 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 apparatus further includes a data block generating module 513, which receives data records to be stored, and determines hash values of the data records, where the data records include 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 is 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, 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 data reading method shown in fig. 4 when executing the program.
Fig. 6 is a schematic diagram illustrating a more specific hardware structure of a computing device according to an embodiment of the present disclosure, where the computing 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 data reading method shown in fig. 6.
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.
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 (15)

1. A data reading method in a block chain type account book comprises the following steps:
receiving a data reading instruction sent by a client, wherein the reading instruction comprises a service attribute;
acquiring a position information set corresponding to the service attribute from a preset index table, wherein the position information comprises the block height of a data block where a data record is located and the offset in the data block where the data record is located;
generating M threads for collecting data records, and dividing the position information set into N mutually exclusive position information subsets, wherein the ratio of N to M is greater than a preset ratio;
traversing the group by adopting M threads, and acquiring data records corresponding to the position information in each position information subset from the block chain type account book;
and aggregating the data records, generating a data record set, and returning the data record set to the client.
2. The method of claim 1, dividing the set of location information into N mutually exclusive subsets of location information, comprising:
and determining the number of the position information in the position information set, and determining the number N of the subsets according to M and the number of the position information in the set.
3. The method of claim 1, generating M threads for collecting data records, comprising:
and determining historical average consumed time when each thread acquires data records corresponding to the position information in each position information subset in the historical records, determining the current thread number M according to the historical average consumed time, and generating M threads for acquiring the data records.
4. The method of claim 1, wherein the preset index table is pre-generated based on:
in a block chain type account book, aiming at any data record, acquiring a service attribute contained in the data record;
determining position information of the data record in the ledger, wherein the position information comprises a block height of a data block where the data record is located and an offset in the located data block;
and establishing a corresponding relation between the service attribute and the position information, and writing an index taking the service attribute as a main key.
5. The method of claim 4, writing an index keyed by the service attribute, comprising:
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.
6. The method of claim 4, wherein the data blocks in the block chain ledger 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 is 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.
7. The method of claim 6, 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.
8. A data reading apparatus in a block chain ledger book, comprising:
the receiving module is used for receiving a data reading instruction sent by a user, wherein the reading instruction comprises a service attribute;
the position information acquisition module is used for acquiring a position information set corresponding to the service attribute from a preset index table, wherein the position information comprises the block height of a data block where a data record is located and the offset of the data block where the data record is located;
the generating module is used for generating M threads for acquiring data records and dividing the position information set into N mutually exclusive position information subsets, wherein the ratio of N to M is greater than a preset ratio;
the data record acquisition module is used for traversing the group by adopting M threads and acquiring data records corresponding to the position information in each position information subset from the block chain type account book;
and the return module is used for aggregating the data records, generating a data record set and returning the data record set to the client.
9. The apparatus of claim 8, the generation module determines a number of position information in the set of position information, and determines the number of subsets N based on M and the number of position information in the set.
10. The apparatus according to claim 8, wherein the generating module determines an average historical consumed time when each thread acquires a data record corresponding to the location information in each subset of the location information in the historical record, determines a current thread number M according to the average historical consumed time, and generates M threads for acquiring the data record.
11. The apparatus of claim 8, further comprising an index generation module, which, in a block-chain ledger, obtains, for any data record, a business attribute contained in the data record; determining position information of the data record in the ledger, wherein the position information comprises a block height of a data block where the data record is located and an offset in the located data block; and establishing a corresponding relation between the service attribute and the position information, and writing an index taking the service attribute as a main key.
12. The apparatus of claim 11, the index generation 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.
13. The apparatus according to claim 12, further comprising a data block generating module, which receives data records to be stored, and determines a hash value of each data record, wherein the data records include 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 is 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.
14. The apparatus of claim 11, 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.
15. 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 7 when executing the program.
CN201910993127.0A 2019-10-18 2019-10-18 Method, device and equipment for reading data in block chain type account book Active CN110874486B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910993127.0A CN110874486B (en) 2019-10-18 2019-10-18 Method, device and equipment for reading data in block chain type account book

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910993127.0A CN110874486B (en) 2019-10-18 2019-10-18 Method, device and equipment for reading data in block chain type account book

Publications (2)

Publication Number Publication Date
CN110874486A true CN110874486A (en) 2020-03-10
CN110874486B CN110874486B (en) 2023-10-17

Family

ID=69717836

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910993127.0A Active CN110874486B (en) 2019-10-18 2019-10-18 Method, device and equipment for reading data in block chain type account book

Country Status (1)

Country Link
CN (1) CN110874486B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180068130A1 (en) * 2016-09-02 2018-03-08 The Toronto-Dominion Bank System and method for maintaining a segregated database in a multiple distributed ledger system
US20180268401A1 (en) * 2017-03-17 2018-09-20 Royal Bank Of Canada Systems and methods for hybrid blockchain platform
US20190036906A1 (en) * 2017-07-28 2019-01-31 SmartAxiom, Inc. System and method for iot security
CN110147410A (en) * 2019-04-18 2019-08-20 阿里巴巴集团控股有限公司 Data verification method, system, device and equipment in a kind of piece of chain type account book
CN110162662A (en) * 2019-04-18 2019-08-23 阿里巴巴集团控股有限公司 Verification method, device and the equipment of data record in a kind of piece of chain type account book
US20190303621A1 (en) * 2018-03-27 2019-10-03 International Business Machines Corporation Runtime self-correction for blockchain ledgers
CN110334094A (en) * 2019-06-20 2019-10-15 阿里巴巴集团控股有限公司 A kind of data query method, system, device and equipment based on inverted index

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180068130A1 (en) * 2016-09-02 2018-03-08 The Toronto-Dominion Bank System and method for maintaining a segregated database in a multiple distributed ledger system
US20180268401A1 (en) * 2017-03-17 2018-09-20 Royal Bank Of Canada Systems and methods for hybrid blockchain platform
US20190036906A1 (en) * 2017-07-28 2019-01-31 SmartAxiom, Inc. System and method for iot security
US20190303621A1 (en) * 2018-03-27 2019-10-03 International Business Machines Corporation Runtime self-correction for blockchain ledgers
CN110147410A (en) * 2019-04-18 2019-08-20 阿里巴巴集团控股有限公司 Data verification method, system, device and equipment in a kind of piece of chain type account book
CN110162662A (en) * 2019-04-18 2019-08-23 阿里巴巴集团控股有限公司 Verification method, device and the equipment of data record in a kind of piece of chain type account book
CN110334094A (en) * 2019-06-20 2019-10-15 阿里巴巴集团控股有限公司 A kind of data query method, system, device and equipment based on inverted index

Also Published As

Publication number Publication date
CN110874486B (en) 2023-10-17

Similar Documents

Publication Publication Date Title
CN110188096B (en) Index creating method, device and equipment for data record
CN110162526B (en) Method, device and equipment for inquiring data records in block chain type account book
CN110162662B (en) Verification method, device and equipment for data records in block chain type account book
CN110349019B (en) Verification method, device and equipment in block chain type account book
CN110825737A (en) Index creation and data query method, device and equipment
CN110879687B (en) Data reading method, device and equipment based on disk storage
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
CN110716965B (en) Query 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
CN111444192A (en) Method, device and equipment for generating Hash of global state in block chain type account book
CN111046069B (en) Aggregation calculation method, device and equipment in block chain type account book
CN110597461B (en) Data storage method, device and equipment in block chain type account book
CN110750533A (en) Data storage method, device and equipment based on multiple service attributes
CN111444194B (en) Method, device and equipment for clearing indexes in block chain type account book
CN110727679A (en) Cooperative tracking method, system, device and equipment for court case
CN110636042B (en) Method, device and equipment for updating verified block height of server
CN110362570B (en) Data storage method, device and equipment
US11115189B2 (en) Verifying a blockchain-type ledger
CN110874486A (en) Data reading method, device and equipment in block chain type account book
CN114513469A (en) Traffic shaping method and device for distributed system and storage medium
CN111444195B (en) Method, device and equipment for clearing indexes in block chain type account book
CN111444215A (en) Blocking method, device and equipment 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
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20200702

Address after: Unit 02, 20 / F, block a, building 4, Lane 838, Huangpi South Road, Huangpu District, Shanghai 200025

Applicant after: Ant blockchain Technology (Shanghai) Co.,Ltd.

Address before: 801-11, Section B, 8th floor, No. 556, Xixi Road, Xihu District, Hangzhou City, Zhejiang Province

Applicant before: Alipay (Hangzhou) Information Technology Co.,Ltd.

REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40025506

Country of ref document: HK

GR01 Patent grant
GR01 Patent grant