Data reading method and device, equipment, storage medium and product

By dynamically adjusting the reading strategy in the client according to factors such as the prefix type and delay time of the data key, the problem of difficult to take into account both the read and write performance and data accuracy in the prior art is solved, and efficient and accurate data reading is achieved.

CN119668862AActive Publication Date: 2025-03-21CHINA MOBILE INTERNET CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411752245.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-03-21
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

Existing client read data modes are difficult to take into account read-write performance and data read accuracy, especially when the master-slave data synchronization delay is too high, reading slave data may be read to old data.

Method used

The read policy is determined by introducing the prefix type of data keys in the client, including read-only master nodes, master-slave nodes are read, and the read node is determined based on the delay time and delay thresholds.

Benefits of technology

Improve read and write performance, ensure that the data read from the node is up-to-date or new enough, improve the accuracy of data reading, and take into account read and write performance and data accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119668862A_ABST
    Figure CN119668862A_ABST
Patent Text Reader

Abstract

The invention discloses a data reading method and device, equipment, a storage medium and a product. The method comprises the following steps: obtaining a read request initiated by a client, the read request being used for reading data in a master node and a slave node; under the condition that the prefix type of a data key in the read request is a first type, reading target data in a main node; under the condition that the prefix type of a data key in the read request is a second type, according to pre-acquired delay time and a first delay threshold value corresponding to the data key, reading target data of the master node, or reading target data of at least one of the master node and the slave node, the delay time is the time required for data synchronization between the master node and the slave node. According to the embodiment of the invention, both the read-write performance and the data reading accuracy can be considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of algorithm scheduling technology, and in particular, relates to a data reading method, device, equipment, storage medium and product. Background Art

[0002] Redis (Remote Dictionary Server) is a data middleware with high performance and high probability. Because the data is stored in the memory, it is usually a master node with multiple slaves. The data is written on the master node and synchronized to multiple slave nodes through the master node. The data reading speed is very fast.

[0003] However, in the existing client data reading mode, choosing to read only the master node will ensure data accuracy, but it will cause all client connections to connect to the master node, without utilizing the reading capability provided by the slave node. The reading and writing pressure is concentrated on the master node, thus affecting the Redis reading and writing performance. Choosing the master-slave reading mode distributes the reading pressure to the slave node, but after writing data, there will be a problem of excessive synchronization delay when the master node data is synchronized to the slave node due to various reasons such as the network, resulting in old data being read when reading the slave node data, reducing the accuracy of data reading.

[0004] Therefore, the existing client data reading mode is difficult to balance the reading and writing performance and data reading accuracy. Summary of the invention

[0005] The embodiments of the present application provide a data reading method, device, equipment and computer storage medium to solve the problem that it is difficult to balance the reading and writing performance and the data reading accuracy in the existing client data reading mode.

[0006] In a first aspect, an embodiment of the present application provides a data reading method, the method comprising:

[0007] Obtain a read request initiated by a client, wherein the read request is used to read data in a master node and a slave node;

[0008] When the prefix type of the data key in the read request is the first type, reading the target data in the master node;

[0009] In the case where the prefix type of the data key in the read request is the second type, the target data of the master node is read according to the pre-acquired delay time and the first delay threshold corresponding to the data key, or the target data of at least one of the master node and the slave node is read, and the delay time is the time required for data synchronization between the master node and the slave node.

[0010] In a second aspect, an embodiment of the present application provides an algorithm scheduling device, the device comprising:

[0011] A first acquisition module, used to acquire a read request initiated by a client, wherein the read request is used to read data in a master node and a slave node;

[0012] A first reading module, configured to read target data in a master node when a prefix type of a data key in the read request is a first type;

[0013] A second reading module is used to read the target data of the master node, or read the target data of at least one of the master node and the slave node, according to a pre-acquired delay time and a first delay threshold corresponding to the data key when the prefix type of the data key in the read request is the second type, wherein the delay time is the time required for data synchronization between the master node and the slave node.

[0014] In a third aspect, an embodiment of the present application provides a terminal device, the device comprising: a processor and a memory storing computer program instructions;

[0015] When the processor executes the computer program instructions, the data reading method of the first aspect is implemented.

[0016] In a fourth aspect, an embodiment of the present application provides a computer storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the data reading method of the first aspect is implemented.

[0017] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the data reading method of the first aspect.

