Data reading method and device, electronic equipment and readable storage medium

CN118170781BActive Publication Date: 2026-10-13DUXIAOMAN TECH (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410414478.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-08
Publication Date
2026-10-13
Estimated Expiration
2044-04-08

AI Technical Summary

Technical Problem

[0003]有鉴于此,本发明实施例提供了一种数据读取方法、装置、电子设备及可读存储介质,以解决目标数据同时被更新和读取时,造成的缓存与数据库不一致的问题

Benefits of technology

[0047]本发明实施例中提供的一个或多个技术方案,在接收到客户端的数据查询指令时,根据第一存储位置中的注解信息获取其内部第一目标数据的状态,根据注解信息更新第一存储位置中读入的第一目标数据,实现基于注解信息设置第一存储位置中数据的缓存逻辑,避免数据库与第一存储位置中数据不一致的情况发生。再利用分布式锁锁定第一存储位置,实现缓存逻辑与业务逻辑的隔离,防止在数据查询过程中线程间相互干扰,进一步保障在数据查询过程中,数据库与第一存储位置中数据的一致性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118170781B_ABST
    Figure CN118170781B_ABST
Patent Text Reader

Abstract

The application provides a data reading method and device, electronic equipment and readable storage medium, comprising: receiving a data query instruction of a client; obtaining annotation information of data in a first storage location; updating first target data in the first storage location according to the annotation information; obtaining a state of a distributed lock of the first storage location; locking a first thread of the server side corresponding to the data query instruction in a state of being not locked, the first thread being a data update channel of the first target data in the server side; and outputting the first target data from the first storage location to the client according to the data query instruction. The application sets a cache logic of data in the first storage location based on annotation information, thereby avoiding a situation of inconsistency between a database and data in the first storage location.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data interaction technology, and in particular to a data reading method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] In current network services, caching typically employs a bypass caching model, such as using caching middleware. A query request first needs to read the cache; if the cache does not exist, it loads data from the database into the cache and sets an expiration time. However, if the target data is being updated, the data retrieved from the cache by the query request will not be the latest version, leading to inconsistencies between the cached and database data. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a data reading method, apparatus, electronic device, and readable storage medium to solve the problem of inconsistency between cache and database when target data is updated and read simultaneously.

[0004] According to one aspect of the present invention, a data reading method is provided, applied on a server side, comprising:

[0005] Receive data query commands from the client;

[0006] Obtain annotation information of data in the first storage location. The annotation information includes annotations for no data, annotations for data processing, and annotations for processed data. Annotations for no data are used to indicate that the first target data does not exist in the first storage location. Annotations for data processing are used to indicate that the first target data in the first storage location is being processed. Annotations for processed data are used to indicate that the first target data in the first storage location is the latest data. The first target data is the data corresponding to the data query instruction.

[0007] Update the first target data in the first storage location based on the annotation information;

[0008] Obtain the state of the distributed lock at the first storage location;

[0009] In the unlocked state, lock the first thread on the server side corresponding to the data query command; or, in the locked state, wait for the locking state to end before locking the first thread on the server side corresponding to the data query command. The first thread is the data update channel for the first target data on the server side.

[0010] According to the data query instruction, the first target data is output from the first storage location to the client.

[0011] Optionally, the data reading method also includes:

[0012] Receive data update instructions;

[0013] Lock the third thread on the server side corresponding to the data update command. The third thread is the data update channel for the second target data on the server side. The second target data is the data corresponding to the data update command.

[0014] Update the second target data in the first database and the second database, with the second database serving as a backup for the first database;

[0015] Write the second target data from the first database to the first storage location and end the locked state.

[0016] Optionally, the annotation information is no data annotation;

[0017] Based on the annotation information, update the first target data in the first storage location, including:

[0018] Write the first target data corresponding to the data query instruction in the second database into the first storage location;

[0019] Update the annotation information in the first storage location to the processed annotation.

[0020] Optionally, the annotation information is annotations during data processing or already processed annotations;

[0021] Based on the annotation information, update the first target data in the first storage location, including:

[0022] Lock the second thread in the first storage location that corresponds to the first target data. The second thread is the data update channel for the first target data in the server.

