WO2021093462A1 - Method and apparatus for storing operation record in database, and device - Google Patents

Method and apparatus for storing operation record in database, and device Download PDF

Info

Publication number
WO2021093462A1
WO2021093462A1 PCT/CN2020/117005 CN2020117005W WO2021093462A1 WO 2021093462 A1 WO2021093462 A1 WO 2021093462A1 CN 2020117005 W CN2020117005 W CN 2020117005W WO 2021093462 A1 WO2021093462 A1 WO 2021093462A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
block
business attribute
change
hash value
Prior art date
Application number
PCT/CN2020/117005
Other languages
French (fr)
Chinese (zh)
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 蚂蚁区块链科技(上海)有限公司
Publication of WO2021093462A1 publication Critical patent/WO2021093462A1/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/23Updating
    • G06F16/2358Change logging, detection, and notification
    • 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
    • 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

Definitions

  • the embodiments of this specification relate to the field of information technology, and in particular to a method, device, and equipment for storing operation records in a database.
  • the centralized database server When the centralized database server provides external data services, it also needs to save the user's operations on the data record (including adding, clearing, hiding, querying, etc.) resulting in the change of the data record or the status change of a certain attribute in the data record , That is, the operation records need to be stored for retrospective or rollback. In a centralized scenario, the number of data records is often huge, and the number of operation records is also often very large.
  • the purpose of the embodiments of the present application is to provide a flexible operation record storage solution in a database.
  • the operation instruction contains a business attribute; evaluate the degree of change of the operation instruction to the data record containing the business attribute, and determine the operation influence characteristic value, wherein the operation influence characteristic value and the operation influence characteristic value include The degree of change of the data record of the business attribute is positively correlated; if the operation influence characteristic value exceeds the threshold, an operation record containing the operation instruction is generated and stored; otherwise, the data record containing the business attribute is determined The change state of, an operation record containing the change state is generated and stored.
  • the embodiment of this specification also provides an operation record storage device in a block chain ledger, including: a receiving module, which receives an operation instruction, the operation instruction contains business attributes; an evaluation module, which evaluates that the operation instruction is effective
  • the change degree of the data record containing the business attribute is determined to determine the operation influence characteristic value, wherein the operation influence characteristic value is positively correlated with the change degree of the data record containing the business attribute; the first storage module, if the If the operation influence characteristic value exceeds the threshold, generate an operation record containing the operation instruction, and store it; the second storage module, otherwise, determine the change state of the data record containing the business attribute, and generate the change state containing the change State operation records and storage.
  • the relevant operation records are dynamically generated to ensure that the data status can be accurately traced back, saving the system overhead when storing the operation records, and realizing a flexible operation record storage method.
  • any one of the embodiments of the present specification does not need to achieve all the above-mentioned effects.
  • Figure 1 is a schematic diagram of the system architecture involved in an embodiment of the specification
  • FIG. 2 is a schematic diagram of the data system architecture provided by an embodiment of this specification.
  • FIG. 3 is a schematic flowchart of a method for storing operation records in a block chain ledger provided by an embodiment of the specification
  • Fig. 4 is a schematic diagram of a process for generating a block chain ledger provided by an embodiment of the specification
  • FIG. 5 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
  • FIG. 6 is a schematic structural diagram of an operation record storage device in a database 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 a system architecture involved in an 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 connected to the database server is a financial product company, and the data records can be individual users’ financial management records in the financial product company; or, the connected organization can be a government department, where the data records are what the government department has for the department. Expense details of the managed public project; or, the database server is connected to a hospital, and the data record is the patient’s medical record; or the database server is connected to a third-party payment agency, and the data record can be an individual user Payment records through the agency, and so on.
  • FIG. 2 is a schematic diagram of the data system architecture provided by the embodiment of the present specification.
  • the user's data is stored in the main body of the ledger shown in Figure 2 (it can be a relational table, a blockchain ledger, etc.).
  • the index can be defined as needed.
  • the index can include an inverted index with the business attribute of the data record as the main key, and the block height and offset sequence number as the value; the metadata part can be Perform statistics on the main body, index and other information of the ledger to obtain relevant information.
  • the metadata part can include: the total number of data records in the ledger, the total number of data blocks in the ledger, the total number of business attributes in the ledger, and the quantity The number of data records of the top business attributes, the number of data blocks where a business attribute is located in the ledger, and so on.
  • metadata can also perform state calculations for certain business attributes.
  • the data record is about the user's expenditure/income record, or the user's purchase/sale of securities Records and so on.
  • the metadata can also include world state values for certain business attributes (for example, the user's amount of money).
  • the user can also perform various operations on the data record in the ledger, for example, including updating UPDATA, adding APPEND, clearing PURGE, verifying VERIFY, querying SELECT, hiding OCCULT, and so on.
  • corresponding operation records will be generated, and the operation records can be stored in the log part or the main part of the ledger in the storage.
  • the embodiment of this specification also provides a method for storing operation records in a block chain ledger, as shown in FIG. 3, which is the flow of the method for storing operation records in a block chain ledger provided by the embodiment of this specification. Schematic diagram, including the following steps.
  • S301 Receive an operation instruction, where the operation instruction includes a business attribute.
  • operation instructions can use common structured query language (SQL), including such as UPDATA, APPEND, PURGE, VERIFY, SELECT, OCCULT, and so on.
  • SQL structured query language
  • SELECT balance, FULL
  • UPDATA key1, v1, v2
  • the ledger will contain data records with the business attribute "key1" Replace v1 in v2 with v2 and so on.
  • the operating instructions can come from the database server, the docking organization, or the users of the docking organization, and so on.
  • operating instructions can also be user-defined statements with certain functions, such as clear PURGE (used to clear data blocks before the specified block height) in the block chain ledger.
  • Hidden OCCULT used to hide the plaintext of a specified data record
  • Business attributes can be fields related to the user's business data, for example, user ID, mobile phone number, item name, etc. There are no restrictions here; business attributes can also be related to the main body of the ledger, index, and metadata that store user data Fields, such as the name of the ledger, the name of the index, the number of rows and columns in the index, and so on.
  • the degree of impact change here mainly includes “changes to the data record itself”, “changes to the index related to the data record”, and “changes to the metadata” and so on.
  • a query command may not change any data records or metadata
  • a hidden command OCCULT may affect a data record
  • an UPDATA may affect all data records containing specified business attributes, and for Both indexing and metadata may have a corresponding impact.
  • Metadata related to the main body of the ledger can be included. For example, the total number of data records in the ledger, the total number of business attributes in the ledger, and the number of business attribute data records in the top several rankings (for example, the top 20).
  • the number of the top 100 data records containing a certain business attribute is recorded in sequence
  • the business attribute "key1” is in the table
  • the number of data records containing the business attribute "key1” is in the table. If the number is "N1”, it can be known that the operation instruction may affect the "N1" data records.
  • the operation influence characteristic value exceeds the threshold, it indicates that the operation instruction may have affected multiple data records and metadata. If the change status of each data record is recorded in the operation instruction, considerable resources may be required.
  • the generated operation record may also include the receiving time of the operation instruction, the user ID of the specific sending instruction, etc., and the operation instruction is stored in plain text.
  • the generated operation record can be stored in the corresponding log file.
  • the generated operation record can also be written into the data block in the ledger.
  • the operation influence characteristic value does not exceed the threshold, it can indicate that the operation record may only affect a small number of data records. For example, for an operation instruction APPEND (key1, V), only a data record containing the business attribute "key1" is added to the database. In the metadata, the possible change is the data record corresponding to "key1" The number of items is +1, or the possible change is that the world state corresponding to "key1" is changed from the current value to the current value plus the corresponding value in "V".
  • the change of the data record itself may be directly recorded. That is, it is determined that in the data record containing the business attribute that has changed, the initial value and the change value of the business attribute are determined, and the operation record containing the initial value and the change value of the business attribute is generated.
  • the cumulative value of the business attribute has a specific meaning to the user (for example, the account balance caused by the change in user account expenditure and income, the user’s buying or selling Profit value, etc.).
  • the cumulative status value of the business attribute in the data record containing the business attribute can also be determined, and an operation record including the cumulative status value can be generated.
  • one operation instruction will only affect one change of the accumulated state value.
  • the state value of the data record when recording the state value of the data record, it is also possible to record the before and after changes of the data record completely, and record the first data hash value of the data record before the change and the data record after the change.
  • the second data hash value of the data record generates an operation record containing the first data hash value and the second data hash value.
  • both the hash value before the data record change and the original text before the data record change are recorded.
  • the data can also be verified according to the first data hash value of the data record: That is, after the rollback, the rollback hash value of the data record is recalculated and compared with the first data hash value. If it is consistent, the rollback is correct and the correctness of the data rollback is ensured.
  • the second data hash value is used when the data state changes next time, and is used to trace back according to the first data hash value and the second data hash value in the operation record.
  • the operation record before generating the operation record, first evaluate the degree of change that the operation instruction may have on the data record containing the business attribute. If the degree of change is large, record the operation instruction and generate the operation containing the operation instruction Record and store; if the degree of change is not large, record the changed data record or its related hash value, generate an operation record containing the aforementioned state change, and store it.
  • the relevant operation records are dynamically generated, while ensuring that the data status can be accurately traced back, the system overhead when storing the operation records is saved, and a flexible operation record storage method is realized.
  • the database involved in the embodiment of this specification may be a centralized database that provides services to external parties with a blockchain ledger.
  • the blockchain ledger here can be either a blockchain ledger or a centralized blockchain-like ledger.
  • FIG. 4 is a schematic diagram of the process of generating a block chain ledger provided by the embodiment of this specification, including:
  • S401 Receive a data record to be stored, and determine a hash value of each data record, where the data record contains business attributes.
  • the data records to be stored here can be various consumption records of individual users on the client side, or they can be business results, intermediate states, and operations generated when the application server executes business logic based on user instructions. Records and so on. Specific business scenarios can include consumption records, audit logs, supply chains, government supervision records, medical records, and so on.
  • the data record contains business attributes.
  • the business attribute is generally the only one in the docking organization, and the business attributes are based on different
  • the business scenarios of, can include user name, user ID number, driver’s license number, mobile phone number, project unique number, etc.
  • the data record is the user's consumption record
  • the business attribute at this time is the user ID (including mobile phone number, ID number, user name, etc.), or the user ID is hashed
  • the hash value obtained by the algorithm; or, for government agencies, the data record is the overhead flow of multiple public projects, then the business attribute at this time can be a unique number for each project.
  • the business attribute can be stored in a designated field in the data record (for example, the head or tail of the data record), so that the database server and the user can easily obtain the business attribute of the data record from it.
  • multiple data records can be included in the same ledger.
  • the business attributes of these data records are likely to be different. For example, when a ledger is open to multiple users, the data records may come from different users. If the business attribute is a user ID, it is easy to understand that different data records often contain different user IDs.
  • S403 When a preset block forming condition is reached, determine each data record to be written in the data block, and generate an Nth data block including the hash value of the data block and the data record.
  • the preset blocking 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.
  • N 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 strong timing characteristics.
  • 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 order in the block.
  • 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 specific verification method includes recalculating the hash value of the data record itself and the hash value of the data block in which it is located, and comparing it with the locally stored hash value.
  • the data block generated in the above manner may include two parts: a block header and a block body.
  • the block body can be used to store the plaintext of the spliced data, or the hash value of the spliced data, 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 the spliced data in the own data block, the hash value of the own data block, the state array used to record the operated state of the spliced data, and so on.
  • FIG. 5 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
  • the user's data record is stored in the blockchain ledger, and integrity verification can be initiated at any time, thereby ensuring that the user's data will not be tampered with.
  • the blockchain ledger is a broadly defined ledger, which not only includes the part of the structure that stores the user's data record, but also includes the storage of metadata and operations related to the data record. Logs, indexes, and so on.
  • data records are stored in a non-tamperable block chain ledger, but the database server can also check the "status data" of a certain business attribute (including accumulated value, whether it has been operated, the time it has been operated, etc.) Etc.) to calculate.
  • the status data related to the business attribute is recorded in a designated area block in the index table or metadata.
  • the database server can determine the changed designated area block containing the business attribute according to the business attribute, and then determine the first block hash value of the designated area block before the change and the changed Specify the second block of the hash value of the area block, and generate an operation record containing the first block of the hash value and the second block of the hash value.
  • the first block of hash value and the second block of hash value have similar functions to the aforementioned first data hash value and second data hash value, and are used for the rollback and traceability of the specified area block. Ensure the accuracy of data rollback.
  • the generated operation record may also include the position mark of the designated table block and the business attribute for traceability and rollback.
  • an embodiment of this specification also provides an operation record storage device in a database, as shown in FIG. 6, which is a schematic structural diagram of an operation record storage device in a database provided by an embodiment of this specification, including the following modules .
  • the receiving module 601 receives an operation instruction, and the operation instruction includes a business attribute.
  • the evaluation module 603 evaluates the degree of change of the operation instruction to the data record containing the business attribute, and determines the operation influence characteristic value, wherein the operation influence characteristic value and the degree of change of the data record containing the business attribute Positive correlation.
  • the first storage module 605 if the operation influence characteristic value exceeds a threshold, generates an operation record containing the operation instruction, and stores it.
  • the second storage module 607 otherwise, determines the change state of the data record containing the business attribute, generates an operation record containing the change state, and stores it.
  • the evaluation module 603 evaluates the degree of change of the operation instruction to the data record containing the business attribute according to the type of the operation instruction.
  • the evaluation module 603 determines the number of data records containing the business attribute, and evaluates the degree of change of the operation instruction to the data records containing the business attribute according to the number .
  • the second storage module 607 determines that in the changed data record containing the business attribute, the initial value and the changed value of the business attribute are generated to contain the business attribute Or, determine the cumulative status value of the business attribute in the data record containing the business attribute, and generate the operation record containing the cumulative status value.
  • the second storage module 607 determines that among the changed data records containing the business attributes, the first data hash value of the data record before the change and the data record after the change The second data hash value of the data record generates an operation record containing the first data hash value and the second data hash value.
  • the second storage module 607 determines the designated area block containing the business attribute that has changed; and determines that before the change occurs The first block hash value of the designated area block and the second block hash value of the designated area block after the change occurs, and an operation record containing the first block hash value and the second block hash value is generated .
  • the device further includes a data block generation module 609, which receives the data records to be stored and determines the hash value of each data record.
  • the data record contains the business attribute; when the preset block condition is reached, it is determined
  • the setting method is given; when N>1, the hash value of the Nth data block is determined according to the data records in the data block to be written and the hash value of the N-1th data block, and the Nth data block is generated.
  • the hash value of the data block and the Nth data block of each data record wherein the block height of the data block increases monotonically based on the sequence of the block time.
  • 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 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 operations shown in FIG. 3 when the program is executed. Record storage prevention and control methods.
  • 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 by 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 realize 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), 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 this specification are implemented by 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 it 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.
  • 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 above device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040, and the bus 1050, in the specific implementation process, the device may also include the equipment necessary for normal operation. Other components.
  • the above-mentioned device may also include only the components necessary to implement the solutions of the embodiments of the present specification, and not necessarily include 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 operation record storage method shown in FIG. 3 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.

