WO2021017422A1 - 一种块链式账本中的索引创建方法、装置及设备 - Google Patents

一种块链式账本中的索引创建方法、装置及设备 Download PDF

Info

Publication number
WO2021017422A1
WO2021017422A1 PCT/CN2020/071420 CN2020071420W WO2021017422A1 WO 2021017422 A1 WO2021017422 A1 WO 2021017422A1 CN 2020071420 W CN2020071420 W CN 2020071420W WO 2021017422 A1 WO2021017422 A1 WO 2021017422A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
block
data block
data record
record
Prior art date
Application number
PCT/CN2020/071420
Other languages
English (en)
French (fr)
Inventor
杨新颖
Original Assignee
创新先进技术有限公司
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 创新先进技术有限公司 filed Critical 创新先进技术有限公司
Priority to US16/807,237 priority Critical patent/US10795874B2/en
Priority to US16/945,593 priority patent/US11068457B2/en
Publication of WO2021017422A1 publication Critical patent/WO2021017422A1/zh
Priority to US17/379,638 priority patent/US11573944B2/en

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
    • 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
    • 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/12Accounting

Definitions

  • the embodiments of this specification relate to the field of information technology, and in particular to an index creation method, device and equipment in a block chain ledger.
  • the ledger records the relevant data records that the relevant users need to save.
  • centralized database service providers In practical applications, centralized database service providers generally dock with corporate users, and the data records that corporate users need to store often have different business attributes. For example, the source of the data record, the user, the belonging project, etc.
  • the storage of data records related to the same business attribute is often scattered and disorderly, and it is inconvenient to perform status statistics and query for data records related to the same business attribute.
  • the purpose of the embodiments of the present application is to provide an index creation method in a block chain ledger to realize flexible data query.
  • An index creation method in a block chain ledger, applied to a centralized database server that stores data through a block chain ledger includes:
  • each data block contains at least one data record
  • each data block contains the hash value of the previous data block and the data record contained in itself Determine the hash value of the own data block
  • the block height of the data block increases monotonically based on the sequence of the block time.
  • the embodiment of this specification also provides an index creation device in a block chain ledger, which is applied to a centralized database server that stores data through a block chain ledger, including:
  • a determining module to determine the location information of the data record in the ledger, where the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located;
  • a writing module to establish a correspondence relationship between the business attributes, location information, and sequence numbers, and write the correspondence relationships in an index with the business attributes as the primary key according to the sequence numbers;
  • each data block contains at least one data record
  • each data block contains the hash value of the previous data block and the data record contained in itself Determine the hash value of the own data block
  • the block height of the data block increases monotonically based on the sequence of the block time.
  • the business attributes of the data records, as well as the storage location and sequence number in the ledger are determined, and the corresponding relationship between the three is established, and the business attributes are created as
  • the inverted index of the primary key does not need to know the user's business details.
  • the data records can be counted in order based on the business attributes, which is convenient for subsequent query and verification.
  • Fig. 1 is a schematic diagram of a process for generating a block chain ledger provided by an embodiment of the specification
  • FIG. 2 is a schematic diagram of the logical structure of a data record provided by an embodiment of this specification
  • FIG. 3 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
  • FIG. 5 is a schematic flowchart of an index creation method in a block chain ledger provided by an embodiment of this specification
  • FIG. 6 is a schematic structural diagram of an index creation device in a block chain ledger provided by an embodiment of this specification
  • Fig. 7 is a schematic structural diagram of a device for configuring the method of the embodiment of this specification.
  • FIG. 1 is a schematic diagram of the process of generating a block chain ledger provided by the embodiment of this specification, including:
  • S101 Receive data to be stored sent by a user, generate a data record containing the data to be stored, and determine a hash value of the data record, where the data record contains business attributes and sequence numbers.
  • the data to be stored here can be various consumption records of individual users of the client, or can be business results, intermediate states, and operation records generated when the application server executes business logic based on user instructions.
  • Specific business scenarios can include consumption records, audit logs, supply chains, government supervision records, medical records, and so on.
  • the database server needs to generate data records for writing into the ledger based on the data to be stored.
  • the data record contains business attributes and sequence numbers.
  • the business attribute characterizes the business characteristics of the data record, and may include user name, user ID number, organization name, transaction type, data record type, and so on.
  • the business attribute in a data record containing a report uploaded by a financial institution, can be the report number "G01" that characterizes the report category, that is, the asset and liability project statistics table; or the data record can be the project number to which the report belongs and many more.
  • the user can determine the method of obtaining the business attributes and sequence numbers in the ledger when the ledger is created.
  • a user can create a ledger through a creation instruction, and the data structure configuration parameters of the ledger are included in the creation instruction, so that the database server can obtain the configuration parameters of the ledger from the instructions and write the configuration parameters Enter the block header of the initial data block of the created ledger, and at the same time, generate a data record containing the creation instruction, and write the data record into the block body of the initial data block.
  • You can find out how the user created the ledger at any time in the future from the initial data block.
  • a user when a user creates a ledger, he can also generate a data structure parameter configuration file of the ledger.
  • the parameter value in the data structure parameter configuration file is the parameter value in the creation instruction, and the data structure parameter configuration file is used for configuration.
  • the type of configuration parameters of the ledger and the specific parameter value of each parameter In other words, after the parameter value is initially set, the user can also change the configuration parameter by changing the configuration file.
  • the data structure configuration parameters can include business attributes and serial number parameters.
  • the user can initiate the command CreateLedger(LedgerID, CLUE: ID) to the database server, where "LedgerID” is the ledger ID, and "CLUE: ID” means that the business attribute of the ledger is set to the user ID; or, the user
  • the command CreateLedger (LedgerID, CLUE: G01) can be initiated to the database server.
  • CLUE: G01 is characterized as modifying the value of the business attribute of the stamped copy to "G01".
  • users A and B both define ID as the business attribute of their respective ledger.
  • User A’s ID is "UID2019”
  • the character string corresponding to the business attribute is "UID2019”
  • the business attribute corresponds to The string is "UID2020”.
  • the sequence number represents the sequence of data records containing the same business attribute in the ledger. Specifically, the sequence number may be determined by the user and written into the data to be stored uploaded by the user, or may be determined by the database server and written into the data to be stored uploaded by the user.
  • the user can modify the value of the serial number parameter in the configuration parameters through instructions. For example, when creating a ledger, enter the command CreateLedger(LedgerID, CLUE, NULL) to set the value of the serial number parameter to "NULL", which means that no serial number is required; Or input the command CreateLedger (LedgerID, CLUE, SEQ-NUM), which means to obtain the user-specified sequence number from the data record to be stored; or, input the command CreateLedger (LedgerID, CLUE, SEQ-TIME), which means that the database server receives The time of the received data determines the sequence number.
  • the solutions provided in the embodiments of this specification involve situations where the data records to be stored require sequential numbering.
  • sequence numbers specifically, for any data to be stored, there are two ways to obtain sequence numbers:
  • the sequence number is designated by the user, that is, the user carries the corresponding sequence number when sending the data to be stored.
  • the database server can obtain the corresponding sequence number from the data to be stored.
  • the sequence number is determined by the database server, that is, the database server assigns a sequence number of the data record to be stored in the ledger according to the time stamp of the received data record to be stored. It is easy to understand that the sequence numbers maintained by each ledger are independent. When the frequency of the data to be stored sent by the user is not high, this method can also be accurately assigned to the corresponding sequence of each data record.
  • the sequence number corresponding to the business attribute "ID" may be "100", and if the business attribute is "G01", the sequence number may be "50".
  • the sequence number can be assigned as 1 at the time of the initial data block, and each time the value of the same business attribute is written in the future, the sequence number is increased by 1. Since the data records stored in the data block actually cannot see their business order relationship, by assigning a sequence number to the data record, the order of each data record in the ledger can be clarified, which is conducive to users' future queries and verification.
  • FIG. 2 is a schematic diagram of a logical structure of a data record provided by an embodiment of this specification.
  • the business attributes and sequence numbers can be placed at the head or tail of the data to be stored. And, it is also necessary to use special identification characters to identify the business attributes and sequence numbers, for example, "OE" as the beginning identification character, and "OF" as the end identification character, and so on. Or, it is also possible to allocate a designated occupied space to the head and tail to distinguish the head and tail of the data record and the data to be stored contained therein.
  • the spliced data record containing business attributes is "UID2019DAT99"; or, when the identification characters are present, generate The data record is "OEUID2019OFDATAOE99OF”.
  • the occupied space of the head and tail when the occupied space of the head and tail is specified, it can also be in the following form: [UID2019][DATA][99], where "[UID2019]” and "[99]” occupy the specified space respectively
  • the length and the insufficient part can be completed with invalid characters.
  • the head, data and tail can be effectively identified, so that the business attributes, data body and sequence number contained in the data record can be easily identified.
  • the preset block conditions include: the number of data records to be stored reaches the number threshold, for example, every time one thousand data records are received, a new data block is generated and one thousand data records are written into the block; or , The time interval from the last block formation time reaches the time threshold, for example, every 5 minutes, a new data block is generated, and the data records received within these 5 minutes are written into the block.
  • the N here refers to the serial number of the data block.
  • the data block is in the form of a block chain, which is arranged sequentially based on the order of the block time, and has a strong timing characteristic.
  • the block height of the data block increases monotonically based on the sequence of the block time.
  • the block height can be a sequence number, at this time the block height of the Nth data block is N; the block height can also be generated in other ways.
  • the data block at this time is the initial data block.
  • the current data block (the first data block) can be generated based on the hash value of the previous data block (that is, the N-1th data block). For example, a feasible way is to determine the hash value of each data record to be written in the Nth block, and generate a Merck according to the sequence in the block. In the Er tree, the root hash value of the Merkel tree and the hash value of the previous data block are spliced together, and the hash algorithm is used again to generate the hash value of the current block.
  • 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 to store the plaintext of the data record, or the hash value of the data record, etc.;
  • the block header can be used to store metadata about the data block, for example, the version number of the ledger, the hash of the previous data block Value, the root hash value of the Merkel tree composed of data records in the own data block, the hash value of the own data block, the state array used to record the operated state of the data record, and so on.
  • the data data structure configuration parameter can be written into the block header in the initial data block.
  • FIG. 3 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
  • Parent_hash the hash value of the previous data block
  • each field will have an actual assignment (for example, the specific value of Parent_hash is a 256-length string, the specific value of CLUE is "ID”, the assignment of SEQ is "SEQ_TIME”, etc.), The specific assignment is not shown in the diagram.
  • the hash value of the corresponding data record and the hash value of the data block can be obtained and saved, and integrity verification can be initiated based on the hash value.
  • the specific verification method is to recalculate the hash value of the data record itself and the hash value of the data block in the database, and compare with the locally stored hash value.
  • each data block is determined by a hash value, and the hash value of the data block is determined by the content and sequence of the 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. Any modification of the data block (including the modification of the data record content or sequence in the data block) will cause the hash value of the data block calculated during verification and The hash value of the data block is inconsistent when it is generated, which causes the verification to fail, thus realizing the immutability under centralization.
  • a segment of data block is designated for continuous integrity verification, or continuous integrity verification starts from the initial data block.
  • the verification method is to obtain the hash value of the previous data block, and use the same algorithm as when generating the hash value of the data block, and recalculate its own data based on its own data record and the hash value of the previous data block. The hash value of the block.
  • FIG. 4 is a schematic diagram of the system architecture involved in the embodiment of the specification.
  • an enterprise organization can face multiple users, and each user can query the database service provider through its corresponding enterprise organization.
  • the organization that the database service party connects to is a financial product company
  • the data record can be the personal user’s financial management records in the financial product company
  • the organization to be connected can be a government department, where the data record is the government department’s Expense details of the managed public project; or, the database service provider is connected to a hospital, and the data record is the patient’s medical record; or the database service provider is connected to a third-party payment agency, and the data record can be an individual user Payment records through the agency, etc.
  • the hospital's medical records of all patients are uploaded sequentially in the order of time. For a certain user in the hospital, there may be multiple medical histories, and the time interval is relatively large. If the hospital or the user needs to select the user's data record from the ledger, it needs to be determined according to the previous storage The hash value of each medical record record of the user can be queried from the ledger, which is very inconvenient and cannot reflect the order relationship between the medical records. If the hospital queries the medical records of the user, there is no difference between the medical records obtained. The user experience is not good due to the timing relationship.
  • the embodiment of this specification provides a method for creating an index of data records, which is applied to a centralized database server that stores data through a block chain ledger. It can be implemented without knowing the business details of the docking organization.
  • the inverted index with business attributes as the main key facilitates the business processing of the docking organization and improves user experience.
  • FIG. 5 is a schematic flowchart of a method for creating an index in a block chain ledger provided by an embodiment of this specification. The process specifically includes the following steps:
  • S501 Acquire business attributes and sequence numbers included in the data record.
  • the data structure of the data record has been determined by the data structure configuration parameters, so the business attributes and sequence number database server contained therein can be parsed based on the configuration parameters of the ledger.
  • the business attribute can be obtained through the identifying characters "OE” and “OF” as “UID2019” and the sequence number is "99 ";
  • the data record [UID2019][DATA][99] can be directly analyzed by segment of the occupied space, and the business attributes and sequence numbers can be directly read.
  • S503 Determine location information of the data record in the ledger, where the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located.
  • a block-chain ledger is composed of multiple data blocks, and at the same time, a data block usually contains multiple data records. Therefore, in the embodiment of this specification, the location information specifically refers to which data block in the ledger is in when a data record is saved, and where it is in the data block.
  • the hash value of the data block is a hash value obtained by hash calculation based on the previous block's hash value and its own data record, which can be used to uniquely and clearly identify a data block.
  • the block height of the first data block is 0, and the block height is increased by 1 for each additional data block; or, the block time of the data block can be converted into a large monotonic increase Integer data (usually 12 to 15 bits) sequence, as the block height of the data block. Therefore, a data block usually has a clear block height.
  • the order of data records has also been fixed, so the offset sequence number of a data record in the data block is also clear, and the length of the data record is a fixed unit
  • the offset sequence number can also be used to clarify the position information of the data recorded in the data block. That is, the offset sequence number can also be used to indicate the offset.
  • the address offset of each data record in the data block can also be used to identify the data records in the data block respectively.
  • the address offset of each data record is not the same.
  • the specific format of the data block can be customized (for example, the metadata information and remark information contained in the block header of the data block, the block height of the data block is adopted Format, etc.), in different formats, the content of the location information will be different, which does not constitute a limitation to this solution.
  • S505 Establish a correspondence relationship between the business attributes, location information, and sequence numbers, and write the correspondence relationships in an index with the business attributes as the primary key in sequence according to the sequence numbers.
  • the index is an inverted index.
  • the primary key is the business attribute contained in the data record.
  • the specific writing method is: when the primary key in the index does not contain the business attribute, an index record with the business attribute as the primary key is created in the index table.
  • the location information and sequence number are written into the index record where the business attribute is located.
  • Table 1 is an exemplary index table provided in the embodiment of this specification.
  • the Key is the specific value of the business attribute, and each array in the Value part is a piece of position information and sequence number.
  • the Value array contains three parts: the first part is the block height of the data record, the second part is the offset sequence number of the data record in the data block, and the third part is the sequence number of the data record based on the business attribute classification. .
  • a data record can be uniquely determined by the block height and offset sequence number. It is easy to understand that in the index table, a key can correspond to multiple location information. For example, for the array (2,8,1), "2" is the block height, "8" is the offset sequence number, and "1" is the sequence number under the business attribute "0X123456".
  • the location information and sequence numbers can also be used. Arranging in sequence according to the sequence number is conducive to user inquiries and verification.
  • the sequence of data records in the ledger reflects the time when the data records are written into the ledger, or reflects the user's determination of the sequence of data records.
  • the business attributes of the data records, as well as the storage location and sequence number in the ledger are determined, and the corresponding relationship between the three is established, and the business attributes are created as
  • the inverted index of the primary key does not need to know the user's business details. From the index, the data records can be counted in order based on business attributes, which is convenient for subsequent query and verification.
  • the status query and statistics of business attributes can be performed based on the index table. For example, receiving a query request containing the specific value of a business attribute (generally, the query request can be sent in the form of an instruction).
  • the inquiry request can come from the docking organization or the service user of the docking organization. Therefore, the database can perform matching from the index table according to the specific value of the business attribute.
  • the user enters the query command, Retrieve (0X123456, &v, FULL), that is, the location information (2,8,1) of the data record corresponding to the user "0X123456" can be obtained from the index table, ( 2,10,2), (300,89,3), (300,999,4), and then according to the location information (2,8), (2,10), (300,89), (300,999) query to get the corresponding Data records, and return the data records corresponding to (2,8), (2,10), (300,89), (300,999) to the user according to the sequence number, or you can also use the database server
  • the sequence number sorts the data records obtained by the query, thereby returning multiple sorted data records to the user.
  • the query can also include a block height parameter used to specify the data block interval, for example, the user enters a query command, Retrieve (0X123456, &v, 100), used to query the data of the specified user 0X123456 before the block height 100 recording.
  • a query command retrieve (0X123456, &v, 100)
  • retrieve 0X123456, &v, 100
  • the location information (2,8), (2,10) and the corresponding data records are obtained, and returned in order.
  • a segment of data block can also be determined by the height of two data blocks, for example, the user enters a query command, Retrieve (0X123456, &v, 200, 1000), which is used to query the specified user 0X123456 in the ledger with a block height of 200 to a block height of 1000
  • the data records between the positions, and the data records corresponding to the position information (300,89,3), (300,999,4) are returned in order.
  • the data records can be counted sequentially based on business attributes, which is convenient for subsequent query and verification.
  • an embodiment of this specification also provides an index creation device in a block chain ledger, as shown in FIG. 6, which is a schematic structural diagram of an index creation device in a block chain ledger provided by an embodiment of this specification ,include:
  • the obtaining module 601 obtains the business attributes and sequence numbers contained in the data record
  • the determining module 603 determines the location information of the data record in the ledger, where the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located;
  • the writing module 605 establishes a correspondence relationship between the business attribute, location information, and sequence number, and sequentially writes the correspondence relationship in the index with the business attribute as the primary key according to the sequence number;
  • each data block contains at least one data record
  • each data block contains the hash value of the previous data block and the data record contained in itself Determine the hash value of the own data block
  • the block height of the data block increases monotonically based on the sequence of the block time.
  • the obtaining module 601 when receiving the data record sent by the user, obtain the business attribute and sequence number contained in the designated identification field in the data record; or determine the data record contained in the data block in the ledger, For any data record contained in the data block, obtain the business attribute and sequence number contained in its designated identification field.
  • the writing module 605 when the primary key in the index does not contain the business attribute, creates an index record with the business attribute as the primary key in the index table; when the primary key in the index When the business attribute is included, the location information and sequence number are written into the index record where the business attribute is located.
  • the device further includes a data block generation module 607, which receives the data to be stored sent by the user, generates a data record containing the data to be stored, and determines the hash value of the data record, wherein the data record contains Business attributes and sequence numbers; when the preset block conditions are reached, each data record to be written in the data block is determined, and the Nth data block containing the hash value of the data block and the data record is generated, which specifically includes:
  • the hash value and block height of the initial data block are given based on a preset method
  • the preset blocking condition includes: the number of data records to be stored reaches the number threshold; or, the time interval from the last blocking time reaches the time threshold.
  • the device further includes a query module 609, which receives a query instruction containing specific values of business attributes; according to the specific values of the user’s business attributes, matching is performed from an index table to determine the business attributes in the index table.
  • the location information and sequence number corresponding to the specific value; the corresponding data record is obtained from the ledger according to the location information, and the obtained corresponding data record is returned to the query instruction sender in sequence according to the sequence number.
  • the embodiments of this specification also provide a computer device, which includes at least a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the blocks shown in FIG. 5 when the program is executed.
  • Index creation method in chain ledger includes at least a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the blocks shown in FIG. 5 when the program is executed. Index creation method in chain ledger.
  • FIG. 7 shows a more specific hardware structure diagram of a computing device provided by an embodiment of this specification.
  • the device may include a processor 1010, a memory 1020, an input/output interface 1030, a communication interface 1040, and a bus 1050.
  • the processor 1010, the memory 1020, the input/output interface 1030, and the communication interface 1040 realize the communication connection between each other in the device through the bus 1050.
  • the processor 1010 may be implemented in a general-purpose CPU (Central Processing Unit, central processing unit), microprocessor, application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits for execution related Program to implement the technical solutions provided in the embodiments of this specification.
  • a general-purpose CPU Central Processing Unit, central processing unit
  • microprocessor microprocessor
  • application specific integrated circuit Application Specific Integrated Circuit, ASIC
  • ASIC Application Specific Integrated Circuit
  • the memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory, random access memory), static storage device, dynamic storage device, etc.
  • the memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of the present specification are implemented through software or firmware, related program codes are stored in the memory 1020 and called and executed by the processor 1010.
  • the input/output interface 1030 is used to connect an input/output module to realize information input and output.
  • the input/output/module can be configured in the device as a component (not shown in the figure), or can be connected to the device to provide corresponding functions.
  • the input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and an output device may include a display, a speaker, a vibrator, an indicator light, and the like.
  • the communication interface 1040 is used to connect a communication module (not shown in the figure) to realize the communication interaction between the device and other devices.
  • the communication module can realize communication through wired means (such as USB, network cable, etc.), or through wireless means (such as mobile network, WIFI, Bluetooth, etc.).
  • the bus 1050 includes a path to transmit information between various components of the device (for example, the processor 1010, the memory 1020, the input/output interface 1030, and the communication interface 1040).
  • the device may also include the necessary equipment for normal operation.
  • the above-mentioned device may also include only the components necessary to implement the solutions of the embodiments of the present specification, rather than all the components shown in the figures.
  • the embodiment of this specification also provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the method for creating an index in the block chain ledger shown in FIG. 5 is implemented.
  • Computer-readable media include permanent and non-permanent, removable and non-removable media, and information storage can be realized by any method or technology.
  • the information can be computer-readable instructions, data structures, program modules, 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, CD-ROM, digital versatile disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. According to the definition in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • a typical implementation device is a computer.
  • the specific form of the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email receiving and sending device, and a game control A console, a tablet computer, a wearable device, or a combination of any of these devices.

