WO2023159976A1 - Data segmented writing method, data reading method and apparatus - Google Patents

Data segmented writing method, data reading method and apparatus Download PDF

Info

Publication number
WO2023159976A1
WO2023159976A1 PCT/CN2022/125887 CN2022125887W WO2023159976A1 WO 2023159976 A1 WO2023159976 A1 WO 2023159976A1 CN 2022125887 W CN2022125887 W CN 2022125887W WO 2023159976 A1 WO2023159976 A1 WO 2023159976A1
Authority
WO
WIPO (PCT)
Prior art keywords
storage space
data
thread
target
redo
Prior art date
Application number
PCT/CN2022/125887
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 WO2023159976A1 publication Critical patent/WO2023159976A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2291User-Defined Types; Storage management thereof
    • 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

Abstract

Disclosed in the embodiments of the present application are a data segmented writing method, a data reading method and an apparatus, which are applied to the technical field of computers, and used for reducing data writing time delay. The data segmented writing method in the embodiments of the present application is applied to a database system, the database system comprising a second storage space and N first storage spaces, and N being a positive integer. The data segmented writing method in the embodiments of the present application comprises: a first thread obtains a redo log according to target data, the redo log being used for representing the target data and a write operation for the target data, and the write operation being used for converting the target data into graph model data and writing the graph model data into the second storage space; and writing the redo log into a target storage space, the target storage space being one of the N first storage spaces, so that a second thread can execute the write operation by replaying the redo log in the target storage space so as to write the graph model data into the second storage space.

Description