Abstract

Disclosed are a method and apparatus for storing an operation record in a database, and a device. The method comprises: receiving an operation instruction, wherein the operation instruction includes a service attribute (S301); assessing the degree to which the operation instruction changes a data record including the service attribute, and determining an operation influence feature value, wherein the operation influence feature value is positively correlated with the degree to which the data record including the service attribute is changed (S303); if the operation influence feature value exceeds a threshold value, generating and storing an operation record including the operation instruction (S305); otherwise, determining a change state of the data record including the service attribute, and generating and storing an operation record including the change state (S307).

Description

一种数据库中的操作记录存储方法、装置及设备Method, device and equipment for storing operation records in database 技术领域Technical field
本说明书实施例涉及信息技术领域,尤其涉及一种数据库中的操作记录存储方法、装置及设备。The embodiments of this specification relate to the field of information technology, and in particular to a method, device, and equipment for storing operation records in a database.
背景技术Background technique
中心化的数据库服务端在对外提供数据服务时,同时需要保存用户对于数据记录的操作(包括添加、清除、隐匿、查询等等)导致数据记录的变化或者数据记录中的某个属性的状态变化,即需要存储操作记录,以便进行追溯或者回滚。在中心化的场景下,数据记录往往数量庞大,操作记录的数量也往往很大。When the centralized database server provides external data services, it also needs to save the user's operations on the data record (including adding, clearing, hiding, querying, etc.) resulting in the change of the data record or the status change of a certain attribute in the data record , That is, the operation records need to be stored for retrospective or rollback. In a centralized scenario, the number of data records is often huge, and the number of operation records is also often very large.
基于此,需要一种灵活的操作记录存储方法。Based on this, a flexible operation record storage method is needed.
发明内容Summary of the invention
本申请实施例的目的是提供一种在数据库中灵活的操作记录存储方案。The purpose of the embodiments of the present application is to provide a flexible operation record storage solution in a database.
为解决上述技术问题,本申请实施例是通过以下方法实现的。In order to solve the above technical problems, the embodiments of the present application are implemented by the following methods.
接收操作指令,所述操作指令中包含有业务属性;评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,确定操作影响特征值,其中,所述操作影响特征值与包含有所述业务属性的数据记录的变动程度正相关;若所述操作影响特征值超过阈值,生成包含所述操作指令的操作记录,并存储;否则,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,并存储。Receive an operation instruction, the operation instruction contains a business attribute; evaluate the degree of change of the operation instruction to the data record containing the business attribute, and determine the operation influence characteristic value, wherein the operation influence characteristic value and the operation influence characteristic value include The degree of change of the data record of the business attribute is positively correlated; if the operation influence characteristic value exceeds the threshold, an operation record containing the operation instruction is generated and stored; otherwise, the data record containing the business attribute is determined The change state of, an operation record containing the change state is generated and stored.
对应的,本说明书实施例还提供一种块链式账本中的操作记录存储装置,包括:接收模块,接收操作指令,所述操作指令中包含有业务属性;评估模块,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,确定操作影响特征值,其中,所述操作影响特征值与包含有所述业务属性的数据记录的变动程度正相关;第一存储模块,若所述操作影响特征值超过阈值,生成包含所述操作指令的操作记录,并存储;第二存储模块,否则,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,并存储。Correspondingly, the embodiment of this specification also provides an operation record storage device in a block chain ledger, including: a receiving module, which receives an operation instruction, the operation instruction contains business attributes; an evaluation module, which evaluates that the operation instruction is effective The change degree of the data record containing the business attribute is determined to determine the operation influence characteristic value, wherein the operation influence characteristic value is positively correlated with the change degree of the data record containing the business attribute; the first storage module, if the If the operation influence characteristic value exceeds the threshold, generate an operation record containing the operation instruction, and store it; the second storage module, otherwise, determine the change state of the data record containing the business attribute, and generate the change state containing the change State operation records and storage.
通过本说明书实施例所提供的方案,在生成操作记录前,首先评估操作指令对于包 含业务属性的数据记录可能产生的变动程度,如果变动程度很大,就记载操作指令,生成包含操作指令的操作记录,进行存储;如果变动程度不大,就记载发生了变化的数据记录或者与其相关的哈希值,生成包含了前述状态变化的操作记录,并进行存储。通过评估操作指令可能产生的影响,动态的生成相关的操作记录,在保障可以准确的回溯数据状态,节省了存储操作记录时的系统开销,实现灵活的操作记录存储方法。Through the solution provided by the embodiment of this specification, before generating the operation record, first evaluate the degree of change that the operation instruction may have on the data record containing the business attribute. If the degree of change is large, record the operation instruction and generate the operation containing the operation instruction Record and store; if the degree of change is not large, record the changed data record or its related hash value, generate an operation record containing the aforementioned state change, and store it. By evaluating the possible impact of the operation instructions, the relevant operation records are dynamically generated to ensure that the data status can be accurately traced back, saving the system overhead when storing the operation records, and realizing a flexible operation record storage method.
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本说明书实施例。It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the embodiments of this specification.
此外,本说明书实施例中的任一实施例并不需要达到上述的全部效果。In addition, any one of the embodiments of the present specification does not need to achieve all the above-mentioned effects.
附图说明Description of the drawings
为了更清楚地说明本说明书实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书实施例中记载的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。In order to more clearly describe the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only These are some of the embodiments described in the embodiments of this specification. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
图1为本说明书实施例所涉及的系统架构示意图;Figure 1 is a schematic diagram of the system architecture involved in an embodiment of the specification;
图2是本说明书实施例所提供的数据系统架构示意图;Figure 2 is a schematic diagram of the data system architecture provided by an embodiment of this specification;
图3为本说明书实施例所提供的块链式账本中的操作记录存储方法的流程示意图;FIG. 3 is a schematic flowchart of a method for storing operation records in a block chain ledger provided by an embodiment of the specification; FIG.
图4为本说明书实施例所提供的一种生成块链式账本的流程示意图;Fig. 4 is a schematic diagram of a process for generating a block chain ledger provided by an embodiment of the specification;
图5为本说明书实施例所提供的一种数据块的块头的示意图;5 is a schematic diagram of a block header of a data block provided by an embodiment of this specification;
图6是本说明书实施例提供的一种数据库中的操作记录存储装置的结构示意图;6 is a schematic structural diagram of an operation record storage device in a database provided by an embodiment of this specification;
图7是用于配置本说明书实施例方法的一种设备的结构示意图。Fig. 7 is a schematic structural diagram of a device for configuring the method of the embodiment of this specification.
具体实施方式Detailed ways
为了使本领域技术人员更好地理解本说明书实施例中的技术方案,下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行详细地描述,显然,所描述的实施例仅仅是本说明书的一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员所获得的所有其他实施例,都应当属于保护的范围。In order to enable those skilled in the art to better understand the technical solutions in the embodiments of this specification, the technical solutions in the embodiments of this specification will be described in detail below in conjunction with the drawings in the embodiments of this specification. Obviously, the described implementation The examples are only a part of the embodiments in this specification, not all the embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art should fall within the scope of protection.
在中心化的数据库服务端,常常面向各种机构提供服务,各机构则可以将它们与第 三方用户(包括其它机构或者个人)之间所产生的数据记录在数据库服务方进行存储。如图1所示,图1为本说明书实施例所涉及的系统架构示意图。在该示意图中,一个企业机构可以面向多名用户,而每个用户均可以通过其对应的企业机构向数据库服务提供方进行查询。Centralized database server often provides services to various institutions, and each institution can record the data generated between them and third-party users (including other institutions or individuals) in the database server for storage. As shown in FIG. 1, FIG. 1 is a schematic diagram of a system architecture involved in an embodiment of the specification. In this schematic diagram, an enterprise organization can face multiple users, and each user can query the database service provider through its corresponding enterprise organization.
例如,数据库服务端对接的机构是某金融产品公司,数据记录可以是个人用户在该金融产品公司的理财记录;或者,对接的机构可以是政府部门,其中的数据记录是政府部门对于该部门所管理的公共项目的开销明细;或者,数据库服务方对接的机构是某个医院,其中的数据记录是病人的病历;或者,数据库服务方对接的机构是第三方支付机构,数据记录可以是个人用户通过该机构的支付记录,等等。For example, the organization connected to the database server is a financial product company, and the data records can be individual users’ financial management records in the financial product company; or, the connected organization can be a government department, where the data records are what the government department has for the department. Expense details of the managed public project; or, the database server is connected to a hospital, and the data record is the patient’s medical record; or the database server is connected to a third-party payment agency, and the data record can be an individual user Payment records through the agency, and so on.
数据库提供服务的方式可以是常规的关系型/非关系型数据结构,可以是块链式的数据结构。如图2所示,图2是本说明书实施例所提供的数据系统架构示意图。用户的数据被保存在图2中所示的账本主体中(可以是关系型的表格,块链式的账本等等)。其中的索引可以根据需要自行定义,例如,对于块链式的账本,索引中可以包含以数据记录的业务属性为主键,以块高和偏移序号为值的倒排索引;元数据部分可以对账本主体、索引以及其它信息进行统计,得到相关的信息,例如,元数据部分可以包括:账本中的数据记录总条数,账本中的数据块的总数量,账本中的业务属性总数量,数量排行前若干位的业务属性的数据记录的数量,账本中某业务属性所处的数据块的数量,等等。在一些业务场景下,元数据还可以对于某个业务属性进行状态计算,例如,在金融相关的场景下,数据记录是关于用户的支出/收入记录,或者是用户关于证券的买进/卖出记录等等,在这个方式下,元数据中还可以包括对于某些业务属性(例如用户的金额相关)的世界状态值。The way the database provides services can be a conventional relational/non-relational data structure, or a block-chain data structure. As shown in FIG. 2, FIG. 2 is a schematic diagram of the data system architecture provided by the embodiment of the present specification. The user's data is stored in the main body of the ledger shown in Figure 2 (it can be a relational table, a blockchain ledger, etc.). The index can be defined as needed. For example, for a blockchain ledger, the index can include an inverted index with the business attribute of the data record as the main key, and the block height and offset sequence number as the value; the metadata part can be Perform statistics on the main body, index and other information of the ledger to obtain relevant information. For example, the metadata part can include: the total number of data records in the ledger, the total number of data blocks in the ledger, the total number of business attributes in the ledger, and the quantity The number of data records of the top business attributes, the number of data blocks where a business attribute is located in the ledger, and so on. In some business scenarios, metadata can also perform state calculations for certain business attributes. For example, in financial-related scenarios, the data record is about the user's expenditure/income record, or the user's purchase/sale of securities Records and so on. In this way, the metadata can also include world state values for certain business attributes (for example, the user's amount of money).
在用户的数据记录被写入数据块之后,用户还可以对账本中的数据记录进行各种操作,例如,包括更新UPDATA、添加APPEND、清除PURGE、验证VERIFY、查询SELECT、隐匿OCCULT等等。在这个过程中就会产生相应的操作记录,操作记录则可以进行存储中的日志部分,或者也可以进行存储中的账本主体部分。基于此,本说明书实施例还提供一种块链式账本中的操作记录存储方法,如图3所示,图3为本说明书实施例所提供的块链式账本中的操作记录存储方法的流程示意图,包括以下步骤。After the user's data record is written into the data block, the user can also perform various operations on the data record in the ledger, for example, including updating UPDATA, adding APPEND, clearing PURGE, verifying VERIFY, querying SELECT, hiding OCCULT, and so on. In this process, corresponding operation records will be generated, and the operation records can be stored in the log part or the main part of the ledger in the storage. Based on this, the embodiment of this specification also provides a method for storing operation records in a block chain ledger, as shown in FIG. 3, which is the flow of the method for storing operation records in a block chain ledger provided by the embodiment of this specification. Schematic diagram, including the following steps.
S301,接收操作指令,所述操作指令中包含有业务属性。S301: Receive an operation instruction, where the operation instruction includes a business attribute.
如前所述,在常规的数据库中,操作指令可以采用常见的结构化查询语言(Structured Query Language,SQL),包括诸如UPDATA、APPEND、PURGE、VERIFY、SELECT、 OCCULT等等。As mentioned above, in conventional databases, operation instructions can use common structured query language (SQL), including such as UPDATA, APPEND, PURGE, VERIFY, SELECT, OCCULT, and so on.
例如SELECT(balance,FULL),查询在账本中以“balance”为业务属性的所有数据记录;又例如,UPDATA(key1,v1,v2),将账本中将包含有业务属性“key1”的数据记录中的v1替换为v2等等。操作指令可以来源于数据库服务端、对接机构或者对接机构的用户等等。For example, SELECT (balance, FULL), to query all data records with "balance" as the business attribute in the ledger; for example, UPDATA (key1, v1, v2), the ledger will contain data records with the business attribute "key1" Replace v1 in v2 with v2 and so on. The operating instructions can come from the database server, the docking organization, or the users of the docking organization, and so on.
在一些非常规的数据库中,操作指令也可以是用户所自定义的具有某些特定功能的语句,例如,在块链式账本中的清除PURGE(用于清除指定块高之前的数据块),隐匿OCCULT(用于隐藏某条指定数据记录的明文)等等。In some unconventional databases, operating instructions can also be user-defined statements with certain functions, such as clear PURGE (used to clear data blocks before the specified block height) in the block chain ledger. Hidden OCCULT (used to hide the plaintext of a specified data record) and so on.
业务属性可以是与用户的业务数据相关的字段,例如,用户ID、手机号、物品名称等等此处不做限制;业务属性也可以是与存储用户数据的账本主体、索引以及元数据相关的字段,例如,账本名称、索引名称、索引中的行列数值等等。Business attributes can be fields related to the user's business data, for example, user ID, mobile phone number, item name, etc. There are no restrictions here; business attributes can also be related to the main body of the ledger, index, and metadata that store user data Fields, such as the name of the ledger, the name of the index, the number of rows and columns in the index, and so on.
S303,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,确定操作影响特征值。S303: Evaluate the degree of change of the operation instruction to the data record containing the business attribute, and determine the operation influence characteristic value.
在用户通过操作指令对于数据记录进行操作时,相应的就会对数据记录产生影响。这里的影响变动程度主要包括“对于数据记录本身的改变”、“对于数据记录相关的索引的改变”以及“对于元数据的改变”等等。When the user operates the data record by operating instructions, the corresponding data record will be affected. The degree of impact change here mainly includes "changes to the data record itself", "changes to the index related to the data record", and "changes to the metadata" and so on.
具体而言,可以从多个方面综合性的进行评估。以下列举两个方面。Specifically, it can be comprehensively evaluated from multiple aspects. Two aspects are listed below.
第一,根据操作指令的类型进行评估。First, evaluate based on the type of operation instruction.
如前所述,操作指令包括多种类型,而不同类型的操作指令对于数据记录的影响程度是不一样的。例如,一个查询指令可能不会改变任何的数据记录或者元数据,而一条隐藏指令OCCULT可能影响到一条数据记录,而一条UPDATA则可能对于所有包含有指定业务属性的数据记录都会产生影响,以及对于索引和元数据都可能产生相应的影响。As mentioned earlier, there are many types of operating instructions, and different types of operating instructions have different effects on data recording. For example, a query command may not change any data records or metadata, while a hidden command OCCULT may affect a data record, and an UPDATA may affect all data records containing specified business attributes, and for Both indexing and metadata may have a corresponding impact.
因此,可以根据实际经验,赋予各操作指令相应的指令影响系数K,指令影响系数用于评估操作指令的操作影响特征值。例如,查询指令的K1=0,隐藏指令的K2=1等等。Therefore, according to actual experience, the corresponding command influence coefficient K can be assigned to each operation command, and the command influence coefficient is used to evaluate the operation influence characteristic value of the operation command. For example, K1=0 for query instructions, K2=1 for hidden instructions, and so on.
第二,根据包含有业务属性的数据记录的数量进行评估。Second, it is evaluated based on the number of data records containing business attributes.
如前所述,在常规的数据库或者块链式的数据库中,都可以包含于账本主体相关的元数据。例如,账本中的数据记录总条数、账本中的业务属性总数量以及数量排行前若 干位(例如,前20位)的业务属性的数据记录的数量。As mentioned earlier, in a conventional database or a block-chain database, metadata related to the main body of the ledger can be included. For example, the total number of data records in the ledger, the total number of business attributes in the ledger, and the number of business attribute data records in the top several rankings (for example, the top 20).
因此,对于一条包含有指定业务属性的操作指令,其可能影响多少条数据记录可以从元数据中直观的得到反映。Therefore, for an operation instruction containing a specified business attribute, how many data records it may affect can be intuitively reflected from the metadata.
例如,假设在元数据中,依序记录了前100名的包含某个业务属性的数据记录的数量,业务属性“key1”处于该表中,包含有业务属性“key1”的数据记录的数量条数为“N1”,则可以知道该操作指令可能影响到“N1”条数据记录。For example, suppose that in the metadata, the number of the top 100 data records containing a certain business attribute is recorded in sequence, the business attribute "key1" is in the table, and the number of data records containing the business attribute "key1" is in the table. If the number is "N1", it can be known that the operation instruction may affect the "N1" data records.
又例如,而假设在元数据中,业务属性“key2”不处于该表格中,则可以知道包含业务属性“key2”的数量不是特别多,可以推定不在前100的业务属性,所对应的数据记录的条数是均匀分布,因此,可以计算得到包含有业务属性“key2”的数量N2=(N总-N前100)/(数据记录总条数-100)。For another example, assuming that the business attribute "key2" is not in the table in the metadata, you can know that the number of business attributes "key2" is not particularly large, and it can be inferred that the business attributes that are not in the top 100 correspond to the data records The number of data records is uniformly distributed. Therefore, the number N2 that contains the business attribute "key2" can be calculated as N2 = (N total-N top 100)/(Total number of data records-100).
在这种情形下,可以根据操作指令可能影响到的数据记录的条数“N”进行评估,得到数据数量影响系数“M”,显然,M与可能影响到的数据记录的条数“N”是正相关的,例如“M=N”,或者“M=LnN”。In this case, you can evaluate the number of data records that may be affected by the operation instruction "N", and get the data quantity influence coefficient "M". Obviously, M and the number of data records that may be affected "N" It is positively correlated, such as "M=N" or "M=LnN".
对于操作影响特征值T的评估可以根据指令影响系数K和/或数据数量影响系数“M”综合进行,例如,T=K*M。以及,在实际应用中,还可以综合其它相关的因素,例如,操作指令本身的时间复杂度或者空间复杂度等等。总之,操作指令可能影响到的数据记录的变动程度越大,操作影响特征值T越大。The evaluation of the operation influence characteristic value T can be carried out comprehensively according to the command influence coefficient K and/or the data quantity influence coefficient "M", for example, T=K*M. And, in practical applications, other related factors can also be integrated, for example, the time complexity or space complexity of the operation instruction itself. In short, the greater the degree of change of the data record that may be affected by the operation instruction, the greater the characteristic value T of the operation influence.
S305,若所述操作影响特征值超过阈值,生成包含所述操作指令的操作记录,并存储。S305: If the operation influence characteristic value exceeds a threshold, an operation record containing the operation instruction is generated and stored.
若所述操作影响特征值超过阈值,说明该操作指令可能影响了多条数据记录以及元数据。如果在操作指令中记载每条数据记录的变化状态,则可能需要相当多的资源。If the operation influence characteristic value exceeds the threshold, it indicates that the operation instruction may have affected multiple data records and metadata. If the change status of each data record is recorded in the operation instruction, considerable resources may be required.
例如,假设一条UPDATA指令对于某业务属性所对应的值进行了统一更新,包含该业务属性的数据记录有1000条,那么,如果对每条数据记录的变化状态进行记载,则需在一条操作记录中记录1000条数据记录的前后变化。这显然需要耗费相当多的资源。For example, suppose that a UPDATA command uniformly updates the value corresponding to a certain business attribute, and there are 1000 data records containing the business attribute. Then, if the change status of each data record is recorded, it needs to be in an operation record Record 1000 data records before and after changes. This obviously requires considerable resources.
而此时如果采用记载操作指令的方式,那么,显然此时只需要在操作记录中包含有该操作指令即可。具体而言,生成的操作记录中还可以包括操作指令的接收时间、具体发送指令的用户标识等等,操作指令以明文形式存储。At this time, if the method of recording the operation instruction is adopted, then obviously only the operation instruction needs to be included in the operation record at this time. Specifically, the generated operation record may also include the receiving time of the operation instruction, the user ID of the specific sending instruction, etc., and the operation instruction is stored in plain text.
生成的操作记录可以存储在相应的日志文件中,在块链式账本中,生成的操作记录也可以写入到账本中的数据块中。The generated operation record can be stored in the corresponding log file. In the block chain ledger, the generated operation record can also be written into the data block in the ledger.
S307,否则,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,并存储。S307: Otherwise, determine the change state of the data record containing the business attribute, generate an operation record containing the change state, and store it.
所述操作影响特征值不超过阈值,则可以说明该操作记录可能仅仅影响了较少数量的数据记录。例如,对于一条操作指令APPEND(key1,V),仅仅是在数据库中添加了一条包含有业务属性“key1”的数据记录,在元数据中,可能导致的改变是“key1”所对应的数据记录的数量条数+1,或者,可能导致的改变是“key1”所对应的世界状态由当前值,变更为当前值加伤“V”中的相应数值。If the operation influence characteristic value does not exceed the threshold, it can indicate that the operation record may only affect a small number of data records. For example, for an operation instruction APPEND (key1, V), only a data record containing the business attribute "key1" is added to the database. In the metadata, the possible change is the data record corresponding to "key1" The number of items is +1, or the possible change is that the world state corresponding to "key1" is changed from the current value to the current value plus the corresponding value in "V".
甚至,如果该业务属性“key1”所对应的数据数量较少(例如,不处于数量前100的表格中),对元数据都不会造成有什么变化。Even if the amount of data corresponding to the business attribute "key1" is small (for example, it is not in the top 100 table), there will be no change to the metadata.
那么,此时可以分别确定有哪些数据记录或者元数据发生了改变,将对应的状态变化写入到操作记录中。Then, you can determine which data records or metadata have changed at this time, and write the corresponding state changes into the operation records.
具体而言,对于操作记录的变化,可以是直接记载数据记录本身的变化。即,确定发生变动的包含有所述业务属性的数据记录中,所述业务属性的初始值和变化值,生成包含有所述业务属性的初始值和变化值的操作记录。Specifically, for the change of the operation record, the change of the data record itself may be directly recorded. That is, it is determined that in the data record containing the business attribute that has changed, the initial value and the change value of the business attribute are determined, and the operation record containing the initial value and the change value of the business attribute is generated.
例如,假设一条操作指令仅仅改变了一条数据记录中“key1”的对应值从“0”变为“1”,对于元数据没有造成改变。则此时,在操作记录中仅仅需要记载该数据记录产生变化的数据记录的位置,业务属性key1,以及初始值(变化前的值)“0”和变化值(即产生变化后的值)“1”即可。For example, suppose an operation instruction only changes the corresponding value of "key1" in a data record from "0" to "1", which does not change the metadata. At this time, the operation record only needs to record the location of the data record where the data record has changed, the business attribute key1, and the initial value (the value before the change) "0" and the change value (that is, the value after the change) " 1" is fine.
在一种实施方式中,对于某些特定的实施场景,如果业务属性的累计值对于用户有特定的意义(例如,用户账户支出、收入的变化导致的账户余额,用户买入、卖出导致的利润值等等)。则此时,对于该操作指令,还可以确定包含有所述业务属性的数据记录中所述业务属性的累计状态值,生成包含有所述累计状态值的操作记录。在这种实施方式下,显然一条操作指令只会影响到累计状态值的1次变更。In one embodiment, for some specific implementation scenarios, if the cumulative value of the business attribute has a specific meaning to the user (for example, the account balance caused by the change in user account expenditure and income, the user’s buying or selling Profit value, etc.). At this time, for the operation instruction, the cumulative status value of the business attribute in the data record containing the business attribute can also be determined, and an operation record including the cumulative status value can be generated. In this embodiment, it is obvious that one operation instruction will only affect one change of the accumulated state value.
在影响到的数据记录不多的时候,通过记录少量数据记录的初始值、变化值以及累计状态值的变化,同样也无需消耗太多资源。When there are not many data records that are affected, by recording the initial value, change value, and change of the cumulative status value of a small amount of data records, too much resources are not required to be consumed.
在一种实施方式下,记录数据记录的状态值的时候,还可以通过对于数据记录的前后变化进行完整的记录,以及记录发生变动前的数据记录的第一数据哈希值和发生变动 后的数据记录的第二数据哈希值,生成包含有所述第一数据哈希值和第二数据哈希值的操作记录。In one embodiment, when recording the state value of the data record, it is also possible to record the before and after changes of the data record completely, and record the first data hash value of the data record before the change and the data record after the change. The second data hash value of the data record generates an operation record containing the first data hash value and the second data hash value.
在这种方式下,数据记录变化前的哈希值以及数据记录变化前的原文都得到了记载,在数据进行回滚的时候,还可以根据数据记录的第一数据哈希值进行校验:即在回滚后重新计算数据记录的回滚哈希值,与第一数据哈希值进行对比,如果一致,则说明回滚正确无误,保证了数据回滚的正确性。第二数据哈希值用于下一次数据状态发生变化时,以及,用于操作记录中根据第一数据哈希值和第二数据哈希值进行追溯。In this way, both the hash value before the data record change and the original text before the data record change are recorded. When the data is rolled back, it can also be verified according to the first data hash value of the data record: That is, after the rollback, the rollback hash value of the data record is recalculated and compared with the first data hash value. If it is consistent, the rollback is correct and the correctness of the data rollback is ensured. The second data hash value is used when the data state changes next time, and is used to trace back according to the first data hash value and the second data hash value in the operation record.
通过本说明书实施例所提供的方案,在生成操作记录前,首先评估操作指令对于包含业务属性的数据记录可能产生的变动程度,如果变动程度很大,就记载操作指令,生成包含操作指令的操作记录,进行存储;如果变动程度不大,就记载发生了变化的数据记录或者与其相关的哈希值,生成包含了前述状态变化的操作记录,并进行存储。通过评估操作指令可能产生的影响,动态的生成相关的操作记录,在保障可以准确的回溯数据状态时,节省了存储操作记录时的系统开销,实现灵活的操作记录存储方法。Through the solution provided by the embodiment of this specification, before generating the operation record, first evaluate the degree of change that the operation instruction may have on the data record containing the business attribute. If the degree of change is large, record the operation instruction and generate the operation containing the operation instruction Record and store; if the degree of change is not large, record the changed data record or its related hash value, generate an operation record containing the aforementioned state change, and store it. By evaluating the possible impact of the operation instructions, the relevant operation records are dynamically generated, while ensuring that the data status can be accurately traced back, the system overhead when storing the operation records is saved, and a flexible operation record storage method is realized.
在一种实施方式中,本说明书实施例中所涉及的数据库可以是以块链式账本对外提供服务的中心化的数据库。这里的块链式账本可以是区块链账本,也可以是中心化的类区块链账本。In an implementation manner, the database involved in the embodiment of this specification may be a centralized database that provides services to external parties with a blockchain ledger. The blockchain ledger here can be either a blockchain ledger or a centralized blockchain-like ledger.
在中心化的数据库服务提供方,块链式的账本通过如下方式生成,如图4所示,图4为本说明书实施例所提供的一种生成块链式账本的流程示意图,包括:At the centralized database service provider, the block chain ledger is generated in the following manner, as shown in Figure 4. Figure 4 is a schematic diagram of the process of generating a block chain ledger provided by the embodiment of this specification, including:
S401,接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性。S401: Receive a data record to be stored, and determine a hash value of each data record, where the data record contains business attributes.
如前所述,此处的待存储的数据记录,可以是客户端个人用户的各种消费记录,也可以是应用服务器基于用户的指令,在执行业务逻辑时产生的业务结果、中间状态以及操作记录等等。具体的业务场景可以包括消费记录、审计日志、供应链条、政府监管记录、医疗记录等等。As mentioned earlier, the data records to be stored here can be various consumption records of individual users on the client side, or they can be business results, intermediate states, and operations generated when the application server executes business logic based on user instructions. Records and so on. Specific business scenarios can include consumption records, audit logs, supply chains, government supervision records, medical records, and so on.
在本说明书实施例中,数据记录中包含有业务属性,在每个与数据库服务方对接的机构中,所述业务属性在所述对接机构中,一般而言是唯一存在的,业务属性基于不同的业务场景,可以包括用户名、用户身份证号、驾照编号、手机号、项目唯一编号等等。In the embodiment of this specification, the data record contains business attributes. In each organization that connects with the database server, the business attribute is generally the only one in the docking organization, and the business attributes are based on different The business scenarios of, can include user name, user ID number, driver’s license number, mobile phone number, project unique number, etc.
例如,对于第三方支付机构而言,数据记录是用户的消费记录,此时的业务属性即为用户标识(包括手机号、身份证号、用户名等等),或者对该用户标识进行哈希算法 所得到的哈希值;或者,对于政府机构而言,数据记录为多个公共项目的开销流水,则此时的业务属性可以为每个项目的唯一编号。For example, for a third-party payment institution, the data record is the user's consumption record, and the business attribute at this time is the user ID (including mobile phone number, ID number, user name, etc.), or the user ID is hashed The hash value obtained by the algorithm; or, for government agencies, the data record is the overhead flow of multiple public projects, then the business attribute at this time can be a unique number for each project.
业务属性可以存储于数据记录中的指定字段(例如,数据记录的头部或者尾部),从而可以方便数据库服务端以及用户从中获取该数据记录的业务属性。The business attribute can be stored in a designated field in the data record (for example, the head or tail of the data record), so that the database server and the user can easily obtain the business attribute of the data record from it.
需要说明的是,在同一账本中,可以包含有多条数据记录。这些数据记录的业务属性则很可能是不一样的。例如,在一个账本面向多个用户开放时,数据记录可能来源于不同的的用户,若业务属性为用户标识,则容易理解不同的数据记录中常常包含了不同的用户标识。It should be noted that multiple data records can be included in the same ledger. The business attributes of these data records are likely to be different. For example, when a ledger is open to multiple users, the data records may come from different users. If the business attribute is a user ID, it is easy to understand that different data records often contain different user IDs.
S403,当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块。S403: When a preset block forming condition is reached, determine each data record to be written in the data block, and generate an Nth data block including the hash value of the data block and the data record.
所述预设的成块条件包括:待存储的数据记录数量达到数量阈值,例如,每接收到一千条数据记录时,生成一个新数据块,将一千条数据记录写入块中;或者,距离上一次成块时刻的时间间隔达到时间阈值,例如,每隔5分钟,生成一个新数据块,将在这5分钟内接收到的数据记录写入块中。The preset blocking 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.
此处的N指的是数据块的序号,换言之,在本说明书实施例中,数据块是以块链的形式,基于成块时间的顺序先后排列,具有很强的时序特征。其中,数据块的块高基于成块时间的先后顺序单调递增。块高可以是序号,此时第N个数据块的块高即为N;块高也可以其它方式生成。Here, N refers to the serial number of the data block. In other words, in the embodiment of this specification, 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 strong timing characteristics. Among them, 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.
当N=1时,即此时的数据块为为初始数据块。初始数据块的哈希值和块高基于预设方式给定。例如,初始数据块中不包含数据记录,哈希值则为任一给定的哈希值,块高blknum=0;又例如,初始数据块的生成触发条件与其它数据块的触发条件一致,但是初始数据块的哈希值由对初始数据块中的所有内容取哈希确定。When N=1, that is, the data block at this time is the initial data block. The hash value and block height of the initial data block are given based on a preset method. For example, if the initial data block does not contain data records, the hash value is any given hash value, and the block height blknum=0; for another example, the generation trigger condition of the initial data block is consistent with the trigger conditions of other data blocks. However, the hash value of the initial data block is determined by hashing all the contents in the initial data block.
当N>1时,由于前一数据块的内容和哈希值已经确定,则此时,可以基于前一数据块(即第N-1个数据块)的哈希值生成当前数据块(第N个数据块)的哈希值,例如,一种可行的方式为,确定每一条将要写入第N个块中的数据记录的哈希值,按照在块中的排列顺序,生成一个默克尔树,将默克尔树的根哈希值和前一数据块的哈希值拼接在一起,再次采用哈希算法,生成当前块的哈希值。又例如,还可以按照块中数据记录的顺序进行拼接并取哈希得到整体数据记录的哈希值,拼接前一数据块的哈希值和整体数据记录的哈希值,并对拼接得到的字串进行哈希运算,生成数据块的哈希值。When N>1, since the content and hash value of the previous data block have been determined, at this time, 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 order 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. For another example, it is also possible to splice according to the order of the data records in the block and obtain the hash value of the entire data record by hashing, splicing the hash value of the previous data block and the hash value of the entire data record, and combining the result The string is hashed to generate the hash value of the data block.
用户在上传数据成功后,即可以得到对应的数据记录的哈希值以及所处的数据块的哈希值,并保存,并且可以基于该哈希值发起完整性验证。具体的验证方式包括重新计算数据记录自身的哈希值以及所处的数据块的哈希值,与本地所保存的进行对比。After the user uploads the data successfully, 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 includes recalculating the hash value of the data record itself and the hash value of the data block in which it is located, and comparing it with the locally stored hash value.
上述方式生成的数据块,可以包括块头和块体两个部分。块体中可以用于存储拼接数据的明文,或者拼接数据的哈希值等等;块头中可以用于存储有关本数据块的元数据,例如,账本的版本号,前一数据块的哈希值,自身数据块中的拼接数据所组成的默克尔树的根哈希值,自身数据块的哈希值,用于记录拼接数据的被操作状态的状态数组等等。如图5所示,图5为本说明书实施例所提供的一种数据块的块头的示意图。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 spliced data, or the hash value of the spliced data, 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 the spliced data in the own data block, the hash value of the own data block, the state array used to record the operated state of the spliced data, and so on. As shown in FIG. 5, FIG. 5 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
通过前述方式,用户的数据记录被保存在了块链式账本中,并且可以随时发起完整性验证,从而保证用户的数据不会被篡改。同时需要说明的是,在本说明书实施例中,块链式账本是一个广义上的账本,其不仅仅包括存储用户的数据记录的那一部分结构,也包括存储与数据记录相关的元数据、操作日志、索引等等部分。Through the foregoing method, the user's data record is stored in the blockchain ledger, and integrity verification can be initiated at any time, thereby ensuring that the user's data will not be tampered with. At the same time, it should be noted that in the embodiments of this specification, the blockchain ledger is a broadly defined ledger, which not only includes the part of the structure that stores the user's data record, but also includes the storage of metadata and operations related to the data record. Logs, indexes, and so on.
在这种实施场景下,数据记录被存储在不可篡改的块链式账本中,但是数据库服务端同样可以对某个业务属性的“状态数据”(包括累计值、是否被操作、被操作时间等等)进行计算。例如,针对某个业务属性,在索引表或者元数据中的指定区域块中记载该业务属性的相关的状态数据。In this implementation scenario, data records are stored in a non-tamperable block chain ledger, but the database server can also check the "status data" of a certain business attribute (including accumulated value, whether it has been operated, the time it has been operated, etc.) Etc.) to calculate. For example, for a certain business attribute, the status data related to the business attribute is recorded in a designated area block in the index table or metadata.
此时,如果用户针对某个业务属性进行了相应的操作,则会导致该区域中的某些值发生变化。则此时,数据库服务端可以根据业务属性,确定发生变动的包含有所述业务属性的指定区域块,进而确定发生变动前的指定区域块的第一块哈希值和发生变动后的所述指定区域块的第二块哈希值,生成包含有所述第一块哈希值和第二块哈希值的操作记录。At this time, if the user performs a corresponding operation for a certain business attribute, some values in the area will change. At this time, the database server can determine the changed designated area block containing the business attribute according to the business attribute, and then determine the first block hash value of the designated area block before the change and the changed Specify the second block of the hash value of the area block, and generate an operation record containing the first block of the hash value and the second block of the hash value.
第一块哈希值与第二块哈希值的作用于前述的第一数据哈希值和第二数据哈希值的作用类似,用于所述的指定区域块的回滚与追溯,以保证数据回滚时的准确。The first block of hash value and the second block of hash value have similar functions to the aforementioned first data hash value and second data hash value, and are used for the rollback and traceability of the specified area block. Ensure the accuracy of data rollback.
显然,在生成的操作记录中还可以包含有指定表区块的位置标示,以及所述业务属性,以便进行追溯与回滚。Obviously, the generated operation record may also include the position mark of the designated table block and the business attribute for traceability and rollback.
对应的,本说明书实施例还提供一种数据库中的操作记录存储装置,如图6所示,图6是本说明书实施例提供的一种数据库中的操作记录存储装置的结构示意图,包括以下模块。Correspondingly, an embodiment of this specification also provides an operation record storage device in a database, as shown in FIG. 6, which is a schematic structural diagram of an operation record storage device in a database provided by an embodiment of this specification, including the following modules .
接收模块601,接收操作指令,所述操作指令中包含有业务属性。The receiving module 601 receives an operation instruction, and the operation instruction includes a business attribute.
评估模块603,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,确定操作影响特征值,其中,所述操作影响特征值与包含有所述业务属性的数据记录的变动程度正相关。The evaluation module 603 evaluates the degree of change of the operation instruction to the data record containing the business attribute, and determines the operation influence characteristic value, wherein the operation influence characteristic value and the degree of change of the data record containing the business attribute Positive correlation.
第一存储模块605,若所述操作影响特征值超过阈值,生成包含所述操作指令的操作记录,并存储。The first storage module 605, if the operation influence characteristic value exceeds a threshold, generates an operation record containing the operation instruction, and stores it.
第二存储模块607,否则,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,并存储。The second storage module 607, otherwise, determines the change state of the data record containing the business attribute, generates an operation record containing the change state, and stores it.
进一步地,在所述装置中,所述评估模块603,根据所述操作指令的类型,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度。Further, in the device, the evaluation module 603 evaluates the degree of change of the operation instruction to the data record containing the business attribute according to the type of the operation instruction.
进一步地,在所述装置中,所述评估模块603,确定包含有所述业务属性的数据记录的数量,根据所述数量评估所述操作指令对于包含有所述业务属性的数据记录的变动程度。Further, in the device, the evaluation module 603 determines the number of data records containing the business attribute, and evaluates the degree of change of the operation instruction to the data records containing the business attribute according to the number .
进一步地,在所述装置中,所述第二存储模块607,确定发生变动的包含有所述业务属性的数据记录中,所述业务属性的初始值和变化值,生成包含有所述业务属性的初始值和变化值的操作记录;或者,确定包含有所述业务属性的数据记录中所述业务属性的累计状态值,生成包含有所述累计状态值的操作记录。Further, in the device, the second storage module 607 determines that in the changed data record containing the business attribute, the initial value and the changed value of the business attribute are generated to contain the business attribute Or, determine the cumulative status value of the business attribute in the data record containing the business attribute, and generate the operation record containing the cumulative status value.
进一步地,在所述装置中,所述第二存储模块607,确定发生变动的包含有所述业务属性的数据记录中,发生变动前的数据记录的第一数据哈希值和发生变动后的数据记录的第二数据哈希值,生成包含有所述第一数据哈希值和第二数据哈希值的操作记录。Further, in the device, the second storage module 607 determines that among the changed data records containing the business attributes, the first data hash value of the data record before the change and the data record after the change The second data hash value of the data record generates an operation record containing the first data hash value and the second data hash value.
进一步地,在所述装置中,当所述数据记录存储在块链式账本中时,所述第二存储模块607,确定发生变动的包含有所述业务属性的指定区域块;确定发生变动前的指定区域块的第一块哈希值和发生变动后的所述指定区域块的第二块哈希值,生成包含有所述第一块哈希值和第二块哈希值的操作记录。Further, in the device, when the data record is stored in the block-chain ledger, the second storage module 607 determines the designated area block containing the business attribute that has changed; and determines that before the change occurs The first block hash value of the designated area block and the second block hash value of the designated area block after the change occurs, and an operation record containing the first block hash value and the second block hash value is generated .
进一步地,所述装置还包括数据块生成模块609,接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性;当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:当N=1时,初始数据块的哈希值和块高基于预设方式给定;当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块,其中,数据块的 块高基于成块时间的先后顺序单调递增。Further, the device further includes a data block generation module 609, which receives the data records to be stored and determines the hash value of each data record. The data record contains the business attribute; when the preset block condition is reached, it is determined For each data record in the data block to be written, the Nth data block containing the hash value of the data block and the data record is generated, which specifically includes: when N=1, the hash value and block height of the initial data block are based on the preset value. The setting method is given; when N>1, the hash value of the Nth data block is determined according to the data records in the data block to be written and the hash value of the N-1th data block, and the Nth data block is generated. The hash value of the data block and the Nth data block of each data record, wherein the block height of the data block increases monotonically based on the sequence of the block time.
进一步地,在所述装置中,所述预设的成块条件包括:待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。Further, in the device, 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.
本说明书实施例还提供一种计算机设备,其至少包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,处理器执行所述程序时实现图3所示的操作记录存储防控方法。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 operations shown in FIG. 3 when the program is executed. Record storage prevention and control methods.
图7示出了本说明书实施例所提供的一种更为具体的计算设备硬件结构示意图,该设备可以包括:处理器1010、存储器1020、输入/输出接口1030、通信接口1040和总线1050。其中处理器1010、存储器1020、输入/输出接口1030和通信接口1040通过总线1050实现彼此之间在设备内部的通信连接。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.
处理器1010可以采用通用的CPU(Central Processing Unit,中央处理器)、微处理器、应用专用集成电路(Application Specific Integrated Circuit,ASIC)、或者一个或多个集成电路等方式实现,用于执行相关程序,以实现本说明书实施例所提供的技术方案。The processor 1010 may be implemented by 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 realize the technical solutions provided in the embodiments of this specification.
存储器1020可以采用ROM(Read Only Memory,只读存储器)、RAM(Random Access Memory,随机存取存储器)、静态存储设备,动态存储设备等形式实现。存储器1020可以存储操作系统和其他应用程序,在通过软件或者固件来实现本说明书实施例所提供的技术方案时,相关的程序代码保存在存储器1020中,并由处理器1010来调用执行。The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (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 this specification are implemented by software or firmware, related program codes are stored in the memory 1020 and called and executed by the processor 1010.
输入/输出接口1030用于连接输入/输出模块,以实现信息输入及输出。输入输出/模块可以作为组件配置在设备中(图中未示出),也可以外接于设备以提供相应功能。其中输入设备可以包括键盘、鼠标、触摸屏、麦克风、各类传感器等,输出设备可以包括显示器、扬声器、振动器、指示灯等。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 it 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.
通信接口1040用于连接通信模块(图中未示出),以实现本设备与其他设备的通信交互。其中通信模块可以通过有线方式(例如USB、网线等)实现通信,也可以通过无线方式(例如移动网络、WIFI、蓝牙等)实现通信。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.).
总线1050包括一通路,在设备的各个组件(例如处理器1010、存储器1020、输入/输出接口1030和通信接口1040)之间传输信息。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).
需要说明的是,尽管上述设备仅示出了处理器1010、存储器1020、输入/输出接口1030、通信接口1040以及总线1050,但是在具体实施过程中,该设备还可以包括实现正常运行所必需的其他组件。此外,本领域的技术人员可以理解的是,上述设备中也可 以仅包含实现本说明书实施例方案所必需的组件,而不必包含图中所示的全部组件。It should be noted that although the above device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040, and the bus 1050, in the specific implementation process, the device may also include the equipment necessary for normal operation. Other components. In addition, those skilled in the art can understand that the above-mentioned device may also include only the components necessary to implement the solutions of the embodiments of the present specification, and not necessarily include all the components shown in the figures.
本说明书实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现图3所示的操作记录存储方法。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 operation record storage method shown in FIG. 3 is implemented.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。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.
通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本说明书实施例可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本说明书实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本说明书实施例各个实施例或者实施例的某些部分所述的方法。From the description of the foregoing implementation manners, it can be understood that those skilled in the art can clearly understand that the embodiments of this specification can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions of the embodiments of this specification can be embodied in the form of software products, which can be stored in storage media, such as ROM/RAM, A magnetic disk, an optical disk, etc., include several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute the methods described in the various embodiments or some parts of the embodiments of this specification.
上述实施例阐明的系统、方法、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, methods, modules, or units explained in the above embodiments may be implemented by computer chips or entities, or implemented by products with certain functions. 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.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于方法实施例而言,由于其基本相似于方法实施例,所以描述得比较简单,相关之处参见方法实施例的部分说明即可。以上所描述的方法实施例仅仅是示意性的,其中所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,在实施本说明书实施例方案时可以把各模块的功能在同一个或多个软件和/或硬件中实现。也可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出 创造性劳动的情况下,即可以理解并实施。The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the method embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiment. The method embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separated. When implementing the solutions of the embodiments of this specification, the functions of the modules may be in the same Or multiple software and/or hardware implementations. It is also possible to select some or all of the modules according to actual needs to achieve the objectives of the solutions of the embodiments. Those of ordinary skill in the art can understand and implement it without creative work.
以上所述仅是本说明书实施例的具体实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本说明书实施例原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本说明书实施例的保护范围。The above are only specific implementations of the embodiments of this specification. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of the embodiments of this specification, several improvements and modifications can be made. These Improvement and retouching should also be regarded as the protection scope of the embodiments of this specification.

