Secondary cache method, apparatus, system, electronic device, and storage medium

By employing a two-level caching method in a distributed system and using message queue middleware to set up local and central cache units in parallel, the problem of data inconsistency between master and slave nodes is solved, thereby improving data consistency and system stability.

CN115481050BActive Publication Date: 2026-11-24HANGZHOU DBAPPSECURITY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211150746.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-21
Publication Date
2026-11-24
Estimated Expiration
2042-09-21

AI Technical Summary

Technical Problem

During the massive data interaction between a large number of distributed nodes and a high-performance distributed master node, high-concurrency queries of hot data can cause excessive pressure on the database, even leading to system crashes. Furthermore, the problem of data inconsistency between master and slave nodes has not been effectively solved in existing technologies.

Method used

A two-level caching method is adopted, in which the data to be processed is sent to the local cache unit of the distributed slave node and the central cache unit of the distributed master node through the message queue middleware. The local cache unit and the central cache unit are set in parallel to ensure that the message queue data is retrieved again for caching processing when caching processing fails.

Benefits of technology

It improves data consistency between master and slave nodes in a distributed system, enhances cache utilization efficiency and system stability, reduces database pressure, and avoids data loss and inconsistency issues.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115481050B_ABST
    Figure CN115481050B_ABST
Patent Text Reader

Abstract

This application relates to a two-level caching method, apparatus, system, electronic device, and storage medium. The two-level caching method includes: acquiring data to be processed and sending the data to a message queue middleware to obtain message queue data; performing caching processing on a local cache unit based on the message queue data; and, if the local cache unit's caching processing fails, reacquiring the message queue data and sending it to the local cache unit; performing caching processing on a central cache unit based on the message queue data; and, if the central cache unit's caching processing fails, reacquiring the message queue data and sending it to the central cache unit; wherein the first cache unit and the central cache unit are connected in parallel. This application solves the problem of data inconsistency between master and slave nodes, improving the consistency of first- and second-level cache data storage in distributed systems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and in particular to methods, apparatus, systems, electronic devices, and storage media for secondary caching. Background Technology

[0002] During the process of massive data interaction between a large number of distributed nodes and a high-performance distributed master node, some hot data is frequently accessed, causing high-concurrency queries on the database, which puts great pressure on the database and may even cause it to crash and affect its use.

[0003] To accommodate access to frequently accessed data and reduce database pressure, Redis is typically used for caching. This Redis cache is then used to update the local data cache and the database. During access, the local data cache is checked first; if the data is not found there, the database is queried, thus improving access speed and reducing database load. However, this approach of using Redis to cache data and then update the local cache and database is susceptible to data loss if either the database master node or the local slave node fails, leading to data inconsistency between the master and slave nodes.

[0004] There is currently no effective solution to the problem of inconsistent data between master and slave nodes in related technologies. Summary of the Invention

[0005] This embodiment provides a two-level caching method, apparatus, system, electronic device, and storage medium to solve the problem of data inconsistency between master and slave nodes in related technologies.

[0006] Firstly, this embodiment provides a two-level caching method, including:

[0007] Obtain the data to be processed, and send the data to the message queue middleware to obtain message queue data;

[0008] The message queue data is used to cache the local cache unit in the distributed slave node. If the local cache unit fails to cache the data, the message queue data is retrieved again and sent to the local cache unit.

[0009] The central cache unit in the distributed master node is cached synchronously according to the message queue data. If the central cache unit fails to cache the data, the message queue data is retrieved again and sent to the central cache unit. The local cache unit is connected in parallel with the central cache unit.

[0010] In some embodiments, there is at least one local cache unit, and each local cache unit corresponds one-to-one with a distributed slave node; the caching process of the local cache unit based on the message queue data includes:

[0011] The message queue data is simultaneously sent to all the distributed slave nodes, and the distributed slave nodes synchronously cache the local cache unit according to the message queue data.

[0012] In some embodiments, the data to be processed includes database business data, and the message queue data includes database message queue data; sending the data to be processed to the message queue middleware to obtain message queue data includes:

[0013] Obtain the corresponding binlog logs based on the database business data, and send the binlog logs to Canal to obtain database encapsulated data;