数据分段写入方法、数据读取方法及装置Data segmentation writing method, data reading method and device
本申请要求于2022年2月28日提交中国专利局、申请号为CN202210189511.7、申请名称为“数据分段写入方法、数据读取方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application submitted to the China Patent Office on February 28, 2022, the application number is CN202210189511.7, and the application name is "data segment writing method, data reading method and device", all of which The contents are incorporated by reference in this application.
技术领域technical field
本申请涉及计算机技术领域,尤其涉及一种数据分段写入方法、数据读取方法及装置。The present application relates to the field of computer technology, and in particular to a data segment writing method, a data reading method and a device.
背景技术Background technique
对现实世界建模,最有效的建模方式是使用实体关系(Entity-Relationship,ER)模型进行建模。当前最流行的关系(Relation Model)模型数据库系统是对ER模型的一种简化,无法表达ER模型中的函数映射关系。相比之下,图模型(Graph model)则能够更好地表达ER模型中的函数映射关系,进而更好地对现实世界建模。To model the real world, the most effective modeling method is to use the entity-relationship (Entity-Relationship, ER) model for modeling. The current most popular relational model database system is a simplification of the ER model, which cannot express the function mapping relationship in the ER model. In contrast, the graph model (Graph model) can better express the function mapping relationship in the ER model, and then better model the real world.
使用图模型对现实世界建模的方法如下:将现实世界的数据转换成图模型数据,再将图模型数据导入图数据库系统。The method of using the graph model to model the real world is as follows: convert the real world data into graph model data, and then import the graph model data into the graph database system.
上述方法也可以理解为图模型数据的写入过程,图模型数据的读取过程则相反,即先读取图模型数据,然后将图模型数据转换成现实世界的数据。The above method can also be understood as the writing process of graph model data, while the reading process of graph model data is the opposite, that is, the graph model data is first read, and then the graph model data is converted into real-world data.
然而,由于现实世界的数据间存在复杂的关联关系,所以在图模型数据的转换过程中,需要识别和提取现实世界的数据间的关联关系,导致现实世界的数据与图模型数据间的转换过程需要耗费较长时间,使得现实世界的数据的处理时延较长,例如:写入时延或读取时延。However, due to the complex relationship between the data in the real world, it is necessary to identify and extract the relationship between the data in the real world during the conversion process of the graph model data, resulting in the conversion process between the data in the real world and the graph model data. It takes a long time, making the processing delay of real-world data long, such as: write delay or read delay.
发明内容Contents of the invention
本申请实施例提供了一种数据分段写入方法、数据读取方法及装置,该方法能够降低同步写入图数据库系统的时延。The embodiment of the present application provides a data segmentation writing method, a data reading method and a device, and the method can reduce the time delay of synchronous writing to the graph database system.
第一方面,本申请提供了一种数据分段写入方法,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,第一存储空间和第二存储空间是相互独立的,第一存储空间可供客户端直接连接并执行读操作或写操作,第二存储空间用于存储图模型数据,其中,N为正整数。该图数据库系统可以供多种业务使用,当N大于1时,每个第一存储空间可以对应一种业务。In the first aspect, the present application provides a data segment writing method, which is applied to a database system. The database system includes a second storage space and N first storage spaces, and the first storage space and the second storage space are independent of each other. , the first storage space can be directly connected by the client to perform read or write operations, and the second storage space is used to store graph model data, where N is a positive integer. The graph database system can be used by various businesses, and when N is greater than 1, each first storage space can correspond to one business.
该方法包括:第一线程根据目标数据得到重做日志,重做日志中包含目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间;第一线程也可以称为主体线程、业务线程或工作线程,具体是指运行数据库的客户端的线程。第一线程将重做日志写入目标存储空间,这样,第二线程便可以通过回放目标存储空间中的重做日志执行上述写操作,以将图模型数据写入第二存储空间,目标存储空间为N个第一存储空间中的一个,第二线程是指数据库的工作线程。The method includes: the first thread obtains a redo log according to the target data, and the redo log includes a write operation of the target data, and the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space; The first thread may also be called a main thread, a business thread or a working thread, and specifically refers to a thread of a client running a database. The first thread writes the redo log into the target storage space, so that the second thread can perform the above-mentioned write operation by replaying the redo log in the target storage space, so as to write the graph model data into the second storage space, and the target storage space is one of the N first storage spaces, and the second thread refers to a working thread of the database.
第一线程将包含目标数据的写操作的重做日志并写入目标存储空间,所以目标存储空间中存储的是重做日志,并不是图模型数据;第二线程通过回放重做日志将目标数据对应 的图模型数据写入第二存储空间,所以第二存储空间中存储的是图模型数据。由此可见,耗时较长的目标数据与图模型数据间的转换发生在回放重做日志的过程中,而在第一线程向目标存储空间写入重做日志的过程中,不会发生的图模型数据的转换,因此,第一线程将目标数据封装成重做日志并写入目标存储空间的过程耗时较短;这样,在写入重做日志后,便返回写入成功的结果,便可以在时延较低的前提下将目标数据同步写入图数据库系统,保证了同步写入的低时延性。The first thread writes the redo log containing the write operation of the target data into the target storage space, so the redo log is stored in the target storage space, not the graph model data; the second thread saves the target data by playing back the redo log The corresponding graph model data is written into the second storage space, so the graph model data is stored in the second storage space. It can be seen that the conversion between the target data and the graph model data that takes a long time occurs in the process of playing back the redo log, but it will not happen when the first thread writes the redo log to the target storage space. The conversion of the graph model data, therefore, the process of the first thread encapsulating the target data into redo logs and writing them into the target storage space takes less time; in this way, after writing the redo logs, it returns the result of successful writing, The target data can be synchronously written into the graph database system under the premise of low latency, which ensures the low latency of synchronous writing.
作为一种可实现的方式,方法还包括:第二线程读取目标存储空间中的重做日志;第二线程回放目标存储空间中的重做日志,以执行写操作。As an implementable manner, the method further includes: the second thread reads the redo logs in the target storage space; and the second thread plays back the redo logs in the target storage space to perform a write operation.
第二线程回放目标存储空间中的重做日志,以执行写操作,从而将图模型数据写入第二存储空间,使得耗时较长的目标数据与图模型数据间的转换发生在回放重做日志的过程中,而不是发生在向目标存储空间写入重做日志的过程中。这样,在写入重做日志后,便返回写入成功的结果,便可以在时延较低的前提下将目标数据同步写入图数据库系统,保证了同步写入的低时延性。The second thread replays the redo logs in the target storage space to perform write operations, thereby writing the graph model data into the second storage space, so that the conversion between the target data and the graph model data that takes a long time takes place in the playback redo Logging process, not in the process of writing redo logs to the target storage space. In this way, after the redo log is written, the result of successful writing is returned, and the target data can be synchronously written to the graph database system under the premise of low latency, ensuring low latency of synchronous writing.
作为一种可实现的方式,方法还包括:第一线程向第二线程发送请求,请求用于指示第二线程回放目标存储空间中的重做日志。As an implementable manner, the method further includes: the first thread sends a request to the second thread, and the request is used to instruct the second thread to replay the redo logs in the target storage space.
第一线程向第二线程发送请求,使得第二线程回放重做日志,从而在第一线程主动请求的情况下实现了目标存储空间到第二存储空间的数据合并。The first thread sends a request to the second thread, so that the second thread plays back the redo log, so that the data merging from the target storage space to the second storage space is realized under the active request of the first thread.
作为一种可实现的方式,第一线程向第二线程发送请求包括:在目标存储空间中已使用的存储空间达到第一阈值的情况下,第一线程向第二线程发送请求。As an implementable manner, the first thread sending the request to the second thread includes: when the used storage space in the target storage space reaches a first threshold, the first thread sends the request to the second thread.
在目标存储空间中已使用的存储空间达到第一阈值的情况下,第一线程向第二线程发送请求,从而为新增数据的重做日志预留了存储空间,保证后续新增数据也能够在较低时延的情况下实现同步写入。When the used storage space in the target storage space reaches the first threshold, the first thread sends a request to the second thread, thereby reserving storage space for the redo log of newly added data, ensuring that subsequent new data can also be Synchronous writes are achieved with lower latency.
作为一种可实现的方式,第一线程向第二线程发送请求包括:响应于业务需求,第一线程向第二线程发送请求。该业务需求可以根据实际情况设定,例如,业务需求包括:需要读取图数据库系统中最新数据。基于此,若第一存储空间中的重做日志未回放,则第二存储空间中的数据不是最新的,此时,响应于该业务需求,第一线程便可以主动向第二线程发送请求。As an implementable manner, the first thread sending the request to the second thread includes: in response to a business requirement, the first thread sending the request to the second thread. The business requirement can be set according to the actual situation. For example, the business requirement includes: the need to read the latest data in the graph database system. Based on this, if the redo logs in the first storage space have not been played back, the data in the second storage space is not up-to-date. At this time, in response to the business requirement, the first thread can actively send a request to the second thread.
响应于业务需求,第一线程向第二线程发送请求,使得第二线程回放重做日志,从而在满足业务需求的情况下实现了目标存储空间到第二存储空间的数据合并。In response to business requirements, the first thread sends a request to the second thread, so that the second thread plays back redo logs, thereby realizing data merging from the target storage space to the second storage space when the business requirements are met.
作为一种可实现的方式,在N大于1的情况下,方法还包括;第一线程根据目标数据对应的标签,以及标签与第一存储空间的对应关系,从N个第一存储空间中确定目标存储空间,标签指示用于存储目标数据的表。As an achievable manner, when N is greater than 1, the method further includes; the first thread determines from the N first storage spaces according to the label corresponding to the target data and the corresponding relationship between the label and the first storage space The target storage space, the label indicates the table used to store the target data.
在数据库中,数据都是以表的形式存储的,所以根据目标数据对应的标签以及标签与第一存储空间的对应关系,能够确定用于存储目标数据的表所在的第一存储空间,即目标存储空间。In the database, data is stored in the form of tables, so according to the label corresponding to the target data and the corresponding relationship between the label and the first storage space, the first storage space where the table used to store the target data is located can be determined, that is, the target storage.
作为一种可实现的方式,第一线程将重做日志写入目标存储空间包括:第一线程通过物理锁的严格两段锁机制,将重做日志写入目标存储空间。As an achievable manner, writing the redo log into the target storage space by the first thread includes: writing the redo log into the target storage space by the first thread through a strict two-stage lock mechanism of a physical lock.
相比于其他锁机制,物理锁的严格两段锁机制的读写流程较为简单,所以能够保证写入重做日志的时延较低;并且,物理锁的严格两段锁机制不包含数据库对象锁,可能降低锁的开销。Compared with other lock mechanisms, the strict two-stage lock mechanism of physical locks has a simpler read and write process, so it can ensure a lower delay in writing redo logs; moreover, the strict two-stage lock mechanism of physical locks does not include database objects Locks, possibly reducing lock overhead.
作为一种可实现的方式,在第一线程将重做日志写入目标存储空间之后,方法还包括:第一线程将事务提交日志写入目标存储空间,事务提交日志用于表示目标数据的写入事务已提交;使得用户可以读取该写入事务中写入的数据,从而保证写入事务的原子性和一致性。As an achievable manner, after the first thread writes the redo log into the target storage space, the method further includes: the first thread writes the transaction commit log into the target storage space, and the transaction commit log is used to represent the writing of the target data The entry transaction has been committed; the user can read the data written in the write transaction, thus ensuring the atomicity and consistency of the write transaction.
第二方面,本申请提供了一种数据分段写入方法,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数,图数据库系统的相关说明可参照第一方面的相关描述。In the second aspect, the present application provides a data segment writing method, which is applied to a database system. The database system includes a second storage space and N first storage spaces, where N is a positive integer. The relevant description of the graph database system Refer to the related description of the first aspect.
该方法包括:第二线程读取目标存储空间中的重做日志,目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间;第二线程回放目标存储空间中的重做日志,以执行写操作。The method includes: the second thread reads the redo log in the target storage space, the target storage space is one of the N first storage spaces, the redo log is used to represent the target data and the write operation of the target data, and the write operation uses Converting the target data into graph model data and writing the graph model data into the second storage space; the second thread replays the redo logs in the target storage space to perform the write operation.
第二线程在回放重做日志的过程中,会执行目标数据的写操作,从而将目标数据转换成图模型数据,该转换操作与第一线程写入重做日志的操作可以是异步进行的,所以在第一线程完成重做日志的写操作后便可以返回同步写入成功的结果,从而保证了同步写入的低时延。并且,第二线程通过回放重做日志,能够将目标数据的图模型数据合并到第二存储空间中,使得第二存储空间中存储的图模型数据与用户实际写入的目标数据是一致的,从而保证了数据一致性。In the process of replaying the redo log, the second thread will execute the write operation of the target data, thereby converting the target data into graph model data. This conversion operation and the operation of writing the redo log by the first thread can be performed asynchronously. Therefore, after the first thread completes the write operation of the redo log, it can return the result of successful synchronous writing, thereby ensuring low latency of synchronous writing. Moreover, the second thread can merge the graph model data of the target data into the second storage space by playing back the redo log, so that the graph model data stored in the second storage space is consistent with the target data actually written by the user, This ensures data consistency.
作为一种可实现的方式,第二线程读取目标存储空间中的重做日志包括:第二线程周期性地读取目标存储空间中的重做日志,其中,第二线程读取重做日志的周期可以根据实际情况进行设定。As an implementable manner, the second thread reading the redo log in the target storage space includes: the second thread periodically reads the redo log in the target storage space, wherein the second thread reads the redo log The cycle can be set according to the actual situation.
第二线程周期性地读取目标存储空间中的重做日志,在第二线程主动的情况下,实现了目标存储空间到第二存储空间的数据合并,并使得第一存储空间中具有足够的剩余空间,以存储新的数据的重做日志。The second thread periodically reads the redo logs in the target storage space. When the second thread takes the initiative, it realizes the data merging from the target storage space to the second storage space, and makes the first storage space have enough The remaining space to store new data in the redo logs.
作为一种可实现的方式,第二线程读取目标存储空间中的重做日志包括:在接收到来自第一线程的请求的情况下,第二线程读取目标存储空间中的重做日志,请求用于指示第二线程回放目标存储空间中的重做日志,以将图模型数据存储至第二存储空间。As an achievable manner, the second thread reading the redo logs in the target storage space includes: upon receiving a request from the first thread, the second thread reads the redo logs in the target storage space, The request is used to instruct the second thread to replay the redo logs in the target storage space, so as to store the graph model data in the second storage space.
在接收到来自第一线程的请求的情况下,第二线程读取目标存储空间中的重做日志,从而在第一线程主动请求的情况下实现了目标存储空间到第二存储空间的数据合并。In the case of receiving a request from the first thread, the second thread reads the redo logs in the target storage space, thereby realizing data merging from the target storage space to the second storage space under the active request of the first thread .
作为一种可实现的方式,第二线程回放目标存储空间中的重做日志包括:第二线程通过多版本的两段锁机制回放目标存储空间中的重做日志。As an implementable manner, the second thread playing back the redo logs in the target storage space includes: the second thread plays back the redo logs in the target storage space through a multi-version two-stage lock mechanism.
多版本的两段锁机制的读写操作代价较小,所以通过多版本的两段锁机制回放重做日志,能够降低锁的开销。The cost of read and write operations of the multi-version two-stage lock mechanism is relatively small, so replaying redo logs through the multi-version two-stage lock mechanism can reduce the lock overhead.
作为一种可实现的方式,在第二线程回放目标存储空间中的重做日志之后,方法还包括:第二线程删除目标存储空间中的重做日志。As an implementable manner, after the second thread plays back the redo logs in the target storage space, the method further includes: the second thread deletes the redo logs in the target storage space.
在回放重做日志后,将重做日志删除,可以保证目标存储空间中有足够的剩余空间,以便第一线程写入新的数据的重做日志。After replaying the redo log, deleting the redo log can ensure that there is enough remaining space in the target storage space so that the first thread can write the redo log of new data.
第三方面,本申请提供了一种数据读取方法,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;方法包括:第三线程获取目标数据对应的数据库主键,第三线程是指数据读取线程,可以与第一方面中的第一线程相同,数据库主键通常是从目标数据中选择的部分数据,其值能唯一地标识表中的每一行。第三线程根据数据库主键从目标存储空间中读取重做日志,例如,第三线程根据数据库主键查询索引,索引中包含数据库主键和存储位置的对应关系,这样,根据该对应关系便可以确定重做日志的存储位置,进而可以读取重做日志。或者,第三线程根据数据库主键从第二存储空间读取图模型数据,图模型数据根据第二线程回放的目标存储空间中的重做日志得到的,需要说明的是,读取模型数据的过程与读取重做日志的过程类似;目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。由此可见,当目标数据以重做日志的形式存储在目标存储空间中时,第三线程可以从目标存储空间中读取目标数据。当目标数据存储在第二存储空间中时,第三线程可以从第二存储空间中读取目标数据。所以本申请能够保证图数据库系统中数据的一致性。In a third aspect, the present application provides a method for reading data, which is applied to a database system. The database system includes a second storage space and N first storage spaces, where N is a positive integer; the method includes: the third thread acquires the target The database primary key corresponding to the data. The third thread refers to the data reading thread, which can be the same as the first thread in the first aspect. The database primary key is usually part of the data selected from the target data, and its value can uniquely identify the data in the table. each row. The third thread reads redo logs from the target storage space according to the primary key of the database. For example, the third thread queries the index according to the primary key of the database. Do the storage location of the log, and then read the redo log. Alternatively, the third thread reads the graph model data from the second storage space according to the primary key of the database. The graph model data is obtained from the redo logs in the target storage space played back by the second thread. It should be noted that the process of reading the model data Similar to the process of reading the redo log; the target storage space is one of the N first storage spaces, the redo log is used to represent the target data and the write operation of the target data, and the write operation is used to convert the target data into a graph model data and write the graph model data into the second storage space. It can be seen that when the target data is stored in the target storage space in the form of redo logs, the third thread can read the target data from the target storage space. When the target data is stored in the second storage space, the third thread may read the target data from the second storage space. Therefore, this application can ensure the consistency of data in the graph database system.
并且,由于第三线程可以通过读取重做日志得到目标数据,而不需执行图模型数据到目标数据的转换操作,所以可以降低目标数据的读取时延。Moreover, since the third thread can obtain the target data by reading the redo log without performing a conversion operation from the graph model data to the target data, the time delay for reading the target data can be reduced.
作为一种可实现的方式,在第三线程根据数据库主键从目标存储空间中读取重做日志之前,方法还包括:第三线程根据数据库主键确定目标数据的写入事务的标识;第三线程根据写入事务的标识,确定目标存储空间中包含事务提交日志,事务提交日志用于表示写入事务已提交。只有当目标存储空间中包含表示写入事务已提交的事务提交日志时,才读取目标存储空间中的目标数据,从而保证写入事务的原子性和一致性。As an implementable manner, before the third thread reads the redo log from the target storage space according to the database primary key, the method further includes: the third thread determines the identifier of the writing transaction of the target data according to the database primary key; the third thread According to the identifier of the write transaction, it is determined that the target storage space contains a transaction commit log, and the transaction commit log is used to indicate that the write transaction has been committed. The target data in the target storage space is read only when the target storage space contains a transaction commit log indicating that the write transaction has been committed, thereby ensuring the atomicity and consistency of the write transaction.
第四方面,本申请提供了一种数据分段写入装置,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;装置包括封装单元,用于根据目标数据得到重做日志,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。In a fourth aspect, the present application provides a device for writing data segments, which is applied to a database system. The database system includes a second storage space and N first storage spaces, where N is a positive integer; the device includes a packaging unit, which uses The redo log is obtained according to the target data, and the redo log is used to represent the target data and the write operation of the target data, and the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space.
写入单元,用于将重做日志写入目标存储空间,目标存储空间为N个第一存储空间中的一个。The write unit is configured to write redo logs into a target storage space, where the target storage space is one of the N first storage spaces.
作为一种可实现的方式,装置还包括:发送单元,用于向第二线程发送请求,请求用于指示第二线程回放目标存储空间中的重做日志,以将目标数据对应的图模型数据写入第二存储空间。As a practicable manner, the device further includes: a sending unit, configured to send a request to the second thread, and the request is used to instruct the second thread to replay the redo logs in the target storage space, so that the graph model data corresponding to the target data Write to the second storage space.
作为一种可实现的方式,发送单元,用于在目标存储空间中已使用的存储空间达到第一阈值的情况下,向第二线程发送请求。As an implementable manner, the sending unit is configured to send a request to the second thread when the used storage space in the target storage space reaches a first threshold.
作为一种可实现的方式,发送单元,用于响应于业务需求,向第二线程发送请求。As an implementable manner, the sending unit is configured to send a request to the second thread in response to a service requirement.
作为一种可实现的方式,装置还包括:确定单元,用于从N个第一存储空间中,确定目标存储空间。As a practicable manner, the device further includes: a determining unit, configured to determine a target storage space from the N first storage spaces.
作为一种可实现的方式,确定单元,用于根据目标数据对应的标签,以及标签与第一存储空间的对应关系,从N个第一存储空间中确定目标存储空间,标签指示用于存储目标数据的表。As a practicable manner, the determining unit is configured to determine the target storage space from the N first storage spaces according to the label corresponding to the target data and the corresponding relationship between the label and the first storage space. table of data.
作为一种可实现的方式,写入单元,用于通过物理锁的严格两段锁机制,将重做日志写入目标存储空间。As an achievable way, the write unit is used to write the redo log into the target storage space through the strict two-stage lock mechanism of the physical lock.
其中,以上各单元的具体实现、相关说明以及技术效果请参考第一方面的相关描述。Wherein, for the specific implementation, relevant description and technical effect of each of the above units, please refer to the relevant description of the first aspect.
第五方面,本申请提供了一种数据分段写入装置,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;装置包括:读取单元,用于第二线程读取目标存储空间中的重做日志,目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间;回放单元,用于回放目标存储空间中的重做日志,以执行写操作。In a fifth aspect, the present application provides a device for writing data segments, which is applied to a database system. The database system includes a second storage space and N first storage spaces, where N is a positive integer; the device includes: a reading unit , used for the second thread to read the redo log in the target storage space, the target storage space is one of the N first storage spaces, the redo log is used to represent the target data and the write operation of the target data, and the write operation is used for The target data is converted into graph model data and the graph model data is written into the second storage space; the replay unit is used to replay redo logs in the target storage space to perform write operations.
作为一种可实现的方式,读取单元,用于周期性地读取目标存储空间中的重做日志。As an implementable manner, the reading unit is used to periodically read redo logs in the target storage space.
作为一种可实现的方式,读取单元,用于在接收到来自第一线程的请求的情况下,读取目标存储空间中的重做日志,请求用于指示第二线程回放目标存储空间中的重做日志,以将图模型数据存储至第二存储空间。As an implementable manner, the reading unit is used to read the redo logs in the target storage space when receiving a request from the first thread, and the request is used to instruct the second thread to play back the redo logs in the target storage space Redo logs to store graph model data in the second storage space.
作为一种可实现的方式,回放单元,用于第二线程通过多版本的两段锁机制回放目标存储空间中的重做日志。As an implementable manner, the replay unit is used for the second thread to replay the redo logs in the target storage space through a multi-version two-segment lock mechanism.
作为一种可实现的方式,装置还包括删除单元,用于删除目标存储空间中的重做日志。As an implementable manner, the device further includes a deletion unit, configured to delete redo logs in the target storage space.
其中,以上各单元的具体实现、相关说明以及技术效果请参考第二方面的相关描述。Wherein, for the specific implementation, relevant description and technical effect of each of the above units, please refer to the relevant description of the second aspect.
第六方面,本申请提供了一种数据读取装置,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;装置包括:获取单元,用于获取目标数据对应的数据库主键;读取单元,用于根据数据库主键从目标存储空间中读取重做日志,或者,用于根据数据库主键从第二存储空间读取图模型数据,图模型数据根据第二线程回放的目标存储空间中的重做日志得到的;目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。In a sixth aspect, the present application provides a data reading device, which is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer; the device includes: an acquisition unit for Acquire the database primary key corresponding to the target data; the reading unit is used to read the redo log from the target storage space according to the database primary key, or to read the graph model data from the second storage space according to the database primary key, and the graph model data is based on The redo log in the target storage space played back by the second thread is obtained; the target storage space is one of the N first storage spaces, and the redo log is used to represent the target data and the write operation of the target data, and the write operation is used to write The target data is converted into graph model data and the graph model data is written into the second storage space.
作为一种可实现的方式,读取单元,用于根据数据库主键查询目标存储空间,以得到目标数据。As a practicable manner, the reading unit is configured to query the target storage space according to the primary key of the database, so as to obtain the target data.
作为一种可实现的方式,读取单元,用于根据数据库主键确定目标数据的写入事务的标识;根据写入事务的标识,确定目标存储空间中包含事务提交日志,事务提交日志用于表示写入事务已提交。As an achievable way, the reading unit is used to determine the identifier of the writing transaction of the target data according to the primary key of the database; according to the identifier of the writing transaction, it is determined that the target storage space contains a transaction commit log, and the transaction commit log is used to represent Write transaction committed.
其中,以上各单元的具体实现、相关说明以及技术效果请参考第三方面的相关描述。Wherein, for the specific implementation, relevant description and technical effect of each of the above units, please refer to the relevant description of the third aspect.
本申请实施例第七方面提供了一种终端设备,包括:一个或多个处理器和存储器;其中,存储器中存储有计算机可读指令;一个或多个处理器读取计算机可读指令,以使计算机设备实现如第一方面任一实现方式的方法,或第二方面任一实现方式的方法,或第三方面任一实现方式的方法。The seventh aspect of the embodiment of the present application provides a terminal device, including: one or more processors and a memory; wherein, computer-readable instructions are stored in the memory; one or more processors read the computer-readable instructions to Make the computer device implement the method in any implementation manner of the first aspect, or the method in any implementation manner of the second aspect, or the method in any implementation manner of the third aspect.
本申请实施例第八方面提供了一种计算机可读存储介质,包括计算机可读指令,当计算机可读指令在计算机上运行时,使得计算机执行如第一方面、第二方面或第三方面任一实现方式的方法。The eighth aspect of the embodiment of the present application provides a computer-readable storage medium, including computer-readable instructions. When the computer-readable instructions are run on a computer, the computer can perform any of the following aspects of the first aspect, the second aspect, or the third aspect. A method of implementation.
本申请实施例第九方面提供了一种芯片,包括一个或多个处理器。处理器中的部分或全部用于读取并执行存储器中存储的计算机程序,以执行上述第一方面、第二方面或第三方面任意可能的实现方式中的方法。A ninth aspect of the embodiments of the present application provides a chip, including one or more processors. Part or all of the processor is used to read and execute the computer program stored in the memory, so as to execute the method in any possible implementation manner of the first aspect, the second aspect or the third aspect above.
可选地,该芯片该包括存储器,该存储器与该处理器通过电路或电线与存储器连接。进一步可选地,该芯片还包括通信接口,处理器与该通信接口连接。通信接口用于接收需要处理的数据和/或信息,处理器从该通信接口获取该数据和/或信息,并对该数据和/或信息进行处理,并通过该通信接口输出处理结果。该通信接口可以是输入输出接口。Optionally, the chip includes a memory, and the memory and the processor are connected to the memory through a circuit or wires. Further optionally, the chip further includes a communication interface, and the processor is connected to the communication interface. The communication interface is used to receive data and/or information to be processed, and the processor obtains the data and/or information from the communication interface, processes the data and/or information, and outputs the processing result through the communication interface. The communication interface may be an input-output interface.
在一些实现方式中,一个或多个处理器中还可以有部分处理器是通过专用硬件的方式来实现以上方法中的部分步骤,例如涉及神经网络模型的处理可以由专用神经网络处理器或图形处理器来实现。In some implementations, some of the one or more processors can also implement some steps in the above method through dedicated hardware. For example, the processing related to the neural network model can be performed by a dedicated neural network processor or graphics processor to achieve.
本申请实施例提供的方法可以由一个芯片实现,也可以由多个芯片协同实现。The method provided in the embodiment of the present application may be implemented by one chip, or may be implemented by multiple chips in cooperation.
本申请实施例第十方面提供了一种计算机程序产品,该计算机程序产品包括计算机软件指令,该计算机软件指令可通过处理器进行加载来实现上述第一方面、第二方面或第三方面中任意一种实现方式的方法。The tenth aspect of the embodiment of the present application provides a computer program product, the computer program product includes computer software instructions, and the computer software instructions can be loaded by a processor to implement any of the above-mentioned first aspect, second aspect or third aspect. A method of implementation.
附图说明Description of drawings
图1为单机数据库系统示意图;Fig. 1 is a schematic diagram of a stand-alone database system;
图2为本申请实施例所应用的图数据库系统的硬件架构示意图;Fig. 2 is a schematic diagram of the hardware architecture of the graph database system applied in the embodiment of the present application;
图3为本申请实施例所应用的图数据库系统的软件架构示意图;Fig. 3 is a schematic diagram of the software architecture of the graph database system applied in the embodiment of the present application;
图4为本申请实施例所应用的图数据库系统与外部系统之间的关系示意图;FIG. 4 is a schematic diagram of the relationship between the graph database system applied in the embodiment of the present application and external systems;
图5为本申请提供的一种数据分段写入方法的一个实施例的示意图;FIG. 5 is a schematic diagram of an embodiment of a data segment writing method provided by the present application;
图6为第二线程回放重做日志的过程示意图;Fig. 6 is a schematic diagram of the process of replaying redo logs by the second thread;
图7为采用本申请实施例提供的方法写入目标数据的过程的示意图;FIG. 7 is a schematic diagram of the process of writing target data using the method provided by the embodiment of the present application;
图8为本申请实施例提供的数据读取方法的一个实施例的示意图;Fig. 8 is a schematic diagram of an embodiment of the data reading method provided by the embodiment of the present application;
图9为本申请实施例提供的数据分段写入装置的实施例示意图;FIG. 9 is a schematic diagram of an embodiment of a data segment writing device provided in an embodiment of the present application;
图10为本申请实施例提供的数据分段写入装置的实施例示意图;FIG. 10 is a schematic diagram of an embodiment of a data segment writing device provided in an embodiment of the present application;
图11为本申请实施例提供的数据读取装置的实施例示意图;FIG. 11 is a schematic diagram of an embodiment of a data reading device provided in an embodiment of the present application;
图12是本申请实施例提供的终端设备的一种结构示意图。FIG. 12 is a schematic structural diagram of a terminal device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面结合附图,对本申请的实施例进行描述,显然,所描述的实施例仅仅是本申请一部分的实施例,而不是全部的实施例。本领域普通技术人员可知,随着技术的发展和新场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。Embodiments of the present application are described below in conjunction with the accompanying drawings. Apparently, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Those of ordinary skill in the art know that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的实施例能够以除了在这里图示或描述的内容以外的顺序实施。 此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second" and the like in the specification and claims of the present application and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific sequence or sequence. It is to be understood that the terms so used are interchangeable under appropriate circumstances such that the embodiments described herein can be practiced in sequences other than those illustrated or described herein. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, for example, a process, method, system, product or device comprising a sequence of steps or elements is not necessarily limited to the expressly listed Those steps or elements may instead include other steps or elements not explicitly listed or inherent to the process, method, product or apparatus.
本申请实施例提供的方法可以应用于数据库系统。数据库系统(database system)一般由以下三部分组成:(1)数据库(database,DB),指长期存储在计算机内的、有组织、可共享的数据的集合。数据库中的数据按一定的数学模型组织、描述和存储,具有较小的冗余,较高的数据独立性和易扩展性,并可为各种用户共享。(2)硬件,包括存储数据所需的数据存储器,例如内存和/或磁盘。(3)软件,包括DBMS(database management system,数据库管理系统),DBMS是数据库系统的核心软件,是用于科学地组织和存储数据,以及高效获取和维护数据的系统软件,数据库引擎是DBMS的核心组件。The method provided in the embodiment of the present application can be applied to a database system. A database system (database system) generally consists of the following three parts: (1) database (database, DB), which refers to a collection of organized and shareable data stored in a computer for a long time. The data in the database is organized, described and stored according to a certain mathematical model, which has less redundancy, higher data independence and easy scalability, and can be shared by various users. (2) Hardware, including data storage required to store data, such as memory and/or disks. (3) Software, including DBMS (database management system, database management system). DBMS is the core software of the database system. It is a system software for scientifically organizing and storing data, and efficiently obtaining and maintaining data. core components.
具体地,如图1所示,图1为单机数据库系统示意图,包括一个数据库管理系统和数据存储器(Data Store),该数据库管理系统用于提供数据库的查询和修改等服务,该数据库管理系统将数据存储到数据存储器中。在单机数据库系统中,数据库管理系统和数据存储器通常位于单一设备上。该设备可以包括多个处理器,所有的处理器共享资源,如总线,内存和I/O系统等。数据库管理系统的功能可由一个或多个处理器执行内存中的程序来实现。Specifically, as shown in Figure 1, Figure 1 is a schematic diagram of a stand-alone database system, including a database management system and a data store (Data Store), the database management system is used to provide services such as database query and modification, and the database management system will The data is stored in the data memory. In a stand-alone database system, the database management system and data storage are usually located on a single device. The device can include multiple processors, all of which share resources such as buses, memory, and I/O systems. The functions of the database management system can be implemented by one or more processors executing programs in memory.
图2为本申请实施例所应用的图数据库系统的硬件架构示意图。本申请实施例可以应用于图2所示的图数据库系统中,该图数据库系统包括第一内存和第二内存,其中,第一内存和第二内存可以理解为图1中的数据存储器。FIG. 2 is a schematic diagram of the hardware architecture of the graph database system applied in the embodiment of the present application. The embodiment of the present application can be applied to the graph database system shown in FIG. 2 . The graph database system includes a first memory and a second memory, where the first memory and the second memory can be understood as the data storage in FIG. 1 .
第一内存是指可供客户端直接连接,并由客户端执行读操作或写操作的内存;本申请实施例对第一内存的存储方式不做具体限定,例如,第一内存的存储方式可以为分页式内存存储方式。The first memory refers to the memory that can be directly connected by the client, and the client can perform read or write operations; the embodiment of the present application does not specifically limit the storage method of the first memory, for example, the storage method of the first memory can be It is a paged memory storage method.
第一内存的数量可以为一个,也可以为多个,其中,图1示出了三个第一内存;由于业务的种类有多种,所以通常情况下,第一内存的数量为多个,每个第一内存对应一种业务。The number of the first memory can be one or more, wherein, Figure 1 shows three first memories; since there are many kinds of services, usually, the number of the first memory is multiple, Each first memory corresponds to a service.
第二内存可以理解为与第一内存分离的一块独立的内存;本申请实施例对第二内存的存储方式不做具体限定,例如,第二内存的存储方式可以为段页式内存存储方式;第二内存的数量通常为一个,也可以为多个。The second memory can be understood as an independent memory separate from the first memory; the embodiment of the present application does not specifically limit the storage method of the second memory, for example, the storage method of the second memory can be a segment page memory storage method; The quantity of the second memory is generally one, and may also be multiple.
需要说明的是,下文也将第一内存称为DeltaStore,将第二内存称为MainStore。It should be noted that, hereinafter, the first memory is also called DeltaStore, and the second memory is called MainStore.
由于现实世界的数据与图模型数据间的转换过程需要耗费较长时间,所以若采用同步写入的方式将现实世界的数据写入图数据库系统,会存在同步写入的时延较长的问题。Since the conversion process between real-world data and graph model data takes a long time, if the real-world data is written into the graph database system by synchronous writing, there will be a problem of long delay in synchronous writing .
其中,同步写入可以理解为一种访问模式,同步表示客户端程序在发出写入请求后一直处于等待状态,直到完成写入后返回该写入请求的处理结果。Among them, synchronous writing can be understood as an access mode, and synchronous means that the client program has been in a waiting state after sending out a writing request, and returns the processing result of the writing request until the writing is completed.
为了解决上述问题,基于图2所示的图数据库系统,本申请实施例提供了一种数据分段写入方法,在该方法中,客户端可以直接连接第一内存并将目标数据以逻辑重做redo日志的形式写入第一内存,之后便可以返回同步写入成功的结果。其中,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据 写入第二存储空间。然后,可以异步回放第一内存中的逻辑redo日志,在回放过程中,会执行前述目标数据的写操作,即将目标数据转换成图模型数据并将图模型数据写入第二内存,从而完成目标数据到图数据库系统的写入过程。逻辑redo日志是表示数据库中的事务日志;下文也将逻辑redo日志简称为重做日志。In order to solve the above problems, based on the graph database system shown in Figure 2, an embodiment of the present application provides a method for writing data segments, in which the client can directly connect to the first memory and rewrite the target data in a logical manner. It is written into the first memory in the form of redo log, and then the result of successful synchronous writing can be returned. Wherein, the redo log is used to represent the target data and the write operation of the target data, and the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space. Then, the logical redo log in the first memory can be played back asynchronously. During the playback process, the write operation of the aforementioned target data will be performed, that is, the target data will be converted into graph model data and the graph model data will be written into the second memory to complete the goal The process of writing data to the graph database system. The logical redo log represents the transaction log in the database; hereinafter, the logical redo log is also referred to as the redo log for short.
异步回放表示在客户端程序在发出写入请求后,先返回客户端程序写入请求的处理结果,然后执行回放操作。Asynchronous playback means that after the client program sends a write request, it first returns the processing result of the client program's write request, and then executes the playback operation.
目标数据可以是任意数据。The target data can be arbitrary data.
按照已有的同步写入方法,客户端程序在发出写入请求后一直处于等待状态,直到将目标数据转换成图模型数据并存储图模型数据后,才会返回该写入请求的处理结果。由于目标数据与图模型数据间的转换过程需要耗费较长时间,因此,已有的同步写入方法的写入时延较长。According to the existing synchronous writing method, the client program has been in a waiting state after sending the writing request, and will not return the processing result of the writing request until the target data is converted into graph model data and the graph model data is stored. Since the conversion process between the target data and the graph model data takes a long time, the existing synchronous writing method has a relatively long writing time delay.
而按照本申请实施例采用的同步写入方法,客户端程序在发出写入请求后处于等待状态,在根据目标数据得到重做日志并将重做日志写入第一内存后,便可以返回客户端程序写入请求的处理结果;在返回处理结果后,再回放重做日志,完成与图模型数据间的转换以及图模型数据的写入。However, according to the synchronous write method adopted in the embodiment of the present application, the client program is in a waiting state after sending out the write request, and after obtaining the redo log according to the target data and writing the redo log into the first memory, it can return to the client. The end program writes the processing result of the request; after the processing result is returned, the redo log is played back to complete the conversion with the graph model data and the writing of the graph model data.
由于目标数据与图模型数据间的转换过程发生在返回客户端程序写入请求的处理结果之后,所以客户端程序等待的时间较短,客户端程序等待的时间即写入时延;因此,相对于已有的同步写入方法来说,本申请实施例的同步写入方法的写入时延较短(也可以理解为低时延)。Since the conversion process between the target data and the graph model data occurs after returning the processing result of the writing request of the client program, the waiting time of the client program is short, and the waiting time of the client program is the writing delay; therefore, relatively Compared with the existing synchronous writing methods, the writing delay of the synchronous writing method of the embodiment of the present application is shorter (also can be understood as low latency).
其中,低时延可以理解为,端到端的执行时间短,一般达到纳秒级别。Among them, low latency can be understood as short end-to-end execution time, generally reaching the nanosecond level.
此外,上述低时延是确定的、可估计的,原因如下。由于客户端可以直接连接第一内存以执行数据写入操作,所以不存在客户端调度其他程序完成写入操作而产生的调度开销,该调度开销往往是不确定的;并且,数据写入的过程是将目标数据以逻辑重做redo日志的形式写入第一内存,redo日志的数据量是确定的,且不受第一内存中索引等其他因素的影响,所以数据写入的时延是确定的、可估计的。In addition, the aforementioned low latency is deterministic and predictable for the following reasons. Since the client can directly connect to the first memory to perform the data writing operation, there is no scheduling overhead caused by the client scheduling other programs to complete the writing operation, and the scheduling overhead is often uncertain; moreover, the process of data writing It is to write the target data into the first memory in the form of logical redo redo logs. The data volume of redo logs is definite and is not affected by other factors such as indexes in the first memory, so the delay of data writing is definite , can be estimated.
图2示出了图数据库系统的硬件部分,除此之外,图数据库系统还包括软件部分,图3为本申请实施例所应用的图数据库系统的软件架构示意图。如图3所示,该图数据库系统包括执行引擎(Execution Engine)模块、存储引擎(Storage Engine)模块、资源管理器(resource maneger)和锁管理器(lock maneger)。FIG. 2 shows the hardware part of the graph database system. In addition, the graph database system also includes a software part. FIG. 3 is a schematic diagram of the software architecture of the graph database system applied in the embodiment of the present application. As shown in Figure 3, the graph database system includes an execution engine (Execution Engine) module, a storage engine (Storage Engine) module, a resource manager (resource manager) and a lock manager (lock manager).
其中,执行引擎模块包含第一内存管理器,第一内存管理器用于负责逻辑redo日志在第一内存中的存储;存储引擎包含第一内存合并单元,第一内存合并单元用于负责第一内存中逻辑redo日志的回放;资源管理器用于负责第二内存中图模型数据的存储;锁管理器用于管理锁资源。Wherein, the execution engine module includes a first memory manager, and the first memory manager is used to store logical redo logs in the first memory; the storage engine includes a first memory merging unit, and the first memory merging unit is used to be responsible for the storage of the first memory Playback of logical redo logs in the middle; the resource manager is responsible for storing graph model data in the second memory; the lock manager is used for managing lock resources.
如图3所示,在实际应用中,响应于应用程序的请求,第一内存管理器将由目标数据得到的逻辑redo日志存储至第一内存中;然后由第一内存合并单元回放逻辑redo日志,以将目标数据的图模型数据合并至第二内存中,并由资源管理器对第二内存中的图模型数据进行管理。在存储逻辑redo日志和回放逻辑redo日志的过程中,可能存在并发情况(即在存 储或回放逻辑redo日志的过程中,客户端程序需要读取或修改逻辑redo日志中的目标数据),当出现并发情况时,便可以采用锁管理器中的锁资源进行并发处理。As shown in Figure 3, in practical applications, in response to the request of the application program, the first memory manager stores the logical redo log obtained from the target data into the first memory; then the logical redo log is played back by the first memory merging unit, The graph model data of the target data is merged into the second memory, and the resource manager manages the graph model data in the second memory. In the process of storing logical redo logs and playing back logical redo logs, concurrency may exist (that is, during the process of storing or playing back logical redo logs, the client program needs to read or modify the target data in logical redo logs), when In case of concurrency, the lock resource in the lock manager can be used for concurrent processing.
图4为本申请实施例所应用的图数据库系统与外部系统之间的关系示意图。如图4所示,外部系统包括管理面、控制面、分析面、DLR(Data Logical Replication)分布式组件以及一些相关的工具(例如开发工具或运维测试工具)。FIG. 4 is a schematic diagram of the relationship between the graph database system applied in the embodiment of the present application and external systems. As shown in Figure 4, the external system includes management plane, control plane, analysis plane, DLR (Data Logical Replication) distributed components and some related tools (such as development tools or operation and maintenance testing tools).
其中,管理面、控制面和分析面是对通信技术领域中业务的划分,管理面用于负责网络中配置数据相关的业务,控制面板用于负责协议的计算、转发管理的业务,分析面用于负责分析设备运行状态的业务,DLR分布式组件用于负责不同设备间的数据的同步。Among them, the management plane, control plane, and analysis plane are the divisions of services in the field of communication technology. The management plane is used for business related to configuration data in the network, the control plane is used for protocol calculation and forwarding management business, and the analysis plane is used for For the business of analyzing the running status of devices, the DLR distributed component is used to synchronize data between different devices.
对于管理面和控制面来说,需要的是具备图数据管理能力的图数据库系统;相对于管理面、控制面来说,管理面、控制面与图数据库系统之间的交互操作均可以划分为主动操作和被动通知操作,其中,主动操作可以包括DDL/DML操作,被动通知操作可以包括pub/sub操作。For the management plane and the control plane, what is needed is a graph database system with graph data management capabilities; compared with the management plane and the control plane, the interactive operations between the management plane, the control plane and the graph database system can be divided into Active operation and passive notification operation, wherein the active operation may include DDL/DML operation, and the passive notification operation may include pub/sub operation.
对于分析面来说,需要的是具备时序能力的图数据库系统。相对于分析面来说,分析面与图数据库系统之间的交互操作均可以划分为主动操作和被动通知操作,其中,主动操作包括时序的DDL/DML操作,被动通知操作包括设定时序规则的通知操作或满足规则数据的通知操作。For the analysis side, what is needed is a graph database system with time series capabilities. Compared with the analysis plane, the interactive operations between the analysis plane and the graph database system can be divided into active operations and passive notification operations. Among them, active operations include timing DDL/DML operations, and passive notification operations include setting timing rules. A notification action or a notification action that satisfies rule data.
通过DLR分布式组件可以访问图数据库系统,具体地,可以并通过DLR分布式组件将图数据库系统中更新的数据同步到其他图数据库系统中,或将其他图数据库系统中的数据同步到该图数据库系统中。The graph database system can be accessed through the DLR distributed component. Specifically, the updated data in the graph database system can be synchronized to other graph database systems through the DLR distributed component, or the data in other graph database systems can be synchronized to the graph. in the database system.
本申请实施例所应用的图数据库系统可以部署在多种终端设备中,本申请实施例对终端设备的种类不做具体限定;例如,具体可以部署在路由器、交换机、防火墙以及WLAN产品中。The graph database system applied in the embodiment of the present application can be deployed in various terminal devices, and the embodiment of the present application does not specifically limit the types of terminal devices; for example, it can be deployed in routers, switches, firewalls, and WLAN products.
下面对本申请实施例提供的方法进行具体介绍。The method provided in the embodiment of the present application will be specifically introduced below.
本申请实施例提供的方法的应用场景:本申请实施例提供的方法可以应用于数据库系统,该数据库系统除了可以为上述图数据库系统,还可以为时序数据库系统、流数据库系统或流图数据库系统。Application scenario of the method provided by the embodiment of the present application: the method provided by the embodiment of the present application can be applied to the database system, and the database system can not only be the above-mentioned graph database system, but also a time series database system, a flow database system or a flow graph database system .
以图数据库系统为例,由于本申请实施例提供的方法能够保证同步写入的时延较低,所以本申请实施例尤其适用于一些对性能要求较高的图数据库系统的业务中。例如,对性能要求较高的图数据库系统的业务可以为转发管理业务,转发管理业务是交换机的核心业务,对数据的读写性能有极大要求。Taking the graph database system as an example, since the method provided by the embodiment of the present application can guarantee a low delay in synchronous writing, the embodiment of the present application is especially suitable for some graph database systems with high performance requirements. For example, the business of a graph database system with high performance requirements can be forwarding management business. Forwarding management business is the core business of switches and has great requirements on data read and write performance.
如图5所示,本申请提供了一种数据分段写入方法的一个实施例,应用于图数据库系统,图数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数。As shown in Figure 5, this application provides an embodiment of a method for writing data segments, which is applied to a graph database system. The graph database system includes a second storage space and N first storage spaces, where N is positive integer.
其中,图数据库系统可以理解为前文中的图数据库系统,第一存储空间可以理解为图1中的第一内存,第二存储空间可以理解为图1中的第二内存;具体可参照图1的相关说明对第一存储空间和第二存储空间进行理解。Among them, the graph database system can be understood as the above graph database system, the first storage space can be understood as the first memory in Figure 1, and the second storage space can be understood as the second memory in Figure 1; for details, refer to Figure 1 The relevant descriptions of .understand the first storage space and the second storage space.
基于上述图数据库系统,该实施例包括:Based on the above graph database system, this embodiment includes:
步骤101,第一线程从N个第一存储空间中,确定目标存储空间。 Step 101, the first thread determines a target storage space from N first storage spaces.
可以理解的是,只有在N大于1的情况下时,才需要执行步骤101,所以步骤101是可选的。It can be understood that step 101 needs to be performed only when N is greater than 1, so step 101 is optional.
第一线程也可以称为主体线程、业务线程或工作线程,具体是指运行数据库的客户端的线程。The first thread may also be called a main thread, a business thread or a working thread, and specifically refers to a thread of a client running a database.
应理解,在第一存储空间中,数据通常是以表的形式存储的,而第一存储空间中的表可以采用标签进行标记。It should be understood that in the first storage space, data is usually stored in the form of tables, and the tables in the first storage space may be marked with tags.
基于此,步骤101可以包括:第一线程根据目标数据对应的标签,以及标签与第一存储空间的对应关系,从N个第一存储空间中确定目标存储空间,标签指示用于存储目标数据的表。Based on this, step 101 may include: the first thread determines the target storage space from the N first storage spaces according to the label corresponding to the target data and the corresponding relationship between the label and the first storage space, and the label indicates the storage space used to store the target data surface.
步骤102,第一线程根据目标数据得到重做日志,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。 Step 102, the first thread obtains the redo log according to the target data, the redo log is used to represent the target data and the write operation of the target data, and the write operation is used to convert the target data into graph model data and write the graph model data into the second storage.
需要说明的是,由于前文对重做日志进行了说明,因此可参照前文的说明对重做日志进行理解;重做日志的格式有多种,本申请实施例对此不做具体限定。另外,根据目标数据得到重做日志的方法是较成熟的技术,本申请实施例在此不做详述。It should be noted that since the foregoing descriptions are made on redo logs, the redo logs can be understood by referring to the foregoing descriptions; there are various formats of redo logs, which are not specifically limited in this embodiment of the present application. In addition, the method of obtaining the redo log according to the target data is a relatively mature technology, which is not described in detail in this embodiment of the present application.
步骤103,第一线程将重做日志写入目标存储空间,目标存储空间为N个第一存储空间中的一个。 Step 103, the first thread writes the redo log into the target storage space, where the target storage space is one of the N first storage spaces.
第二线程是指数据库的工作线程。The second thread refers to a worker thread of the database.
可以理解的是,第一线程在向目标存储空间写入重做日志的过程中,可能出现并发情况,其中,并发情况是指其他线程需要对目标存储空间进行读操作或写操作的情况。It can be understood that, when the first thread writes redo logs to the target storage space, a concurrency situation may occur, wherein the concurrency situation refers to the situation that other threads need to perform read or write operations on the target storage space.
当出现并发情况时,可以采用相应的锁机制进行并发情况的控制。When concurrency occurs, the corresponding lock mechanism can be used to control the concurrency.
锁机制的选择方法如下。The selection method of the locking mechanism is as follows.
首先,对于目标存储空间,负载特征如下:基于前文中的第一内存的相关说明可知,通常情况下,每种业务对应一个第一存储空间,其他种类的业务对目标存储空间进行读操作或写操作的可能性很小。一般只有当第一线程向第一存储空间中写入重做日志,且第二线程回放目标存储空间中的重做日志时,才可能出现并发情况;然而,基于数据合并机制,通常情况下,第一线程写入重做日志的操作和第二线程回放重做日志的操作会在不同的时间执行,下文会对数据合并机制进行说明。First of all, for the target storage space, the load characteristics are as follows: Based on the description of the first memory in the previous section, it can be known that, usually, each type of service corresponds to a first storage space, and other types of services perform read operations or write operations on the target storage space. Operation is very unlikely. Generally, only when the first thread writes redo logs to the first storage space, and the second thread plays back the redo logs in the target storage space, concurrency may occur; however, based on the data merging mechanism, usually, The operation of writing the redo log by the first thread and playing back the redo log by the second thread will be performed at different times, and the data merging mechanism will be described below.
通常情况下,物理锁和事务锁配合可以处理各种冲突场景,但基于上述负载特征,在第一线程对目标存储空间进行写操作时,出现并发情况的可能性较小,即在目标存储空间中产生的冲突较小。因此可以仅选择物理锁处理出现的并发情况,并且,对于物理锁来说,存在多种用于处理并发情况的锁机制,基于冲突小的负载特征,本申请实施例可以采用简单的锁机制,以降低同步写入过程中的时延。具体地,步骤103可以包括:Normally, the combination of physical locks and transaction locks can handle various conflict scenarios, but based on the above load characteristics, when the first thread writes to the target storage space, the possibility of concurrency is less, that is, in the target storage space The conflicts that arise are minor. Therefore, only the physical lock can be selected to handle the concurrency that occurs, and for the physical lock, there are multiple locking mechanisms for handling the concurrency. Based on the load characteristics of small conflicts, the embodiment of the present application can adopt a simple lock mechanism. To reduce the delay in the process of synchronous writing. Specifically, step 103 may include:
第一线程通过物理锁的严格两段锁机制,将重做日志写入目标存储空间。The first thread writes the redo log into the target storage space through the strict two-stage lock mechanism of the physical lock.
需要说明的是,相比于物理锁的其他锁机制,物理锁的严格两段锁机制(Strict 2Phase Locking)较为简单,所以能够降低写入重做日志的时延;并且,物理锁的严格两段锁机制不包含数据库对象锁,可以降低锁的开销。It should be noted that compared with other locking mechanisms of physical locks, the strict two-phase locking mechanism of physical locks (Strict 2Phase Locking) is relatively simple, so it can reduce the delay of writing redo logs; and, the strict two-phase locking mechanism of physical locks The segment lock mechanism does not include database object locks, which can reduce the overhead of locks.
在执行步骤103之后,可以基于设定的数据合并机制,将目标存储空间中的数据合并到第二存储空间中。After step 103 is executed, the data in the target storage space may be merged into the second storage space based on the set data merging mechanism.
数据合并机制包括多种,本申请实施例对此不做具体限定。下面通过步骤104和步骤107对数据合并机制进行介绍。There are multiple data merging mechanisms, which are not specifically limited in this embodiment of the present application. The data merging mechanism is introduced below through step 104 and step 107 .
步骤104,第一线程向第二线程发送请求,请求用于指示第二线程回放目标存储空间中的重做日志。 Step 104, the first thread sends a request to the second thread, and the request is used to instruct the second thread to replay the redo logs in the target storage space.
在执行步骤103之后,可以通过步骤104通知第二线程回放重做日志,以将第一存储空间中的数据合并到第二存储空间中;需要说明的是,在未接收通知的情况下,第二线程也可以自行回放重做日志,因此步骤104是可选的。After step 103 is executed, step 104 may be used to notify the second thread to play back the redo log, so as to merge the data in the first storage space into the second storage space; it should be noted that if the notification is not received, the second thread The second thread can also replay the redo log by itself, so step 104 is optional.
第一线程向第二线程发送请求的情况有多种,本申请实施例对此不做具体限定。There are many situations in which the first thread sends a request to the second thread, which is not specifically limited in this embodiment of the present application.
作为一种可实现的方式,步骤104包括:在目标存储空间中已使用的存储空间达到第一阈值的情况下,第一线程向第二线程发送请求。As an implementable manner, step 104 includes: when the used storage space in the target storage space reaches a first threshold, the first thread sends a request to the second thread.
可以理解的是,由于目标存储空间中已使用的存储空间达到第一阈值,这表明目标存储空间中的剩余空间有限,因此可以主动向第二线程发送请求。It can be understood that since the used storage space in the target storage space reaches the first threshold, it indicates that the remaining space in the target storage space is limited, so a request may be actively sent to the second thread.
具体地,第一线程在需要写入新的数据的重做日志的情况下,对目标存储空间中已使用的存储空间进行判断,以防止目标存储空间中的剩余空间有限无法存储新的数据的重做日志。Specifically, when the first thread needs to write the redo log of new data, it judges the used storage space in the target storage space, so as to prevent the situation that the remaining space in the target storage space is limited and cannot store new data. Redo logs.
作为另一种可实现的方式,步骤104包括:响应于业务需求,第一线程向第二线程发送请求。As another implementable manner, step 104 includes: the first thread sends a request to the second thread in response to a service requirement.
需要说明的是,本申请实施例对业务需求的内容不做具体限定。It should be noted that, the embodiment of the present application does not specifically limit the content of the service requirement.
例如,业务需求包括:需要从第二存储空间中读取图数据库系统中的最新数据。基于此,若第一存储空间中的重做日志未回放,则第二存储空间中的数据不是最新的,此时,响应于该业务需求,第一线程便可以主动向第二线程发送请求。For example, the business requirement includes: the latest data in the graph database system needs to be read from the second storage space. Based on this, if the redo logs in the first storage space have not been played back, the data in the second storage space is not up-to-date. At this time, in response to the business requirement, the first thread can actively send a request to the second thread.
步骤105,第二线程读取目标存储空间中的重做日志,目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间; Step 105, the second thread reads the redo log in the target storage space, the target storage space is one of the N first storage spaces, the redo log is used to represent the target data and the write operation of the target data, and the write operation is used for converting the target data into graph model data and writing the graph model data into the second storage space;
其中,第二线程读取重做日志可以包括主动读取和被动读取两种情况,下面对此进行具体介绍。The reading of redo logs by the second thread may include active reading and passive reading, which will be described in detail below.
作为一种可实现的方式,步骤105包括:第二线程周期性地读取目标存储空间中的重做日志。As an implementable manner, step 105 includes: the second thread periodically reads redo logs in the target storage space.
具体地,可以为第二线程设定定时任务,使得第二线程定时检查包含目标存储空间在内的每个第一存储空间,若目标存储空间当前没有正在指定的数据合并操作,则主动读取目标存储空间中的重做日志,以完成数据合并操作。Specifically, a timed task can be set for the second thread, so that the second thread regularly checks each first storage space including the target storage space, and if the target storage space does not currently have a designated data merge operation, it will actively read Redo logs in the target storage space to complete the data consolidation operation.
上述情况可以理解为第二线程主动读取重做日志的情况,下面介绍第二线程被动读取重做日志的情况。The above situation can be understood as the situation where the second thread actively reads the redo log, and the following describes the situation where the second thread passively reads the redo log.
作为另一种可实现的方式,步骤105包括:As another practicable manner, step 105 includes:
在接收到来自所述第一线程的请求的情况下,所述第二线程读取目标存储空间中的重 做日志,所述请求用于指示所述第二线程回放所述目标存储空间中的所述重做日志,以将所述目标数据对应的图模型数据写入所述第二存储空间。When receiving a request from the first thread, the second thread reads the redo logs in the target storage space, and the request is used to instruct the second thread to play back the redo logs in the target storage space The redo log is used to write the graph model data corresponding to the target data into the second storage space.
需要说明的是,可参阅步骤104的情况对请求进行具体理解。It should be noted that the request can be specifically understood with reference to the situation in step 104 .
步骤106,第二线程回放目标存储空间中的重做日志,以执行写操作。 Step 106, the second thread plays back the redo logs in the target storage space to perform the write operation.
具体地,第二线程可以逐行回放重做日志,以实现数据的合并。Specifically, the second thread can replay the redo log line by line, so as to realize data merging.
下面结合图6对第二线程回放重做日志的过程进行说明。The process of replaying redo logs by the second thread will be described below with reference to FIG. 6 .
如图6所示,重做日志中一般包含开始事务(start transaction)(T1)操作、写(write)A(T1)操作、start transaction(T2)操作、write B(T1)操作、write C(T2)操作、完成(commit)(T1)操作以及commit(T2)操作。As shown in Figure 6, redo logs generally include start transaction (T1) operation, write (write) A (T1) operation, start transaction (T2) operation, write B (T1) operation, write C ( T2) operation, commit (T1) operation, and commit (T2) operation.
在回放重做日志的过程中,第二线程会调用数据库的相应的应用程序接口(Application Programming Interface,API),以将目标数据对应的图模型数据写入第二存储空间。In the process of playing back the redo log, the second thread will call the corresponding application programming interface (Application Programming Interface, API) of the database to write the graph model data corresponding to the target data into the second storage space.
如图6所示,第二线程调用的API依次为start transaction API(用于执行开始事务T1操作)、write API(用于执行写A操作)、start transaction API(用于执行开始事务T2操作)、write API(用于执行写B操作)、write API(用于执行写C操作)、start transaction API(用于执行完成T1操作)、start transaction API(用于执行完成T2操作)。As shown in Figure 6, the APIs called by the second thread are start transaction API (used to execute the start transaction T1 operation), write API (used to execute the write A operation), start transaction API (used to execute the start transaction T2 operation) , write API (used to execute write B operation), write API (used to execute write C operation), start transaction API (used to execute and complete T1 operation), start transaction API (used to execute and complete T2 operation).
第二线程在回放重做日志时,需要执行对第二存储空间的写操作,与第一线程写入重做日志的类似,第二线程在回放重做日志的过程中也可能出现并发情况;当出现并发情况时,可以采用相应的锁机制进行并发情况的控制。When the second thread plays back the redo log, it needs to perform a write operation to the second storage space, which is similar to the first thread writing the redo log, and the second thread may also have concurrency in the process of playing back the redo log; When concurrency occurs, the corresponding lock mechanism can be used to control the concurrency.
锁机制的选择方法如下。The selection method of the locking mechanism is as follows.
首先,对于第二存储空间,负载特征如下:第二存储空间中的事务主要包括线程的数据写入事务以及只读事务;尽管可能存在多个第一存储空间,但每个第一存储空间对应的写入事务只负责将第一存储空间中的数据合并至第二存储空间中的某个特定的存储位置上,因此多个第一存储空间对应的写入事务之间没有冲突;基于此,冲突主要发生在线程的写事务和线程的只读事务之间。First of all, for the second storage space, the load characteristics are as follows: the transactions in the second storage space mainly include data write transactions and read-only transactions of threads; although there may be multiple first storage spaces, each first storage space corresponds to The write transaction in the first storage space is only responsible for merging the data in the first storage space to a specific storage location in the second storage space, so there is no conflict between the write transactions corresponding to multiple first storage spaces; based on this, Conflicts mainly occur between a thread's write transaction and a thread's read-only transaction.
基于上述负载特征,在第二线程对目标存储空间进行写操作时,可以选择读写操作代价较小的锁机制。Based on the above load characteristics, when the second thread performs a write operation on the target storage space, a lock mechanism with a lower cost for read and write operations can be selected.
具体地,步骤106包括:第二线程通过多版本的两段锁机制(Multi-Version 2Phase Locking,MV2PL)机制回放目标存储空间中的重做日志。Specifically, step 106 includes: the second thread replays the redo logs in the target storage space through a multi-version two-phase locking mechanism (Multi-Version 2Phase Locking, MV2PL) mechanism.
当并发情况(可以理解为既需要对数据进行读操作,也需要对数据进行写操作)发生时,MV2PL多版本的两段锁机制使得读操作和写操作可以同时进行,不需要等待一个操作(例如写操作)完成后再执行另一个操作(例如读操作),所以代价较小,能够降低第二线程在回放重做日志过程的开销。When a concurrent situation (which can be understood as requiring both data read and write operations) occurs, the two-stage lock mechanism of the MV2PL multi-version allows read operations and write operations to be performed at the same time without waiting for an operation ( For example, another operation (such as a read operation) is performed after the completion of the write operation, so the cost is small, and the overhead of the second thread in the playback redo log process can be reduced.
步骤107,第二线程删除目标存储空间中的重做日志。 Step 107, the second thread deletes redo logs in the target storage space.
在回放重做日志后,将重做日志删除,可以保证目标存储空间中有足够的剩余空间,以便第一线程写入新的数据的重做日志。After replaying the redo log, deleting the redo log can ensure that there is enough remaining space in the target storage space so that the first thread can write new data into the redo log.
由此可见,在本申请实施例中,目标存储空间主要负责存储新增的数据的重做日志,简单的说,目标存储空间负责存储增量数据;对应地,第二存储空间则负责存储全量数据。It can be seen that in the embodiment of this application, the target storage space is mainly responsible for storing the redo logs of newly added data. Simply put, the target storage space is responsible for storing incremental data; correspondingly, the second storage space is responsible for storing the full amount data.
根据步骤101至步骤107的说明可知,本申请实施例将图数据库中的写入目标数据的事务分解成user transaction用户事务和system transaction系统事务这两段事务。用户事务是指运行在第一存储空间中的事务,用于将由目标数据封装成的重做日志写入目标存储空间,并做一些必要的检查,这些必要的检查包约束性检查、唯一性检查等。此外,用户事务还用于通过逆序访问来实现数据的可见性控制,通过锁机制来实现并发控制,保证了第一存储空间中并发读写的正确性。系统事务是指运行在第二存储空间中的事务,用于回放重做日志,并用于维护图模型数据在第二存储空间中的索引以及触发订阅推送等操作。According to the description of step 101 to step 107, it can be seen that in the embodiment of the present application, the transaction of writing target data in the graph database is decomposed into two transactions: user transaction and system transaction. User transaction refers to the transaction running in the first storage space, which is used to write the redo log encapsulated by the target data into the target storage space, and do some necessary checks, which include constraint checks and uniqueness checks wait. In addition, user transactions are also used to implement data visibility control through reverse order access, and achieve concurrency control through the lock mechanism, ensuring the correctness of concurrent read and write in the first storage space. System transactions refer to transactions running in the second storage space, used to play back redo logs, maintain the index of graph model data in the second storage space, and trigger operations such as subscription push.
逆序访问是指按照数据产生的时间由晚到早的顺序访问,以日志为例,数据库中可以包含很多日志,不同的日志对应不同的生成时间,逆序访问则是指先访问较晚生成的日志,再访问较早生成的日志。Reverse order access refers to accessing data in the order from late to early when the data is generated. Taking logs as an example, the database can contain many logs, and different logs correspond to different generation times. Reverse order access refers to accessing the logs generated later. Revisit earlier generated logs.
上述两段事务保证了图数据库系统的事务性,提高了数据库系统的可靠性和可用性。The above two transactions ensure the transactionality of the graph database system and improve the reliability and availability of the database system.
如图7所示,采用本申请实施例提供的方法写入目标数据的过程包括:第一线程将目标数据的重做日志写入目标存储空间,并返回写成成功的结果;第二线程读取目标存储空间中的重做日志,并回放重做日志;在回放重做日志后,删除目标存储空间中已经回放的重做日志。As shown in Figure 7, the process of writing target data using the method provided by the embodiment of the present application includes: the first thread writes the redo log of the target data into the target storage space, and returns the result of successful writing; the second thread reads Redo logs in the target storage space, and replay the redo logs; after replaying the redo logs, delete the redo logs that have been played back in the target storage space.
上文对写入图数据库系统的过程进行了介绍,下面对读取图数据库系统的过程进行介绍。The process of writing to the graph database system is introduced above, and the process of reading the graph database system is introduced below.
基于前文说明可知,数据库系统包括第二存储空间和N个第一存储空间,下面以N个第一存储空间中的目标存储空间为例进行说明。Based on the foregoing description, it can be known that the database system includes a second storage space and N first storage spaces, and the following description will be made by taking a target storage space among the N first storage spaces as an example.
可以理解的是,由于在写入过程中,目标数据先以重做日志的形式存储在目标存储空间中,然后经过重做日志的回放存储在第二存储空间中。It can be understood that, during the writing process, the target data is first stored in the target storage space in the form of redo logs, and then stored in the second storage space after redo log playback.
所以当需要读取目标数据时,目标数据可能存储在目标存储空间中,也可能存储在第二存储空间中。Therefore, when the target data needs to be read, the target data may be stored in the target storage space or in the second storage space.
因此,第三线程可以先查询目标存储空间,然后再查询第二存储空间;第三线程也可以直接查询第二存储空间。Therefore, the third thread can query the target storage space first, and then query the second storage space; the third thread can also directly query the second storage space.
以先查询目标存储空间,再查询第二存储空间为例,存在两种情况:第一种情况是目标数据对应的重做日志存储在目标存储空间,但目标数据未存储在第二存储空间中;第二种情况是目标数据存储在第二存储空间中。Taking querying the target storage space first, and then querying the second storage space as an example, there are two cases: the first case is that the redo logs corresponding to the target data are stored in the target storage space, but the target data is not stored in the second storage space ; The second case is that the target data is stored in the second storage space.
对于上述第一种情况,请参阅图8,数据读取方法包括以下步骤。For the first case above, please refer to FIG. 8 , the data reading method includes the following steps.
步骤108,第三线程获取目标数据对应的数据库主键。 Step 108, the third thread obtains the database primary key corresponding to the target data.
数据库主键通常是从目标数据中选择的部分数据,其值能唯一地标识表中的每一行。A database primary key is usually a selected portion of the target data whose value uniquely identifies each row in the table.
可以理解的是,在数据库中,数据是以表的形式存储的,表中包含多行,每行存储有数据。It can be understood that in the database, data is stored in the form of a table, and the table contains multiple rows, and each row stores data.
步骤109,第三线程根据数据库主键从目标存储空间中读取重做日志。 Step 109, the third thread reads redo logs from the target storage space according to the database primary key.
目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。The target storage space is one of the N first storage spaces. The redo log is used to represent the target data and the write operation of the target data. The write operation is used to convert the target data into graph model data and write the graph model data into the second storage.
第三线程是指数据读取线程,可以与前文中的第一线程相同。The third thread refers to the data reading thread, which may be the same as the first thread mentioned above.
由于第三线程可以通过读取重做日志得到目标数据,而不需执行图模型数据到目标数据的转换操作,所以可以降低目标数据的读取时延。Since the third thread can obtain the target data by reading the redo log without performing a conversion operation from the graph model data to the target data, the time delay for reading the target data can be reduced.
作为一种可实现的方式,在步骤109之前,该方法还包括:As an implementable manner, before step 109, the method further includes:
第三线程根据数据库主键确定目标数据的写入事务的标识;The third thread determines the identifier of the writing transaction of the target data according to the database primary key;
第三线程根据写入事务的标识,确定目标存储空间中包含事务提交日志,该事务提交日志用于表示写入事务已提交。The third thread determines that the target storage space contains a transaction commit log according to the identifier of the write transaction, and the transaction commit log is used to indicate that the write transaction has been committed.
可以理解的是,对于数据库中的事务来说,会通过事务提交日志表示事务已提交;同样地,在本申请实施例中,也通过事务提交日志表示写入事务已提交。It can be understood that, for a transaction in the database, the transaction commit log is used to indicate that the transaction has been committed; similarly, in the embodiment of the present application, the transaction commit log is also used to indicate that the writing transaction has been committed.
若写入事务已提交,则表示目标数据已完成写入过程,其他用户便可以读取该目标数据;若写入事务未提交,则表示目标数据未完成写入过程,其他用户便不能读取该目标数据。If the write transaction has been submitted, it means that the target data has completed the writing process, and other users can read the target data; if the write transaction is not committed, it means that the target data has not completed the writing process, and other users cannot read it the target data.
需要说明的是,由于事务提交日志的存储位置通常位于写入事务的日志的存储位置之后,所以在查找目标存储空间中是否包含事务提交日志时,可以采用前文中的逆序访问的方法遍历,以便尽快查找目标存储空间中是否包含事务提交日志。It should be noted that since the storage location of the transaction commit log is usually after the storage location of the log written to the transaction, when looking for whether the target storage space contains the transaction commit log, you can use the reverse order access method mentioned above to traverse, so that Find out whether the target storage space contains transaction commit logs as soon as possible.
对于上述第二种情况,数据读取方法包括以下步骤。For the second case above, the data reading method includes the following steps.
第三线程根据数据库主键查询目标存储空间;在目标存储空间中不包含目标数据的情况下,第三线程根据数据库主键查询第二存储空间,以得到目标数据。The third thread queries the target storage space according to the primary key of the database; if the target storage space does not contain the target data, the third thread queries the second storage space according to the primary key of the database to obtain the target data.
在该实施例中,第三线程先查询目标存储空间,若未查询到目标数据,则再查询第二存储空间。In this embodiment, the third thread queries the target storage space first, and then queries the second storage space if the target data is not found.
基于上文说明可知,在数据写入过程中,先以重做日志的形式将目标数据写入目标存储空间,然后通过重做日志的回放将目标数据写入第二存储过程;相应地,在数据读取过程中,可以先后查询目标存储空间和第二存储空间,以得到目标数据。Based on the above description, in the data writing process, the target data is first written into the target storage space in the form of redo logs, and then the target data is written into the second storage process through redo log playback; correspondingly, in During the data reading process, the target storage space and the second storage space may be queried successively to obtain the target data.
由此可见,在本申请实施例中,可能需要两次读取才能得到目标数据,因此,本申请实施例是通过增加读取时延,来降低目标数据的写入时延。It can be seen that, in the embodiment of the present application, two reads may be required to obtain the target data. Therefore, the embodiment of the present application reduces the writing delay of the target data by increasing the read delay.
基于前文说明可知,第三线程也可以直接查询第二存储空间,具体地,第三线程根据数据库主键从第二存储空间读取图模型数据,图模型数据根据第二线程回放的目标存储空间中的重做日志得到的。Based on the previous description, the third thread can also directly query the second storage space. Specifically, the third thread reads the graph model data from the second storage space according to the database primary key, and the graph model data is stored in the target storage space played back by the second thread. The redo log obtained.
图9为本申请实施例提供的数据分段写入装置的实施例示意图。如图9所示,本申请提供了一种数据分段写入装置的一个实施例,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;装置包括:封装单元201,用于根据目标数据得到重做日志,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。FIG. 9 is a schematic diagram of an embodiment of an apparatus for writing data segments according to an embodiment of the present application. As shown in FIG. 9, the present application provides an embodiment of a device for writing data segments, which is applied to a database system. The database system includes a second storage space and N first storage spaces, where N is a positive integer; The device includes: an encapsulation unit 201, configured to obtain a redo log according to the target data, the redo log is used to represent the target data and the write operation of the target data, and the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space.
写入单元202,用于将重做日志写入目标存储空间,目标存储空间为N个第一存储空间中的一个。The writing unit 202 is configured to write redo logs into a target storage space, where the target storage space is one of the N first storage spaces.
作为一种可实现的方式,装置还包括:发送单元203,用于向第二线程发送请求,请求用于指示第二线程回放目标存储空间中的重做日志,以将目标数据对应的图模型数据写入第二存储空间。As an implementable manner, the device further includes: a sending unit 203, configured to send a request to the second thread, and the request is used to instruct the second thread to replay the redo logs in the target storage space, so as to model the graph corresponding to the target data Data is written into the second storage space.
作为一种可实现的方式,发送单元203,用于在目标存储空间中已使用的存储空间达到第一阈值的情况下,向第二线程发送请求。As an implementable manner, the sending unit 203 is configured to send a request to the second thread when the used storage space in the target storage space reaches a first threshold.
作为一种可实现的方式,发送单元203,用于响应于业务需求,向第二线程发送请求。As an implementable manner, the sending unit 203 is configured to send a request to the second thread in response to a service requirement.
作为一种可实现的方式,装置还包括:确定单元204,用于从N个第一存储空间中,确定目标存储空间。As a practicable manner, the device further includes: a determining unit 204, configured to determine a target storage space from the N first storage spaces.
作为一种可实现的方式,确定单元204,用于根据目标数据对应的标签,以及标签与第一存储空间的对应关系,从N个第一存储空间中确定目标存储空间,标签指示用于存储目标数据的表。As a practicable manner, the determining unit 204 is configured to determine the target storage space from the N first storage spaces according to the label corresponding to the target data and the corresponding relationship between the label and the first storage space, and the label indicates that it is used to store A table of target data.
作为一种可实现的方式,写入单元202,用于通过物理锁的严格两段锁机制,将重做日志写入目标存储空间。As a practicable manner, the writing unit 202 is configured to write the redo log into the target storage space through the strict two-stage locking mechanism of the physical lock.
其中,以上各单元的具体实现、相关说明以及技术效果请参考方法部分的相关描述。Wherein, for the specific implementation, relevant description and technical effects of the above units, please refer to the relevant description in the method part.
图10为本申请实施例提供的数据分段写入装置的实施例示意图。如图10所示,本申请提供了一种数据分段写入装置的另一个实施例,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;装置包括:读取单元301,用于第二线程读取目标存储空间中的重做日志,目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间;回放单元302,用于回放目标存储空间中的重做日志,以执行写操作。FIG. 10 is a schematic diagram of an embodiment of an apparatus for writing data segments according to an embodiment of the present application. As shown in Figure 10, the present application provides another embodiment of a device for writing data segments, which is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer The device includes: a reading unit 301, used for the second thread to read the redo log in the target storage space, the target storage space is one of the N first storage spaces, and the redo log is used to represent the target data and the target data The write operation is used to convert the target data into graph model data and write the graph model data into the second storage space; the replay unit 302 is used to replay redo logs in the target storage space to perform the write operation.
作为一种可实现的方式,读取单元301,用于周期性地读取目标存储空间中的重做日志。As a practicable manner, the reading unit 301 is configured to periodically read redo logs in the target storage space.
作为一种可实现的方式,读取单元301,用于在接收到来自第一线程的请求的情况下,读取目标存储空间中的重做日志,请求用于指示第二线程回放目标存储空间中的重做日志,以将图模型数据存储至第二存储空间。As an implementable manner, the reading unit 301 is configured to read the redo logs in the target storage space when receiving a request from the first thread, and the request is used to instruct the second thread to replay the target storage space Redo logs in to store the graph model data in the secondary storage space.
作为一种可实现的方式,回放单元302,用于第二线程通过多版本的两段锁机制回放目标存储空间中的重做日志。As an implementable manner, the replay unit 302 is used for the second thread to replay the redo logs in the target storage space through a multi-version two-segment lock mechanism.
作为一种可实现的方式,装置还包括删除单元303,用于删除目标存储空间中的重做日志。As a practicable manner, the device further includes a deletion unit 303, configured to delete redo logs in the target storage space.
其中,以上各单元的具体实现、相关说明以及技术效果请参考方法部分的相关描述。Wherein, for the specific implementation, relevant description and technical effects of the above units, please refer to the relevant description in the method part.
图11为本申请实施例提供的数据读取装置的实施例示意图。如图11所示,本申请提供了一种数据读取装置的一个实施例,应用于数据库系统,数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;装置包括:获取单元401,用于获取目标数据对应的数据库主键;读取单元402,用于根据数据库主键从目标存储空间中读取重做日志,或者,用于根据数据库主键从第二存储空间读取图模型数据,图模型数据根据第二线程回放的目标存储空间中的重做日志得到的;目标存储空间为N个第一存储空间中的一个,重 做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。FIG. 11 is a schematic diagram of an embodiment of a data reading device provided in an embodiment of the present application. As shown in Figure 11, the present application provides an embodiment of a data reading device, which is applied to a database system, and the database system includes a second storage space and N first storage spaces, wherein N is a positive integer; the device includes : the obtaining unit 401 is used to obtain the database primary key corresponding to the target data; the reading unit 402 is used to read the redo log from the target storage space according to the database primary key, or to read the redo log from the second storage space according to the database primary key Graph model data, the graph model data is obtained according to the redo log in the target storage space played back by the second thread; the target storage space is one of the N first storage spaces, and the redo log is used to represent the target data and the target data A write operation, the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space.
作为一种可实现的方式,读取单元402,用于根据数据库主键查询目标存储空间,以得到目标数据。As a practicable manner, the reading unit 402 is configured to query the target storage space according to the primary key of the database, so as to obtain the target data.
作为一种可实现的方式,读取单元402,用于根据数据库主键确定目标数据的写入事务的标识;根据写入事务的标识,确定目标存储空间中包含事务提交日志,事务提交日志用于表示写入事务已提交。As an achievable manner, the reading unit 402 is configured to determine the identifier of the write transaction of the target data according to the database primary key; according to the identifier of the write transaction, determine that the target storage space contains a transaction commit log, and the transaction commit log is used for Indicates that the write transaction has committed.
其中,以上各单元的具体实现、相关说明以及技术效果请参考第三方面的相关描述。Wherein, for the specific implementation, relevant description and technical effect of each of the above units, please refer to the relevant description of the third aspect.
请参阅图12,图12是本申请实施例提供的终端设备的一种结构示意图,具体用于实现图9对应实施例中数据分段写入装置的功能、图10对应实施例中数据分段写入装置的功能或图11对应实施例中数据读取装置的功能;终端设备1800可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(central processing units,CPU)1822(例如,一个或一个以上处理器)和存储器1832,一个或一个以上存储应用程序1842或数据1844的存储介质1830(例如一个或一个以上海量存储设备)。其中,存储器1832和存储介质1830可以是短暂存储或持久存储。存储在存储介质1830的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对终端设备中的一系列指令操作。更进一步地,中央处理器1822可以设置为与存储介质1830通信,在终端设备1800上执行存储介质1830中的一系列指令操作。Please refer to Figure 12, Figure 12 is a schematic structural diagram of a terminal device provided in the embodiment of the present application, which is specifically used to realize the function of the data segment writing device in the embodiment corresponding to Figure 9, and the data segment in the embodiment corresponding to Figure 10 The function of the writing device or the function of the data reading device in the corresponding embodiment in FIG. 11; the terminal device 1800 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (central processing units, CPUs) ) 1822 (eg, one or more processors) and memory 1832, one or more storage media 1830 (eg, one or more mass storage devices) that store application programs 1842 or data 1844. Wherein, the memory 1832 and the storage medium 1830 may be temporary storage or persistent storage. The program stored in the storage medium 1830 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the terminal device. Furthermore, the central processing unit 1822 may be configured to communicate with the storage medium 1830 , and execute a series of instruction operations in the storage medium 1830 on the terminal device 1800 .
终端设备1800还可以包括一个或一个以上电源1826,一个或一个以上有线或无线网络接口1850,一个或一个以上输入输出接口1858,和/或,一个或一个以上操作系统1841,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。The terminal device 1800 can also include one or more power supplies 1826, one or more wired or wireless network interfaces 1850, one or more input and output interfaces 1858, and/or, one or more operating systems 1841, such as Windows Server™, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
本申请实施例中,中央处理器1822,可以用于执行图9对应实施例中数据分段写入装置执行的数据分段写入方法。具体的,中央处理器1822,可以用于:In the embodiment of the present application, the central processing unit 1822 may be configured to execute the data segment writing method performed by the data segment writing device in the embodiment corresponding to FIG. 9 . Specifically, the central processing unit 1822 can be used for:
根据目标数据得到重做日志,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间;A redo log is obtained according to the target data, and the redo log is used to represent the target data and a write operation of the target data, and the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space;
将重做日志写入目标存储空间,目标存储空间为N个第一存储空间中的一个。Write the redo log into the target storage space, where the target storage space is one of the N first storage spaces.
本申请实施例中,中央处理器1822,可以用于执行图10对应实施例中数据分段写入装置执行的数据分段写入方法。具体的,中央处理器1822,可以用于:In the embodiment of the present application, the central processing unit 1822 may be configured to execute the data segment writing method performed by the data segment writing device in the embodiment corresponding to FIG. 10 . Specifically, the central processing unit 1822 can be used for:
读取目标存储空间中的重做日志,目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间;Read the redo log in the target storage space. The target storage space is one of the N first storage spaces. The redo log is used to represent the target data and the write operation of the target data. The write operation is used to convert the target data into a graph Model data and write the graph model data into the second storage space;
回放目标存储空间中的重做日志,以执行写操作。Replay the redo logs in the target storage space for write operations.
本申请实施例中,中央处理器1822,可以用于执行图11对应实施例中数据读取装置执行的数据读取方法。具体的,中央处理器1822,可以用于:In the embodiment of the present application, the central processing unit 1822 may be used to execute the data reading method performed by the data reading device in the embodiment corresponding to FIG. 11 . Specifically, the central processing unit 1822 can be used for:
获取目标数据对应的数据库主键;Obtain the database primary key corresponding to the target data;
根据数据库主键从目标存储空间中读取重做日志,或者,第三线程根据数据库主键从第二存储空间读取图模型数据,图模型数据根据第二线程回放的目标存储空间中的重做日 志得到的;Read the redo logs from the target storage space according to the database primary key, or, the third thread reads the graph model data from the second storage space according to the database primary key, and the graph model data is based on the redo logs in the target storage space played back by the second thread owned;
目标存储空间为N个第一存储空间中的一个,重做日志用于表示目标数据以及目标数据的写操作,写操作用于将目标数据转换成图模型数据并将图模型数据写入第二存储空间。The target storage space is one of the N first storage spaces. The redo log is used to represent the target data and the write operation of the target data. The write operation is used to convert the target data into graph model data and write the graph model data into the second storage.
本申请实施例还提供一种芯片,包括一个或多个处理器。所述处理器中的部分或全部用于读取并执行存储器中存储的计算机程序,以执行前述各实施例的方法。The embodiment of the present application also provides a chip, including one or more processors. Part or all of the processor is used to read and execute the computer program stored in the memory, so as to execute the methods of the foregoing embodiments.
可选地,该芯片该包括存储器,该存储器与该处理器通过电路或电线与存储器连接。进一步可选地,该芯片还包括通信接口,处理器与该通信接口连接。通信接口用于接收需要处理的数据和/或信息,处理器从该通信接口获取该数据和/或信息,并对该数据和/或信息进行处理,并通过该通信接口输出处理结果。该通信接口可以是输入输出接口。Optionally, the chip includes a memory, and the memory and the processor are connected to the memory through a circuit or wires. Further optionally, the chip further includes a communication interface, and the processor is connected to the communication interface. The communication interface is used to receive data and/or information to be processed, and the processor obtains the data and/or information from the communication interface, processes the data and/or information, and outputs the processing result through the communication interface. The communication interface may be an input-output interface.
在一些实现方式中,所述一个或多个处理器中还可以有部分处理器是通过专用硬件的方式来实现以上方法中的部分步骤,例如涉及神经网络模型的处理可以由专用神经网络处理器或图形处理器来实现。In some implementations, some of the one or more processors may implement some of the steps in the above method through dedicated hardware, for example, the processing related to the neural network model may be performed by a dedicated neural network processor or graphics processor to achieve.
本申请实施例提供的方法可以由一个芯片实现,也可以由多个芯片协同实现。The method provided in the embodiment of the present application may be implemented by one chip, or may be implemented by multiple chips in cooperation.
本申请实施例还提供了一种计算机存储介质,该计算机存储介质用于储存为上述计算机设备所用的计算机软件指令,其包括用于执行为计算机设备所设计的程序。The embodiment of the present application also provides a computer storage medium, which is used for storing computer software instructions used by the above-mentioned computer equipment, including instructions for executing a program designed for the computer equipment.
该计算机设备可以如前述图9对应实施例中的数据分段写入装置、图10对应实施例中的数据分段写入装置或图11对应实施例中数据读取装置的功能。The computer device may have the same functions as the data segment writing device in the embodiment corresponding to FIG. 9 , the data segment writing device in the embodiment corresponding to FIG. 10 , or the data reading device in the embodiment corresponding to FIG. 11 .
本申请实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机软件指令,该计算机软件指令可通过处理器进行加载来实现前述各个实施例所示的方法中的流程。The embodiment of the present application also provides a computer program product, the computer program product includes computer software instructions, and the computer software instructions can be loaded by a processor to implement the procedures in the methods shown in the foregoing embodiments.
以上,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。The above is only the specific implementation of the application, but the scope of protection of the application is not limited thereto. Anyone familiar with the technical field can easily think of changes or replacements within the technical scope disclosed in the application, and should cover Within the protection scope of this application.