[0023] Write the first target data corresponding to the data query instruction in the first database to the first storage location, and end the locked state.

[0024] According to a second aspect of the present invention, a data reading device is provided, applied to a server, comprising:

[0025] The first receiving module is used to receive data query commands from the client.

[0026] The first acquisition module is used to acquire annotation information of data in the first storage location. The annotation information includes no data annotation, data processing annotation and processed annotation. The no data annotation is used to indicate that the first target data does not exist in the first storage location. The data processing annotation is used to indicate that the first target data in the first storage location is being processed. The processed annotation is used to indicate that the first target data in the first storage location is the latest data. The first target data is the data corresponding to the data query instruction.

[0027] The first data caching module is used to update the first target data in the first storage location according to the annotation information;

[0028] The status query module is used to obtain the status of the distributed lock in the first storage location;

[0029] The first processing module is used to lock the first thread on the server side corresponding to the data query instruction when the state is unlocked, or to lock the first thread on the server side corresponding to the data query instruction when the state is locked and the locking state ends. The first thread is the data update channel for the first target data on the server side.

[0030] The first output module is used to output the first target data from the first storage location to the client according to the data query instruction.

[0031] Optionally, the data reading device further includes:

[0032] The second receiving module is used to receive data update instructions;

[0033] The second processing module is used to lock the third thread on the server side corresponding to the data update instruction. The third thread is the data update channel for the second target data on the server side. The second target data is the data corresponding to the data update instruction.

[0034] The data update module is used to update the second target data in the first database and the second database, with the second database serving as a backup database for the first database.

[0035] The second data caching module is used to write the second target data from the first database to the first storage location and end the locked state.

[0036] Optionally, the first data caching module includes:

[0037] The first data reading module is used to write the first target data corresponding to the data query instruction in the second database into the first storage location;

[0038] The update submodule is used to update the annotation information in the first storage location with the processed annotations.

[0039] Optionally, the first data caching module includes:

[0040] The third processing module is used to lock the second thread corresponding to the first target data in the first storage location. The second thread is the data update channel for the first target data in the server.

[0041] The second data reading module is used to write the first target data corresponding to the data query instruction in the first database into the first storage location and end the locked state.

[0042] According to a third aspect of the present invention, an electronic device is provided, comprising:

[0043] Processor; and

[0044] Stored program memory,

[0045] The program includes instructions that, when executed by a processor, cause the processor to perform a method according to any one of the first aspects of the invention.

[0046] According to a fourth aspect of the invention, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause a computer to perform a method according to any one of the first aspects of the invention.

[0047] One or more technical solutions provided in this embodiment of the invention, upon receiving a data query instruction from a client, obtain the state of the first target data within the first storage location based on annotation information, and update the first target data read into the first storage location according to the annotation information. This achieves caching logic for the data in the first storage location based on annotation information, preventing inconsistencies between the database and the data in the first storage location. Furthermore, a distributed lock is used to lock the first storage location, isolating the caching logic from the business logic, preventing interference between threads during data querying, and further ensuring consistency between the database and the data in the first storage location during the data query process. Attached Figure Description

[0048] Further details, features, and advantages of the invention are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:

[0049] Figure 1 A flowchart of a data reading method according to an exemplary embodiment of the present invention is shown;

[0050] Figure 2 The diagram illustrates the implementation steps of a data reading method according to an exemplary embodiment of the present invention;

[0051] Figure 3 A schematic block diagram of a data reading apparatus according to an exemplary embodiment of the present invention is shown;

[0052] Figure 4 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present invention is shown. Detailed Implementation

[0053] Embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While some embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the invention. It should be understood that the accompanying drawings and embodiments are for illustrative purposes only and are not intended to limit the scope of protection of the invention.

[0054] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.

[0055] The term "comprising" and its variations as used herein are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc., mentioned in this invention are used only to distinguish different devices, modules, or units, and are not intended to limit the order of functions performed by these devices, modules, or units or their interdependencies.

[0056] It should be noted that the terms "a" and "a plurality of" used in this invention are illustrative rather than restrictive. Those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0057] The names of the messages or information exchanged between the multiple devices in the embodiments of the present invention are for illustrative purposes only and are not intended to limit the scope of these messages or information.

