WO2021114848A1 - 数据库的数据读写方法及装置 - Google Patents

数据库的数据读写方法及装置 Download PDF

Info

Publication number
WO2021114848A1
WO2021114848A1 PCT/CN2020/120216 CN2020120216W WO2021114848A1 WO 2021114848 A1 WO2021114848 A1 WO 2021114848A1 CN 2020120216 W CN2020120216 W CN 2020120216W WO 2021114848 A1 WO2021114848 A1 WO 2021114848A1
Authority
WO
WIPO (PCT)
Prior art keywords
connection
table space
node
read
thread
Prior art date
Application number
PCT/CN2020/120216
Other languages
English (en)
French (fr)
Inventor
阙鸣健
王传廷
王俊捷
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP20899431.9A priority Critical patent/EP4057160A4/en
Publication of WO2021114848A1 publication Critical patent/WO2021114848A1/zh
Priority to US17/837,496 priority patent/US11868333B2/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5083Techniques for rebalancing the load in a distributed system
    • G06F9/5088Techniques for rebalancing the load in a distributed system involving task migration
    • 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/2282Tablespace storage structures; 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/24Querying
    • G06F16/245Query processing
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • This application relates to the technical field of data reading and writing, and in particular to a method and device for reading and writing data in a database.
  • a computer device is a data reading and writing device that can support reading and writing operations on data.
  • Computer devices usually include a processor, memory, and external memory, and the data to be read and written is often the data in the external memory.
  • the computer device receives a read and write request for data in external storage, the computer device needs to process the read and write request through a working thread in the processor. For example, the worker thread will load the data from the external memory to the memory for reading and writing.
  • Such a computer device can be divided into multiple nodes according to the multiple processors, and each node includes a processor and a part of memory.
  • the computer device can process the read and write request through a worker thread in a processor in any node.
  • the worker thread can load the data targeted by the read and write request into the memory of any node for reading and writing.
  • the worker threads in the node will often load data into the memory outside the node, which causes the processor to read and write data across the nodes. Since the efficiency of reading and writing data across nodes is low, it is difficult to ensure high data reading and writing efficiency when the computer device is divided into multiple nodes.
  • This application provides a method and device for reading and writing data in a database, which can solve the problem of low data reading and writing efficiency.
  • the technical solution is as follows:
  • a method for reading and writing data in a database is provided.
  • the method is used in a computer device.
  • the computer device includes a plurality of nodes.
  • Each node of the plurality of nodes includes a processor and a memory.
  • the method includes: first, establishing a first connection with a client, and the first connection is used to transmit a read and write request sent by the client; determining a first table space corresponding to the first connection, and determining among the plurality of nodes The first node corresponding to the first connection or the first table space; wherein the first connection receives the read and write request sent by the client; after that, the data of the first table space can be loaded to In the memory of the first node, a first worker thread is used to process read and write requests on the first connection, where the first worker thread is generated by a processor in the first node.
  • the read and write request sent by the client through the first connection will have a high probability of accessing the first table space.
  • every table space that the client needs to access has a high probability of being the first table space. Therefore, if the data in the table space accessed by the read and write request on the first connection is loaded to the first node, and the first worker thread in the first node is used to read the read and write request loaded to the first node Write, you can avoid reading and writing data across nodes with a high probability.
  • determining the first table space corresponding to the first connection includes: first using an initial worker thread to respond to read and write requests on the first connection , And determine the table space accessed by the initial worker thread when responding to the read and write request on the first connection; then according to the table space accessed by the initial worker thread when responding to the read and write request on the first connection Determine the first table space corresponding to the first connection.
  • the initial worker thread runs in any one of the multiple nodes.
  • the data reading and writing method provided by this application can determine the first table space corresponding to the first connection according to the table space accessed by the initial worker thread in response to the read and write request on the first connection, so that the first table space
  • the correlation with the table space accessed by the read and write request on the first connection is relatively large.
  • the table space that is accessed when the initial worker thread responds to the read and write request on the first connection determines that it corresponds to the first connection
  • the first table space includes: determining the first table space accessed by the initial worker thread in the process of responding to the read and write request on the first connection as the first table space; or In the process of the initial working thread responding to the read and write request on the first connection, the table space with the highest access frequency within a predetermined period of time is determined to be the first table space.
  • the computer device determines the above-mentioned first table space as the first table space
  • the computer device only needs to detect the first connection in the process of responding to the read and write request on the first connection using the initial working thread.
  • the above read and write request only needs to access the first table space, so the computer device is more efficient in determining the first table space.
  • the computer device determines the above-mentioned table space with the highest access frequency as the first table space
  • the first table space is determined by the computer device based on the history of multiple accesses to the table space by the initial worker thread. Therefore, it is determined The first table space is more likely to be accessed than the read and write requests on the first connection.
  • the method before the use of the first worker thread to process the read and write requests on the first connection, the method further includes: determining the initial The worker thread is located at a node other than the first node; the initial worker thread is migrated to the first node, where the initial worker thread after migration is the first worker thread.
  • the working threads for processing read and write requests on the first connection are the same before the first table space is determined and after the first table space is determined, which facilitates the management of the working threads.
  • the computer device can determine that the initial working thread is the first working thread, and there is no need to migrate the initial working thread.
  • the determining a first node corresponding to the first connection or the first table space among the multiple nodes includes: according to the The characteristics of the first connection determine the first node, wherein the characteristics of the first connection include the Internet Protocol IP address of the client, the name of the user who uses the client, or the first connection corresponding to the The name of the application. It can be seen that the first node identified by the connection of the same feature is the same, which ensures that the table space that needs to be accessed by the read and write request on the connection of the same feature can be loaded to the same node as much as possible, which is convenient for subsequent data in the table space. Read and write.
  • the method before the first connection is established with the client, the method further includes: creating the first table space, wherein the first table The space carries a first identifier, and the first identifier indicates the first node; at this time, the determining the first node corresponding to the first connection or the first table space among the plurality of nodes , Including: determining the first node according to the first identifier carried by the first table space.
  • the created first table space carries the first identifier
  • the first node can be determined directly according to the first identifier carried in the first table space, so that the efficiency of determining the first node is higher.
  • the identifier carried by the table space may also be an identifier of a buffer in a node corresponding to the table space. It can be seen that there is a corresponding relationship between the table space and the buffer in the node.
  • the data in the table space may be used to load into the corresponding buffer, and of course the data in the table space may not be used to load into the corresponding buffer, which is not limited in the embodiment of the present application.
  • the computer device may first determine the first buffer corresponding to the first table space or the first connection, and then determine the node where the first buffer is located as the first connection Or the first node corresponding to the first tablespace. Loading the data in the table space into the buffer in the node can facilitate the computer device to effectively manage the data loaded in the node.
  • the computer device includes a first thread pool and a second thread pool, and the worker threads in the first thread pool are used to process and carry the first thread pool.
  • the read and write requests on the connection of the identifier, the worker threads in the second thread pool are used to process the read and write requests on the connection that does not carry the identifier.
  • the method further includes: enabling the first connection to carry the first identifier. After that, because the first connection carries the first identifier for indicating the first node, the computer device can take out an idle worker thread from the first thread pool of the first node as the first worker thread, and use the first worker thread.
  • the worker thread responds to the read and write request on the first connection.
  • the computer device can take out an idle thread from the second thread pool as The initial working thread, and the initial working thread is used to respond to the read and write request on the first connection.
  • the thread pool mode when a computer device uses a worker thread to respond to read and write requests on a connection, it needs to meet the condition that there is an idle worker thread in the corresponding thread pool, so as to ensure that the computer device can read data on multiple connections in an orderly manner.
  • the write request is processed.
  • the computer device can also detect whether the number of worker threads that access the first table space within the target time length is less than the first number threshold, and if the number of worker threads that access the first table space is less than the first number threshold within the target time length, If the number of working threads in the table space is less than the first number threshold, the computer device can migrate all data in the first table space to the second table space.
  • the second table space may be any table space except the first table space.
  • the number of worker threads accessing the second table space within the target duration may be greater than or equal to the first number threshold. In this way, the computer device migrates the data in the first table space that is accessed less frequently to the second table space that is accessed more frequently, thereby avoiding the existence of the table space that is accessed less frequently.
  • the computer device can also detect whether the number of worker threads accessing the first table space within the target time period is greater than a second number threshold, which can be greater than the foregoing The first number threshold. If the number of worker threads accessing the first table space within the target duration is greater than the second number threshold, the computer device may migrate at least part of the data in the first table space to the third table space.
  • the third table space may be any table space except the first table space.
  • the number of worker threads accessing the third table space within the target duration may be less than or equal to the second number threshold. In this way, the computer device migrates at least part of the data in the first table space that is accessed more frequently to the third table space that is accessed less frequently, thereby avoiding the first table space from being accessed too frequently.
  • the computer device may also detect the load of multiple nodes.
  • the computer device can migrate the data of the part of the table space corresponding to the first node to the second node, and Modify the correspondence between the migrated table space and the nodes to achieve load balancing between the nodes.
  • a data reading and writing device for a database includes modules for executing any of the data reading and writing methods provided in the first aspect.
  • a computer device in a third aspect, includes: a processor and a memory, the memory is stored with a program, and the processor is configured to call the program stored in the memory to make the computer device Execute any method for reading and writing data of a database as provided in the first aspect.
  • a computer storage medium stores a computer program.
  • the computer program runs on a computer device, the computer device executes any data reading of the database provided in the first aspect. Writing method.
  • FIG. 1 is a schematic structural diagram of a computer device provided by an embodiment of this application.
  • FIG. 2 is a schematic structural diagram of another computer device provided by an embodiment of this application.
  • FIG. 3 is a flowchart of a method for reading and writing data in a database according to an embodiment of the application
  • FIG. 4 is a schematic diagram of a correspondence relationship between a table space and a node according to an embodiment of the application
  • FIG. 5A is a schematic diagram of a data reading and writing process provided by an embodiment of this application.
  • 5B is a flowchart of another method for reading and writing data in a database provided by an embodiment of the application.
  • FIG. 6 is a flowchart of another method for reading and writing data in a database provided by an embodiment of the application.
  • FIG. 7 is a schematic diagram of another data reading and writing process provided by an embodiment of the application.
  • FIG. 8 is a schematic diagram of another data reading and writing process provided by an embodiment of this application.
  • FIG. 9 is a schematic diagram of another data reading and writing process provided by an embodiment of the application.
  • FIG. 10 is a schematic diagram of another data reading and writing process provided by an embodiment of the application.
  • FIG. 11 is a schematic diagram of another data reading and writing process provided by an embodiment of this application.
  • FIG. 12 is a schematic diagram of another data reading and writing process provided by an embodiment of this application.
  • FIG. 13 is a schematic diagram of another data reading and writing process provided by an embodiment of this application.
  • FIG. 14 is a block diagram of a device for reading and writing data of a database provided by an embodiment of the application.
  • FIG. 15 is a schematic structural diagram of a computer device 700 provided according to an embodiment of the present application.
  • FIG. 1 is a schematic structural diagram of a computer device provided by an embodiment of this application.
  • the computer device 01 may be any device with data reading and writing functions, such as a server or a computer.
  • the computer device 01 generally includes a processor 011, a memory 012, an external memory 013, a bus 104, and an input/output (I/O) interface 105.
  • the processor 101, the memory 102, and the I/O interface 105 are communicatively connected via the bus 104, and the I/O interface 105 is also connected to the external memory 103.
  • the processor 101 can call the data stored in the memory 102 through the bus 104.
  • Both the memory 012 and the external memory 013 may be structures for storing data in the computer device 01.
  • the memory 012 is also called internal memory or main memory, and its function is to temporarily store operational data in the processor and data exchanged with external memory.
  • External storage 013 is also called external storage or auxiliary storage. Its function is to store data permanently.
  • External storage 013 can be hard disk, floppy disk, optical disk, U disk, etc.
  • the processor 011 can directly access the memory 012, but cannot directly access the external memory 013. When the processor 011 needs to access the data in the external memory 013, it usually needs to load the data in the external memory 013 to the memory 012 through the I/O interface 105 and the bus 104, and then the processor 011 can access the data loaded in the memory 012. The data.
  • the memory 012 stores data faster than the external memory 013.
  • the capacity of the memory 012 is usually much smaller than that of the external memory 013.
  • the data stored in the memory 012 usually cannot be saved after the computer device 01 is powered off.
  • the data stored in the external storage 013 can still be saved after the computer device 01 is powered off.
  • the computer device can manage the data in the external storage through a database
  • the database can be any kind of database, such as a disk database or a memory database, which is not limited in the embodiment of the present application.
  • the computer device may not use a database to manage the data in the external storage, which is not limited in the embodiment of the present application.
  • the database may include multiple table spaces, the table spaces correspond to a part of the storage space in the external memory, and the storage spaces corresponding to different table spaces are different.
  • Table space is a logical storage concept. The data in the table space is actually stored in the storage space corresponding to the table space, and the data read and write for each table space is equivalent to the corresponding storage of the table space in the external memory. Space for data reading and writing.
  • the data stored in the database may be referred to as table data.
  • the table data may include at least one page. It can be understood that the table data can be divided into at least one page, and the at least one page can be spliced to obtain the table data.
  • table data can record the name, age, and gender of each student in a certain class. If the students of the class are divided into four groups, the table data may include four pages corresponding to the four groups of students one-to-one, and each page may include the name, age, and gender of the corresponding group of students. Alternatively, the table data may include two pages, where one page includes the name and age of each student in the class, and the other page includes the name and gender of each student in the class. The relationship between the table data and the page may also be other relationships, which are not described in detail in the embodiment of the present application.
  • Each table space in the database can correspond to at least one type of business, and the table space is used to store data of the corresponding business.
  • the services corresponding to each table space may be the same or different, which is not limited in the embodiment of the present application.
  • the database can also name certain storage areas in the memory of the computer device as buffers.
  • the processor 011 needs to load the data from the external memory to the buffer of the memory 012 through the working thread, and then load the data to the memory.
  • the data in the buffer of 012 is read and written.
  • the buffer in the embodiment of this application may be a global buffer in memory, such as a global buffer managed by the system global area (SGA): global data page buffer (Data Buffer), global log buffer (Log Buffer), global execution plan buffer (SQL Cache), global sort/materialization buffer (Sort Area), or global data dictionary (metadata) buffer (Dictionary Cache), etc.
  • SGA system global area
  • FIG. 1 only includes a processor 011 and a memory 012.
  • FIG. 2 is a schematic structural diagram of another computer device provided by an embodiment of the application. As shown in FIG. 2, in FIG. On the basis of, the computer device may also include multiple processors 011 and multiple memories 012, and multiple processors 011 and multiple memories 012 form multiple nodes, and each node includes a processor 011 and a memory 012 .
  • the node may also be referred to as a non-uniform memory access (NUMA) node.
  • NUMA non-uniform memory access
  • the processor 011 and the memory 012 in each node are connected by a bus, and the processors of each node are connected by a high-speed interconnection bus (such as a quick path interconnect (QPI) bus), and the high-speed interconnection bus
  • QPI quick path interconnect
  • the transfer rate is lower than the transfer rate of the bus connected between the processor and the memory in the node.
  • FIG. 2 only shows the connection relationship between the processor of one node and the processors of other nodes.
  • the processor 011 in each node in FIG. 2 can read and write data in external storage.
  • the computer device can load the data in the table space to the memory 012 in the node through the work thread in the processor of any node, and can also load the data in the table space to the memory 012 in other nodes. .
  • the processor 011 After the computer device loads the data in the table space into the memory 012 of other nodes through the working thread of the processor 011 of a certain node, the processor 011 then reads and writes and loads it into the memory 012 of other nodes through the local working thread. Data, it will lead to cross-node reading and writing of data.
  • the embodiment of the present application provides a method for reading and writing data of a database, which can reduce the probability of reading and writing data across nodes and improve the efficiency of data reading and writing.
  • FIG. 3 is a flowchart of a method for reading and writing data in a database provided by an embodiment of the application.
  • the method for reading and writing data may be used in the computer device shown in FIG.
  • the data reading and writing method may include:
  • Step 301 Create at least one table space, and each of the at least one table space has a corresponding node.
  • the computer device may create a table space based on a table space creation instruction, and the table space creation instruction needs to carry the file corresponding to the table space in the external memory, so that the data written into the table space can be stored in the table. In the file corresponding to the space.
  • each table space corresponds to a type of service, and the table space is only used to store data of the corresponding service.
  • an enterprise can create a table space for each employee.
  • the table space of each employee is used to store the data processed by the employee. This can be regarded as the business corresponding to the table space for storing the data processed by the employee.
  • the computer device can select a node in the computer device as the node corresponding to the table space according to the service corresponding to the table space.
  • the computer device may use hash, round-robin or other methods to filter the nodes corresponding to the table space based on the characteristics of the business corresponding to the table space.
  • the nodes corresponding to the table spaces corresponding to the same business are the same.
  • table space 1 corresponds to service 1
  • table space 2 corresponds to service 2
  • table space 3 corresponds to service 3.
  • the computer device can select node 1 as the node corresponding to table space 1 according to the characteristics of service 1, select node 2 as the node corresponding to table space 2 according to the characteristics of service 2, and select node 3 as table space 3 according to the characteristics of service 3.
  • the corresponding node may not filter the nodes corresponding to the table space in the computer device based on the characteristics of the business corresponding to the table space. For example, the computer device may randomly select the nodes corresponding to the table space in the computer device. There is no restriction on this.
  • the table space created by the computer device may carry an identifier, and the identifier is used to indicate the node corresponding to the table space.
  • the creation instruction of the table space also needs to carry an identifier.
  • the table space creation instruction can be create tablespace ⁇ spc_numa_x> ⁇ datafile>numa x.
  • create tablespace ⁇ spc_numa_x> means to create a table space ⁇ spc_numa_x>
  • ⁇ spc_numa_x> means the name of the created table space
  • ⁇ datafile> means the file name corresponding to the table space in external storage
  • numbera x is The identifier indicates the node corresponding to the table space among the multiple nodes of the computer device.
  • the at least one table space created in step 301 may include: a read-write table space and a read-only table space.
  • the read-write table space supports read operations and write operations, while the read-only table space only supports read operations and does not support write operations. operating.
  • the created read-write table space can correspond to one node among multiple nodes, the nodes corresponding to different read-write table spaces can be the same or different, and the read-only table space corresponds to all nodes in the multiple nodes.
  • Table spaces 1, 2, and 3 in Figure 4 are all read-write table spaces, corresponding to a node, and table space 4 is a read-only table space, corresponding to nodes 1, 2, 3, and 4.
  • the data in each table space is used to load into the corresponding node. Therefore, the read-write table space can only be loaded to one node, and the read-only table space can be loaded to any node among multiple nodes.
  • the creation instruction of the aforementioned table space may be a creation instruction of a read-write table space
  • the creation instruction of a read-only table space may be: create tablespace ⁇ spc_numa_x> ⁇ datafile>numa replication.
  • create tablespace ⁇ spc_numa_x> means to create a table space ⁇ spc_numa_x>
  • ⁇ spc_numa_x> means the name of the created table space
  • ⁇ datafile> means the file name corresponding to the table space in external storage
  • "numa replication” is Identifier, which is used to indicate all nodes of the computer device corresponding to the table space.
  • the data in the table space when the table space is read and written, the data in the table space is used for loading into the node corresponding to the table space as an example.
  • the data in the table space may not be used to load to the node corresponding to the table space, which is not limited in the embodiment of the present application.
  • Step 302 Establish a first connection with the client, where the first connection is used to transmit a read and write request sent by the client.
  • the computer device may establish a first connection with the client according to the connection request sent by the client.
  • the first connection may be any communication connection, such as a transmission control protocol (TCP) connection, a hypertext transmission protocol (hypertext transport protocol, HTTP) connection, and so on.
  • TCP transmission control protocol
  • HTTP hypertext transport protocol
  • the connection established between the computer device and the client may also be referred to as a session.
  • the computer device can receive at least one read and write request sent by the client through the first connection, and the at least one read and write request may include a read and write request for accessing the first table space.
  • the read and write requests transmitted by the first connection are all read and write requests of the same service, and these read and write requests are all read and write requests to access the first table space, and the node corresponding to the first table space can be determined according to the characteristics of the service from.
  • Step 303 Determine the first table space corresponding to the first connection.
  • each table space corresponds to a type of service, and the table space is only used to store data of the corresponding service, and the table spaces corresponding to different services are different.
  • the computer device may determine the table space corresponding to the service corresponding to the first connection as the first table space.
  • Step 304 Determine the first node corresponding to the first table space among the multiple nodes.
  • each table space created by the computer device has a corresponding node. Therefore, in step 304, the computer device can obtain the corresponding relationship between the table space and the node, and look up the first table based on the corresponding relationship. The first node corresponding to the space.
  • the computer device in the process of creating the table space in step 301, can obtain the corresponding relationship between the table space and the node.
  • the computer device may store the correspondence relationship locally in the computer device, or of course, may also be stored on other equipment outside the computer device, as long as the computer device can obtain the correspondence relationship in step 303.
  • table space 1 corresponds to node 1
  • table space 2 corresponds to node 2
  • table space 3 corresponds to node 3
  • table space 4 corresponds to nodes 1, 2, and 3.
  • the computer device may determine node 3 corresponding to table space 3 as the first node.
  • Step 305 Load the data of the first table space into the memory of the first node.
  • the computer device may load the data in the first table space into the memory of the first node.
  • Step 306 Use the first worker thread to process the read and write request on the first connection, where the first worker thread is generated by the processor in the first node.
  • the computer device may use the first working thread generated by the processor in the first node to process the read and write requests on the first connection in a fixed manner. And no matter how many read and write requests there are on the first connection, they are all processed by the first worker thread.
  • the data in the first table space can be loaded into the first node, the read and write request on the first connection is used to access the first table space, and the computer device can be generated by the processor in the first node
  • the first worker thread processes the read and write request.
  • the first working thread and the data in the first table space to be read and written are all located in the first node, which avoids cross-node reading and writing of data, and improves the efficiency of data reading and writing.
  • the read and write requests 1, 2, 3, and 4 on the first connection are all used to access the first table space (table space 1), and the first table space (table space 1) corresponds to The first node is node 1.
  • the computer device loads the data in the table space 1 into the memory (memory 1) of the node 1.
  • thread 1 can read and write data in the table space 1 loaded into memory 1. It can be seen that the memory 1 to which the data to be accessed by the read and write request on the first connection is loaded and the thread 1 that reads and writes the data are located on the same node 1. Therefore, it is avoided that thread 1 reads and writes data across nodes.
  • the read and write request transmitted by the connection of each service feature may only be used to access the table space corresponding to the service feature, and the table space corresponding to each service feature corresponds to the same node in the computer device.
  • the above service feature is the IP address of the client
  • each client is used to access the table space corresponding to its IP address, and will not access the table space corresponding to the IP address of other clients.
  • the first node is determined based on the characteristics of the first connection, it can be considered that the node corresponding to the table space (such as the first table space) accessed by each read and write request on the first connection is the first node.
  • FIG. 5B is a flowchart of another method for reading and writing data of a database provided by an embodiment of the application.
  • the method for reading and writing data may be used in the computer device shown in FIG. 2.
  • the data reading and writing method may include:
  • Step 501 Create at least one table space.
  • step 301 The difference from step 301 is that the table space created by the computer device in step 501 does not have a corresponding node.
  • Step 502 Establish a first connection with the client, where the first connection is used to transmit the read and write request sent by the client.
  • Step 502 may refer to step 302, which is not described in detail in the embodiment of the present application.
  • Step 503 Determine the first table space corresponding to the first connection.
  • Step 503 can refer to step 303, which is not described in detail in the embodiment of the present application.
  • Step 504 Determine the first node corresponding to the first connection among the multiple nodes.
  • the computer device may determine the first node according to the characteristics of the first connection.
  • the characteristics of the first connection may include: the internet protocol (IP) address of the client, the name of the user using the client, or the name of the application corresponding to the first connection, etc.
  • IP internet protocol
  • the computer device can screen a node as the first node in the computer device based on the characteristics of the first connection.
  • the screening process can refer to the process of the computer screening nodes based on the characteristics of the business corresponding to the table space in step 301. This application is implemented The examples are not repeated here.
  • Step 505 Load the data of the first table space into the memory of the first node.
  • Step 505 can refer to step 305, which is not described in detail in the embodiment of the present application.
  • Step 506 Use the first worker thread to process the read and write request on the first connection, where the first worker thread is generated by the processor in the first node.
  • Step 506 may refer to step 306, which is not described in detail in the embodiment of the present application.
  • the data in the first table space can be loaded into the first node, the read and write request on the first connection is used to access the first table space, and the computer device can be generated by the processor in the first node
  • the first worker thread processes the read and write request.
  • the first working thread and the data in the first table space to be read and written are all located in the first node, which avoids cross-node reading and writing of data, and improves the efficiency of data reading and writing.
  • FIG. 6 is a flowchart of another method for reading and writing data of a database provided by an embodiment of the application, and the method for reading and writing data may be used in the computer device shown in FIG. 2.
  • the data reading and writing method may include:
  • Step 601 Create at least one table space.
  • step 601 that is, at least one table space created may have a corresponding node (refer to step S301) or no corresponding node (refer to step S501), which is not limited in the embodiment of the present application.
  • Step 602 Establish a first connection with the client, where the first connection is used to transmit a read and write request sent by the client.
  • Step 602 can refer to step 302, but unlike step 302, in this embodiment, the read and write request transmitted by the first connection in step 602 may include a read and write request for accessing one or more table spaces.
  • Step 603 Use the initial worker thread to respond to the read and write request on the first connection, where the initial worker thread runs in any one of the multiple nodes of the computer device.
  • the computer device After the computer device establishes the first connection with the client, the computer device can first start an initial working thread (which can be located on any node in the computer device), and then use the initial working thread to perform read and write requests on the first connection. response.
  • an initial working thread which can be located on any node in the computer device
  • the initial worker thread in the process of responding to the read and write request on the first connection, the initial worker thread will access the table space that the read and write request needs to access. It should be noted that there may be at least one read and write request on the first connection, and the initial worker thread may sequentially respond to the read and write requests on the first connection.
  • the computer device includes nodes 1, 2, 3, and 4, and node 1 has thread 1, node 2 has thread 2, node 3 has thread 3, and node 4 has thread 4.
  • the computer device can use thread 2 on node 2 as the above-mentioned initial working thread, and use thread 2 to sequentially make read and write requests 1, 2, 3, and 3 on the first connection. 4 Respond.
  • Step 604 Determine the table space accessed by the initial worker thread when responding to the read and write request on the first connection.
  • Step 605 Determine the first table space corresponding to the first connection according to the table space accessed when the initial worker thread responds to the read and write request on the first connection.
  • the computer device can determine the table space accessed by the initial worker thread when responding to the read and write request on the first connection, and then it can be based on these table spaces. Use multiple implementation methods to determine the first table space.
  • the computer device may determine the first table space accessed by the initial worker thread in the process of responding to the read and write request on the first connection as the first table space. It can be seen that, in the process of using the initial working thread to respond to the read and write request on the first connection, the computer device only needs to detect the first table space that the read and write request on the first connection needs to access.
  • the relationship between the table space in the database and the pages in the table space is shown in Table 2. If the initial worker thread responds to the read and write request on the first connection, the first page accessed is page 4, you can It is determined that the table space 2 where the page 4 is located is the first table space accessed by the initial worker thread, and the table space 2 is determined to be the above-mentioned first table space.
  • the computer device may determine the table space with the highest access frequency within a predetermined period of time in the process of the initial worker thread responding to the read and write request on the first connection as the first table space. It can be seen that when the computer device uses the initial working thread to respond to the read and write requests on the first connection, it needs to count the table spaces that need to be accessed by the read and write requests on the first connection within a predetermined period of time, and determine these The first table space with the highest access frequency in the table space is sufficient.
  • table space 5 For example, for the table space shown in Table 2, it is assumed that the initial worker thread has accessed the table spaces 1, 4, and 5 within the first time period of responding to the read and write request on the first connection. And, as shown in Table 3, within the predetermined time period, the frequency of accessing tablespace 1 is 2 times/min, the frequency of accessing tablespace 4 is 3 times/min, and the frequency of accessing tablespace 5 is 5 times/min. It can be seen that during the first time period during which the initial worker thread responds to the read and write request on the first connection, table space 5 has the highest frequency of being accessed. At this time, the computer device can determine that table space 5 is the aforementioned first table space.
  • Table space The frequency of accessing the table space within a predetermined period of time (times/min) 1 2 4 3 5 5
  • Step 606 Determine the first node corresponding to the first connection or the first table space.
  • step 601 Since at least one table space created in step 601 may have a corresponding node or no corresponding node, when the created table space has a corresponding node, the first node corresponding to the first table space can be directly determined; When there is no corresponding node in the table space of, step S504 can be referred to to determine the corresponding first node according to the characteristics of the first connection.
  • Step 607 Determine that the initial working thread is located at a node other than the first node.
  • the computer device After determining the first node, the computer device needs to determine whether the initial working thread is located at a node other than the first node.
  • the node whose initial working thread is located outside the first node is taken as an example.
  • Step 608 Migrate the initial working thread to the first node, where the initial working thread after the migration is the first working thread.
  • the computer device can migrate thread 2 from node 2 to node 1.
  • the initial worker thread before migration and the initial worker thread after migration can be the same worker thread, but the initial worker thread before migration is not located in the first node, and the initial worker thread after migration The initial worker thread (that is, the first worker thread) is located in the first node.
  • the initial working thread before migration and the initial working thread after migration are different working threads.
  • the computer device migrates the initial working thread, it can start a working thread in the first node, and The data required by the initial worker thread is migrated to the worker thread in the first node, so that the function of the initial worker thread is transferred to the worker thread in the first node, and the migrated initial worker thread (that is, the first job Thread).
  • Step 609 Load the data of the first table space into the memory of the first node.
  • step 609 reference may be made to step 305, which is not described in detail in the embodiment of the present application.
  • the initial worker thread will access the table space that the read and write request needs to access.
  • the data in the first table space may be loaded into the memory of the first node, or may not be loaded into the memory of the first node; if in the process of the access, the first table space If the data in the first node is not loaded into the memory of the first node, step 609 can be executed to ensure that the data in the first table space is loaded into the memory of the first node; if during the access process, the first table The data in the space has been loaded into the memory of the first node, and step 609 may not be executed.
  • Step 610 Use the first worker thread to process the read and write request on the first connection, where the first worker thread is generated by the processor in the first node.
  • Step 610 may refer to step 306, which is not described in detail in the embodiment of the present application.
  • the computer device may not perform steps 607 and 608, and determine that the initial worker thread is the first worker thread, and directly execute steps 609 is fine.
  • the computer device may not perform step 607 and step 608. Instead, after step 606, the computer device directly starts another worker thread on the first node, and uses the worker thread as For the first working thread, just execute step 609.
  • the initial worker thread (thread 2) responds to the read and write request 1 on the first connection before migrating to node 1, but has not yet responded to the read and write requests 2, 3 and on the first connection. 3 Respond. Then after the initial worker thread (thread 2) is migrated to the first node (node 1) to obtain the first worker thread, the first worker thread (thread 2 migrated to node 1) can be used to sequentially connect to the first connection To respond to read and write requests 2, 3, and 4.
  • the first worker thread on the first node needs to be used in the embodiment of the present application to process the read and write requests on the first connection.
  • the read and write request sent by the client through the first connection will have a greater probability (such as 99%, 98%, or 80%, etc.) to access the first table space, and a small probability (such as 1%, 2% or 20%, etc.) will access other table spaces.
  • the table space that the client needs to access each time is likely to be the first table space. Therefore, if the data in the table space accessed by the read and write request on the first connection is loaded to the first node, and the first worker thread in the first node is used to read the read and write request loaded to the first node Write, it is possible to avoid reading and writing data across nodes with a greater probability.
  • TPC-C Transaction Processing Performance Council
  • each warehouse is responsible for supplying 10 points of sale, and each point of sale serves 3000 clients.
  • the table data of multiple commodity warehouses for client access can be divided into multiple partitions, and these partitions are distributed in multiple table spaces, and each table space stored in the partition of each commodity warehouse corresponds to The same node.
  • the orders submitted by each client about 90% of the products are in the warehouse corresponding to the client (that is, the warehouse corresponding to the point of sale that directly provides the server for the client), and 10% of the products are in the warehouse There is no inventory in it, and it must be supplied by other warehouses.
  • each client has a high probability (about 90%) to access the table space where the partition of its corresponding warehouse is located. Therefore, the computer device can determine the first table space that the client needs to access as the first table. Space, and determine the node corresponding to the table space as the first node. After the first node is determined, it can be considered that the node corresponding to the table space used for access by each read and write request on the first connection has a high probability of being the first node.
  • the first working thread in the first node corresponding to the first table space is used to process the read and write requests on the first connection, which can avoid reading and writing data across nodes with a high probability.
  • the computer device may not execute steps 607 to 608, but replace the node corresponding to the aforementioned first table space from the aforementioned first table space.
  • the node is changed to the node where the initial worker thread is located, and then the initial worker thread is used to process the read and write request on the first connection.
  • the initial worker thread processes the read and write request on the first connection, it can load the data in the first table space accessed by the read and write request to the node where the initial worker thread is located, thereby reducing cross-nodes. Probability of reading and writing data.
  • the table space has a corresponding node, and the identifier carried by the table space is the identifier of the node corresponding to the table space as an example.
  • the identifier carried by the table space may also be one of the nodes corresponding to the table space.
  • the identifier of the buffer It can be seen that there is a corresponding relationship between the table space and the buffer in the node.
  • the data in the table space may be used to load into the corresponding buffer, and of course the data in the table space may not be used to load into the corresponding buffer, which is not limited in the embodiment of the present application.
  • the table space creation instruction can be: create tablespace ⁇ spc_numa_x> ⁇ datafile> ⁇ buf_x>.
  • create tablespace ⁇ spc_numa_x> means to create a table space ⁇ spc_numa_x>
  • ⁇ spc_numa_x> means the name of the created table space
  • ⁇ datafile> means the file name corresponding to the table space in external storage
  • ⁇ buf_x> It is the identifier of the table space and is used to indicate the buffer corresponding to the table space.
  • the buffer in the node also carries the identifier of the node where the buffer is located.
  • the creation instruction of the buffer can be: create database buffer ⁇ buf_x>numa x, "create database buffer ⁇ buf_x>” means to create buffer ⁇ buf_x>, " ⁇ buf_x>” is the name of the created buffer, " numa x” is the identifier of the node, which is used to indicate the node where the created buffer is located.
  • the computer device when determining the first node corresponding to the first connection or the first table space among the multiple nodes, the computer device may first determine the first connection or the first table space. The first buffer area corresponding to the space, and then the node where the first buffer area is located is determined as the first node.
  • each page in the database can only be accessed by one worker thread at the same time. Therefore, when multiple worker threads need to access a page, these worker threads need to access the page in turn, resulting in these tasks The thread access to the page is less efficient.
  • the table data in the table space can be partitioned to obtain multiple partitions, and then these partitions are stored in at least one table space.
  • Each partition includes at least one page.
  • the pages in the partition can be pages in the table data, or pages obtained by splitting the pages in the table data.
  • the table data includes page 1.1, page 1.2, and page 1.3.
  • partition 2.1, partition 2.2, and partition 2.3 are obtained.
  • partition 2.1 includes page 2.11 and page 2.12
  • partition 2.2 includes page 1.2
  • partition 2.3 includes page 1.3.
  • Page 1.1 includes page 2.11 and page 2.12. It can be seen that in the process of partitioning the table data, page 1.1 is divided into page 2.11 and page 2.12. In this way, if the worker thread a needs to access the page 2.11 and the worker thread b needs to access the page 2.12, the two worker threads can access the page that needs to be accessed at the same time.
  • any partitioning method may be adopted, such as hash, range, or round-robin.
  • the computer device may also migrate the data in the table space at an appropriate time.
  • the computer device may also detect (such as periodically detecting) whether the number of worker threads accessing the first table space within the target duration is less than the first number threshold, if the number of worker threads accessing the first table space within the target duration If it is less than the first number threshold, it can be determined that the frequency of the first table space is low. At this time, the computer device can migrate all the data in the first table space to the second table space.
  • the second table space may be any table space except the first table space.
  • the number of worker threads accessing the second table space within the target duration may be greater than or equal to the first number threshold. In this way, the computer device migrates the data in the first table space that is accessed less frequently to the second table space that is accessed more frequently, thereby avoiding the existence of the table space that is accessed less frequently.
  • the computer device may also detect (eg periodically detect) whether the number of worker threads accessing the first table space within the target time period is greater than a second number threshold, which may be greater than the aforementioned first number threshold. If the number of worker threads accessing the first table space within the target duration is greater than the second number threshold, the computer device can determine that the frequency of accessing the first table space is too high. At this time, the computer device can migrate at least part of the data in the first table space to the third table space.
  • the third table space may be any table space except the first table space.
  • the number of worker threads accessing the third table space within the target duration may be less than or equal to the second number threshold. In this way, the computer device migrates at least part of the data in the first table space that is accessed more frequently to the third table space that is accessed less frequently, thereby avoiding the first table space from being accessed too frequently.
  • the computer device also supports load balancing between nodes.
  • the computer device can also detect the load of multiple nodes (related to the memory consumption and/or the density of the working threads of the nodes).
  • the computer device may migrate data of a part of the table space corresponding to the first node to the second node, and modify the corresponding relationship between the migrated table space and the node, so as to achieve load balancing among the nodes.
  • the computer device may immediately load the table corresponding to the first node loaded in the memory of the first node The data in the space is migrated to the memory of the second node.
  • the computer device may not migrate these data immediately, but migrate the page to the memory of the second node every time a read and write request for a certain page of the data is received. In this way, it is possible to reduce the resource overhead at the moment when it is determined that the load of the first node is higher than the first load threshold and the load of the second node is lower than the second load threshold.
  • the computer device can also enter the thread pool mode. For example, when the number of connections established between the computer device and the client is greater than the number of working threads in the computer device, the computer device can also enter the thread pool mode.
  • the computer device can maintain the first thread pool of the first node and the second thread pool in the thread pool mode.
  • the worker threads in the first thread pool are used to process read and write requests on connections that carry the first identifier
  • the worker threads in the second thread pool are used to process read and write requests on connections that do not carry the identifier.
  • the computer device may cause the first connection to carry the first identifier (the identifier indicating the first node).
  • the computer device can take out an idle worker thread from the first thread pool of the first node as the first worker thread, and use the first worker thread. The worker thread responds to the read and write request on the first connection.
  • the computer device can take out an idle thread from the second thread pool as The initial working thread, and the initial working thread is used to respond to the read and write request on the first connection.
  • the worker thread After the worker thread finishes processing the read and write request on a certain connection, if the worker thread is taken from a certain thread pool, the worker thread can be added to the thread pool again. For example, after the initial worker thread has processed the read and write request on the first connection, the initial worker thread can be added to the second thread pool. After the first worker thread finishes processing the read and write request on the first connection, the first worker thread may be added to the first thread pool.
  • the read and write request sent by the client through the first connection will have a high probability of accessing the first table space.
  • every table space that the client needs to access has a high probability of being the first table space. Therefore, if the data in the table space accessed by the read and write request on the first connection is loaded to the first node, and the first worker thread in the first node is used to read the read and write request loaded to the first node Write, you can avoid reading and writing data across nodes with a high probability.
  • FIG. 14 is a block diagram of a data reading and writing device for a database provided by an embodiment of the application.
  • the computer device provided by the embodiment of the application may include the data reading and writing device.
  • the data reading and writing device includes:
  • the establishment module 1401 is configured to establish a first connection with a client, where the first connection is used to transmit a read and write request sent by the client;
  • the determining module 1402 is configured to determine the first table space corresponding to the first connection
  • each node of the plurality of nodes includes a processor and a memory.
  • the processing module 1403 is configured to: load the data of the first table space into the memory of the first node;
  • a first worker thread is used to process read and write requests on the first connection, where the first worker thread is generated by a processor in the first node.
  • the read and write request sent by the client through the first connection will have a high probability of accessing the first table space.
  • each table space that the client needs to access has a high probability of being the first table space. Therefore, if the loading module loads the data in the table space accessed by the read and write request on the first connection to the first node, and the processing module uses the first worker thread in the first node to perform the read load on the first node.
  • the write request for reading and writing can avoid reading and writing data across nodes with a high probability.
  • the above-mentioned data reading and writing device is also used to perform other steps in the data reading and writing method shown in FIG. 3, FIG. 5B, and FIG. 6.
  • the establishment module 1401 is used to perform step 302 in FIG. 3, step 502 in FIG. 5B, and step 602 in FIG. 6
  • the determination module 1402 is used to perform steps 303 and 304 in FIG. 3, and step 503 in FIG. 5B And 504 and steps 603, 604, 605, 606, and 607 in Figure 6
  • the processing module 1403 is used to execute steps 301, 305, and 306 in Figure 3, steps 501, 505, and 506 in Figure 5B, and steps in Figure 6 Steps 601, 608, 609, and 610.
  • FIG. 15 is a schematic structural diagram of a computer device 700 provided according to an embodiment of the present application.
  • the computer device 700 in this embodiment may be one of the specific implementation manners of the computer device in the foregoing embodiments.
  • the computer device 700 includes a processor 701, and the processor 701 is connected to a memory 705.
  • the processor 701 can be a field programmable gate array (English full name: Field Programmable Gate Array, abbreviation: FPGA), or a digital signal processor (English full name: Digital Signal Processor, abbreviation: DSP) or other calculation logic or any of the above calculation logic combination.
  • the processor 701 may also be a single-core processor or a multi-core processor.
  • the memory 705 can be random access memory (Random Access Memory, RAM), flash memory, read only memory (Read Only Memory, ROM), erasable Programmable Read Only Memory (EPROM), and electrable erasable Programmable read-only memory (Electrically Erasable Programmable read only memory), register, or any other form of storage medium known in the art.
  • RAM Random Access Memory
  • ROM read only memory
  • EPROM erasable Programmable Read Only Memory
  • electrable erasable Programmable read-only memory Electrically Erasable Programmable read only memory
  • register or any other form of storage medium known in the art.
  • the memory can be used to store program instructions 707. When the program instructions 707 are executed by the processor 701, the processing The device 701 executes the method described in the foregoing embodiment.
  • the connecting wire 709 is used to transfer information between the various components of the computer device.
  • the connecting wire 709 may be a wired connection or a wireless connection, which is not limited in this application.
  • the connection 709 is also connected to a network interface 704.
  • the network interface 704 uses connection devices such as but not limited to cables or twisted wires to realize communication with other devices or the network 711.
  • the network interface 704 may also be connected to the network 711 in a wireless manner.
  • Some features of the embodiments of the present application may be implemented/supported by the processor 701 executing program instructions or software codes in the memory 705.
  • the software components loaded on the memory 705 may be summarized in terms of function or logic, for example, the establishment module 1401, the processing module 1402, and the loading module 1403 shown in FIG. 15.
  • the processor 701 executes the transactions related to the above-mentioned function/logic module in the memory.
  • the computer device may further include an auxiliary memory 702 and an input/output interface 703.
  • the auxiliary memory 702 is used for the auxiliary memory 705 to store program instructions.
  • the input/output interface 703 is used to interact with devices external to the computer apparatus 700 to obtain data input by the external device or output data to the external device.
  • FIG. 15 is only an example of the computer device 700, and the computer device 700 may include more or fewer components than those shown in FIG. 15, or may have different component configurations.
  • the various components shown in FIG. 15 can be implemented by hardware, software, or a combination of hardware and software.
  • the memory and the processor may be implemented in one module, and the instructions in the memory may be written into the memory in advance, or may be loaded by the subsequent processor during execution.
  • the embodiment of the present application provides a computer storage medium in which a computer program is stored, and the computer program is used to execute the data reading and writing method of the database provided in the present application.
  • the embodiments of the present application provide a computer program product containing instructions.
  • the computer program product runs on a computer device, the computer device executes any of the data reading and writing methods provided in the embodiments of the present application.
  • the computer may be implemented in whole or in part by software, hardware, firmware, or any combination thereof.
  • software it may be implemented in the form of a computer program product in whole or in part, and the computer program product includes one or more computer instructions.
  • the computer program instructions When the computer program instructions are loaded and executed on the computer, the processes or functions described in the embodiments of the present application are generated in whole or in part.
  • the computer may be a general-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.
  • the computer instructions may be transmitted from a website, computer, server, or data.
  • the center transmits to another website, computer, server, or data center through wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.).
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center integrated with one or more available media.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium, or a semiconductor medium (for example, a solid state hard disk).
  • first and second are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance.
  • the term “at least one” refers to one or more, and “multiple” refers to two or more, unless expressly defined otherwise.
  • the disclosed device and the like can be implemented in other structural manners.
  • the device embodiments described above are merely illustrative, for example, the division of units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components can be combined or integrated. To another system, or some features can be ignored, or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical or other forms.
  • the units described as separate components may or may not be physically separate, and the components described as units may or may not be physical units, and may be located in one place or distributed to multiple network devices (such as terminal devices). )on. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种数据库的数据读写方法及装置,属于数据读写技术领域。所述方法包括:与客户端建立第一连接,并确定与第一连接对应的第一表空间,以及确定多个节点中与第一连接或第一表空间对应的第一节点;其中,第一连接接收客户端发送的读写请求;之后,加载第一表空间的数据至第一节点的内存中,并使用第一工作线程对第一连接上的读写请求进行处理,其中,第一工作线程由第一节点中的处理器生成。所述方法用于数据的读写,可以解决数据读写效率较低的问题,提高了数据读写效率。