[0014] The database encapsulated data is sent to the message queue middleware to obtain the database message queue data.

[0015] In some embodiments, the caching process of the local cache unit based on the message queue data and the caching process of the central cache unit based on the message queue data include:

[0016] The local cache unit and the central cache unit are cached according to the data processing type of the database message queue data; wherein, the data processing type includes adding data type, updating data type, and deleting data type.

[0017] In some embodiments, the data to be processed further includes non-database business data, and the message queue data includes non-database message queue data; the step of sending the data to be processed to the message queue middleware to obtain message queue data includes:

[0018] The non-database business data is encapsulated to obtain non-database encapsulated data, which is then sent to the message queue middleware to obtain the non-database message queue data.

[0019] In some embodiments, sending the data to be processed to the message queue middleware to obtain message queue data includes:

[0020] Obtain the specific topic corresponding to the data to be processed in the message queue middleware, send the data to be processed to the specific topic, and obtain the message queue data.

[0021] Secondly, this embodiment provides a two-level caching device, including: a forwarding module, a first-level caching module, and a second-level caching module;

[0022] The forwarding module is used to obtain the data to be processed and send the data to be processed to the message queue middleware to obtain message queue data;

[0023] The first-level cache module is used to cache the local cache unit in the distributed slave node according to the message queue data, and if the local cache unit fails to cache, it will re-acquire the message queue data and send it to the local cache unit.

[0024] The secondary cache module is used to synchronously cache the central cache unit in the distributed master node according to the message queue data. If the central cache unit fails to cache the data, it will reacquire the message queue data and send it to the central cache unit. The local cache unit is connected in parallel with the central cache unit.

[0025] Thirdly, this embodiment provides a two-level caching system, characterized in that it includes: a distributed master node and distributed slave nodes; wherein the distributed master node is connected to the distributed slave nodes through a transmission device;

[0026] The distributed master node is used to execute the second-level caching method described in the first aspect above;

[0027] The transmission device is used to send message queue data to the distributed slave node;

[0028] The distributed slave node is used to obtain the message queue data and perform caching processing on the local cache unit based on the message queue data.

[0029] Fourthly, this embodiment provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the secondary cache method described in the first aspect above.

[0030] Fourthly, this embodiment provides a storage medium on which a computer program is stored, which, when executed by a processor, implements the secondary cache method described in the first aspect above.

[0031] Compared with related technologies, the secondary caching method, apparatus, system, electronic device, and storage medium provided in this embodiment obtains data to be processed, sends the data to be processed to a message queue middleware to obtain message queue data; performs caching processing on the local cache unit in the distributed slave node according to the message queue data, and if the local cache unit fails to perform caching processing, re-obtains the message queue data and sends it to the local cache unit; and synchronously performs caching processing on the central cache unit in the distributed master node according to the message queue data, and if the central cache unit fails to perform caching processing, re-obtains the message queue data and sends it to the central cache unit. The local cache unit and the central cache unit are connected in parallel, which solves the problem of data inconsistency between master and slave nodes and improves the consistency of primary and secondary cache data storage in the distributed system's master and slave nodes.

[0032] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description

[0033] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0034] Figure 1 This is a diagram illustrating an application scenario of a two-level caching method in one embodiment.

[0035] Figure 2 This is a flowchart illustrating a second-level caching method in one embodiment;

[0036] Figure 3 This is a flowchart illustrating a second-level caching method in another embodiment;

[0037] Figure 4 This is a structural block diagram of a secondary cache device in one embodiment;

[0038] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0039] To better understand the purpose, technical solution, and advantages of this application, the application is described and illustrated below in conjunction with the accompanying drawings and embodiments.

[0040] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning as understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these,” used in this application, do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to such processes, methods, products, or devices. The terms “connected,” “linked,” and “coupled,” used in this application, are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. The term “multiple” used in this application refers to two or more. The "and / or" operator describes the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: A alone, A and B simultaneously, and B alone. Typically, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," and "third," etc., used in this application are merely for distinguishing similar objects and do not represent a specific ordering of the objects.