[0058] The present invention will now be described with reference to the accompanying drawings. The technical solutions provided by the embodiments of the present invention will be explained in detail through specific examples and application scenarios.

[0059] When reading data from the server, it is necessary to cache the data in the primary storage location to improve data access speed, user experience, system performance and stability, and reduce the pressure on the database for data queries. However, introducing caching increases the maintenance complexity of the server side, and the data caching and invalidation maintenance logic is complex. Hard-coding maintenance in projects is difficult, and errors can lead to serious problems such as cache inconsistencies and API exceptions.

[0060] In view of the above, the present invention provides a data reading method, apparatus, electronic device and readable storage medium, wherein the data reading method is applied to any electronic device with data reading function, including but not limited to: personal mobile terminal device, computer or server device, etc.

[0061] like Figure 1 As shown, Figure 1 This is a flowchart illustrating a data reading method provided in an embodiment of the present invention. The data reading method may include the following steps S101 to S106:

[0062] S101 receives data query instructions from the client.

[0063] S102, obtain the annotation information of the data in the first storage location. The annotation information includes no data annotation, data processing annotation and processed annotation. The no data annotation is used to indicate that the first target data does not exist in the first storage location. The data processing annotation is used to indicate that the first target data in the first storage location is being processed. The processed annotation is used to indicate that the first target data in the first storage location is the latest data. The first target data is the data corresponding to the data query instruction.

[0064] As one implementation, when reading data from the server, the first storage location serves as a bypass cache location for caching data in either the first database or the second database. The first database is the primary database, and the second database is a backup database for the first database.

[0065] The annotation information for the first storage location is set to characterize the state of the data within that location. The annotation information includes three categories: no data, data processing, and processed. A no data annotation indicates that the first target data corresponding to the data query instruction does not exist in the first storage location. A data processing annotation indicates that the first target data corresponding to the data query instruction exists in the first storage location, but the data in the first database or second database is being processed and has undergone changes. A processed annotation indicates that the first target data corresponding to the data query instruction exists in the first storage location, but the data in the first database or second database has not been processed and has not changed.

[0066] S103, Update the first target data in the first storage location according to the annotation information.

[0067] As one implementation method, the first target data in the cache is updated based on the annotation information. Specifically, if the annotation information is "no data annotation," the first target data is retrieved from either the first or second database and cached in the first storage location, thus updating the data in the first storage location. If the first storage location is full, the earliest cached data is deleted in chronological order to provide a cache location for the first target data. To avoid conflicts with other operations in the first database (which serves as the primary database), it is often preferable to retrieve the first target data from the backup second database for caching.

[0068] When the annotation information is a data processing annotation, it indicates that the first target data corresponding to the data query instruction exists in the first storage location, but the first target data in the first database is being processed, such as an update process. At this time, the data in the second database has not yet been updated according to the update in the first database. Therefore, the data in both the second database and the first storage location are inconsistent with the updated data in the first database. In this case, it is necessary to retrieve the updated first target data from the first database to update the first target data in the first storage location. Alternatively, after the second database is updated according to the first database, the updated first target data can be retrieved from the second database.

[0069] If the annotation information is "processed," it indicates that the first target data corresponding to the data query instruction exists in the first storage location, and the first target data in both the first and second databases has not been processed, meaning no data update has occurred. In this case, the first target data in the first storage location does not need to be updated.

[0070] In one specific implementation, upon receiving a data query instruction, it is determined that the first target data corresponding to the data query instruction is A, and the annotation information of A in the first storage location is retrieved. If the annotation information indicates no data annotation, it means that A is not cached in the first storage location. In this case, the first target data A is retrieved from the first database or the second database and cached in the first storage location, thereby updating the data in the first storage location.

[0071] When the annotation information is a data processing annotation, it indicates that the first target data A corresponding to the data query instruction exists in the first storage location, but the first target data in the first database is being processed, for example, updated to A1. At this time, the data in the second database has not yet been updated according to the update in the first database, and the data in the second database and the data in the first storage location are still A. In this case, it is necessary to retrieve the updated A1 from the first database and update the first target data in the first storage location to A1. Alternatively, after the second database is updated to A1 according to the first database, the updated A1 is retrieved from the second database.