Claims (22)

  1. 一种数据分段写入方法,其特征在于,应用于数据库系统,所述数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;A data segment writing method, characterized in that it is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer;
    所述方法包括:The methods include:
    第一线程根据目标数据得到重做日志,所述重做日志用于表示所述目标数据以及所述目标数据的写操作,所述写操作用于将所述目标数据转换成图模型数据并将所述图模型数据写入所述第二存储空间;The first thread obtains a redo log according to the target data, the redo log is used to represent the target data and a write operation of the target data, and the write operation is used to convert the target data into graph model data and The graph model data is written into the second storage space;
    所述第一线程将所述重做日志写入目标存储空间,所述目标存储空间为所述N个第一存储空间中的一个。The first thread writes the redo log into a target storage space, and the target storage space is one of the N first storage spaces.
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method according to claim 1, further comprising:
    第二线程读取目标存储空间中的重做日志;The second thread reads the redo logs in the target storage space;
    所述第二线程回放所述目标存储空间中的重做日志,以执行所述写操作。The second thread plays back redo logs in the target storage space to perform the write operation.
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, characterized in that the method further comprises:
    所述第一线程向第二线程发送请求,所述请求用于指示所述第二线程回放所述目标存储空间中的所述重做日志。The first thread sends a request to the second thread, and the request is used to instruct the second thread to play back the redo log in the target storage space.
  4. 根据权利要求3所述的方法,其特征在于,所述第一线程向第二线程发送请求包括:The method according to claim 3, wherein the first thread sending a request to the second thread comprises:
    在所述目标存储空间中已使用的存储空间达到第一阈值的情况下,所述第一线程向第二线程发送请求。When the used storage space in the target storage space reaches a first threshold, the first thread sends a request to the second thread.
  5. 根据权利要求3所述的方法,其特征在于,所述第一线程向第二线程发送请求包括:The method according to claim 3, wherein the first thread sending a request to the second thread comprises:
    响应于业务需求,所述第一线程向第二线程发送请求。In response to business requirements, the first thread sends a request to the second thread.
  6. 根据权利要求5所述的方法,其特征在于,在N大于1的情况下,所述方法还包括:The method according to claim 5, wherein when N is greater than 1, the method further comprises:
    所述第一线程根据所述目标数据对应的标签,以及所述标签与所述第一存储空间的对应关系,从所述N个第一存储空间中确定所述目标存储空间,所述标签指示用于存储所述目标数据的表。The first thread determines the target storage space from the N first storage spaces according to the label corresponding to the target data and the corresponding relationship between the label and the first storage space, the label indicating A table used to store the target data.
  7. 根据权利要求1至6中任意一项所述的方法,其特征在于,所述第一线程将所述重做日志写入目标存储空间包括:The method according to any one of claims 1 to 6, wherein writing the redo log into the target storage space by the first thread comprises:
    所述第一线程通过物理锁的严格两段锁机制,将所述重做日志写入目标存储空间。The first thread writes the redo log into the target storage space through the strict two-stage lock mechanism of the physical lock.
  8. 根据权利要求1至6中任意一项所述的方法,其特征在于,在所述第一线程将所述重做日志写入目标存储空间之后,所述方法还包括:The method according to any one of claims 1 to 6, wherein after the first thread writes the redo log into the target storage space, the method further comprises:
    所述第一线程将事务提交日志写入所述目标存储空间,所述事务提交日志用于表示所 述目标数据的写入事务已提交。The first thread writes a transaction commit log into the target storage space, and the transaction commit log is used to indicate that the write transaction of the target data has been committed.
  9. 一种数据分段写入方法,其特征在于,应用于数据库系统,所述数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;A data segment writing method, characterized in that it is applied to a database system, and the database system includes a second storage space and N first storage spaces, wherein N is a positive integer;
    所述方法包括:The methods include:
    第二线程读取目标存储空间中的重做日志,所述目标存储空间为所述N个第一存储空间中的一个,所述重做日志用于表示所述目标数据以及所述目标数据的写操作,所述写操作用于将所述目标数据转换成图模型数据并将所述图模型数据写入所述第二存储空间;The second thread reads a redo log in a target storage space, where the target storage space is one of the N first storage spaces, and the redo log is used to represent the target data and the target data a write operation, the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space;
    所述第二线程回放所述目标存储空间中的重做日志,以执行所述写操作。The second thread plays back redo logs in the target storage space to perform the write operation.
  10. 根据权利要求9所述的方法,其特征在于,所述第二线程读取目标存储空间中的重做日志包括:The method according to claim 9, wherein reading the redo logs in the target storage space by the second thread comprises:
    所述第二线程周期性地读取目标存储空间中的重做日志。The second thread periodically reads redo logs in the target storage space.
  11. 根据权利要求9所述的方法,其特征在于,所述第二线程读取目标存储空间中的重做日志包括:The method according to claim 9, wherein reading the redo logs in the target storage space by the second thread comprises:
    在接收到来自所述第一线程的请求的情况下,所述第二线程读取目标存储空间中的重做日志,所述请求用于指示所述第二线程回放所述目标存储空间中的所述重做日志,以将所述图模型数据存储至所述第二存储空间。When receiving a request from the first thread, the second thread reads the redo logs in the target storage space, and the request is used to instruct the second thread to play back the redo logs in the target storage space The redo log is used to store the graph model data in the second storage space.
  12. 根据权利要求9至11中任意一项所述的方法,其特征在于,所述第二线程回放所述目标存储空间中的重做日志包括:The method according to any one of claims 9 to 11, wherein playing back the redo logs in the target storage space by the second thread comprises:
    所述第二线程通过多版本的两段锁机制回放所述目标存储空间中的重做日志。The second thread plays back the redo logs in the target storage space through a multi-version two-segment lock mechanism.
  13. 根据权利要求9至12中任意一项所述的方法,其特征在于,在所述第二线程回放所述目标存储空间中的重做日志之后,所述方法还包括:The method according to any one of claims 9 to 12, wherein after the second thread plays back the redo logs in the target storage space, the method further comprises:
    所述第二线程删除所述目标存储空间中的重做日志。The second thread deletes redo logs in the target storage space.
  14. 一种数据读取方法,其特征在于,应用于数据库系统,所述数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;A data reading method, characterized in that it is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer;
    所述方法包括:The methods include:
    第三线程获取目标数据对应的数据库主键;The third thread obtains the database primary key corresponding to the target data;
    所述第三线程根据所述数据库主键从目标存储空间中读取重做日志,或者,所述第三线程根据所述数据库主键从所述第二存储空间读取图模型数据,所述图模型数据根据第二线程回放所述目标存储空间中的重做日志得到;The third thread reads redo logs from the target storage space according to the database primary key, or the third thread reads graph model data from the second storage space according to the database primary key, and the graph model The data is obtained by replaying the redo logs in the target storage space by the second thread;
    所述目标存储空间为所述N个第一存储空间中的一个,所述重做日志用于表示所述目标数据以及所述目标数据的写操作,所述写操作用于将所述目标数据转换成图模型数据并 将所述图模型数据写入所述第二存储空间。The target storage space is one of the N first storage spaces, the redo log is used to represent the target data and a write operation of the target data, and the write operation is used to store the target data converting into graph model data and writing the graph model data into the second storage space.
  15. 根据权利要求14所述的方法,其特征在于,在所述第三线程根据所述数据库主键从目标存储空间中读取重做日志之前,所述方法还包括:The method according to claim 14, wherein before the third thread reads redo logs from the target storage space according to the database primary key, the method further comprises:
    所述第三线程根据所述数据库主键确定所述目标数据的写入事务的标识;The third thread determines the identifier of the writing transaction of the target data according to the database primary key;
    所述第三线程根据所述写入事务的标识,确定所述目标存储空间中包含事务提交日志,所述事务提交日志用于表示写入事务已提交。The third thread determines, according to the identifier of the write transaction, that the target storage space contains a transaction commit log, and the transaction commit log is used to indicate that the write transaction has been committed.
  16. 一种数据分段写入装置,其特征在于,应用于数据库系统,所述数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;A data segment writing device, characterized in that it is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer;
    所述装置包括:The devices include:
    封装单元,用于根据目标数据得到重做日志,所述重做日志用于表示所述目标数据以及所述目标数据的写操作,所述写操作用于将所述目标数据转换成图模型数据并将所述图模型数据写入所述第二存储空间;An encapsulation unit, configured to obtain a redo log according to the target data, where the redo log is used to represent the target data and a write operation of the target data, and the write operation is used to convert the target data into graph model data and writing the graph model data into the second storage space;
    写入单元,用于将所述重做日志写入目标存储空间,所述目标存储空间为所述N个第一存储空间中的一个。A writing unit, configured to write the redo log into a target storage space, where the target storage space is one of the N first storage spaces.
  17. 一种数据分段写入装置,其特征在于,应用于数据库系统,所述数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;A data segment writing device, characterized in that it is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer;
    所述装置包括:The devices include:
    读取单元,用于读取目标存储空间中的重做日志,所述目标存储空间为所述N个第一存储空间中的一个,所述重做日志用于表示目标数据以及所述目标数据的写操作,所述写操作用于将所述目标数据转换成图模型数据并将所述图模型数据写入所述第二存储空间;A reading unit, configured to read a redo log in a target storage space, the target storage space is one of the N first storage spaces, the redo log is used to represent target data and the target data A write operation, the write operation is used to convert the target data into graph model data and write the graph model data into the second storage space;
    回放单元,用于回放所述目标存储空间中的重做日志,以执行所述写操作。The replay unit is used to replay the redo logs in the target storage space to execute the write operation.
  18. 一种数据读取装置,其特征在于,应用于数据库系统,所述数据库系统包括第二存储空间和N个第一存储空间,其中,N为正整数;A data reading device, characterized in that it is applied to a database system, and the database system includes a second storage space and N first storage spaces, where N is a positive integer;
    所述装置包括:The devices include:
    获取单元,用于获取目标数据对应的数据库主键;The obtaining unit is used to obtain the database primary key corresponding to the target data;
    读取单元,用于根据所述数据库主键从目标存储空间中读取重做日志,或者,用于根据所述数据库主键从所述第二存储空间读取图模型数据,所述图模型数据根据第二线程回放的所述目标存储空间中的重做日志得到的;A reading unit, configured to read redo logs from the target storage space according to the database primary key, or to read graph model data from the second storage space according to the database primary key, the graph model data according to Obtained from the redo logs in the target storage space played back by the second thread;
    所述目标存储空间为所述N个第一存储空间中的一个,所述重做日志用于表示所述目标数据以及所述目标数据的写操作,所述写操作用于将所述目标数据转换成图模型数据并将所述图模型数据写入所述第二存储空间。The target storage space is one of the N first storage spaces, and the redo log is used to represent the target data and a write operation of the target data, and the write operation is used to store the target data converting into graph model data and writing the graph model data into the second storage space.
  19. 一种终端设备,其特征在于,所述终端设备包括:存储器和处理器,其中,N为正 整数;A terminal device, characterized in that the terminal device includes: a memory and a processor, wherein N is a positive integer;
    所述处理器,用于执行存储器中存储的计算机程序或指令,以使所述终端设备执行如权利要求1-15中任一项所述的方法。The processor is configured to execute computer programs or instructions stored in the memory, so that the terminal device executes the method according to any one of claims 1-15.
  20. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质具有程序指令,当所述程序指令被直接或者间接执行时,使得如权利要求1至15中任一所述的方法被实现。A computer-readable storage medium, characterized in that the computer-readable storage medium has program instructions, and when the program instructions are executed directly or indirectly, the method according to any one of claims 1 to 15 is executed accomplish.
  21. 一种芯片系统,其特征在于,所述芯片系统包括至少一个处理器,所述处理器用于执行存储器中存储的计算机程序或指令,当所述计算机程序或所述指令在所述至少一个处理器中执行时,使得如权利要求1至15中任一所述的方法被实现。A chip system, characterized in that the chip system includes at least one processor, and the processor is used to execute a computer program or an instruction stored in a memory, when the computer program or the instruction is executed on the at least one processor When executed, the method according to any one of claims 1 to 15 is realized.
  22. 一种计算机程序产品,其特征在于,包括指令,当所述指令在计算机上运行时,使得计算机执行权利要求1至15中任一项所述的方法。A computer program product, characterized by comprising instructions, which, when run on a computer, cause the computer to execute the method according to any one of claims 1 to 15.
