A method and device for determining a primary data center in a distributed system

By automatically determining the main data center identity by detecting the read and write status of the data center in a distributed system, the problem of difficulty in positioning from the data center after switching of the main data center in the prior art is solved, and efficient automatic positioning and service processing are achieved.

CN115237999BActive Publication Date: 2025-05-20NETSUNION CLEARING CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110446720.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-25
Publication Date
2025-05-20
Estimated Expiration
2041-04-25

AI Technical Summary

Technical Problem

After the main data center is switched in distributed systems, it is difficult for the slave data center to automatically locate the new main data center, which requires more manual intervention and is not efficient.

Method used

By executing the method in any data center of the distributed system, in response to the data center detection task, the main data center identification is obtained based on the read and write status detection of the database in the same data center as the server, and the main data center identification stored in the server is updated to finally determine the main data center in the distributed system.

Benefits of technology

It realizes automatic detection and obtaining the latest master data center identifier when switching the main data center, and quickly and accurately locate the main data center without manual intervention, which is more efficient, ensuring the timely processing of business requests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115237999B_ABST
    Figure CN115237999B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for determining a primary data center in a distributed system. The method is executed by any data center in the distributed system. The method includes: in response to a data center detection task, detecting and obtaining a primary data center identifier based on the read and write status of a database in the same data center as the server; updating the primary data center identifier stored in the server based on the detected primary data center identifier; and determining the primary data center in the distributed system based on the primary data center identifier stored in the server. When the primary data center switches, the present application can automatically detect and obtain the latest primary data center identifier at the data center level, thereby quickly and accurately locating the primary data center. The process does not require manual intervention and is more efficient. At the same time, it does not need to rely on the primary data center identifier maintained in an external system, which reduces the coupling with the external system and provides a guarantee for the timely processing of subsequent business requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of distributed systems, and in particular, to a method and device for determining a primary data center in a distributed system. Background Art

[0002] In a distributed system architecture, an Internet Data Center (IDC) is part of the network infrastructure resources, providing a high-end data transmission service and a high-speed access service, and offering users a comprehensive and complete solution.

[0003] To achieve a complete solution for high security, high reliability, high stability, and high-concurrency eventual consistency of data in a distributed system, existing data centers usually adopt a primary-secondary mode. In the primary-secondary mode, when the primary data center fails, its services can be quickly switched to another running secondary data center, and the switching process should be imperceptible to users.

[0004] However, the inventor found that after the primary data center is switched in the prior art, it is difficult for the secondary data center to locate the new primary data center, which requires a lot of manual intervention to complete and has low efficiency. Summary of the Invention

[0005] Embodiments of this application provide a method and device for determining a primary data center in a distributed system, an electronic device, and a storage medium to improve the efficiency of primary data center switching.

[0006] Embodiments of this application adopt the following technical solutions:

[0007] In a first aspect, embodiments of this application provide a method for determining a primary data center in a distributed system, which is executed by any one of the data centers in the distributed system. Among them, the method includes:

[0008] In response to a data center detection task, according to the read-write status of the database in the same data center as the server, detect the primary data center identifier;

[0009] Update the primary data center identifier stored in the server according to the detected primary data center identifier;

[0010] Determine the primary data center in the distributed system according to the primary data center identifier stored in the server.

[0011] Optionally, the read-write status includes the write status of the database. The detecting the primary data center identifier according to the read-write status of the database in the same data center as the server includes:

[0012] Perform a write operation on the database;

[0013] If the operation is successful, determine that the write status of the database is writable, use the identifier of the data center where this server is located as the primary data center identifier, and synchronize the primary data center identifier to the databases in the secondary data centers through the databases in the same data center as this server;

[0014] If the operation fails, determine that the write status of the database is not writable, obtain the detection task configuration file corresponding to this server, and detect the primary data center identifier according to the detection method recorded in the detection task configuration file.

[0015] Optionally, the performing a write operation on the database includes:

[0016] Determine whether the data center where this server is located is the initial primary data center;

[0017] If the data center where this server is located is the initial primary data center, perform an operation to update data on the test entry in the database;

[0018] If the data center where this server is located is the initial secondary data center, perform an operation to insert data on the test entry in the database;

[0019] Wherein, the test entry refers to a data table storing the initial primary data center identifier, and the data refers to the identifier of the data center.

[0020] Optionally, a business application is deployed on this server, and determining whether the data center where this server is located is the initial primary data center includes:

[0021] Obtain the detection task configuration file corresponding to this server according to the data center detection task, where the detection task configuration file includes the data center identifier corresponding to this server;

[0022] Obtain the initial primary data center identifier when the business application is started on this server;

[0023] If the data center identifier corresponding to this server is consistent with the initial primary data center identifier, determine that the data center where this server is located is the initial primary data center;

[0024] If the data center identifier corresponding to this server is inconsistent with the initial primary data center identifier, determine that the data center where this server is located is the initial secondary data center.

[0025] Optionally, the detection method includes a database detection method and an RPC remote procedure call detection method, and detecting the primary data center identifier according to the detection method recorded in the detection task configuration file includes:

[0026] If the detection method is the database detection method, the primary data center identifier is queried in a database in the same data center as the server, wherein the database in the same data center as the server can synchronize the primary data center identifier stored in the database according to the master-slave relationship between data centers;

[0027] If the detection method is the RPC remote procedure call detection method, the RPC interface of the designated data center corresponding to the data center where the server is located is called to query the primary data center identifier through the RPC interface, wherein the designated data center includes a data center in the same city and / or a data center in a different location.

[0028] Optionally, before responding to the data center detection task, the method further includes:

[0029] Start the business application and load the detection task configuration file of the server where the business application is located;

[0030] Verify the configuration parameters in the detection task configuration file;

[0031] If the verification is passed, the initial primary data center identifier is obtained according to the detection method in the configuration parameters, and the primary data center identifier stored in the server is updated according to the obtained initial primary data center identifier;

[0032] If the verification fails, the startup of the business application is prohibited and an error message is output.

[0033] Optionally, after responding to the data center detection task, the method further includes:

[0034] According to the data center detection task, obtaining the detection task configuration file corresponding to the server, wherein the detection task configuration file includes a detection switch and a detection mode;

[0035] If the detection switch is in the on state and the detection mode is the database detection mode, then the step of determining whether the data center where the server is located is the initial primary data center is executed;

[0036] If the detection switch is in the off state, the step of obtaining the detection task configuration file corresponding to the server and detecting and obtaining the main data center identifier according to the detection method recorded in the detection task configuration file is executed.

[0037] In a second aspect, the embodiment of the present application further provides a service request processing method, which is executed by any data center in a distributed system, wherein the method includes:

[0038] Receive a service request;

[0039] Obtain the interface name of the master data center;

[0040] Initiate a call according to the interface name of the master data center to forward the service request to the master data center for processing;

[0041] Wherein, the master data center is determined based on the method for determining the master data center in the distributed system described in any one of the foregoing items.

[0042] Optionally, the obtaining the interface name of the master data center includes:

[0043] Obtain the service name of this server;

[0044] Concatenate the updated master data center identifier stored in this server with the service name to obtain the interface name of the master data center.

[0045] In a third aspect, an embodiment of the present application further provides a device for determining a master data center in a distributed system, which is applied to any data center in the distributed system, wherein the device is used to implement the method for determining the master data center in the distributed system described in any one of the foregoing.

[0046] In a fourth aspect, an embodiment of the present application further provides a service request processing device, which is applied to any data center in the distributed system, wherein the device is used to implement the service request processing method described in any one of the foregoing.

[0047] In a fifth aspect, an embodiment of the present application further provides an electronic device, including:

[0048] A processor; and

[0049] A memory arranged to store computer-executable instructions, and when the executable instructions are executed, the processor executes the method for determining the master data center in the distributed system described in any one of the foregoing, or executes the service request processing method described in any one of the foregoing.

[0050] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium stores one or more programs, and when the one or more programs are executed by an electronic device including a plurality of application programs, the electronic device executes the method for determining the master data center in the distributed system described in any one of the foregoing, or executes the service request processing method described in any one of the foregoing.

[0051] The above at least one technical solution adopted in the embodiments of the present application can achieve the following beneficial effects: The method for determining the main data center in the distributed system of the embodiments of the present application can be executed by any data center in the distributed system. When locating the main data center in the distributed system, first, in response to the data center detection task, and according to the read-write status of the database in the same data center as the server, the main data center identifier is detected. Then, according to the detected main data center identifier, the main data center identifier stored in the server is updated. Finally, according to the main data center identifier stored in the server, the main data center in the distributed system is determined. The method for determining the main data center in the distributed system of the embodiments of the present application can automatically detect the latest main data center identifier at the data center level when the main data center switches, and then quickly achieve the accurate positioning of the main data center. This process requires no manual intervention and has higher efficiency, providing a guarantee for the timely processing of subsequent service requests. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:

[0053] Figure 1 is a schematic diagram of the process of processing service requests in a distributed system in the prior art;

[0054] Figure 2 is a schematic flowchart of a method for determining the main data center in a distributed system according to an embodiment of the present application;

[0055] Figure 3 is a schematic logic block diagram of detecting the main data center identifier according to an embodiment of the present application;

[0056] Figure 4 is a schematic logic block diagram of initializing and loading the main data center identifier when a service application is started according to an embodiment of the present application;

[0057] Figure 5 is a schematic structural diagram of a device for determining the main data center in a distributed system according to an embodiment of the present application;

[0058] Figure 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0059] To make the objectives, technical solutions and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts shall fall within the scope of protection of this application.

[0060] The technical solutions provided by each embodiment of this application will be described in detail below in conjunction with the drawings.