[0018] The data reading method provided in the embodiment of the present application introduces data keys that are read by both the master node and the master-slave node, and implements prefix queries of different data keys in a system that can select the read-only master node or the read master-slave node, avoiding the problem that the client connections are all connected to the master node without utilizing the reading capabilities provided by the slave node, thereby improving the read and write performance. At the same time, in the mode where both the master and slave nodes read, by comparing the input delay time with the delay threshold, it helps to ensure that when reading data from the slave node, the data is already the latest or at least new enough, thereby improving the accuracy of data reading. Thus, both read and write performance and data reading accuracy are taken into account to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0020] Figure 1 It is a flowchart of a data reading method provided in an embodiment of the present application;

[0021] Figure 2 It is a structural diagram of an algorithm scheduling device provided in an embodiment of the present application;

[0022] Figure 3 It is a schematic diagram of the structure of the terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0023] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.

[0024] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0025] In order to solve the problems of the prior art, the embodiments of the present application provide a data reading method, device, equipment, storage medium and product.

[0026] The following first introduces the data reading method provided in the embodiment of the present application.

[0027] Figure 1 FIG. 1 is a flow chart of a data reading method provided by an embodiment of the present application. Figure 1 As shown, the method includes:

[0028] Step 101, obtaining a read request initiated by a client, wherein the read request is used to read data in a master node and a slave node;

[0029] In this embodiment, the data reading method is applied to the client. The user can initiate a read request through the client, and the read request is used to read data in the Redis server, wherein the Redis server includes a master node and a slave node, and the number of the slave nodes can be multiple.

[0030] The read request contains the data key, which is the basic unit of Redis data operations. The client sends a command containing the key to request Redis to perform a specific operation, such as getting (GET) or setting (SET) the value associated with the key.

[0031] You can decide how to read the data associated with the key based on the key prefix type. Specifically, multiple global variables are defined in the client, which include multiple prefix sets and corresponding reading rules, including:

[0032] masterPrefixs collection: a collection of key prefixes of the read-only master database. For keys starting with these prefixes, only data from the master node will be read when querying.

[0033] bothPrefixs collection: a collection of key prefixes read by both the master and slave libraries. When a key that begins with these prefixes is queried, data from multiple master and slave nodes will be read in a round-robin manner.

[0034] delayThresholdPrefixs collection: For keys starting with these prefixes, queries will select a read-only master node or a master-slave multi-node based on the master-slave synchronization delay monitored by the monitoring task.

[0035] Step 102, when the prefix type of the data key in the read request is the first type, read the target data in the master node;

[0036] In this embodiment, the first type is the data key type that conforms to the masterPrefixs set. The client first determines whether the key satisfies the type in the masterPrefixs set. If the prefix type of the data key key satisfies the type in the masterPrefixs set, the client can read the target data corresponding to the key in the master node.

[0037] Step 103, when the prefix type of the data key in the read request is the second type, read the target data of the master node according to the pre-acquired delay time and the first delay threshold corresponding to the data key, or read the target data of at least one of the master node and the slave node, the delay time being the time required for data synchronization between the master node and the slave node.

[0038] In this embodiment, the second type is the data key type that conforms to the delayThresholdPrefixs set. If the prefix type of the key is a type in the delayThresholdPrefixs set, the client needs to obtain the delay time and the first delay threshold corresponding to the key, and compare the two, and then determine whether to query the master node, or read the target data in both the master node and the slave node based on the comparison result.

[0039] The delay time refers to the time required for data synchronization between the master node and the slave node. The data in the slave node is copied from the master node, so whether to increase the data reading in the slave node based on the delay time can ensure that when the client queries the data in the slave node, the data in the slave node is consistent with the data in the master node, avoiding querying old data in the slave node, thereby improving the accuracy of data query.

[0040] In this embodiment, data keys that are read only by the master node and read by both the master and slave nodes are introduced, so that prefix queries of different data keys in a system can select read only by the master node or read master and slave nodes, avoiding the problem that the client connections are all connected to the master node without utilizing the reading capability provided by the slave node, thereby improving the read and write performance. At the same time, in the mode where both the master and slave nodes read, by comparing the input delay time with the delay threshold, it helps to ensure that when reading data from the slave node, the data is already the latest or at least new enough, thereby improving the accuracy of data reading. Thus, both read and write performance and data reading accuracy are taken into account to a certain extent.

[0041] In an embodiment of the present application, reading target data of at least one of the master node and the slave node according to the pre-acquired delay time and the first delay threshold corresponding to the data key includes:

[0042] Obtaining a first delay threshold corresponding to the data key;

[0043] When the first delay threshold is less than the delay time, reading the target data in the master node;

[0044] When the first delay threshold is greater than or equal to the delay time, target data of at least one of the master node and the slave node is read.

[0045] In this embodiment, the client also includes a delayThresholdMapping set, which records the key prefix and the corresponding delay threshold. Different key prefixes may have different delay thresholds. Therefore, the first delay threshold of the corresponding key can be queried in the set. In addition, if there is no first delay threshold corresponding to the key in the set, the default delay threshold is used as the first delay threshold.

[0046] When the first delay threshold is less than the delay time, it means that the synchronization delay between the master and slave nodes is too high. In order to avoid the data of the slave node being out of synchronization, it can only be queried from the master node; otherwise, it means that the synchronization delay between the master and slave nodes is within the threshold, and the master node or the slave node can be queried, and queries can also be performed in the master node and the slave node at the same time.

[0047] In one embodiment, obtaining the first delay threshold corresponding to the data key includes:

[0048] In a case where the global variable of the client includes a second delay threshold corresponding to the data key, determining the second delay threshold as the first delay threshold;

[0049] When the global variables of the client do not include the second delay threshold corresponding to the data key, the preset delay threshold is determined as the first delay threshold.

[0050] In this embodiment, in addition to the masterPrefixs set, bothPrefixs set, and delayThresholdPrefixs set, the global variables also include a delayThresholdMapping set. In this set, if there is a second delay threshold corresponding to the key, the second delay threshold is used as the first delay threshold. In this set, if there is no second delay threshold corresponding to the key, the preset delay threshold is determined as the first delay threshold.

[0051] In this embodiment, by introducing a comparison mechanism between the first delay threshold and the delay time, the data reading strategy can be dynamically adjusted according to the synchronization status and access requirements of the data. When the first delay threshold is less than the delay time, the data is read from the master node to ensure the consistency and accuracy of the data; when the first delay threshold is greater than or equal to the delay time, the data can be read from the master node or the slave node to improve the reading efficiency and load balancing. This strategy improves the flexibility and adaptability of data reading, so that it can better meet the needs of different scenarios.

[0052] In an embodiment of the present application, when the prefix type of the data key in the read request is the second type, after reading the target data in the master node and / or the slave node according to the delay time and the first delay threshold corresponding to the data key, the method further includes:

[0053] When the prefix type of the data key in the read request is the third type, target data of at least one of the master node or the slave node is read.

[0054] In this embodiment, if the client determines that the key is not of the first type and the second type, but of the third type, the target data is read from the master node and the slave node. The third type is the data key type that conforms to the bothPrefixs set. If the prefix type of the key is a type in the bothPrefixs set, the client can query the target data from the master node or the slave node.

[0055] By reading data from any node among the master node or slave nodes, the data reading pressure of the master node can be relieved and the efficiency of data reading can be improved.

[0056] In an embodiment of the present application, when the prefix type of the data key in the read request is the third type, after reading the target data of at least one of the master node or the slave node, the method further includes:

[0057] When the prefix type of the data key in the read request is not the third type, obtaining a default read mode of the client;

[0058] According to the default read mode, target data is read from at least one of the master node and the slave node.

[0059] In this embodiment, if the client determines that the prefix type of the key does not belong to any of the first type, the second type, and the third type, it is necessary to use the default read mode preset in the client to read the data.

[0060] The default read mode is also represented in the client in the form of a global variable called defaultReadModel. The value of this variable can be used to determine which mode to use for data reading. Specifically, the default read mode values ​​are master, both, and delayThreshold. Among them, master only queries the master node, both queries both the master and slave nodes, and delayThreshold is determined based on the synchronization delay and delay threshold.

[0061] In one embodiment, reading the target data from at least one of the master node and the slave node according to the default read mode includes:

[0062] When the default read mode is a first mode, reading target data from the master node, the first mode being a mode for reading data in the master node;

[0063] In the case where the default read mode is the second mode, target data is read from at least one of the master node and the slave node, and the second mode is a mode in which data can be read from the master node and the slave node.

[0064] In this embodiment, the first mode is the master mode, in which the target data can only be queried in the master node. The second mode is the both mode, in which the target data can be queried in any node of the master node and the slave node.