Description

数据库的数据读写方法及装置
本申请要求于2019年12月13日提交的申请号为201911282832.6、发明名称为“一种数据库高性能架构及设置方法”的中国专利申请的优先权,以及要求于2020年01月23日提交的申请号为202010077018.7、发明名称为“数据库的数据读写方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及数据读写技术领域,特别涉及一种数据库的数据读写方法及装置。
背景技术
计算机装置是一种数据读写装置,能够支持对数据进行读写操作。计算机装置通常包括处理器、内存和外存,被读写的数据往往是外存中的数据。计算机装置在接收到对外存中的数据的读写请求时,计算机装置需要通过处理器中的工作线程对该读写请求进行处理。比如,工作线程会将该数据从外存中加载至内存中进行读写。
随着科技的发展,包括多个处理器的计算机装置得到了广泛的应用。这种计算机装置可以按照该多个处理器划分为多个节点,每个节点均包括一个处理器和一部分内存。在这种场景下,计算机装置可以通过任一节点中的处理器中的工作线程对该读写请求进行处理。并且,工作线程可以将该读写请求所针对的数据加载至任一节点的内存中进行读写。
但是,在计算机装置划分为多个节点的情况下,节点中的工作线程会经常将数据加载至节点外的内存,从而导致处理器跨节点读写数据。由于跨节点读写数据的效率较低,因此,在计算机装置划分为多个节点的情况下,较难保证较高的数据读写效率。
发明内容
本申请提供了一种数据库的数据读写方法及装置,可以解决数据读写效率较低的问题,所述技术方案如下:
第一方面,提供了一种数据库的数据读写方法,所述方法用于计算机装置,所述计算机装置包括多个节点,所述多个节点中的每个节点包括处理器和内存,所述方法包括:首先,与客户端建立第一连接,该第一连接用于传输客户端发送的读写请求;确定与所述第一连接对应的第一表空间,以及确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点;其中,所述第一连接接收所述客户端发送的读写请求;之后,可以加载所述第一表空间的数据至所述第一节点的内存中,并使用第一工作线程对所述第一连接上的读写请求进行处理,其中,所述第一工作线程由所述第一节点中的处理器生成。
本申请实施例提供的数据读写方法中,客户端通过第一连接发送的读写请求会大概率的访问第一表空间。客户端与计算机装置在建立第一连接后,客户端需要访问的每个表空间均大概率的是第一表空间。因此,若将第一连接上的读写请求用于访问的表空间中的数据加载至第一节点,且采用第一节点中的第一工作线程对加载至第一节点的读写请求进行读写,则 能够大概率的避免跨节点读写数据。
根据第一方面,在本申请一种可能的实现方式中,确定与所述第一连接对应的第一表空间,包括:首先使用初始工作线程对所述第一连接上的读写请求进行响应,并确定所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间;再根据所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间确定与所述第一连接对应的第一表空间。其中,所述初始工作线程运行在所述多个节点中的任一节点中。可以看出,本申请提供的数据读写方法可以根据初始工作线程响应第一连接上的读写请求时所访问的表空间,确定第一连接对应的第一表空间,从而使得第一表空间与第一连接上的读写请求所访问的表空间的关联性较大。
根据第一方面,在本申请另一种可能的实现方式中,所述根据所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间确定与所述第一连接对应的第一表空间,包括:将所述初始工作线程响应所述第一连接上的读写请求的过程中访问的第一个表空间,确定为所述第一表空间;或者,将所述初始工作线程响应所述第一连接上的读写请求的过程中,在预定时长内访问频率最高的表空间,确定为所述第一表空间。
一方面,当计算机装置将上述第一个表空间确定为第一表空间时,计算机装置在使用初始工作线程为第一连接上的读写请求进行响应的过程中,仅需检测该第一连接上的读写请求需要访问的第一个表空间即可,因此计算机装置确定第一表空间的效率较高。另一方面,当计算机装置将上述访问频率最高的表空间确定为第一表空间时,第一表空间是计算机装置基于初始工作线程多次访问表空间的历史情况确定的,因此,确定出的第一表空间较为第一连接上的读写请求需要大概率访问的表空间。
根据第一方面,在本申请另一种可能的实现方式中,在所述使用第一工作线程对所述第一连接上的读写请求进行处理之前,所述方法还包括:确定所述初始工作线程位于所述第一节点之外的节点;将所述初始工作线程迁移至所述第一节点,其中,迁移后的所述初始工作线程为所述第一工作线程。通过对初始工作线程的迁移,使得确定第一表空间之前和确定第一表空间之后,对第一连接上的读写请求进行处理的工作线程一致,便于工作线程的管理。当初始工作线程所在的节点为第一节点时,计算机装置可以确定初始工作线程为第一工作线程即可,而无需对初始工作线程进行迁移。
根据第一方面,在本申请另一种可能的实现方式中,所述确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点,包括:根据所述第一连接的特征,确定所述第一节点,其中,所述第一连接的特征包括所述客户端的网际互连协议IP地址、使用所述客户端的用户的名称或者所述第一连接对应的应用程序的名称。可以看出,相同特征的连接确定出的第一节点相同,这就保证了同样特征的连接上的读写请求需要访问的表空间能够尽量加载至同一节点,便于后续对该表空间的数据的读写。
根据第一方面,在本申请另一种可能的实现方式中,在所述与客户端建立第一连接之前,所述方法还包括:创建所述第一表空间,其中,所述第一表空间携带第一标识符,所述第一标识符指示所述第一节点;此时,所述确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点,包括:根据所述第一表空间携带的所述第一标识符确定所述第一节点。在创建的第一表空间携带有第一标识符时,可以直接根据第一表空间携带的第一标识符确定第一节点,从而使确定出第一节点的效率较高。
根据第一方面,在本申请另一种可能的实现方式中,表空间携带的标识符也可以为表空间对应的节点中某一缓冲区的标识符。可以看做是,表空间与节点中的缓冲区存在对应关系。可选地,表空间中的数据可以用于加载至对应的缓冲区,当然表空间中的数据也可以不用于加载至对应的缓冲区,本申请实施例对此不作限定。在表空间携带的标识符为缓冲区的标识符时,计算机装置可以首先确定第一表空间或第一连接对应的第一缓冲区,之后再将第一缓冲区所在的节点确定为第一连接或第一表空间对应的第一节点。将表空间中的数据加载至节点中的缓冲区,能够便于计算机装置对加载至节点中的数据进行有效管理。
根据第一方面,在本申请另一种可能的实现方式中,所述计算机装置包括第一线程池和第二线程池,所述第一线程池中的工作线程用于处理携带所述第一标识符的连接上的读写请求,所述第二线程池中的工作线程用于处理未携带标识符的连接上的读写请求,在所述确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点之后,所述方法还包括:使所述第一连接携带所述第一标识符。之后,由于第一连接携带有用于指示第一节点的第一标识符,因此计算机装置便可以从第一节点的第一线程池中取出一个空闲工作线程作为第一工作线程,并使用该第一工作线程对第一连接上的读写请求进行响应。在需要使用初始工作线程对第一连接上的读写请求进行响应之前,由于初始工作线程未携带有用于指示任何节点的标识符,因此,计算机装置可以从第二线程池中取出一个空闲线程作为初始工作线程,并采用该初始工作线程对第一连接上的读写请求进行响应。在线程池模式下,计算机装置在采用工作线程响应连接上的读写请求时,需要满足相应地线程池中具有空闲工作线程的条件,从而能够保证计算机装置有序地对多个连接上的读写请求进行处理。
根据第一方面,在本申请另一种可能的实现方式中,计算机装置还可以检测在目标时长内访问第一表空间的工作线程的数量是否小于第一数量阈值,若目标时长内访问第一表空间的工作线程的数量小于第一数量阈值,则计算机装置可以将第一表空间中的全部数据迁移至第二表空间。该第二表空间可以为除第一表空间之外的任一表空间,可选地,在目标时长内访问该第二表空间的工作线程的数量可以大于或等于第一数量阈值。这样一来,计算机装置便将被访问频率较小的第一表空间中的数据迁移至被访问频率较高的第二表空间,从而避免存在被访问频率过低的表空间。
根据第一方面,在本申请另一种可能的实现方式中,计算机装置还可以检测在目标时长内访问第一表空间的工作线程的数量是否大于第二数量阈值,第二数量阈值可以大于上述第一数量阈值。若目标时长内访问第一表空间的工作线程的数量大于第二数量阈值,则计算机装置可以将第一表空间中的至少部分数据迁移至第三表空间。该第三表空间可以为除第一表空间之外的任一表空间,可选地,在目标时长内访问该第三表空间的工作线程的数量可以小于或等于第二数量阈值。这样一来,计算机装置便将被访问频率较高的第一表空间中的至少部分数据迁移至被访问频率较低的第三表空间,从而避免第一表空间被访问频率过高。
根据第一方面,在本申请另一种可能的实现方式中,计算机装置还可以检测多个节点的负载。当确定第一节点的负载高于第一负载阈值,且第二节点的负载低于第二负载阈值时,计算机装置可以通过将第一节点对应的部分表空间的数据迁移至第二节点,并修改所迁移的表空间与节点之间的对应关系,来实现各个节点之间的负载均衡。
第二方面,提供了一种数据库的数据读写装置,所述数据读写装置包括:用于执行第一方面提供的任一种数据读写方法的各个模块。
第三方面,提供了一种计算机装置,所述计算机装置包括:处理器和存储器,所述存储器中存储有程序,所述处理器用于调用所述存储器中存储的程序,以使得所述计算机装置执行如第一方面提供的任一种数据库的数据读写方法。
第四方面,提供了一种计算机存储介质,所述存储介质内存储有计算机程序,当计算机程序在计算机装置上运行时,使该计算机装置执行如第一方面提供的任一种数据库的数据读写方法。
附图说明
图1为本申请实施例提供的一种计算机装置的结构示意图;
图2为本申请实施例提供的另一种计算机装置的结构示意图;
图3为本申请实施例提供的一种数据库的数据读写方法的流程图;
图4为本申请实施例提供的一种表空间与节点的对应关系示意图;
图5A为本申请实施例提供的一种数据读写过程示意图;
图5B为本申请实施例提供的另一种数据库的数据读写方法的流程图;
图6为本申请实施例提供的又一种数据库的数据读写方法的流程图;
图7为本申请实施例提供的另一种数据读写过程示意图;
图8为本申请实施例提供的另一种数据读写过程示意图;
图9为本申请实施例提供的另一种数据读写过程示意图;
图10为本申请实施例提供的另一种数据读写过程示意图;
图11为本申请实施例提供的另一种数据读写过程示意图;
图12为本申请实施例提供的另一种数据读写过程示意图;
图13为本申请实施例提供的另一种数据读写过程示意图;
图14为本申请实施例提供的一种数据库的数据读写装置的框图;
图15为依据本申请的实施例提供的计算机装置700的结构示意图。
具体实施方式
为使本申请的原理、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
图1为本申请实施例提供的一种计算机装置的结构示意图。计算机装置01可以为服务器或电脑等具有数据读写功能的任意设备。如图1所示,计算机装置01通常包括处理器011、内存012、外存013、总线104和输入/输出(input/output,I/O)接口105。其中,该处理器101、内存102、I/O接口105通过总线104通信连接,I/O接口105还与外存103连接。处理器101能够通过总线104调用内存102中存储的数据。
内存012和外存013均可以为计算机装置01中用于存储数据的结构。内存012也被称为内存储器或主存储器,其作用是用于暂时存放处理器中的运算数据,以及与外存交换的数据。外存013也称为外存储器或辅助存储器,其作用是用于永久存放数据,外存013可以为硬盘、软盘、光盘、U盘等。处理器011能够直接对内存012进行访问,但无法直接对外存013直接进行访问。处理器011在需要访问外存013中的数据时,通常需要先通过I/O接口105和总线104将外存013中的数据加载至内存012,之后处理器011才能访问加载至内存012中 的该数据。并且,内存012存储数据的速度快于外存013存储数据的速度,但内存012的容量通常远小于外存013的容量,内存012中存储的数据通常在计算机装置01断电后无法保存,而外存013中存储的数据在计算机装置01断电后仍然能够保存。
计算机装置可以通过数据库来管理外存中的数据,该数据库可以为任一种数据库,比如,磁盘数据库或内存数据库等,本申请实施例对此不作限定。当然,计算机装置也可以不通过数据库来管理外存中的数据,本申请实施例对此不作限定。
示例地,数据库可以包括多个表空间,表空间对应外存中的一部分存储空间,且不同表空间对应的存储空间不同。表空间是一种逻辑存储概念,表空间中的数据实际上存储在表空间对应的存储空间中,且对每个表空间进行数据的读写,相当于是对该表空间在外存中对应的存储空间进行数据的读写。
数据库中存储的数据可以称为表数据,表数据可以包括至少一个页面,可以理解为表数据可以划分为至少一个页面,将该至少一个页面进行拼接,能够得到该表数据。比如,表数据可以记录有某一班级中各个学生的名字、年龄和性别。若该班级的学生分为四组,则该表数据可以包括与这四组学生一一对应的四个页面,每个页面可以包括对应的一组学生的名字、年龄和性别。或者,该表数据可以包括两个页面,其中,一个页面包括该班级中各个学生的名字和年龄,另一个页面包括该班级中各个学生的名字和性别。表数据与页面的关系还可以是其他关系,本申请实施例在此不做赘述。
数据库中的每个表空间可以对应至少一种业务,表空间用于存储对应的业务的数据。各个表空间对应的业务可以相同也可以不同,本申请实施例对此不作限定。
数据库还可以将计算机装置的内存中的某些存储区域命名为缓冲区。计算机装置在对某一表空间中的数据进行读写的过程中,处理器011需要通过其中的工作线程,先将该数据从外存中加载至内存012的缓冲区中,再对加载至内存012的缓冲区中的该数据进行读写。本申请实施例中的缓冲区可以为内存中的全局缓冲区,如系统全局区域(system global area,SGA)管理的全局缓冲区:全局数据页面缓冲区(Data Buffer)、全局日志缓冲区(Log Buffer)、全局执行计划缓冲区(SQL Cache)、全局排序/物化缓冲区(Sort Area)或全局数据字典(元数据)缓冲区(Dictionary Cache)等。
图1所示出的计算机装置01仅包括一个处理器011和一个内存012,进一步地,图2为本申请实施例提供的另一种计算机装置的结构示意图,如图2所示,在图1的基础上,该计算机装置还可以包括多个处理器011和多个内存012,并且,多个处理器011和多个内存012组成多个节点,每个节点包括一个处理器011和一个内存012。
其中,节点也可以称为非一致性内存访问(non uniform memory access,NUMA)节点。每个节点中的处理器011和内存012之间通过总线连接,各个节点的处理器之间通过高速互联总线(比如快速路径互连(quick path interconnect,QPI)总线)连接,且该高速互联总线的传输速率低于节点内处理器和内存之间连接的总线的传输速率。需要说明的是,图2中仅示出了一个节点的处理器与其他节点的处理器的连接关系。
图2中每个节点中的处理器011均可以对外存中的数据进行读写。相关技术中,计算机装置可以通过任一节点的处理器中的工作线程,将表空间中的数据加载至该节点中的内存012,也可以将表空间中的数据加载至其他节点中的内存012。计算机装置在通过某一节点的处理器011的工作线程,将表空间中的数据加载至其他节点的内存012后,该处理器011再通过 本地的工作线程读写加载至其他节点的内存012中的数据,就会导致跨节点读写数据的情况发生。
由于跨节点读写数据时需要通过较多总线对数据进行读写,并且,节点间的连接线(如上述高速互联总线)的数据传输速率较低,这样就会导致跨节点读写数据的效率较低,较难保证较高的数据读写效率。
本申请实施例提供了一种数据库的数据读写方法,能够降低跨节点读写数据的概率,提升数据读写的效率。
示例地,图3为本申请实施例提供的一种数据库的数据读写方法的流程图,该数据读写方法可以用于如图2所示的计算机装置。如图3所示,该数据读写方法可以包括:
步骤301、创建至少一个表空间,该至少一个表空间均具有对应的节点。
示例地,计算机装置可以基于表空间的创建指令创建表空间,该表空间的创建指令需要携带该表空间在外存中对应的文件,以便于后续写入该表空间中的数据可以存储在该表空间对应的文件中。
在本申请一种可能的实现方式中,每个表空间对应一种业务,该表空间仅用于存储对应的业务的数据。比如,企业可以为每个员工创建一个表空间,每个员工的表空间均用于存储该员工处理过的数据,这可以看做是该表空间对应的业务为存储该员工处理过的数据。计算机装置可以根据该表空间对应的业务,在计算机装置中筛选一个节点作为该表空间对应的节点。比如,计算机装置可以基于表空间对应的业务的特征,采用哈希(hash)、轮询调度(round-robin)或者其他方式,在计算机装置中筛选该表空间对应的节点。这样一来,对应相同业务的表空间对应的节点相同。示例地,如图4所示,假设表空间1对应业务1,表空间2对应业务2,表空间3对应业务3。计算机装置可以根据业务1的特征,选择节点1作为表空间1对应的节点;根据业务2的特征,选择节点2作为表空间2对应的节点;根据业务3的特征,选择节点3作为表空间3对应的节点。可选地,计算机装置也可以不是基于表空间对应的业务的特征,在计算机装置中筛选表空间对应的节点,比如,计算机装置可以在计算机装置中随机筛选表空间对应的节点,本申请实施例对此不作限定。
计算机装置创建的表空间可以携带有标识符,且该标识符用于指示该表空间对应的节点。相应地,表空间的创建指令也需要携带有标识符。例如,表空间的创建指令可以为create tablespace<spc_numa_x><datafile>numa x。其中,“create tablespace<spc_numa_x>”表示创建表空间<spc_numa_x>,“<spc_numa_x>”表示创建的表空间的名称,<datafile>表示该表空间在外存中对应的文件名,“numa x”为标识符,表示该表空间在计算机装置的多个节点中对应的节点。
进一步地,步骤301中创建的至少一个表空间可以包括:读写表空间和只读表空间,读写表空间支持读操作和写操作,而只读表空间仅支持读操作,且不支持写操作。创建的读写表空间可以对应多个节点中的一个节点,不同读写表空间对应的节点可以相同也可以不同,只读表空间对应多个节点中的全部节点。如图4中的表空间1、2和3均为读写表空间,分别对应一个节点,而表空间4为只读表空间,同时对应节点1、2、3和4。每个表空间中的数据用于加载至对应的节点中,因此,读写表空间只会被加载至一个节点,而只读表空间能够被加载至多个节点中的任一节点。
示例地,上述表空间的创建指令可以为读写表空间的创建指令,只读表空间的创建指令可以为:create tablespace<spc_numa_x><datafile>numa replication。其中,“create tablespace<spc_numa_x>”表示创建表空间<spc_numa_x>,“<spc_numa_x>”表示创建的表空间的名称,<datafile>表示该表空间在外存中对应的文件名,“numa replication”为标识符,该标识符用于表示该表空间对应计算机装置的所有节点。
需要说明的是,本申请实施例中以表空间在被读写时,表空间中的数据用于加载至表空间对应的节点中为例。当然,表空间中的数据也可以不用于加载至表空间对应的节点,本申请实施例对此不作限定。
步骤302、与客户端建立第一连接,其中,该第一连接用于传输客户端发送的读写请求。
在创建上述至少一个表空间之后,计算机装置可以根据客户端发送的连接请求,与客户端建立第一连接。该第一连接可以为任一种通信连接,如传输控制协议(transmission control protocol,TCP)连接、超文本传输协议(hypertext transport protocol,HTTP)连接等。计算机装置与客户端建立的连接也可以称为会话(session)。
计算机装置能够通过该第一连接接收客户端发送的至少一个读写请求,该至少一个读写请求可以包括访问第一表空间的读写请求。第一连接传输的读写请求均为同一业务的读写请求,且这些读写请求都是访问第一表空间的读写请求,该第一表空间对应的节点可以是根据该业务的特征确定出来的。
步骤303、确定与第一连接对应的第一表空间。
在本申请实施例中,每个表空间对应一种业务,该表空间仅用于存储对应的业务的数据,且不同业务对应的表空间不同。在步骤303中,计算机装置可以将第一连接对应的业务所对应的表空间确定为第一表空间。
步骤304、确定多个节点中与第一表空间对应的第一节点。
如步骤301中所述,计算机装置创建的每个表空间均具有对应的节点,因此,在步骤304中,计算机装置可以获取到表空间与节点的对应关系,并基于该对应关系查找第一表空间对应的第一节点。
其中,计算机装置在步骤301中创建表空间的过程中,可以得到表空间与节点的对应关系。计算机装置可以将该对应关系存储在计算机装置本地,当然也可以存储在计算机装置外部的其他设备上,只要计算机装置在步骤303中能够获取到该对应关系即可。
例如,图4中表空间与节点的对应关系可以如表1所示,表空间1对应节点1,表空间2对应节点2,表空间3对应节点3,表空间4对应节点1、2和3。若第一表空间为表空间3,则在步骤304中,计算机装置可以将表空间3对应的节点3确定为第一节点。
表1
表空间 节点
1 1
2 2
3 3
4 1、2、3
步骤305、加载第一表空间的数据至第一节点的内存中。
在确定第一表空间和第一节点后,计算机装置可以将第一表空间中的数据加载至第一节点的内存中。
步骤306、使用第一工作线程对第一连接上的读写请求进行处理,其中,第一工作线程由第一节点中的处理器生成。
计算机装置可以使用第一节点中的处理器生成的第一工作线程,固定对第一连接上的读写请求进行处理。并且无论第一连接上会有多少读写请求,均由该第一工作线程进行处理。
本申请实施例中第一表空间中的数据可以被加载至第一节点中,第一连接上的读写请求用于访问第一表空间,且计算机装置能够采用第一节点中的处理器生成的第一工作线程对该读写请求进行处理。这样一来,就使得第一工作线程和被读写的第一表空间中的数据均位于第一节点中,避免了跨节点读写数据,提高了数据读写效率。
示例地,如图5A所示,第一连接上的读写请求1、2、3和4均用于访问第一表空间(表空间1),且第一表空间(表空间1)对应的第一节点为节点1。计算机装置会将表空间1中的数据加载至节点1的内存(内存1)中。在采用节点1中的处理器生成的第一工作线程(线程1)对这些读写请求进行处理的过程中,线程1能够对加载至内存1中的该表空间1中的数据进行读写。可以看出,第一连接上的读写请求用于访问的数据被加载至的内存1与读写该数据的线程1均位于同一节点1上,因此,避免了线程1跨节点读写数据。
在本申请实施例中,每种业务特征的连接传输的读写请求可以仅用于访问该业务特征对应的表空间,且每种业务特征对应的表空间对应计算机装置中的同一节点。比如,假设上述业务特征为客户端的IP地址,每个客户端用于访问其IP地址对应的表空间,且不会对其他客户端的IP地址对应的表空间进行访问。在基于第一连接的特征确定第一节点后,可以认为该第一连接上的每个读写请求用于访问的表空间(如第一表空间)对应的节点均为该第一节点。若将第一连接上的每个读写请求用于访问的表空间中的数据均加载至第一节点,且采用第一节点中的工作线程对加载至第一节点的读写请求进行读写,则能够完全避免跨节点读写数据。
图5B为本申请实施例提供的另一种数据库的数据读写方法的流程图,该数据读写方法可以用于如图2所示的计算机装置。如图5B所示,该数据读写方法可以包括:
步骤501、创建至少一个表空间。
与步骤301不同的是,步骤501中计算机装置创建的表空间不具有对应的节点。
步骤502、与客户端建立第一连接,其中,该第一连接用于传输客户端发送的读写请求。
步骤502可以参考步骤302,本申请实施例在此不做赘述。
步骤503、确定与第一连接对应的第一表空间。
步骤503可以参考步骤303,本申请实施例在此不做赘述。
步骤504、确定多个节点中与第一连接对应的第一节点。
可选地,计算机装置可以根据第一连接的特征确定第一节点。其中,第一连接的特征可以包括:客户端的网际互连协议(internet protocol,IP)地址,使用所述客户端的用户的名称,或者第一连接对应的应用程序的名称等。
示例地,计算机装置可以基于第一连接的特征,在计算机装置中筛选一个节点作为第一节点,该筛选过程可以参考步骤301中计算机基于表空间对应的业务的特征筛选节点的过程, 本申请实施例在此不作赘述。
步骤505、加载第一表空间的数据至第一节点的内存中。
步骤505可以参考步骤305,本申请实施例在此不做赘述。
步骤506、使用第一工作线程对第一连接上的读写请求进行处理,其中,第一工作线程由第一节点中的处理器生成。
步骤506可以参考步骤306,本申请实施例在此不做赘述。
本申请实施例中第一表空间中的数据可以被加载至第一节点中,第一连接上的读写请求用于访问第一表空间,且计算机装置能够采用第一节点中的处理器生成的第一工作线程对该读写请求进行处理。这样一来,就使得第一工作线程和被读写的第一表空间中的数据均位于第一节点中,避免了跨节点读写数据,提高了数据读写效率。
再示例地,图6为本申请实施例提供的又一种数据库的数据读写方法的流程图,该数据读写方法可以用于如图2所示的计算机装置。如图6所示,该数据读写方法可以包括:
步骤601、创建至少一个表空间。
在步骤601中,即创建的至少一个表空间既可以具有对应的节点(参考步骤S301),也可以没有对应的节点(参考步骤S501),本申请实施例不对此进行限定。
步骤602、与客户端建立第一连接,其中,该第一连接用于传输客户端发送的读写请求。
步骤602可以参考步骤302,但与步骤302不同的是,在本实施例中,步骤602中第一连接传输的读写请求可以包括用于访问一个或多个表空间的读写请求。步骤603、使用初始工作线程对第一连接上的读写请求进行响应,其中,初始工作线程运行在计算机装置的多个节点中的任一节点中。
在计算机装置与客户端建立第一连接后,计算机装置可以首先起一个初始工作线程(可以位于计算机装置中的任一节点上),之后再使用初始工作线程对第一连接上的读写请求进行响应。
其中,初始工作线程在对第一连接上的读写请求进行响应的过程中,会对该读写请求需要访问的表空间进行访问。需要说明的是,第一连接上的读写请求可以有至少一个,初始工作线程可以依次响应第一连接上的读写请求。
示例地,如图7所示,假设计算机装置包括节点1、2、3和4,且节点1具有线程1,节点2具有线程2,节点3具有线程3,节点4具有线程4。在计算机装置与客户端建立的第一连接后,计算机装置便可以将节点2上的线程2作为上述初始工作线程,并使用线程2依次对第一连接上的读写请求1、2、3和4进行响应。
步骤604、确定初始工作线程响应第一连接上的读写请求时所访问的表空间。
步骤605、根据初始工作线程响应第一连接上的读写请求时所访问的表空间确定与第一连接对应的第一表空间。
在初始工作线程对第一连接上的读写请求进行响应的过程中,计算机装置可以确定初始工作线程响应第一连接上的读写请求时所访问的表空间,之后,便可以根据这些表空间采用多种实现方式确定第一表空间。
在第一种实现方式中,计算机装置可以将初始工作线程响应第一连接上的读写请求的过程中访问的第一个表空间确定为第一表空间。可以看出,计算机装置在使用初始工作线程为 第一连接上的读写请求进行响应的过程中,仅需检测该第一连接上的读写请求需要访问的第一个表空间即可。
比如,数据库中表空间以及表空间中的页面的关系如表2所示,若初始工作线程在响应第一连接上的读写请求的过程中,访问的第一个页面为页面4,则可以确定页面4所在的表空间2为初始工作线程访问的第一个表空间,并确定表空间2为上述第一表空间。
表2
表空间 页面
1 1、2、3
2 4、5
3 6
4 7、8
在第二种实现方式中,计算机装置可以将初始工作线程响应第一连接上的读写请求的过程中,在预定时长内访问频率最高的表空间,确定为第一表空间。可以看出,计算机装置在使用初始工作线程为第一连接上的读写请求进行响应的过程中,需要统计预定时长内该第一连接上的读写请求需要访问的表空间,并确定出这些表空间中访问频率最高的第一表空间即可。
比如,对于如表2所示的表空间,假设初始工作线程在响应第一连接上的读写请求的第一时长内,访问了表空间1、4和5。并且,如表3所示,在预定时长内,访问表空间1的频率为2次/分,访问表空间4的频率为3次/分,访问表空间5的频率为5次/分。可以看出,在初始工作线程响应第一连接上的读写请求的第一时长内,表空间5的被访问频率最高,此时计算机装置可以确定表空间5为上述第一表空间。
表3
表空间 在预定时长内访问表空间的频率(次/分)
1 2
4 3
5 5
步骤606、确定第一连接或者第一表空间对应的第一节点。
由于在步骤601创建的至少一个表空间既可以具有对应的节点,也可以没有对应的节点,当创建的表空间具有对应的节点时,可以直接确定第一表空间对应的第一节点;当创建的表空间没有对应的节点时,可以参考步骤S504,根据第一连接的特征确定对应的第一节点。步骤607、确定初始工作线程位于第一节点之外的节点。
在确定第一节点之后,计算机装置需要判断初始工作线程是否位于第一节点之外的节点。本申请实施例中以初始工作线程位于第一节点之外的节点为例。
步骤608、将初始工作线程迁移至第一节点,其中,迁移后的初始工作线程为第一工作线程。
如图8所示,假设第一节点为节点1,而初始工作线程(线程2)所在的节点2与节点1不同,则计算机装置可以将线程2从节点2迁移至节点1。
需要说明的是,迁移前的初始工作线程和迁移后的初始工作线程(也即第一工作线程)可以为同一工作线程,但迁移前的初始工作线程并非位于第一节点中,且迁移后的初始工作线程(也即第一工作线程)位于第一节点中。
或者,迁移前的初始工作线程和迁移后的初始工作线程(也即第一工作线程)为不同的工作线程,计算机装置在迁移初始工作线程时,可以在第一节点中起一个工作线程,并将初始工作线程工作所需的数据均迁移至第一节点中的工作线程,从而使初始工作线程的功能转移至第一节点中的工作线程,得到迁移后的初始工作线程(也即第一工作线程)。
步骤609、加载第一表空间的数据至第一节点的内存中。
步骤609可以参考步骤305,本申请实施例在此不做赘述。
需要说明的是,初始工作线程在对第一连接上的读写请求进行响应的过程中,会对该读写请求需要访问的表空间进行访问。在该访问的过程中,第一表空间中的数据可能被加载至第一节点的内存中,也有可能未被加载至第一节点的内存中;若在该访问的过程中,第一表空间中的数据未被加载至第一节点的内存中,则可以执行步骤609,以确保第一表空间中的数据被加载至第一节点的内存中;若在该访问的过程中,第一表空间中的数据已被加载至第一节点的内存中,则可以无需执行步骤609。
步骤610、使用第一工作线程对第一连接上的读写请求进行处理,其中,第一工作线程由第一节点中的处理器生成。
步骤610可以参考步骤306,本申请实施例在此不做赘述。
在本申请一种可能的实现方式中,当初始工作线程所在的节点为第一节点时,计算机装置可以不执行步骤607和步骤608,且确定初始工作线程为第一工作线程,并直接执行步骤609即可。
在本申请另一种可能的实现方式中,计算机装置也可以不执行步骤607和步骤608,而是在步骤606之后,计算机装置直接在第一节点上另起一个工作线程,将该工作线程作为第一工作线程,执行步骤609即可。
如图9所示,假设初始工作线程(线程2)在迁移至节点1之前,对第一连接上的读写请求1进行响应,但还未对第一连接上的读写请求2、3和3进行响应。则在将初始工作线程(线程2)迁移至第一节点(节点1)得到第一工作线程后,便可以采用该第一工作线程(迁移至节点1中的线程2)依次对第一连接上的读写请求2、3和4进行响应。
可以看出,无论是否对初始工作线程进行迁移,本申请实施例中均需要采用第一节点上的第一工作线程对第一连接上的读写请求进行处理。
在本申请实施例中,客户端通过第一连接发送的读写请求会较大概率(如99%、98%或80%等)地访问第一表空间,且较小概率(如1%、2%或20%等)会访问其他表空间。相应的,客户端与计算机装置在建立第一连接后,客户端每次需要访问的表空间较大概率会是第一表空间。因此,若将第一连接上的读写请求用于访问的表空间中的数据加载至第一节点,且采用第一节点中的第一工作线程对加载至第一节点的读写请求进行读写,则能够较大概率避免跨节点读写数据。
以业务处理系统(Transaction Processing Performance Council,TPC-C)为例,TPC-C管理若干个分布在不同区域的商品仓库。假设每个仓库负责为10个销售点供货,其中每个销售 点为3000个客户端提供服务。在这种场景下,供客户端访问的多个商品仓库的表数据可以划分为多个分区,并将这些分区分布在多个表空间中,每个商品仓库的分区所存储的各个表空间对应同一节点。每个客户端提交的订单中,约90%的产品在该客户端对应的仓库(也即为该客户端直接提供服务器的销售点对应的仓库)中有存货,且10%的产品在该仓库中没有存货,必须由其他仓库来供货。这样一来,每个客户端会大概率(约90%)的访问其对应的仓库的分区所在的表空间,因此,计算机装置可以将客户端需要访问的第一个表空间确定为第一表空间,并将该表空间对应的节点确定为第一节点。在确定第一节点后,可以认为该第一连接上的每个读写请求用于访问的表空间对应的节点均大概率的为该第一节点。采用第一表空间对应的第一节点中的第一工作线程对第一连接上的读写请求进行处理,能够大概率的避免跨节点读写数据。
可选地,在步骤606之后,若第一节点与初始工作线程所在的节点不同,则计算机装置也可以不执行步骤607至步骤608,而是将前述第一表空间对应的节点由上述第一节点变更为初始工作线程所在的节点,之后,再采用初始工作线程对该第一连接上的读写请求进行处理。这样一来,初始工作线程在处理第一连接上的读写请求时,可以将该读写请求访问的第一表空间中的数据加载至初始工作线程所在的节点,从而也能减小跨节点读写数据的概率。
步骤301中以表空间具有对应的节点,表空间携带的标识符为表空间对应的节点的标识符为例,可选地,表空间携带的标识符也可以为表空间对应的节点中某一缓冲区的标识符。可以看做是,表空间与节点中的缓冲区存在对应关系。可选地,表空间中的数据可以用于加载至对应的缓冲区,当然表空间中的数据也可以不用于加载至对应的缓冲区,本申请实施例对此不作限定。
在表空间携带的标识符为缓冲区的标识符时,表空间的创建指令可以为:create tablespace<spc_numa_x><datafile><buf_x>。其中,“create tablespace<spc_numa_x>”表示创建表空间<spc_numa_x>,“<spc_numa_x>”表示创建的表空间的名称,<datafile>表示该表空间在外存中对应的文件名,“<buf_x>”为表空间的标识符,且用于表示该表空间对应的缓冲区。
另外,在表空间携带的标识符为缓冲区的标识符时,节点中的缓冲区也携带有该缓冲区所在的节点的标识符。在创建表空间之前,还可以根据缓冲区创建指令,创建缓冲区。其中,该缓冲区的创建指令可以为:create database buffer<buf_x>numa x,“create database buffer<buf_x>”表示创建缓冲区<buf_x>,“<buf_x>”为创建的缓冲区的名称,“numa x”为节点的标识符,用于表示创建的缓冲区所在的节点。
在表空间携带的标识符为缓冲区的标识符时,计算机装置在确定多个节点中与第一连接或第一表空间对应的第一节点时,可以首先确定与第一连接或第一表空间对应的第一缓冲区,之后再将第一缓冲区所在的节点确定为第一节点。
需要说明的是,数据库中每个页面在同一时刻仅能够被一个工作线程访问,因此,当多个工作线程均需要访问某一页面时,这些工作线程需要依次对该页面进行访问,导致这些工作线程访问该页面的效率较低。
为了提高各个工作线程访问页面的效率,可以对表空间中的表数据进行分区,得到多个分区,再将这些分区存储在至少一个表空间中。每个分区包括至少一个页面,分区中的页面 可以是表数据中的页面,也可以是将表数据中的页面拆分后得到的页面。
比如,表数据包括页面1.1、页面1.2和页面1.3,在对表数据进行分区后得到分区2.1、分区2.2和分区2.3。其中,分区2.1包括页面2.11和页面2.12,分区2.2包括页面1.2,分区2.3包括页面1.3。页面1.1包括页面2.11和页面2.12。可以看出,在对表数据进行分区的过程中,页面1.1被分为页面2.11和页面2.12。这样一来,若工作线程a需要访问页面2.11,工作线程b需要访问页面2.12,则这两个工作线程可以同时对需要访问的页面进行访问。但是,若未对表数据进行分区,则由于页面2.11和页面2.12均属于页面1.1,因此,工作线程a和工作线程b需要依次对页面1.1进行访问。所以,通过对表数据进行分区,能够提高工作线程对页面的访问效率。
可选地,工作线程在对表数据进行分区时,可以采用任一种分区方式,比如哈希(hash)、顺序排布(range)或轮询调度(round-robin)等方式。
可选地,计算机装置还可以在适当的时机,对表空间中的数据进行迁移。
示例地,计算机装置还可以检测(如周期性地检测)在目标时长内访问第一表空间的工作线程的数量是否小于第一数量阈值,若目标时长内访问第一表空间的工作线程的数量小于第一数量阈值,则可以确定该第一表空间被访问的频率较低。此时,计算机装置可以将第一表空间中的全部数据迁移至第二表空间。该第二表空间可以为除第一表空间之外的任一表空间,可选地,在目标时长内访问该第二表空间的工作线程的数量可以大于或等于第一数量阈值。这样一来,计算机装置便将被访问频率较小的第一表空间中的数据迁移至被访问频率较高的第二表空间,从而避免存在被访问频率过低的表空间。
又示例地,计算机装置还可以检测(如周期性地检测)在目标时长内访问第一表空间的工作线程的数量是否大于第二数量阈值,第二数量阈值可以大于上述第一数量阈值。若目标时长内访问第一表空间的工作线程的数量大于第二数量阈值,则计算机装置可以确定该第一表空间被访问的频率过高。此时,计算机装置可以将第一表空间中的至少部分数据迁移至第三表空间。该第三表空间可以为除第一表空间之外的任一表空间,可选地,在目标时长内访问该第三表空间的工作线程的数量可以小于或等于第二数量阈值。这样一来,计算机装置便将被访问频率较高的第一表空间中的至少部分数据迁移至被访问频率较低的第三表空间,从而避免第一表空间被访问频率过高。
需要说明的是,当某一表空间被访问的频率过高时,各个工作线程访问该表空间的效率就会降低,而本申请实施例中通过将表空间中的至少部分数据进行迁移,能够降低表空间被访问的频率,从而提高各个工作线程访问表空间的效率。
可选地,计算机装置还支持节点间的负载均衡。示例地,计算机装置还可以检测多个节点的负载(与节点的内存消耗和/或工作线程密度相关)。当确定第一节点的负载高于第一负载阈值,且第二节点的负载低于第二负载阈值时,表明第一节点的负载较高,第二节点的负载较低。其中,第一负载阈值大于或等于第二负载阈值。此时,计算机装置可以通过将第一节点对应的部分表空间的数据迁移至第二节点,并修改所迁移的表空间与节点之间的对应关系,来实现各个节点之间的负载均衡。
示例地,计算机装置在确定第一节点的负载高于第一负载阈值,且第二节点的负载低于第二负载阈值时,可以立即将第一节点的内存中加载的第一节点对应的表空间中的数据迁移 至第二节点的内存中。当然,计算机装置也可以不立即迁移这些数据,而是在每接收到针对这些数据中某一页面的读写请求之后,才将该页面迁移至第二节点的内存中。这样一来,能够减少在确定第一节点的负载高于第一负载阈值,且第二节点的负载低于第二负载阈值这一时刻的资源开销。
可选地,计算机装置还可以进入线程池模式。比如,当计算机装置与客户端建立的连接的数量大于计算机装置中工作线程的数量时,计算机装置还可以进入线程池模式。
示例地,计算机装置在线程池模式下可以维护第一节点的第一线程池,以及第二线程池。第一线程池中的工作线程用于处理携带第一标识符的连接上的读写请求,第二线程池中的工作线程用于处理未携带标识符的连接上的读写请求。
计算机装置在确定多个节点中与第一连接或第一表空间对应的第一节点之后,可以使第一连接携带第一标识符(指示第一节点的标识符)。之后,由于第一连接携带有用于指示第一节点的第一标识符,因此计算机装置便可以从第一节点的第一线程池中取出一个空闲工作线程作为第一工作线程,并使用该第一工作线程对第一连接上的读写请求进行响应。在需要使用初始工作线程对第一连接上的读写请求进行响应之前,由于初始工作线程未携带有用于指示任何节点的标识符,因此,计算机装置可以从第二线程池中取出一个空闲线程作为初始工作线程,并采用该初始工作线程对第一连接上的读写请求进行响应。
在工作线程对某一连接上的读写请求处理完毕后,如果工作线程是从某一线程池中取出的,则可以将该工作线程再加入该线程池。比如,在初始工作线程对第一连接上的读写请求处理完毕之后,可以将初始工作线程再加入第二线程池。在第一工作线程对第一连接上的读写请求处理完毕之后,可以将第一工作线程在加入第一线程池。
在线程池模式下,计算机装置在采用工作线程响应连接上的读写请求时,需要满足相应地线程池中具有空闲工作线程的条件,从而能够保证计算机装置有序地对多个连接上的读写请求进行处理。
综上所述,本申请实施例提供的数据读写方法中,客户端通过第一连接发送的读写请求会大概率的访问第一表空间。客户端与计算机装置在建立第一连接后,客户端需要访问的每个表空间均大概率的是第一表空间。因此,若将第一连接上的读写请求用于访问的表空间中的数据加载至第一节点,且采用第一节点中的第一工作线程对加载至第一节点的读写请求进行读写,则能够大概率的避免跨节点读写数据。
上文中结合图1至图13,详细描述了本申请所提供的数据库的数据读写方法,下面将结合图14描述本申请所提供的数据库的数据读写。
图14为本申请实施例提供的一种数据库的数据读写装置的框图,本申请实施例提供的计算机装置可以包括该数据读写装置。如图14所示,该数据读写装置包括:
建立模块1401,用于与客户端建立第一连接,其中,所述第一连接用于传输所述客户端发送的读写请求;
确定模块1402,用于:确定与所述第一连接对应的第一表空间;
确定计算机装置的多个节点中与所述第一连接或所述第一表空间对应的第一节点,所述多个节点中的每个节点包括处理器和内存。
处理模块1403,用于:加载所述第一表空间的数据至所述第一节点的内存中;
使用第一工作线程对所述第一连接上的读写请求进行处理,其中,所述第一工作线程由所述第一节点中的处理器生成。
综上所述,本申请实施例提供的数据读写装置中,客户端通过第一连接发送的读写请求会大概率的访问第一表空间。客户端与建立模块在建立第一连接后,客户端需要访问的每个表空间均大概率的是第一表空间。因此,若加载模块将第一连接上的读写请求用于访问的表空间中的数据加载至第一节点,且处理模块采用第一节点中的第一工作线程对加载至第一节点的读写请求进行读写,则能够大概率的避免跨节点读写数据。
上述数据读写装置还用于执行如图3、图5B和图6所示的数据读写方法中的其他步骤。比如,建立模块1401用于执行图3中的步骤302、图5B中的步骤502和图6中的步骤602;确定模块1402用于执行图3中的步骤303和304,图5B中的步骤503和504以及图6中的步骤603、604、605、606和607;处理模块1403用于执行图3中的步骤301、305和306,图5B中的步骤501、505和506以及图6中的步骤601、608、609和610。各个模块执行各个步骤的具体流程请见上文对图3、图5B和图6的介绍,此处不再赘述。
图15为依据本申请的实施例提供的计算机装置700的结构示意图。本实施例中的计算机装置700可以是上述各实施例中的计算机装置的其中一种具体实现方式。
如图15所示,该计算机装置700包括处理器701,处理器701与存储器705连接。处理器701可以为现场可编程门阵列(英文全称:Field Programmable Gate Array,缩写:FPGA),或数字信号处理器(英文全称:Digital Signal Processor,缩写:DSP)等计算逻辑或以上任意计算逻辑的组合。处理器701也可以为单核处理器或多核处理器。
存储器705可以是随机存取存储器(Random Access Memory,RAM)、闪存、只读存储器(Read Only Memory,ROM)、可擦除可编程只读存储器(Erasable Programmable Read Only Memory,EPROM)、带电可擦可编程只读存储器(Electrically Erasable Programmable read only memory,EEPROM)、寄存器或者本领域熟知的任何其它形式的存储介质,存储器可以用于存储程序指令707,该程序指令707被处理器701执行时,处理器701执行上述实施例中的所述的方法。
连接线709用于在计算机装置的各部件之间传递信息,连接线709可以使用有线的连接方式或采用无线的连接方式,本申请并不对此进行限定。连接709还连接有网络接口704。
网络接口704使用例如但不限于电缆或电绞线一类的连接装置,来实现与其他设备或网络711之间的通信,网络接口704还可以通过无线的形式与网络711互连。
本申请实施例的一些特征可以由处理器701执行存储器705中的程序指令或者软件代码来完成/支持。存储器705上在加载的软件组件可以从功能或者逻辑上进行概括,例如,图15所示的建立模块1401、处理模块1402以及加载模块1403。
在本申请的一个实施例中,当存储器705加载程序指令后,处理器701执行存储器中的上述功能/逻辑模块相关的事务。
可选地,该计算机装置还可以包括辅助存储器702和输入/输出接口703,辅助存储器702用于辅助存储器705存储程序指令。输入/输出接口703用于与计算机装置700外部的设备进行交互,以获取外部设备输入的数据或向外部设备输出数据。
此外,图15仅仅是一个计算机装置700的例子,计算机装置700可能包含相比于图15展示的更多或者更少的组件,或者有不同的组件配置方式。同时,图15中展示的各种组件可以用硬件、软件或者硬件与软件的结合方式实施。例如,存储器和处理器可以在一个模块中实现,存储器中的指令可以是预先写入存储器的,也可以是后续处理器在执行的过程中加载的。
本申请实施例提供了一种计算机存储介质,所述存储介质内存储有计算机程序,所述计算机程序用于执行本申请提供的数据库的数据读写方法。
本申请实施例提供了一种包含指令的计算机程序产品,当计算机程序产品在计算机装置上运行时,使得计算机装置执行本申请实施例提供的任一数据读写方法。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现,所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机的可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者包含一个或多个可用介质集成的服务器、数据中心等数据存储装置。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带)、光介质,或者半导体介质(例如固态硬盘)等。
在本申请中,术语“第一”和“第二”等仅用于描述目的,而不能理解为指示或暗示相对重要性。术语“至少一个”指一个或多个,“多个”指两个或两个以上,除非另有明确的限定。
本申请实施例提供的方法实施例和装置实施例等不同类型的实施例均可以相互参考,本申请实施例对此不做限定。本申请实施例提供的方法实施例操作的先后顺序能够进行适当调整,操作也能够根据情况进行响应增减,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化的方法,都应涵盖在本申请的保护范围之内,因此不再赘述。
在本申请提供的相应实施例中,应该理解到,所揭露的装置等可以通过其它的构成方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性或其它的形式。
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元描述的部件可以是或者也可以不是物理单元,既可以位于一个地方,或者也可以分布到多个网络设备(例如终端设备)上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或 替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。