[0061] For the convenience of understanding each embodiment of this application, as Figure 1 shown, a schematic diagram of the process of processing service requests in a distributed system in the prior art is provided. It mainly involves the following three levels: the upper application layer, the data center layer, and the database layer. The upper application layer may include multiple terminals where the upper applications are distributed, which may refer to the terminals directly triggered by users for service requests. After the upper application layer generates a service request, it will forward the service request to the data center layer. The data center layer may include multiple data centers, and each data center can be regarded as a computer room, which may consist of multiple servers and is used to process the service requests sent by the upper application layer. The database layer includes multiple databases connected to each data center and is used to respond to the access requests of the servers in the data center and perform operations such as data storage and synchronization.

[0062] In an actual application scenario, the above data center layer generally includes a main data center and multiple slave data centers. For example, Figure 1 in the figure, data center A is the main data center, and data centers B and C are slave data centers. After the server in the main data center A receives a service request, it can directly process the service request and perform data reading, writing, and synchronization operations by accessing the database connected to the main data center A. After the servers in the slave data centers B and C receive a service request, they cannot directly process the service request but need to forward the service request to the main data center A for service processing. After that, the database connected to the main data center A will synchronize the processed data to the databases connected to the servers in the slave data centers B and C according to the synchronization relationship between the databases.

[0063] When the main data center A fails, it can no longer process service requests. At this time, it is necessary to promptly switch the main data center, and let other data centers take over the work of the original main data center A to avoid affecting the timely processing of service requests.

[0064] The switch of the main data center is an overall switch involving all levels in the distributed system architecture. Specifically, it involves each database in the database layer, that is, the switch of the physical database, and each server in the data center layer, that is, the switch of the business service layer, both of which need to be switched uniformly.

[0065] The existing switching methods are usually divided into two steps: 1) Manual switching of the database layer: By providing a unified switching operation entry, the entire physical database is switched uniformly; 2) Manual switching of the data center layer: After the database is switched, the main data center identifier is manually switched separately in the data center layer. The main data center identifier is generally maintained in the operation system. However, both of the two switching processes above are completed by manual intervention, resulting in low switching efficiency and high coupling degree due to relying on the maintenance entry of the operation system when switching the main data center.

[0066] Based on this, for the above-mentioned switching of the data center layer, the embodiments of this application provide a method for determining the main data center in a distributed system, which is executed by any one of the data centers in the distributed system, such as Figure 2 As shown, it provides a schematic flowchart of a method for determining the main data center in a distributed system according to an embodiment of this application. The method at least includes the following steps S210 to step S230:

[0067] Step S210, in response to the data center detection task, detect the main data center identifier according to the read-write state of the database in the same data center as the current server.

[0068] The distributed system in the embodiments of this application may specifically refer to a distributed cross-center master-slave system, that is, a distributed system composed of a main data center and multiple slave data centers.

[0069] The method for determining the main data center in the distributed system of the embodiments of this application can be executed by any one of the data centers in the distributed system, specifically by each server in each data center. When locating the main data center, it can first receive the data center detection task. Here, the data center detection task can be understood as the task of determining the main data center in the current data center layer. This data center detection task can be generated by a separate task server and sent to each server node in the data center layer, or can be pre-deployed to each server node and executed regularly by setting a timing task, for example, once per minute. Of course, how to configure the data center detection task specifically can be flexibly set by those skilled in the art according to actual needs, and no specific limitation is made here.

[0070] Since the database connected to the primary data center has read and write permissions for data, while the database connected to the secondary data center has only read permissions for data and no write permissions. Based on this, in the embodiment of the present application, when determining the primary data center, the detection of the primary data center identifier can be performed according to the read and write status of the database in the same data center as the present server. "Detection" can be understood as a process of obtaining relevant information of the primary data center. For example, the primary data center identifier can be regarded as the unique identifier information of the primary data center.

[0071] Step S220: Update the primary data center identifier stored in the present server according to the detected primary data center identifier.

[0072] After detecting the primary data center identifier, it is necessary to update the primary data center identifier cached in the present server according to the detected primary data center identifier to realize the switching of the primary data center identifier at the data center level.

[0073] Step S230: Determine the primary data center in the distributed system according to the primary data center identifier stored in the present server.

[0074] After updating the primary data center identifier cached in the present server, the primary data center in the distributed system can be determined according to the updated primary data center identifier. In this way, when the present server receives a new service request subsequently, the service request can be forwarded to the corresponding primary data center for service processing.

[0075] When the primary data center in the distributed system of the embodiment of the present application is switched, the latest primary data center identifier can be automatically detected at the data center level, and then the accurate positioning of the primary data center can be quickly realized. This process does not require manual intervention and has higher efficiency, providing a guarantee for the timely processing of subsequent service requests.

[0076] In an embodiment of the present application, the read and write status includes the write status of the database. The detection of the primary data center identifier according to the read and write status of the database in the same data center as the present server includes: performing a write operation on the database; if the operation is successful, determining that the write status of the database is writable, taking the identifier of the data center where the present server is located as the primary data center identifier, and synchronizing the primary data center identifier to the database of the secondary data center through the database in the same data center as the present server; if the operation fails, determining that the write status of the database is not writable, obtaining the detection task configuration file corresponding to the present server, and detecting the primary data center identifier according to the detection method recorded in the detection task configuration file.