[0041] The two-level caching method provided in this application can be applied to, for example... Figure 1 In the application environment shown, distributed slave node 102 communicates with distributed master node 104 via a network. Distributed master node 104 obtains data to be processed and sends it to a message queue middleware to obtain message queue data. Distributed master node 104 performs caching processing on the local cache unit in the distributed slave node based on the message queue data. If the local cache unit fails to process the data, it re-obtains the message queue data and sends it to the local cache unit. Distributed master node 104 synchronously performs caching processing on the central cache unit in the distributed master node based on the message queue data. If the central cache unit fails to process the data, it re-obtains the message queue data and sends it to the central cache unit. The local cache unit and the central cache unit are connected in parallel. Distributed slave node 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. Distributed master node 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.

[0042] This embodiment provides a two-level caching method. Figure 2 This is a flowchart of the second-level caching method in this embodiment, as follows: Figure 2 As shown, the process includes the following steps:

[0043] Step S202: Obtain the data to be processed and send it to the message queue middleware to obtain message queue data. The data to be processed refers to data that needs to be cached at level two. The message queue middleware can be ActiveMQ, RabbitMQ, RocketMQ, or Kafka; preferably, it is Kafka. Specifically, obtain the data to be processed, encapsulate it to obtain encapsulated data, and send the encapsulated data to the topic of the message queue middleware.

[0044] Step S204: The local cache unit in the distributed slave node is cached according to the message queue data. If the local cache unit fails to cache the data, the message queue data is retrieved again and sent to the local cache unit. Here, the local cache unit refers to a local cache that can reduce IO overhead, such as Guava and Caffeine. Preferably, the local cache unit is the Caffeine cache unit of the Java 8 high-performance caching library.

[0045] Step S206: Based on the message queue data, the central cache unit in the distributed master node is cached synchronously. If the central cache unit fails to cache, the message queue data is retrieved again and sent to the central cache unit. The local cache unit is connected in parallel with the central cache unit. The central cache unit refers to a cache database unit that supports data persistence and data backup. It can be a local cache or a remote cache, such as Redis, Memcache, MongoDB, etc. Preferably, the central cache unit is a Redis cache unit that supports remote caching. The central cache unit can be deployed on the distributed master node 104 or on a remote server.

[0046] Through the above steps, the data to be processed is sent to the message queue middleware to obtain message queue data. Based on this message queue data, the local cache unit and the central cache unit are cached separately. The local cache unit and the central cache unit are connected in parallel. This application uses the message queue middleware as the message middleware, and then simultaneously distributes the message queue data to the parallel local cache unit and the central cache unit. Compared with the related technology where data is directly transmitted to the Redis cache and then the local cache is updated based on the Redis cache, the two-level caching method of this application uses the message queue middleware for cache processing, which improves the reliability and consistency of message delivery. At the same time, the parallel relationship between the local cache unit and the central cache unit ensures that if one cache unit fails and cache processing fails, other cache units can still be used normally. The failed cache unit can re-acquire data and cache it again after cache processing failure until successful caching, ensuring data integrity and consistency, enhancing cache utilization efficiency, improving system throughput, and solving the problem of data inconsistency between master and slave nodes in the cache.

[0047] In some embodiments, there is at least one local cache unit, and each local cache unit corresponds one-to-one with a distributed slave node; caching the local cache unit based on the message queue data includes:

[0048] The message queue data is simultaneously sent to all the distributed slave nodes, and the distributed slave nodes synchronously cache the local cache unit based on the message queue data.

[0049] It should be noted that this local caching unit can be deployed on each distributed slave node. After receiving message queue data sent by the distributed master node, the distributed slave node retrieves the message queue data and sends it to the local caching unit. The distributed slave node then performs distributed slave node business processing based on the message queue data. If caching fails, the message queue data is retrieved again and the local caching unit is cached until caching is successful, thereby enabling distributed slave node business processing.

[0050] Through the above steps, the local cache unit corresponds one-to-one with the distributed slave node, and all distributed slave nodes synchronously cache the local cache unit according to the message queue data. The local cache units on all distributed slave nodes do not interfere with each other, thereby solving the problem of data inconsistency between distributed slave nodes and improving the consistency of caching results.

[0051] In some embodiments, the data to be processed includes database business data, and the message queue data includes database message queue data; sending the data to be processed to the message queue middleware to obtain message queue data includes:

[0052] The corresponding binlog is obtained based on the database business data, and the binlog is sent to Canal to obtain the database encapsulated data.

[0053] The database encapsulated data is sent to the message queue middleware to obtain the database message queue data.

[0054] The database business data refers to data related to database business, which can be MySQL database definition language data and database operation data.

[0055] Specifically, first, the binlog-format mode of the MySQL database with binlog writing enabled is obtained. If the binlog-format mode is ROW mode, a synchronization user interface is created and authorized; this synchronization user interface points to the distributed slave node connected to the distributed master node. Second, the connection result between Canal and MySQL is obtained. If the connection result indicates that the connection between Canal and MySQL is successful, all or a specified number of database tables in MySQL are subscribed to, and all or a specified number of database business data are retrieved from the last table without ACK. Here, ACK (Acknowledge Character) is a transmission control character sent by the receiving station to the sending station in data communication, indicating that the sent data has been confirmed to be received correctly. If no database business data is retrieved, the database sleeps for two seconds. If the database business data is retrieved, the corresponding RowChange object (containing all characteristics of a row of data changes) is retrieved in a loop based on the database business data, and the RowChange object data is obtained. The binlog log is then obtained based on all RowChange object data. The binlog log is sent to Canal for encapsulation, resulting in database encapsulated data, and the current ACK is marked. The database encapsulated data is a JSON string. Finally, using a single-partition, single-topic routing mode, the database-encapsulated data is sent to a specific topic in the message queue middleware in chronological order, ensuring that the data is sent in the correct order.

[0056] It should be noted that the database encapsulated data sent by Canal to the message queue middleware needs to be processed into a fixed-format message. For database business data, the message for this database encapsulated data can be:

[0057]

[0058]

[0059] The `data` array is a collection of database operation content; the `isDdl` field indicates whether the operation is a DDL (Data Definition Language) type operation (operations on the database and tables that do not involve data, such as common database operations, common table structure operations, and table structure modification operations), excluding DDL data; `type` refers to the data processing type, including INSERT (adding a new data type), UPDATE (updating a data type), DELETE (deleting a data type), ERASE (deleting a table), etc.

[0060] Through the above steps, a binlog connection is established with MySQL via the Canal middleware. Canal receives binlog messages, receives data operation pushes from the database, and performs real-time caching of database business data. Database business data can be sent to the message queue middleware without executing a program, achieving zero intrusion into business code, no awareness of business operations, and ensuring business security.

[0061] In some embodiments, caching of the local cache unit based on the message queue data and caching of the central cache unit based on the message queue data include:

[0062] Based on the data processing type of the database message queue data, cache processing is performed on the local cache unit and the central cache unit; where the data processing type includes adding data types, updating data types, deleting data types, and deleting table data types.

[0063] Specifically, the data processing type of the database message queue data is obtained. If the data processing type is an add data type, the database message queue data is added to the local cache unit and the central cache unit. If the data processing type is an update data type, the corresponding data in the local cache unit and the central cache unit is cached according to the database message queue data, and the cache time is reset respectively. If the data processing type is a delete data type, the corresponding data in the local cache unit and the central cache unit is deleted according to the database message queue data. If the data processing type is a delete table data type, the corresponding data table in the local cache unit and the central cache unit is deleted according to the database message queue data. It should be noted that during the caching process of the local cache unit and the central cache unit, when the local cache unit and / or the central cache unit return a processing failure message, the database message queue data corresponding to the processing failure message is returned to the topic of the message queue middleware. The above process is repeated until the local cache unit and the central cache unit succeed in processing, so as to avoid the problem of cache inconsistency between master and slave nodes due to data caching failure. When the central cache unit is Redis, the central cache unit needs to open up a separate processing service to complete the caching process of the central cache unit.

[0064] Through the above steps, based on the data processing type of the database message queue data, the local cache unit and the central cache unit are cached synchronously. When the distributed slave node performs a large number of cache reads due to business processing needs, the local cache unit is read first, reducing the number of reads of the central cache unit. This avoids the central cache unit becoming a bottleneck of the entire system due to a large number of reads, or even causing the central cache unit to crash and be unable to cache the message queue data pushed by the message queue middleware, which would impact the backend business that directly reads the data from the central cache unit. This solves the problem of data inconsistency between master and slave nodes, improves the consistency of the system's first and second-level cache data, and improves the stability of the system through the second-level cache.