[0072] If the annotation information is "processed," it indicates that the first target data A corresponding to the data query instruction exists in the first storage location, and A in both the first and second databases has not been processed, meaning no data update has occurred. In this case, the first target data in the first storage location does not need to be updated.

[0073] As a specific implementation method, A in the first database and the second database is called metadata, and its metadata format is as follows:

[0074] Metadata key format: meta:customerId;

[0075] Metadata value format:

[0076]

[0077] Here, meta refers to the meta tag, which is used to provide metadata about the HTML document; customerId refers to the user ID; processing and processed are annotation information that characterizes the status of data in the first storage location.

[0078] The data A in the first storage location is called cached data, and its cached data format is as follows:

[0079] Cache data key format: customerId:relationInfo

[0080] Cache data value format:

[0081] id It is associated with the ID in the metadata and controls logic such as cache invalidation. data Actual cached business data

[0082] Here, relationInfo refers to the key generated by parsing annotation information in aspect code.

[0083] S104, obtain the state of the distributed lock at the first storage location;

[0084] As an implementation method, a distributed lock has two states: locked and unlocked. In a distributed system, when different processes or threads access shared resources simultaneously, resource contention occurs, which can lead to program errors if left uncontrolled. Distributed locks employ a mutual exclusion mechanism to prevent interference between threads or processes, thus ensuring data consistency. The use of distributed locks prevents situations where client A is reading data while client B is simultaneously updating data.

[0085] S105, in the unlocked state, lock the first thread of the server corresponding to the data query instruction; or, in the locked state, wait for the locking state to end before locking the first thread of the server corresponding to the data query instruction. The first thread is the data update channel for the first target data in the server.

[0086] As one implementation method, when the distributed lock is not engaged, the first thread on the server side corresponding to the data query command is locked to prevent other clients from operating on the data corresponding to the first thread. This prevents inconsistencies in the data in the first storage location when multiple clients perform read and write operations simultaneously. When the lock is engaged, the first target data in the first storage location is output to the client.

[0087] When a distributed lock is acquired, it indicates that a client is interacting with the server, and the client needs to wait for the operation corresponding to the lock to complete before locking the first thread according to the data query command. This protects the ongoing data interaction from being affected by the data query command. Mutual exclusion is a key characteristic of distributed locks; at any given time, only one thread can hold the lock.

[0088] S106, according to the data query instruction, the first target data is output from the first storage location to the client.

[0089] As one implementation method, when the first thread is locked according to the data query instruction, the first target data cached in the first storage location is returned to the client, thus completing the reading of the data according to the data query instruction.

[0090] In one embodiment of the present invention, the data reading method further includes:

[0091] S107, Receive data update command;

[0092] S108, lock the third thread on the server side corresponding to the data update instruction. The third thread is the data update channel for the second target data on the server side. The second target data is the data corresponding to the data update instruction.

[0093] S109, Update the second target data in the first database and the second database, with the second database serving as a backup database for the first database;

[0094] S110, write the second target data from the first database to the first storage location and end the locking state.

[0095] As one implementation, in addition to receiving data query commands, the server also receives data update commands. Based on these commands, the server locks the data update channel for the second target data, ensuring that this data is not read during the update process. The second target data B in the first and second databases is then updated according to the data update commands, written to the first storage location, and the locking state is lifted to allow operations by other threads.

[0096] In one specific implementation, upon receiving a data update instruction, the first and second databases update according to the user-written update instruction. A distributed lock locks the third thread on the server side, and the locking time of the distributed lock can be flexibly set by the updating user. During the update, the metadata status in the first and second databases is changed to "processing" to indicate that the data is in an update state. Simultaneously, a universally unique identifier (UUID) is generated in the updated metadata based on the write operation to represent the data update information. After the first database completes the update, the metadata status in both the first and second databases is changed to "processed," the second target data in the first database is written to the first storage location, and the locking state is released.

[0097] In one embodiment of the present invention, the annotation information is no data annotation;