[0077] When detecting the main data center identifier according to the read / write status of the database in the same data center as the server, a write operation can be first performed on the database in the same data center as the server. If the write operation is successful, it indicates that the database connected to the server has write permission, and the data center where the server is located is the current main data center. At this time, the identifier of the data center where the server is located can be directly used as the main data center identifier.

[0078] In addition, based on the data synchronization relationship between the databases in the main data center and the secondary data centers, the main data center identifier can be synchronized to the databases in the secondary data centers, so that the databases in the secondary data centers can obtain the latest main data center identifier. Of course, in addition to the automatic synchronization method according to the synchronization relationship, the main data center identifier can also be sent to the databases in the secondary data centers according to instructions or requests, etc., which will not be listed one by one here.

[0079] If the write operation fails, it indicates that the database connected to the server does not have write permission, and the data center where the server is located is not the current main data center. However, the server needs to further confirm the location of the current main data center to forward the service request to the corresponding main data center for processing later. Therefore, here, the detection task configuration file corresponding to the server can be obtained, and the main data center identifier can be detected according to the detection method recorded in the detection task configuration file.

[0080] In an embodiment of the present application, the write operation on the database includes: determining whether the data center where the server is located is the initial main data center; if the data center where the server is located is the initial main data center, then perform an operation of updating data on the test entry in the database; if the data center where the server is located is the initial secondary data center, then perform an operation of inserting data on the test entry in the database; where the test entry refers to a data table storing the initial main data center identifier, and the data refers to the identifier of the data center.

[0081] As Figure 3 shown, a detection logic block diagram of the main data center identifier in an embodiment of the present application is provided. The test entry in the embodiment of the present application can be understood as a separately set detection data table in the database, mainly used for storing and updating the main data center identifier. The initial main data center identifier is stored in the detection data table. When a new data center identifier enters the detection data table, the new entered data center identifier is used as the latest main data center identifier.

[0082] The write operation in the embodiment of the present application may specifically include two operations: updating data and inserting data. Here, for the primary data center, the operation of updating data is mainly to avoid data redundancy in the detection data table. For example, if the data center where this server is located is the initial primary data center, it means that the initial primary data center identifier stored in the detection data table has not changed. Then, an update operation for updating the initial primary data center identifier can be directly executed in the detection data table. If the update is successful, it indicates that the data center where this server is located is still the primary data center and there has been no switch of the primary data center. At this time, the initial primary data center identifier recorded in the detection data table is still the latest primary data center identifier.

[0083] If the data center where this server is located is the initial secondary data center, the initial primary data center identifier stored in the detection data table is not the identifier of the data center where this server is located. To determine whether the data center where this server is located has become the current primary data center, an insert operation for inserting the identifier of the data center where this server is located can be directly executed in the database. If the insert is successful, it indicates that the data center where this server is located has changed from the initial secondary data center to the current primary data center, that is, there has been a switch of the primary data center. At the same time, the identifier of the data center where this server is located is also stored in the detection data table as the latest primary data center identifier.

[0084] The above update operation performed on the primary data center can, to a certain extent, reduce data redundancy in the detection data table and avoid excessive occupation of the database storage space.

[0085] The primary data center identifiers detected in the above two cases can be correspondingly updated to the cache of this server. Of course, for the first case where the primary data center has not switched, the above "update" can be understood as the primary data center identifier has not changed.

[0086] In an embodiment of the present application, a business application is deployed on this server. Determining whether the data center where this server is located is the initial primary data center includes: obtaining the detection task configuration file corresponding to this server according to the data center detection task, where the detection task configuration file includes the data center identifier corresponding to this server; obtaining the initial primary data center identifier when the business application is started on this server; if the data center identifier corresponding to this server is consistent with the initial primary data center identifier, determining that the data center where this server is located is the initial primary data center; if the data center identifier corresponding to this server is inconsistent with the initial primary data center identifier, determining that the data center where this server is located is the initial secondary data center.

[0087] The server in the embodiment of the present application can be understood as a machine with a specific business application service deployed, and the "initial" in the initial primary data center and the initial secondary data center can be understood as the time point or time period when the business application service is started on the server.

[0088] Therefore, when determining whether the data center where the server is located is the initial primary data center, you can first obtain the detection task configuration file corresponding to the server. The detection task configuration file contains various configuration information associated with the data center, which may specifically include the data center identifier corresponding to the server. Then obtain the initial primary data center identifier recorded when the business application is started on the server, and compare the data center identifier corresponding to the server with the initial primary data center identifier. If the data center identifier corresponding to the server is consistent with the initial primary data center identifier, it means that the data center where the server is located is the initial primary data center. If they are inconsistent, it means that the data center where the server is located is the initial secondary data center.