[0065] In some embodiments, the data to be processed further includes non-database business data, and the message queue data includes non-database message queue data; sending the data to be processed to the message queue middleware to obtain message queue data includes:

[0066] After encapsulating the non-database business data to obtain non-database encapsulated data, it is sent to the message queue middleware to obtain the non-database message queue data.

[0067] It's important to note that for non-database business data, the processing differs from the `canal` handling of database business data. When caching non-database business data, the business code needs to actively send this data to the message queue middleware according to business requirements to obtain the non-database message queue data. When the distributed master-slave nodes obtain this non-database message queue data, since this data is generated based on actual business needs, the caching processing of this data is handled by the distributed master-slave nodes consuming data in real-time according to specific business data, and caching it in both the local and central cache units. When the local and / or central cache units return processing failure information, the database message queue data corresponding to the failure information is returned to the topic in the message queue middleware. This process is repeated until the local and central cache units succeed, avoiding cache inconsistencies between master and slave nodes due to data caching failures. If the central cache unit is Redis, a separate processing service needs to be established to handle its caching.

[0068] Through the above steps, non-database business data is encapsulated and sent to the message queue middleware to obtain non-database message queue data. Then, the distributed master and slave nodes consume the data in real time according to the specific business data, thereby caching the local cache unit and the central cache unit. This avoids the problem that the central cache unit will become the bottleneck of the entire system due to a large number of reads, or even cause the central cache unit to crash. This solves the problem of data inconsistency between master and slave nodes, improves the consistency of the system's first and second level cache data, and improves the stability of the system through the second level cache.

[0069] In some embodiments, the data to be processed is sent to a message queue middleware to obtain message queue data, including:

[0070] Retrieve the specific topic corresponding to the data to be processed in the message queue middleware, send the data to be processed to the specific topic, and obtain the message queue data.

[0071] In this embodiment, the specific topic adopts a single-partition, single-topic mode, which is different from the general mode where one type of data corresponds to one topic. In addition to being distinguished by data type, the specific topic in this embodiment is also divided by time and batch. Different types of data to be processed are stored in different topics in Kafka at different times and in different batches. This ensures that the data stored in Kafka is stored in Kafka in chronological order. After the data stored in Kafka is distributed to all distributed master and slave nodes and ACKs are received from all distributed master and slave nodes, the distributed topic is deleted, and the next data to be processed is obtained and stored in Kafka.

[0072] By following the steps above, data stored in Kafka is transferred to a fixed Kafka topic, configured with a single partition, and real-time message notifications are sent through the Kafka topic. This ensures that message order is maintained and that cache inconsistency is not caused by concurrent caching, thus resolving the issue of cache inconsistency between master and slave nodes.

[0073] Taking two distributed slave nodes as an example, this embodiment also provides a two-level caching method. Figure 3 This is a flowchart of another two-level caching method in this embodiment, such as... Figure 3 As shown, the process includes the following steps:

[0074] Step S302: Obtain non-database business data.

[0075] Step S304: Encapsulate the non-database business data. Specifically, after encapsulating the non-database business data to obtain non-database encapsulated data, send it to Kafka to obtain non-database Kafka data.

[0076] Step S306: Obtain the business data from the database.

[0077] Step S308: Obtain the connection result between canal and MySQL. If the connection result indicates that the connection between canal and MySQL is successful, proceed to step S310.

[0078] Step S310: Obtain the MySQL binlog based on the database business data. Specifically, subscribe to all or a specified database table in MySQL, and retrieve all or a specified number of database business data from the last table without ACK; where ACK (Acknowledge Character) is a transmission control character sent by the receiving station to the sending station in data communication, indicating that the sent data has been confirmed to have been received correctly; if the database business data is not obtained, sleep for two seconds; if the database business data is obtained, cyclically obtain the corresponding RowChange object (containing all characteristics of a row of data changes) based on the database business data, obtain the RowChange object data, and obtain the binlog based on all RowChange object data.

[0079] Step S312: Send the binlog log to Canal for encapsulation. Specifically, send the binlog log to Canal for encapsulation to obtain the database encapsulated data, and mark the current ACK.

