Database access method and device, equipment and medium
By using the sequential access method of the first-level caching module and the extended caching module during the database access process, the problem of introducing database cache middleware affecting database access performance is solved, and more efficient database access is achieved.
Patent Information
- Application Number
- CN202411744394.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-30
- Publication Date
- 2025-04-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The introduction of database cache middleware will affect the database access performance, increasing read and write burden and network latency.
A database access method is adopted, and cache operations are performed during database access through the first-level cache module and the extended cache module, and accessed in the order of the first-level cache module, the extended cache module and disk files, avoiding the introduction of middleware.
It improves the efficiency of database access, increases the hit probability of cache space, reduces IO operations, and solves the problem that middleware affects database access performance.
Smart Images

Figure CN119829623A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to data processing technology, and specifically to a method, apparatus, device and medium for accessing a database. Background Art
[0002] Database caching technology is a technology that temporarily stores part of the data in the database in a cache component to improve data access speed and performance. At present, database caching is mainly implemented through database cache middleware, and existing database cache middleware includes: Memcached, Redis, and Ehcache. However, the introduction of database cache middleware will cause the access process to the database to change from one thread to two threads, thereby affecting the access performance of the database, for example: increasing the read and write burden of the database, or increasing the network delay of accessing the distributed data database. Summary of the invention
[0003] The embodiments of the present application provide a method, apparatus, device and medium for accessing a database to solve the technical problem that the introduction of database cache middleware affects the access performance of the database.
[0004] In a first aspect, an embodiment of the present application provides a method for accessing a database, the method comprising:
[0005] receiving a database access request;
[0006] According to the database access request, access operations are performed in the order of the primary cache module, the extended cache module, and the disk file;
[0007] The first-level cache module is used to cache multiple first data pages, where the first data pages are data pages in a database;
[0008] The extended cache module is used to cache multiple second data pages, where the second data pages are data pages in the database, and the heat of the second data pages is less than the heat of the first data pages;
[0009] The disk file is used to store all data pages of the database.
[0010] In a second aspect, an embodiment of the present application provides a database access device, the device comprising:
[0011] A receiving module, used for receiving a database access request;
[0012] An operation module, used to perform access operations in the order of the primary cache module, the extended cache module and the disk file according to the database access request;
[0013] The first-level cache module is used to cache multiple first data pages, where the first data pages are data pages in a database;
[0014] The extended cache module is used to cache multiple second data pages, where the second data pages are data pages in the database, and the heat of the second data pages is less than the heat of the first data pages;
[0015] The disk file is used to store all data pages of the database.
[0016] In a third aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any embodiment of the first aspect.
[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any embodiment of the first aspect.
[0018] The database access method, device, equipment and medium provided in the embodiment of the present application include two cache modules-a first-level cache module and an extended cache module. In the process of accessing the database, according to the database access request, the access operation can be performed in the order of the first-level cache module, the extended cache module and the disk file, so that the access operation can be performed in the first-level cache module first. If the first-level cache module does not hit, it is performed in the extended cache module, and finally in the disk file. The two cache modules provide a larger cache space, so that the hit probability of the database access operation in the cache module is higher, thereby improving the efficiency of accessing the database. Since the technical solution provided in the embodiment of the present application can achieve the purpose of improving the database access efficiency only through two cache modules, there is no need to introduce any database cache middleware, and the database access operation only needs one thread to complete, which solves the technical problem that the introduction of database cache middleware affects the access performance of the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0020] Figure 1 is a flowchart of an embodiment of a method for accessing a database of the present application;
[0021] Figure 2 yes Figure 1 One of the flowcharts of step 102 of the method for accessing the database of the present application is shown;
[0022] Figure 3 yes Figure 1 The second flowchart of step 102 of the method for accessing the database of the present application is shown;
[0023] Figure 4 yes Figure 1 A flowchart of a method for eliminating data pages from a primary cache module in the database access method of the present application is shown;
[0024] Figure 5 It is a structural diagram of an embodiment of a database access device of the present application;
[0025] Figure 6 It is a schematic diagram of the structure of an electronic device used to implement an embodiment of the present application. DETAILED DESCRIPTION
[0026] All actions to obtain signals, information or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where they are located, and with the authorization given by the owner of the corresponding device.
[0027] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It should also be noted that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0028] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0029] The database access method, apparatus, device and medium proposed in the embodiments of the present application can be applied in the process of accessing the database.
[0030] In this embodiment, the types of databases include, but are not limited to, relational database management system MySQL (MyStructured Query Language) and object-relational database management system PostgreSQL.
[0031] In this embodiment, the database may be a centralized database or a distributed cluster database. In order to enable those skilled in the art to more clearly understand the technical solution provided by the embodiment of the present application, in the following embodiments, only the distributed cluster database is used as an example for explanation.
[0032] In this embodiment, the database architecture in the form of a distributed cluster includes:
[0033] 1. Master
[0034] The number of master nodes is usually 1.
[0035] The master node is mainly responsible for processing the client's write requests and will record the write operations in the redo log to ensure the persistence and consistency of the data. The data may be copied to the slave node to achieve high data availability and load balancing.
[0036] 2. Slave
[0037] The number of slave nodes is usually multiple, and the specific number is set according to actual usage requirements.
[0038] The slave node is usually responsible for processing the client's read requests, receiving data replication from the master node, and keeping the data synchronized with the master node, providing high availability and scalability of read operations.
[0039] 3. Computation Layer
[0040] The computing layer is the part of the cluster responsible for processing requests and performing computing tasks. It includes a computing node that is responsible for processing all read and write requests and generating corresponding redo logs based on the operations.
[0041] 4. Storage Layer
[0042] The storage layer is the part of the cluster responsible for data storage and persistence, including multiple storage nodes. The main task of the storage node is to provide the required data to the computing node and complete the data persistence.
[0043] 5. Computation Node
[0044] Compute node is the core component in the computing layer, responsible for processing all read and write requests, interacting with the storage layer according to the operation type (read or write), reading or writing data, and generating redo logs to ensure data consistency and recovery capabilities.
[0045] 6. Storage Node
[0046] The storage node is the core component in the storage layer, responsible for data storage and persistence, receiving data requests from computing nodes and providing the required data. It can also receive data replication from the master node to keep the data of the slave node synchronized with the master node.
[0047] In the above-mentioned distributed cluster database architecture, depending on the specific implementation and configuration, the master node may only include computing nodes, and the slave node may only include storage nodes; or, the master node and the slave node may both include computing nodes and storage nodes to provide more flexible data processing and storage capabilities. In order to enable those skilled in the art to more clearly understand the technical solutions provided in the embodiments of the present application, in the following embodiments, only the example of the master node and the slave node both including computing nodes and storage nodes is used for explanation.
[0048] In this embodiment, the database architecture in the form of a distributed cluster also includes: a cache system.
[0049] In this embodiment, the cache system may include: a first-level cache module and a second-level cache module.
[0050] The first-level cache module is used to cache multiple first data pages, where the first data pages are data pages in the database.
[0051] The secondary cache module is used to cache multiple second data pages, where the second data pages are data pages in the database, and the heat of the second data pages is lower than the heat of the first data pages.
[0052] It should be noted that, in this embodiment, the first data page is a general term for the data pages cached in the first-level cache module, and the number of first data pages cached in the first-level cache module is set according to the capacity of the first-level cache module.
[0053] Similarly, in this embodiment, the second data page is a general term for the data pages cached in the extended cache module, and the number of the second data pages cached in the extended cache module is set according to the capacity of the extended cache module.
[0054] In this embodiment, the first data page cached in the primary cache module is a data page with high popularity in the database; the second data page cached in the extended cache module is a data page with secondary popularity in the database.
[0055] In this embodiment, methods for determining the heat of data pages in the database include, but are not limited to, access counting method, time window method, and least recently used algorithm (Least Recently Used, LRU), etc.
[0056] In this embodiment, the second data page stored in the extended cache module can be managed and controlled by the LRU linked list; and / or the first data page stored in the first-level cache module can be managed and controlled by the LRU linked list.
[0057] In this embodiment, the first-level cache module can be set in the memory of the device. Taking the master node as an example, the first-level cache module can be set in the memory of the device deployed in the master node.
[0058] In order to avoid the problem of insufficient cache space allocated to the extended cache module due to the limited memory capacity of the device, in this embodiment, the extended cache module is established on a solid-state drive. Among them, the solid-state drive can be a solid-state drive built into the device, or a solid-state drive external to the device. This embodiment does not limit the specific type and size of the solid-state drive. For example, the solid-state drive can be a non-volatile memory host controller interface specification (Non-Volatile Memory Express, NVMe) type, and each case will not be described one by one here.
[0059] Optionally, in order to dynamically adjust the capacity of the primary cache module and the extended cache module, reduce lock contention in the cache system, and reduce performance consumption caused by waiting between operations, in this embodiment, the cache system may further include: a cache system control module.
[0060] The cache system control module is used to control the primary cache module and the extended cache module according to the load size. The control includes partition control and configuration of cache size.
[0061] Optionally, in order to ensure that the second data pages stored in the extended cache module are all of a certain popularity, in this embodiment, the cache system may further include: a cache filtering module.
[0062] The cache filtering module is used to filter the data pages entering the extended cache module to determine whether the data pages can be stored in the extended cache module. In this embodiment, the cache filtering module can filter the data pages entering the extended cache module by the above-mentioned method for determining the heat of data pages in the database.
[0063] The database and cache system provided in the above-mentioned embodiment of the present application are of integrated design, have no inherent limitations, and will not affect the access performance of the database.
[0064] Based on the database provided by the embodiments of the present application described above, please refer to Figure 1 , which shows a process 100 of an embodiment of a method for accessing a database according to the present application. The method for accessing a database can be applied to various electronic devices with data processing functions. For example, the electronic devices may include but are not limited to cloud servers, physical servers, etc. The execution subject of the automatic discovery method of topological relationships may be a processor in the electronic devices.
[0065] like Figure 1 As shown, the method for accessing the database includes the following steps:
[0066] Step 101: Receive a database access request.
[0067] In this embodiment, the database access request may include: a data page read request and a data write request, etc. In actual use, the database access request may also be other read / write requests, which will not be described one by one here.
[0068] Step 102: According to the database access request, access operations are performed in the order of the primary cache module, the extended cache module, and the disk file.
[0069] In this embodiment, when the database access request is a request to read a data page, Figure 2 As shown, step 102 may include:
[0070] Step 201: Determine a first target data page to be read according to a data page read request.
[0071] Step 202: query the first-level cache module to obtain a first query result.
[0072] Step 203: When the first query result indicates that the first target data page exists in the first data page, the first target data page is returned.
[0073] In this embodiment, step 203 of returning the first target data page specifically includes: returning the first target data page to an upper system, wherein the upper system is a system that sends a request to read the data page.
[0074] Step 204: When the first query result is that the first target data page does not exist in the first data page, query the extended cache module to obtain a second query result.
[0075] In this embodiment, the method for querying the extended cache module can be: based on a zipper-type hash table, using a one-way linked list and adopting a head-insertion method. This method can achieve the purpose of quickly obtaining data pages in the extended cache module.
[0076] Of course, the above method of querying the extended cache module is only a specific example. In actual use, other methods may also be used, and each case will not be described one by one here.
[0077] Step 205: When the second query result indicates that the first target data page exists in the second data page, the first target data page is returned and cached in the first-level cache module.
[0078] In this embodiment, the purpose of caching the first target data page into the first-level cache module in step 205 is to ensure that the first data pages stored in the first-level cache module are all hot data pages, so as to achieve the purpose of quickly hitting the first-level cache in the process of accessing the database, thereby improving the access efficiency of the database.
[0079] Step 206: When the second query result is that the first target data page does not exist in the second data page, query the disk file, obtain the first target data page from the disk file, return the first target data page, and cache the first target data page in the first-level cache module.
[0080] In this embodiment, the disk file is used to store all data pages of the database. In step 206, when both the primary cache module and the extended cache module do not hit, IO search is performed in the disk file, which can effectively reduce the IO operation of the database access method provided in the embodiment of the present application, thereby improving the access efficiency of the database.
[0081] In this embodiment, when the database access request is a write data request, Figure 3 As shown, step 102 may include:
[0082] Step 301: Determine data to be written according to a data write request.
[0083] In this embodiment, the write data request may carry not only the data to be written but also the following contents:
[0084] Transaction identifier, used to track and manage the execution process of the transaction.
[0085] The operation type, which indicates whether it is an insert (INSERT), update (UPDATE), or delete (DELETE) operation.
[0086] Data location, used to specify the location of data, such as table name, row identifier, or conditional expression.
[0087] Data formats and types are used to ensure that data can be interpreted and stored correctly.
[0088] Permission and security information, which is used to verify the user identity and permissions of the write operation to ensure the security of the operation.
[0089] Log information, used to record detailed changes of transactions.
[0090] Timestamps or version numbers are used to resolve transaction conflicts and consistency issues in concurrency control.
[0091] Batch information is used to manage the order and dependencies of multiple operations when a write request contains multiple operations.
[0092] Lock information is used in some database systems to ensure the consistency of data when it is modified.
[0093] Rollback and recovery information is used to undo the operations that have been performed if the write operation fails, and recovery information is used to restore to a normal state.
[0094] Performance monitoring information, additional information for performance monitoring and optimization.
[0095] Step 302: query the first-level cache module to obtain the third query result.
[0096] In this embodiment, step 302 can query the first-level cache module through the relevant content carried in the write data request described in step 301, such as data location, etc., to obtain the third query result.
[0097] Step 303: When the third query result is that the second target data page exists in the first data page, the second target data page is modified using the data to be written to obtain a modified second target data page, and the modified second target data page is used to replace the second target data page in the first-level cache module, wherein the second target data page is used to store the data to be written.
[0098] Step 304: When the third query result is that the second target data page does not exist in the first data page, query the extended cache module to obtain a fourth query result.
[0099] In this embodiment, the method for querying the extended cache module can be: based on a zipper-type Hash table, using a one-way linked list and adopting a head-insertion method. This method can achieve the purpose of quickly obtaining data pages in the extended cache module.
[0100] Of course, the above method of querying the extended cache module is only a specific example. In actual use, other methods may also be used, and each case will not be described one by one here.
[0101] Step 305: When the fourth query result is that the second target data page exists in the second data page, the second target data page is modified using the data to be written to obtain a modified second target data page, the modified second target data page is used to replace the second target data page in the extended cache module, and the modified second target data page is cached in the first-level cache module.
[0102] Step 306: When the fourth query result is that the second target data page does not exist in the second data page, query the disk file, obtain the second target data page from the disk file, modify the second target data page with the data to be written, obtain the modified second target data page, and cache the modified second target data page in the extended cache module.
[0103] In this embodiment, the first-level cache module may need to eliminate part of the first data page, for example: Figure 2In step 205, when caching the first target data page to the first-level cache module, if the first-level cache module is full, it is necessary to eliminate part of the first data page to release cache space for caching the first target data page. At this time, the database access method provided by the embodiment of the present application may also include a method for eliminating data pages from the first-level cache module, such as Figure 4 As shown, the method may include the following steps:
[0104] Step 401: When there are data pages to be eliminated in the first data page, the query extension cache module obtains the fifth query result.
[0105] Step 402: When the fifth query result indicates that there is no data page to be eliminated in the second data page, the data page to be eliminated is eliminated in the first-level cache module.
[0106] Step 403: When the fifth query result is that there are data pages to be eliminated in the second data page, if the data pages to be eliminated in the second data page have the same version as the data pages to be eliminated in the first data page, the data pages to be eliminated are eliminated in the first-level cache module; otherwise, the data pages to be eliminated in the second data page are replaced with the data pages to be eliminated in the first data page, and then the data pages to be eliminated are eliminated in the first-level cache module.
[0107] In this embodiment, after the to-be-eliminated data page in the first data page is used to replace the to-be-eliminated data page in the second data page, a dirty page mark can be set for the replaced data page. After the operation is completed, the data page marked as a dirty page will be asynchronously persisted to the lower storage system (disk file) by the dirty flushing thread of the buffer pool.
[0108] pass Figure 4 The method for eliminating data pages from the first-level cache module shown in the figure, when the data page in the extended cache has not been replaced with the latest version, the upper system can obtain the latest version of the data page from the first-level cache, and does not need to obtain the data page from the extended cache. At this time, even if the data page in the extended cache is not the latest version, it will not have any impact on the system's work of obtaining data pages. After the operation of asynchronous replacement of dirty pages, the data pages read from the extended cache will all be the latest version. The above method provides a guarantee for data consistency.
[0109] The database access method provided by the embodiment of the present application includes two cache modules, namely, a first-level cache module and an extended cache module. In the process of accessing the database, according to the database access request, the access operation can be performed in the order of the first-level cache module, the extended cache module and the disk file, so that the access operation can be performed in the first-level cache module first. If the first-level cache module does not hit, it is performed in the extended cache module, and finally in the disk file. The two cache modules provide a larger cache space, so that the hit probability of the database access operation in the cache module is higher, thereby improving the efficiency of accessing the database. Since the technical solution provided by the embodiment of the present application can achieve the purpose of improving the database access efficiency only through two cache modules, there is no need to introduce any database cache middleware, and the database access operation only needs one thread to complete, which solves the technical problem that the introduction of database cache middleware affects the access performance of the database.
[0110] like Figure 5 As shown, the database access device 500 of this embodiment includes:
[0111] Receiving module 501, used for receiving a database access request;
[0112] An operation module 502 is used to perform an access operation in the order of a primary cache module, an extended cache module, and a disk file according to the database access request;
[0113] The first-level cache module is used to cache multiple first data pages, where the first data pages are data pages in a database;
[0114] The extended cache module is used to cache multiple second data pages, where the second data pages are data pages in the database, and the heat of the second data pages is less than the heat of the first data pages;
[0115] The disk file is used to store all data pages of the database.
[0116] Optionally, the operation module 502 is specifically used to determine the first target data page to be read according to the read data page request when the database access request is a read data page request; query the first-level cache module to obtain a first query result; when the first query result is that the first target data page exists in the first data page, return the first target data page; when the first query result is that the first target data page does not exist in the first data page, query the extended cache module to obtain a second query result; when the second query result is that the first target data page exists in the second data page, return the first target data page and cache the first target data page in the first-level cache module; when the second query result is that the first target data page does not exist in the second data page, query the disk file, obtain the first target data page from the disk file, return the first target data page, and cache the first target data page in the first-level cache module.
[0117] Optionally, the operation module 502 is specifically used to, when the database access request is a write data request, determine the data to be written according to the write data request; query the first-level cache module to obtain a third query result; when the third query result is that the second target data page exists in the first data page, use the data to be written to modify the second target data page to obtain a modified second target data page, and use the modified second target data page to replace the second target data page in the first-level cache module, wherein the second target data page is used to store the data to be written; when the third query result is that the second target data page does not exist in the first data page, query the extended cache module to obtain a fourth query result; in the fourth When the query result is that the second target data page exists in the second data page, the second target data page is modified using the data to be written to obtain the modified second target data page, the modified second target data page is used to replace the second target data page in the extended cache module, and the modified second target data page is cached in the first-level cache module; when the fourth query result is that the second target data page does not exist in the second data page, the disk file is queried, the second target data page is obtained from the disk file, the second target data page is modified using the data to be written to obtain the modified second target data page, and the modified second target data page is cached in the extended cache module.
[0118] Optionally, operation module 502 can also be used to query the extended cache module to obtain a fifth query result when there is a data page to be eliminated in the first data page; to eliminate the data page to be eliminated in the first-level cache module when the fifth query result is that the data page to be eliminated does not exist in the second data page; and to eliminate the data page to be eliminated in the second data page if the fifth query result is that the data page to be eliminated exists in the second data page, if the data page to be eliminated in the second data page has the same version as the data page to be eliminated in the first data page, the data page to be eliminated in the first-level cache module; otherwise, the data page to be eliminated in the second data page is replaced with the data page to be eliminated in the first data page, and then the data page to be eliminated in the first-level cache module.
[0119] Optionally, the method for querying the extended cache module is: based on a zipper-type hash table implementation, using a one-way linked list with a head-insertion method.
[0120] Optionally, the second data page stored in the extended cache module is managed and controlled by a least recently used algorithm LRU linked list.
[0121] Optionally, the extended cache module is established on a solid state drive.
[0122] The database access device provided in the embodiment of the present application includes two cache modules, namely, a first-level cache module and an extended cache module. In the process of accessing the database, according to the database access request, the access operation can be performed in the order of the first-level cache module, the extended cache module and the disk file, so that the access operation can be performed in the first-level cache module first. If the first-level cache module does not hit, it is performed in the extended cache module, and finally in the disk file. The two cache modules provide a larger cache space, so that the hit probability of the database access operation in the cache module is higher, thereby improving the efficiency of accessing the database. Since the technical solution provided in the embodiment of the present application can achieve the purpose of improving the database access efficiency only through two cache modules, there is no need to introduce any database cache middleware, and the database access operation only needs one thread to complete, which solves the technical problem that the introduction of database cache middleware affects the access performance of the database.
[0123] Reference below Figure 6 , which shows a schematic structural diagram of an electronic device for implementing some embodiments of the present application. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0124] like Figure 6As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0125] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a disk, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 4 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0126] In particular, according to some embodiments of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, some embodiments of the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In some such embodiments, the computer program can be downloaded and installed from the network through the communication device 609, or installed from the storage device 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of some embodiments of the present application are executed.
[0127] It should be noted that the computer-readable medium described in some embodiments of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In some embodiments of the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In some embodiments of the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0128] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0129] The computer-readable medium may be included in the electronic device; or it may exist independently without being assembled into the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: receives a database access request; performs access operations in the order of the primary cache module, the extended cache module, and the disk file according to the database access request; the primary cache module is used to cache multiple first data pages, the first data pages are data pages in the database; the extended cache module is used to cache multiple second data pages, the second data pages are data pages in the database, and the heat of the second data pages is less than the heat of the first data page; the disk file is used to store all data pages of the database.
[0130] Computer program code for performing the operations of some embodiments of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++; and also conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, or may be connected to an external computer (e.g., through the Internet using an Internet service provider), including a local area network (LAN) or a wide area network (WAN).
[0131] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0132] The units described in some embodiments of the present application may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor includes a first determination unit, a second determination unit, a selection unit, and a third determination unit. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0133] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0134] The above description is only some preferred embodiments of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present application is not limited to the technical solutions formed by the specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with (but not limited to) the technical features with similar functions disclosed in the embodiments of the present application to form a technical solution.
Claims
1. A method for accessing a database, characterized in that: The method comprises: receiving a database access request; According to the database access request, access operations are performed in the order of the primary cache module, the extended cache module, and the disk file; The first-level cache module is used to cache multiple first data pages, where the first data pages are data pages in a database; The extended cache module is used to cache multiple second data pages, where the second data pages are data pages in the database, and the heat of the second data pages is less than the heat of the first data pages; The disk file is used to store all data pages of the database.
2. The method according to claim 1, characterized in that In the case where the database access request is a request to read a data page, performing the access operation in the order of the primary cache module, the extended cache module, and the disk file according to the database access request includes: Determining a first target data page to be read according to the data page read request; Query the first-level cache module to obtain the first query result; If the first query result is that the first target data page exists in the first data page, returning the first target data page; When the first query result is that the first target data page does not exist in the first data page, query the extended cache module to obtain a second query result; If the second query result is that the first target data page exists in the second data page, returning the first target data page, and caching the first target data page in the first-level cache module; When the second query result is that the first target data page does not exist in the second data page, query the disk file, obtain the first target data page from the disk file, return the first target data page, and cache the first target data page in the first-level cache module.
3. The method according to claim 1, characterized in that In the case where the database access request is a data write request, performing the access operation in the order of the primary cache module, the extended cache module, and the disk file according to the database access request includes: Determining data to be written according to the write data request; Query the first-level cache module to obtain the third query result; If the third query result is that the second target data page exists in the first data page, modify the second target data page using the data to be written to obtain a modified second target data page, and replace the second target data page in the first-level cache module with the modified second target data page, wherein the second target data page is used to store the data to be written; When the third query result is that the second target data page does not exist in the first data page, query the extended cache module to obtain a fourth query result; If the fourth query result is that the second target data page exists in the second data page, modify the second target data page using the data to be written to obtain the modified second target data page, replace the second target data page in the extended cache module with the modified second target data page, and cache the modified second target data page in the first-level cache module; When the fourth query result is that the second target data page does not exist in the second data page, query the disk file, obtain the second target data page from the disk file, modify the second target data page using the data to be written, obtain the modified second target data page, and cache the modified second target data page in the extended cache module.
4. The method according to claim 1, characterized in that: The method further comprises: In the case where there are data pages to be eliminated in the first data pages, querying the extended cache module to obtain a fifth query result; If the fifth query result is that the to-be-eliminated data page does not exist in the second data page, evicting the to-be-eliminated data page in the first-level cache module; In the case where the fifth query result is that the data page to be eliminated exists in the second data page, if the data page to be eliminated in the second data page is the same version as the data page to be eliminated in the first data page, the data page to be eliminated in the first-level cache module; otherwise, the data page to be eliminated in the second data page is replaced by the data page to be eliminated in the first-level cache module.
5. The method according to any one of claims 2 to 4, characterized in that: The method for querying the extended cache module is: based on the zipper-type hash table implementation, using a one-way linked list with a head-insertion method.
6. The method according to claim 1, characterized in that The second data page stored in the extended cache module is managed and controlled by a least recently used algorithm LRU linked list.
7. The method according to claim 1, characterized in that The extended cache module is established on the solid state drive.
8. A database access device, characterized in that: The device comprises: A receiving module, used for receiving a database access request; An operation module, used to perform access operations in the order of the primary cache module, the extended cache module and the disk file according to the database access request; The first-level cache module is used to cache multiple first data pages, where the first data pages are data pages in a database; The extended cache module is used to cache multiple second data pages, where the second data pages are data pages in the database, and the heat of the second data pages is less than the heat of the first data pages; The disk file is used to store all data pages of the database.
9. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Data caching method and apparatus
CN105447171A
Data caching method and device, electronic equipment and computer readable medium
CN112948286A