[0089] In one embodiment of the present application, the detection method includes a database detection method and an RPC remote procedure call detection method, and the detection method recorded in the detection task configuration file to obtain the main data center identifier includes: if the detection method is the database detection method, then querying the main data center identifier in a database in the same data center as the server, wherein the database in the same data center as the server can synchronize the main data center identifier stored in the database according to the master-slave relationship between data centers; if the detection method is the RPC remote procedure call detection method, then calling the RPC interface of the designated data center corresponding to the data center where the server is located, so as to query the main data center identifier through the RPC interface, wherein the designated data center includes a data center in the same city and / or a data center in a different location.

[0090] As mentioned above, if the write operation to the database in the same data center as the server fails, it can only be determined that the data center where the server is located is not the current primary data center, but it is still necessary to further confirm the location of the current primary data center so that the service request can be forwarded later. Therefore, if Figure 3 As shown, in the case of the above write operation failure, the embodiment of the present application mainly provides the following two detection methods to further detect the main data center identifier, one is the database (DB) detection method, and the other is the remote procedure call (RPC) detection method. These two detection methods are also pre-configured in the detection task configuration file.

[0091] The DB detection method can be understood as obtaining the main data center identifier through the database connected to this server. The databases in the embodiments of this application have been synchronized and configured in advance. Therefore, each database can synchronize the main data center identifier stored in other databases according to the master-slave relationship between data centers. Here, it mainly refers to the database of the main data center synchronizing the main data center identifier to the database of the slave data center, so as to ensure that each server can obtain the latest main data center identifier from the database it is connected to.

[0092] The RPC detection method is mainly applicable to some special scenarios. For example, a certain server in the data center is not connected to the database, and at this time, the main data center identifier cannot be directly obtained from the database. Therefore, the query interface set on the server of other data centers can be called through RPC to obtain the main data center identifier recorded in other data centers.

[0093] When the RPC detection method is adopted, in order to improve the efficiency of RPC calls, the distance of the data center to be called can be further considered. Specifically, data centers can be mainly divided into local data centers and remote data centers according to geographical locations. A local data center is a data center in the same city as this data center, such as both being Beijing data centers. A remote data center refers to a data center in a different city from this data center. For example, this data center is a Beijing data center and the remote data center is a Shenzhen data center.

[0094] Therefore, before making an RPC call, the call priority can be set in advance. For example, set the RPC call priority of the local data center to be higher than that of the remote data center, so as to ensure that the local data center can be called first when an RPC call is needed, improve the RPC call efficiency, and further improve the positioning efficiency of the main data center.

[0095] In an embodiment of this application, before responding to the data center detection task, the method further includes: starting the business application and loading the detection task configuration file of this server where the business application is located; verifying the configuration parameters in the detection task configuration file; if the verification passes, obtaining the initial main data center identifier according to the detection method in the configuration parameters, and updating the main data center identifier stored in this server according to the obtained initial main data center identifier; if the verification fails, prohibiting the startup of the business application and outputting an error message.

[0096] The above embodiment detects the main data center identifier after the business application is started. Therefore, as Figure 4As shown, a logic block diagram for initializing and loading the main data center identifier when a service application is started in an embodiment of the present application is provided. Specifically, before responding to the data center detection task in the embodiment of the present application, the service application will be started first, and the detection task configuration file of the server where the service application is located will be initialized and loaded. Here, the detection task configuration file also refers to a file containing various configuration information related to each server in the data center. For example, it may include the task execution interval time, detection method, detection switch, the data center identifier where the current service application is located, application name, start delay start time, etc. Of course, as for which specific configuration information is included, those skilled in the art can flexibly set it according to actual needs and no specific limitation is made here.

[0097] Afterwards, to ensure the smooth progress of subsequent detection tasks, the legality and integrity of each configuration parameter in the above detection task configuration file can be verified. If the verification passes, the initial main data center identifier can be obtained through the detection method configured in the configuration parameter, such as the DB detection method or the RPC detection method, and then the main data center identifier cached in the server can be updated according to the obtained initial main data center identifier. If the verification fails, for example, some parameter configurations are illegal or the parameter configurations are incomplete, the startup of the service application can be prohibited and an error message can be output to facilitate subsequent reconfiguration of relevant parameters and restart.

[0098] Since the detection of the main data center identifier in the embodiment of the present application mainly targets the situation where the main data center switches, it can be defaulted here that each server initially knows the location of the initial main data center. Therefore, the initial main data center identifier is also stored in the database connected to each server as the basis for subsequent detection and update.

[0099] In an embodiment of the present application, after responding to the data center detection task, the method further includes: obtaining the detection task configuration file corresponding to the server according to the data center detection task, where the detection task configuration file includes a detection switch and a detection method; if the detection switch is in the on state and the detection method is the database detection method, then perform the step of determining whether the data center where the server is located is the initial main data center; if the detection switch is in the off state, then perform the step of obtaining the detection task configuration file corresponding to the server and detecting the main data center identifier according to the detection method recorded in the detection task configuration file.