[0080] Step S314: Process the canal's encapsulated data into a fixed-format message.

[0081] Step S316: The database encapsulated data after processing the fixed-format message is sent to a specific topic in Kafka to obtain the database Kafka data.

[0082] Step S318: Perform secondary caching on the central cache unit based on the Kafka stored data. The Kafka stored data includes both database Kafka data and non-database Kafka data.

[0083] Step S320: Cache the Kafka storage data to the central cache unit.

[0084] Step S322: The first slave node performs first-level caching on its local cache unit based on the data stored in Kafka.

[0085] Step S324: Cache the Kafka storage data to the local cache unit of the first slave node.

[0086] Step S326: The second slave node performs first-level caching on its local cache unit based on the data stored in Kafka.

[0087] Step S328: Cache the Kafka storage data to the local cache unit of the second slave node.

[0088] By using Kafka as a message middleware through the above steps, and distributing the data stored in Kafka to both the parallel local cache unit and the central cache unit, compared with the related technologies that directly transmit data to the Redis cache and then update the local cache based on the Redis cache, the two-level caching method of this application uses the message middleware Kafka for cache processing, which improves the reliability and consistency of message delivery. At the same time, the parallel relationship between the local cache unit and the central cache unit ensures that if one cache unit fails and cache processing fails, the other cache units can still be used normally. The failed cache unit can re-acquire data and cache it again after cache processing failure until it is successfully cached, ensuring data integrity and consistency, enhancing cache utilization efficiency, improving system throughput, and solving the problem of data inconsistency between master and slave nodes in the cache.

[0089] It should be understood that, although Figure 2-3 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2-3 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0090] This embodiment also provides a secondary cache device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. The terms "module," "unit," "subunit," etc., used below refer to combinations of software and / or hardware that implement a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0091] Figure 4 This is a structural block diagram of the secondary cache device in this embodiment, as shown below. Figure 4 As shown, the device includes: a forwarding module 10, a first-level cache module 20, and a second-level cache module 30;

[0092] The forwarding module 10 is used to obtain the data to be processed, send the data to be processed to the message queue middleware, and obtain the message queue data.

[0093] The first-level cache module 20 is used to perform cache processing on the local cache unit in the distributed slave node according to the message queue data. If the local cache unit fails to perform cache processing, the message queue data is retrieved again and sent to the local cache unit.

[0094] The secondary cache module 30 is used to synchronously cache the central cache unit in the distributed master node according to the message queue data. If the central cache unit fails to cache the data, it will re-acquire the message queue data and send it to the central cache unit. The local cache unit is connected in parallel with the central cache unit.

[0095] For specific limitations regarding the L2 cache device, please refer to the limitations of the L2 cache method above, which will not be repeated here. Each module in the aforementioned L2 cache device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in the computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the operations corresponding to each module.

[0096] This embodiment also provides a two-level caching system, including: a distributed master node 104 and a distributed slave node 102; wherein, the distributed master node 104 is connected to the distributed slave node 102 through a transmission device;

[0097] The distributed master node 104 is used to execute the steps in any of the above method embodiments;

[0098] The transmission device is used to send message queue data to the distributed slave node;

[0099] The distributed slave node 102 is used to obtain the message queue data and cache the local cache unit according to the message queue data.

[0100] This embodiment also provides an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.

[0101] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0102] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:

[0103] S1, obtain the data to be processed, send the data to be processed to the message queue middleware, and obtain the message queue data;

[0104] S2, based on the message queue data, perform caching processing on the local cache unit in the distributed slave node; if the caching processing of the local cache unit fails, retrieve the message queue data again and send it to the local cache unit.

[0105] S3, based on the message queue data, synchronously perform caching processing on the central cache unit in the distributed master node. If the central cache unit fails to perform caching processing, re-acquire the message queue data and send it to the central cache unit; wherein, the local cache unit is connected in parallel with the central cache unit.

[0106] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated in this embodiment.

[0107] Furthermore, in conjunction with the two-level caching method provided in the above embodiments, this embodiment can also provide a storage medium for implementation. This storage medium stores a computer program; when executed by a processor, the computer program implements any of the two-level caching methods described in the above embodiments.

