Data processing method, device, equipment and storage medium
By introducing a circuit breaker mechanism in the database cluster, limiting the maximum number of switching times within the preset time, the problem of large-scale cluster switching caused by temporary network failure is solved, which improves switching efficiency and avoids waste of resources.
Patent Information
- Application Number
- CN202111284951.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-01
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2041-11-01
AI Technical Summary
In the event of a brief network failure, the prior art may lead to large-scale database cluster switching, resulting in waste of resources and data confusion, and lack of a circuit breaker mechanism to avoid unnecessary switching.
When the connection with the main databases of K database clusters fails, the first and second parameters are queried from the preset data table, these parameters are used to determine the parameters to be updated, and the parameters are updated through multiple threads, limiting them to the preset time. Perform a database cluster switching operation with the maximum number of switching times M.
The circuit breaker mechanism is implemented, which avoids large-scale cluster switching caused by temporary network failures, improves switching efficiency, and reduces resource waste.
Smart Images

Figure CN114064717B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data processing method, device, equipment and storage medium. Background Art
[0002] At present, database high availability is an eternal topic. When the master database hangs, a slave database needs to be promoted to the new master database to allow business writing to proceed normally. MySql high-availability switching open source software Orchestrator can switch multiple database clusters in parallel and each switch does not affect each other. For example, if Orchestrator fails to directly connect to the master database, and continues to fail to connect to the master database again through the slave database, it will be determined that the master database is hung, and the database cluster will be switched. However, when Orchestrator determines that a large-scale master database is hung, it may be that a temporary network failure has occurred. If the network recovers quickly, it is not worth switching a large-scale database cluster. Summary of the invention
[0003] In view of this, embodiments of the present invention are intended to provide a data processing method, apparatus, device, and storage medium.
[0004] The technical solution of the embodiment of the present invention is achieved as follows:
[0005] At least one embodiment of the present invention provides a data processing method, the method comprising:
[0006] In the case where the connection with the main database in the K database clusters fails, querying a first parameter and a second parameter from a preset data table; the first parameter is related to the maximum number of switching times M; the second parameter represents a first timestamp;
[0007] And do the following:
[0008] Determine a parameter to be updated from the first parameter and the second parameter;
[0009] Using the Nth thread, the value of the parameter to be updated is updated, and a switching operation is performed on the primary database of the Nth database cluster among the K database clusters;
[0010] And so on, until the number of switching operations completed within the preset time reaches the maximum number of switching times M;
[0011] Among them, N = 1, 2, ..., M; K is greater than M, and K and M are both integers.
[0012] In the above solution, determining the parameter to be updated from the first parameter and the second parameter includes:
[0013] If the second parameter meets the first preset condition, the second parameter is used as the parameter to be updated.
[0014] In the above solution, determining the parameter to be updated from the first parameter and the second parameter includes:
[0015] If the second parameter satisfies a second preset condition and the first parameter satisfies a third preset condition, the first parameter is used as a parameter to be updated.
[0016] In the above solution, determining the parameter to be updated from the first parameter and the second parameter includes:
[0017] If the second parameter satisfies a second preset condition and the first parameter satisfies a fourth preset condition, then stop determining the parameter to be updated from the first parameter and the second parameter.
[0018] In the above solution, the switching operation on the master database of the Nth database cluster among the K database clusters includes:
[0019] Switch the master database of the Nth database cluster among the K database clusters where the connection fails to occur to any slave database.
[0020] In the above scheme, the method further comprises:
[0021] Creating the preset data table;
[0022] The preset data table is saved locally.
[0023] In the above scheme, the method further comprises:
[0024] An initial value of the first parameter and an initial value of the second parameter are set in the preset data table.
[0025] At least one embodiment of the present invention provides a data processing device, comprising:
[0026] A first processing unit, configured to query a first parameter and a second parameter from a preset data table when all connections to the main databases in the K database clusters fail; the first parameter is related to a maximum number of switching times M; and the second parameter represents a first timestamp;
[0027] The second processing unit is configured to perform the following operations:
[0028] Determine a parameter to be updated from the first parameter and the second parameter;
[0029] Using the Nth thread, the value of the parameter to be updated is updated, and a switching operation is performed on the primary database of the Nth database cluster among the K database clusters;
[0030] And so on, until the number of switching operations completed within the preset time reaches the maximum number of switching times M;
[0031] Among them, N = 1, 2, ..., M; K is greater than M, and K and M are both integers.
[0032] At least one embodiment of the present invention provides a network device, characterized in that it includes a processor and a memory for storing a computer program that can be run on the processor.
[0033] Wherein, the processor is used to execute the steps of the method described above on the network device side when running the computer program.
[0034] At least one embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of any of the above methods when executed by a processor.
[0035] The data processing method, device, equipment and storage medium provided by the embodiment of the present invention, when the connection with the main database in K database clusters fails, queries the first parameter and the second parameter from the preset data table; the first parameter is related to the maximum switching number M; the second parameter represents the first timestamp; and performs the following operations: determining the parameter to be updated from the first parameter and the second parameter; using the Nth thread, updating the value of the parameter to be updated, and performing a switching operation on the main database of the Nth database cluster in the K database clusters; and so on, until the number of switching operations completed within the preset time reaches the maximum switching number M; wherein N=1, 2…, M; K is greater than M, and K and M are both integers. The technical solution of the embodiment of the present invention is adopted to realize the fuse mechanism, effectively avoid the occurrence of large-scale cluster switching problems caused by short-term network failures, and improve the switching efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a schematic diagram of the implementation flow of the data processing method according to an embodiment of the present invention;
[0037] Figure 2 It is a schematic diagram of a specific implementation flow of the data processing method according to an embodiment of the present invention;
[0038] Figure 3 It is a schematic diagram of part of the content in the preset data table of an embodiment of the present invention;
[0039] Figure 4 is a schematic diagram of variables defined in a preset data table according to an embodiment of the present invention;
[0040] Figure 5 is a schematic diagram of the values of the value and update_time fields recorded in the preset data table in an embodiment of the present invention;
[0041] Figure 6 It is a schematic diagram of the structure of a data processing device according to an embodiment of the present invention;
[0042] Figure 7 It is a schematic diagram of the composition structure of the network device according to the embodiment of the present invention. DETAILED DESCRIPTION
[0043] Before introducing the technical solution of the embodiment of the present invention, the related technology is first described.
[0044] In related technologies, database high availability is an eternal topic. When the master database of a database fails, a slave database needs to be promoted to the new master database to allow business writing to proceed normally. To complete the above operations, third-party open source software can be used. Orchestrator is one of the open source software for MySQL high availability switching. The interface-based operation method brings a lot of convenience to database administrators (DBA, DataBase Administrator).
[0045] The odd number of nodes of Orchestrator are distributed in multiple computer rooms, and the leader node is elected through the distributed protocol, namely the raft protocol. Each orchestrator node stores the MySQL cluster information it manages in the local MySQL database. Only the leader node has the right to switch the MySQL database cluster. When the leader node switches the MySQL database cluster, the switching operation log is synchronized to other nodes through the raft protocol, which ensures that the data of all nodes is consistent.
[0046] If Orchestrator fails to connect to the master database directly, and then fails to connect to the master database again through the slave database, then the master database will be considered to be down and the cluster will be switched. Before and after the slave database is promoted to the new master database, some hook scripts will be executed. If the script exit status is not 0, the subsequent switching operation will not continue. Orchestrator can switch multiple database clusters in parallel and each switch will not affect each other.
[0047] However, there is no mechanism to fuse large-scale switching in the related technology. When the network fails temporarily, the orchestrator will determine that the large-scale master database is down, and then perform a large-scale cluster switch. If the network recovers quickly, then the large-scale cluster switch is not worth it. Large-scale cluster switching is not conducive to DBA to compare data and repair clusters after switching. If some unknown problems cause large-scale cluster switching, it is very likely to cause the cluster to become chaotic.
[0048] Based on this, in an embodiment of the present invention, when the connection with the main databases in the K database clusters fails, a first parameter and a second parameter are queried from a preset data table; the first parameter is related to the maximum number of switching times M; the second parameter represents a first timestamp; and the following operations are performed: the parameter to be updated is determined from the first parameter and the second parameter; the value of the parameter to be updated is updated using the Nth thread, and a switching operation is performed on the main database of the Nth database cluster in the K database clusters; and so on, until the number of switching operations completed within the preset time reaches the maximum number of switching times M; wherein N=1, 2…, M; K is greater than M, and K and M are both integers.
[0049] Figure 1 Schematic diagram of the implementation flow of the data processing method of the embodiment of the present invention. Figure 1 As shown, the method includes steps 101 to 102:
[0050] Step 101: When all connections to the main databases in the K database clusters fail, query a first parameter and a second parameter from a preset data table; the first parameter is related to the maximum number of switching times M; the second parameter represents a first timestamp.
[0051] It can be understood that the database cluster may be composed of at least two database servers, and the database cluster may specifically refer to a relational database cluster.
[0052] It is understandable that the database cluster may adopt a one-master-multiple-slave architecture, that is, the database cluster may include a master database and multiple slave databases.
[0053] It can be understood that the failure to connect to the primary database in the database cluster may mean that after the failure to connect to the primary database, the failure to connect to the primary database again by the slave database will determine that the connection to the primary database in the database cluster has failed, that is, the primary database has hung up.
[0054] In actual applications, when a network failure occurs, it may be determined that the connection with the master databases in the K database clusters has failed, indicating that a large-scale master database has crashed. If the network failure is only temporary, that is, the network will recover soon, then it is unnecessary to switch the master databases of the K database clusters.
[0055] Based on this, in order to avoid large-scale cluster switching in the event of a short network failure, a fuse mechanism can be added, that is, the maximum number of switching within a preset time is limited.
[0056] In order to implement the fuse mechanism, the preset data table may be created and saved locally.
[0057] Furthermore, the initial value of the first parameter and the initial value of the second parameter may be set in the preset data table.
[0058] Specifically, the initial value of the first parameter is related to the maximum number of switching times M. For example, the initial value of the first parameter is set to M-1.
[0059] The second parameter represents a first timestamp; the first timestamp is smaller than the second timestamp. The second timestamp refers to a timestamp at which the second parameter is started to be recorded in the preset data table.
[0060] Step 102: perform the following operations: determine the parameter to be updated from the first parameter and the second parameter; use the Nth thread to update the value of the parameter to be updated, and perform a switching operation on the master database of the Nth database cluster among the K database clusters; and so on, until the number of switching operations completed within a preset time reaches a maximum number of switching operations M; wherein N=1, 2…, M; K is greater than M, and K and M are both integers.
[0061] It is understandable that in order to avoid large-scale cluster switching in the event of a short network failure, a fuse mechanism can be added, that is, a maximum number of switching times within a preset time period is limited.
[0062] In order to achieve the maximum number of switching times within a preset time length, after querying and obtaining the initial values of the first parameter and the second parameter, the parameter to be updated can be determined from the first parameter and the second parameter; then, by updating the value of the parameter to be updated, the maximum number of switching times within the preset time length can be achieved.
[0063] It can be understood that determining the parameter to be updated from the first parameter and the second parameter may include the following three situations:
[0064] In the first case, if the second parameter meets the first preset condition, the second parameter is used as the parameter to be updated.
[0065] That is to say, after the second parameter is taken as the parameter to be updated, the value of the second parameter can be updated, while the value of the first parameter remains unchanged.
[0066] In the second case, if the second parameter satisfies the second preset condition and the first parameter satisfies the third preset condition, the first parameter is used as the parameter to be updated.
[0067] That is to say, after taking the first parameter as the parameter to be updated, the value of the first parameter can be updated, while the value of the second parameter remains unchanged.
[0068] In a third case, if the second parameter satisfies a second preset condition and the first parameter satisfies a fourth preset condition, then the determination of the parameter to be updated from the first parameter and the second parameter is stopped.
[0069] That is, after stopping determining the parameter to be updated from the first parameter and the second parameter, the values of the first parameter and the second parameter remain at the current values.
[0070] With respect to the first situation described above, in one embodiment, determining the parameter to be updated from the first parameter and the second parameter includes:
[0071] If the second parameter meets the first preset condition, the second parameter is used as the parameter to be updated.
[0072] It can be understood that the first preset condition may refer to summing the time corresponding to the first timestamp represented by the second parameter with the preset duration to obtain a first value; converting the first value into a third timestamp, the third timestamp being less than the current timestamp. The current timestamp may refer to the timestamp of reading the second parameter in the preset data table.
[0073] For example, assuming that the first timestamp represented by the second parameter is 1608710638, the moment corresponding to the first timestamp is 2020-7-23 16:03:58, and the preset duration is 3 minutes, then the first value is 2020-7-23 16:06:58, and the first value is converted into a third timestamp of 1608710818. Assuming that the timestamp of reading the second parameter in the preset data table is 1608710900, the third timestamp is less than the timestamp of reading the second parameter in the preset data table, that is, the second parameter meets the first preset condition.
[0074] Further, after the second parameter is used as the parameter to be updated, the value of the parameter to be updated can be updated by using the Nth thread, and a switching operation is performed on the main database of the Nth database cluster among the K database clusters.
[0075] Here, updating the value of the parameter to be updated may refer to updating the value of the second parameter to the current timestamp, that is, reading the timestamp of the second parameter in the preset data table.
[0076] With respect to the second situation described above, in one embodiment, determining the parameter to be updated from the first parameter and the second parameter includes:
[0077] If the second parameter satisfies a second preset condition and the first parameter satisfies a third preset condition, the first parameter is used as a parameter to be updated.
[0078] It can be understood that the second preset condition may refer to summing the time corresponding to the first timestamp represented by the second parameter with the preset duration to obtain a first value; converting the first value into a third timestamp, the third timestamp being greater than or equal to the current timestamp. The current timestamp may refer to the timestamp of reading the second parameter in the preset data table.
[0079] For example, assuming that the first timestamp represented by the second parameter is 1608710638, the moment corresponding to the first timestamp is 2020-7-23 16:03:58, and the preset duration is 3 minutes, then the first value is 2020-7-23 16:06:58, and the first value is converted into a third timestamp of 1608710818. Assuming that the timestamp of reading the second parameter in the preset data table is 1608710800, the third timestamp is greater than the timestamp of reading the second parameter in the preset data table, that is, the second parameter meets the second preset condition; otherwise, it does not meet the second preset condition.
[0080] It can be understood that the first parameter satisfying the third preset condition may mean that the value of the first parameter is greater than or equal to a preset value, and the preset value is, for example, 1.
[0081] For example, assuming that the value of the first parameter is equal to M-1=5-1=4, and the preset value is equal to 1, since the value of the first parameter is greater than the preset value, the first parameter satisfies the third preset condition.
[0082] Further, after the first parameter is used as the parameter to be updated, the value of the parameter to be updated can be updated by using the Nth thread, and a switching operation is performed on the main database of the Nth database cluster among the K database clusters.
[0083] With respect to the third situation, determining the parameter to be updated from the first parameter and the second parameter includes:
[0084] If the second parameter satisfies a second preset condition and the first parameter satisfies a fourth preset condition, then the determination of the parameter to be updated from the first parameter and the second parameter is stopped.
[0085] It can be understood that the second parameter satisfying the second preset condition has been described above and will not be repeated here.
[0086] It can be understood that the first parameter satisfying the fourth preset condition may mean that the value of the first parameter is less than a preset value, and the preset value is, for example, 1.
[0087] For example, assuming that the value of the first parameter is equal to 0 and the preset value is equal to 1, since the value of the first parameter is less than the preset value, the first parameter satisfies the fourth preset condition; otherwise, it does not satisfy it.
[0088] Further, after stopping determining the parameters to be updated from the first parameters and the second parameters, the switching operation on the primary database of the Nth database cluster among the K database clusters may be stopped.
[0089] In actual application, the database cluster can adopt a one-master-multiple-slave architecture, that is, the database cluster can include a master database and multiple slave databases, so that when the master database connection fails, any slave database can be switched to a new master database.
[0090] Based on this, in one embodiment, performing a switching operation on the master database of the Nth database cluster among the K database clusters includes:
[0091] Switch the master database of the Nth database cluster among the K database clusters where the connection fails to occur to any slave database.
[0092] It can be understood that switching the master database where the connection failure occurs to any slave database may refer to switching any slave database to a new master database.
[0093] It should be noted that, in the case that the primary databases of the K database clusters all fail, the maximum number of switching times within the preset time period can be M times.
[0094] That is to say, after the preset time, if the network returns to normal, there is no need to switch the other database clusters except the M database clusters among the K database clusters, thereby improving the switching efficiency and avoiding resource waste.
[0095] For example, if the main databases of 10 database clusters all fail, the maximum number of switches that can be performed within 3 minutes is 5 times; if the network returns to normal after 3 minutes, there is no need to switch the remaining 5 database clusters.
[0096] It is understandable that after the preset time period, if the network returns to normal, the values of the first parameter and the second parameter in the preset data table can be restored to the initial values.
[0097] In the embodiment of the present invention, when the connection with the master databases in the K database clusters fails, a fuse mechanism is implemented, which has the following advantages:
[0098] (1) A circuit breaker mechanism is implemented to effectively avoid large-scale cluster switching caused by network failures or other problems.
[0099] (2) Utilize the transaction function of the MySQL InnoDB storage engine to allow only a limited number of switching operations to pass within a limited time.
[0100] Figure 2 is a schematic diagram of a specific implementation flow of the data processing method of an embodiment of the present invention, wherein the failover_circuit_breaker_config data table corresponds to the preset data table; value corresponds to the first parameter, and the initial value of value=M-1=4; the maximum number of switching times M=5; update_time corresponds to the second parameter, and the initial value of update_time is the first timestamp; PERIOD corresponds to the preset duration, such as 3 minutes; Figure 2 As shown, the method includes steps 201 to 208:
[0101] Step 201: The orchestrator node executes the PreFailoverProcesses script.
[0102] It is understandable that the orchestrator node executes the PreFailoverProcesses script to implement a circuit breaker mechanism that allows a maximum of 5 database clusters to switch within 3 minutes.
[0103] It is understandable that, when the orchestrator node fails to connect to the master databases in the K database clusters, before promoting the slave database to the new master database, the orchestrator node executes the PreFailoverProcesses script.
[0104] It should be noted that the orchestrator node and the K database clusters can be deployed on different servers. For example, the orchestrator node is deployed on server 1, and the K database clusters are deployed on server 2, server 3, ..., server K+1.
[0105] Step 202: The orchestrator node queries the values of the value and update_time fields in the failover_circuit_breaker_config data table.
[0106] It is understandable that the orchestrator node can use select for update to query the values of the value and update_time fields in the failover_circuit_breaker_config data table.
[0107] It is understandable that the orchestrator node can create a failover_circuit_breaker_config data table, ie, the preset data table, in the MySQL database that stores cluster information locally.
[0108] Figure 3 It is a schematic diagram of part of the contents in the preset data table.
[0109] Figure 4 is a schematic diagram of the variables defined in the preset data table, such as Figure 4 As shown, the defined variables include a preset duration, such as 3 minutes.
[0110] Figure 5 This is a schematic diagram of the values of the value and update_time fields recorded in the preset data table, such as Figure 5 As shown, the initial value of value is set to M-1=5-1=4, and the initial value of update_time is set to the first timestamp, such as 1608710638.
[0111] Step 203: sum the value of the update_time field and the value of PERIOD to obtain a first value, and convert the first value into a third timestamp; determine whether the third timestamp is less than the second timestamp; if the third timestamp is less than the second timestamp, execute step 204; otherwise, execute step 205.
[0112] It can be understood that the second timestamp may refer to the timestamp when the failover_circuit_breaker_config data table starts recording the values of value and update_time.
[0113] Step 204: Update the value of the update_time field in the failover_circuit_breaker_config data table to the current timestamp; and execute step 207.
[0114] It can be understood that the current timestamp may refer to the timestamp of reading the values of value and update_time in the failover_circuit_breaker_config data table.
[0115] It is understandable that the PreFailoverProcesses script will try to update the update_time record in the failover_circuit_breaker_config data table in the database on the local node.
[0116] It is understandable that the MySQL innodb storage engine can be used to store the failover_circuit_breaker_config data table. At the read committed transaction isolation level, multiple transactions concurrently update the same record in the innodb storage engine table. Due to the existence of innodb row locks, a transaction can only update and commit after another transaction completes and commits the update.
[0117] In other words, when the first thread is used to update the value of the update_time field in the failover_circuit_breaker_config data table, other threads do not update the value of the field, and other threads can directly use the value of the field updated by the thread.
[0118] Step 205: Determine whether the value of value is less than 1; if the value of value is greater than or equal to 1, execute step 206; otherwise, execute step 208.
[0119] Step 206: Update the value of value to value-1, and execute step 207.
[0120] It is understandable that the PreFailoverProcesses script will try to update the value record in the failover_circuit_breaker_config data table in the database on this node.
[0121] Step 207: Using the Nth thread, a switch is performed on the primary database of the Nth database cluster in the Kth database cluster.
[0122] Step 208: Stop switching.
[0123] In this example, the parallel switching operation initiated by the Orchestrator leader node attempts to query and update the same database record when executing the PreFailoverProcesses script. The switchover will continue only if the update succeeds, and the switchover will be aborted if it fails. This implements the fuse mechanism that suspends the switchover when the number of database clusters switched within a limited time reaches a certain target.
[0124] In order to implement the data processing method of the embodiment of the present invention, the embodiment of the present invention also provides a data processing device, Figure 6 FIG. 1 is a schematic diagram of the structure of a data processing device according to an embodiment of the present invention; Figure 6 As shown, the device comprises:
[0125] The first processing unit 61 is used to query a first parameter and a second parameter from a preset data table when all connections to the main databases in the K database clusters fail; the first parameter is related to the maximum number of switching times M; the second parameter represents a first timestamp;
[0126] The second processing unit 62 is configured to perform the following operations:
[0127] Determine a parameter to be updated from the first parameter and the second parameter;
[0128] Using the Nth thread, the value of the parameter to be updated is updated, and a switching operation is performed on the primary database of the Nth database cluster among the K database clusters;
[0129] And so on, until the number of switching operations completed within the preset time reaches the maximum number of switching times M;
[0130] Among them, N = 1, 2, ..., M; K is greater than M, and K and M are both integers.
[0131] In one embodiment, determining the parameter to be updated from the first parameter and the second parameter includes:
[0132] If the second parameter meets the first preset condition, the second parameter is used as the parameter to be updated.
[0133] In one embodiment, the second processing unit 62 is specifically configured to:
[0134] If the second parameter satisfies a second preset condition and the first parameter satisfies a third preset condition, the first parameter is used as a parameter to be updated.
[0135] In one embodiment, the second processing unit 62 is specifically configured to:
[0136] If the second parameter satisfies a second preset condition and the first parameter satisfies a fourth preset condition, then stop determining the parameter to be updated from the first parameter and the second parameter.
[0137] In one embodiment, the second processing unit 62 is specifically configured to:
[0138] Switch the master database of the Nth database cluster among the K database clusters where the connection fails to occur to any slave database.
[0139] In one embodiment, the second processing unit 62 is further configured to:
[0140] Creating the preset data table;
[0141] The preset data table is saved locally.
[0142] In one embodiment, the second processing unit 62 is further configured to:
[0143] An initial value of the first parameter and an initial value of the second parameter are set in the preset data table.
[0144] In actual application, the first processing unit 61 and the second processing unit 62 can be implemented by a processor in a data processing device.
[0145] It should be noted that: when the data processing device provided in the above embodiment performs data processing, only the division of the above program modules is used as an example. In actual applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device is divided into different program modules to complete all or part of the processing described above. In addition, the data processing device provided in the above embodiment and the data processing method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0146] The embodiment of the present invention also provides a network device, such as Figure 7 As shown, including:
[0147] Communication interface 71, capable of exchanging information with other devices;
[0148] The processor 72 is connected to the communication interface 71 and is used to execute the method provided by one or more technical solutions on the terminal side when running the computer program. The computer program is stored in the memory 73.
[0149] It should be noted that the specific processing process of the processor 72 and the communication interface 71 is detailed in the method embodiment and will not be repeated here.
[0150] Of course, in actual application, the various components in the network device 70 are coupled together through the bus system 74. It is understandable that the bus system 74 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 74 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 7 Various buses are labeled as bus system 74 .
[0151] The memory 73 in the embodiment of the present application is used to store various types of data to support the operation of the network device 70. Examples of such data include: any computer program used to operate on the network device 70.
[0152] The method disclosed in the above embodiment of the present application can be applied to the processor 72, or implemented by the processor 72. The processor 72 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 72. The above-mentioned processor 72 may be a general-purpose processor, a digital data processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 72 can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiment of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present application, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 73, and the processor 72 reads the information in the memory 73 and completes the steps of the above method in combination with its hardware.
[0153] In an exemplary embodiment, the network device 70 can be implemented by one or more application specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), field programmable gate array (FPGA), general processor, controller, microcontroller (MCU), microprocessor, or other electronic components to execute the aforementioned method.
[0154] It can be understood that the memory (memory 73) of the embodiment of the present application can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a ferromagnetic random access memory, a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), and direct RAMbus random access memory (DRRAM, Direct Rambus Random Access Memory).The memories described in the embodiments of the present application are intended to include, but are not limited to, these and any other suitable types of memories.
[0155] In an exemplary embodiment, the embodiment of the present invention further provides a storage medium, namely a computer storage medium, specifically a computer-readable storage medium, for example, a memory 71 storing a computer program, and the computer program can be executed by a processor 72 of a network device 70 to complete the steps of the aforementioned terminal side method. The computer-readable storage medium can be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface storage, optical disk, or CD-ROM.
[0156] It should be noted that: "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0157] In addition, the technical solutions described in the embodiments of the present invention can be arbitrarily combined without conflict.
[0158] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention.
Claims
1. A data processing method, characterized in that: The method comprises: In the case where the connection with the main database in the K database clusters fails, querying a first parameter and a second parameter from a preset data table; the first parameter is related to the maximum number of switching times M; the second parameter represents a first timestamp; And do the following: Determine a parameter to be updated from the first parameter and the second parameter; Using the Nth thread, the value of the parameter to be updated is updated, and a switching operation is performed on the primary database of the Nth database cluster among the K database clusters; And so on, until the number of switching operations completed within the preset time reaches the maximum number of switching times M; Among them, N = 1, 2, ..., M; K is greater than M, and K and M are both integers.
2. The method according to claim 1, characterized in that The determining the parameter to be updated from the first parameter and the second parameter comprises: If the second parameter meets the first preset condition, the second parameter is used as the parameter to be updated.
3. The method according to claim 1, characterized in that Determining a parameter to be updated from the first parameter and the second parameter includes: If the second parameter satisfies a second preset condition and the first parameter satisfies a third preset condition, the first parameter is used as a parameter to be updated.
4. The method according to claim 1, characterized in that: The determining the parameter to be updated from the first parameter and the second parameter comprises: If the second parameter satisfies a second preset condition and the first parameter satisfies a fourth preset condition, then the determination of the parameter to be updated from the first parameter and the second parameter is stopped.
5. The method according to claim 1, characterized in that The performing a switching operation on the master database of the Nth database cluster among the K database clusters includes: Switch the master database of the Nth database cluster among the K database clusters where the connection fails to occur to any slave database.
6. The method according to claim 1, characterized in that The method further comprises: Creating the preset data table; The preset data table is saved locally.
7. The method according to claim 6, characterized in that The method further comprises: An initial value of the first parameter and an initial value of the second parameter are set in the preset data table.
8. A data processing device, characterized in that: include: A first processing unit, configured to query a first parameter and a second parameter from a preset data table when all connections to the main databases in the K database clusters fail; the first parameter is related to a maximum number of switching times M; and the second parameter represents a first timestamp; The second processing unit is configured to perform the following operations: Determine a parameter to be updated from the first parameter and the second parameter; Using the Nth thread, the value of the parameter to be updated is updated, and a switching operation is performed on the primary database of the Nth database cluster among the K database clusters; And so on, until the number of switching operations completed within the preset time reaches the maximum number of switching times M; Among them, N = 1, 2, ..., M; K is greater than M, and K and M are both integers.
9. A network device, characterized in that: comprising a processor and a memory for storing a computer program capable of being executed on the processor, Wherein, when the processor is used to run the computer program, it executes the steps of the method described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Database switching method and device, computer equipment and storage medium
CN111198921A
Method and apparatus for outputting information
US20200097355A1