[0100] To meet different application scenarios, in the detection task configuration file of the embodiments of the present application, in addition to setting the detection method, a detection switch is also set. When the detection switch is in the on state and the detection method is the database detection method, the main data center identifier can be detected by the above method of performing a write operation on the database. If the detection switch is in the off state, the main data center identifier can be detected according to the detection method recorded in the detection task configuration file, such as the DB query or RPC call method.

[0101] For the on and off states of the detection switch, those skilled in the art can flexibly set them according to the needs of the actual application scenario. For example, in the production environment, the detection switch is generally in the on state. In the test environment, if frequent detection is not required, the detection switch can be turned off. When the state of the detection switch needs to be adjusted, it can be directly modified in the detection task configuration file. The parameter form of the detection switch set in the detection task configuration file can be, for example, setting "0" to represent the off state and setting "1" to represent the on state. Of course, other forms can also be used, and no specific limitation is made here.

[0102] The detection method of the main data center identifier adopted in the above embodiments does not need to rely on the main data center identifier maintained in the external system, reduces the coupling degree with the external system, improves the positioning efficiency of the main data center, and further ensures the high security, high reliability and high stability of data processing in the distributed system.

[0103] The embodiments of the present application also provide a service request processing method, which is executed by any one of the data centers in the distributed system. The method includes: receiving a service request; obtaining the interface name of the main data center; initiating a call according to the interface name of the main data center to forward the service request to the main data center for processing, where the main data center is determined by the method for determining the main data center in the distributed system according to any one of the foregoing items.

[0104] After the service application is started on the local server, the local server will start to receive service requests one after another. At this time, the local server can locate the position of the current main data center through the main data center identifier cached locally, and then obtain the interface name of the main data center. Here, the interface name can be understood as a name containing main data center identifier information, call address information, etc. Then, an RPC call is initiated to the service interface of the main data center according to the interface name of the main data center, and thus the service request can be forwarded to the corresponding main data center for processing.

[0105] Of course, it should be noted that if the data center where the local server is located is the current main data center, there is no need to forward the service request and the service can be directly processed.

[0106] In an embodiment of the present application, the obtaining of the interface name of the primary data center includes: obtaining the service name of the present server; splicing the updated primary data center identifier stored in the present server with the service name to obtain the interface name of the primary data center.

[0107] In business applications, there are clear agreements on the service naming of different data centers. Service naming is usually related to the identification information of each data center. Therefore, after the primary data center is switched, the service name will be spliced and obtained through the identifier of the switched primary data center, and this is used as the interface name of the primary data center. Thus, servers in different data centers construct the routing of the primary data center service through the primary data center identifier, realizing the fast forwarding and processing of business requests, and further improving the business processing efficiency.

[0108] An embodiment of the present application further provides a determining device 500 for the primary data center in a distributed system, which is applied to any one of the data centers in the distributed system, such as Figure 5 As shown, a schematic structural diagram of a determining device for the primary data center in an embodiment of the present application is provided. The device 500 includes: a detection unit 510, an update unit 520, and a determination unit 530, where:

[0109] The detection unit 510 is configured to, in response to a data center detection task, detect a primary data center identifier according to the read / write state of a database in the same data center as the present server;

[0110] The update unit 520 is configured to update the primary data center identifier stored in the present server according to the detected primary data center identifier;

[0111] The determination unit 530 is configured to determine the primary data center in the distributed system according to the primary data center identifier stored in the present server.

[0112] In an embodiment of the present application, the read / write state includes the write state of the database. The detection unit 510 is specifically configured to: perform a write operation on the database; if the operation is successful, determine that the write state of the database is a writable state, use the identifier of the data center where the present server is located as the primary data center identifier, and synchronize the primary data center identifier to the database of the slave data center through the database in the same data center as the present server; if the operation fails, determine that the write state of the database is an unwritable state, obtain the detection task configuration file corresponding to the present server, and detect the primary data center identifier according to the detection method recorded in the detection task configuration file.

[0113] In one embodiment of the present application, the detection unit 510 is specifically configured to: determine whether the data center where the present server is located is the initial master data center; if the data center where the present server is located is the initial master data center, perform an operation of updating data on the test entries in the database; if the data center where the present server is located is the initial slave data center, perform an operation of inserting data on the test entries in the database; wherein, the test entries refer to the data table storing the initial master data center identifier, and the data refers to the identifier of the data center.

[0114] In one embodiment of the present application, a business application is deployed on the present server, and the detection unit 510 is specifically configured to: according to the data center detection task, obtain the detection task configuration file corresponding to the present server, wherein the detection task configuration file includes the data center identifier corresponding to the present server; obtain the initial master data center identifier when the business application is started on the present server; if the data center identifier corresponding to the present server is consistent with the initial master data center identifier, determine that the data center where the present server is located is the initial master data center; if the data center identifier corresponding to the present server is inconsistent with the initial master data center identifier, determine that the data center where the present server is located is the initial slave data center.