PCT/CN2022/125887 2022-02-28 2022-10-18 Data segmented writing method, data reading method and apparatus WO2023159976A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210189511.7A CN116701387A (en) 2022-02-28 2022-02-28 Data segmentation writing method, data reading method and device
CN202210189511.7 2022-02-28

Publications (1)

Publication Number Publication Date
WO2023159976A1 true WO2023159976A1 (en) 2023-08-31

Family

ID=87764580

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/125887 WO2023159976A1 (en) 2022-02-28 2022-10-18 Data segmented writing method, data reading method and apparatus

Country Status (2)

Country Link
CN (1) CN116701387A (en)
WO (1) WO2023159976A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117555874A (en) * 2024-01-11 2024-02-13 成都大成均图科技有限公司 Log storage method, device, equipment and medium of distributed database

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105930361A (en) * 2016-04-12 2016-09-07 北京恒冠网络数据处理有限公司 Method for converting relational database into Neo4j model and data migration method
CN108388623A (en) * 2018-02-12 2018-08-10 平安科技(深圳)有限公司 ER relationships generation method, device, computer equipment and storage medium
CN109753537A (en) * 2019-01-25 2019-05-14 中国人民大学 A kind of interactive data moving method from relation data to diagram data
WO2021051492A1 (en) * 2019-09-18 2021-03-25 招商银行股份有限公司 Database service node switching method, apparatus and device, and computer storage medium
CN113220490A (en) * 2021-05-31 2021-08-06 清华大学 Transaction persistence method and system for asynchronous write-back persistent memory

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105930361A (en) * 2016-04-12 2016-09-07 北京恒冠网络数据处理有限公司 Method for converting relational database into Neo4j model and data migration method
CN108388623A (en) * 2018-02-12 2018-08-10 平安科技(深圳)有限公司 ER relationships generation method, device, computer equipment and storage medium
CN109753537A (en) * 2019-01-25 2019-05-14 中国人民大学 A kind of interactive data moving method from relation data to diagram data
WO2021051492A1 (en) * 2019-09-18 2021-03-25 招商银行股份有限公司 Database service node switching method, apparatus and device, and computer storage medium
CN113220490A (en) * 2021-05-31 2021-08-06 清华大学 Transaction persistence method and system for asynchronous write-back persistent memory

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117555874A (en) * 2024-01-11 2024-02-13 成都大成均图科技有限公司 Log storage method, device, equipment and medium of distributed database
CN117555874B (en) * 2024-01-11 2024-03-29 成都大成均图科技有限公司 Log storage method, device, equipment and medium of distributed database