[0098] S103, based on the annotation information, update the first target data in the first storage location, including:

[0099] S1031, Write the first target data corresponding to the data query instruction in the second database into the first storage location;

[0100] S1032, update the annotation information in the first storage location to the processed annotation.

[0101] As an implementation approach, in order to avoid conflicts with other operations in the primary database, it is common practice to retrieve the first target data from the backup secondary database for caching.

[0102] When the annotation information is empty, the second database synchronizes the data change information with the first database, retrieves the first target data from the second database, and caches it in the first storage location, thus updating the data in the first storage location. If the first storage location is full, the earliest cached data is deleted in chronological order to make room for the first target data.

[0103] In one embodiment of the present invention, the annotation information is an annotation during data processing or a processed annotation;

[0104] S103, based on the annotation information, update the first target data in the first storage location, including:

[0105] S1033, Lock the second thread in the first storage location that corresponds to the first target data;

[0106] S1034, write the first target data corresponding to the data query instruction in the first database to the first storage location, and end the locked state.

[0107] As one implementation, when the annotation information is a data processing annotation, it indicates that the first target data corresponding to the data query instruction exists in the first storage location, but the first target data in the first database is being processed, such as through an update process. At this time, the data in the second database has not yet been updated according to the update in the first database, and the data in both the second database and the first storage location are inconsistent with the updated data in the first database. In this case, the second thread corresponding to the first target data in the first storage location is locked to complete the update of the first target data in the first storage location. Here, the second thread is the data update channel for the first target data on the server side, and the locking function is to prevent the operation of reading the first target data in the first storage location during the update process. After writing the first target data corresponding to the data query instruction in the first database into the first storage location, the locking state is released.

[0108] If the annotation information indicates that the first target data corresponding to the data query instruction exists in the first storage location, and the first target data in both the first and second databases has not been processed and has not been updated, then the first target data in the first storage location does not need to be updated. However, in this case, the second thread corresponding to the first target data in the first storage location is locked to complete the reading of the first target data in the first storage location. The purpose of locking is to prevent the operation of updating the first target data in the first storage location during the reading process. After writing the first target data corresponding to the data query instruction in the first database to the first storage location, the locking state is released.

[0109] In one embodiment of the present invention, such as Figure 2The diagram illustrates the process of a client sending data query and update commands. Spring is an open-source Java platform framework, and Spring annotations are used to add metadata to Java code, enabling the Spring container to understand and manipulate these code elements. After the client sends a data query command, the server retrieves the annotation information of the cached data and the status of the Redission distributed lock. In this embodiment, the key-value storage system Redis is selected as the cache, i.e., the first storage location. Then, based on the annotation information, the server checks whether the first target data exists in the cache. If it does not exist, the Redission distributed lock is used to write the first target data from the MySQL database to the Redis cache. If it exists, the first target data in the cache is returned to the client.

[0110] After the client sends a data update command, the server obtains the annotation information of the data in the cache and the status of the Redission distributed lock. Then, it uses the Redission distributed lock to lock the corresponding thread and writes the first target data to be updated from the MySQL database into the cache Redis.

[0111] The data reading method provided in this embodiment of the invention, upon receiving a data query instruction from a client, obtains the state of the first target data within the first storage location based on the annotation information, updates the first target data read into the first storage location according to the annotation information, and implements caching logic for the data in the first storage location based on the annotation information, thus avoiding inconsistencies between the database and the data in the first storage location. Furthermore, a distributed lock is used to lock the first storage location, achieving isolation between the caching logic and the business logic, preventing interference between threads during data querying, and further ensuring consistency between the database and the data in the first storage location during the data query process.

[0112] Corresponding to the above embodiments, see [link to relevant documentation]. Figure 3 This invention also provides a data reading device 300, applied to a server, the data reading device 300 comprising:

[0113] The first receiving module 301 is used to receive data query instructions from the client;

[0114] The first acquisition module 302 is used to acquire annotation information of data in the first storage location. The annotation information includes no data annotation, data processing annotation and processed annotation. The no data annotation is used to indicate that the first target data does not exist in the first storage location. The data processing annotation is used to indicate that the first target data in the first storage location is being processed. The processed annotation is used to indicate that the first target data in the first storage location is the latest data. The first target data is the data corresponding to the data query instruction.

