Method and system for controlling live migration of cache data, storage medium, and electronic device
By establishing listening and asynchronous processing threads for cache instances, cache data can be dynamically migrated, solving the problem of business fluctuations during cache data migration and achieving real-time and consistency in data reading and writing.
Patent Information
- Application Number
- PCT/CN2024/133324
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-03-29
- Filing Date
- 2024-11-20
- Publication Date
- 2025-10-02
AI Technical Summary
During big data processing, it takes time to restart the application and build a new cache instance when migrating cache data. This causes cache data reading to affect application performance and cause business fluctuations.
By establishing a monitor for the application's cache instance, dynamically monitoring configuration changes, creating a copy of the cache instance, and hot migrating data to the copy through asynchronous processing threads, and using read-write synchronizers to control the data migration status, we ensure real-time and consistent data reading and writing.
This avoids business fluctuations caused by frequent application restarts, ensures the real-time and accuracy of cached data reading and writing, and reduces the problem of inaccurate data reading by users.
Smart Images

Figure CN2024133324_02102025_PF_FP_ABST
Abstract
Description
Cache data hot migration control method, system, storage medium and electronic device
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to Chinese patent application No. 202410377787.7, filed on March 29, 2024, entitled “Cache data hot migration control method, system, storage medium and electronic device,” and the entire contents of that application are incorporated herein by reference. Technical Field
[0003] The present application belongs to the field of computer technology, and in particular relates to a cache data hot migration control method, system, storage medium and electronic device. Background Art
[0004] When processing big data, applications use local caching to reduce processing time. However, changes to local cache configurations, such as cache duration, memory size, and expired data cleanup frequency, require restarting the application, rebuilding a new cache instance, and migrating the locally cached data to the new cache instance. Because restarting the application and rebuilding the new cache instance take time, cached data reading can be affected, impacting application performance and potentially causing business fluctuations. Summary of the Invention
[0005] The present application provides a cache data hot migration control method, system, storage medium and electronic device for avoiding business fluctuations during cache data migration.
[0006] In a first aspect, an embodiment of the present application provides a method for controlling hot migration of cache data, comprising: establishing a listener for a cache instance of the application when the application is started; creating a copy of the cache instance in response to a configuration change of the cache instance monitored; hot migrating the data of the cache instance of the application to the copy of the cache instance; and if a data processing request is received, controlling the application to respond based on the cache instance or the copy of the cache instance according to the hot migration status of the data of the cache instance. In an implementation of the first aspect, hot migrating the data of the cache instance to the copy of the cache instance comprises: reading the data of the cache instance in a data locking mode; the data locking mode is used to lock the data of the cache instance to remain unchanged; when the data of the cache instance does not exist in the copy of the cache instance, writing the data of the cache instance to the copy of the cache instance; when the copy of the cache instance has data identical to the data of the cache instance and the creation time of the data of the cache instance is later than the creation time of the data of the copy of the cache instance, writing the data of the cache instance to the copy of the cache instance.
[0007] In an implementation of the first aspect, controlling the application to respond based on the cache instance or the copy of the cache instance according to the hot migration status of the data of the cache instance includes: if the hot migration status indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, controlling the application to respond based on the copy of the cache instance; if the hot migration status indicates that the process of hot migration of the data of the cache instance to the copy of the cache instance has ended, controlling the application to respond based on the cache instance.
[0008] In an implementation of the first aspect, the data processing request includes a data write request, the hot migration status is represented by the status of a read-write synchronizer, and the hot migration status of the data of the cache instance is used to control the application to respond based on the cache instance or the copy of the cache instance, including: if the status of the read-write synchronizer is on, it is determined that the hot migration status represents that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then the application is controlled to write the data of the data write request to the copy of the cache instance; if the status of the read-write synchronizer is off, it is determined that the hot migration status represents that the process of hot migration of the data of the cache instance to the copy of the cache instance has ended, then the application is controlled to write the data of the data write request to the cache instance.
[0009] In an implementation of the first aspect, controlling the application to write the data of the data write request into the copy of the cache instance includes: reading the data of the data write request in a data locking mode, and the data locking mode is used to lock the data of the cache instance to remain unchanged; when the data of the data write request does not exist in the copy of the cache instance, writing the data of the data write request into the copy of the cache instance; when the copy of the cache instance has data identical to the data of the data write request, and the creation time of the data of the data write request is later than the creation time of the data of the copy of the cache instance, writing the data of the data write request into the copy of the cache instance.
[0010] In an implementation of the first aspect, the data processing request includes a data read request, the hot migration status is represented by the status of a read-write synchronizer, and the control of the application to respond based on the cache instance or the copy of the cache instance according to the hot migration status of the data of the cache instance includes: in response to receiving the data read request, judging the current status of the read-write synchronizer; if the status of the read-write synchronizer is on, determining that the hot migration status represents that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then controlling the application to read data from the copy of the cache instance; if the status of the read-write synchronizer is off, determining that the hot migration status represents that the process of hot migration of the data of the cache instance to the copy of the cache instance has ended, then controlling the application to read data from the cache instance.
[0011] In an implementation of the first aspect, after completing the hot migration of the data of the cache instance to the copy of the cache instance, it also includes: switching the cache instance of the application to the copy of the cache instance; configuring the state of the read-write synchronizer to be closed; and releasing the current cache instance.
[0012] In an implementation of the first aspect, hot migrating the data of the cache instance of the application to the copy of the cache instance includes: hot migrating the data of the cache instance to the copy of the cache instance through an asynchronous processing thread.
[0013] In an implementation of the first aspect, establishing a listener for configuration changes of the cache instance in the application includes: when the application is started, detecting whether application configuration information is stored; if so, establishing a listener for the cache instance of the application based on the application configuration information; if not, obtaining and storing the default configuration information of the application, and establishing a listener for the cache instance of the application based on the default configuration information of the application.
[0014] In an implementation of the first aspect, configuration parameters of the cache instance are obtained and stored based on the application configuration information; a cache instance is constructed for the application based on the cache framework and the configuration parameters of the cache instance; and the hot migration state is configured to indicate that a process of hot migrating data of the cache instance to a copy of the cache instance has not been started.
[0015] In an implementation of the first aspect, the application configuration information includes at least an application name, a cache instance name, and attributes of the cache instance.
[0016] In a second aspect, an embodiment of the present application provides a cache data hot migration control system, comprising: a listener, for establishing a listener for a cache instance of an application when the application is started; a data builder, for creating a copy of the cache instance in response to listening to a configuration change of the cache instance; a state memory, for storing the configuration of the cache instance; a data dumper, for hot migrating the data of the cache instance to the copy of the cache instance in response to listening to a configuration change of the cache instance; and a request processor, for controlling the application to respond based on the cache instance or the copy of the cache instance according to the hot migration status of the data of the cache instance if a data processing request is received.
[0017] In an implementation of the second aspect, the local cache data hot migration control system also includes a read-write synchronizer, which is used to: characterize the hot migration state by being turned on or off; wherein, if the state of the read-write synchronizer is on, it is determined that the hot migration state characterizes that the data of the cache instance is in the process of hot migration to a copy of the cache instance, and then the application is controlled to respond based on the copy of the cache instance; if the state of the read-write synchronizer is off, it is determined that the hot migration state characterizes that the process of hot migration of the data of the cache instance to the copy of the cache instance has ended, and then the application is controlled to respond based on the cache instance.
[0018] In an implementation of the second aspect, the listener is connected to a configuration center. When the application is started, the listener detects whether the configuration center stores application configuration information. If so, a listener is established for configuration changes of the cache instance in the application based on the application configuration information. If not, the default configuration information of the application is obtained, the default configuration information of the application is stored in the configuration center, and a listener is established for configuration changes of the cache instance in the application based on the default configuration information of the application.
[0019] In an implementation of the second aspect, when the configuration center receives the configuration of the input cache instance, it compares whether the configuration of the input cache instance is the same as the configuration of the currently stored cache instance. If not, it confirms the configuration change of the cache instance and feeds back the configuration change of the cache instance to the listener.
[0020] In a third aspect, an embodiment of the present application provides a computer-readable storage medium on which a computer program is cached. When the computer program is executed by a processor, the cache data hot migration control method described in any one of the first aspects of the present application is implemented.
[0021] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising: a cache that caches a computer program; a processor that is communicatively connected to the cache and executes the cache data hot migration control method described in any one of the first aspects of the present application when calling the computer program.
[0022] The cache data hot migration control method provided in the embodiment of the present application has the following beneficial effects:
[0023] This application establishes a monitor for configuration changes of cache instances in the application, can dynamically monitor changes in the application's local cache configuration, update the configuration of the cache instance in real time, hot migrate the data of the application's cache instance to a copy of the cache instance through an independent asynchronous processing thread, and control the reading and writing of data through the state of the read-write synchronizer. This does not affect the real-time reading and writing of data, avoids the impact of business fluctuations caused by frequent releases or restarts of applications, and can also avoid the problem of inaccurate data reading by users due to data migration. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] FIG1 is a schematic diagram showing an application scenario of a cache data hot migration control method according to an embodiment of the present application.
[0025] FIG. 2 is a flow chart showing a cache data live migration control method according to an embodiment of the present application.
[0026] FIG. 3 is a flow chart showing a method for controlling cache data live migration according to an embodiment of the present application for establishing a monitor.
[0027] FIG4 is a flowchart showing initialization after application startup in a cache data live migration control method according to an embodiment of the present application.
[0028] FIG5 is a schematic diagram showing the implementation principle after application startup in a cache data hot migration control method according to an embodiment of the present application.
[0029] FIG6 is a diagram showing an implementation principle of monitoring a configuration change in a cache data live migration control method according to an embodiment of the present application.
[0030] FIG. 7 is a schematic diagram showing an implementation process of data hot migration in a cache data hot migration control method according to an embodiment of the present application.
[0031] FIG. 8 is a schematic diagram showing the principle of data reading in a cache data hot migration control method according to an embodiment of the present application.
[0032] FIG9 is a schematic diagram showing the principle of a cache data hot migration control system according to an embodiment of the present application.
[0033] FIG10 is a schematic diagram showing the structure of an electronic device in an embodiment of the present application.
[0034] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments.
[0035] Component Reference Numerals 100 Electronic Device 101 Memory 102 Processor 103 Display 10 Cache Data Hot Migration Control System 110 Listener 120 Data Constructor 130 State Memory 140 Read / Write Synchronizer 150 Data Dumper 160 Request Processor S100-S400 Steps S111-S117 Steps DETAILED DESCRIPTION
[0036] The following describes the embodiments of the present application through specific examples. Those skilled in the art can easily understand the other advantages and effects of the present application from the content disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments. The details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other unless they conflict.
[0037] Existing technical solutions using cache frameworks such as Caffeine and ehcache to implement cache migration are roughly the same, either based on hard coding or setting properties through configuration files, but lack implementation solutions in terms of real-time monitoring configuration and data migration to ensure real-time data reading and writing.
[0038] The terms involved in this embodiment are explained as follows:
[0039] Hot migration: also known as online migration or live migration, refers to the process of migrating applications or data without interrupting system operation.
[0040] Cache instance: An instance of an application-specific cache, including related data files, log files, and resources such as memory and processes that support the operation of these files.
[0041] Read-write synchronizer: A tool or service used to ensure the consistency of read and write data between different data storage systems.
[0042] This embodiment is based on a compatible general cache framework and combines the hot migration of cached data implemented by the configuration center to solve the following technical problems:
[0043] 1) Dynamically monitor local cache configuration and update the configuration in real time.
[0044] 2) Support different cache frameworks and provide abstract custom interface implementation.
[0045] 3) Hot migration avoids business fluctuations caused by frequent application releases or restarts.
[0046] 4) Ensure the real-time reading and writing of cached data and the business performance of applications.
[0047] The cache data hot migration control method of this embodiment is applied to an existing cache framework. Specifically, a data cache instance is constructed on top of the existing cache framework. This embodiment implements the cache data hot migration control method of this embodiment by installing a plug-in or software development kit (SDK) on an electronic device with an application installed. The cache framework described herein includes, but is not limited to, Caffeine, ehcache, etc. The application is described below using the installed SDK as an example.
[0048] Figure 1 shows a schematic diagram of the application scenario of the cache data hot migration control method of an embodiment of the present application. The cache data hot migration control method of this embodiment is used to perform data hot migration on the previous data cache instance when the configuration of the cache instance of the client application changes. As shown in Figure 1, the cache data hot migration control method of this embodiment can be applied to the client and the configuration center server connected to the client. There is a communication connection between the client and the configuration center server, which can be a wired connection or a wireless connection, which is not specifically limited in this application. Among them, the number of clients that establish a communication connection with the configuration center server can be one or more, which is not specifically limited in this application. The client is used to realize human-computer interaction and can be deployed on a terminal device or a computing device. The terminal device includes a personal computer, a smart phone, a wearable device, a handheld processing device, a tablet computer, a mobile notebook, an augmented reality device, a virtual reality device, an integrated handheld game console, a wearable device, a vehicle-mounted device, an intelligent conference device, an intelligent advertising device, a smart home appliance, etc. The smart home appliance can be a sweeping robot, a mopping robot, etc., which is not specifically limited here.
[0049] In a specific implementation, the application of the above-mentioned client can be software or an application running on a terminal device or computing device controlled by the user, such as a personal computer client, or a web client accessed based on a browser, or an application client running on a mobile terminal, or a console of a cloud platform. This application does not make any specific limitations.
[0050] After the application in the client is started, it establishes a connection with the configuration center server, actively discovers and registers relevant information of the application, including the application name, cache instance name, cache attribute information, etc., and establishes a monitor through the SDK to monitor the configuration changes of the application's cache instance in real time.
[0051] When the SDK detects that the configuration of the cache instance of the application has changed, the cache data in the cache instance will be hot migrated. Specifically, when the SDK detects that the configuration of the cache instance of the application has changed, it creates a copy of the cache instance and an asynchronous processing thread based on the cache framework and the configuration change of the cache instance, and configures the read-write synchronizer to be on. The cache instance is built on the basis of the cache framework to adapt to different cache frameworks. By establishing a monitor for the configuration change of the cache instance in the application, the changes in the local cache configuration of the application can be dynamically monitored and the configuration of the cache instance can be updated in real time. Then, the data of the cache instance of the application is hot migrated to the copy of the cache instance through an independent asynchronous processing thread, and when a data processing request is received, the application is controlled to respond based on the cache instance or the copy of the cache instance according to the hot migration status of the data of the cache instance. For example, data can be written to the cache instance or to a copy of the cache instance based on the state of the read-write synchronizer, or data can be read from the cache instance or from a copy of the cache instance based on the state of the read-write synchronizer. During hot data migration, it does not affect the real-time performance of data reading and writing, and can also avoid the problem of inaccurate data reading by users due to data migration, effectively ensuring the real-time performance of cached data reading and writing and the business performance of the application.
[0052] Therefore, the cache data hot migration control method provided in this embodiment can dynamically monitor the local cache configuration, update the configuration in real time, support different cache frameworks, hot migration of cache data and control data reading and writing, which can ensure the real-time reading and writing of cache data and the business performance of the application.
[0053] The cache data hot migration control method in the embodiment of the present application will be described in detail below with reference to Figures 2 to 9 in the embodiment of the present application.
[0054] Figure 2 is a flow chart of a method for controlling cache data hot migration according to an embodiment of the present application. As shown in Figure 2 , the method for controlling cache data hot migration according to an embodiment of the present application includes the following steps S100 to S400 .
[0055] Step S100, when the application is started, establish a monitor for the cache instance of the application;
[0056] Step S200, in response to monitoring a configuration change of the cache instance, creating a copy of the cache instance;
[0057] Step S300: hot-migrating the data of the cache instance of the application to the copy of the cache instance;
[0058] Step S400: If a data processing request is received, the application is controlled to respond based on the cache instance or a copy of the cache instance according to the hot migration status of the data of the cache instance.
[0059] The following describes in detail steps S100 to S400 of the cache data live migration control method of this embodiment.
[0060] Step S100: When an application is started, a monitor is established for the cache instance of the application.
[0061] This embodiment uses the SDK to establish a monitor for configuration changes of the cache instance in the application, which can dynamically monitor changes in the local cache configuration of the application and update the configuration of the cache instance in real time.
[0062] Specifically, in this embodiment, after the application is started, the SDK actively detects the application configuration information and stores the application configuration information, so as to establish a configuration change monitoring for the application according to the stored application configuration information.
[0063] Among them, one way to store application configuration information is to store the application configuration information in a remote server, for example, to store the application configuration information in a configuration center server, that is, to register the application configuration information in the configuration center server and establish a monitor for configuration changes of cache instances in the application.
[0064] In one implementation of this embodiment, the application configuration information includes, but is not limited to, the application name, cache instance name, and cache instance attributes. When an application starts, the cache data hot migration control method of this embodiment actively discovers and registers application configuration information, such as the application name, cache instance name, and cache attribute information. A listener is established for configuration changes of the application's cache instance, monitoring cache configuration changes in real time.
[0065] Figure 3 shows a flow chart of establishing a monitor in a cache data hot migration control method according to an embodiment of the present application. As shown in Figure 3, in one implementation of this embodiment, establishing a monitor for configuration changes of the cache instance in the application includes the following steps S111 to S114.
[0066] Step S111, when the application is started, detect whether the application configuration information is stored; if so, execute step S112: establish a monitor for the cache instance of the application based on the application configuration information; if not, execute steps S113 and S114.
[0067] Step S113, obtaining and storing the default configuration information of the application;
[0068] Step S114: Establish a listener for the cache instance in the application based on the default configuration information of the application.
[0069] In this embodiment, when the application is started, the SDK actively detects whether the application configuration information is stored. If so, it directly establishes a monitor for the application. If not, it obtains the default configuration information of the application and establishes a monitor based on the default configuration information of the application.
[0070] For example, if the application configuration information is stored and registered in the configuration center, the application configuration information will be discovered, registered, monitored, and the existing application configuration will be pulled from the configuration center. If the application configuration information does not exist, the application configuration information will be added. The application configuration information registered with the configuration center will prevail. If the application configuration information does not exist, the default configuration information within the application will prevail.
[0071] In addition, this embodiment further includes storing the application configuration information in the cache framework, for example, configuring a state memory in the cache framework, and storing the application configuration information in the state memory.
[0072] In this embodiment, after establishing a listener for configuration changes for the application, the cache framework is also initialized. Figure 4 shows a flowchart of the initialization after application startup in the cache data hot migration control method of one embodiment of the present application. In one implementation of this embodiment, after establishing a listener for configuration changes of the cache instance in the application, the following steps S115 to S117 are also included.
[0073] Step S115: Acquire and store configuration parameters of the cache instance based on the application configuration information.
[0074] The configuration parameters of the cache instance include but are not limited to the capacity of the cache instance, the validity period of the cache instance, etc.
[0075] Step S116: construct a cache instance for the application based on the cache framework and the configuration parameters of the cache instance.
[0076] The cache framework provides a virtual interface with a unified implementation. The cache framework can adopt any cache framework in the existing technology. This embodiment constructs a data cache instance based on the existing cache framework and the configuration parameters of the acquired cache instance, that is, creates a data storage db instance based on the cache framework, which can adapt to different cache frameworks.
[0077] Step S117 : Configuring the hot migration state indicates that the process of hot migration of the data of the cache instance to the copy of the cache instance is not started.
[0078] This embodiment can configure the initial state of hot migration when the application is started, so that when the configuration change of the application is monitored later, the hot migration state can be changed to effectively control the corresponding processing of data during the data migration process.
[0079] Figure 5 is a schematic diagram of the implementation principles of the cache data hot migration control method after application startup in one embodiment of the present application. As shown in Figure 5, when the application starts, a listener is established for configuration changes of the cache instance in the application by actively detecting the application configuration information, storing the application configuration information, and constructing a cache instance for the application based on the cache framework and the configuration parameters of the cache instance. The initial state of the read-write synchronizer is then configured to complete the initialization of cache control.
[0080] Step S200: In response to monitoring a configuration change of the cache instance, creating a copy of the cache instance.
[0081] In this embodiment, when the configuration parameters of the cache instance change, the data hot migration process is triggered. First, a copy of the cache instance is created through the pre-processing process of the hot migration process.
[0082] Among them, changes to the configuration of the cache instance can be input through the human-computer interaction interface of the configuration center, or can be implemented by inputting into the application. For example, if the cache configuration parameters of increasing the cache instance or modifying the validity period of the cache instance are monitored, a new cache instance needs to be built for the application based on the new configuration parameters. At this time, the preprocessing process of data hot migration is triggered: a copy of the cache instance is created based on the cache framework and the configuration changes of the cache instance.
[0083] Figure 6 illustrates the implementation principle of monitoring configuration changes in a cache data hot migration control method according to an embodiment of the present application. As shown in Figure 6, upon monitoring a configuration change of a cache instance, the configuration information of the new cache instance is synchronously updated and stored, and then a cache instance replica is constructed. The cache instance replica is constructed in the same manner as the current cache instance, creating a cache instance replica based on the cache framework and the configuration change of the cache instance to adapt to different cache frameworks.
[0084] Step S300: Hot migrate the data of the cache instance of the application to the copy of the cache instance.
[0085] In some application scenarios, for example, synchronous processing threads may be used to improve processing efficiency. Such application scenarios may be, for example, non-high concurrency scenarios.
[0086] In other application scenarios, data of the cache instance of the application can be hot migrated to the copy of the cache instance through an asynchronous processing thread. The asynchronous processing thread can be created after the copy of the cache instance is created.
[0087] Furthermore, during the hot migration process, the data source of the cache instance replica is two-fold: one is the cache instance data, and the other is the real-time write request data. The principles for processing cache instance data and real-time write request data are the same, and this embodiment will explain them one by one.
[0088] First, the process of processing cache instance data during hot migration is described. FIG7 shows a schematic diagram of the implementation process of data hot migration in a cache data hot migration control method according to an embodiment of the present application. As shown in FIG7 , in one implementation of this embodiment, hot migration of cache instance data to a copy of the cache instance includes:
[0089] 1) Enter data lock mode.
[0090] Data locking modes are tools or services used to ensure data consistency and integrity. They include various lock types, such as shared locks, exclusive locks, row locks, page locks, and table locks. In data locking mode, the processed data is no longer accessible to other processes or services, thus ensuring data consistency between the data instance and its replicas.
[0091] In this embodiment, after entering the data locking mode, only the asynchronous processing thread handling the live migration can read the data of the cache instance, and other threads can no longer read the data of the cache instance, which can ensure the data consistency of the data live migration.
[0092] 2) To further ensure the real-time performance and accuracy of data during data migration, this embodiment reads the data of the cache instance in data locking mode and compares the data of the copy of the cache instance with the data of the cache instance. The specific process is as follows:
[0093] 2 1) When the data of the cache instance does not exist in the copy of the cache instance, write the data of the cache instance into the copy of the cache instance.
[0094] 2 2) When the copy of the cache instance contains data identical to the data of the cache instance, compare the data of the cache instance with the data of the copy of the cache instance based on a time attribute; and when the creation time of the data of the cache instance is later than the creation time of the data of the copy of the cache instance, write the data of the cache instance to the copy of the cache instance.
[0095] When the creation time of the data of the cache instance is earlier than the creation time of the data of the copy of the cache instance, it means that the latest corresponding data already exists in the copy of the cache instance, and there is no need to migrate the data of the cache instance; when the creation time of the data of the cache instance is later than the creation time of the data of the copy of the cache instance, it means that the cache instance contains the latest corresponding data, the data of the cache instance is written to the copy of the cache instance, and the data locking mode is exited.
[0096] The processing flow from 1) to 2) is executed cyclically until the hot migration of the data of the cache instance to the copy of the cache instance is completed.
[0097] This embodiment uses an independent asynchronous processing thread to hot migrate the data of an application's cache instance to a replica of the cache instance. This allows the application's cache data to be migrated even when the application is restarted, without affecting the read and write of the cache data. This ensures that the application's usage is not affected during the cache data migration process, and avoids the impact of frequent service fluctuations caused by application restarts. In one implementation of this embodiment, as shown in FIG7 , after completing the hot migration of the cache instance's data to the replica of the cache instance, the following steps are also included:
[0098] 3) Switching the cache instance of the application from the cache instance to the copy of the cache instance.
[0099] 4) configuring the read-write synchronizer to be closed;
[0100] 5) Release the cache instance.
[0101] At this time, all the data of the cache instance has been migrated to the copy of the cache instance. The copy of the cache instance is generated based on the user's latest configuration. The data is migrated through an independent asynchronous processing thread, which will not cause fluctuations in the processing of business data.
[0102] During the data hot migration process or after the migration is completed, if a data processing request is received, the data processing request is processed according to the following step S400.
[0103] Step S400: If a data processing request is received, the application is controlled to respond based on the cache instance or a copy of the cache instance according to the hot migration status of the data of the cache instance.
[0104] The above hot migration status can represent three situations: (1) the process of hot migration of the data of the cache instance to the copy of the cache instance has not been started; (2) the data of the cache instance is in the process of hot migration to the copy of the cache instance; (3) the process of hot migration of the data of the cache instance to the copy of the cache instance has ended.
[0105] It should be noted that when the data of a cache instance is in the process of hot migration to a copy of the cache instance, the data can be hot migrated; while in the other two cases, the data cannot be hot migrated.
[0106] Then, the above step 400 may include: if the hot migration status indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then controlling the application to respond based on the copy of the cache instance; if the hot migration status indicates that the process of hot migration of the data of the cache instance to the copy of the cache instance has ended, then controlling the application to respond based on the cache instance.
[0107] Furthermore, the data processing request may include a data read request or a data write request. Thus, the SDK may, for example, control whether to write data to the cache instance or to a replica of the cache instance based on the hot migration state in response to receiving the data read request or the data write request, or control whether to read data from the cache instance or from a replica of the cache instance based on the hot migration state.
[0108] FIG8 is a schematic diagram showing the principle of data reading in a cache data hot migration control method according to an embodiment of the present application. As shown in FIG8 , specifically, in one implementation of this embodiment, the data processing request includes a data write request, and the hot migration state is represented by the state of a read-write synchronizer. Thus, the above-mentioned control of the application to respond based on the cache instance or a copy of the cache instance according to the hot migration state of the data of the cache instance includes:
[0109] In response to receiving a data write request, determining the current read-write synchronizer:
[0110] 1) If the read-write synchronizer is currently turned on, and it is determined that the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then the application is controlled to write the data of the data write request to the copy of the cache instance through the asynchronous processing thread.
[0111] 2) If the read-write synchronizer is currently closed, and it is determined that the hot migration state indicates that the hot migration process of the data of the cache instance to the copy of the cache instance has ended, the application is controlled to write the data of the data write request into the aforementioned data cache instance.
[0112] That is, in this embodiment, if the read-write synchronizer is enabled, the data of the data write request is written into the copy of the cache instance; if it is not enabled, the data of the data write request is written into the original cache instance.
[0113] In this embodiment, the write data is processed in data lock mode. In data lock mode, only the asynchronous processing thread that handles hot migration can read the data of the data write request, and other threads can no longer process the data of the data write request, which can ensure the consistency of the written data. In this embodiment, to further ensure the real-time and accuracy of the written data during the data migration process, specifically, in one implementation of this embodiment, controlling the application to write the data of the data write request to the copy of the cache instance includes:
[0114] 1) In a data locking mode, the data of the data write request is read, and the data of the data write request is compared with the data of the copy of the cache instance; the data locking mode is used to lock the data of the cache instance to remain unchanged.
[0115] 2) When the data of the data write request does not exist in the copy of the cache instance, write the data of the data write request to the copy of the cache instance; when the copy of the cache instance has data identical to the data of the data write request, compare the data of the data write request with the data of the copy of the cache instance based on a time attribute, and when the creation time of the data of the data write request is later than the creation time of the data of the copy of the cache instance, write the data of the data write request to the copy of the cache instance, and exit the data locking mode.
[0116] If the creation time of the data in the data write request is earlier than the creation time of the data in the copy of the cache instance, it indicates that the latest corresponding data already exists in the copy of the cache instance, and there is no need to write the data in the data write request. If the creation time of the data in the data write request is later than the creation time of the data in the copy of the cache instance, it indicates that the data in the data write request is the latest corresponding data. The data in the data write request is written to the copy of the cache instance, thereby ensuring that the copy of the cache instance contains the latest data and improving data accuracy. The data locking mode is then exited.
[0117] In one implementation of this embodiment, the data processing request includes a data read request, and the hot migration state is represented by the state of a read-write synchronizer. Thus, controlling the application to respond based on the cache instance or a copy of the cache instance according to the hot migration state of the data of the cache instance includes:
[0118] In response to receiving a data read request, determining the current read-write synchronizer:
[0119] 1) If the state of the read-write synchronizer is on, it is determined that the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then the application is controlled to read data from the copy of the cache instance; wherein, if the data read from the copy of the cache instance is empty, the data is read from the cache instance.
[0120] 2) If the read-write synchronizer is currently closed, and it is determined that the hot migration state indicates that the hot migration of the data of the cache instance to the copy of the cache instance has ended, the application is controlled to read data from the cache instance.
[0121] In this embodiment, if the read-write synchronizer is enabled, data will be read from the copy of the cache instance. If the read fails, the data will be read from the cache instance again. If the read-write synchronizer is not enabled, data will be read directly from the cache instance.
[0122] Therefore, the hot migration in this embodiment is a real-time data migration with non-blocking reading and writing achieved through asynchronous execution of independent asynchronous threads and state control of read-write synchronizers, which ensures the accuracy of data reading and writing during the real-time migration process.
[0123] Furthermore, this embodiment controls the reading and writing of data during data hot migration based on the state of the read-write synchronizer, effectively ensuring the real-time and consistency of the reading and writing of cached data, and avoiding the problem of inaccurate data reading by users due to data migration.
[0124] The protection scope of the cache data hot migration control method described in the embodiment of the present application is not limited to the execution order of the steps listed in this embodiment. All solutions implemented by adding, reducing, or replacing steps in the existing technology based on the principles of the present application are included in the protection scope of the present application.
[0125] The present application also provides a cache data hot migration control system. Figure 9 shows a schematic diagram of the cache data hot migration control system 10 of this embodiment. As shown in Figure 9, the cache data hot migration control system 10 of this embodiment includes: a listener 110, a data builder 120, a state memory 130, a read-write synchronizer 140, a data dumper 150, and a request processor 160.
[0126] Specifically, in this embodiment, the listener 110 establishes a listener for the configuration change of the cache instance in the application when the application is started; the data builder 120 creates a copy of the cache instance in response to monitoring the configuration change of the cache instance; the state memory 130 is used to store the configuration of the cache instance of the application; the data dumper 150 builds an asynchronous processing thread in response to monitoring the configuration change of the cache instance, and hot migrates the data of the cache instance to the copy of the cache instance through the asynchronous processing thread; the read-write synchronizer 140 represents the hot migration state by turning it on or off; wherein, if the read-write synchronizer If the state of the read-write synchronizer is on, and it is determined that the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then the application is controlled to respond based on the copy of the cache instance; if the state of the read-write synchronizer is off, and it is determined that the hot migration state indicates that the process of hot migration of the data of the cache instance to the copy of the cache instance has ended, then the application is controlled to respond based on the cache instance; if the request processor 160 receives a data processing request, then according to the hot migration state of the data of the cache instance, the application is controlled to respond based on the cache instance or the copy of the cache instance. For example, in response to receiving a data read request or a data write request, the state of the read-write synchronizer controls whether the data is written to the cache instance or the copy of the cache instance, or the state of the read-write synchronizer controls whether the data is read from the cache instance or from the copy of the cache instance.
[0127] When the application is started, the listener 110 establishes a listener for the configuration changes of the cache instance in the application. When the listener 110 detects that the configuration of the cache instance of the application has changed, the data builder 120 creates a copy of the cache instance based on the configuration change in response to the configuration change of the cache instance, and builds the cache instance based on the cache framework to adapt to different cache frameworks. By establishing a listener for the configuration changes of the cache instance in the application, the changes in the local cache configuration of the application can be dynamically monitored and the configuration of the cache instance can be updated in real time.
[0128] In response to monitoring the configuration changes of the cache instance, the data dumper 150 constructs an asynchronous processing thread, and hot migrates the data of the cache instance of the application to the copy of the cache instance through the asynchronous processing thread. Hot migrating the data of the cache instance of the application to the copy of the cache instance through an independent asynchronous processing thread can avoid the business fluctuations caused by frequent release or restart of the application.
[0129] During or after data hot migration, if data is read or written, the request processor 160 controls whether to write the data to the cache instance or to a replica of the cache instance based on the state of the read-write synchronizer, or controls whether to read the data from the cache instance or from a replica of the cache instance based on the state of the read-write synchronizer. Controlling data reading and writing during data hot migration based on the state of the read-write synchronizer can effectively ensure the real-time and accuracy of cache data reading and writing.
[0130] In one implementation of this embodiment, the listener 110 is connected to a configuration center. When the application is started, it detects whether the configuration center stores application configuration information: if so, a listener is established for the configuration changes of the cache instance in the application based on the application configuration information; if not, the default configuration information of the application is obtained, the default configuration information of the application is stored in the configuration center, and a listener is established for the configuration changes of the cache instance in the application based on the default configuration information of the application.
[0131] In one implementation of this embodiment, when the configuration center receives the configuration of the input cache instance, it compares whether the configuration of the input cache instance is the same as the configuration of the currently stored cache instance. If not, it confirms the configuration change of the cache instance and feeds back the configuration change of the cache instance to the listener 110.
[0132] In this embodiment, when an application starts, it actively discovers, registers, listens to, and pulls the application configuration information from the configuration center. If the application configuration information does not exist, it adds the application configuration information. The application configuration information registered with the configuration center is used as the basis. If the application configuration information does not exist, the default configuration within the application is used as the basis.
[0133] In this embodiment, the implementation principle of the cache data hot migration control system 10 is the same as the implementation principle of the cache data hot migration control method described above, and the implementation principle of data hot migration by the cache data hot migration control system 10 will not be repeated here.
[0134] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is cached. When the computer program is executed by a processor, the cache data hot migration control method provided in any embodiment of the present application is implemented.
[0135] In the embodiment of the present application, any combination of one or more storage media can be used. The storage medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination of the above. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a RAM, a ROM, an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium that contains or caches a program that can be used by or in combination with an instruction execution system, device or device.
[0136] The embodiment of the present application also provides an electronic device. Figure 10 shows a schematic diagram of the structure of the electronic device 100 provided in the embodiment of the present application. In some embodiments, the electronic device can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA) and other terminal devices. In addition, the cache data hot migration provided by the present application
[0137] The control method can also be applied to databases, servers, and data storage systems based on terminal artificial intelligence.
[0138] As shown in FIG10 , the electronic device 100 provided in an embodiment of the present application includes a memory 101 and at least one processor 102 , with one processor being used as an example in FIG10 .
[0139] The memory 101 is used to store computer programs; preferably, the memory 101 includes: ROM, RAM, disk, USB flash drive, cache card or optical disk, etc., which can cache program codes.
[0140] Specifically, the memory 101 can be implemented by any type of volatile or non-volatile storage device or a combination thereof. The memory 101 may include a computer system readable medium in the form of a volatile memory, such as a random access memory (RAM) and / or a cache memory. The electronic device 100 may further include other removable / non-removable, volatile / non-volatile computer system storage media. The memory 101 may include at least one program product having a set (e.g., at least one) program modules, which are configured to execute the solutions provided in the various embodiments of the present application. The specific functions and technical effects that can be achieved are not repeated here.
[0141] The processor 102 is connected to the memory 101 and is used to execute the computer program cached in the memory 101 so that the electronic device 100 executes the cache data hot migration control method provided in any embodiment of the present application.
[0142] Optionally, the processor 102 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0143] Optionally, the electronic device 100 in this embodiment may further include a display 103. The display 103 is communicatively connected to the memory 101 and the processor 102, and is configured to display a GUI interaction interface related to the cache data hot migration control method.
[0144] Furthermore, the electronic device 100 also includes other components such as a firewall, a load balancer, a communication component, a power supply component, etc. FIG10 only schematically shows some components, which does not mean that the electronic device only includes the components shown in FIG10.
[0145] The above embodiments can be implemented in whole or in part through software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. A computer program product includes multiple computer instructions. When the computer program instructions are loaded or executed on a computer, the processes or functions according to the embodiments of the present invention are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.
[0146] In summary, this application establishes a monitor for configuration changes of cache instances in the application, can dynamically monitor changes in the application's local cache configuration, update the configuration of the cache instance in real time, hot migrate the data of the application's cache instance to a copy of the cache instance through an independent asynchronous processing thread, and control the reading and writing of data through the state of the read-write synchronizer, which does not affect the real-time reading and writing of data, avoids the impact of business fluctuations caused by frequent releases or restarts of applications, and can also avoid the problem of inaccurate data reading by users due to data migration. Therefore, this application effectively overcomes the various shortcomings of the existing technology and has high industrial utilization value.
[0147] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Anyone skilled in the art may modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by one of ordinary skill in the art without departing from the spirit and technical concepts disclosed in this application shall be covered by the claims of this application.
Claims
1. A method for controlling hot migration of local cache data, characterized in that: include: When the application starts, a listener is established for the cache instance of the application; In response to monitoring a configuration change of the cache instance, creating a copy of the cache instance; Hot migrating data of the cache instance of the application to a copy of the cache instance; If a data processing request is received, the application is controlled to respond based on the cache instance or a copy of the cache instance according to the hot migration status of the data of the cache instance.
2. The local cache data hot migration control method according to claim 1, characterized in that: Hot migrating data of a cache instance to a replica of the cache instance includes: Read the data of the cache instance in a data locking mode; the data locking mode is used to lock the data of the cache instance to remain unchanged; When the data of the cache instance does not exist in the copy of the cache instance, writing the data of the cache instance into the copy of the cache instance; When the copy of the cache instance has the same data as the data of the cache instance and the creation time of the data of the cache instance is later than the creation time of the data of the copy of the cache instance, the data of the cache instance is written to the copy of the cache instance.
3. The local cache data hot migration control method according to any one of claims 1 or 2, characterized in that: The controlling, according to the hot migration state of the data of the cache instance, the application to respond based on the cache instance or a copy of the cache instance includes: If the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, controlling the application to respond based on the copy of the cache instance; If the hot migration status indicates that the hot migration process of the data of the cache instance to the copy of the cache instance has been completed, the application is controlled to respond based on the cache instance.
4. The local cache data hot migration control method according to claim 3, characterized in that: The data processing request includes a data write request, the hot migration state is represented by the state of the read-write synchronizer, and The controlling, according to the hot migration state of the data of the cache instance, the application to respond based on the cache instance or a copy of the cache instance includes: If the state of the read-write synchronizer is on, and it is determined that the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then controlling the application to write the data of the data write request to the copy of the cache instance; If the state of the read-write synchronizer is closed, it is determined that the hot migration state indicates that the hot migration process of the data of the cache instance to the copy of the cache instance has ended, and then the application is controlled to write the data of the data write request into the cache instance.
5. The local cache data hot migration control method according to claim 4, characterized in that: The controlling the application to write the data of the data write request into the copy of the cache instance includes: In a data locking mode, reading the data of the data write request, the data locking mode is used to lock the data of the cache instance to remain unchanged; When the data of the data write request does not exist in the copy of the cache instance, writing the data of the data write request into the copy of the cache instance; When the copy of the cache instance has the same data as the data of the data write request, and the creation time of the data of the data write request is later than the creation time of the data of the copy of the cache instance, the data of the data write request is written to the copy of the cache instance.
6. The local cache data hot migration control method according to claim 3, characterized in that: The data processing request includes a data read request, the hot migration state is represented by the state of the read-write synchronizer, and The controlling, according to the hot migration state of the data of the cache instance, the application to respond based on the cache instance or a copy of the cache instance includes: In response to receiving a data read request, determining a current state of the read-write synchronizer; If the state of the read-write synchronizer is on, determining that the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then controlling the application to read the data from the copy of the cache instance; If the state of the read-write synchronizer is closed, it is determined that the hot migration state indicates that the hot migration process of the data of the cache instance to the copy of the cache instance has ended, and then the application is controlled to read data from the cache instance.
7. The method for controlling hot migration of local cache data according to any one of claims 4 to 6, characterized in that: After completing the hot migration of the data of the cache instance to the replica of the cache instance, the method further includes: Switching the cache instance of the application to a copy of the cache instance; Configuring the state of the read-write synchronizer to be closed; and Releases the current cache instance.
8. The local cache data hot migration control method according to claim 1, characterized in that: The hot migration of data of the cache instance of the application to the copy of the cache instance includes: Hot migration of the data of the cache instance to the copy of the cache instance is performed through an asynchronous processing thread.
9. The local cache data hot migration control method according to claim 1, characterized in that: The establishing of a monitor for the cache instance of the application includes: When the application is started, check whether the application configuration information is stored; If yes, establish a listener for the cache instance of the application based on the application configuration information; If not, the default configuration information of the application is obtained and stored, and a listener is established for the cache instance of the application based on the default configuration information of the application.
10. The local cache data hot migration control method according to claim 9, characterized in that: After establishing a monitor for the cache instance of the application, the method further includes: Acquire and store configuration parameters of the cache instance based on the application configuration information; Building a cache instance for the application based on a cache framework and configuration parameters of the cache instance; Configuring the hot migration state indicates that a process of hot migrating the data of the cache instance to the copy of the cache instance has not been started.
11. The local cache data hot migration control method according to claim 9 or 10, characterized in that: The application configuration information includes at least an application name, a cache instance name, and attributes of the cache instance.
12. A local cache data hot migration control system, characterized in that: include: A listener, used to establish a listener for the cache instance of the application when the application starts; A data builder, configured to create a copy of the cache instance in response to monitoring a configuration change of the cache instance; A state memory, configured to store the configuration of the cache instance; A data dumper, configured to hot migrate the data of the cache instance to a copy of the cache instance in response to monitoring a configuration change of the cache instance; The request processor is configured to, upon receiving a data processing request, control the application to respond based on the cache instance or a copy of the cache instance according to the hot migration status of the data of the cache instance.
13. The local cache data hot migration control system according to claim 12, characterized in that: It also includes a read-write synchronizer, which is used to: Characterize the thermal migration state by turning it on or off; If the state of the read-write synchronizer is on, it is determined that the hot migration state indicates that the data of the cache instance is in the process of hot migration to the copy of the cache instance, then the application is controlled based on the cache. A copy of the stored instance responds; If the state of the read-write synchronizer is closed, it is determined that the hot migration state indicates that the hot migration process of the data of the cache instance to the copy of the cache instance has ended, and then the application is controlled to respond based on the cache instance.
14. The local cache data hot migration control system according to claim 12 or 13, characterized in that: The listener is connected to a configuration center and detects whether the configuration center stores application configuration information when the application is started; If yes, establish a listener for the cache instance of the application based on the application configuration information; If not, the default configuration information of the application is obtained, the default configuration information of the application is stored in the configuration center, and a listener is established for the cache instance of the application based on the default configuration information of the application.
15. The local cache data hot migration control system according to claim 14, characterized in that: When the configuration center receives the configuration of the input cache instance, it compares whether the configuration of the input cache instance is the same as the configuration of the currently stored cache instance. If not, it confirms the configuration change of the cache instance and feeds back the configuration change of the cache instance to the listener.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the local cache data hot migration control method according to any one of claims 1 to 11 is implemented.
17. An electronic device, characterized in that: The electronic device comprises: a memory storing a computer program; A processor is communicatively connected to the memory, and executes the local cache data hot migration control method according to any one of claims 1 to 11 when calling the computer program.
18. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the local cache data hot migration control method according to any one of claims 1 to 11 is executed.
Citation Information
Patent Citations
Virtual machine live migration method, virtual machine migration management apparatus, and virtual machine live migration system
CN104965757A
Storage capacity adjusting method, device and equipment and storage medium
CN112230853A
Data migration method and system and related equipment
CN112578997A
Cache data thermal migration control method and system, storage medium and electronic equipment
CN118377418A
Migration flow control
US20190236150A1