Claims (16)

  1. 一种数据库的数据读写方法,其特征在于,所述方法用于计算机装置,所述计算机装置包括多个节点,所述多个节点中的每个节点包括处理器和内存,所述方法包括:
    与客户端建立第一连接,其中,所述第一连接用于传输所述客户端发送的读写请求;
    确定与所述第一连接对应的第一表空间;
    确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点;
    加载所述第一表空间的数据至所述第一节点的内存中;
    使用第一工作线程对所述第一连接上的读写请求进行处理,其中,所述第一工作线程由所述第一节点中的处理器生成。
  2. 根据权利要求1所述的方法,其特征在于,确定与所述第一连接对应的第一表空间,包括:
    使用初始工作线程对所述第一连接上的读写请求进行响应,其中,所述初始工作线程运行在所述多个节点中的任一节点中;
    确定所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间;
    根据所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间确定与所述第一连接对应的第一表空间。
  3. 根据权利要求2所述的方法,其特征在于,所述根据所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间确定与所述第一连接对应的第一表空间,包括:
    将所述初始工作线程响应所述第一连接上的读写请求的过程中访问的第一个表空间,确定为所述第一表空间;或者,
    将所述初始工作线程响应所述第一连接上的读写请求的过程中,在预定时长内访问频率最高的表空间,确定为所述第一表空间。
  4. 根据权利要求2或3所述的方法,其特征在于,在所述使用第一工作线程对所述第一连接上的读写请求进行处理之前,所述方法还包括:
    确定所述初始工作线程位于所述第一节点之外的节点;
    将所述初始工作线程迁移至所述第一节点,其中,迁移后的所述初始工作线程为所述第一工作线程。
  5. 根据权利要求1至4任一所述的方法,其特征在于,所述确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点,包括:
    根据所述第一连接的特征,确定所述第一节点,其中,所述第一连接的特征包括所述客户端的网际互连协议IP地址、使用所述客户端的用户的名称或者所述第一连接对应的应用程序的名称。
  6. 根据权利要求1至4任一项所述的方法,其特征在于,在所述与客户端建立第一连接之前,所述方法还包括:
    创建所述第一表空间,其中,所述第一表空间携带第一标识符,所述第一标识符指示所述第一节点;
    所述确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点,包括:
    根据所述第一表空间携带的所述第一标识符确定所述第一节点。
  7. 根据权利要求6所述的方法,其特征在于,所述计算机装置包括第一线程池和第二线程池,所述第一线程池中的工作线程用于处理携带所述第一标识符的连接上的读写请求,所述第二线程池中的工作线程用于处理未携带标识符的连接上的读写请求,
    在所述确定所述多个节点中与所述第一连接或所述第一表空间对应的第一节点之后,所述方法还包括:
    使所述第一连接携带所述第一标识符。
  8. 一种数据库的数据读写装置,其特征在于,所述数据读写装置包括:
    建立模块,用于:与客户端建立第一连接,其中,所述第一连接用于传输所述客户端发送的读写请求;
    确定模块,用于:确定与所述第一连接对应的第一表空间;
    确定计算机装置的多个节点中与所述第一连接或所述第一表空间对应的第一节点,所述多个节点中的每个节点包括处理器和内存;
    处理模块,用于:加载所述第一表空间的数据至所述第一节点的内存中;
    使用第一工作线程对所述第一连接上的读写请求进行处理,其中,所述第一工作线程由所述第一节点中的处理器生成。
  9. 根据权利要求8所述的数据读写装置,其特征在于,
    所述确定模块用于:
    使用初始工作线程对所述第一连接上的读写请求进行响应,其中,所述初始工作线程运行在所述多个节点中的任一节点中;
    确定所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间;
    根据所述初始工作线程响应所述第一连接上的读写请求时所访问的表空间确定与所述第一连接对应的第一表空间。
  10. 根据权利要求9所述的数据读写装置,其特征在于,所述确定模块用于:
    将所述初始工作线程响应所述第一连接上的读写请求的过程中访问的第一个表空间,确定为所述第一表空间;或者,
    将所述初始工作线程响应所述第一连接上的读写请求的过程中,在预定时长内访问频率最高的表空间,确定为所述第一表空间。
  11. 根据权利要求9或10所述的数据读写装置,其特征在于,所述确定模块还用于:
    确定所述初始工作线程位于所述第一节点之外的节点;
    所述处理模块还用于:将所述初始工作线程迁移至所述第一节点,其中,迁移后的所述初始工作线程为所述第一工作线程。
  12. 根据权利要求8至11任一所述的数据读写装置,其特征在于,所述确定模块用于:
    根据所述第一连接的特征,确定所述第一节点,其中,所述第一连接的特征包括所述客户端的网际互连协议IP地址、使用所述客户端的用户的名称或者所述第一连接对应的应用程序的名称。
  13. 根据权利要求8至11任一项所述的数据读写装置,其特征在于,
    所述处理模块还用于:
    创建所述第一表空间,其中,所述第一表空间携带第一标识符,所述第一标识符指示所述第一节点;
    所述确定模块用于:
    根据所述第一表空间携带的所述第一标识符确定所述第一节点。
  14. 根据权利要求13所述的数据读写装置,其特征在于,所述计算机装置包括第一线程池和第二线程池,所述第一线程池中的工作线程用于处理携带所述第一标识符的连接上的读写请求,所述第二线程池中的工作线程用于处理未携带标识符的连接上的读写请求;
    所述处理模块还用于使所述第一连接携带所述第一标识符。
  15. 一种计算机装置,其特征在于,所述计算机装置包括:处理器和存储器,所述存储器中存储有程序,所述处理器用于调用所述存储器中存储的程序,以使得所述计算机装置执行如权利要求1至7任一项所述的数据库的数据读写方法。
  16. 一种计算机存储介质,其特征在于,所述存储介质内存储有计算机程序,当所述计算机程序在计算机装置上运行时,使所述计算机装置执行权利要求1至7任一项所述的数据库的数据读写方法。