Claims (17)

  1. 一种数据库中的操作记录存储方法,包括:A method for storing operation records in a database, including:
    接收操作指令,所述操作指令中包含有业务属性;Receiving an operation instruction, where the operation instruction includes a business attribute;
    评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,确定操作影响特征值,其中,所述操作影响特征值与包含有所述业务属性的数据记录的变动程度正相关;Evaluating the degree of change of the operation instruction to the data record containing the business attribute, and determining the operation influence characteristic value, wherein the operation influence characteristic value is positively correlated with the degree of change of the data record containing the business attribute;
    若所述操作影响特征值超过阈值,生成包含所述操作指令的操作记录,并存储;If the operation influence characteristic value exceeds the threshold, an operation record containing the operation instruction is generated and stored;
    否则,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,并存储。Otherwise, the change state of the data record containing the business attribute is determined, and the operation record containing the change state is generated and stored.
  2. 如权利要求1所述的方法,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,包括:The method of claim 1, evaluating the degree of change of the operation instruction to the data record containing the business attribute, comprising:
    根据所述操作指令的类型,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度。According to the type of the operation instruction, the degree of change of the operation instruction to the data record containing the business attribute is evaluated.
  3. 如权利要求1所述的方法,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,包括:The method of claim 1, evaluating the degree of change of the operation instruction to the data record containing the business attribute, comprising:
    确定包含有所述业务属性的数据记录的数量,根据所述数量评估所述操作指令对于包含有所述业务属性的数据记录的变动程度。The number of data records containing the business attribute is determined, and the degree of change of the operation instruction to the data records containing the business attribute is evaluated according to the number.
  4. 如权利要求要求1所述的方法,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,包括:The method of claim 1, determining the change state of the data record containing the business attribute, and generating the operation record containing the change state, comprising:
    确定发生变动的包含有所述业务属性的数据记录中,所述业务属性的初始值和变化值,生成包含有所述业务属性的初始值和变化值的操作记录;Determine the initial value and the change value of the business attribute in the changed data record containing the business attribute, and generate an operation record that includes the initial value and the change value of the business attribute;
    或者,确定包含有所述业务属性的数据记录中所述业务属性的累计状态值,生成包含有所述累计状态值的操作记录。Alternatively, the cumulative status value of the business attribute in the data record containing the business attribute is determined, and an operation record including the cumulative status value is generated.
  5. 如权利要求1所述的方法,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,包括:The method of claim 1, determining the change state of the data record containing the business attribute, and generating the operation record containing the change state, comprising:
    确定发生变动的包含有所述业务属性的数据记录中,发生变动前的数据记录的第一数据哈希值和发生变动后的数据记录的第二数据哈希值,生成包含有所述第一数据哈希值和第二数据哈希值的操作记录。Determine the changed data record containing the business attribute, the first data hash value of the data record before the change and the second data hash value of the data record after the change, and generate the data record containing the first Operation record of the hash value of the data and the hash value of the second data.
  6. 如权利要求1所述的方法,当所述数据记录存储在块链式账本中时,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,包括:The method of claim 1, when the data record is stored in a blockchain ledger, determining the change state of the data record containing the business attribute, and generating an operation record containing the change state, include:
    确定发生变动的包含有所述业务属性的指定区域块;Determine the changed designated area block containing the business attribute;
    确定发生变动前的指定区域块的第一块哈希值和发生变动后的所述指定区域块的第二块哈希值,生成包含有所述第一块哈希值和第二块哈希值的操作记录。Determine the first block hash value of the designated area block before the change and the second block hash value of the designated area block after the change, and generate the first block hash value and the second block hash value Operation record of the value.
  7. 如权利要求6所述的方法,所述块链式账本通过如下方式预先生成:The method according to claim 6, wherein the block chain ledger is pre-generated in the following manner:
    接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性;Receive the data records to be stored and determine the hash value of each data record, where the data record contains business attributes;
    当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:When the preset blocking condition is 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:
    当N=1时,初始数据块的哈希值和块高基于预设方式给定;When N=1, the hash value and block height of the initial data block are given based on a preset method;
    当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块,其中,数据块的块高基于成块时间的先后顺序单调递增。When N>1, determine the hash value of the Nth data block according to the data records in the data block to be written and the hash value of the N-1th data block, and generate a hash containing the Nth data block The value and the Nth data block of each data record, where the block height of the data block increases monotonically based on the sequence of the block time.
  8. 如权利要求7所述的方法,所述预设的成块条件包括:8. The method of claim 7, wherein the preset blocking condition comprises:
    待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。The number of data records to be stored reaches the number threshold; or, the time interval from the last block time reaches the time threshold.
  9. 一种数据库中的操作记录存储装置,包括:An operation record storage device in a database, including:
    接收模块,接收操作指令,所述操作指令中包含有业务属性;The receiving module receives an operation instruction, and the operation instruction contains business attributes;
    评估模块,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度,确定操作影响特征值,其中,所述操作影响特征值与包含有所述业务属性的数据记录的变动程度正相关;The evaluation module evaluates the degree of change of the operation instruction to the data record containing the business attribute, and determines the operation influence characteristic value, wherein the degree of change of the operation influence characteristic value and the data record containing the business attribute is positive Related
    第一存储模块,若所述操作影响特征值超过阈值,生成包含所述操作指令的操作记录,并存储;The first storage module, if the operation influence characteristic value exceeds a threshold value, generate an operation record containing the operation instruction, and store it;
    第二存储模块,否则,确定所述包含有所述业务属性的数据记录的变动状态,生成包含有所述变动状态的操作记录,并存储。The second storage module, otherwise, determines the change state of the data record containing the business attribute, generates and stores the operation record containing the change state.
  10. 如权利要求9所述的装置,所述评估模块,根据所述操作指令的类型,评估所述操作指令对于包含有所述业务属性的数据记录的变动程度。9. The device according to claim 9, wherein the evaluation module evaluates the degree of change of the operation instruction to the data record containing the business attribute according to the type of the operation instruction.
  11. 如权利要求9所述的装置,所述评估模块,确定包含有所述业务属性的数据记录的数量,根据所述数量评估所述操作指令对于包含有所述业务属性的数据记录的变动程度。9. The apparatus according to claim 9, wherein the evaluation module determines the number of data records containing the business attribute, and evaluates the degree of change of the operation instruction to the data records containing the business attribute according to the number.
  12. 如权利要求9所述的装置,所述第二存储模块,确定发生变动的包含有所述业务属性的数据记录中,所述业务属性的初始值和变化值,生成包含有所述业务属性的初 始值和变化值的操作记录;或者,确定包含有所述业务属性的数据记录中所述业务属性的累计状态值,生成包含有所述累计状态值的操作记录。9. The device according to claim 9, wherein the second storage module determines the initial value and the changed value of the business attribute in the changed data record containing the business attribute, and generates a data record containing the business attribute Operation records of the initial value and the change value; or, determining the cumulative status value of the business attribute in the data record containing the business attribute, and generating the operation record containing the cumulative status value.
  13. 如权利要求9所述的装置,所述第二存储模块,确定发生变动的包含有所述业务属性的数据记录中,发生变动前的数据记录的第一数据哈希值和发生变动后的数据记录的第二数据哈希值,生成包含有所述第一数据哈希值和第二数据哈希值的操作记录。The device according to claim 9, wherein the second storage module determines that among the changed data records containing the business attributes, the first data hash value of the data record before the change and the data after the change The recorded second data hash value generates an operation record containing the first data hash value and the second data hash value.
  14. 如权利要求9所述的装置,当所述数据记录存储在块链式账本中时,所述第二存储模块,确定发生变动的包含有所述业务属性的指定区域块;确定发生变动前的指定区域块的第一块哈希值和发生变动后的所述指定区域块的第二块哈希值,生成包含有所述第一块哈希值和第二块哈希值的操作记录。9. The device according to claim 9, when the data record is stored in a block chain ledger, the second storage module determines the designated area block containing the business attribute that has changed; and determines the data before the change The hash value of the first block of the designated area block and the hash value of the second block of the designated area block after the change are generated, and an operation record containing the hash value of the first block and the hash value of the second block is generated.
  15. 如权利要求9所述的装置,还包括数据块生成模块,接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性;当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:The device according to claim 9, further comprising a data block generating module, which receives the data records to be stored and determines the hash value of each data record, wherein the data record contains the business attribute; when the preset block condition is reached , Determine each data record in the data block to be written, and generate the Nth data block containing the hash value of the data block and the data record, which specifically includes:
    当N=1时,初始数据块的哈希值和块高基于预设方式给定;When N=1, the hash value and block height of the initial data block are given based on a preset method;
    当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块,其中,数据块的块高基于成块时间的先后顺序单调递增。When N>1, determine the hash value of the Nth data block according to each data record to be written in the data block and the hash value of the N-1th data block, and generate a hash containing the Nth data block The value and the Nth data block of each data record, where the block height of the data block increases monotonically based on the sequence of the block time.
  16. 如权利要求9所述的装置,所述预设的成块条件包括:待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。9. The device according to claim 9, wherein the preset blocking condition comprises: 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.
  17. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,所述处理器执行所述程序时实现如权利要求1至8任一项所述的方法。A computer device, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the processor executes the program as described in any one of claims 1 to 8 method.
