Data reading method, device, equipment, storage medium and product
By dynamically adjusting the reading strategy from master and slave nodes in the Redis system based on the prefix type and latency of the data key, the problem of balancing read/write performance and data accuracy is solved, achieving efficient and accurate data reading.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA MOBILE INTERNET CO LTD
- Filing Date
- 2024-11-29
- Publication Date
- 2026-04-14
AI Technical Summary
Existing client-side data reading models struggle to balance read/write performance and data reading accuracy. Choosing to read only the master node can cause connections to cluster on the master node, impacting performance. Choosing to read from both master and slave nodes may result in excessively high data synchronization latency, leading to the reading of old data.
By determining the prefix type of the data key, selectively reading only the master node or master-slave node, and dynamically adjusting the data reading strategy in conjunction with latency time and latency threshold, data consistency and accuracy are ensured.
It improves read and write performance, ensuring that the data read from the node is up-to-date or sufficiently new, thus balancing read and write performance with data reading accuracy.
Smart Images

Figure CN119668862B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of algorithm scheduling technology, and in particular relates to a data reading method, apparatus, device, storage medium and product. Background Technology
[0002] Redis (Remote Dictionary Server) is a high-performance, high-reliability data middleware. Because the data is stored in memory, it typically uses a master-slave architecture. Data is written to the master node and synchronized to multiple slave nodes through the master node, resulting in very fast data reading speeds.
[0003] However, in the existing client data reading mode, choosing to read only the master node ensures data accuracy, but it causes all client connections to the master node, failing to utilize the reading capabilities provided by the slave nodes. This concentrates read and write pressure on the master node, thus affecting Redis read and write performance. Choosing a mode that reads from both master and slave nodes distributes the read pressure to the slave nodes, but there is a problem that after writing data, the synchronization latency from the master node to the slave nodes may be too high due to network and other factors. This results in reading old data from the slave nodes, reducing the accuracy of data reading.
[0004] Therefore, the existing client-side data reading model struggles to balance read / write performance with data reading accuracy. Summary of the Invention
[0005] This application provides a data reading method, apparatus, device, and computer storage medium to solve the problem that existing client data reading modes are difficult to balance read / write performance and data reading accuracy.
[0006] In a first aspect, embodiments of this application provide a data reading method, the method comprising:
[0007] Obtain read requests initiated by the client, which are used to read data from the master node and slave node;
[0008] If the prefix type of the data key in the read request is of type 1, read the target data from the master node;
[0009] If 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, wherein the delay time is the time required for data synchronization between the master node and the slave node.
[0010] Secondly, embodiments of this application provide an algorithm scheduling apparatus, the apparatus comprising:
[0011] The first acquisition module is used to acquire read requests initiated by the client, the read requests being used to read data from the master node and the slave node;
[0012] The first reading module is used to read target data from the master node when the prefix type of the data key in the read request is of the first type;
[0013] The 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, based on 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, wherein the delay time is the time required for data synchronization between the master node and the slave node.
[0014] Thirdly, embodiments of this application provide a terminal device, the device including: a processor and a memory storing computer program instructions;
[0015] When the processor executes computer program instructions, it implements the data reading method as described in the first aspect.
[0016] Fourthly, embodiments of this application provide a computer storage medium on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the data reading method as described in the first aspect is implemented.
[0017] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform the data reading method as described in the first aspect.
[0018] The data reading method provided in this application introduces a data key that can be read from both the master node and the master-slave nodes. This allows different data key prefix queries within a system to select either a read-only master node or a read-master-slave node, avoiding the problem of client connections all connecting to the master node without utilizing the read capabilities provided by the slave nodes, thus improving read and write performance. Simultaneously, in the master-slave read mode, comparing the ingress latency time with a latency threshold helps ensure that when reading data from the slave node, the data is already up-to-date or at least sufficiently new, improving data reading accuracy. Therefore, it balances read and write performance and data reading accuracy to a certain extent. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating the data reading method provided in an embodiment of this application;
[0021] Figure 2 This is a schematic diagram of the structure of the algorithm scheduling device provided in the embodiments of this application;
[0022] Figure 3 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation
[0023] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0024] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.
[0025] To address the problems in the prior art, embodiments of this application provide a data reading method, apparatus, device, storage medium, and product.
[0026] The data reading method provided in the embodiments of this application will be described below.
[0027] Figure 1 A flowchart illustrating a data reading method according to an embodiment of this application is shown. Figure 1 As shown, the method includes:
[0028] Step 101: Obtain the read request initiated by the client, which is used to read data from the master node and the slave node;
[0029] In this embodiment, the data reading method is applied to the client. Users can initiate read requests through the client to read data from the Redis server. The Redis server includes master nodes and slave nodes, and there can be multiple slave nodes.
[0030] A read request contains a data key, which is the basic unit of data operations in Redis. Clients request Redis to perform specific operations by sending commands containing the key, such as getting (GET) or setting (SET) the value associated with that key.
[0031] The method for retrieving data associated with a key can be determined based on the key's prefix type. Specifically, several global variables are defined in the client, including multiple prefix sets and corresponding retrieval rules, such as:
[0032] The masterPrefixs collection: A collection of key prefixes for the read-only master database. When querying keys that start with these prefixes, only the master node's data will be read.
[0033] The `bothPrefixs` set: This set of key prefixes that are read by both the master and slave databases. When querying keys that start with these prefixes, data will be read from multiple nodes, including the master and slave, using methods such as round-robin.
[0034] The delayThresholdPrefixs set: keys starting with these prefixes will be used to select either a read-only master node or a master-slave multi-node system based on the master-slave synchronization delay monitored by the monitoring task.
[0035] Step 102: If the prefix type of the data key in the read request is of 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 conforms to the type in the masterPrefixs set. If the prefix type of the data key conforms to the type in the masterPrefixs set, the client can read the target data corresponding to the key from the master node.
[0037] Step 103: If 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, wherein the delay time is 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, compare the two, and then determine whether to query on the master node or read the target data from both the master node and the slave node based on the comparison result.
[0039] The latency refers to the time required for data synchronization between the master and slave nodes. Since the data in the slave node is copied from the master node, determining whether to increase data reading on the slave node based on the latency ensures that when a client queries data on the slave node, the data on the slave node is consistent with the data on the master node, avoiding the querying of outdated data and thus improving the accuracy of data queries.
[0040] In this embodiment, a data key that can be read by both the master node and both master and slave nodes is introduced. This allows different data key prefix queries within a system to select either the master node (read-only) or the master-slave node (read-only), avoiding the problem of client connections all connecting to the master node without utilizing the read capabilities provided by the slave nodes, thus improving read and write performance. Simultaneously, in the master-slave read mode, comparing the ingress latency time with a latency threshold helps ensure that data is up-to-date or at least sufficiently new when reading data from the slave node, improving data read accuracy. Therefore, this approach balances read and write performance with data read accuracy to a certain extent.
[0041] In one embodiment of this application, reading target data from at least one of the master node and the slave node based on a pre-acquired delay time and a first delay threshold corresponding to the data key includes:
[0042] Obtain the first delay threshold corresponding to the data key;
[0043] If the first delay threshold is less than the delay time, read the target data from the master node;
[0044] If the first delay threshold is greater than or equal to the delay time, the 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 key prefixes and their corresponding latency thresholds. Different key prefixes can have different latency thresholds. Therefore, the first latency threshold for the corresponding key can be queried from this set. Furthermore, if no first latency threshold is found for a key in this set, a default latency threshold is used as the first latency threshold.
[0046] If the first latency threshold is less than the delay time, it indicates that the synchronization latency between the master and slave nodes is too high. To avoid the slave node's data not being synchronized, it is only possible to query from the master node. Otherwise, it indicates that the synchronization latency between the master and slave nodes is within the threshold. You can query the master node or the slave node, or you can query both the master node and the slave node at the same time.
[0047] In one embodiment, obtaining the first latency threshold corresponding to the data key includes:
[0048] If the client's global variables include a second latency threshold corresponding to the data key, the second latency threshold is determined as the first latency threshold;
[0049] If the client's global variables do not include the second latency threshold corresponding to the data key, the preset latency threshold is determined as the first latency threshold.
[0050] In this embodiment, in addition to the aforementioned masterPrefixs, bothPrefixs, and delayThresholdPrefixs sets, the global variables also include a delayThresholdMapping set. If a second delay threshold corresponding to a key exists in this set, it is used as the first delay threshold. If no second delay threshold corresponding to a key exists in this set, a preset delay threshold is determined as the first delay threshold.
[0051] In this embodiment, by introducing a comparison mechanism between a first latency threshold and the latency time, the data reading strategy can be dynamically adjusted according to the data synchronization status and access requirements. When the first latency threshold is less than the latency time, data is read from the master node to ensure data consistency and accuracy; while when the first latency threshold is greater than or equal to the latency time, data can be read from either the master node or a slave node to improve reading efficiency and load balancing. This strategy improves the flexibility and adaptability of data reading, enabling it to better meet the needs of different scenarios.
[0052] In one embodiment of this application, when the prefix type of the data key in the read request is a second type, after reading the target data from 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] If the prefix type of the data key in the read request is a third type, the target data of at least one of the master node or slave nodes is read.
[0054] In this embodiment, if the client determines that the key is not of the first or second type, but belongs to the third type, then it reads the target data from both the master node and the slave node. The third type refers to data key types that conform to the `bothPrefixs` set. If the key's prefix type is a type in the `bothPrefixs` set, then the client can query the target data from either the master node or the slave node.
[0055] By reading data from any node, whether it's the master or a slave node, the data reading pressure on the master node can be alleviated, and the efficiency of data reading can be improved.
[0056] In one embodiment of this application, when the prefix type of the data key in the read request is a third type, after reading the target data of at least one of the master node or slave nodes, the method further includes:
[0057] If the prefix type of the data key in the read request is not a third type, obtain the client's default read mode;
[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, second, and third types, then the client needs to use the default read mode preset in the client to read the data.
[0060] The default read mode is also represented as a global variable in the client, named `defaultReadModel`. The value of this variable determines which mode to use for data reading. Specifically, the default read mode values are `master`, `both`, and `delayThreshold`. `master` means querying only the master node, `both` means querying both master and slave nodes, and `delayThreshold` is determined based on synchronization latency and a latency threshold.
[0061] In one embodiment, reading 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 the first mode, the target data is read from the master node, where the first mode is the mode for reading data from the master node;
[0063] When the default read mode is the second mode, target data is read from at least one of the master node and the slave node, where the second mode is a mode in which data can be read from both 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 on the master node. The second mode is the both mode, in which the target data can be queried on either the master node or the slave node.
[0065] In this embodiment, by introducing a default read mode and selecting different read strategies based on different modes, different read requirements can be addressed more flexibly. In scenarios where data accuracy is critical, data can be read from the master node; while in scenarios where consistency requirements are less stringent, data can be read from the slave node to improve read efficiency and load balancing.
[0066] In one embodiment of this application, after reading target data from at least one of the master node and the slave node when the default read mode is the second mode, the method further includes:
[0067] When the default read mode is the third mode, if the 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.
[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 slave node according to the latency time and the third latency threshold.
[0070] Specifically, since the prefix type of the key does not belong to the second type, the key does not have a corresponding latency threshold. Therefore, the third latency threshold can be a preset latency threshold.
[0071] If the third latency threshold is greater than the latency time, it indicates that there is no data synchronization delay between the master node and the slave node, and their data is consistent. In this case, the target data can be queried from either the master node or the slave node. If the third latency threshold is less than the latency time, it indicates that there is a data synchronization delay between the master node and the slave node. To ensure the accuracy of the read data, data can only be read from the master node.
[0072] In this embodiment, by comparing the third delay threshold with the delay time, the target of the client reading data is determined, which can ensure reading performance while guaranteeing the accuracy of the read data.
[0073] In one embodiment of this application, before obtaining the read request initiated by the client, the method further includes:
[0074] The monitoring script is loaded into the master node, and the monitoring script is used to generate test key-value pairs;
[0075] The monitoring script is used to write the test key-value pair into the master node;
[0076] At preset intervals, the test key-value pairs are extracted from the master node and the slave node, wherein the test key-value pairs in the slave node are obtained through data synchronization with the master node;
[0077] The delay time is determined using the extracted test key-value pairs.
[0078] In this embodiment, a monitoring script is also configured in the client to determine the latency between the master and slave nodes. When the client starts, the monitoring script is loaded into the master node, and test key-value pairs are written to the master node through the monitoring script. The value of the key-value pair is in the format ${value}-${nowTime}, where ${value} is a fixed value (which can be any identifier), and ${nowTime} is the timestamp when the test key-value pair is written to the master node.
[0079] During data synchronization between the master and slave nodes, the slave node also synchronizes this test key-value pair. Therefore, the same test key-value pair is periodically read from both the master and slave nodes. 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] Extract the first test key-value pair from the master node, and extract the second test key-value pair from the slave node;
[0082] Determining the delay time using the extracted test key-value pairs 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 when the master node synchronizes the key-value pair to the slave node during data synchronization between the master and slave nodes. The first timestamp in the first key-value pair is the time when the first test pair was written to the master node. By calculating the difference between the second timestamp and the first timestamp, the latency required for data synchronization between the master and slave nodes can be obtained.
[0085] In this embodiment, by loading a monitoring script into the master node, test key-value pairs can be automatically generated and written. These test key-value pairs act as "probes" for data synchronization status, reflecting the data synchronization between the master and slave nodes in real time or periodically. Based on this data synchronization status, the node for reading data is determined, thereby improving the accuracy of data reading.
[0086] Based on the same inventive concept, embodiments of this application also provide an algorithm scheduling device. Specifically, in conjunction with... Figure 2 The algorithm scheduling device provided in the embodiments of this application will be described in detail.
[0087] Figure 2 This is a schematic diagram of the structure of an algorithm scheduling device provided in an embodiment of this application.
[0088] like Figure 2 As shown, the algorithm scheduling device 200 may include:
[0089] The first acquisition module 201 is used to acquire read requests initiated by the client, the read requests being used to read data from the master node and the slave node;
[0090] The first reading module 202 is used 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, based on 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, wherein 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] The acquisition submodule is used to acquire the first delay threshold corresponding to the data key;
[0094] The first reading submodule is used to read target data from the master node when the first delay threshold is less than the delay time.
[0095] The second reading submodule is used to read target data from 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] The first determining unit is configured to determine the second delay threshold as the first delay threshold when the global variables of the client include a second delay threshold corresponding to the data key.
[0098] The second determining unit is used to determine the preset delay threshold as the first delay threshold when the second delay threshold corresponding to the data key is not included in the global variables of the client.
[0099] Optionally, the algorithm scheduling device 200 is specifically used for:
[0100] If the prefix type of the data key in the read request is a third type, the target data of at least one of the master node or slave nodes is read.
[0101] Optionally, the algorithm scheduling device 200 further includes:
[0102] The second acquisition module is used to acquire the client's default read mode when the prefix type of the data key in the read request is not a third type.
[0103] The third reading module is used to read 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] The third reading submodule is used to read target data from the master node when the default reading mode is the first mode, wherein the first mode is the mode for reading data from 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 read mode is the second mode, wherein the second mode is a mode in which data can be read from both the master node and the slave node.
[0107] Optionally, the algorithm scheduling device 200 is specifically used for:
[0108] When the default read mode is the third mode, if the 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 used for:
[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 is used to load the monitoring script into the master node, and the monitoring script is used to generate test key-value pairs;
[0113] The writing module is used to write the test key-value pair into the master node using the monitoring script.
[0114] An extraction module is used to extract the test key-value pairs from the master node and the slave node at preset time intervals, wherein the test key-value pairs in the slave node are obtained through data synchronization with the master node;
[0115] A determination module is used to determine the delay time using the extracted test key-value pairs.
[0116] Optionally, the extraction module is specifically used for:
[0117] Extract the first test key-value pair from the master node, and extract the second test key-value pair from the slave node;
[0118] Optionally, a module is defined, 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 data reading method. All implementation methods in the above method embodiments are applicable to the embodiments of this device and can achieve the same technical effect.
[0121] Figure 3 A schematic diagram of the hardware structure of the terminal device provided in an embodiment of this 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), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0124] Memory 302 may include mass storage for data or instructions. For example, and not limitingly, memory 302 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 302 may include removable or non-removable (or fixed) media. Where appropriate, memory 302 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 302 is non-volatile solid-state memory.
[0125] In certain embodiments, memory 302 may include read-only memory (ROM), random access memory (RAM), disk storage media device, optical storage media device, flash memory device, electrical, optical, or other physical / tangible memory storage device. Thus, generally, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) 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 one aspect of this disclosure.
[0126] The processor 301 implements any of the data reading methods described in the above embodiments by reading and executing computer program instructions stored in the memory 302.
[0127] In one example, the terminal device may also include a communication interface 303 and a bus 310. Wherein, for example... Figure 3 As shown, the processor 301, memory 302, and communication interface 303 are connected through bus 310 and complete communication with each other.
[0128] The communication interface 303 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0129] Bus 310 includes hardware, software, or both, that couples components of an online data traffic metering device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 310 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, any suitable bus or interconnect is contemplated herein.
[0130] Furthermore, in conjunction with the data reading methods in the above embodiments, this application embodiment can provide a computer storage medium for implementation. This computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the data reading methods in the above embodiments.
[0131] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this 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, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on 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, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0133] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. 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 embodiments, or in a different order, or several steps can be performed simultaneously.
[0134] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, 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 apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable algorithm scheduling apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. 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 is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0135] The above are merely specific embodiments of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A data reading method, characterized in that, The method includes: Obtain read requests initiated by the client, which are used to read data from the master node and slave node; If the prefix type of the data key in the read request is of type 1, read the target data from the master node; If 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, wherein the delay time is the time required for data synchronization between the master node and the slave node; When 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, including: Obtain the first delay threshold corresponding to the data key; If the first delay threshold is less than the delay time, read the target data from the master node; If the first delay threshold is greater than or equal to the delay time, the target data of at least one of the master node and the slave node is read.
2. The data reading method as described in claim 1, characterized in that, The step of obtaining the first delay threshold corresponding to the data key includes: If the client's global variables include a second latency threshold corresponding to the data key, the second latency threshold is determined as the first latency threshold; If the client's global variables do not include the second latency threshold corresponding to the data key, the preset latency threshold is determined as the first latency threshold.
3. The data reading method as described in claim 1, characterized in that, When the prefix type of the data key in the read request is the second type, the method further includes 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, after reading the target data of at least one of the master node and the slave node, the method further includes: If the prefix type of the data key in the read request is of type 3, the target data of at least one of the master node and slave node is read.
4. The data reading method as described in claim 3, characterized in that, When the prefix type of the data key in the read request is a third type, after reading the target data of at least one of the master node and slave node, the method further includes: If the prefix type of the data key in the read request is not a third type, obtain the client's default read mode; According to the default read mode, target data is read from at least one of the master node and the slave node.
5. The data reading method as described in claim 4, 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 the first mode, the target data is read from the master node, where the first mode is the mode for reading data from the master node; When the default read mode is the second mode, target data is read from at least one of the master node and the slave node, where the second mode is a mode in which data can be read from both the master node and the slave node.
6. The data reading method as described in claim 5, characterized in that, 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: When the default read mode is the third mode, if the 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.
7. The data reading method as described in claim 5, characterized in that, 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: 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.
8. The data reading method as described in claim 1, characterized in that, Before obtaining the read request initiated by the client, the method further includes: The monitoring script is loaded into the master node, and the monitoring script is used to generate test key-value pairs; The monitoring script is used to write the test key-value pair into the master node; At preset intervals, the test key-value pairs are extracted from the master node and the slave node, wherein the test key-value pairs in the slave node are obtained through data synchronization with the master node; The delay time is determined using the extracted test key-value pairs.
9. The data reading method as described in claim 8, characterized in that, The test key-value pair includes a first test key-value pair and a second test key-value pair; Extracting the test key-value pair from the master node and the slave node includes: Extract the first test key-value pair from the master node, and extract the second test key-value pair from the slave node; Determining the delay time using the extracted test key-value pairs 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
Data reading method and terminal
CN113760934A
Database access method and device, equipment and storage medium
CN114880336A