[0065] In this embodiment, by introducing a default read mode and selecting different read strategies according to different modes, different read requirements can be more flexibly responded to. In scenarios where data accuracy is required to be high, data can be read from the master node; in scenarios where consistency requirements are not so strict, data can be read from the slave node to improve reading efficiency and load balancing.

[0066] In an embodiment of the present application, when the default read mode is the second mode, after reading the target data from at least one of the master node and the slave node, the method further includes:

[0067] In a case where the default read mode is the third mode, if a preset third delay threshold is greater than the delay time, reading target data from at least one of the master node and the slave node;

[0068] When the default read mode is the third mode, if the preset third delay threshold is less than or equal to the delay time, the target data is read from the master node.

[0069] In this embodiment, when the default read mode is the third mode, it is necessary to query the target data in the master node and the slave node according to the delay time and the third delay threshold.

[0070] Specifically, since the prefix type of the key does not belong to the second type, the key has no corresponding delay threshold, so the third delay threshold may be a preset delay threshold.

[0071] When the third delay threshold is greater than the delay time, it means that there is no data synchronization delay between the master node and the slave node, and the data of the two are consistent, then the target data can be queried at any of the master node and the slave node. When the third delay threshold is less than the delay time, it means that there is a data synchronization delay between the master node and the slave node, and to ensure the accuracy of the read data, the data can only be read from the master node.

[0072] In this embodiment, the target of the client to read data is determined by comparing the third delay threshold with the delay time, so that the reading performance can be guaranteed on the basis of ensuring the accuracy of the read data.

[0073] In an embodiment of the present application, before obtaining the read request initiated by the client, the method further includes:

[0074] Loading a monitoring script into the master node, wherein the monitoring script is used to generate a test key-value pair;

[0075] Using the monitoring script to write the test key-value pair in the master node;

[0076] Extracting the test key-value pairs from the master node and the slave node at intervals of a preset duration, wherein the test key-value pairs in the slave node are obtained through data synchronization of the master node;

[0077] The delay time is determined using the extracted test key-value pair.

[0078] In this embodiment, in order to determine the delay time between the master and slave nodes, a monitoring script is also provided in the client. When the client is started, the monitoring script is loaded into the master node, and a test key-value pair is written into the master node through the monitoring script. The value format of the key-value pair is ${value}-${nowTime}, where ${value} is a fixed value (can be any identifier), and ${nowTime} is the timestamp when the test key-value pair is written into the master node.

[0079] During the data synchronization between the master node and the slave node, the slave node will also synchronize the test key-value pair. Therefore, the same test key-value pair is read from the master node and the slave node at regular intervals. The delay time is then determined based on the read test key-value pair.

[0080] Specifically, in one embodiment, extracting the test key-value pair from the master node and the slave node includes:

[0081] Extracting a first test key-value pair from the master node, and extracting a second test key-value pair from the slave node;

[0082] The step of determining the delay time by using the extracted test key-value pair includes:

[0083] The difference between the first timestamp in the first test key-value pair and the second timestamp in the second test key-value pair is determined as the delay time, the first timestamp is the time when the first test key-value pair is written to the master node, and the second timestamp is the time when the second test key-value pair is written to the slave node.

[0084] In this embodiment, the second timestamp in the second test key-value pair is the time point when the master node synchronizes the key-value pair to the slave node when the master node synchronizes data with the slave node. The first timestamp in the first key-value pair is the time when the first test pair is written to the master node. By calculating the difference between the second timestamp and the first timestamp, the delay time required for data synchronization between the master and slave nodes can be obtained.

[0085] In this embodiment, by loading the monitoring script in the master node, test key-value pairs can be automatically generated and written. These test key-value pairs serve as "probes" of the data synchronization status and can reflect the data synchronization status between the master node and the slave node in real time or regularly. The node that reads the data is determined based on the data synchronization status, thereby improving the accuracy of data reading.

[0086] Based on the same inventive concept, the embodiment of the present application also provides an algorithm scheduling device. Figure 2 The algorithm scheduling device provided in the embodiment of the present application is described in detail.

[0087] Figure 2 It is a structural diagram of an algorithm scheduling device provided in an embodiment of the present application.

[0088] like Figure 2 As shown, the algorithm scheduling device 200 may include:

[0089] A first acquisition module 201 is used to acquire a read request initiated by a client, where the read request is used to read data in a master node and a slave node;

[0090] A first reading module 202, configured to read target data in the master node when the prefix type of the data key in the read request is a first type;