Also Published As

Publication number Publication date
CN116701387A (en) 2023-09-05

Similar Documents

Publication Publication Date Title
US10860612B2 (en) Parallel replication across formats
EP2565806B1 (en) Multi-row transactions
US11093468B1 (en) Advanced metadata management
US9208191B2 (en) Lock-free, scalable read access to shared data structures
CN111352925B (en) Policy driven data placement and information lifecycle management
US8799213B2 (en) Combining capture and apply in a distributed information sharing system
CN109710388B (en) Data reading method and device, electronic equipment and storage medium
US20160328488A1 (en) Structure linked native query database management system and methods
US20150142733A1 (en) System and method for efficient management of big data in a database using streaming tables
US10452655B2 (en) In-memory cursor duration temp tables
Moniz et al. Blotter: Low latency transactions for geo-replicated storage
CN109033359A (en) A kind of method of multi-process secure access sqlite
CN113391885A (en) Distributed transaction processing system
KR20200056357A (en) Technique for implementing change data capture in database management system
JP2023541298A (en) Transaction processing methods, systems, devices, equipment, and programs
CN111444149A (en) Data import method, device, equipment and storage medium
WO2023159976A1 (en) Data segmented writing method, data reading method and apparatus
CN114116665B (en) Method for writing transaction log in parallel in database to promote processing efficiency
Felber et al. On the support of versioning in distributed key-value stores
CN115114370B (en) Master-slave database synchronization method and device, electronic equipment and storage medium
CN107704603A (en) A kind of method and device for realizing read and write abruption
Yuan et al. Rubato DB: A highly scalable staged grid database system for OLTP and big data applications
CN109359005B (en) Cross-process data acquisition and processing method
CN111459882A (en) Namespace transaction processing method and device of distributed file system
CN107590199B (en) Memory-oriented multithreading database design method

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

Country of ref document: EP

Kind code of ref document: A1