Client connection switching method and device for multi-cache cluster
By switching mode and listening to tags on the client side, and switching to the target cluster after the source cluster is synchronized with the target cluster data, the problem of business continuity affected in the traditional method is solved, and smooth switching and data consistency are achieved.
Patent Information
- Application Number
- CN202411786392.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-14
AI Technical Summary
Traditional methods cause the client to stop writing and wait for the target cluster and source cluster data to be aligned when the cache database version is upgraded or data migration, resulting in business continuity being affected.
By writing migration marks to the source cluster, the client switches to migration mode and listens to switching marks and read and write marks. When the source cluster and the target cluster data are synchronized, simulated data with incremental characteristics are written, synchronous progress is polled, and the synchronization progress is switched to read-only mode and target cluster after synchronization is completed.
It realizes smooth switching of cache clusters in the continuous operation of the client, shortens the service unavailability time, and ensures data consistency and business continuity.
Smart Images

Figure CN119621147A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud computing technology and can also be used in the financial field, and in particular to a method and device for switching client connections of a multi-cache cluster. Background Art
[0002] In scenarios such as cache database version upgrades / data migration, the traditional method of cluster switching is that the client disconnects from cluster A, cluster A has no new writes, and the current log sequence is N; the target cluster B starts synchronizing data from the source cluster A, cluster B reaches data consistency with cluster A, and the sequence is N; the client connection configuration is updated and restarted, so that the client can create a connection to cluster B. However, the above traditional methods have major business continuity issues:
[0003] 1. The client stops writing and waits for the target cluster and source cluster data to align before switching the client to the target cluster. The waiting time for data alignment cannot be determined.
[0004] 2. When using the native client to switch, you need to replace the original connection pool configuration and then restart the client to make the new connection take effect.
[0005] Combining the above two points, using traditional methods to switch clusters requires a long switching time and the client needs to be restarted, which greatly affects business continuity.
[0006] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section. Summary of the invention
[0007] An embodiment of the present invention provides a method for switching client connections of a multi-cache cluster, for smoothly switching the connection between the client and the multi-cache cluster, the method comprising:
[0008] Write a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after listening to the value of the migration mark as "migrating" through the message channel, and listens to the switching mark and the read-write mark;
[0009] After the source cluster and the target cluster have synchronized data, write the simulated data with incremental characteristics to the source cluster according to a preset time interval, and poll to detect the synchronization progress of the simulated data synchronized in the target cluster;
[0010] If the synchronization progress is synchronization completion, write a read-write mark with a value of read-only to the source cluster, so that the client switches to read-only mode after monitoring the value of the read-write mark as read-only through the message channel, and stops writing information to the source cluster;
[0011] Deleting the simulated data in the source cluster, and polling to detect the deletion progress of the simulated data synchronized in the target cluster;
[0012] If the deletion progress is deletion completed, a switch mark with a value of switch is written to the source cluster, so that the client monitors the switch mark with a value of switch through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
[0013] Furthermore, after the source cluster and the target cluster are synchronized, before writing the simulated data with incremental characteristics to the source cluster according to a preset time interval and polling to detect the synchronization progress of the simulated data synchronized in the target cluster, it also includes:
[0014] Polling to detect the data synchronization status between the source cluster and the target cluster;
[0015] It is determined whether the data synchronization status is synchronization completed, and if so, the source cluster and the target cluster have synchronized data.
[0016] Furthermore, it also includes:
[0017] If the data synchronization state is incomplete due to timeout, a switch mark with a value of switchback is written to the source cluster, so that after the client monitors through the message channel that the value of the switch mark is switchback, the cluster switch is stopped and switched to the normal mode.
[0018] Furthermore, the polling to detect the data synchronization status between the source cluster and the target cluster includes:
[0019] Use command statistics instructions to count the total number of commands for each source shard in the source cluster and the total number of commands for each corresponding replica shard in the target cluster;
[0020] Calculate the difference in the number of commands according to the total number of commands of the source shard and the total number of commands of the corresponding replica shard;
[0021] Iteratively executing the above steps until a first preset time is exceeded or the command number difference is less than a first preset threshold;
[0022] If the command number difference is less than the first preset threshold, the data synchronization status is synchronization completed; if the command number difference is still not less than the first preset threshold after a first preset time, the data synchronization status is timeout and incomplete.
[0023] Furthermore, it also includes:
[0024] If the synchronization progress is incomplete due to timeout, a switch mark with a value of switchback is written, so that after the client monitors the value of the switch mark as switchback through the message channel, the cluster switch is stopped and switched to the normal mode.
[0025] Furthermore, the polling to detect the synchronization progress of the simulated data synchronized in the target cluster includes:
[0026] Acquire the simulated data written to the source cluster and the simulated data synchronized with the target cluster;
[0027] Calculate the simulated data difference according to the simulated data written into the source cluster and the simulated data synchronized with the target cluster;
[0028] Iteratively executing the above steps until a second preset time is exceeded or the simulation data difference is less than a second preset threshold;
[0029] If the simulation data difference is less than the second preset threshold, the synchronization progress is synchronization completed; if the simulation data difference is still not less than the second preset threshold after continuing for a second preset time, the synchronization progress is timeout and incomplete.
[0030] Further, after writing the switching mark with a value of switching to the source cluster, the method further includes:
[0031] Check whether the source cluster and the target cluster have simulated data written;
[0032] If the source cluster has no simulated data written and the target cluster has simulated data written, the cluster switching is successful; otherwise, the cluster switching fails.
[0033] Furthermore, it also includes:
[0034] When the cluster switching is successful, a migration mark with a migration completion value is written to the source cluster, so that the client monitors the migration mark synchronized to the target cluster through the message channel and switches to the normal mode after the migration is completed, and stops message monitoring and simulating data writing;
[0035] When cluster switching fails, a switch mark with a value of switchback is written to the source cluster, so that the client monitors through the message channel that the value of the switch mark synchronized to the target cluster is switchback and then switches back to the source cluster, stops writing simulation data and switches to normal mode.
[0036] The embodiment of the present invention further provides a client connection switching device of a multi-cache cluster, which is used to smoothly switch the connection between the client and the multi-cache cluster. The device includes:
[0037] A migration control unit, used for writing a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after monitoring the value of the migration mark as "migrating" through the message channel, and monitors the switching mark and the read-write mark;
[0038] A synchronization progress detection unit, configured to write simulation data with incremental characteristics to the source cluster according to a preset time interval after the source cluster and the target cluster have synchronized data, and to poll and detect the synchronization progress of the simulation data synchronized in the target cluster;
[0039] A read-write control unit, configured to write a read-write mark with a value of read-only to the source cluster if the synchronization progress is synchronization completion, so that the client switches to read-only mode after monitoring that the value of the read-write mark is read-only through the message channel, and stops writing information to the source cluster;
[0040] A deletion progress detection unit, used to delete the simulation data in the source cluster and poll and detect the deletion progress of the simulation data synchronized in the target cluster;
[0041] The cluster switching control unit is used to write a switching mark with a value of switching to the source cluster if the deletion progress is deletion completion, so that the client monitors the value of the switching mark through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
[0042] Furthermore, it also includes:
[0043] A data synchronization status detection unit, used for polling and detecting the data synchronization status between the source cluster and the target cluster;
[0044] The data synchronization status judgment unit is used to judge whether the data synchronization status is synchronization completed. If so, the source cluster and the target cluster have synchronized data.
[0045] Furthermore, it also includes:
[0046] The first cluster switchback control unit is used to write a switchback mark with a value of switchback to the source cluster if the data synchronization state is incomplete due to timeout, so that after the client monitors that the value of the switchback mark is switchback through the message channel, it stops cluster switching and switches to normal mode.
[0047] Furthermore, the data synchronization status detection unit includes:
[0048] A command total statistics module is used to use command statistics instructions to respectively count the total number of commands of each source shard in the source cluster and the total number of commands of each corresponding replica shard in the target cluster;
[0049] A command number difference calculation module, used to calculate the command number difference according to the total number of commands of the source shard and the total number of commands of the corresponding replica shard;
[0050] A first iterative operation module, used for iteratively executing the above steps until a first preset time is exceeded or the command number difference is less than a first preset threshold;
[0051] The data synchronization status confirmation module is used to determine that if the command number difference is less than a first preset threshold, the data synchronization status is synchronization completed; if the command number difference is still not less than the first preset threshold after a first preset time, the data synchronization status is timeout and incomplete.
[0052] Furthermore, it also includes:
[0053] The second cluster switchback control unit is used to write a switch mark with a switchback value if the synchronization progress is incomplete due to timeout, so that the client stops cluster switching and switches to normal mode after monitoring that the switch mark value is switchback through the message channel.
[0054] Furthermore, the synchronization progress detection unit includes:
[0055] A simulation data acquisition module, used to acquire simulation data written into the source cluster and simulation data synchronized with the target cluster;
[0056] A simulation data difference calculation module, used to calculate the simulation data difference according to the simulation data written into the source cluster and the simulation data synchronized with the target cluster;
[0057] A second iterative operation module, used for iteratively executing the above steps until a second preset time is exceeded or the simulation data difference is less than a second preset threshold;
[0058] The synchronization progress confirmation module is used to determine that if the simulation data difference is less than a second preset threshold, the synchronization progress is synchronization completed; if the simulation data difference is still not less than the second preset threshold after a second preset time, the synchronization progress is timed out and incomplete.
[0059] Furthermore, it also includes:
[0060] A write check unit, used to check whether the source cluster and the target cluster have simulated data written;
[0061] The switching result determining unit is used to determine that the cluster switching is successful if no simulation data is written to the source cluster and simulation data is written to the target cluster; otherwise, the cluster switching fails.
[0062] Furthermore, it also includes:
[0063] A mode switching control unit, configured to write a migration mark with a migration completion value to the source cluster when the cluster switching is successful, so that the client monitors the migration mark synchronized to the target cluster through the message channel to switch to the normal mode after the migration is completed, and stop message monitoring and simulation data writing;
[0064] The third cluster switchback control unit is used to write a switch mark with a switchback value to the source cluster when the cluster switch fails, so that the client can switch back to the source cluster after listening to the switch mark synchronized to the target cluster through the message channel, stop writing simulation data and switch to normal mode.
[0065] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned client connection switching method of the multi-cache cluster when executing the computer program.
[0066] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the client connection switching method of the multi-cache cluster is implemented.
[0067] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method for switching client connections of the multi-cache cluster is implemented.
[0068] The client connection switching method and device of a multi-cache cluster provided by an embodiment of the present invention writes a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after listening to the switching mark and the read-write mark through the message channel; when the source cluster and the target cluster have synchronized data, writes simulated data with incremental characteristics to the source cluster according to a preset time interval, and polls to detect the synchronization progress of the simulated data synchronized in the target cluster; if the synchronization progress is synchronization completion, writes a read-write mark with a value of read-only to the source cluster, so that the client switches to the migration mode after listening to the switching mark and the read-write mark through the message channel; After monitoring that the value of the read-write tag is read-only, switch to read-only mode and stop writing information to the source cluster; delete the simulated data in the source cluster, and poll to detect the deletion progress of the simulated data synchronized in the target cluster; if the deletion progress is deletion completion, write a switch tag with a value of switch to the source cluster, so that the client monitors the value of the switch tag through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulated data, thereby achieving smooth switching of the connected cache cluster while the client is continuously running, ensuring service continuity and data consistency, and minimizing the client unavailability time.
[0069] Among them, by polling to detect the synchronization progress of the simulated data synchronized in the target cluster and the deletion progress of the simulated data synchronized in the target cluster, it is possible to ensure that the source cluster and the target cluster data are synchronized before the cluster switch to ensure data consistency; by writing a read-write mark with a value of read-only to the source cluster, so that the client can switch to read-only mode after listening to the value of the read-write mark through the message channel, stop writing information to the source cluster, and write a switch mark with a value of switch to the source cluster, so that the client can switch the connection from the source cluster to the target cluster after listening to the value of the switch mark through the message channel, which can shorten the service unavailable time during the switching process to the shortest. In addition, by writing a switch mark with a value of back-switching to the source cluster, so that the client can stop cluster switching and switch to normal mode after listening to the value of the switch mark through the message channel, it is possible to roll back the client connection to the source cluster when an abnormality occurs during the switching process, thereby ensuring normal business. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0071] Figure 1 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application;
[0072] Figure 2 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application;
[0073] Figure 3 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application;
[0074] Figure 4 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application;
[0075] Figure 5 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application;
[0076] Figure 6 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application;
[0077] Figure 7 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0078] Figure 8 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0079] Fig. 9 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0080] Fig.10 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0081] Fig.11 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0082] Fig.12 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0083] Fig.13 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0084] Fig.14 A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application;
[0085] Fig.15 A schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention;
[0086] Fig.16 A schematic diagram of a process of successfully switching a client from a source cluster to a target cluster provided in an embodiment of the present application. DETAILED DESCRIPTION
[0087] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0088] The information collected in the technical solution of this application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0089] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0090] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0091] During data migration or cache cluster version upgrade, the client connection switching of multiple cache clusters needs to be implemented through the client, the switching control end, the source cluster, and the target cluster. Among them, the source cluster is the cache cluster to which the client is connected before the switching among multiple cache clusters; the target cluster is the cache cluster to which the client is connected after the switching among multiple cache clusters; the switching control end is responsible for mastering the migration progress, detecting the migration status, and issuing migration instructions to the client; the application accesses the cache cluster through the client; the data of the source cluster is synchronized to the target cluster in log order through the data synchronization component.
[0092] Figure 1 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the client connection switching method of the multi-cache cluster provided by the present application includes:
[0093] S101: Write a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after monitoring the value of the migration mark as "migrating" through the message channel, and monitors the switching mark and the read-write mark;
[0094] S102: After the source cluster and the target cluster have synchronized data, write simulation data with incremental characteristics to the source cluster according to a preset time interval, and poll to detect the synchronization progress of the simulation data synchronized in the target cluster;
[0095] S103: If the synchronization progress is synchronization completion, write a read-write mark with a value of read-only to the source cluster, so that the client switches to read-only mode after monitoring the value of the read-write mark as read-only through the message channel, and stops writing information to the source cluster;
[0096] S104: deleting the simulation data in the source cluster, and polling to detect the deletion progress of the simulation data synchronized in the target cluster;
[0097] S105: If the deletion progress is deletion completed, write a switch mark with a value of switch to the source cluster, so that the client monitors the value of the switch mark through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
[0098] from Figure 1 As can be seen from the process shown, the client connection switching method of the multi-cache cluster provided in the present application writes a migration mark with a value of migrating to the source cluster, so that the client switches to the migration mode after listening to the switching mark and the read-write mark through the message channel; when the source cluster and the target cluster have synchronized data, writes simulated data with incremental characteristics to the source cluster according to a preset time interval, and polls to detect the synchronization progress of the simulated data synchronized in the target cluster; if the synchronization progress is synchronization completion, writes a read-write mark with a value of read-only to the source cluster, so that the client listens to the switching mark and the read-write mark through the message channel. After the channel monitors that the value of the read-write mark is read-only, it switches to read-only mode and stops writing information to the source cluster; deletes the simulated data in the source cluster, and polls to detect the deletion progress of the simulated data synchronized in the target cluster; if the deletion progress is deletion completion, writes a switch mark with a value of switch to the source cluster, so that the client monitors that the value of the switch mark is switch through the message channel, and then switches the connection from the source cluster to the target cluster after switching, and writes the simulated data, thereby realizing smooth switching of the connected cache cluster under the continuous operation of the client, ensuring service continuity and data consistency, and minimizing the client unavailability time.
[0099] The following takes the switching control end as the execution subject and explains each step in detail.
[0100] S101: Write a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after monitoring the value of the migration mark as "migrating" through the message channel, and monitors the switching mark and the read-write mark;
[0101] Specifically, the access method of the source cluster and the target cluster is configured in the client to ensure service continuity when switching connections. The client has three operating modes: normal mode, migration mode, and read-only mode. Among them, in normal mode, the client only connects to the configured specific cluster (source cluster or target cluster), can read and write, is called normally by the business, and does not listen to the message of switching control end; in migration mode, the client listens to the signal from the control end; in read-only mode, all write requests are rejected, and the source cluster is read but not written, and the target cluster is neither read nor written.
[0102] The client monitors the tags that can trigger the client status change through the message channel, including migration tags, switch tags and read-write tags, all of which are key-value pairs. Among them, the migration tag value includes migrating or migration completed, that is, key1 = migrating / done; the switch tag value includes switch or rollback, that is, key2 = switch / rollback; the read-write tag value includes read-only or read-write, that is, key3 = readonly / readwrite.
[0103] After the client is started, it first checks the migration tag key1. If key1 is not found, the migration has not started yet and the client is in normal mode, connected to the source cluster. If the value of key1 is migrating, the client has entered the migration mode. If the value of key1 is done, the migration is completed and the client is in normal mode, connected to the target cluster.
[0104] The switching control end writes the migration tag key1=migrating to the source cluster, so that the client can monitor the migration tag key1=migrating through the message channel, switch to the migration mode according to the tag, and monitor the switching tag key2 and the read-write tag key3.
[0105] S102: After the source cluster and the target cluster have synchronized data, write simulation data with incremental characteristics to the source cluster according to a preset time interval, and poll to detect the synchronization progress of the simulation data synchronized in the target cluster;
[0106] Specifically, after the source cluster and the target cluster have initially completed data synchronization, in order to further ensure the data consistency and synchronization performance between the two, the switch control end uses incremental simulation data for continuous testing and monitoring. According to the set time interval, the source cluster is continuously written with incremental simulation data. The simulation data is written to the detection tag key4 of the message channel. It is a sequence data that is easy to track and identify, so as to perform comparative analysis in the source cluster and the target cluster. After writing this data to the source cluster, the switch control end polls to detect the progress of the simulated data synchronized in the target cluster. By checking whether the latest simulation data is received in the target cluster and whether the data content is accurate, the synchronization speed and reliability can be evaluated.
[0107] In one embodiment, the value of the detection tag key4 is analog data of value+1 each time.
[0108] Figure 2 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, before S102, it also includes:
[0109] S201: Polling to detect the data synchronization status between the source cluster and the target cluster;
[0110] Specifically, in order to shorten the time that client services are stopped after the switch is enabled and improve the efficiency of the switch process, the switch management and control end checks the data synchronization status between the source cluster and the target cluster in real time to ensure data integrity and consistency. At the beginning of the switch operation, the switch management and control end will continuously monitor the data transmission and replication progress of the source cluster and the target cluster, and verify whether the data in the target cluster is fully aligned with the latest data in the source cluster through synchronization status checks.
[0111] In one embodiment, the data written in the cache cluster is a log with a sequence number N. For the same key, the value of the sequence N is the largest, that is, the value of the last log. For the source cluster and the target cluster, the data is consistent if and only if the log sequence N of all nodes is the same and the (key, value) of each log is consistent. The target cluster synchronizes data from the source cluster. When the client connection is disconnected from the source cluster, the cache of the source cluster is log_a. When connected to the target cluster, the cache data of the target cluster is log_b. Log_a and log_b should achieve data consistency.
[0112] Figure 3 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, S201 includes:
[0113] S301: Count the total number of commands for each source shard in the source cluster and the total number of commands for each corresponding replica shard in the target cluster using a command statistics instruction;
[0114] Specifically, during the data synchronization process between the source cluster and the target cluster, in order to accurately monitor and judge the synchronization status, the switch control end performs command statistics operations on each shard in the source cluster and the target cluster respectively to ensure that data consistency and synchronization effects meet expectations. First, execute the command statistics instruction on each source shard in the source cluster, and count the total number of commands received and executed by each shard in the source cluster one by one. Then, in the target cluster, the command statistics instruction is also executed for each corresponding replica shard to count the total number of commands received and executed by each shard in the target cluster environment. By comparing the command statistics results of each shard in the source cluster with the command statistics results of the replica shard in the target cluster, the data consistency during the synchronization process can be effectively monitored and verified.
[0115] In one embodiment, the command statistics instruction is a commandstat instruction.
[0116] S302: Calculate the difference in the number of commands according to the total number of commands of the source shard and the total number of commands of the corresponding replica shard;
[0117] Specifically, after obtaining the total number of commands of the source shard and the target shard, the switch management end calculates the difference in the number of commands between the source shard and the target shard based on the total number of commands of the source shard and the total number of commands of the target shard. This difference represents the progress deviation of the source cluster and the target cluster during the synchronization process, that is, the difference in the number of commands can intuitively reflect the lag in data transmission or processing.
[0118] S303: Iteratively execute the above steps until a first preset time is exceeded or the command number difference is less than a first preset threshold;
[0119] Specifically, in order to ensure the accuracy and timeliness of data synchronization, the switching control end iteratively executes the above steps, continuously counting and calculating the difference in the total number of commands. In each iteration, the switching control end checks whether the current difference in the number of commands is less than a first preset threshold or whether the duration has exceeded a first preset time.
[0120] S304: If the command number difference is less than the first preset threshold, the data synchronization status is synchronization completed; if the command number difference is still not less than the first preset threshold after a first preset time, the data synchronization status is timeout and incomplete.
[0121] Specifically, if the difference in the number of commands is less than the first preset threshold, it indicates that the number of commands of the source cluster and the target cluster are basically consistent. At this time, the switching management end determines that the data synchronization status is "synchronization completed", that is, the synchronization process is successfully completed and the switching is ready.
[0122] However, if during continuous monitoring, the switching control end finds that the difference in the number of commands is still not less than the first preset threshold after exceeding the first preset time, it can be determined that the data synchronization status is "timeout and incomplete", which may mean that there is blockage or delay in the synchronization process.
[0123] Through the above-mentioned sharding statistics process and iterative judgment mechanism, the switching control end can determine the data synchronization status of the source cluster and the target cluster more accurately and timely, thereby achieving higher reliability and efficiency in cluster switching and data consistency management, providing strong data support for cluster switching, and thus optimizing the reliability and accuracy of the switching operation.
[0124] S202: Determine whether the data synchronization status is synchronization completed, and if so, the source cluster and the target cluster have synchronized data.
[0125] Specifically, after polling and detecting the data synchronization status of the source cluster and the target cluster, if the switching management end determines that the data synchronization status is synchronization completed, it means that the source cluster and the target cluster have been synchronized, and continue to execute writing of simulated data with incremental characteristics to the source cluster according to the preset time interval, and poll and detect the synchronization progress of the simulated data synchronized in the target cluster.
[0126] In one embodiment, the client connection switching method of the multi-cache cluster provided by the present application further includes:
[0127] If the data synchronization state is incomplete due to timeout, a switch mark with a value of switchback is written to the source cluster, so that after the client monitors through the message channel that the value of the switch mark is switchback, the cluster switch is stopped and switched to the normal mode.
[0128] Specifically, during the data synchronization process, if the switch control end detects that the data synchronization status is "timeout and incomplete", it means that the synchronization between the source cluster and the target cluster has failed to reach the expected synchronization threshold within the specified time. In this case, in order to avoid business anomalies caused by data inconsistency, the switch control end immediately adopts a switchback strategy. First, the switch control end writes a switch mark to the source cluster, and the value of the switch mark is set to "switchback" to instruct the switch control end to terminate the current switch operation.
[0129] Once the value of the switch tag is set to "switch back", the client monitors this change in real time through the preset message channel. After receiving this tag value, the client immediately stops the current cluster switching process to avoid directing client requests to the target cluster that has not been fully synchronized, thereby ensuring the accuracy and consistency of data access. In addition, the client triggers the fallback mechanism and reverts from the migration mode to the normal mode to continue to rely on the source cluster to provide services, ensuring the stability and high availability of the business switching management and control end.
[0130] Through the above-mentioned switchback mechanism, the switch control end can quickly take emergency measures when synchronization is not completed, avoiding potential risks caused by data asynchrony and ensuring the security, stability and consistency of the switch control end. The switchback operation provides a layer of security during the cluster switching process, and can have higher fault tolerance and flexibility when dealing with complex network conditions or high-load scenarios.
[0131] Figure 4 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, S102 includes:
[0132] S401: Acquire simulation data written into the source cluster and simulation data synchronized with the target cluster;
[0133] Specifically, during the synchronization process between the source cluster and the target cluster, in order to ensure data consistency between the two, the switch control end monitors the synchronization progress in real time by comparing the simulated data written to the source cluster with the simulated data synchronized to the target cluster. First, the switch control end obtains the simulated data written to the source cluster, and at the same time, the switch control end obtains the synchronized simulated data from the target cluster to compare and analyze the synchronization effect.
[0134] In one embodiment, the simulation data has a clear incremental feature, such as a sequence number or a timestamp, to facilitate tracking and ensure the orderliness of the data.
[0135] S402: Calculating a simulated data difference according to the simulated data written into the source cluster and the simulated data synchronized with the target cluster;
[0136] Specifically, after obtaining the simulated data of the source cluster and the target cluster each time, the switching control end will calculate the simulated data difference based on the difference between the simulated data of the source cluster and the target cluster. The simulated data difference is the sequence difference between the latest simulated data of the source cluster and the target cluster, indicating whether there is a delay in the synchronization process of the target cluster.
[0137] S403: iteratively executing the above steps until a second preset time is exceeded or the simulation data difference is less than a second preset threshold;
[0138] Specifically, the switching control terminal continuously iterates and executes the above steps of obtaining, comparing and calculating, and continuously monitors the changes in the simulation data difference. In each iteration, the switching control terminal checks whether the current simulation data difference is less than the second preset threshold or whether the duration has exceeded the second preset time.
[0139] S404: If the simulation data difference is less than the second preset threshold, the synchronization progress is synchronization completed; if the simulation data difference is still not less than the second preset threshold after continuing for a second preset time, the synchronization progress is timeout and incomplete.
[0140] Specifically, if the simulated data difference is found to be less than the second preset threshold during the iteration process, that is, the data synchronization between the source cluster and the target cluster is basically consistent, then the synchronization progress can be determined as "synchronization completed". This indicates that the target cluster has successfully received the latest data, and the synchronization process has met the expected time and content consistency requirements. However, if the simulated data difference is still not less than the second preset threshold after the second preset time, the switching control end will determine the synchronization progress as "timeout and incomplete".
[0141] Through the above-mentioned iterative detection and judgment mechanism, the switching control end can accurately monitor the data synchronization progress of the source cluster and the target cluster, ensure that the cluster is switched after the data consistency requirements are met, reduce client downtime and improve overall high availability.
[0142] S103: If the synchronization progress is synchronization completion, write a read-write mark with a value of read-only to the source cluster, so that the client switches to read-only mode after monitoring the value of the read-write mark as read-only through the message channel, and stops writing information to the source cluster;
[0143] Specifically, after confirming that the synchronization progress is "synchronization completed", the switching control end writes a read-write tag in the source cluster, and the value of the read-write tag is set to "read-only". The purpose of this operation is to prevent the source cluster from being written to during the switching process, thereby ensuring data consistency. After writing the tag, the client will monitor the changes in the value of the read-write tag in real time through the preset message channel.
[0144] Once the client detects that the read-write flag in the source cluster has been updated to "read-only", the client immediately switches to read-only mode, stops any write operations to the source cluster, and returns an error code to all application write requests. This mechanism ensures that the data in the source cluster remains stable before switching, preventing new data or updates from introducing inconsistencies. After switching to read-only mode, the client only performs read operations on the source cluster, which not only ensures the normal operation of the business, but also prevents possible synchronization conflicts.
[0145] In one embodiment, the client connection switching method of the multi-cache cluster provided by the present application further includes:
[0146] If the synchronization progress is incomplete due to timeout, a switch mark with a value of switchback is written, so that after the client monitors the value of the switch mark as switchback through the message channel, the cluster switch is stopped and switched to the normal mode.
[0147] Specifically, during the data synchronization process, if the switch control end detects that the synchronization progress of the simulated data is "timeout and incomplete", it means that the synchronization between the source cluster and the target cluster has failed to reach the expected synchronization threshold within the specified time. In this case, in order to avoid business anomalies caused by data inconsistency, the switch control end immediately adopts a switchback strategy. First, the switch control end writes a switch mark to the source cluster, and the value of the switch mark is set to "switchback" to instruct the switch control end to terminate the current switch operation.
[0148] Once the value of the switch tag is set to "switch back", the client monitors this change in real time through the preset message channel. After receiving this tag value, the client immediately stops the current cluster switching process to avoid directing client requests to the target cluster that has not been fully synchronized, thereby ensuring the accuracy and consistency of data access. In addition, the client triggers the fallback mechanism and reverts from the migration mode to the normal mode to continue to rely on the source cluster to provide services, ensuring the stability and high availability of the business switching management and control end.
[0149] Through the above-mentioned switchback mechanism, the switch control end can quickly take emergency measures when synchronization is not completed, avoiding potential risks caused by data asynchrony and ensuring the security, stability and consistency of the switch control end. The switchback operation provides a layer of security during the cluster switching process, and can have higher fault tolerance and flexibility when dealing with complex network conditions or high-load scenarios.
[0150] S104: deleting the simulation data in the source cluster, and polling to detect the deletion progress of the simulation data synchronized in the target cluster;
[0151] Specifically, after confirming that the source cluster has entered read-only mode, the switch control end begins to delete the previously written simulation data in the source cluster. These simulation data are used for early synchronization detection and progress monitoring. Clearing them before switching helps ensure data consistency and prevents irrelevant data from being transmitted to the target cluster.
[0152] After the deletion operation is completed, the switch control end will poll the deletion progress of the simulated data in the target cluster to ensure that the status of the target cluster is consistent with the source cluster. The polling detection process includes periodically obtaining the data status in the target cluster and checking whether there is residual simulated data. If the simulated data in the target cluster has not been deleted, the switch control end will continue to wait and may adjust the polling frequency according to the situation to reduce the burden on the switch control end.
[0153] S105: If the deletion progress is deletion completed, write a switch mark with a value of switch to the source cluster, so that the client monitors the value of the switch mark through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
[0154] Specifically, after confirming that the simulated data deletion progress of the target cluster is "deletion completed", the switch control end will write a switch mark to the source cluster, and the value of the switch mark is "switch". This mark indicates that the client is about to perform a cluster switch operation.
[0155] After the client detects that the switch flag in the source cluster has changed to "switch" through the message channel, it will automatically adjust the connection configuration and switch the connection from the source cluster to the target cluster. This switching process is smooth to ensure that the client does not experience business interruption due to the switch. After the client completes the switch, it will no longer access the source cluster, making the target cluster the new data service provider. In addition, the client writes new simulated data to the target cluster to ensure that the switch is successful.
[0156] Through the above switching process, the switching control end realizes the smooth migration of business requests and ensures the integrity and consistency of data.
[0157] Figure 5A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, after S105, it also includes:
[0158] S501: Check whether the source cluster and the target cluster have simulated data written;
[0159] Specifically, after the cluster switching operation is completed, the switching control end needs to verify the success of the switch to ensure that the business can be smoothly transferred to the target cluster. The switching control end first checks the source cluster to verify whether there is still new simulated data writing activity. This step is to ensure that the simulated data written by the client is not written to the source cluster. Next, the switching control end checks the target cluster to confirm that the simulated data has been successfully written to the target cluster, indicating that the target cluster has successfully received and processed the client's data write request.
[0160] S502: If the source cluster has no simulated data written and the target cluster has simulated data written, the cluster switching is successful; otherwise, the cluster switching fails.
[0161] Specifically, based on the inspection results, the switching control end determines whether the cluster switching is successful or not. If it is detected that there is no simulated data written to the source cluster, and the target cluster receives the simulated data normally, it means that the switching operation has been successfully completed, the client has successfully switched to the target cluster, and the write operation of the source cluster has stopped. If the detection results show that there is still simulated data written to the source cluster, or the target cluster fails to receive the simulated data, it means that the switching operation did not achieve the expected effect.
[0162] Through the above inspection and judgment, the switching control end can accurately evaluate the results of cluster switching and take corresponding measures in time, so as to maintain efficiency, security and business continuity during the switching operation.
[0163] Figure 6 A schematic diagram of a flow chart of a method for switching client connections in a multi-cache cluster provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, after S502, the following steps are also included:
[0164] S601: When the cluster switching is successful, a migration mark with a migration completion value is written to the source cluster, so that the client monitors the migration mark synchronized to the target cluster through the message channel and switches to the normal mode after the migration is completed, and stops message monitoring and simulating data writing;
[0165] Specifically, when the cluster switch is successful, that is, the client has successfully switched to the target cluster, the switch control end writes a migration marker to the source cluster, and its value is set to "Migration Completed" to notify the client that the switch operation has ended and the data migration is complete. After writing the migration marker, the client monitors the status of the marker through the preset message channel.
[0166] After the migration tag of the source cluster is synchronized to the target cluster, the client detects that the value of the migration tag is "Migration Completed" and immediately switches to normal mode and enters normal business mode. At this point, the client no longer participates in the data synchronization operation between the source cluster and the target cluster, and only interacts with data through the target cluster to ensure that the business request has been completely transferred to the target cluster. The client stops writing simulated data and terminates the monitoring operation on the source cluster tag value to avoid unnecessary switching control-end overhead due to tag changes, releases switching control-end resources, and focuses on normal business processing. At this point, the switching operation is completely successful, the source cluster enters the standby state, and may regularly perform maintenance operations such as backup and archiving to provide protection for future switching needs.
[0167] In one embodiment, the process of successfully switching a client from a source cluster to a target cluster is as follows: Fig.16 shown.
[0168] S602: When cluster switching fails, write a switch mark with a value of switchback to the source cluster, so that the client monitors through the message channel that the value of the switch mark synchronized to the target cluster is switchback and then switches back to the source cluster, stops writing simulation data and switches to normal mode.
[0169] Specifically, in the event of a cluster switch failure, the switch control end detects that the client has failed to successfully switch to the target cluster. In order to ensure business continuity and data consistency, the switch control end will immediately execute the switchback process.
[0170] The switching control end writes a switching mark to the source cluster with a value of "switch back", indicating that the client should return to the source cluster to continue processing business requests. This mark notifies the client to terminate the current switching process and roll back the business load to the source cluster to ensure stable business operation.
[0171] After the client detects that the switch mark has changed to "switch back" through the message channel, it automatically redirects the business request to the source cluster. This operation ensures that the client can resume business in time when a switch failure is detected, and avoids access interruption caused by a switch failure. After the client switches back, it terminates the simulated data write operation to the source cluster to reduce unnecessary data burden and ensure that the business data environment of the source cluster remains clear and consistent. At the same time, the client returns to normal mode, no longer monitors the mark, and only uses the source cluster for normal business operations.
[0172] The present application provides a method for switching client connections of a multi-cache cluster, which writes a migration mark with a value of "migrating" to the source cluster, so that the client can switch to the migration mode after listening to the value of the migration mark through a message channel, and listen to the switching mark and the read-write mark; when the source cluster and the target cluster have synchronized data, write simulated data with incremental characteristics to the source cluster according to a preset time interval, and poll to detect the synchronization progress of the simulated data synchronized in the target cluster; if the synchronization progress is synchronization completion, write a read-write mark with a value of read-only to the source cluster, so that the client can listen to the switching mark and the read-write mark through the message channel. After the value of the read-write tag is read-only, it switches to read-only mode and stops writing information to the source cluster; deletes the simulated data in the source cluster, and polls to detect the deletion progress of the simulated data synchronized in the target cluster; if the deletion progress is deletion completion, writes a switch tag with a value of switch to the source cluster, so that the client listens to the value of the switch tag through the message channel, switches the connection from the source cluster to the target cluster after switching, and writes simulated data, thereby achieving smooth switching of the connected cache cluster while the client is continuously running, ensuring service continuity and data consistency, and minimizing the client unavailability time.
[0173] Among them, by polling to detect the synchronization progress of the simulated data synchronized in the target cluster and the deletion progress of the simulated data synchronized in the target cluster, it is possible to ensure that the source cluster and the target cluster data are synchronized before the cluster switch to ensure data consistency; by writing a read-write mark with a value of read-only to the source cluster, so that the client can switch to read-only mode after listening to the value of the read-write mark through the message channel, stop writing information to the source cluster, and write a switch mark with a value of switch to the source cluster, so that the client can switch the connection from the source cluster to the target cluster after listening to the value of the switch mark through the message channel, which can shorten the service unavailable time during the switching process to the shortest. In addition, by writing a switch mark with a value of back-switching to the source cluster, so that the client can stop cluster switching and switch to normal mode after listening to the value of the switch mark through the message channel, it is possible to roll back the client connection to the source cluster when an abnormality occurs during the switching process, thereby ensuring normal business.
[0174] The embodiment of the present invention also provides a client connection switching device for a multi-cache cluster, as described in the following embodiment. Since the principle of solving the problem by the device is similar to the client connection switching method for a multi-cache cluster, the implementation of the device can refer to the implementation of the client connection switching method for a multi-cache cluster, and the repeated parts will not be repeated.
[0175] Figure 7A schematic diagram of the structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, such as Figure 7 As shown, the device comprises:
[0176] The migration control unit 701 is used to write a migration mark with a value of migrating to the source cluster, so that the client switches to the migration mode after monitoring the value of the migration mark as migrating through the message channel, and monitors the switching mark and the read-write mark;
[0177] Specifically, the access method of the source cluster and the target cluster is configured in the client to ensure service continuity when switching connections. The client has three operating modes: normal mode, migration mode, and read-only mode. Among them, in normal mode, the client only connects to the configured specific cluster (source cluster or target cluster), can read and write, is called normally by the business, and does not listen to the message of switching control end; in migration mode, the client listens to the signal from the control end; in read-only mode, all write requests are rejected, and the source cluster is read but not written, and the target cluster is neither read nor written.
[0178] The client monitors the tags that can trigger the client status change through the message channel, including migration tags, switch tags and read-write tags, all of which are key-value pairs. Among them, the migration tag value includes migrating or migration completed, that is, key1 = migrating / done; the switch tag value includes switch or rollback, that is, key2 = switch / rollback; the read-write tag value includes read-only or read-write, that is, key3 = readonly / readwrite.
[0179] After the client is started, it first checks the migration tag key1. If key1 is not found, the migration has not started yet and the client is in normal mode, connected to the source cluster. If the value of key1 is migrating, the client has entered the migration mode. If the value of key1 is done, the migration is completed and the client is in normal mode, connected to the target cluster.
[0180] The migration control unit 701 writes the migration tag key1=migrating to the source cluster, so that the client monitors the migration tag key1=migrating through the message channel, switches to the migration mode according to the tag, and monitors the switching tag key2 and the read-write tag key3.
[0181] A synchronization progress detection unit 702 is used to write simulation data with incremental characteristics to the source cluster according to a preset time interval after the source cluster and the target cluster have synchronized data, and poll to detect the synchronization progress of the simulation data synchronized in the target cluster;
[0182] Specifically, after the source cluster and the target cluster have initially completed data synchronization, in order to further ensure the data consistency and synchronization performance between the two, the switching control end uses simulated data with incremental characteristics for continuous testing and monitoring. According to the set time interval, simulated data with incremental characteristics are continuously written to the source cluster. The simulated data is written to the detection mark key4 of the message channel. It is a sequence data that is easy to track and identify, so as to perform comparative analysis in the source cluster and the target cluster. After writing these data to the source cluster, the synchronization progress detection unit 702 polls to detect the progress of the simulated data synchronized in the target cluster. By checking whether the latest simulated data is received in the target cluster and whether the data content is accurate, the synchronization speed and reliability can be evaluated.
[0183] A read / write control unit 703 is configured to write a read / write mark with a value of read-only to the source cluster if the synchronization progress is synchronization completion, so that the client switches to read-only mode after monitoring that the value of the read / write mark is read-only through the message channel, and stops writing information to the source cluster;
[0184] Specifically, after confirming that the synchronization progress is "synchronization completed", the read-write control unit 703 writes a read-write mark in the source cluster, and the value of the read-write mark is set to "read-only". The purpose of this operation is to prevent the source cluster from being continuously written during the switching process, thereby ensuring data consistency. After writing the mark, the client will monitor the changes in the value of the read-write mark in real time through the preset message channel.
[0185] Once the client detects that the read-write flag in the source cluster has been updated to "read-only", the client immediately switches to read-only mode, stops any write operations to the source cluster, and returns an error code to all application write requests. This mechanism ensures that the data in the source cluster remains stable before switching, preventing new data or updates from introducing inconsistencies. After switching to read-only mode, the client only performs read operations on the source cluster, which not only ensures the normal operation of the business, but also prevents possible synchronization conflicts.
[0186] A deletion progress detection unit 704 is used to delete the simulation data in the source cluster and poll and detect the deletion progress of the simulation data synchronized in the target cluster;
[0187] Specifically, after confirming that the source cluster enters the read-only mode, the deletion progress detection unit 704 starts to delete the previously written simulation data in the source cluster. These simulation data are used for early synchronization detection and progress monitoring. Clearing them before switching helps to ensure data consistency and prevent irrelevant data from being transmitted to the target cluster.
[0188] After the deletion operation is completed, the deletion progress detection unit 704 polls the deletion progress of the simulation data in the target cluster to ensure that the state of the target cluster is consistent with the source cluster. The polling detection process includes periodically obtaining the data state in the target cluster and checking whether there is residual simulation data. If the simulation data in the target cluster has not been deleted, the switching control end will continue to wait and may adjust the polling frequency according to the situation to reduce the burden on the switching control end.
[0189] The cluster switching control unit 705 is used to write a switching mark with a value of switching to the source cluster if the deletion progress is deletion completed, so that the client monitors the value of the switching mark through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
[0190] Specifically, after confirming that the simulated data deletion progress of the target cluster is "deletion completed", the cluster switching control unit 705 will write a switching mark to the source cluster, and the value of the switching mark is "switch". This mark indicates that the client is about to perform a cluster switching operation.
[0191] After the client detects that the switch flag in the source cluster has changed to "switch" through the message channel, it will automatically adjust the connection configuration and switch the connection from the source cluster to the target cluster. This switching process is smooth to ensure that the client does not experience business interruption due to the switch. After the client completes the switch, it will no longer access the source cluster, making the target cluster the new data service provider. In addition, the client writes new simulated data to the target cluster to ensure that the switch is successful.
[0192] Through the above switching process, smooth migration of business requests is achieved, ensuring the integrity and consistency of data.
[0193] Figure 8 A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Figure 7 Based on the embodiment, further, Figure 8 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0194] A data synchronization status detection unit 801 is used to poll and detect the data synchronization status between the source cluster and the target cluster;
[0195] The data synchronization status judgment unit 802 is used to judge whether the data synchronization status is synchronization completed. If so, the source cluster and the target cluster have synchronized data.
[0196] Fig. 9 A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Figure 8Based on the embodiment, further, Fig. 9 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0197] The first cluster switchback control unit 901 is used to write a switchback mark with a value of switchback to the source cluster if the data synchronization state is incomplete due to timeout, so that after the client monitors that the value of the switchback mark is switchback through the message channel, it stops cluster switching and switches to normal mode.
[0198] Fig.10 A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Figure 8 Based on the embodiment, further, Fig.10 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0199] The command total statistics module 1001 is used to respectively count the total number of commands of each source shard in the source cluster and the total number of commands of each corresponding replica shard in the target cluster using command statistics instructions;
[0200] A command number difference calculation module 1002, used to calculate the command number difference according to the total number of commands of the source shard and the total number of commands of the corresponding replica shard;
[0201] A first iterative operation module 1003, configured to iteratively execute the above steps until a first preset time is exceeded or the command number difference is less than a first preset threshold;
[0202] The data synchronization status confirmation module 1004 is used to confirm that if the command number difference is less than a first preset threshold, the data synchronization status is synchronization completed; if the command number difference is still not less than the first preset threshold after a first preset time, the data synchronization status is timeout and incomplete.
[0203] Fig.11 A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Figure 7 Based on the embodiment, further, Fig.11 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0204] The second cluster switchback control unit 1101 is used to write a switchback mark with a value of switchback if the synchronization progress is incomplete due to timeout, so that the client stops cluster switching and switches to normal mode after monitoring that the switchback mark has a value of switchback through a message channel.
[0205] Fig.12A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Figure 7 Based on the embodiment, further, Fig.12 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0206] The simulation data acquisition module 1201 is used to acquire the simulation data written into the source cluster and the simulation data synchronized with the target cluster;
[0207] A simulation data difference calculation module 1202 is used to calculate the simulation data difference according to the simulation data written into the source cluster and the simulation data synchronized with the target cluster;
[0208] A second iterative operation module 1203, configured to iteratively execute the above steps until a second preset time is exceeded or the simulation data difference is less than a second preset threshold;
[0209] The synchronization progress confirmation module 1204 is used to determine that if the simulation data difference is less than a second preset threshold, the synchronization progress is synchronization completed; if the simulation data difference is still not less than the second preset threshold after a second preset time, the synchronization progress is timed out and incomplete.
[0210] Fig.13 A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Figure 7 Based on the embodiment, further, Fig.13 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0211] A write checking unit 1301 is used to check whether the source cluster and the target cluster have simulated data written;
[0212] The switching result determining unit 1302 is configured to determine that the cluster switching is successful if no simulation data is written to the source cluster and simulation data is written to the target cluster; otherwise, the cluster switching fails.
[0213] Fig.14 A schematic diagram of a structure of a client connection switching device for a multi-cache cluster provided in an embodiment of the present application, wherein Fig.13 Based on the embodiment, further, Fig.14 As shown, the client connection switching device of the multi-cache cluster provided by the present application also includes:
[0214] The mode switching control unit 1401 is configured to write a migration mark with a migration completion value to the source cluster when the cluster switching is successful, so that the client monitors the migration mark synchronized to the target cluster through the message channel and switches to the normal mode, and stops message monitoring and simulating data writing;
[0215] The third cluster switchback control unit 1402 is used to write a switchback mark with a value of switchback to the source cluster when the cluster switch fails, so that the client can switch back to the source cluster after monitoring the switchback mark synchronized to the target cluster through the message channel, stop writing simulation data and switch to normal mode.
[0216] The present application provides a method and device for switching client connections of a multi-cache cluster, which writes a migration mark with a value of "migrating" to a source cluster, so that the client can monitor the value of the migration mark through a message channel and then switch to a migration mode, monitor the switching mark and the read-write mark; when the source cluster and the target cluster have synchronized data, write simulated data with an incremental characteristic to the source cluster according to a preset time interval, and poll to detect the synchronization progress of the simulated data synchronized in the target cluster; if the synchronization progress is synchronization completion, write a read-write mark with a value of read-only to the source cluster, so that the client can monitor the synchronization progress through the message channel, and then switch to a migration mode; After hearing that the value of the read-write tag is read-only, it switches to read-only mode and stops writing information to the source cluster; deletes the simulated data in the source cluster, and polls to detect the deletion progress of the simulated data synchronized in the target cluster; if the deletion progress is deletion completion, writes a switch tag with a value of switch to the source cluster, so that the client can monitor the value of the switch tag through the message channel and switch the connection from the source cluster to the target cluster after switching, and writes simulated data, thereby achieving smooth switching of the connected cache cluster while the client is continuously running, ensuring service continuity and data consistency, and minimizing the client unavailability time.
[0217] Among them, by polling to detect the synchronization progress of the simulated data synchronized in the target cluster and the deletion progress of the simulated data synchronized in the target cluster, it is possible to ensure that the source cluster and the target cluster data are synchronized before the cluster switch to ensure data consistency; by writing a read-write mark with a value of read-only to the source cluster, so that the client can switch to read-only mode after listening to the value of the read-write mark through the message channel, stop writing information to the source cluster, and write a switch mark with a value of switch to the source cluster, so that the client can switch the connection from the source cluster to the target cluster after listening to the value of the switch mark through the message channel, which can shorten the service unavailable time during the switching process to the shortest. In addition, by writing a switch mark with a value of back-switching to the source cluster, so that the client can stop cluster switching and switch to normal mode after listening to the value of the switch mark through the message channel, it is possible to roll back the client connection to the source cluster when an abnormality occurs during the switching process, thereby ensuring normal business.
[0218] It should be noted that the client connection switching method and device for a multi-cache cluster provided in the embodiment of the present invention can be used in the financial field, and can also be used in any technical field other than the financial field. The embodiment of the present invention does not limit the application field of the client connection switching method and device for a multi-cache cluster.
[0219] Fig.15 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as Fig.15 As shown, the electronic device includes: a processor (processor) 1501, a memory (memory) 1502 and a bus 1503.
[0220] The processor 1501 and the memory 1502 communicate with each other via a bus 1503 .
[0221] The processor 1501 is used to call the program instructions in the memory 1502 to execute the methods provided by the above method embodiments.
[0222] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the client connection switching method of the multi-cache cluster is implemented.
[0223] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method for switching client connections of the multi-cache cluster is implemented.
[0224] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0225] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0226] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0227] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0228] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for switching client connections in a multi-cache cluster, characterized in that: include: Write a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after listening to the value of the migration mark as "migrating" through the message channel, and listens to the switching mark and the read-write mark; After the source cluster and the target cluster have synchronized data, write the simulated data with incremental characteristics to the source cluster according to a preset time interval, and poll to detect the synchronization progress of the simulated data synchronized in the target cluster; If the synchronization progress is synchronization completion, write a read-write mark with a value of read-only to the source cluster, so that the client switches to read-only mode after monitoring the value of the read-write mark as read-only through the message channel, and stops writing information to the source cluster; Deleting the simulated data in the source cluster, and polling to detect the deletion progress of the simulated data synchronized in the target cluster; If the deletion progress is deletion completed, a switch mark with a value of switch is written to the source cluster, so that the client monitors the switch mark with a value of switch through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
2. The method according to claim 1, characterized in that After the source cluster is synchronized with the target cluster data, before writing the simulated data with incremental characteristics to the source cluster according to a preset time interval and polling to detect the synchronization progress of the simulated data synchronized in the target cluster, the method further includes: Polling to detect the data synchronization status between the source cluster and the target cluster; It is determined whether the data synchronization status is synchronization completed, and if so, the source cluster and the target cluster have synchronized data.
3. The method according to claim 2, characterized in that Also includes: If the data synchronization state is incomplete due to timeout, a switch mark with a value of switchback is written to the source cluster, so that after the client monitors through the message channel that the value of the switch mark is switchback, the cluster switch is stopped and switched to the normal mode.
4. The method according to claim 2, characterized in that The polling to detect the data synchronization status between the source cluster and the target cluster includes: Use command statistics instructions to count the total number of commands for each source shard in the source cluster and the total number of commands for each corresponding replica shard in the target cluster; Calculate the difference in the number of commands according to the total number of commands of the source shard and the total number of commands of the corresponding replica shard; Iteratively executing the above steps until a first preset time is exceeded or the command number difference is less than a first preset threshold; If the command number difference is less than the first preset threshold, the data synchronization status is synchronization completed; if the command number difference is still not less than the first preset threshold after a first preset time, the data synchronization status is timeout and incomplete.
5. The method according to claim 1, characterized in that Also includes: If the synchronization progress is incomplete due to timeout, a switch mark with a value of switchback is written, so that after the client monitors the value of the switch mark as switchback through the message channel, the cluster switch is stopped and switched to the normal mode.
6. The method according to claim 1, characterized in that The polling to detect the synchronization progress of the simulated data synchronized in the target cluster includes: Acquire the simulated data written to the source cluster and the simulated data synchronized with the target cluster; Calculate the simulated data difference according to the simulated data written into the source cluster and the simulated data synchronized with the target cluster; Iteratively executing the above steps until a second preset time is exceeded or the simulation data difference is less than a second preset threshold; If the simulation data difference is less than the second preset threshold, the synchronization progress is synchronization completed; if the simulation data difference is still not less than the second preset threshold after continuing for a second preset time, the synchronization progress is timeout and incomplete.
7. The method according to claim 1, characterized in that After writing the switching mark with a value of switching to the source cluster, the method further includes: Check whether the source cluster and the target cluster have simulated data written; If the source cluster has no simulated data written and the target cluster has simulated data written, the cluster switching is successful; otherwise, the cluster switching fails.
8. The method according to claim 7, characterized in that Also includes: When the cluster switching is successful, a migration mark with a migration completion value is written to the source cluster, so that the client monitors the migration mark synchronized to the target cluster through the message channel and switches to the normal mode after the migration is completed, and stops message monitoring and simulating data writing; When cluster switching fails, a switch mark with a value of switchback is written to the source cluster, so that the client monitors through the message channel that the value of the switch mark synchronized to the target cluster is switchback and then switches back to the source cluster, stops writing simulation data and switches to normal mode.
9. A client connection switching device for a multi-cache cluster, characterized in that: include: A migration control unit, used for writing a migration mark with a value of "migrating" to the source cluster, so that the client switches to the migration mode after monitoring the value of the migration mark as "migrating" through the message channel, and monitors the switching mark and the read-write mark; A synchronization progress detection unit, configured to write simulation data with incremental characteristics to the source cluster according to a preset time interval after the source cluster and the target cluster have synchronized data, and to poll and detect the synchronization progress of the simulation data synchronized in the target cluster; A read-write control unit, configured to write a read-write mark with a value of read-only to the source cluster if the synchronization progress is synchronization completion, so that the client switches to read-only mode after monitoring that the value of the read-write mark is read-only through the message channel, and stops writing information to the source cluster; A deletion progress detection unit, used to delete the simulation data in the source cluster and poll and detect the deletion progress of the simulation data synchronized in the target cluster; The cluster switching control unit is used to write a switching mark with a value of switching to the source cluster if the deletion progress is deletion completion, so that the client monitors the value of the switching mark through the message channel and switches the connection from the source cluster to the target cluster after switching, and writes simulation data.
10. The device according to claim 9, characterized in that Also includes: A data synchronization status detection unit, used for polling and detecting the data synchronization status between the source cluster and the target cluster; The data synchronization status judgment unit is used to judge whether the data synchronization status is synchronization completed. If so, the source cluster and the target cluster have synchronized data.
11. The device according to claim 10, characterized in that Also includes: The first cluster switchback control unit is used to write a switchback mark with a value of switchback to the source cluster if the data synchronization state is incomplete due to timeout, so that after the client monitors that the value of the switchback mark is switchback through the message channel, it stops cluster switching and switches to normal mode.
12. The device according to claim 10, characterized in that The data synchronization state detection unit comprises: A command total statistics module is used to use command statistics instructions to respectively count the total number of commands of each source shard in the source cluster and the total number of commands of each corresponding replica shard in the target cluster; A command number difference calculation module, used to calculate the command number difference according to the total number of commands of the source shard and the total number of commands of the corresponding replica shard; A first iterative operation module, used for iteratively executing the above steps until a first preset time is exceeded or the command number difference is less than a first preset threshold; The data synchronization status confirmation module is used to determine that if the command number difference is less than a first preset threshold, the data synchronization status is synchronization completed; if the command number difference is still not less than the first preset threshold after a first preset time, the data synchronization status is timeout and incomplete.
13. The device according to claim 9, characterized in that Also includes: The second cluster switchback control unit is used to write a switch mark with a switchback value if the synchronization progress is incomplete due to timeout, so that the client stops cluster switching and switches to normal mode after monitoring that the switch mark value is switchback through the message channel.
14. The device according to claim 9, characterized in that The synchronization progress detection unit comprises: A simulation data acquisition module, used to acquire simulation data written into the source cluster and simulation data synchronized with the target cluster; A simulation data difference calculation module, used to calculate the simulation data difference according to the simulation data written into the source cluster and the simulation data synchronized with the target cluster; A second iterative operation module, used for iteratively executing the above steps until a second preset time is exceeded or the simulation data difference is less than a second preset threshold; The synchronization progress confirmation module is used to determine that if the simulation data difference is less than a second preset threshold, the synchronization progress is synchronization completed; if the simulation data difference is still not less than the second preset threshold after a second preset time, the synchronization progress is timed out and incomplete.
15. The device according to claim 9, characterized in that Also includes: A write check unit, used to check whether the source cluster and the target cluster have simulated data written; The switching result determining unit is used to determine that the cluster switching is successful if no simulation data is written to the source cluster and simulation data is written to the target cluster; otherwise, the cluster switching fails.
16. The device according to claim 15, characterized in that Also includes: A mode switching control unit, configured to write a migration mark with a migration completion value to the source cluster when the cluster switching is successful, so that the client monitors the migration mark synchronized to the target cluster through the message channel to switch to the normal mode after the migration is completed, and stop message monitoring and simulation data writing; The third cluster switchback control unit is used to write a switch mark with a switchback value to the source cluster when the cluster switch fails, so that the client can switch back to the source cluster after listening to the switch mark synchronized to the target cluster through the message channel, stop writing simulation data and switch to normal mode.
17. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 8 is implemented.
18. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
19. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.