[0091] The second reading module 203 is used to read the target data of the master node, or read the target data of at least one of the master node and the slave node, according to the pre-acquired delay time and the first delay threshold corresponding to the data key when the prefix type of the data key in the read request is the second type, and the delay time is the time required for data synchronization between the master node and the slave node.

[0092] Optionally, the second reading module 203 includes:

[0093] An acquisition submodule, used to acquire a first delay threshold corresponding to the data key;

[0094] A first reading submodule, configured to read target data in the master node when the first delay threshold is less than the delay time;

[0095] The second reading submodule is used to read the target data of at least one of the master node and the slave node when the first delay threshold is greater than or equal to the delay time.

[0096] Optionally, obtain submodules, including:

[0097] A first determining unit, configured to determine the second delay threshold as the first delay threshold when the global variable of the client includes the second delay threshold corresponding to the data key;

[0098] The second determining unit is configured to determine a preset delay threshold as the first delay threshold when the global variable of the client does not include the second delay threshold corresponding to the data key.

[0099] Optionally, the algorithm scheduling device 200 is specifically configured to:

[0100] When the prefix type of the data key in the read request is the third type, target data of at least one of the master node or the slave node is read.

[0101] Optionally, the algorithm scheduling device 200 further includes:

[0102] A second acquisition module, configured to acquire a default read mode of the client when the prefix type of the data key in the read request is not the third type;

[0103] The third reading module is used to read the target data from at least one of the master node and the slave node according to the default reading mode.

[0104] Optionally, the third reading module includes:

[0105] A third reading submodule, configured to read target data from the master node when the default reading mode is a first mode, wherein the first mode is a mode for reading data in the master node;

[0106] The fourth reading submodule is used to read target data from at least one of the master node and the slave node when the default reading mode is the second mode, and the second mode is a mode in which data can be read from the master node and the slave node.

[0107] Optionally, the algorithm scheduling device 200 is specifically configured to:

[0108] In a case where the default read mode is the third mode, if a preset third delay threshold is greater than the delay time, the target data is read from at least one of the master node and the slave node.

[0109] Optionally, the algorithm scheduling device 200 is specifically configured to:

[0110] When the default read mode is the third mode, if the preset third delay threshold is less than or equal to the delay time, the target data is read from the master node.

[0111] Optionally, the algorithm scheduling device 200 further includes:

[0112] A loading module, used to load a monitoring script into the master node, wherein the monitoring script is used to generate a test key-value pair;

[0113] A writing module, used for writing the test key-value pair in the master node using the monitoring script;

[0114] An extraction module, used for extracting the test key-value pairs from the master node and the slave node at intervals of a preset time, wherein the test key-value pairs in the slave node are obtained through data synchronization of the master node;

[0115] The determination module is used to determine the delay time by using the extracted test key-value pair.

[0116] Optionally, the extraction module is specifically used to:

[0117] Extracting a first test key-value pair from the master node, and extracting a second test key-value pair from the slave node;

[0118] Optionally, a module is determined, specifically for:

[0119] The difference between the first timestamp in the first test key-value pair and the second timestamp in the second test key-value pair is determined as the delay time, the first timestamp is the time when the first test key-value pair is written to the master node, and the second timestamp is the time when the second test key-value pair is written to the slave node.

[0120] It should be noted that the algorithm scheduling device 200 is a device corresponding to the above-mentioned data reading method, and all implementation methods in the above-mentioned method embodiment are applicable to the embodiment of the device and can achieve the same technical effect.

[0121] Figure 3 A schematic diagram of the hardware structure of a terminal device provided in an embodiment of the present application is shown.

[0122] The terminal device may include a processor 301 and a memory 302 storing computer program instructions.

[0123] Specifically, the processor 301 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.

[0124] The memory 302 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 302 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 302 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 302 is a non-volatile solid-state memory.

[0125] In certain embodiments, the memory 302 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, in general, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.

[0126] The processor 301 implements any one of the data reading methods in the above embodiments by reading and executing the computer program instructions stored in the memory 302 .

[0127] In one example, the terminal device may further include a communication interface 303 and a bus 310. Figure 3 As shown, the processor 301, the memory 302, and the communication interface 303 are connected via a bus 310 and communicate with each other.

[0128] The communication interface 303 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.

[0129] Bus 310 includes hardware, software or both, and the parts of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-end bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 310 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.

[0130] In addition, in combination with the data reading method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the data reading methods in the above embodiment is implemented.

[0131] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.

[0132] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.