Landscapes

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

Abstract

一种块链式账本中的索引创建方法、装置及设备,所述方法包括:获取数据记录中所包含的业务属性和顺序编号(501);确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及在所处的数据块中的偏移量(503);建立所述业务属性、位置信息和顺序编号的对应关系,按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引(505)。所述方法创建以业务属性为主键的倒排索引,便于后续查询。

Description

一种块链式账本中的索引创建方法、装置及设备 技术领域
本说明书实施例涉及信息技术领域,尤其涉及一种块链式账本中的索引创建方法、装置及设备。
背景技术
在中心化的数据库服务方以块链式的账本对外提供服务时,账本中记录了相关用户所需要保存的相关数据记录。
在实际应用中,中心化的数据库服务方一般对接的是企业用户,而企业用户需要进行存储的数据记录往往具有不同的业务属性。例如,数据记录的来源、用户、所属项目等等。在块链式账本中对于同一业务属性相关的数据记录的存储往往是分散的且无序的,对于同一业务属性相关的数据记录进行状态统计以及查询不便。
基于此,需要一种关于数据记录的业务属性的索引创建方案,以实现灵活的数据查询。
发明内容
本申请实施例的目的是提供一种块链式账本中的索引创建方法,以实现灵活的数据查询。
为解决上述技术问题,本申请实施例是这样实现的:
一种块链式账本中的索引创建方法,应用于通过块链式账本存储数据的中心化的数据库服务端中,包括:
获取数据记录中所包含的业务属性和顺序编号;
确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量;
建立所述业务属性、位置信息和顺序编号的对应关系;
按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引;
其中,在所述块链式账本中,除初始数据块以外,每一数据块中包含至少一条数 据记录,每一数据块中包含由前一数据块的哈希值和自身所包含的数据记录确定的自身数据块的哈希值,数据块的块高基于成块时间的先后顺序单调递增。
对应的,本说明书实施例还提供一种块链式账本中的索引创建装置,应用于通过块链式账本存储数据的中心化的数据库服务端中,包括:
获取模块,获取数据记录中所包含的业务属性和顺序编号;
确定模块,确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量;
写入模块,建立所述业务属性、位置信息和顺序编号的对应关系,按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引;
其中,在所述块链式账本中,除初始数据块以外,每一数据块中包含至少一条数据记录,每一数据块中包含由前一数据块的哈希值和自身所包含的数据记录确定的自身数据块的哈希值,数据块的块高基于成块时间的先后顺序单调递增。
通过本说明书实施例所提供的方案,对于写入账本的数据记录,确定出数据记录的业务属性,以及在账本中的存储位置和顺序编号,建立起三者的对应关系,创建以业务属性为主键的倒排索引,不必了解用户的业务详情,根据索引中即可以基于业务属性对于数据记录进行依序统计,便于后续的查询和验证。
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本说明书实施例。
此外,本说明书实施例中的任一实施例并不需要达到上述的全部效果。
附图说明
为了更清楚地说明本说明书实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书实施例中记载的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。
图1为本说明书实施例所提供的一种生成块链式账本的流程示意图;
图2为本说明书实施例所提供的一种数据记录的逻辑结构示意图;
图3为本说明书实施例所提供的一种数据块的块头的示意图;
图4为本说明书实施例所涉及的系统架构示意图;
图5是本说明书实施例提供的一种块链式账本中的索引创建方法的流程示意图;
图6是本说明书实施例提供的一种块链式账本中的索引创建装置的结构示意图;
图7是用于配置本说明书实施例方法的一种设备的结构示意图。
具体实施方式
为了使本领域技术人员更好地理解本说明书实施例中的技术方案,下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行详细地描述,显然,所描述的实施例仅仅是本说明书的一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员所获得的所有其他实施例,都应当属于保护的范围。
首先对本说明书实施例中所涉及的中心化下的块链式的账本予以说明。在中心化的数据库服务提供方,块链式的账本通过如下方式生成,如图1所示,图1为本说明书实施例所提供的一种生成块链式账本的流程示意图,包括:
S101,接收用户所发送的待存储数据,生成包含所述待存储数据的数据记录,确定所述数据记录的哈希值,其中,数据记录中包含业务属性和顺序编号。
此处的待存储数据,可以是客户端个人用户的各种消费记录,也可以是应用服务器基于用户的指令,在执行业务逻辑时产生的业务结果、中间状态以及操作记录等等。具体的业务场景可以包括消费记录、审计日志、供应链条、政府监管记录、医疗记录等等。
数据库服务端需要根据待存储数据生成用于写入账本的数据记录。数据记录中包含有业务属性和顺序编号。
其中,业务属性表征了数据记录的业务特征,可以包括用户名、用户身份证号、机构名、交易类别、数据记录类别等等。例如,在一条由金融机构上传的包含报表的数据记录中,业务属性可以是表征该报表类别的报表编号“G01”,即资产负债项目统计表;或者,数据记录可以是该报表所属的项目编号等等。
在一种实施方式中,用户可以在创建账本时即确定该账本中的业务属性和顺序编号的获得方式。
例如,用户可以通过创建指令进行创建账本,并且在创建指令中即包含有该账本的数据结构配置参数,从而,数据库服务端可以从指令中获取该账本的配置参数,并且 将所述配置参数写入所创建的账本的初始数据块的块头中,同时,生成包含所述创建指令的数据记录,将所述数据记录写入所述初始数据块的块体中。日后可以随时从初始数据块中查询得到用户是如何创建该账本的。
又例如,用户在创建账本时,还可以生成所述账本的数据结构参数配置文件,数据结构参数配置文件中的参数值即为创建指令中的参数值,所述数据结构参数配置文件用于配置所述账本的配置参数的类型以及每个参数的具体参数值。换言之,在初始设定了参数值以后,用户还可以通过更改配置文件来实现对于配置参数的更改。数据结构配置参数即可以包括业务属性和序号参数。
例如,用户可以向数据库服务端发起指令CreateLedger(LedgerID,CLUE:ID),其中,“LedgerID”为账本ID,“CLUE:ID”表征为将该账本的业务属性设置为用户ID;又或者,用户可以向数据库服务端发起指令CreateLedger(LedgerID,CLUE:G01),“CLUE:G01”表征为将盖章本的业务属性的值修改为“G01”。
在前序示例中,若用户A和B均定义ID为各自账本的业务属性。用户A的ID为“UID2019”,则对于该用户A而言,业务属性所对应的字符串为“UID2019”;用户B的ID为“UID2020”,则对于该用户B而言,业务属性所对应的字符串为“UID2020”。
顺序编号则是表征了在该账本那种包含同一业务属性的数据记录的先后关系。具体而言,顺序编号可以是由用户确定并写入用户所上传的待存储的数据中,也可以是由数据库服务端所确定,并写入用户所上传的待存储的数据中。
例如,用户可以通过指令修改配置参数中序号参数的值,例如,在创建账本时,输入指令CreateLedger(LedgerID,CLUE,NULL),将序号参数的值设定为“NULL”,表示无需顺序编号;或者输入指令CreateLedger(LedgerID,CLUE,SEQ-NUM),表示从待存储的数据记录中获取用户指定的顺序编号;或者,输入指令CreateLedger(LedgerID,CLUE,SEQ-TIME),表示数据库服务端根据接收到的数据的时间确定顺序编号。当然,本说明书实施例中所提供的方案所涉及的即待存储的数据记录为需要顺序编号的情形。
针对顺序编号,具体而言,针对任一待存储数据,获取顺序编号的方式可以有如下两种方式:
第一种,顺序编号由用户方指定,即用户在发送待存储数据时即携带相应的顺序编号。这种方式下需要数据库服务端和用户之间协议数据格式。以便数据库服务端可以从待存储数据中获取出对应的顺序编号。
第二种,顺序编号由数据库服务端确定,即数据库服务端根据接收到的待存储数据记录的时间戳,分配给该待存储数据记录在该账本中的一个顺序编号。容易理解,各账本所维护的顺序编号是分别独立的。在用户发送的待存储数据的频率不高时,该方式同样可以准确的分配给各数据记录相应的顺序。
例如,在同一账本中的同一用户所上传的数据,业务属性“ID”所对应的顺序编号可能是“100”,而如果业务属性是“G01”,其顺序编号可能是“50”。具体而言对于每一业务属性,可以在初始数据块时即分配顺序编号为1,以后每写入同一业务属性的值,顺序编号加1。由于在数据块中存储的数据记录实际上是看不出来彼此在业务上的顺序关系的,通过给数据记录分配顺序编号可以明确账本中的各数据记录的先后关系,有利于用户日后的查询与验证。
进而,数据库服务端可以对待存储数据、顺序编号和业务属性进行拼接,生成包含所述待存储数据的数据记录,并且确定出所述数据记录的哈希值,并返回所述哈希值至用户。如图2所示,图2为本说明书实施例所提供的一种数据记录的逻辑结构示意图。
具体而言,可以将业务属性和顺序编号置于待存储数据的头部或者尾部。以及,还可以需要使用特殊的标识字符用于识别所述业务属性和顺序编号,例如,以“OE”作为开头标识字符,以“OF”作为结束标识字符,等等。又或者,还可以通过将头部以及尾部分配指定的占用空间,以便区分所述数据记录的头部、尾部和其中所包含的待存储数据。
例如,若用户A上传的待存储数据为“DATA”,该数据的顺序编号为99,则拼接得到的包含业务属性的数据记录为“UID2019DAT99”;或者,当存在所述标识字符时,则生成的数据记录为“OEUID2019OFDATAOE99OF”。
又例如,在指定了头部以及尾部的占用空间时,还可以是如下形式:[UID2019][DATA][99],其中,“[UID2019]”和“[99]”分别占用了指定的空间长度,不足部分可以用无效字符补全,在这种方式下可以有效的识别出头部、数据和尾部,从而可以方便的识别出数据记录中所包含的业务属性、数据正文和顺序编号。
S103,当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块。
所述预设的成块条件包括:待存储的数据记录数量达到数量阈值,例如,每接收到一千条数据记录时,生成一个新数据块,将一千条数据记录写入块中;或者,距离上 一次成块时刻的时间间隔达到时间阈值,例如,每隔5分钟,生成一个新数据块,将在这5分钟内接收到的数据记录写入块中。
此处的N指的是数据块的序号,换言之,在本说明书实施例中,数据块是以块链的形式,基于成块时间的顺序先后排列,具有很强的时序特征。其中,数据块的块高基于成块时间的先后顺序单调递增。块高可以是序号,此时第N个数据块的块高即为N;块高也可以其它方式生成。
当N=1时,即此时的数据块为为初始数据块。初始数据块的哈希值和块高基于预设方式给定。例如,初始数据块中不包含数据记录,哈希值则为任一给定的哈希值,块高blknum=0;又例如,初始数据块的生成触发条件与其它数据块的触发条件一致,但是初始数据块的哈希值由对初始数据块中的所有内容取哈希确定。
当N>1时,由于前一数据块的内容和哈希值已经确定,则此时,可以基于前一数据块(即第N-1个数据块)的哈希值生成当前数据块(第N个数据块)的哈希值,例如,一种可行的方式为,确定每一条将要写入第N个块中的数据记录的哈希值,按照在块中的排列顺序,生成一个默克尔树,将默克尔树的根哈希值和前一数据块的哈希值拼接在一起,再次采用哈希算法,生成当前块的哈希值。又例如,还可以按照块中数据记录的顺序进行拼接并取哈希得到整体数据记录的哈希值,拼接前一数据块的哈希值和整体数据记录的哈希值,并对拼接得到的字串进行哈希运算,生成数据块的哈希值。
上述方式生成的数据块,可以包括块头和块体两个部分。块体中可以用于存储数据记录的明文,或者数据记录的哈希值等等;块头中可以用于存储有关本数据块的元数据,例如,账本的版本号,前一数据块的哈希值,自身数据块中的数据记录所组成的默克尔树的根哈希值,自身数据块的哈希值,用于记录数据记录的被操作状态的状态数组等等。
例如,可以将数据数据结构配置参数写入初始数据块中的块头中。如图3所示,图3为本说明书实施例所提供的一种数据块的块头的示意图。在初始数据块中,Parent_hash(前一数据块的哈希值)可以为空,以及,还可以包括诸如CLUE、LENGTH以及SEQ等数据结构配置参数。在实际应用中,每个字段均会有一个实际的赋值(例如,Parent_hash的具体值为一个256长度的字符串,CLUE的具体值为“ID”,SEQ的赋值为“SEQ_TIME”等等),具体的赋值在该示意图中未显示。
用户在上传数据成功后,即可以得到对应的数据记录的哈希值以及所处的数据块的哈希值,并保存,并且可以基于该哈希值发起完整性验证。具体的验证方式即为在数 据库中重新计算数据记录自身的哈希值以及所处的数据块的哈希值,与本地所保存的进行对比。
通过前述的数据块的生成方式,每一个数据块通过哈希值确定,数据块的哈希值由数据块中的数据记录的内容、顺序以及前一数据块的哈希值决定。用户可以随时基于数据块的哈希值发起验证,对于数据块中任何内容(包括对于数据块中数据记录内容或者顺序的修改)的修改都会造成在验证时计算得到的数据块的哈希值和数据块生成时的哈希值不一致,而导致验证失败,从而实现了中心化下的不可篡改。
在对于块链式的账本进行验证时,一般而言,即指定一段数据块进行连续的完整性验证,或者从初始数据块开始进行连续的完整性验证。验证的方式即为获取前一数据块的哈希值,并采用与生成数据块的哈希值时的同样算法,根据自身的数据记录和前一数据块的哈希值,重新计算一遍自身数据块的哈希值。
前述部分对于本说明书实施例所涉及的块链式的账本进行了说明。在实际应用中,数据库服务方面向的常常为各种机构,各机构则可以将它们与第三方用户(包括其它机构或者个人)之间所产生的数据记录在数据库服务方进行存储。如图4所示,图4为本说明书实施例所涉及的系统架构示意图。在该示意图中,一个企业机构可以面向多名用户,而每个用户均可以通过其对应的企业机构向数据库服务提供方进行查询。
例如,数据库服务方对接的机构是某金融产品公司,数据记录可以是个人用户在该金融产品公司的理财记录;或者,对接的机构可以是政府部门,其中的数据记录是政府部门对于该部门所管理的公共项目的开销明细;或者,数据库服务方对接的机构是某个医院,其中的数据记录是病人的病历;或者,数据库服务方对接的机构是第三方支付机构,数据记录可以是个人用户通过该机构的支付记录,等等。
如前所述,这些数据记录在写入账本时虽然已经有了较强的时序特征,但是对于用户而言,其数据记录通常是分散式的存储在多个数据块中的。
例如,医院对于所有病人的病历记录按照时间产生的顺序,依次上传。而对于医院的某个用户而言,其病史可能有多条,时间间隔又比较大,如果医院或者该用户需要从账本中将该用户的数据记录挑选出来,则需要根据之前在存储时所确定的每条病历记录的哈希值从账本中进行查询,很不方便,而且无法反映出各条病历之间的顺序关系,如果医院在查询该用户的病历时,得到的各条病历之间没有时序的关系,用户体验不佳。
基于此,本说明书实施例提供一种数据记录的索引创建方法,应用于通过块链式 账本存储数据的中心化的数据库服务端中,可以实现在不必了解对接机构的业务详情时,创建出以业务属性为主键的倒排索引,方便对接机构的业务处理,提高用户体验。
以下结合附图,详细说明本说明书各实施例提供的技术方案。如图5所示,图5是本说明书实施例提供的一种块链式账本中的索引创建方法的流程示意图,该流程具体包括如下步骤:
S501,获取数据记录中所包含的业务属性和顺序编号。
如前所述,数据记录的数据结构已经通过数据结构配置参数所确定,因此其中所包含的业务属性和顺序编号数据库服务端可以基于该账本的配置参数进行解析得到。
例如,在数据记录是通过标识字符来标识业务属性和顺序编号时,“OEUID2019OFDATAOE99OF”,此时,即可以通过标识字符“OE”和“OF”得到业务属性为“UID2019”,顺序编号为“99”;
又例如,如果指定了占用空间,则直接可以对数据记录[UID2019][DATA][99]进行占用空间的分段解析,直接读取出业务属性和顺序编号。
S503,确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量。
如前所述,一个块链式的账本由多个数据块组成,同时,一个数据块中通常包含多个数据记录。因此,在本说明书实施例中,所述的位置信息具体指的是一条数据记录被保存时,处于账本中的哪个数据块上,以及,在该数据块中的什么位置。
在本说明书实施例所提供的数据块中,可以有多种方式用来标识不同的数据块,包括数据块的哈希值或者块高。
数据块的哈希值为根据前一区块哈希值和自身数据记录进行哈希计算而得到的哈希值,可以用于唯一、明确地标识一个数据块。在块链式的账本中,通常第一个数据块其块高为0,以后每增加一个数据块,块高加1;或者,还可以将数据块的成块时间转换为一个大的单调递增整型数据(一般为12至15位)序列,作为数据块的块高。因此,一个数据块通常有一个明确的块高。
又例如,在一个已经确定的要写入数据库的数据块,其中数据记录的排序也已经固定,因此一个数据记录在该数据块中的偏移序号也是明确的,在数据记录的长度为固定单位时,偏移序号同样可以用于明确该数据记录在其所处的数据块中的位置信息。即, 偏移序号同样也可以用于指示偏移量。
同时,在一个数据块中,由于通常包含了多个数据记录,因此,还可以用各数据记录在该数据块中的地址偏移量来分别标识数据块中的数据记录。显而易见,在同一个数据块中,各数据记录的地址偏移量并不相同。
当然,由于在本说明书实施例所提供的方式中,数据块的具体格式是可以自定义的(例如,数据块的块头中所包含的元数据信息和备注信息,数据块的块高所采取的形式等等),在不同的格式下,位置信息的内容也会有所不同,这并不构成对本方案的限定。
S505,建立所述业务属性、位置信息和顺序编号的对应关系,按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引。
即,该索引是一个倒排索引。在该索引中,主键是数据记录中所包含的业务属性。具体的写入方式为,当索引中的主键不包含所述业务属性时,在索引表中创建以所述业务属性为主键的索引记录。
当所述索引中的主键包含所述业务属性时,将所述位置信息和顺序编号写入所述业务属性所处的索引记录。
如表1所示,表1为本说明书实施例所提供的一种示例性索引表。其中Key即为业务属性的具体值,Value部分的每个数组即为一条位置信息和顺序编号,
Value数组中包含三个部分:第一部分为数据记录所处的块高,第二部分为数据记录在该数据块中的偏移序号,第三部分为基于业务属性分类给该数据记录的顺序编号。通过块高和偏移序号即可以唯一的确定一条数据记录。容易理解,在索引表中,一个key可以对应于多个位置信息。例如,对于数组(2,8,1)而言,其中的“2”即为块高,“8”即为偏移序号,“1”即为在业务属性“0X123456”下的顺序编号。
表1
Key Value
0X123456 (2,8,1),(2,10,2),(300,89,3),(300,999,4)
344X0001 (5,01,1),(8,22,2)
…… ……
在索引表中,由于一个业务属性可以对应于多个位置信息和顺序编号(即对应于 多个数据记录),因此,在将位置信息写入索引中时,还可以将位置信息和顺序编号,按照所述顺序编号依次进行排列,有利于用户的查询以及验证。数据记录在账本中的先后顺序即体现了数据记录被写入账本的时间,或者体现了用户对于数据记录的先后顺序的确定。
通过本说明书实施例所提供的方案,对于写入账本的数据记录,确定出数据记录的业务属性,以及在账本中的存储位置和顺序编号,建立起三者的对应关系,创建以业务属性为主键的倒排索引,不必了解用户的业务详情,从索引中即可以基于业务属性对于数据记录进行依序统计,便于后续的查询和验证。
在索引表被创建以后,即可以基于该索引表进行业务属性的状态查询以及统计。例如,接收包含业务属性具体值的查询请求(一般而言,查询请求可以以指令的形式予以发送)。查询请求可以来自于对接机构,也可以是来自于对接机构的服务用户。从而,数据库可以根据业务属性的具体值,从索引表中进行匹配。例如,在表1被创建之后,用户输入查询指令,Retrieve(0X123456,&v,FULL),即可以从索引表中取得用户“0X123456”相应的数据记录的位置信息(2,8,1),(2,10,2),(300,89,3),(300,999,4),进而根据位置信息(2,8),(2,10),(300,89),(300,999)查询得到相应的数据记录,并且根据顺序编号依次的将(2,8),(2,10),(300,89),(300,999)所对应的数据记录返回至用户,或者,还可以在数据库服务端即根据顺序编号对查询得到的数据记录进行排序,从而返回排序好的多条数据记录至用户。
进一步地,在查询时还可以包含用于指定数据块区间的块高参数,例如,用户输入查询指令,Retrieve(0X123456,&v,100),用于查询指定的用户0X123456在块高100之前的数据记录。从而,得到位置信息(2,8),(2,10),所对应的数据记录,并依序返回。
以及,还可以由两个数据块高确定一段数据块,例如,用户输入查询指令,Retrieve(0X123456,&v,200,1000),用于查询指定的用户0X123456在账本中块高200至块高1000之间的数据记录,从而得到位置信息(300,89,3),(300,999,4)所对应的数据记录兵依序返回。
通过创建索引,用户想要针对数据记录进行某些统计时,则只需直接依据索引表进行就可以了。例如,对接机构想要统计各用户的数据记录的数量,或者,用户想要知道自身与对接机构的数据记录数量,此时,直接统计在索引表中的各Key值之后的Value数量就可以了,根据索引中即可以基于业务属性对于数据记录进行依序统计,便于后续 的查询和验证。
对应的,本说明书实施例还提供一种块链式账本中的索引创建装置,如图6所示,图6是本说明书实施例提供的一种块链式账本中的索引创建装置的结构示意图,包括:
获取模块601,获取数据记录中所包含的业务属性和顺序编号;
确定模块603,确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量;
写入模块605,建立所述业务属性、位置信息和顺序编号的对应关系,按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引;
其中,在所述块链式账本中,除初始数据块以外,每一数据块中包含至少一条数据记录,每一数据块中包含由前一数据块的哈希值和自身所包含的数据记录确定的自身数据块的哈希值,数据块的块高基于成块时间的先后顺序单调递增。
进一步地,所述获取模块601:接收到用户所发送的数据记录时,获取数据记录中的指定标识字段所包含的业务属性和顺序编号;或者,确定账本中的数据块所包含的数据记录,针对所述数据块中所包含的任一数据记录,获取其指定标识字段所包含的业务属性和顺序编号。
进一步地,所述写入模块605,当所述索引中的主键不包含所述业务属性时,在所述索引表中创建以所述业务属性为主键的索引记录;当所述索引中的主键包含所述业务属性时,将所述位置信息和顺序编号和写入所述业务属性所处的索引记录。
进一步地,所述装置还包括数据块生成模块607,接收用户所发送的待存储数据,生成包含所述待存储数据的数据记录,确定所述数据记录的哈希值,其中,数据记录中包含业务属性和顺序编号;当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:
当N=1时,初始数据块的哈希值和块高基于预设方式给定;
当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块,其中,数据块的块高基于成块时间的先后顺序单调递增。
进一步地,所述预设的成块条件包括:待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。
进一步地,所述装置还包括查询模块609,接收包含业务属性具体值的查询指令;根据所述用户业务属性的具体值,从索引表中进行匹配,确定在所述索引表中所述业务属性具体值所对应的位置信息和顺序编号;根据所述位置信息从所述账本中获取对应的数据记录,按照所述顺序编号依序返回获取得到的对应的数据记录至查询指令发送方。
本说明书实施例还提供一种计算机设备,其至少包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,处理器执行所述程序时实现图5所示的块链式账本中的索引创建方法。
图7示出了本说明书实施例所提供的一种更为具体的计算设备硬件结构示意图,该设备可以包括:处理器1010、存储器1020、输入/输出接口1030、通信接口1040和总线1050。其中处理器1010、存储器1020、输入/输出接口1030和通信接口1040通过总线1050实现彼此之间在设备内部的通信连接。
处理器1010可以采用通用的CPU(Central Processing Unit,中央处理器)、微处理器、应用专用集成电路(Application Specific Integrated Circuit,ASIC)、或者一个或多个集成电路等方式实现,用于执行相关程序,以实现本说明书实施例所提供的技术方案。
存储器1020可以采用ROM(Read Only Memory,只读存储器)、RAM(Random Access Memory,随机存取存储器)、静态存储设备,动态存储设备等形式实现。存储器1020可以存储操作系统和其他应用程序,在通过软件或者固件来实现本说明书实施例所提供的技术方案时,相关的程序代码保存在存储器1020中,并由处理器1010来调用执行。
输入/输出接口1030用于连接输入/输出模块,以实现信息输入及输出。输入输出/模块可以作为组件配置在设备中(图中未示出),也可以外接于设备以提供相应功能。其中输入设备可以包括键盘、鼠标、触摸屏、麦克风、各类传感器等,输出设备可以包括显示器、扬声器、振动器、指示灯等。
通信接口1040用于连接通信模块(图中未示出),以实现本设备与其他设备的通信交互。其中通信模块可以通过有线方式(例如USB、网线等)实现通信,也可以通过无线方式(例如移动网络、WIFI、蓝牙等)实现通信。
总线1050包括一通路,在设备的各个组件(例如处理器1010、存储器1020、输入/输出接口1030和通信接口1040)之间传输信息。
需要说明的是,尽管上述设备仅示出了处理器1010、存储器1020、输入/输出接口1030、通信接口1040以及总线1050,但是在具体实施过程中,该设备还可以包括实现正常运行所必需的其他组件。此外,本领域的技术人员可以理解的是,上述设备中也可以仅包含实现本说明书实施例方案所必需的组件,而不必包含图中所示的全部组件。
本说明书实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现图5所示的块链式账本中的索引创建方法。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本说明书实施例可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本说明书实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本说明书实施例各个实施例或者实施例的某些部分所述的方法。
上述实施例阐明的系统、方法、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于方法实施例而言,由于其基本相似于方法实施例,所以描述得比较简单,相关之处参见方法实施例的部分说明即可。以上所描述的方法实施例仅仅是示意性的,其中所述作为分 离部件说明的模块可以是或者也可以不是物理上分开的,在实施本说明书实施例方案时可以把各模块的功能在同一个或多个软件和/或硬件中实现。也可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。
以上所述仅是本说明书实施例的具体实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本说明书实施例原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本说明书实施例的保护范围。