PCT/CN2020/117005 2019-11-11 2020-09-23 Method and apparatus for storing operation record in database, and device WO2021093462A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911094100.4A CN111046052B (en) 2019-11-11 2019-11-11 Method, device and equipment for storing operation records in database
CN201911094100.4 2019-11-11

Publications (1)

Publication Number Publication Date
WO2021093462A1 true WO2021093462A1 (en) 2021-05-20

Family

ID=70231903

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/117005 WO2021093462A1 (en) 2019-11-11 2020-09-23 Method and apparatus for storing operation record in database, and device

Country Status (2)

Country Link
CN (1) CN111046052B (en)
WO (1) WO2021093462A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111046052B (en) * 2019-11-11 2021-04-06 蚂蚁区块链科技(上海)有限公司 Method, device and equipment for storing operation records in database
CN111444215A (en) * 2020-06-12 2020-07-24 支付宝(杭州)信息技术有限公司 Blocking method, device and equipment in block chain type account book
US20230409594A1 (en) * 2022-06-15 2023-12-21 International Business Machines Corporation Conditional replication of data

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104715041A (en) * 2015-03-24 2015-06-17 深圳市乾华数据科技有限公司 Database recovery method and system
CN107145403A (en) * 2017-04-20 2017-09-08 浙江工业大学 The relevant database data retrogressive method of web oriented development environment
US20180329931A1 (en) * 2017-05-10 2018-11-15 Dropbox, Inc. Automatically coordinating application schema changes in a distributed data storage system
CN110020547A (en) * 2019-01-31 2019-07-16 阿里巴巴集团控股有限公司 A kind of data hiding method, device and equipment
CN110362570A (en) * 2019-06-20 2019-10-22 阿里巴巴集团控股有限公司 A kind of date storage method, device and equipment
CN111046052A (en) * 2019-11-11 2020-04-21 支付宝(杭州)信息技术有限公司 Method, device and equipment for storing operation records in database

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4697126B2 (en) * 2006-11-21 2011-06-08 株式会社デンソー Soft decision correction method, receiver, program
CN102073555A (en) * 2009-11-24 2011-05-25 联想(北京)有限公司 Backup method, device for backing up and computer
CN110046162B (en) * 2019-03-26 2023-06-20 创新先进技术有限公司 Auxiliary evidence storage method, system, device and equipment
CN110275916B (en) * 2019-05-23 2021-01-12 创新先进技术有限公司 Data operation record storage method, system, device and equipment
CN110347679B (en) * 2019-06-20 2020-08-04 阿里巴巴集团控股有限公司 Data storage method, device and equipment based on receipt

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104715041A (en) * 2015-03-24 2015-06-17 深圳市乾华数据科技有限公司 Database recovery method and system
CN107145403A (en) * 2017-04-20 2017-09-08 浙江工业大学 The relevant database data retrogressive method of web oriented development environment
US20180329931A1 (en) * 2017-05-10 2018-11-15 Dropbox, Inc. Automatically coordinating application schema changes in a distributed data storage system
CN110020547A (en) * 2019-01-31 2019-07-16 阿里巴巴集团控股有限公司 A kind of data hiding method, device and equipment
CN110362570A (en) * 2019-06-20 2019-10-22 阿里巴巴集团控股有限公司 A kind of date storage method, device and equipment
CN111046052A (en) * 2019-11-11 2020-04-21 支付宝(杭州)信息技术有限公司 Method, device and equipment for storing operation records in database