[0133] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.

[0134] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable algorithm scheduling device to produce a machine so that these instructions executed by the processor of the computer or other programmable algorithm scheduling device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.

[0135] The above are only specific implementation methods of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.

Claims

1. A data reading method, characterized in that: The method comprises: Obtain a read request initiated by a client, wherein the read request is used to read data in a master node and a slave node; When the prefix type of the data key in the read request is the first type, reading the target data in the master node; In the case where the prefix type of the data key in the read request is the second type, the target data of the master node is read according to the pre-acquired delay time and the first delay threshold corresponding to the data key, or the target data of at least one of the master node and the slave node is read, and the delay time is the time required for data synchronization between the master node and the slave node.

2. The data reading method according to claim 1, characterized in that: In a case where the prefix type of the data key in the read request is the second type, reading the target data of the master node according to the pre-acquired delay time and the first delay threshold corresponding to the data key, or reading the target data of at least one of the master node and the slave node, including: Obtaining a first delay threshold corresponding to the data key; When the first delay threshold is less than the delay time, reading the target data in the master node; When the first delay threshold is greater than or equal to the delay time, target data of at least one of the master node and the slave node is read.

3. The data reading method according to claim 2, characterized in that: The obtaining a first delay threshold corresponding to the data key includes: In a case where the global variable of the client includes a second delay threshold corresponding to the data key, determining the second delay threshold as the first delay threshold; When the global variables of the client do not include the second delay threshold corresponding to the data key, the preset delay threshold is determined as the first delay threshold.

4. The data reading method according to claim 1, characterized in that: In the case where the prefix type of the data key in the read request is the second type, according to the pre-acquired delay time and the first delay threshold corresponding to the data key, reading the target data of the master node, or after reading the target data of at least one of the master node and the slave node, the method further includes: In a case where the prefix type of the data key in the read request is the third type, target data of at least one of the master node and the slave node is read.

5. The data reading method according to claim 4, characterized in that: In the case where the prefix type of the data key in the read request is the third type, after reading the target data of at least one of the master node and the slave node, the method further includes: When the prefix type of the data key in the read request is not the third type, obtaining a default read mode of the client; According to the default read mode, target data is read from at least one of the master node and the slave node.

6. The data reading method according to claim 5, characterized in that: The step of reading target data from at least one of the master node and the slave node according to the default read mode includes: When the default read mode is a first mode, reading target data from the master node, the first mode being a mode for reading data in the master node; In the case where the default read mode is the second mode, target data is read from at least one of the master node and the slave node, and the second mode is a mode in which data can be read from the master node and the slave node.

7. The data reading method according to claim 6, characterized in that: In the case where the default read mode is the second mode, after reading the target data from at least one of the master node and the slave node, the method further includes: In a case where the default read mode is the third mode, if a preset third delay threshold is greater than the delay time, the target data is read from at least one of the master node and the slave node.

8. The data reading method according to claim 6, characterized in that: In the case where the default read mode is the second mode, after reading the target data from at least one of the master node and the slave node, the method further includes: When the default read mode is the third mode, if the preset third delay threshold is less than or equal to the delay time, the target data is read from the master node.

9. The data reading method according to claim 1, characterized in that: Before obtaining the read request initiated by the client, the method further includes: Loading a monitoring script into the master node, wherein the monitoring script is used to generate a test key-value pair; Using the monitoring script to write the test key-value pair in the master node; Extracting the test key-value pairs from the master node and the slave node at intervals of a preset duration, wherein the test key-value pairs in the slave node are obtained through data synchronization of the master node; The delay time is determined using the extracted test key-value pair.

10. The data reading method according to claim 9, characterized in that: The test key-value pair includes a first test key-value pair and a second test key-value pair; The extracting the test key-value pair from the master node and the slave node includes: Extracting a first test key-value pair from the master node, and extracting a second test key-value pair from the slave node; The step of determining the delay time by using the extracted test key-value pair includes: The difference between the first timestamp in the first test key-value pair and the second timestamp in the second test key-value pair is determined as the delay time, the first timestamp is the time when the first test key-value pair is written to the master node, and the second timestamp is the time when the second test key-value pair is written to the slave node.

Citation Information

Patent Citations

  • Method and device for reading data based on data cache

    CN102902730A

  • Data reading method and terminal

    CN113760934A

  • Database access method and device, equipment and storage medium

    CN114880336A

  • Data backup method, system, and storage medium

    WO2024234763A1