PCT/CN2020/120216 2019-12-13 2020-10-10 数据库的数据读写方法及装置 WO2021114848A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP20899431.9A EP4057160A4 (en) 2019-12-13 2020-10-10 METHOD AND DEVICE FOR READING AND WRITING DATA FOR DATABASE
US17/837,496 US11868333B2 (en) 2019-12-13 2022-06-10 Data read/write method and apparatus for database

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN201911282832 2019-12-13
CN201911282832.6 2019-12-13
CN202010077018.7 2020-01-23
CN202010077018.7A CN111309805B (zh) 2019-12-13 2020-01-23 数据库的数据读写方法及装置

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/837,496 Continuation US11868333B2 (en) 2019-12-13 2022-06-10 Data read/write method and apparatus for database

Publications (1)

Publication Number Publication Date
WO2021114848A1 true WO2021114848A1 (zh) 2021-06-17

Family

ID=71161659

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/120216 WO2021114848A1 (zh) 2019-12-13 2020-10-10 数据库的数据读写方法及装置

Country Status (4)

Country Link
US (1) US11868333B2 (zh)
EP (1) EP4057160A4 (zh)
CN (1) CN111309805B (zh)
WO (1) WO2021114848A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111309805B (zh) * 2019-12-13 2023-10-20 华为技术有限公司 数据库的数据读写方法及装置
CN113704254B (zh) * 2021-07-30 2023-06-16 北京奇艺世纪科技有限公司 一种数据库的业务处理方法、装置、电子设备和存储介质
CN117076465B (zh) * 2023-10-16 2024-04-05 支付宝(杭州)信息技术有限公司 一种数据关联查询方法及相关设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150052214A1 (en) * 2011-12-28 2015-02-19 Beijing Qihoo Technology Company Limited Distributed system and data operation method thereof
CN106484311A (zh) * 2015-08-31 2017-03-08 华为数字技术(成都)有限公司 一种数据处理方法及装置
CN109460426A (zh) * 2018-11-05 2019-03-12 郑州云海信息技术有限公司 一种基于MongoDB的分级存储的系统及方法、路由节点
CN109889561A (zh) * 2017-12-25 2019-06-14 新华三大数据技术有限公司 一种数据处理方法及装置
CN111309805A (zh) * 2019-12-13 2020-06-19 华为技术有限公司 数据库的数据读写方法及装置