[0115] The first data caching module 303 is used to update the first target data in the first storage location according to the annotation information;

[0116] The status query module 304 is used to obtain the status of the distributed lock in the first storage location;

[0117] The first processing module 305 is used to lock the first thread on the server side corresponding to the data query instruction when the state is unlocked, or to lock the first thread on the server side corresponding to the data query instruction when the state is locked and the locking state ends. The first thread is the data update channel for the first target data on the server side.

[0118] The first output module 306 is used to output the first target data from the first storage location to the client according to the data query instruction.

[0119] Optionally, the data reading device 300 further includes:

[0120] The second receiving module 307 is used to receive data update instructions;

[0121] The second processing module 308 is used to lock the third thread on the server side corresponding to the data update instruction. The third thread is the data update channel for the second target data on the server side. The second target data is the data corresponding to the data update instruction.

[0122] The data update module 309 is used to update the second target data in the first database and the second database, where the second database is a backup database for the first database.

[0123] The second data caching module 310 is used to write the second target data from the first database to the first storage location and end the locked state.

[0124] Optionally, the first data cache module 303 includes:

[0125] The first data reading module 3031 is used to write the first target data corresponding to the data query instruction in the second database into the first storage location;

[0126] The update submodule 3032 is used to update the annotation information in the first storage location to the processed annotation.

[0127] Optionally, the first data cache module 303 includes:

[0128] The third processing module 3033 is used to lock the second thread in the first storage location corresponding to the first target data. The second thread is the data update channel of the first target data in the server.

[0129] The second data reading module 3034 is used to write the first target data corresponding to the data query instruction in the first database into the first storage location and end the locked state.

[0130] The data reading device provided in this embodiment of the invention, upon receiving a data query instruction from a client, obtains the state of the first target data within the first storage location based on the annotation information, and updates the first target data read into the first storage location according to the annotation information. This implements caching logic for the data in the first storage location based on the annotation information, preventing inconsistencies between the database and the data in the first storage location. Furthermore, a distributed lock is used to lock the first storage location, isolating the caching logic from the business logic, preventing interference between threads during data querying, and further ensuring consistency between the database and the data in the first storage location during the data query process.

[0131] An exemplary embodiment of the present invention also provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, which, when executed by the at least one processor, causes the electronic device to perform a method according to an embodiment of the present invention.

[0132] An exemplary embodiment of the present invention also provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to an embodiment of the present invention.

[0133] An exemplary embodiment of the present invention also provides a computer program product, including a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to an embodiment of the present invention.

[0134] refer to Figure 4 The present invention will now be described in the form of a structural block diagram of an electronic device 400 that can serve as a server or client of the present invention, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0135] like Figure 4As shown, the electronic device 400 includes a computing unit 401, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 402 or a computer program loaded from a storage unit 408 into a random access memory (RAM) 403. The RAM 403 may also store various programs and data required for the operation of the electronic device 400. The computing unit 401, ROM 402, and RAM 403 are interconnected via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0136] Multiple components in electronic device 400 are connected to I / O interface 405, including: input unit 406, output unit 407, storage unit 408, and communication unit 409. Input unit 406 can be any type of device capable of inputting information to electronic device 400. Input unit 406 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 407 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 408 may include, but is not limited to, disks and optical discs. Communication unit 409 allows electronic device 400 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth™ devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.

[0137] The computing unit 401 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 401 performs the various methods and processes described above. For example, in some embodiments, the data reading method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 408. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 400 via ROM 402 and / or communication unit 409. In some embodiments, the computing unit 401 may be configured to perform the data reading method by any other suitable means (e.g., by means of firmware).

[0138] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data reading device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0139] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0140] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.

[0141] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0142] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0143] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.

Claims