[0108] In one embodiment, a computer device is provided, which may be a server acting as a distributed master node, and its internal structure diagram may be as follows: Figure 5 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data to be processed. The network interface communicates with external distributed slave nodes via a network connection. The computer program, when executed by the processor, implements a two-level caching method.

[0109] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0110] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0111] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.

[0112] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.

[0113] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0114] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.

Claims

1. A two-level caching method, characterized in that, Applied to a distributed master node, wherein the master node is connected to at least one distributed slave node, the method includes: Obtain the data to be processed, and send the data to the message queue middleware to obtain message queue data; The message queue data is used to cache the local cache unit in the distributed slave node. If the local cache unit fails to cache the data, the message queue data is retrieved again and sent to the local cache unit. The central cache unit in the distributed master node is cached synchronously according to the message queue data. If the central cache unit fails to cache the data, the message queue data is retrieved again and sent to the central cache unit. The local cache unit is connected in parallel with the central cache unit. There is at least one local cache unit, and each local cache unit corresponds one-to-one with a distributed slave node; the local cache units in the distributed slave nodes are cached according to the message queue data, including: The message queue data is simultaneously sent to all the distributed slave nodes, and the distributed slave nodes synchronously cache the local cache unit according to the message queue data.

2. The two-level caching method according to claim 1, characterized in that, The data to be processed includes database business data, and the message queue data includes database message queue data; the data to be processed is sent to the message queue middleware to obtain message queue data, including: Obtain the corresponding binlog logs based on the database business data, and send the binlog logs to Canal to obtain database encapsulated data; The database encapsulated data is sent to the message queue middleware to obtain the database message queue data.

3. The two-level caching method according to claim 2, characterized in that, The step of caching the local cache unit based on the message queue data and caching the central cache unit based on the message queue data includes: The local cache unit and the central cache unit are cached according to the data processing type of the database message queue data; wherein, the data processing type includes adding data type, updating data type, deleting data type, and deleting table data type.

4. The two-level caching method according to claim 1, characterized in that, The data to be processed also includes non-database business data, and the message queue data includes non-database message queue data; the step of sending the data to be processed to the message queue middleware to obtain message queue data includes: The non-database business data is encapsulated to obtain non-database encapsulated data, which is then sent to the message queue middleware to obtain the non-database message queue data.

5. The two-level caching method according to claim 1, characterized in that, The data to be processed is sent to the message queue middleware to obtain message queue data, including: Obtain the specific topic corresponding to the data to be processed in the message queue middleware, send the data to be processed to the specific topic, and obtain the message queue data.

6. A secondary cache device, characterized in that, Applied to a distributed master node, wherein the distributed master node is connected to at least one distributed slave node, the device includes: a forwarding module, a first-level cache module, and a second-level cache module; The forwarding module is used to obtain the data to be processed and send the data to be processed to the message queue middleware to obtain message queue data; The first-level cache module is used to cache the local cache unit in the distributed slave node according to the message queue data, and if the local cache unit fails to cache, it will re-acquire the message queue data and send it to the local cache unit. The secondary cache module is used to synchronously cache the central cache unit in the distributed master node according to the message queue data. If the central cache unit fails to cache the data, it will reacquire the message queue data and send it to the central cache unit. The local cache unit is connected in parallel with the central cache unit. There is at least one local cache unit, and each local cache unit corresponds one-to-one with a distributed slave node; the local cache units in the distributed slave nodes are cached according to the message queue data, including: The message queue data is simultaneously sent to all the distributed slave nodes, and the distributed slave nodes synchronously cache the local cache unit according to the message queue data.

7. A two-level cache system, characterized in that, include: Distributed master nodes and distributed slave nodes; wherein the distributed master nodes are connected to the distributed slave nodes through transmission equipment; The distributed master node is used to execute the second-level caching method according to any one of claims 1 to 5; The transmission device is used to send message queue data to the distributed slave node; The distributed slave node is used to obtain the message queue data and perform caching processing on the local cache unit based on the message queue data.

8. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the secondary cache method according to any one of claims 1 to 5.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the secondary cache method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Cache updating method and system based on Canal

    CN109241072A

  • Data caching processing method and system, calculation equipment and readable storage medium

    CN113032432A