Family Cites Families (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5758345A (en) * 1995-11-08 1998-05-26 International Business Machines Corporation Program and method for establishing a physical database layout on a distributed processor system
US6272491B1 (en) * 1998-08-24 2001-08-07 Oracle Corporation Method and system for mastering locks in a multiple server database system
US7281206B2 (en) * 2001-11-16 2007-10-09 Timebase Pty Limited Maintenance of a markup language document in a database
US7665089B1 (en) * 2004-11-02 2010-02-16 Sun Microsystems, Inc. Facilitating distributed thread migration within an array of computing nodes
US8224828B2 (en) * 2009-12-22 2012-07-17 Sap Ag Multi-client generic persistence for extension fields
CN102831223A (zh) * 2012-08-23 2012-12-19 大唐移动通信设备有限公司 一种分布式数据库的管理方法和系统
JP5698865B2 (ja) * 2013-03-12 2015-04-08 株式会社東芝 データベースシステム、プログラムおよびデータ処理方法
WO2015169067A1 (en) * 2014-05-05 2015-11-12 Huawei Technologies Co., Ltd. Method, device, and system for peer-to-peer data replication and method, device, and system for master node switching
CN105260376B (zh) * 2015-08-17 2018-08-14 北京京东尚科信息技术有限公司 用于集群节点缩扩的方法、设备和系统
US10452655B2 (en) * 2015-10-23 2019-10-22 Oracle International Corporation In-memory cursor duration temp tables
CN105354319B (zh) * 2015-11-16 2019-01-25 天津南大通用数据技术股份有限公司 针对sn架构的mpp数据库集群的数据库连接池管理方法及系统
CN106815251B (zh) * 2015-11-30 2019-09-03 成都华为技术有限公司 分布式数据库系统、数据库访问方法及装置
US10235440B2 (en) * 2015-12-21 2019-03-19 Sap Se Decentralized transaction commit protocol
US9996432B2 (en) * 2016-02-03 2018-06-12 International Business Machines Corporation Automated local database connection affinity and failover
CN107229635B (zh) * 2016-03-24 2020-06-02 华为技术有限公司 一种数据处理的方法、存储节点及协调节点
US9948704B2 (en) * 2016-04-07 2018-04-17 International Business Machines Corporation Determining a best fit coordinator node in a database as a service infrastructure
CN106060004A (zh) * 2016-05-09 2016-10-26 深圳市永兴元科技有限公司 数据库访问方法及数据库代理节点
CN106339432A (zh) * 2016-08-19 2017-01-18 上海巨数信息科技有限公司 一种按查询内容进行负载均衡的系统及其方法
CN107016039B (zh) * 2017-01-06 2020-11-03 创新先进技术有限公司 数据库写入的方法和数据库系统
CN109241193B (zh) * 2018-09-26 2022-10-25 联想(北京)有限公司 分布式数据库的处理方法和装置,及服务器集群
CN110300188B (zh) * 2019-07-25 2022-03-22 中国工商银行股份有限公司 数据传输系统、方法和设备
CN110471977B (zh) * 2019-08-22 2022-04-22 杭州数梦工场科技有限公司 一种数据交换方法、装置、设备、介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150052214A1 (en) * 2011-12-28 2015-02-19 Beijing Qihoo Technology Company Limited Distributed system and data operation method thereof
CN106484311A (zh) * 2015-08-31 2017-03-08 华为数字技术(成都)有限公司 一种数据处理方法及装置
CN109889561A (zh) * 2017-12-25 2019-06-14 新华三大数据技术有限公司 一种数据处理方法及装置
CN109460426A (zh) * 2018-11-05 2019-03-12 郑州云海信息技术有限公司 一种基于MongoDB的分级存储的系统及方法、路由节点
CN111309805A (zh) * 2019-12-13 2020-06-19 华为技术有限公司 数据库的数据读写方法及装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4057160A4

Also Published As

Publication number Publication date
US11868333B2 (en) 2024-01-09
EP4057160A1 (en) 2022-09-14
EP4057160A4 (en) 2023-01-04
CN111309805B (zh) 2023-10-20
CN111309805A (zh) 2020-06-19
US20220300477A1 (en) 2022-09-22

Similar Documents

Publication Publication Date Title
WO2021114848A1 (zh) 数据库的数据读写方法及装置
US10771584B2 (en) Provisioning using pre-fetched data in serverless computing environments
US20170046375A1 (en) Workload balancing in a distributed database
WO2021254135A1 (zh) 任务执行方法及存储设备
US10523743B2 (en) Dynamic load-based merging
CN104102693A (zh) 对象处理方法和装置
US20090240911A1 (en) Information processing apparatus and informaiton processing method
US20150112934A1 (en) Parallel scanners for log based replication
CN111600957A (zh) 文件传输方法、装置、系统和电子设备
US8930518B2 (en) Processing of write requests in application server clusters
US10613992B2 (en) Systems and methods for remote procedure call
US20160378703A1 (en) Management of allocation for alias devices
US20180121474A1 (en) Database rebalancing method
US20200349081A1 (en) Method, apparatus and computer program product for managing metadata
CN109684270A (zh) 数据库归档方法、装置、系统、设备及可读存储介质
CN110781159B (zh) Ceph目录文件信息读取方法、装置、服务器及存储介质
CN115129621A (zh) 一种内存管理方法、设备、介质及内存管理模块
CN113535087A (zh) 数据迁移过程中的数据处理方法、服务器及存储系统
US10061725B2 (en) Scanning memory for de-duplication using RDMA
CN117762898A (zh) 数据迁移方法、装置、设备及存储介质
US20150149498A1 (en) Method and System for Performing an Operation Using Map Reduce
CN113407108A (zh) 一种数据存储方法和系统
US11977513B2 (en) Data flow control in distributed computing systems
WO2022199206A1 (zh) 用于虚拟机的内存共享方法及装置
WO2023040302A1 (zh) 一种升级进程的方法、装置、设备及存储介质

Legal Events

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

Ref document number: 20899431

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2020899431

Country of ref document: EP

Effective date: 20220607

NENP Non-entry into the national phase

Ref country code: DE