1. A data reading method, applied on a server side, characterized in that, include: Receive data query commands from the client; Obtain annotation information of data in the first storage location. The annotation information includes annotations for no data, data processing in progress, and processed data. The annotation for no data indicates that the first target data does not exist in the first storage location. The annotation for data processing in progress indicates that the first target data corresponding to the data query instruction exists in the first storage location, but the first target data in the first database or the second database is being processed, the first target data has changed, and the second database is a backup database for the first database. The annotation for processed data indicates that the first target data in the first storage location is the latest data, and the first target data is the data corresponding to the data query instruction. Update the first target data in the first storage location according to the annotation information; Obtain the state of the distributed lock at the first storage location; In the unlocked state, the first thread of the server corresponding to the data query instruction is locked; or, in the locked state, after the locking state ends, the first thread of the server corresponding to the data query instruction is locked, wherein the first thread is the data update channel for the first target data in the server. According to the data query instruction, the first target data is output from the first storage location to the client.

2. The data reading method according to claim 1, characterized in that, The data reading method further includes: Receive data update instructions; Lock the third thread on the server side corresponding to the data update instruction. The third thread is the data update channel for the second target data on the server side. The second target data is the data corresponding to the data update instruction. Update the second target data in the first and second databases; Write the second target data from the first database to the first storage location and end the locked state.

3. The data reading method according to claim 1, characterized in that, The annotation information is a no-data annotation; The step of updating the first target data in the first storage location according to the annotation information includes: Write the first target data corresponding to the data query instruction in the second database into the first storage location; Update the annotation information in the first storage location to the processed annotation.

4. The data reading method according to claim 1, characterized in that, The annotation information is either an annotation in data processing or an annotation that has already been processed. The step of updating the first target data in the first storage location according to the annotation information includes: Lock the second thread in the first storage location that corresponds to the first target data, where the second thread is the data update channel for the first target data in the server. Write the first target data corresponding to the data query instruction in the first database into the first storage location, and end the locked state.

5. A data reading device, applied to a server, characterized in that, include: The first receiving module is used to receive data query commands from the client. The first acquisition module is used to acquire annotation information of data in the first storage location. The annotation information includes annotations for no data, annotations for data processing, and annotations for processed data. The annotation for no data indicates that the first target data does not exist in the first storage location. The annotation for data processing indicates that the first target data corresponding to the data query instruction exists in the first storage location, but the first target data in the first database or the second database is being processed, the first target data has changed, and the second database is a backup database for the first database. The annotation for processed data indicates that the first target data in the first storage location is the latest data, and the first target data is the data corresponding to the data query instruction. The first data caching module is used to update the first target data in the first storage location according to the annotation information; The status query module is used to obtain the status of the distributed lock at the first storage location; The first processing module is configured to lock the first thread of the server corresponding to the data query instruction when the state is unlocked, or, when the state is locked, wait for the locking state to end before locking the first thread of the server corresponding to the data query instruction, wherein the first thread is the data update channel for the first target data in the server. The first output module is used to output the first target data from the first storage location to the client according to the data query instruction.

6. The data reading device according to claim 5, characterized in that, The data reading device further includes: The second receiving module is used to receive data update instructions; The second processing module is used to lock the third thread on the server side corresponding to the data update instruction. The third thread is the data update channel for the second target data on the server side, and the second target data is the data corresponding to the data update instruction. The data update module is used to update the second target data in the first database and the second database; The second data caching module is used to write the second target data from the first database to the first storage location and end the locked state.

7. The data reading device according to claim 5, characterized in that, The first data caching module includes: The first data reading module is used to write the first target data corresponding to the data query instruction in the second database into the first storage location; The update submodule is used to update the annotation information in the first storage location to the processed annotation.

8. The data reading device according to claim 5, characterized in that, The first data caching module includes: The third processing module is used to lock the second thread in the first storage location corresponding to the first target data, and the second thread is the data update channel of the first target data in the server. The second data reading module is used to write the first target data corresponding to the data query instruction in the first database into the first storage location and end the locked state.

9. An electronic device, comprising: processor; as well as Stored program memory, The program includes instructions that, when executed by the processor, cause the processor to perform the method according to any one of claims 1-4.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-4.

Citation Information

Patent Citations

  • Cache-based data update method and server

    CN108429777A

  • Data cache processing method, device and equipment and cache component

    CN110989939A