Data reading method and data storage method
By dividing data in the local cache of a distributed system and using the same version of data packets to store data, the data consistency problem in distributed systems is solved, efficient data reading and storage is achieved, and the scalability and availability of the system is improved.
Patent Information
- Application Number
- CN202411648420.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-11
AI Technical Summary
In distributed systems, ensuring that all instances read data from cache remains consistent is an extremely critical issue.
Data reading and storage methods are implemented by pre-dividing data in the local cache and using the same data packet to store data into a group of data using the same version. The specific steps include receiving a read request, determining an appropriate data packet from the multiple data packets based on the request time and version information, and returning the corresponding data.
Through this method, it is possible to ensure the consistency of each application when reading data from the cache based on version information and effective time in a distributed system, solve the single point of failure and performance bottleneck problems of centralized cache, and improve the scalability and availability of the system.
Smart Images

Figure CN119597841A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical fields of distributed systems, data reading, and data storage, and in particular to a data reading method and a data storage method. Background Art
[0002] In traditional centralized software architectures, software systems usually use caching technology to store data that is frequently read but not in large quantities locally to improve system performance. However, in this way, data is concentrated on a single or a small number of cache nodes, which can easily lead to performance bottlenecks and single points of failure.
[0003] Distributed cache is suitable for large-scale systems with distributed architecture and high concurrency scenarios, and can provide good scalability and availability. Assume that there are multiple application instances running on different servers at the same time, and these instances together constitute a distributed system. When one of the instances is processing business logic, if it finds that some data can be cached to improve the performance of subsequent access, the instance will write the data to the cache. In order to enhance the high availability and fault tolerance of cached data, distributed systems generally adopt data replication or synchronization mechanisms. This means that once an instance writes data to the cache, the data will be copied or synchronized to the caches of other instances. However, in this process, ensuring that the data read from the cache by all instances remains consistent has become an extremely critical issue in distributed systems. Summary of the invention
[0004] The present application proposes a data reading method and a data storage method.
[0005] In a first aspect, an embodiment of the present application proposes a data reading method, which is applied to any application instance of a plurality of application instances included in a distributed system, wherein the application instance divides the data in advance, and uses the same data group of the same version to store the data divided into a group in a local cache; the method comprises: receiving a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version; determining a first data group of a first version from a plurality of data groups according to a request time corresponding to the read request, a name of the data group requested by the read request, and at least one of the version information; wherein at least two versions of the first data are stored in the first data group of the first version, and different versions of the first data have different effective times; determining first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective times of the at least two versions of the first data; and sending the first data to be returned to the application.
[0006] The second aspect of the present application proposes a data storage method, which is applied to any application instance of multiple application instances included in a distributed system, and the application instance divides the data in advance, and uses the same data group of the same version to store the data divided into a group in the local cache; the method includes: receiving a first update notification sent by a target service included in the distributed system; wherein the first update notification is used to indicate an update of second data, and the second data is stored in any data group of any version; determining a second data group of a second version from multiple data groups according to the name and version information of the data group notified by the first update notification; using the second data group of the second version to store the updated second data; wherein the effective time of the second data is different from the effective time of the updated second data, and the second data and the updated second data are two versions of the second data stored in the second data group of the second version.
[0007] In a third aspect, an embodiment of the present application proposes a data reading device, which is applied to any application instance of a plurality of application instances included in a distributed system, wherein the application instance divides the data in advance and uses the same data group of the same version to store the data divided into a group in a local cache; the device comprises: a first sending and receiving module, which is used to receive a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version; a first determining module, which is used to determine a first data group of a first version from a plurality of data groups according to a request time corresponding to the read request, a name of the data group requested by the read request, and at least one of the version information; wherein at least two versions of the first data are stored in the first data group of the first version, and the effective time of the first data of different versions is different; a second determining module, which is used to determine the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data; and a sending module, which is used to send the first data to be returned to the application.
[0008] In a fourth aspect, an embodiment of the present application proposes a data storage device, which is applied to any application instance of a plurality of application instances included in a distributed system, wherein the application instance divides the data in advance, and uses the same data group of the same version to store the data divided into a group in a local cache; the device comprises: a second receiving module, which is used to receive a first update notification sent by a target service included in the distributed system; wherein the first update notification is used to indicate an update of second data, and the second data is stored in any data group of any version; a third determination module, which is used to determine a second data group of a second version from a plurality of data groups according to the name and version information of the data group notified by the first update notification; a storage module, which is used to use the second data group of the second version to store the updated second data; wherein the effective time of the second data is different from the effective time of the updated second data, and the second data and the updated second data are two versions of the second data stored in the second data group of the second version.
[0009] The fifth aspect embodiment of the present application proposes an electronic device, including: a memory and a processor; the memory stores computer instructions, and when the computer instructions are executed by the processor, the data reading method in the first aspect embodiment of the present application is implemented, or the data storage method in the second aspect embodiment of the present application is implemented.
[0010] The sixth aspect embodiment of the present application proposes a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the data reading method in the first aspect embodiment of the present application, or implements the data storage method in the second aspect embodiment of the present application.
[0011] The seventh aspect embodiment of the present application proposes a computer program product, including: a computer program, which, when executed by a processor, implements the data reading method in the first aspect embodiment of the present application, or implements the data storage method in the second aspect embodiment of the present application.
[0012] The technical solution provided by the embodiments of the present application brings at least the following beneficial effects:
[0013] Any application instance among multiple application instances divides the data in advance, and uses the same version of the same data group to store the data divided into a group in the local cache, and receives a read request sent by the application; wherein the read request is used to request to read the first data, and the first data is stored in any data group of any version; according to the request time corresponding to the read request, the name of the data group requested by the read request, and at least one of the version information, the first data group of the first version is determined from the multiple data groups; wherein at least two versions of the first data are stored in the first data group of the first version, and the effective time of the first data of different versions is different; according to the request time corresponding to the read request and the effective time of the first data of at least two versions, the first data to be returned is determined from the at least two versions of the first data; and the first data to be returned is sent to the application. Thus, any application instance can use different versions of data groups to store the corresponding data in the local cache, and at least two versions of the data can be stored in the same version of the data group, and the effective time of the different versions of the data is different, so that the consistency of each application in the distributed system when reading data from the cache can be guaranteed based on the version information and the effective time.
[0014] Other effects of the above optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0016] Figure 1 A flowchart of a data reading method provided in one embodiment of the present application;
[0017] Figure 2 A schematic diagram of different versions of data packets provided by an embodiment of the present application;
[0018] Figure 3 A schematic diagram of a flow chart of a data reading method provided in another embodiment of the present application;
[0019] Figure 4 A schematic diagram of a flow chart of a data reading method provided in another embodiment of the present application;
[0020] Figure 5 A schematic diagram of a data storage method according to an embodiment of the present application;
[0021] Figure 6 A schematic diagram of a flow chart of a data storage method provided by another embodiment of the present application;
[0022] Figure 7 A schematic diagram of a flow chart of a data reading method provided in another embodiment of the present application;
[0023] Figure 8 A schematic diagram of the structure of a data reading device provided in one embodiment of the present application;
[0024] Fig. 9 A schematic diagram of the structure of a data storage device provided in one embodiment of the present application;
[0025] Fig.10 It is a schematic structural diagram of an electronic device 1000 shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0026] Embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0027] It should be noted that the acquisition, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations.
[0028] Cache is defined as a copy of the original data stored on a computer for easy access. Cache can be simply divided into three categories: hardware cache, operating system cache, and application cache. Application cache can be roughly divided into client cache, server cache, and network cache according to its location in the software system.
[0029] The server cache is the core of the cache system and is critical to system performance. The database performance is slow. By tuning the cache parameters, the performance can be significantly improved without changing the architecture and code logic. The database is an IO-intensive application responsible for data management and storage. The database cache is its own caching mechanism. Most databases run quickly without configuration, but are not optimized for specific needs. Cache optimization is very important when tuning the database.
[0030] In the traditional centralized software architecture, the software system usually accesses cached data to improve system performance for data that is frequently read but not in large amounts. However, in the traditional way, all cached data is stored on a single cache node or a small number of cache nodes. This also causes some problems because all cached data is concentrated on a single node, which can easily become a performance bottleneck and a single point of failure.
[0031] Distributed cache is suitable for large-scale systems with distributed architecture and high concurrency scenarios, and can provide good scalability and availability. Assume that there are multiple application instances running on different servers at the same time, and these instances together constitute a distributed system. When one of the instances is processing business logic, if it finds that some data can be cached to improve the performance of subsequent access, the instance will write the data to the cache. Secondly, in a distributed cache system, data replication or synchronization mechanisms are usually used to ensure high availability and fault tolerance of cached data. Therefore, when an instance writes data to the cache, the data may be copied to the cache of other instances to ensure that the system can still operate normally even if some instances fail.
[0032] Distributed cache can reduce the load of a single node and enhance the fault tolerance of the system through technologies such as data sharding and replication. The cache data is stored in multiple cache nodes, which can be located on different servers. But this also brings problems. Compared with centralized cache, the configuration and management of distributed architecture is more complicated, and issues such as data consistency and load balancing need to be considered. The specific problems and solutions are:
[0033] 1. The data in the cache may be inconsistent with the source data (such as data stored in the database). The current main approach is to use a centralized cache, such as Redis. When the data changes, the database is updated first, and then the cache is updated.
[0034] 2. If there are associations between multiple cache data items, when we update these caches, we need to ensure that their data versions are consistent. For example: when A=1, B=2. When A=2, B=3. When we change A from 1 to 2, we need to ensure that B also changes from 2 to 3. If the change to A is successful, the change to B must also be successful. Conversely, if the change to A fails, the change to B must also fail. To solve this problem, the current common practice is to use Redis's Lua script to ensure that the two data items are updated at the same time; or merge the A / B data items into one data item and update them at one time.
[0035] 3. When each business step uses the same cache during business processing, the cache contents read by different business steps may be inconsistent during the processing of the same business due to the different cache read times of each business step. The current common practice is to use a centralized cache to ensure that the cache is read only once during business processing.
[0036] 4. In a distributed architecture, during business processing, the cache accessed by each business step may not be the same. The updates of these caches may be inconsistent due to the order of writing or write failure. The current common practice is to use a centralized cache and ensure that the cache is read only once during business processing.
[0037] The above existing distributed cache solutions have the following problems:
[0038] For Solution 1: This centralized cache has problems such as single point failure and high access latency (when the system is a multi-center architecture), and still cannot guarantee the consistency between the data in the database and the data in the cache. For example: after the source data is updated in the database, the write cache fails or the write latency is large.
[0039] For solution 2: Using Lua scripts will rely on centralized cache products such as Redis, and it is difficult to avoid problem 1; merging the two data items A / B may destroy the original cache-related loose coupling design, and there will be certain efficiency issues in cache data access.
[0040] For solution 3 / 4: In addition to the aforementioned problems caused by using centralized cache. In a distributed microservice architecture, each microservice is autonomous. Unless the data read from the cache is passed in the parameters or context of the service call, it is impossible to ensure that the data read from the cache in each business step is consistent. Not all cached data is suitable for passing through service call parameters or context. This cached data passing method will also increase the resource overhead of service calls and affect performance.
[0041] Therefore, the present application provides a data reading method and a data storage method to realize the use of distributed cache (such as local cache, local Redis) instead of centralized cache, solve the problems of single point failure and high access latency (when the distance is long) of centralized cache, and greatly improve the performance; avoid dependence on specific functions (such as Redis's Lua script) without affecting the application's design of the cache data structure; solve the consistency problem when each business step reads data from the cache in a distributed microservice architecture; support multiple data versions and support grayscale release (parallelism of new and old data).
[0042] The data reading method and data storage method according to the embodiments of the present application are described below with reference to the accompanying drawings.
[0043] First combine Figure 1 , the data reading method provided in the embodiment of the present application is described. Figure 1 A flowchart of a data reading method provided in an embodiment of the present application is shown.
[0044] It should be noted that the data reading method provided in the embodiment of the present application is applied to any application instance among multiple application instances included in the distributed system. The application instance divides the data in advance and stores the data divided into a group using the same data group of the same version in the local cache.
[0045] That is, in the application instance, multiple data packets have been pre-stored in the local cache, and each data packet has corresponding version information for uniquely identifying the version corresponding to the data packet. The version information may be, for example, a version number or other information, which is not limited in this application.
[0046] As an example, the business data that needs to be cached can be divided into multiple groups according to business needs, and a version information attribute is added to each group.
[0047] Therefore, by grouping related data and storing them in the same data group of the same version, data locality can be improved. In this way, when an application requests to read data, the system can locate the data group storing the data more quickly, thereby reducing search time. Moreover, since the data is effectively organized and stored, the distributed system can rely more on local cache to satisfy the application's read requests, thereby reducing the number of accesses to remote databases or distributed storage systems, helping to reduce network latency and improve response speed.
[0048] like Figure 1 As shown, the data reading method may include:
[0049] Step 101: receiving a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version.
[0050] The first data may be any data, such as business data (data required for business processing).
[0051] It should be noted that, in the embodiment of the present application, each time the application sends a read request, there will be a corresponding request time.
[0052] Since the application instance will store multiple data groups in the local cache, and each data group may have at least one version, the read request at least includes the name of the data group requested by the read request, so that the application instance can determine the target data group from multiple data groups based on the name of the data group requested by the read request. However, the read request may include the version information of the data group requested by the read request, and may not include the version information of the data group requested by the read request. This is because in the embodiment of the present application, after the caches of all application instances of the distributed system have successfully written a new version of a data group, the target service of the distributed system will notify each application instance to switch the data group from the original version to the new version. Therefore, when the read request does not include the version information of the data group requested by the read request, the application instance can directly determine the version information of the target data group based on the request time and switching time corresponding to the read request.
[0053] Step 102, determine the first data group of the first version from multiple data groups based on the request time corresponding to the read request, the name of the data group requested by the read request, and at least one of the version information; wherein the first data group of the first version stores at least two versions of the first data, and different versions of the first data have different effective times.
[0054] As an example, Figure 2 As shown, data packet A has two versions, namely version V1 and version V2, wherein the data packet A of version V1, namely Figure 2 There are two versions of data stored in the data group A-V1 in , one version of the data takes effect on 2024-08-08, and the other version of the data takes effect on 2024-09-01. Similarly, the data group A of version V2, i.e. Figure 2 The data group A-V2 in the data also stores two versions of data, one version of the data takes effect on 2024-01-01, and the other version of the data takes effect on 2024-10-01.
[0055] As a possible implementation method, the application instance can put a List (linked list) in the key (data group) of the local cache. Each element in the List is an object with an effective time (a single version data group object, whose value can be a single value or a data object). The elements in the List are different versions of data.
[0056] Therefore, by setting version information for each data group, and storing at least two versions of data in each version of the data group, different versions of data have different effective times, which can ensure the consistency of each application in the distributed system when reading data from the cache based on the version information and effective time.
[0057] In an embodiment of the present application, when determining the first data of the first version from multiple data packets, the determination can be made based on at least one of the request time corresponding to the read request, the name of the data packet requested by the read request, and the version information of the data packet requested by the read request. The first data packet of the first version is a data packet whose name is consistent with the name of the data packet requested by the read request and whose version is consistent with the version indicated by the version information of the data packet requested by the read request, or a data packet whose name is consistent with the name of the data packet requested by the read request and whose version is consistent with the version indicated by the version information determined based on the request time corresponding to the read request and the switching time corresponding to each first data packet.
[0058] As a possible implementation method, when the read request does not include version information of the data group requested by the read request, the first data group of the first version can be determined from multiple data groups based on the request time corresponding to the read request and the name of the data group requested by the read request; or, when the read request includes version information of the data group requested by the read request, the first data group of the first version can be determined from multiple data groups based on the name and version information of the data group requested by the read request.
[0059] When determining the first data group of the first version from multiple data groups according to the name and version information of the data group requested by the read request, at least one data group may be determined from the multiple data groups according to the name of the data group requested by the read request, and then the first data group of the first version may be determined from the at least one data group according to the version information of the data group requested by the read request. Alternatively, at least one data group may be determined from the multiple data groups according to the version information of the data group requested by the read request, and then the first data group of the first version may be determined from the at least one data group according to the name of the data group requested by the read request.
[0060] Specifically, at least one data group whose name is consistent with the name of the data group requested by the read request can be first determined from multiple data groups; then the version information of each data group in the at least one data group is queried; and the data group in the at least one data group whose version information is consistent with the version information of the data group requested by the read request is determined as the first data group of the first version.
[0061] It is also possible to first determine at least one data group from multiple data groups whose version information is consistent with the version information of the data group requested by the read request; then query the name of each data group in the at least one data group; and determine the data group in the at least one data group whose name is consistent with the name of the data group requested by the read request as the first data group of the first version.
[0062] Step 103 : determining the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data.
[0063] It should be noted that, since at least two versions of the first data are stored in the first data group of the first version, after determining the first data group of the first version, it is also necessary to determine the first data to be returned from the at least two versions of the first data stored in the first data group of the first version.
[0064] In an embodiment of the present application, the first data to be returned can be determined from at least two versions of the first data stored in the first data group of the first version by comparing the request time corresponding to the read request and the effective time of each version of the first data stored in the first data group of the first version.
[0065] As a possible implementation method, the request time corresponding to the read request can be compared with the effective time of at least two versions of the first data to obtain at least one version of the first data whose effective time is earlier than or equal to the request time; and the first data of the at least one version with the latest effective time is determined as the first data to be returned.
[0066] Therefore, by selecting the data to be returned according to the request time corresponding to the read request and the effective time of each version of the first data stored in the first data group of the first version, it can be ensured that the latest and valid data is returned to the application.
[0067] As a possible implementation manner, the request time corresponding to the read request may be indicated by request information of the read request or a context corresponding to the read request.
[0068] As an example, the request time can be indicated by different parts of the HTTP request (such as request header, request parameters or message body):
[0069] Request headers: HTTP request headers contain various metadata sent by the application. The application can add a custom field (such as X-Request-Time) in the request header and send the request time (usually in timestamp format) as the value of the field to the application instance. After receiving the request, the application instance can extract the value of this field from the request header to obtain the request time.
[0070] Request Parameters: For GET requests, the application can add the request time as a query parameter to the URL. When parsing the URL, the application instance can extract the value of this query parameter to obtain the request time. For POST or other types of requests, although it is generally not recommended to pass large amounts of data in the URL, it is theoretically possible to pass the request time as a hidden form field or as part of a URL-encoded parameter.
[0071] Message body: For requests that contain a message body, such as POST and PUT, the application can send the request time as part of the message body content to the application instance. When parsing the message body, the application instance can extract the request time.
[0072] As another example, when using the RPC (Remote Procedure Call) framework, the request time can be indicated by the context:
[0073] In the RPC framework, context is a very important concept, which is used to pass metadata throughout the service call process. These metadata may include user information, request ID, tracking information, and request time.
[0074] Optionally, when using the RPC framework, the application can create a context object before creating an RPC call and add the request time as an attribute or key-value pair of the context. Then, pass the context object to the application instance as a parameter of the RPC call. When the application instance receives the RPC call, it can extract the request time from the context.
[0075] Step 104: Send the first data to be returned to the application.
[0076] The data reading method of the embodiment of the present application receives a read request sent by an application; wherein the read request is used to request to read the first data, and the first data is stored in any data group of any version; according to the request time corresponding to the read request, the name of the data group requested by the read request, and at least one of the version information, the first data group of the first version is determined from multiple data groups; wherein at least two versions of the first data are stored in the first data group of the first version, and the effective time of the first data of different versions is different; according to the request time corresponding to the read request and the effective time of the first data of at least two versions, the first data to be returned is determined from the first data of at least two versions; and the first data to be returned is sent to the application. Thus, any application instance can use different versions of data groups to store corresponding data in the local cache, and at least two versions of data can be stored in the same version of the data group, and the effective time of different versions of data is different, so that the consistency of each application in the distributed system when reading data from the cache can be guaranteed based on the version information and the effective time.
[0077] In order to clearly illustrate how any application example in the above embodiments of the present application determines the first data group of the first version from multiple data groups based on the request time corresponding to the read request and the name of the data group requested by the read request, the embodiments of the present application propose another data reading method.
[0078] Figure 3 A schematic flow chart of a data reading method provided in another embodiment of the present application.
[0079] Similarly, the data reading method provided in the embodiment of the present application is applied to any application instance among the multiple application instances included in the distributed system. The application instance divides the data in advance and stores the divided data in a group using the same data group of the same version in the local cache.
[0080] like Figure 3 As shown, the data reading method may include:
[0081] Step 301: Receive a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version.
[0082] Step 302: Determine at least one data group from a plurality of data groups, the name of which is consistent with the name of the data group requested by the read request; wherein the version information of each data group in the at least one data group is different.
[0083] Optionally, the name of each data group in the multiple data groups may be compared with the name of the data group requested by the read request, thereby determining at least one data group whose name is consistent with the name of the data group requested by the read request from the multiple data groups, and the version information of each data group in the determined at least one data group is different.
[0084] Step 303: Determine a first data packet of a first version from at least one data packet according to a request time corresponding to the read request and a switching time of each data packet in the at least one data packet.
[0085] Among them, the switching time of any data group is the time when the target service included in the distributed system sends a switching notification to the application when it determines that multiple application instances included in the distributed system have completed the update of the data group, and the application switches from reading data from the data group to reading data from the updated data group in response to the switching notification.
[0086] In an embodiment of the present application, after determining at least one data group whose name is consistent with the name of the data group requested by the read request, it is necessary to further filter according to the request time corresponding to the read request and the switching time of each data group in the at least one data group, and determine the first data group of the first version from the at least one data group.
[0087] As a possible implementation method, at least one candidate data group whose switching time is earlier than the request time corresponding to the read request can be determined from at least one data group based on the request time corresponding to the read request and the switching time of each data group in at least one data group; and the candidate data group with the latest switching time in the at least one candidate data group is determined as the first data group of the first version.
[0088] Therefore, by accurately matching data group names, comparing request times and switching times, unnecessary data screening and comparison can be reduced, the data processing flow is optimized, only data groups related to read requests are processed, and the latest version of data groups is quickly located, thereby improving data processing efficiency.
[0089] Step 304 : determining the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data.
[0090] Step 305: Send the first data to be returned to the application.
[0091] It should be noted that the execution process of step 301 and step 304 to step 305 can be implemented in any way in the embodiments of the present application, and the embodiments of the present application do not limit this and will not be repeated.
[0092] The data reading method of the embodiment of the present application determines at least one data group whose name is consistent with the name of the data group requested by the read request from multiple data groups; and determines the first data group of the first version from the at least one data group according to the request time corresponding to the read request and the switching time of each data group in the at least one data group. Thus, by accurately matching the data group name, comparing the request time and the switching time, unnecessary data screening and comparison can be reduced, the data processing flow can be optimized, only the data groups related to the read request are processed, and the latest version of the data group is quickly located, thereby improving the data processing efficiency.
[0093] In order to clearly illustrate how any application example in the above embodiments of the present application determines the first data to be returned from at least two versions of the first data based on the request time corresponding to the read request and the effective time of at least two versions of the first data, the embodiments of the present application propose another data reading method.
[0094] Figure 4 A schematic flow chart of a data reading method provided in another embodiment of the present application.
[0095] Similarly, the data reading method provided in the embodiment of the present application is applied to any application instance among the multiple application instances included in the distributed system. The application instance divides the data in advance and stores the divided data in a group using the same data group of the same version in the local cache.
[0096] like Figure 4 As shown, the data reading method may include:
[0097] Step 401 : receiving a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version.
[0098] Step 402, determine the first data group of the first version from multiple data groups based on the request time corresponding to the read request, the name of the data group requested by the read request, and at least one of the version information; wherein the first data group of the first version stores at least two versions of the first data, and different versions of the first data have different effective times.
[0099] Step 403 : According to the storage locations of the at least two versions of the first data, the effective time of the at least two versions of the first data is compared with the request time corresponding to the read request in order from front to back.
[0100] It should be noted that, in an embodiment of the present application, when the first data group of the first version stores at least two versions of the first data, they are stored in the order of the effective time of the different versions of the first data, wherein the first data of the version with the latest effective time among the at least two versions of the first data is stored at the front position, and the first data of the version with the earliest effective time is stored at the back position.
[0101] Step 404 , in response to first determining that a version of the first data meets the set condition, stop comparing, and determine the determined first data as the first data to be returned.
[0102] The setting condition is that the effective time is earlier than or equal to the request time corresponding to the read request.
[0103] In an embodiment of the present application, since the first data of different versions are stored in order of effective time, the application instance can quickly start comparing from the frontmost version, and once a version that meets the set conditions is found, the comparison can be stopped immediately, thereby improving the efficiency of data retrieval.
[0104] The storage method of the embodiment of the present application simplifies the complexity of version management. The application instance does not need to track the complex dependencies or state changes of each version, and only needs to store and compare them in order of effectiveness time. Moreover, as time goes by, more versions of the first data may be added to the data group. Since the first data of different versions are stored in the order of effectiveness time, there is no need to reorganize or adjust the storage location of the existing first data when adding a new version of the first data, which enhances the scalability of the local cache.
[0105] Step 405: Send the first data to be returned to the application.
[0106] It should be noted that the execution process of step 401 to step 402 and step 405 can be implemented in any way in the embodiments of the present application, and the embodiments of the present application do not limit this and will not be repeated.
[0107] The data reading method of the embodiment of the present application compares the effective time of at least two versions of the first data with the request time corresponding to the read request in order from front to back according to the storage position of the at least two versions of the first data; in response to the first determination of a version of the first data that meets the set condition, stops the comparison and determines the determined first data as the first data to be returned; wherein the set condition is that the effective time is earlier than or equal to the request time corresponding to the read request. Since the first data of different versions are stored in the order of the effective time, the application instance can quickly start the comparison from the frontmost version, and once the version that meets the condition is found, the comparison can be stopped immediately, thereby improving the efficiency of data retrieval.
[0108] The above embodiment describes the data reading process. Figure 5 , explain the data storage process.
[0109] Figure 5 A flowchart of a data storage method provided in one embodiment of the present application.
[0110] Similarly, the data reading method provided in the embodiment of the present application is applied to any application instance among the multiple application instances included in the distributed system. The application instance divides the data in advance and stores the divided data in a group using the same data group of the same version in the local cache.
[0111] like Figure 5 As shown, the data storage method may include:
[0112] Step 501: Receive a first update notification sent by a target service included in a distributed system; wherein the first update notification is used to indicate an update of second data, and the second data is stored in any data group of any version.
[0113] Since the application instance stores multiple data groups in the local cache and each data group may have at least one version, the first update notification includes at least the name and version information of the data group notified by the first update notification, so that the application instance can determine the target data group from multiple data groups based on the name and version information of the data group notified by the first update notification.
[0114] The target service is responsible for monitoring changes in the data stored in each data group.
[0115] In an embodiment of the present application, the target service can send a first update notification to any application instance of the multiple application instances included in the distributed system when the data stored in any data group is sent to change, so as to notify each application instance to update the second data stored in any data group of any version. Accordingly, any application instance can receive the first update notification sent by the target service.
[0116] As an example, the target service can notify each application instance to update when the source data changes through additional mechanisms such as MQ.
[0117] Step 502: Determine a second data group of a second version from a plurality of data groups according to the name and version information of the data group notified by the first update notification.
[0118] In the embodiment of the present application, the application instance can accurately locate the second data group of the second version from multiple data groups according to the name and version information of the data group notified by the first update notification. The second data group of the second version is a data group whose name is consistent with the name of the data group notified by the first update notification and whose version is consistent with the version indicated by the version information of the data group notified by the first update notification.
[0119] When determining the second data group of the second version from multiple data groups according to the name and version information of the data group notified by the first update notification, at least one data group may be determined from multiple data groups according to the name of the data group notified by the first update notification, and then the second data group of the second version may be determined from at least one data group according to the version information of the data group notified by the first update notification. Alternatively, at least one data group may be determined from multiple data groups according to the version information of the data group notified by the first update notification, and then the second data group of the second version may be determined from at least one data group according to the name of the data group notified by the first update notification.
[0120] Specifically, at least one data group whose name is consistent with the name of the data group notified by the first update notification can be first determined from multiple data groups; then the version information of each data group in the at least one data group is queried; and the data group in the at least one data group whose version information is consistent with the version information of the data group notified by the first update notification is determined as the second data group of the second version.
[0121] It is also possible to first determine at least one data group from multiple data groups whose version information is consistent with the version information of the data group notified by the first update notification; then query the name of each data group in the at least one data group; and determine the data group in the at least one data group whose name is consistent with the name of the data group notified by the first update notification as the second data group of the second version.
[0122] In summary, since the data group to be updated can be located directly according to the name and version information of the data group notified by the first update notification, the efficiency of data update can be significantly improved and the time overhead of data search and location can be reduced.
[0123] Step 503, use the second version of the second data group to store the updated second data; wherein the effective time of the second data and the effective time of the updated second data are different, and the second data and the updated second data are two versions of the second data stored in the second version of the second data group.
[0124] In the embodiment of the present application, after determining the second data group of the second version, the application instance stores the updated second data in the data group, that is, the second data group of the second version is used to store the updated second data.
[0125] As a possible implementation manner, the application instance may also use the second data group of the second version to store the effective time and version information of the updated second data.
[0126] Among them, when using the second version of the second data grouping to store the updated second data, as well as the effective time and version information of the updated second data, the second version of the second data grouping can be used to store the updated second data, as well as the effective time and version information of the updated second data in the form of key-value pairs.
[0127] In order to optimize the utilization of storage space and reduce unnecessary storage overhead, the application instance may store only two versions of the second data in the second data group of the second version.
[0128] As a possible implementation method, in the case where the second data group of the second version only stores two versions of the second data, if two versions of the second data are already stored in the second data group of the second version before the second data group of the second version is used to store the updated second data, then the second data of the version with a later effective time among the two versions of the second data is retained, and the second data group of the second version is used to store the updated target data.
[0129] The data storage method of the embodiment of the present application receives a first update notification sent by a target service included in a distributed system; wherein the first update notification is used to indicate the update of the second data, and the second data is stored in any data group of any version; according to the name and version information of the data group notified by the first update notification, the second data group of the second version is determined from multiple data groups; the second data group of the second version is used to store the updated second data; wherein the effective time of the second data and the effective time of the updated second data are different, and the second data and the updated second data are two versions of the second data stored in the second data group of the second version. Thus, any application instance can ensure the consistency and accuracy of the data and avoid data conflicts, losses or inconsistencies by receiving the update notification of the target service and updating the data accordingly.
[0130] It should be noted that in this application, in addition to updating the data in a certain version of a data group, a new version can also be added to a certain data group. Figure 6 This process is described below.
[0131] Figure 6A schematic flow chart of a data storage method provided in another embodiment of the present application.
[0132] Similarly, the data reading method provided in the embodiment of the present application is applied to any application instance among the multiple application instances included in the distributed system. The application instance divides the data in advance and stores the divided data in a group using the same data group of the same version in the local cache.
[0133] like Figure 6 As shown, the data storage method may include:
[0134] Step 601: Receive a first update notification sent by a target service included in a distributed system; wherein the first update notification is used to indicate an update of second data, and the second data is stored in any data group of any version.
[0135] Step 602: Determine a second data group of a second version from a plurality of data groups according to the name and version information of the data group notified by the first update notification.
[0136] Step 603, using the second version of the second data group to store the updated second data; wherein the effective time of the second data and the effective time of the updated second data are different, and the second data and the updated second data are two versions of the second data stored in the second version of the second data group.
[0137] Step 604: Receive a second update notification sent by the target service; wherein the second update notification is used to indicate an update of any data group among the multiple data groups.
[0138] The target service is also responsible for monitoring the update status of the versions of each data group.
[0139] In the embodiment of the present application, the target service may also send a second update notification to any application instance of the multiple application instances included in the distributed system when the version of a certain data group needs to be updated, so as to notify each application instance to update any data group of the multiple data groups. Accordingly, any application instance may receive the second update notification sent by the target service.
[0140] As an example, assuming that a version of an application uses a version of data grouping to store relevant data of the version of the application, each time the application is updated, a corresponding version of the data grouping needs to be updated.
[0141] Step 605, in response to the second update notification, generate an updated data group, and use the updated data group to store the data carried in the second update notification; wherein the data group and the updated data group are two data groups with different version information and the same name.
[0142] Among them, the second update notification includes not only information about which data group needs to be updated, but also data to be stored in the updated data group. Therefore, in the embodiment of the present application, the application instance can generate an updated data group in response to the second update notification, and use the updated data group to store the data carried by the second update notification. Therefore, by updating the data group in a timely manner, it can be ensured that each application instance can access the latest data status, thereby maintaining data consistency.
[0143] As a possible implementation method, the target service sends a switching notification to the application when it is determined that multiple application instances included in the distributed system have completed the update of the data group; wherein the switching notification is used to instruct the application to switch from reading data from the data group to reading data from the updated data group.
[0144] Therefore, by ensuring that all application instances complete the update of data groups before switching, data inconsistency problems that occur during the switching process can be avoided.
[0145] It should be noted that the execution process of step 601 to step 603 can be implemented in any way in the embodiments of the present application, and the embodiments of the present application do not limit this and will not be repeated.
[0146] The data storage method of the embodiment of the present application receives a second update notification sent by the target service; wherein the second update notification is used to indicate the update of any data group in multiple data groups; in response to the second update notification, an updated data group is generated, and the updated data group is used to store the data carried by the second update notification; wherein the data group and the updated data group are two data groups with different version information and the same name. Therefore, by updating the data group in a timely manner, it can be ensured that the application can access the latest data status, thereby maintaining data consistency. Moreover, by ensuring that all application instances complete the update of the data group before switching, data inconsistency problems that occur during the switching process can be avoided.
[0147] In order to clearly illustrate the updating and switching process of data groups in the present application, an example is now given to illustrate.
[0148] Figure 7 A schematic flow chart of a data reading method provided in another embodiment of the present application.
[0149] The embodiment of the present application is a cache consistency method under a distributed architecture, which solves the problem of inconsistent cache data read by applications without relying on centralized cache. The specific design points are as follows:
[0150] 1. Use local cache instead of centralized cache to avoid the problems caused by centralized cache in distributed architecture;
[0151] 2. Refer to the concept of cache multi-version grouping (i.e., data grouping in this application), divide the business data that needs to be cached into multiple groups according to business needs, and add a version number attribute to each group. When the data of a cache group needs to be changed, the current version in the cache will not be modified directly, but a new version will be added to the data group, and the latest data will be written to this latest version. When the application reads the cache, it will decide which cache to read based on the version number in the current request. First, store the cache version information and effective time of different business parameters in a list format, with the latest value always at the front, such as QuryProd[{effective time: 2024-05-11 09:00:00.000” value: "2.0"}{effective time: 2024-05-1108:00:00.000” value: 1.0”}], and then store the VALUE of different KEY values under the corresponding cache version of each business parameter in the form of key and value. When querying, query the version used by the corresponding business parameter according to the transaction time sequence of the public message header. Find the corresponding information according to different key values. When the data is updated, the cache version information and effective time of the corresponding parameter will be added and inserted into the head of the list, and a cache version before the current time will be retained. The previous old version will be deleted, and only two cache versions will be retained at the same time. Business parameters under different cache versions are not in different regions.
[0152] 3. The data that needs to be cached needs to support multiple versions in terms of data structure, allowing the application to query the corresponding version of data based on the version number. In principle, the cached data only retains the current latest version and the previous version of cached data.
[0153] 4. Through additional mechanisms such as MQ, notify each application to update its local cache when the source data changes.
[0154] like Figure 7 As shown, the data reading method may include:
[0155] Step 701, the business code reads the v1 version of cache group A from the cache normally.
[0156] Step 702: Notify the application instance to write version v2 of cache group A.
[0157] Optionally, the target service included in the distributed system may notify the application instance to write the v2 version of cache group A through MQ or broadcast call or the like.
[0158] Step 703: After the caches of all application instances are written to version v2 successfully, the application is notified to switch the version of cache group A from v1 to v2.
[0159] Optionally, after the target service has successfully written version v2 into the caches of all application instances, it may notify the application to switch the version of cache group A from v1 to v2 through MQ or broadcast call.
[0160] Step 704: The business code reads version v2 of cache group A from the cache.
[0161] It should be noted that when a call request is received, if the request time (the request time is passed with the service call parameters or context) is later than the time to switch to v2, then the v2 version will be used, otherwise the v1 version will continue to be used.
[0162] In summary, the technical points in the embodiments of the present application include:
[0163] 1. Introduce the concept of cache multi-version grouping, allowing at least two versions of cache data to coexist at the same time, and separate cache writing (updating) and use.
[0164] 2. In a distributed architecture, cache version switching is performed only after all caches have been successfully updated.
[0165] 3. The request time is passed through the service call parameters or context, and used as a basis to determine the cache version to use.
[0166] As a result, at least the following beneficial effects are brought about:
[0167] 1. Use distributed cache (such as local cache, local Redis) instead of centralized cache to solve the problems of single point failure and high access latency (when the distance is long) of centralized cache, which greatly improves performance.
[0168] 2. Avoid dependence on specific functions (such as Redis's Lua script) and do not affect the application's design of the cache data structure.
[0169] 3. Solve the consistency problem when each business step reads data from the cache in a distributed microservice architecture.
[0170] 4. Support multiple data versions and grayscale release (parallel release of new and old data).
[0171] With the above Figure 1 , Figure 3 and Figure 4 Corresponding to the data reading method provided in the embodiment, the present application also provides a data reading device. Figure 1 , Figure 3 and Figure 4The data reading method provided in the embodiment corresponds to the data reading method, so the implementation of the data reading method is also applicable to the data reading device provided in the embodiment of the present application, and will not be described in detail in the embodiment of the present application.
[0172] Figure 8 A schematic diagram of the structure of a data reading device provided in one embodiment of the present application.
[0173] like Figure 8 As shown, the data reading device 800 includes: a first receiving module 801 , a first determining module 802 , a second determining module 803 and a sending module 803 .
[0174] The first receiving module 801 is used to receive a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version;
[0175] A first determining module 802 is configured to determine a first data group of a first version from multiple data groups according to a request time corresponding to the read request, a name of a data group requested by the read request, and at least one of version information; wherein the first data group of the first version stores at least two versions of first data, and different versions of the first data have different effective times;
[0176] A second determining module 803 is used to determine the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data;
[0177] The sending module 804 is used to send the first data to be returned to the application.
[0178] It should be noted that the data reading device provided in the embodiment of the present application is applied to any application instance among the multiple application instances included in the distributed system. The application instance divides the data in advance and uses the same version of the same data grouping to store the data divided into a group in the local cache.
[0179] In a possible implementation of the embodiment of the present application, the first determining module 802 includes:
[0180] A first determining unit is configured to determine, when the read request does not include version information of the data packet requested by the read request, a first data packet of a first version from multiple data packets according to a request time corresponding to the read request and a name of the data packet requested by the read request; or
[0181] The second determining unit is configured to determine a first data packet of a first version from a plurality of data packets according to a name and version information of the data packet requested by the read request when the read request includes version information of the data packet requested by the read request.
[0182] In a possible implementation manner of the embodiment of the present application, the first determining unit is configured to:
[0183] Determine at least one data group from the plurality of data groups, the name of which is consistent with the name of the data group requested by the read request; wherein the version information of each data group in the at least one data group is different;
[0184] According to the request time corresponding to the read request and the switching time of each data group in at least one data group, the first data group of the first version is determined from at least one data group; wherein the switching time of any data group is the time when the target service included in the distributed system sends a switching notification to the application when it is determined that multiple application instances included in the distributed system have completed the update of the data group, and the application switches from reading data from the data group to reading data from the updated data group in response to the switching notification.
[0185] In a possible implementation manner of the embodiment of the present application, the first determining unit is configured to:
[0186] Determine, from the at least one data group, at least one candidate data group whose switching time is earlier than the request time corresponding to the read request, according to the request time corresponding to the read request and the switching time of each data group in the at least one data group;
[0187] A candidate data packet with the latest switching time among the at least one candidate data packet is determined as the first data packet of the first version.
[0188] In a possible implementation manner of the embodiment of the present application, the second determining unit is configured to:
[0189] determining, from the plurality of data packets, at least one data packet having a name that is consistent with a name of the data packet requested by the read request;
[0190] querying version information of each data group in at least one data group;
[0191] A data packet in at least one data packet whose version information is consistent with the version information of the data packet requested by the read request is determined as a first data packet of the first version.
[0192] In a possible implementation manner of the embodiment of the present application, the second determining unit is configured to:
[0193] Determine at least one data packet from the plurality of data packets, the version information of which is consistent with the version information of the data packet requested by the read request;
[0194] Querying a name of each data group in at least one data group;
[0195] A data packet in the at least one data packet whose name is consistent with the name of the data packet requested by the read request is determined as a first data packet of the first version.
[0196] In a possible implementation of the embodiment of the present application, when storing at least two versions of the first data in a first version group, the first data is stored in the order of effectiveness time of the different versions of the first data, wherein the first data of the at least two versions of the first data with the latest effectiveness time is stored at the front position, and the first data of the version with the earliest effectiveness time is stored at the back position;
[0197] The second determining module 803 is used to:
[0198] According to storage locations of the at least two versions of the first data, comparing, from front to back, the effective time of the at least two versions of the first data with the request time corresponding to the read request;
[0199] In response to first determining that a version of first data meets a set condition, the comparison is stopped, and the determined first data is determined as the first data to be returned; wherein the set condition is that the effective time is earlier than or equal to the request time corresponding to the read request.
[0200] In a possible implementation of the embodiment of the present application, the second determining module 803 is configured to:
[0201] Compare the request time corresponding to the read request with the effective time of at least two versions of the first data respectively, and obtain at least one version of the first data whose effective time is earlier than or equal to the request time;
[0202] The first data of a version with the latest effective time among the at least one version of the first data is determined as the first data to be returned.
[0203] In a possible implementation manner of the embodiment of the present application, the request time corresponding to the read request is indicated by the request information of the read request or the context corresponding to the read request.
[0204] The data reading device provided by the embodiment of the present application receives a read request sent by an application; wherein the read request is used to request to read the first data, and the first data is stored in any data group of any version; according to the request time corresponding to the read request, the name of the data group requested by the read request, and at least one of the version information, the first data group of the first version is determined from multiple data groups; wherein at least two versions of the first data are stored in the first data group of the first version, and the effective time of the first data of different versions is different; according to the request time corresponding to the read request and the effective time of the first data of at least two versions, the first data to be returned is determined from the first data of at least two versions; and the first data to be returned is sent to the application. Thus, any application instance can use different versions of data groups to store corresponding data in the local cache, and at least two versions of data can be stored in the same version of the data group, and the effective time of different versions of data is different, so that the consistency of each application in the distributed system when reading data from the cache can be guaranteed based on the version information and the effective time.
[0205] With the above Figure 5 , Figure 6 Corresponding to the data storage method provided in the embodiment, the present application also provides a data storage device. Since the data storage device provided in the embodiment of the present application is similar to the above-mentioned Figure 5 , Figure 6 The data storage method provided in the embodiment corresponds to the data storage method, so the implementation method of the data storage method is also applicable to the data storage device provided in the embodiment of the present application, and will not be described in detail in the embodiment of the present application.
[0206] Fig. 9 A schematic diagram of the structure of a data storage device provided in one embodiment of the present application.
[0207] like Fig. 9 As shown, the data storage device 900 includes: a second receiving module 901 , a third determining module 902 and a storage module 903 .
[0208] The second receiving module 901 is used to receive a first update notification sent by the target service; wherein the first update notification is used to indicate updating of second data, and the second data is stored in any data group of any version;
[0209] A third determining module 902, configured to determine a second data group of a second version from a plurality of data groups according to the name and version information of the data group notified by the first update notification;
[0210] Storage module 903 is used to store updated second data using the second version of the second data group; wherein the effective time of the second data is different from the effective time of the updated second data, and the second data and the updated second data are two versions of the second data stored in the second version of the second data group.
[0211] It should be noted that the data storage device provided in the embodiment of the present application is applied to any application instance among the multiple application instances included in the distributed system. The application instance divides the data in advance and uses the same version of the same data grouping to store the data divided into a group in the local cache.
[0212] In a possible implementation of the embodiment of the present application, the storage module 903 is further configured to:
[0213] The second data group of the second version is used to store the effective time and version information of the updated second data.
[0214] In a possible implementation of the embodiment of the present application, the storage module 903 is further configured to:
[0215] The second data group of the second version is adopted to store the updated second data, as well as the effective time and version information of the updated second data in a key-value pair manner.
[0216] In a possible implementation of the embodiment of the present application, the above-mentioned device further includes:
[0217] A third receiving module is used to receive a second update notification sent by the target service; wherein the second update notification is used to indicate an update of any data group among the multiple data groups;
[0218] The processing module is used to generate an updated data group in response to the second update notification, and use the updated data group to store the data carried by the second update notification; wherein the data group and the updated data group are two data groups with different version information and the same name.
[0219] In a possible implementation of an embodiment of the present application, the target service sends a switching notification to the application when it is determined that multiple application instances included in the distributed system have completed the update of data groups; wherein the switching notification is used to instruct the application to switch from reading data from the data group to reading data from the updated data group.
[0220] In a possible implementation of the embodiment of the present application, the storage module 903 is further configured to:
[0221] In the case where the second data group of the second version only stores two versions of the second data, if two versions of the second data are already stored in the second data group of the second version before the second data group of the second version is used to store the updated second data, then the second data of the version with a later effective time among the two versions of the second data is retained, and the second data group of the second version is used to store the updated target data.
[0222] The data storage device provided by the embodiment of the present application receives a first update notification sent by a target service included in a distributed system; wherein the first update notification is used to indicate an update of the second data, and the second data is stored in any data group of any version; according to the name and version information of the data group notified by the first update notification, the second data group of the second version is determined from multiple data groups; the second data group of the second version is used to store the updated second data; wherein the effective time of the second data and the effective time of the updated second data are different, and the second data and the updated second data are two versions of the second data stored in the second data group of the second version. Thus, any application instance can ensure the consistency and accuracy of the data and avoid data conflicts, losses or inconsistencies by receiving the update notification of the target service and updating the data accordingly.
[0223] In an exemplary embodiment, the present application also provides an electronic device.
[0224] Among them, electronic equipment includes:
[0225] processor;
[0226] a memory for storing processor-executable instructions;
[0227] The processor is configured to execute instructions to implement the data reading method or data storage method proposed in any of the aforementioned embodiments.
[0228] As an example, Fig.10 is a schematic diagram of the structure of an electronic device 1000 shown in an exemplary embodiment of the present application. Fig.10 As shown, the electronic device 1000 includes:
[0229] The memory 1010 and the processor 1020, a bus 1030 connecting different components (including the memory 1010 and the processor 1020), the memory 1010 stores a computer program, and when the processor 1020 executes the program, the data reading method or the data storage method of the embodiment of the present application is implemented.
[0230] Bus 1030 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0231] The electronic device 1000 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 1000, including volatile and non-volatile media, removable and non-removable media.
[0232] The memory 1010 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 1040 and / or cache memory 1050. The electronic device 1000 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 1060 may be used to read and write non-removable, non-volatile magnetic media ( Fig.10 not shown, usually called a "hard drive"). Although Fig.10 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical medium) may be provided. In these cases, each drive may be connected to bus 1030 via one or more data medium interfaces. Memory 1010 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of each embodiment of the present application.
[0233] A program / utility 1070 having a set (at least one) of program modules 1070 may be stored, for example, in the memory 1010, such program modules 1070 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 1070 generally perform the functions and / or methods of the embodiments described herein.
[0234] The electronic device 1000 may also communicate with one or more external devices 1090 (e.g., keyboard, pointing device, display 1091, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1000, and / or communicate with any device that enables the electronic device 1000 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 1092. In addition, the electronic device 1000 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 1093. As shown, the network adapter 1093 communicates with other modules of the electronic device 1000 through a bus 1030. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1000, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0235] The processor 1020 executes various functional applications and data processing by running the programs stored in the memory 1010 .
[0236] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the data reading method or data storage method of the embodiment of the present application, and will not be repeated here.
[0237] In an exemplary embodiment, the present application also provides a computer-readable storage medium including instructions, such as a memory including instructions, and the above instructions can be executed by a processor of an electronic device to complete the data reading method or data storage method proposed in any of the above embodiments. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0238] In an exemplary embodiment, the present application further provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the data reading method or data storage method proposed in any of the above embodiments.
[0239] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the inventions claimed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary techniques in the art that are not claimed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0240] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data reading method, characterized in that: Applied to any application instance among a plurality of application instances included in a distributed system, the application instance divides data in advance, and uses the same version of the same data group to store the data divided into a group in a local cache; The method comprises: Receiving a read request sent by an application; wherein the read request is used to request to read first data, and the first data is stored in any data group of any version; Determine a first data group of a first version from multiple data groups according to a request time corresponding to the read request and at least one of a name and version information of the data group requested by the read request; wherein the first data group of the first version stores at least two versions of first data, and different versions of the first data have different effective times; Determine the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data; The first data to be returned is sent to the application.
2. The method according to claim 1, characterized in that: The determining, from the plurality of data packets, a first data packet of a first version according to at least one of a request time corresponding to the read request and a name and version information of the data packet requested by the read request, comprises: In a case where the read request does not include version information of the data packet requested by the read request, determining a first data packet of a first version from a plurality of data packets according to a request time corresponding to the read request and a name of the data packet requested by the read request; or In a case where the read request includes version information of the data packet requested by the read request, a first data packet of a first version is determined from a plurality of data packets according to the name and version information of the data packet requested by the read request.
3. The method according to claim 2, characterized in that The determining, according to the request time corresponding to the read request and the name of the data packet requested by the read request, the first data packet of the first version from the multiple data packets comprises: Determine at least one data group from a plurality of data groups, the name of which is consistent with the name of the data group requested by the read request; wherein the version information of each data group in the at least one data group is different; Determine a first data group of a first version from at least one data group according to a request time corresponding to the read request and a switching time of each data group in the at least one data group; wherein the switching time of any data group is a time when a target service included in the distributed system sends a switching notification to the application when it is determined that multiple application instances included in the distributed system have completed the update of the data group, and the application switches from reading data from the data group to reading data from the updated data group in response to the switching notification; The determining of the first version of the first data packet from the at least one data packet according to the request time corresponding to the read request and the switching time of each data packet in the at least one data packet includes: Determine, from the at least one data group, at least one candidate data group whose switching time is earlier than the request time corresponding to the read request, according to the request time corresponding to the read request and the switching time of each data group in the at least one data group; A candidate data packet with the latest switching time among the at least one candidate data packet is determined as the first data packet of the first version.
4. The method according to claim 2, characterized in that The step of determining a first data packet of a first version from a plurality of data packets according to the name and version information of the data packet requested by the read request comprises: determining at least one data packet from a plurality of data packets, the name of which is consistent with the name of the data packet requested by the read request; Querying version information of each of the at least one data group; Determine a data packet in the at least one data packet whose version information is consistent with the version information of the data packet requested by the read request as a first data packet of a first version; or,. Determine at least one data packet from the plurality of data packets, the version information of which is consistent with the version information of the data packet requested by the read request; Querying the name of each of the at least one data group; A data packet in the at least one data packet whose name is consistent with the name of the data packet requested by the read request is determined as a first data packet of the first version.
5. The method according to claim 1, characterized in that: When storing the at least two versions of the first data in the first data group of the first version, the first data of different versions are stored in the order of effectiveness time of the first data, wherein the first data of the version with the latest effectiveness time among the at least two versions of the first data is stored at the front position, and the first data of the version with the earliest effectiveness time is stored at the back position; The determining the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data includes: According to the storage locations of the at least two versions of the first data, comparing the effective time of the at least two versions of the first data with the request time corresponding to the read request in order from front to back; In response to first determining a version of first data that meets a set condition, stopping comparison, and determining the determined first data as the first data to be returned; wherein the set condition is that the effective time is earlier than or equal to the request time corresponding to the read request.
6. The method according to claim 1, characterized in that The determining the first data to be returned from the at least two versions of the first data according to the request time corresponding to the read request and the effective time of the at least two versions of the first data includes: Compare the request time corresponding to the read request with the effective time of the at least two versions of the first data respectively, and obtain at least one version of the first data whose effective time is earlier than or equal to the request time; The first data of a version with the latest effective time among the at least one version of the first data is determined as the first data to be returned.
7. A data storage method, characterized in that: Applied to any application instance among a plurality of application instances included in a distributed system, the application instance divides data in advance, and uses the same version of the same data group to store the data divided into a group in a local cache; The method comprises: Receiving a first update notification sent by a target service included in the distributed system; wherein the first update notification is used to indicate updating of second data, and the second data is stored in any data group of any version; Determine a second data group of a second version from a plurality of data groups according to the name and version information of the data group notified by the first update notification; The second version of the second data group is used to store the updated second data; wherein the effective time of the second data is different from the effective time of the updated second data, and the second data and the updated second data are two versions of the second data stored in the second version of the second data group.
8. The method according to claim 7, characterized in that The method further comprises: Using the second data group of the second version to store the effective time and version information of the updated second data; The second data grouping using the second version to store the updated target data, as well as the effective time and version information of the updated second data, includes: The second data grouping of the second version is adopted to store the updated second data, as well as the effective time and version information of the updated second data in a key-value pair manner.
9. The method according to claim 7, characterized in that: The method further comprises: receiving a second update notification sent by the target service; wherein the second update notification is used to indicate an update of any data group among the multiple data groups; In response to the second update notification, generating the updated data group, and using the updated data group to store the data carried by the second update notification; wherein the data group and the updated data group are two data groups with different version information and the same name; Wherein, the target service sends a switching notification to the application when it is determined that multiple application instances included in the distributed system have completed the update of the data group; wherein the switching notification is used to instruct the application to switch from reading data from the data group to reading data from the updated data group.
10. The method according to any one of claims 7 to 9, characterized in that: The storing updated second data in the second data group of the second version includes: In the case that the second data group of the second version only stores two versions of the second data, if two versions of the second data are already stored in the second data group of the second version before the second data group of the second version is used to store the updated second data, then the second data of the version with a later effective time among the two versions of the second data is retained, and the second data group of the second version is used to store the updated target data.