Claims (13)

  1. 一种块链式账本中的索引创建方法,应用于通过块链式账本存储数据的中心化的数据库服务端中,包括:
    获取数据记录中所包含的业务属性和顺序编号;
    确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量;
    建立所述业务属性、位置信息和顺序编号的对应关系,按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引;
    其中,在所述块链式账本中,除初始数据块以外,每一数据块中包含至少一条数据记录,每一数据块中包含由前一数据块的哈希值和自身所包含的数据记录确定的自身数据块的哈希值,数据块的块高基于成块时间的先后顺序单调递增。
  2. 如权利要求1所述的方法,获取数据记录中的业务属性和顺序编号,包括:
    接收到用户所发送的数据记录时,获取数据记录中的指定标识字段所包含的业务属性和顺序编号;或者,
    确定账本中的数据块所包含的数据记录,针对所述数据块中所包含的任一数据记录,获取其指定标识字段所包含的业务属性和顺序编号。
  3. 如权利要求1所述的方法,将所述对应关系依序写入以所述业务属性为主键的索引,包括:
    当所述索引中的主键不包含所述业务属性时,在所述索引表中创建以所述业务属性为主键的索引记录;
    当所述索引中的主键包含所述业务属性时,将所述位置信息和顺序编号和写入所述业务属性所处的索引记录。
  4. 如权利要求1所述的方法,在中心化的数据库服务端,数据块通过如下方式预先生成:
    接收用户所发送的待存储数据,生成包含所述待存储数据的数据记录,确定所述数据记录的哈希值,其中,数据记录中还包含业务属性和顺序编号;
    当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:
    当N=1时,初始数据块的哈希值和块高基于预设方式给定;
    当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块, 其中,数据块的块高基于成块时间的先后顺序单调递增。
  5. 如权利要求4所述的方法,所述预设的成块条件包括:
    待存储的数据记录数量达到数量阈值;或者,
    距离上一次成块时刻的时间间隔达到时间阈值。
  6. 如权利要求1所述的方法,所述方法还包括:
    接收包含业务属性具体值的查询指令;
    根据所述用户业务属性的具体值,从索引表中进行匹配,确定在所述索引表中所述业务属性具体值所对应的位置信息和顺序编号;
    根据所述位置信息从所述账本中获取对应的数据记录,按照所述顺序编号依序返回获取得到的对应的数据记录至查询指令发送方。
  7. 一种块链式账本中的索引创建装置,应用于通过块链式账本存储数据的中心化的数据库服务端中,包括:
    获取模块,获取数据记录中所包含的业务属性和顺序编号;
    确定模块,确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量;
    写入模块,建立所述业务属性、位置信息和顺序编号的对应关系,按照所述顺序编号,将所述对应关系依序写入以所述业务属性为主键的索引;
    其中,在所述块链式账本中,除初始数据块以外,每一数据块中包含至少一条数据记录,每一数据块中包含由前一数据块的哈希值和自身所包含的数据记录确定的自身数据块的哈希值,数据块的块高基于成块时间的先后顺序单调递增。
  8. 如权利要求7所述的装置,所述获取模块:接收到用户所发送的数据记录时,获取数据记录中的指定标识字段所包含的业务属性和顺序编号;或者,确定账本中的数据块所包含的数据记录,针对所述数据块中所包含的任一数据记录,获取其指定标识字段所包含的业务属性和顺序编号。
  9. 如权利要求7所述的装置,所述写入模块,当所述索引中的主键不包含所述业务属性时,在所述索引表中创建以所述业务属性为主键的索引记录;当所述索引中的主键包含所述业务属性时,将所述位置信息和顺序编号和写入所述业务属性所处的索引记录。
  10. 如权利要求7所述的装置,还包括数据块生成模块,接收用户所发送的待存储数据,生成包含所述待存储数据的数据记录,确定所述数据记录的哈希值,其中,数据记录中包含业务属性和顺序编号;当达到预设的成块条件时,确定待写入数据块中的各 数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:
    当N=1时,初始数据块的哈希值和块高基于预设方式给定;
    当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块,其中,数据块的块高基于成块时间的先后顺序单调递增。
  11. 如权利要求10所述的装置,所述预设的成块条件包括:待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。
  12. 如权利要求7所述的装置,所述装置还包括查询模块,接收包含业务属性具体值的查询指令;根据所述用户业务属性的具体值,从索引表中进行匹配,确定在所述索引表中所述业务属性具体值所对应的位置信息和顺序编号;根据所述位置信息从所述账本中获取对应的数据记录,按照所述顺序编号依序返回获取得到的对应的数据记录至查询指令发送方。
  13. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,所述处理器执行所述程序时实现如权利要求1至6任一项所述的方法。