[0115] In one embodiment of the present application, the detection method includes a database detection method and an RPC remote procedure call detection method, and the detection unit 510 is specifically configured to: if the detection method is the database detection method, query the master data center identifier in the database in the same data center as the present server, wherein the database in the same data center as the present server can synchronize the master data center identifier stored in the database according to the master-slave relationship between data centers; if the detection method is the RPC remote procedure call detection method, call the RPC interface of the specified data center corresponding to the data center where the present server is located to query the master data center identifier through the RPC interface, wherein the specified data center includes an in-city data center and / or an out-of-city data center.

[0116] In one embodiment of the present application, the device further includes: a start unit, configured to start the business application and load the detection task configuration file of the present server where the business application is located; a verification unit, configured to verify the configuration parameters in the detection task configuration file; a first acquisition unit, configured to, if the verification passes, obtain the initial master data center identifier according to the detection method in the configuration parameters, and update the master data center identifier stored in the present server according to the obtained initial master data center identifier;

[0117] If the verification fails, prohibit the start of the business application and output an error message.

[0118] In one embodiment of the present application, the device further includes: a second acquisition unit, configured to acquire a detection task configuration file corresponding to the present server according to the data center detection task, where the detection task configuration file includes a detection switch and a detection method; a first execution unit, configured to execute the step of determining whether the data center where the present server is located is the initial primary data center if the detection switch is in an on state and the detection method is a database detection method; a second execution unit, configured to execute the step of acquiring the detection task configuration file corresponding to the present server and detecting the primary data center identifier according to the detection method recorded in the detection task configuration file if the detection switch is in an off state.

[0119] An embodiment of the present application further provides a service request processing device, which is applied to any one of the data centers in a distributed system. The device includes: a receiving unit, configured to receive a service request; a third acquisition unit, configured to acquire the interface name of the primary data center; a forwarding unit, configured to initiate a call according to the interface name of the primary data center to forward the service request to the primary data center for processing, where the primary data center is determined by the method for determining the primary data center in the distributed system described in any one of the foregoing.

[0120] In one embodiment of the present application, the third acquisition unit is specifically configured to: acquire the service name of the present server; splice the updated primary data center identifier stored in the present server with the service name to obtain the interface name of the primary data center.

[0121] It can be understood that the device for determining the primary data center in the distributed system can implement each step of the method for determining the primary data center in the distributed system executed by any one of the data centers in the foregoing embodiment. The related explanations about the method for determining the primary data center in the distributed system are applicable to the device for determining the primary data center in the distributed system, and the same is true for the service request processing device, which will not be elaborated here.

[0122] Figure 6 It is a schematic structural diagram of an electronic device according to an embodiment of the present application. Please refer to Figure 6 , at the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. Among them, the memory may include a memory, such as a high-speed random access memory (Random-Access Memory, RAM), and may also include a non-volatile memory, such as at least one disk memory, etc. Of course, the electronic device may also include other hardware required for other services.

[0123] The processor, network interface, and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity in representation, Figure 6 only a bidirectional arrow is used herein, but it does not mean that there is only one bus or one type of bus.

[0124] Memory, which is used to store programs. Specifically, a program can include program code, and the program code includes computer operation instructions. The memory can include a memory and a non-volatile memory, and provides instructions and data to the processor.

[0125] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a determining device for the main data center in the distributed system at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations:

[0126] In response to a data center detection task, according to the read / write status of the database in the same data center as this server, detect the main data center identifier;

[0127] According to the detected main data center identifier, update the main data center identifier stored in this server;

[0128] According to the main data center identifier stored in this server, determine the main data center in the distributed system.

[0129] As described in this application above Figure 5The method executed by the determining device of the main data center in the distributed system disclosed in the illustrated embodiment can be applied to or implemented by a processor. The processor 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 integrated logic circuit of the hardware in the processor or the instructions in the form of software. The above-mentioned processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed by the hardware decoding processor, or executed by the combination of the hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps of the above method.

[0130] The electronic device can also execute Figure 5 the method executed by the determining device of the main data center in the distributed system in Figure 5 the illustrated embodiment, and implement the function of the determining device of the main data center in the distributed system in

[0131] Embodiments of the present application also propose a computer-readable storage medium. The computer-readable storage medium stores one or more programs. The one or more programs include instructions that, when executed by an electronic device including multiple application programs, can enable the electronic device to execute Figure 5 the method executed by the determining device of the main data center in the distributed system in the illustrated embodiment, and specifically used to execute:

[0132] In response to the data center detection task, according to the read-write status of the database in the same data center as the present server, detect the main data center identifier;

[0133] Update the primary data center identifier stored in this server according to the detected primary data center identifier;

[0134] Determine the primary data center in the distributed system according to the primary data center identifier stored in this server.

[0135] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can 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.

[0136] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be realized by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate means for realizing the specified functions in one process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0137] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means, and the instruction means realizes the specified functions in one process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0138] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for realizing the specified functions in one process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0139] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and a memory.

[0140] Memory may include non-permanent storage in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0141] Computer-readable media include permanent and non-permanent, removable and non-removable media that can implement information storage by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0142] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device that includes a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises one..." do not exclude the existence of other identical elements in the process, method, commodity or device that includes the elements.