Also Published As

Publication number Publication date
CN111046052A (en) 2020-04-21
CN111046052B (en) 2021-04-06

Similar Documents

Publication Publication Date Title
WO2021073242A1 (en) Index creation and data querying methods, apparatus and device
US10255108B2 (en) Parallel execution of blockchain transactions
WO2021093462A1 (en) Method and apparatus for storing operation record in database, and device
CN110188096B (en) Index creating method, device and equipment for data record
WO2020233146A1 (en) Data operation record storage method, system and apparatus, and device
TWI706259B (en) Data query method and query device
WO2020211569A1 (en) Method for constructing index of data record
CN110162662B (en) Verification method, device and equipment for data records in block chain type account book
WO2021017422A1 (en) Index creation method in block chain type account book, device and apparatus
US20120023586A1 (en) Determining privacy risk for database queries
WO2020244237A1 (en) Verification method, device and apparatus for blockchain ledger
WO2020244239A1 (en) Index creation method, apparatus and device based on service identifier
US10025878B1 (en) Data lineage analysis
WO2020244238A1 (en) Data storage method, device and apparatus employing multilevel blockchain ledgers
CA2957674C (en) Testing insecure computing environments using random data sets generated from characterizations of real data sets
WO2020211497A1 (en) Method, system, apparatus and device for storing personal asset change record
WO2021073240A1 (en) Method, device, and apparatus for storing data in blockchain ledger
US10089334B2 (en) Grouping of database objects
WO2021073241A1 (en) Disk storage-based data reading method and device, and apparatus
WO2020253231A1 (en) Receipt-based data storage method and apparatus, and device
WO2021057164A1 (en) Query method and device for blockchain ledger, and apparatus
US20200097615A1 (en) Difference-based comparisons in log-structured graph databases
US20120030192A1 (en) Apparatus for processing materialized tables in a multi-tenant application system
WO2021093461A1 (en) Method and apparatus for aggregation calculation in blockchain-type ledger, and device
CN113711221A (en) Efficient chained record access

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: 20887252

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: 20887252

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 05/07/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20887252

Country of ref document: EP

Kind code of ref document: A1