PCT/CN2020/071420 2019-07-29 2020-01-10 一种块链式账本中的索引创建方法、装置及设备 WO2021017422A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
US16/807,237 US10795874B2 (en) 2019-07-29 2020-03-03 Creating index in blockchain-type ledger
US16/945,593 US11068457B2 (en) 2019-07-29 2020-07-31 Creating index in blockchain-type ledger
US17/379,638 US11573944B2 (en) 2019-07-29 2021-07-19 Creating index in blockchain-type ledger

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910689278.7 2019-07-29
CN201910689278.7A CN111352935B (zh) 2019-07-29 2019-07-29 一种块链式账本中的索引创建方法、装置及设备

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US16/807,237 Continuation US10795874B2 (en) 2019-07-29 2020-03-03 Creating index in blockchain-type ledger

Publications (1)

Publication Number Publication Date
WO2021017422A1 true WO2021017422A1 (zh) 2021-02-04

Family

ID=71192842

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/071420 WO2021017422A1 (zh) 2019-07-29 2020-01-10 一种块链式账本中的索引创建方法、装置及设备

Country Status (2)

Country Link
CN (2) CN111352935B (zh)
WO (1) WO2021017422A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113055226A (zh) * 2021-02-20 2021-06-29 烽火通信科技股份有限公司 一种网管配置数据下载的排序方法及装置
CN115809248A (zh) * 2022-12-30 2023-03-17 联通智网科技股份有限公司 数据查询方法和装置以及存储介质
CN116665913A (zh) * 2023-07-13 2023-08-29 之江实验室 一种跨机构的患者匹配系统和方法

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113094395B (zh) * 2021-03-19 2022-05-24 杭州复杂美科技有限公司 数据查询方法、计算机设备和存储介质
CN114997841B (zh) * 2022-07-18 2022-10-21 成都信通信息技术有限公司 一种基于区块链的低碳行为数据管理系统
CN116304390B (zh) * 2023-04-13 2024-02-13 北京基调网络股份有限公司 时序数据处理方法、装置、存储介质及电子设备

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9009206B1 (en) * 2012-11-20 2015-04-14 Netapp, Inc. Method and system for optimizing traversal and storage of directory entries of a storage volume
CN107562775A (zh) * 2017-07-14 2018-01-09 阿里巴巴集团控股有限公司 一种基于区块链的数据处理方法及设备
CN108197505A (zh) * 2017-12-29 2018-06-22 泰康保险集团股份有限公司 区块链业务数据处理方法、装置及电子设备
CN108876615A (zh) * 2018-06-11 2018-11-23 腾讯科技(深圳)有限公司 债权数据存储方法、装置、设备及介质
CN109873866A (zh) * 2019-02-20 2019-06-11 北京邮电大学 一种基于区块链的数据共享方法、装置及电子设备
CN109902071A (zh) * 2019-01-31 2019-06-18 阿里巴巴集团控股有限公司 业务日志存储方法、系统、装置及设备

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7340527B2 (en) * 2002-05-09 2008-03-04 Matsushita Electric Industrial Co., Ltd. Content distribution system that distributes line of stream data generated by splicing plurality of pieces of stream data
US9009655B2 (en) * 2008-09-28 2015-04-14 KOUSOKUYA, Inc. Code string search apparatus, search method, and program
CN101599079B (zh) * 2009-07-22 2011-08-31 中国科学院计算技术研究所 一种备份数据集中存储的管理方法
CN101620617B (zh) * 2009-07-28 2011-07-13 中兴通讯股份有限公司 日志文件的查询和处理的方法及装置
CN103810246B (zh) * 2013-12-27 2017-10-13 北京天融信软件有限公司 一种索引创建方法和装置以及索引查询方法和装置
CN104090987B (zh) * 2014-07-28 2018-03-13 华中科技大学 一种历史数据存储及索引方法
CA3065319A1 (en) * 2017-06-01 2018-12-06 Schvey, Inc. d/b/a/ Axoni Distributed privately subspaced blockchain data structures with secure access restriction management
CN107436938B (zh) * 2017-07-27 2019-11-05 国家电网公司 一种关系数据库前映像的附加日志解析方法
CN110059084B (zh) * 2019-01-31 2023-08-01 创新先进技术有限公司 一种数据存储方法、装置及设备
CN109902086B (zh) * 2019-01-31 2022-12-20 创新先进技术有限公司 一种索引创建方法、装置及设备
CN110061843B (zh) * 2019-01-31 2022-02-18 创新先进技术有限公司 一种链式账本中的块高创建方法、装置及设备
CN110008743B (zh) * 2019-03-26 2023-02-28 创新先进技术有限公司 一种块链式账本中的数据属性标识方法、装置及设备

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9009206B1 (en) * 2012-11-20 2015-04-14 Netapp, Inc. Method and system for optimizing traversal and storage of directory entries of a storage volume
CN107562775A (zh) * 2017-07-14 2018-01-09 阿里巴巴集团控股有限公司 一种基于区块链的数据处理方法及设备
CN108197505A (zh) * 2017-12-29 2018-06-22 泰康保险集团股份有限公司 区块链业务数据处理方法、装置及电子设备
CN108876615A (zh) * 2018-06-11 2018-11-23 腾讯科技(深圳)有限公司 债权数据存储方法、装置、设备及介质
CN109902071A (zh) * 2019-01-31 2019-06-18 阿里巴巴集团控股有限公司 业务日志存储方法、系统、装置及设备
CN109873866A (zh) * 2019-02-20 2019-06-11 北京邮电大学 一种基于区块链的数据共享方法、装置及电子设备

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113055226A (zh) * 2021-02-20 2021-06-29 烽火通信科技股份有限公司 一种网管配置数据下载的排序方法及装置
CN113055226B (zh) * 2021-02-20 2022-04-26 烽火通信科技股份有限公司 一种网管配置数据下载的排序方法及装置
CN115809248A (zh) * 2022-12-30 2023-03-17 联通智网科技股份有限公司 数据查询方法和装置以及存储介质
CN115809248B (zh) * 2022-12-30 2024-03-22 联通智网科技股份有限公司 数据查询方法和装置以及存储介质
CN116665913A (zh) * 2023-07-13 2023-08-29 之江实验室 一种跨机构的患者匹配系统和方法
CN116665913B (zh) * 2023-07-13 2023-10-13 之江实验室 一种跨机构的患者匹配系统和方法