[0143] It should be understood by those skilled in the art that the embodiments of the present application can be provided as methods, systems or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the present application can 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.

[0144] The above description is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent substitution, improvement, etc. made within the spirit and principle of the present application shall be included in the scope of the claims of the present application.

Claims

1. A method for determining a primary data center in a distributed system, performed by any data center in the distributed system, wherein: The method comprises: In response to the data center detection task, according to the read and write status of the database in the same data center as the server, the primary data center identifier is detected; According to the main data center identifier obtained by detection, the main data center identifier stored in the server is updated; Determine the primary data center in the distributed system according to the primary data center identifier stored in the server; The read / write status includes the write status of the database, and the detection of the primary data center identifier based on the read / write status of the database in the same data center as the server includes: Performing a write operation on the database; If the operation is successful, the write state of the database is determined to be writable, the identifier of the data center where the server is located is used as the primary data center identifier, and the primary data center identifier is synchronized to the database in the secondary data center through the database in the same data center as the server; If the operation fails, it is determined that the write state of the database is a non-writable state, the detection task configuration file corresponding to the server is obtained, and the main data center identifier is detected according to the detection method recorded in the detection task configuration file.

2. The method of claim 1, wherein: The performing a write operation on the database comprises: Determine whether the data center where the server is located is the initial primary data center; If the data center where the server is located is the initial primary data center, performing an operation of updating data on the test entry in the database; If the data center where the server is located is the initial slave data center, inserting data into the test entry in the database; The test entry refers to a data table storing an initial master data center identifier, and the data refers to an identifier of a data center.

3. The method of claim 2, wherein: The server has a business application deployed thereon, and determining whether the data center where the server is located is the initial primary data center includes: According to the data center detection task, obtaining a detection task configuration file corresponding to the server, wherein the detection task configuration file includes a data center identifier corresponding to the server; Obtaining an initial primary data center identifier when the business application is started on the server; If the data center identifier corresponding to the server is consistent with the initial primary data center identifier, then the data center where the server is located is determined to be the initial primary data center; If the data center identifier corresponding to the present server is inconsistent with the initial master data center identifier, the data center where the present server is located is determined to be the initial slave data center.

4. The method of claim 1, wherein: The detection method includes a database detection method and an RPC remote procedure call detection method. The detection method recorded in the detection task configuration file to obtain the primary data center identifier includes: If the detection method is the database detection method, the primary data center identifier is queried in a database in the same data center as the server, wherein the database in the same data center as the server can synchronize the primary data center identifier stored in the database according to the master-slave relationship between data centers; If the detection method is the RPC remote procedure call detection method, the RPC interface of the designated data center corresponding to the data center where the server is located is called to query the main data center identifier through the RPC interface, wherein the designated data center includes a data center in the same city and / or a data center in a different location.

5. The method of claim 3, wherein: Before responding to the data center detection task, the method further includes: Start the business application and load the detection task configuration file of the server where the business application is located; Verifying the configuration parameters in the detection task configuration file; If the verification is passed, the initial primary data center identifier is obtained according to the detection method in the configuration parameters, and the primary data center identifier stored in the server is updated according to the obtained initial primary data center identifier; If the verification fails, the startup of the business application is prohibited and an error message is output.

6. The method of claim 2, wherein: After responding to the data center detection task, the method further includes: According to the data center detection task, obtaining a detection task configuration file corresponding to the server, wherein the detection task configuration file includes a detection switch and a detection mode; If the detection switch is in the on state and the detection mode is the database detection mode, then executing the step of determining whether the data center where the server is located is the initial main data center; If the detection switch is in the off state, the step of obtaining the detection task configuration file corresponding to the server and detecting and obtaining the main data center identifier according to the detection method recorded in the detection task configuration file is executed.

7. A method for processing a business request, executed by any data center in a distributed system, wherein: The method comprises: Receive business requests; Get the interface name of the primary data center; Initiate a call according to the interface name of the primary data center to forward the service request to the primary data center for processing; The primary data center is determined based on the method for determining the primary data center in a distributed system according to any one of claims 1 to 6.

8. The method of claim 7, wherein: The interface name for obtaining the primary data center includes: Get the service name of the server; The updated primary data center identifier stored in the server is concatenated with the service name to obtain the interface name of the primary data center.

9. A device for determining a primary data center in a distributed system, applied to any data center in the distributed system, wherein: The device is used to implement any one of the methods of claims 1 to 6.

10. A service request processing device, applied to any data center in a distributed system, wherein: The device is used to implement any one of the methods of claims 7 to 8.

11. An electronic device, comprising: processor; as well as A memory arranged to store computer executable instructions, which, when executed, cause the processor to perform the method of any one of claims 1 to 6, or to perform the method of any one of claims 7 to 8.

12. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of application programs, enables the electronic device to execute any one of the methods of claims 1 to 6, or to execute any one of the methods of claims 7 to 8.

Citation Information

Patent Citations

  • A method and a system for configuring a data center

    CN109165256A

  • Multi-center service data management system

    CN111708787A