Also Published As

Publication number Publication date
CN111352935A (zh) 2020-06-30
CN113535720A (zh) 2021-10-22
CN111352935B (zh) 2021-05-18

Similar Documents

Publication Publication Date Title
WO2021073242A1 (zh) 索引创建和数据查询方法、装置及设备
WO2021017422A1 (zh) 一种块链式账本中的索引创建方法、装置及设备
CN110188096B (zh) 一种数据记录的索引创建方法、装置及设备
WO2020211569A1 (zh) 一种数据记录的索引创建方法
WO2020244239A1 (zh) 一种基于业务标识的索引创建方法、装置及设备
CN110162526B (zh) 一种块链式账本中数据记录的查询方法、装置及设备
WO2020253231A1 (zh) 一种基于收据的数据存储方法、装置及设备
WO2021073240A1 (zh) 一种块链式账本中的数据存储方法、装置及设备
US11573944B2 (en) Creating index in blockchain-type ledger
US11816099B2 (en) Service identifier-based data indexing
WO2021057164A1 (zh) 一种块链式账本中的查询方法、装置及设备
WO2020244237A1 (zh) 一种块链式账本中的验证方法、装置及设备
WO2021093461A1 (zh) 一种块链式账本中的聚合计算方法、装置及设备
WO2021073241A1 (zh) 一种基于磁盘存储的数据读取方法、装置及设备
US10999062B2 (en) Blockchain-type data storage
WO2021057127A1 (zh) 一种基于多条业务属性的数据存储方法、装置及设备
US11126751B2 (en) Index creation for data records
WO2021093462A1 (zh) 一种数据库中的操作记录存储方法、装置及设备
CN110362570B (zh) 一种数据存储方法、装置及设备
CN111444194B (zh) 一种块链式账本中索引的清除方法、装置及设备
CN111444195B (zh) 一种块链式账本中索引的清除方法、装置及设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20846537

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20846537

Country of ref document: EP

Kind code of ref document: A1