Method and device for processing database
By periodically updating the timestamp of online hosts and checking host status in batches in the distributed service framework, the problem of large database updates is solved, the availability and stability of the framework are improved, and the offline status detection cycle is shortened.
Patent Information
- Application Number
- CN201911239584.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-06
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2039-12-06
AI Technical Summary
In the distributed service framework, a large number of hosts send heartbeat information to the registration center, resulting in a large amount of database updates, increasing the burden on the storage server, and affecting availability and stability.
By determining the hosts that are online during the cycle in the distributed service framework, and performing a one-step update operation at the end of the cycle to update their corresponding timestamps, reduce the number of database updates, improve the efficiency of the storage server, and check the hosts in batches status and reduce network resource usage, shortening the offline status detection cycle.
It reduces the number of database updates and storage server burden, avoids delays, improves the availability and stability of the distributed service framework, and detects offline hosts earlier.
Smart Images

Figure CN112925844B
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular to a method and device for processing a database. Background Art
[0002] The distributed service framework includes a registration center, a storage server and multiple hosts, each of which is used to provide services. The storage server includes a database, which is used to store the correspondence between device identification and timestamp. For each host, the host can be registered in the registration center. The registration center stores the device identification and current timestamp of the host in the database of the storage server.
[0003] After the host is registered with the registration center, it periodically sends heartbeat information to the registration center. The registration center receives the heartbeat information, obtains the current timestamp, and updates the timestamp corresponding to the device identifier of the host in the database to the current timestamp. Among them, the storage server obtains the time difference between the timestamp corresponding to each host stored in the database and the current time in real time; for hosts whose time difference exceeds the time threshold, the storage server determines that the status of the host is offline, and deletes the record including the device identifier of the host and the timestamp corresponding to the host from the database; for hosts whose time difference does not exceed the time threshold, the storage server determines that the status of the host is online, and retains the record including the device identifier of the host and the timestamp corresponding to the host in the database.
[0004] In the process of implementing this application, the inventor found that the prior art has at least the following problems:
[0005] Distributed service frameworks often include a large number of hosts. Such a large number of hosts send heartbeat information to the registration center, which causes the registration center to update the database a lot. This increases the burden on the storage server, causes large update delays, and affects the availability and stability of the distributed service framework. Summary of the invention
[0006] The present application provides a method and device for processing a database to improve the availability and stability of a distributed service framework.
[0007] The technical solution is as follows:
[0008] In a first aspect, the present application provides a method for processing a database, the method applies a distributed service framework, the distributed service framework includes a storage server, a first device and a first host set, the storage server includes a database, the first host set includes M hosts registered with the first device, the database is used to save the first timestamp corresponding to the host included in the first host set, the state of the host at the first timestamp is online, and M is an integer greater than 0. In the method, the first device determines N hosts in the first host set that are online within a first cycle, N is an integer less than or equal to M and greater than 0, and the first cycle is a cycle after the first timestamp. At the end of the first cycle, the first device updates the first timestamp corresponding to each of the N hosts stored in the database to a second timestamp through a one-step update operation, and the second timestamp is within the first cycle.
[0009] Since the first device can determine the N hosts that are online in the first cycle, the first device can use a one-step update operation to update the first timestamp corresponding to each of the N hosts in the database to a second timestamp. This greatly reduces the number of times the database is updated, reduces the burden on the storage server, avoids delays when updating the database, and improves the availability and stability of the distributed service framework. In addition, since the number of updates is reduced, the length of the cycle for checking the host can be shortened, so that the host in the offline state can be discovered earlier.
[0010] In a possible implementation, the first device sends a check request message to each host in the first host set at the start time of the first cycle. The first device receives a check response message corresponding to the check request message sent by a host in the first host set within the first cycle, and determines that the state of the host sending the check response message is an online state. Since a check request message can be sent to each host in the first host set, and a check response message corresponding to the check request message sent by each online host in the first host set is received within the first cycle, it is possible to implement batch checking of the host state, thereby improving the inspection efficiency.
[0011] In another possible implementation, the first device sends an update request to the storage server, the update request including the second timestamp and the device identification of each of the N hosts, and the update request is used by the storage server to update the first timestamp corresponding to each of the N hosts stored in the database to the second timestamp. Since one update request includes the device identification of each of the N hosts, the database can be updated in one step, and since only one update request is sent, the occupation of network resources is also reduced.
[0012] In another possible implementation, the first device receives a device identifier of a host in an offline state sent by a storage server, and the time difference between the timestamp corresponding to the offline host and the current time exceeds a time threshold. The first device determines the terminal that has subscribed to the service provided by the offline host based on the device identifier of the offline host. The first device sends an offline notification message to the terminal, and the offline notification message includes the device identifier of the offline host. Since the offline host cannot continue to provide services, the offline notification message allows the terminal to cancel its subscription to the services in the host, thereby avoiding the request error phenomenon caused by the terminal requesting services from the offline host.
[0013] In another possible implementation, the second timestamp is the end time of the first cycle.
[0014] In a second aspect, the present application provides a device for processing a database, which is used to execute the method in the first aspect or any possible implementation of the first aspect. Specifically, the device includes a unit for executing the method in the first aspect or any possible implementation of the first aspect.
[0015] In a third aspect, the present application provides a device for processing a database, the device comprising: a processor, a memory, and a transceiver. The processor, the memory, and the transceiver may be connected via a bus system. The memory is used to store one or more programs, and the processor is used to execute one or more programs in the memory to complete the method in the first aspect or any possible implementation of the first aspect.
[0016] In a fourth aspect, the present application provides a computer-readable storage medium, in which program code is stored. When the computer-readable storage medium is run on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation of the first aspect.
[0017] In a fifth aspect, the present application provides a computer program product comprising program codes, which, when executed on a computer, enables the computer to execute the method in the above-mentioned first aspect or any possible implementation manner of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is a schematic diagram of a distributed service framework structure provided in an embodiment of the present application;
[0019] Figure 2 is a flow chart of a method for processing a database provided in an embodiment of the present application;
[0020] Figure 3 is a flow chart of another method for processing a database provided in an embodiment of the present application;
[0021] Figure 4 It is a schematic diagram of the structure of a device for processing a database provided in an embodiment of the present application;
[0022] Figure 5 It is a schematic diagram of the structure of another device for processing a database provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] The implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0024] See also Figure 1 , the embodiment of the present application provides a distributed service framework, including:
[0025] A storage server, a registration center and a plurality of hosts. The storage server includes a database, which is used to store the corresponding relationship between the device identification, service information and timestamp of the host, and the registration center may include at least one device.
[0026] For any record in the database including the device identification, service information and timestamp of the host, the record is used to indicate that the state of the host at the timestamp is online, and the service information is the service information of the service that the host can provide.
[0027] The content in the database is saved by the device in the registration center. In implementation: for any one of the multiple hosts, the host can select a device from the registration center and register to the selected device. The device obtains the device identification of the host, the service information of the service provided by the host, and the current timestamp, and stores the device identification of the host, the service information, and the current timestamp in the database of the storage server accordingly.
[0028] Optionally, the device also stores the device identification of any host. For example, the device may include a storage structure, and the device identification of any host may be stored in the storage structure. The storage structure may be an array or a queue.
[0029] The service information of the service may include information such as the service name of the service and / or the service group to which the service belongs.
[0030] Optionally, the operation of registering any one of the hosts on the device may be: the any one of the hosts establishes a network connection with the device to register on the device.
[0031] Optionally, the network connection established between any one of the hosts and the device is a long connection.
[0032] For example, it is assumed that the distributed server framework includes seven hosts, namely hosts 1, 2, 3, 4, 5, 6 and 7. And the registration center includes three devices, namely devices 1, 2 and 3. For host 1, it is assumed that host 1 selects device 1 in the registration center and establishes a network connection with device 1. Device 1 obtains the device identification of host 1 as H1, service information 1 of the service provided by host 1 and current timestamp t1, saves the device identification H1 of host 1 to its own storage structure, and stores the device identification H1 of host 1, the service information 1 of the service and the current timestamp t1 in the database of the storage server, which is shown in Table 1 below.
[0033] For each other host, it also selects a device from the registration center and registers to the selected device as host 1. For example, assuming that host 2 and host 3 also select device 1, device 1 saves the device identification H2 of host 2 and the device identification H3 of host 3 to its own storage structure, that is, the storage structure of device 1 saves the device identification H1 of host 1, the device identification H2 of host 2 and the device identification H3 of host 3; the device identification H2 of host 2, the service information 2 of the service provided by host 2 and the timestamp t2 are correspondingly saved in the database shown in Table 1 in the storage server, and the device identification H3 of host 3, the service information 3 of the service provided by host 3 and the timestamp t3 are correspondingly saved in the database shown in Table 1 in the storage server.
[0034] And, assume again that host 4 and host 5 select device 2, device 2 saves the device identification H4 of host 4 and the device identification H5 of host 5 into its own storage structure, saves the device identification H4 of host 4, the service information 4 of the service provided by host 4 and the timestamp t4 correspondingly into the database shown in Table 1, and saves the device identification H5 of host 5, the service information 5 of the service provided by host 5 and the timestamp t5 correspondingly into the database shown in Table 1 in the storage server.
[0035] Furthermore, it is assumed that host 6 and host 7 select device 3, and device 3 saves the device identification H6 of host 6 and the device identification H7 of host 7 into its own storage structure, and saves the device identification H6 of host 6, the service information 6 of the service provided by host 6, and the timestamp t6 correspondingly into the database shown in Table 1, and saves the device identification H7 of host 7, the service information 7 of the service provided by host 7, and the timestamp t7 correspondingly into the database shown in Table 1 in the storage server.
[0036] Table 1
[0037] The device ID of the host Service Information Timestamp H1 Service Information 1 t1 H2 Service Information 2 t2 H3 Service Information 3 t3 H4 Service Information 4 t4 H5 Service Information 5 t5 H6 Service Information 6 t6 H7 Service Information 7 t7 …… …… ……
[0038] For any device in the registration center, for the sake of convenience, it is called the first device. The first device can periodically determine the status of each host in the first host set. The first host set includes M hosts that have been registered with the first device, where M is an integer greater than 0, that is, the first host set includes the host corresponding to each device identifier stored in the storage structure of the first device.
[0039] For any cycle, which is called the first cycle for the sake of convenience, the first device can determine the N hosts in the first host set that are online in the first cycle. At the end of the first cycle, the first timestamp corresponding to each of the N hosts stored in the database is updated to a second timestamp through a one-step update operation. The second timestamp is within the first cycle, and the first timestamp corresponding to each host is earlier than the first cycle. The detailed implementation process will be described later. Figure 2 The embodiment shown is used for illustration only and will not be described in detail here.
[0040] Optionally, for any device in the registration center, the device may save the correspondence between the device identification of the host and the device identification of the terminal. For any record in the correspondence including the device identification of the host and the device identification of the terminal, the record is used to indicate that the terminal has subscribed to the service provided by the host.
[0041] The services provided by each host in the distributed service framework can be subscribed by terminals. For any terminal, when the terminal needs to subscribe to a certain service, the terminal can send a subscription request message to a device in the registration center. The subscription request message includes service information of the service to be subscribed.
[0042] The device receives the subscription request message, obtains the device identification of a host used to provide the service to be subscribed to the terminal based on the service information of the service to be subscribed and the database in the storage server, and sends a subscription response message to the terminal, the subscription response message including the device identification of the host, and saves the correspondence between the device identification of the terminal and the device identification of the host in the correspondence relationship between the device identification of the host and the device identification of the terminal.
[0043] The terminal receives the subscription response message and can request the host to provide services according to the device identification of the host included in the subscription response message.
[0044] For example, it is assumed that terminal 1 sends a subscription request message to device 1, and the subscription request message includes service information 1 of service 1 to be subscribed. After receiving the subscription request message sent by terminal 1, device 1 obtains the device identification H1 of host 1 for providing service 1 according to the service information 1 of service 1 to be subscribed included in the subscription request message and the database shown in the above Table 1 stored in the storage server, and sends a subscription response message to terminal 1, the subscription response message includes the device identification H1 of host 1, and the device identification H1 of host 1 and the device identification T1 of terminal 1 are correspondingly stored in the corresponding relationship between the device identification of the host and the device identification of the terminal as shown in the following Table 2. Terminal 1 receives the subscription response message, and requests host 1 to provide service 1 according to the device identification H1 of host 1 included in the subscription response message.
[0045] For another example, assume that terminal 2 sends a subscription request message to device 1, and the subscription request message includes service information 4 of service 4 to be subscribed. After receiving the subscription request message sent by terminal 2, device 1 obtains device identification H4 of host 4 for providing service 4 according to service information 4 of service 4 to be subscribed included in the subscription request message and the database shown in the above Table 1 stored in the storage server, and sends a subscription response message to terminal 2, the subscription response message includes device identification H4 of host 4, and the device identification H4 of host 4 and device identification T2 of terminal 2 are correspondingly stored in the corresponding relationship between device identification of host and device identification of terminal shown in the following Table 2. Terminal 2 receives the subscription response message, and requests host 4 to provide service 4 according to device identification H4 of host 4 included in the subscription response message.
[0046] Table 2
[0047] The device ID of the host Device ID of the terminal H1 T1 H4 T2 …… ……
[0048] Optionally, the device in the registration center is a server or a host, etc. The device identifier of the device in the registration center is the address of the device, which is an IP address or a MAC address.
[0049] Optionally, the device identifier of the host may be the address of the host, which may also be an Internet Protocol (IP) address or a Media Access Control (MAC) address. The device identifier of the terminal may be the address of the terminal, which may also be an IP address or a MAC address.
[0050] See also Figure 2 The present application embodiment provides a method for processing a database, which can be applied to Figure 1 The distributed service framework shown includes:
[0051] Step 201: the first device sends a check request message to each host in a first host set at the start time of a first cycle, where the first host set includes M hosts registered with the first device, where M is an integer greater than 0.
[0052] The first device is any device in the registration center of the distributed service framework, and the first period is any period. The period length of the first period can be 2 seconds, 3 seconds, or 4 seconds, etc.
[0053] The first device includes a storage structure, which is used to store device identifications of various hosts registered with the first device, and the first host set includes hosts corresponding to the device identifications of each host stored in the storage structure.
[0054] In this step, the check request message generated by the first device is sent to each host respectively at the start time of the first cycle according to the device identification of each host stored in the storage structure included in the first device.
[0055] Optionally, the inspection request message may further include a message identifier of the inspection request message.
[0056] Optionally, for any host in the distributed service framework, when the host starts to go online, it can select a device from the registration center and register to the device. The implementation process can be:
[0057] The host sends a connection establishment request message to the device, and the device receives the connection establishment request message and sends a connection establishment response message to the host to establish a network connection with the host. After the network connection is established, the host is registered with the device.
[0058] The device also saves the device identification of the host to its own storage structure, obtains service information of the services that the host can provide from the host through the network connection, and saves the device identification of the host, the obtained service information and the current timestamp correspondingly to the database of the storage server.
[0059] Since there is a network connection between the device and each host in the first host set, in this step, the device can send a check request message to each host respectively through the network connection between the device and each host in the first host set.
[0060] For example, the first device is Figure 1In the distributed service framework shown, the storage structure of the first device includes the device identifier H1 of host 1, the device identifier H2 of host 2, and the device identifier H3 of host 3, that is, the first host set includes host 1 corresponding to the device identifier H1, host 2 corresponding to the device identifier H2, and host 3 corresponding to the device identifier H3. At the start time of the first cycle, the first device sends a check request message to host 1 corresponding to the device identifier H1, host 2 corresponding to the device identifier H2, and host 3 corresponding to the device identifier H3, respectively. The check request message includes a message identifier of the check request message, assuming that the message identifier is 20.
[0061] Optionally, device 1 sends an inspection request message to host 1 through the network connection between device 1 and host 1, sends an inspection request message to host 2 through the network connection between device 1 and host 2, and sends an inspection request message to host 3 through the network connection between device 1 and host 3.
[0062] Optionally, the database in the current storage server can be modified so that the database is used to store the corresponding relationship between the host's device identification, service information and timestamp. Alternatively, the current database may not be modified and is used to store the corresponding relationship between the primary key value, the host's device identification and timestamp.
[0063] Without modifying the database, the storage server also needs to save the corresponding relationship between the master key value, the host's device identification and the service information. In this way, the operation of the device saving the host's device identification, the obtained service information and the current timestamp to the database of the storage server can be:
[0064] The device sends a storage request to the storage server, and the storage request includes the device identification of the host, the obtained service information and the current timestamp. The storage server receives the storage request, generates a primary key value for identifying the host in the database, stores the primary key value, the device identification of the host and the current timestamp in the database, and stores the primary key value, the device identification of the host and the service information in the database.
[0065] In this case, when the terminal subscribes to a service provided by a server to the first device, the terminal sends a subscription request message to the first device, and the subscription request message includes service information of the service to be subscribed. The first device obtains the device identification of at least one host that can provide the service to be subscribed from the correspondence between the primary key value, the device identification of the host and the service information stored in the storage server according to the service information of the service to be subscribed. A device identification of a host is selected from the device identifications of the at least one host, and a subscription response message is sent to the terminal, and the subscription response message includes selecting a device identification of a host. The terminal receives the subscription response message, and requests the host to provide the service to be subscribed according to the device identification of the host included in the subscription response message.
[0066] Step 202: The host receives the check request message, and sends a check response message corresponding to the check request message to the first device.
[0067] Optionally, the check response message may include a message identifier of the check request message.
[0068] The host is any online host in the first host set, and within the first period, there is a network connection between the online hosts in the first host set and the first device. Therefore, the online host can receive the check request message sent by the first device, generate a check response message within the first period, and the check response message includes the message identifier of the check request message, and send the check response message to the first device through the network connection.
[0069] During the first cycle, the hosts in the first host set that are in an offline state have disconnected the network connection with the first device, so the hosts in an offline state will not receive the check request message, and therefore will not send a check response message corresponding to the check request message to the first device.
[0070] For example, it is assumed that in the first cycle, the status of host 1 and host 2 is online, while the status of host 3 is offline. Host 1 receives the inspection request message sent by device 1 through the network connection between it and device 1, and the inspection request message includes message identifier 20, and sends the inspection response message including message identifier 20 to device 1 through the network connection. Host 2 receives the inspection request message sent by device 1 through the network connection between it and device 1, and the inspection request message includes message identifier 20, and sends the inspection response message including message identifier 20 to device 1 through the network connection. However, host 3 is offline and has disconnected the network connection with device 1, so host 3 will not receive the inspection request message and will not send the inspection response message.
[0071] Step 203: In the first cycle, the first device receives the check response message corresponding to the check request message sent by N hosts in the first host set, where N is a host greater than 0 and less than or equal to M, and determines that the status of the N hosts in the first cycle is online.
[0072] In this step, the first device receives a check response message sent by any host. If the check response message includes the message identifier of the check request message, it is determined that the check response message is the check response message corresponding to the check request message, and it is determined that the status of any host in the first cycle is online.
[0073] The check response message is a check response message corresponding to the check request message, indicating that any one of the hosts receives the check request message within the first cycle and sends a check response message to the first device, so that the first device can determine that the status of any one of the hosts is online.
[0074] For example, in the first cycle, device 1 receives a check response message sent by host 1, and the check response message includes the message identifier 20 of the check request message, and determines that the state of host 1 in the first cycle is online. Device 1 receives a check response message sent by host 2, and the check response message includes the message identifier 20 of the check request message, and determines that the state of host 2 in the first cycle is online.
[0075] Step 204: At the end of the first cycle, the first device sends an update request to the storage server, the update request including a second timestamp and a device identifier of each of the N hosts, the second timestamp being within the first cycle.
[0076] Optionally, the first device obtains the second timestamp and generates a database update statement, the database update statement including the second timestamp and a device identifier of each host in the N hosts. The database update statement is an update request.
[0077] The second timestamp may be the end time of the first period.
[0078] For example, the first device obtains the end time t8 of the first cycle as the second timestamp, and sends an update request to the storage server. The update request includes the second timestamp t8, the device identifier H1 of the host 1, and the device identifier H2 of the host 2.
[0079] Step 205: The storage server receives the update request, and updates the first timestamp corresponding to each of the N hosts stored in the database to a second timestamp.
[0080] For ease of explanation, the timestamp of each host stored in the database is referred to as the first timestamp. In this step, the storage server receives the update request, which includes the second timestamp and the device identification of each host in the N hosts, obtains the first timestamp corresponding to each host in the database according to the device identification of each host, and updates the first timestamp corresponding to each host to the second timestamp in the database.
[0081] It should be noted that: for N hosts that need to update timestamps, the first device only performs one update operation, that is, sends one update request to the storage server, which reduces the number of update requests sent to the storage server. And the storage server receives one update request and only needs to perform one operation on the database to update the first timestamp corresponding to each host to the second timestamp, which greatly reduces the burden on the storage server and reduces the number of times data is updated, so that each update of the database will not cause delay.
[0082] For example, the storage server receives an update request, which includes the second timestamp t8, the device identifier H1 of the host 1, and the device identifier H2 of the host 2. According to the device identifier H1 of the host 1, the first timestamp t1 corresponding to the host 1 is obtained in the database shown in Table 1, and the first timestamp t1 corresponding to the host 1 is updated to the second timestamp t8 in the database. According to the device identifier H2 of the host 2, the first timestamp t2 corresponding to the host 2 is obtained in the database shown in Table 1, and the first timestamp t1 corresponding to the host 2 is updated to the second timestamp t8 in the database, and the obtained database is shown in Table 3 below.
[0083] Table 3
[0084] The device ID of the host Service Information Timestamp H1 Service Information 1 t8 H2 Service Information 2 t8 H3 Service Information 3 t3 H4 Service Information 4 t4 H5 Service Information 5 t5 H6 Service Information 6 t6 H7 Service Information 7 t7 …… …… ……
[0085] For each other device in the registration center, the above process is executed in the same way as the first device to process the database in the storage server.
[0086] Among them, it should be noted that: for a host in an offline state, since the host will not send a check response message to the first device, the first device will not timely update the first timestamp corresponding to the host in the database. The first timestamp corresponding to the offline host saved in the database may be much earlier than the current time, and the time difference between the first timestamp corresponding to the offline host and the current time may exceed the time threshold, which is greater than the period length of the first period.
[0087] The storage server has an aging mechanism, through which the offline hosts in the distributed service framework can be discovered and then the database can be processed. Figure 3 The method for processing the database includes:
[0088] Step 301: The storage server determines at least one host in the distributed service framework that is in an offline state according to a database, and deletes the record including the device identification of the offline host from the database.
[0089] In this step, the storage server obtains at least one target record from the database, the timestamp included in the target record is earlier than the third timestamp, the third timestamp is earlier than the current time, and the time difference between the third timestamp and the current time is the time threshold, and the host corresponding to the device identifier saved in each target record is determined as an offline host, and the target record is deleted.
[0090] When the database is used to store the correspondence between the primary key value, the device identification of the host and the timestamp, the database itself has an aging mechanism. The database can obtain at least one target record in real time, and the timestamp included in the target record is earlier than the third timestamp. Each target record including the primary key value of the offline host is notified to the storage server, and each target record is deleted from the database at the same time.
[0091] The storage server receives the primary key value of each host in the offline state, and obtains the device identification of each host in the offline state from the corresponding relationship between the primary key value, the device identification of the host and the service information according to the primary key value of each host.
[0092] Step 302: The storage server sends a device identification of at least one host in an offline state to each device in a registration center in the distributed service framework.
[0093] For any device in the registration center, for the sake of convenience, the device is called the first device. The first device performs the following operations:
[0094] Step 303: The first device receives the device identification of the at least one host, and for any one of the at least one host, determines, based on the device identification of the any one host, terminals that have subscribed to the service provided by the any one host.
[0095] In this step, the first device obtains the device identification of each terminal that has subscribed to the service provided by any host from the corresponding relationship between the device identification of the host and the device identification of the terminal according to the device identification of the any host.
[0096] Step 304: the first device sends a notification message to each terminal, where the notification message includes the device identification of any host, so that the terminal cancels the subscription to the service provided by any host.
[0097] For each other host in the at least one host, the first device repeats the above steps 303 and 304.
[0098] In an embodiment of the present application, since the first device determines the N hosts in the first host set that are online within a cycle, at the end of the cycle, the first timestamp corresponding to each of the N hosts stored in the database is updated to a second timestamp through a one-step update operation. This reduces the number of update operations on the database, reduces the burden on the storage server, and ensures that each update operation will not cause delays, thereby improving the availability and stability of the distributed service framework.
[0099] See also Figure 4 The embodiment of the present application provides a device 400 for processing a database, and the device 400 is applied as follows Figure 1 The distributed service framework shown in the figure includes a storage server, the device 400 and a first host set, the storage server includes a database, the first host set includes M hosts registered with the device 400, and the database is used to store the first timestamps corresponding to the hosts included in the first host set, the state of the host at the first timestamp is online, and M is an integer greater than 0. The device 400 can be as described above Figure 2 or Figure 3 The first device in the illustrated embodiment comprises:
[0100] The processing unit 401 is configured to determine N hosts in a first host set that are online within a first period, where N is an integer less than or equal to M and greater than 0, and the first period is a period after the first timestamp;
[0101] The updating unit 402 is used to update the first timestamp corresponding to each host in the N hosts stored in the database to a second timestamp within the first period through a one-step updating operation at the end of the first period. The second timestamp is within the first period.
[0102] Optionally, the device 400 further includes: a sending unit 403 and a receiving unit 404;
[0103] The sending unit 403 is used to send a check request message to each host in the first host set at the start time of the first cycle;
[0104] The receiving unit 404 is configured to receive a check response message corresponding to the check request message sent by a host in the first host set within a first period;
[0105] The processing unit 401 is configured to determine that the status of the host sending the check response message is an online status.
[0106] Optionally, the sending unit 403 is used to send an update request to the storage server, the update request including a second timestamp and a device identifier of each of the N hosts, and the update request is used by the storage server to update the first timestamp corresponding to each of the N hosts stored in the database to the second timestamp.
[0107] Optionally, the receiving unit 404 is configured to receive a device identification of a host in an offline state sent by the storage server, wherein a time difference between a timestamp corresponding to the host in the offline state and the current time exceeds a time threshold;
[0108] The processing unit 401 is further configured to determine, according to the device identification of the offline host, a terminal that has subscribed to a service provided by the offline host;
[0109] The sending unit 403 is configured to send an offline notification message to the terminal, where the offline notification message includes a device identifier of the host in an offline state.
[0110] The second timestamp is the end time of the first cycle.
[0111] In the embodiment of the present application, since the processing unit can determine the N hosts that are online in the first cycle, the update unit can use a one-step update operation to update the first timestamp corresponding to each of the N hosts in the database to the second timestamp. This greatly reduces the number of times the update unit updates the database, reduces the burden on the storage server, avoids delays when updating the database, and improves the availability and stability of the distributed service framework.
[0112] See also Figure 5 , an embodiment of the present application provides a schematic diagram of an apparatus 500 for processing a database. The apparatus 500 may be the first device in any of the above embodiments. The apparatus 500 includes at least one processor 501, a bus system 502, a memory 503 and at least one transceiver 504.
[0113] The device 500 is a hardware structure device that can be used to implement Figure 4 The functional modules in the device 400 are as follows. For example, those skilled in the art may think of Figure 4 The processing unit 401 and the updating unit 402 in the device 400 shown in the figure can be implemented by the at least one processor 501 calling the code in the memory 503. Figure 4 The sending unit 403 and the receiving unit 404 in the device 400 shown can be implemented by the transceiver 504 .
[0114] Optionally, the device 500 can also be used to implement the functions of the collection and analysis device in any of the above embodiments.
[0115] Optionally, the processor 501 may be a general-purpose central processing unit (CPU), a network processor (NP), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0116] The bus system 502 may include a path for transmitting information between the components.
[0117] The transceiver 504 is used to communicate with other devices or communication networks.
[0118] The memory 503 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a bus. The memory may also be integrated with the processor.
[0119] The memory 503 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 501. The processor 501 is used to execute the application code stored in the memory 503, so as to realize the functions in the method of the present patent.
[0120] In a specific implementation, as an embodiment, the processor 501 may include one or more CPUs, such as Figure 5 CPU0 and CPU1 in.
[0121] In a specific implementation, as an embodiment, the device 500 may include multiple processors, such as Figure 5501 and processor 507 in the embodiment of the present invention. Each of these processors may be a single-CPU processor or a multi-CPU processor. The processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0122] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0123] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for processing a database, characterized in that: The method applies a distributed service framework, the distributed service framework includes a storage server, a first device and a first host set, the storage server includes a database, the first host set includes M hosts registered with the first device, the database is used to store first timestamps corresponding to the hosts included in the first host set, the state of the host at the first timestamp is an online state, and M is an integer greater than 0, including: The first device generates a check request message including a message identifier, and sends the check request message to each host in the first host set at a start time of a first cycle, where the first cycle is a cycle after the first timestamp; The first device receives, within the first period, check response messages including the message identifier sent by N hosts in the first host set, and determines that the status of the N hosts that sent the check response messages is an online status, where N is an integer less than or equal to M and greater than 0; The first device generates a database update statement at the end of the first cycle, the database update statement including a second timestamp and a device identifier of each of the N hosts, the second timestamp being within the first cycle; The first device sends the database update statement to the storage server, so that the storage server executes the database update statement to update the first timestamp corresponding to each of the N hosts stored in the database to a second timestamp by performing an update operation on the database.
2. The method according to claim 1, characterized in that The M hosts include a first host, and determining that the status of the N hosts that send the check response message is an online status includes: If the message identifier included in the check request message is the same as the message identifier included in the check response message sent by the first host, it is determined that the state of the first host is an online state.
3. The method according to claim 2, characterized in that The method further comprises: If the message identifier included in the check request message is different from the message identifier included in the check response message sent by the first host, it is determined that the state of the first host is an offline state.
4. The method according to any one of claims 1 to 3, characterized in that: The first device determines N hosts in the first host set that are online within a first period, including: The first device sends a check request message to each host in the first host set at a start time of the first cycle; The first device receives a check response message corresponding to the check request message sent by a host in the first host set within the first period, and determines that the status of the host sending the check response message is an online status.
5. The method according to any one of claims 1 to 3, characterized in that: At the end of the first cycle, the first device updates the first timestamp corresponding to each of the N hosts stored in the database to a second timestamp through an update operation, including: The first device sends an update request to the storage server, the update request including the second timestamp and the device identifier of each of the N hosts, and the update request is used by the storage server to update the first timestamp corresponding to each of the N hosts stored in the database to the second timestamp.
6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: The first device receives a device identifier of a host in an offline state sent by the storage server, and a time difference between a timestamp corresponding to the host in the offline state and a current time exceeds a time threshold; The first device determines, according to the device identifier of the offline host, a terminal that has subscribed to a service provided by the offline host; The first device sends an offline notification message to the terminal, where the offline notification message includes a device identifier of the host in the offline state.
7. The method according to any one of claims 1 to 3, characterized in that: The second timestamp is the end time of the first cycle.
8. A device for processing a database, characterized in that: The device applies a distributed service framework, the distributed service framework includes a storage server, the device and a first host set, the storage server includes a database, the first host set includes M hosts registered with the device, the database is used to store first timestamps corresponding to the hosts included in the first host set, the state of the host at the first timestamp is an online state, and M is an integer greater than 0, including: a processing unit, configured to generate a check request message including a message identifier, and send the check request message to each host in the first host set at a start time of a first cycle, wherein the first cycle is a cycle located after the first timestamp; receive a check response message including the message identifier sent by N hosts in the first host set within the first cycle, and determine that the status of the N hosts that sent the check response message is an online status, wherein N is an integer less than or equal to M and greater than 0; An update unit is used to generate a database update statement at the end of the first cycle, wherein the database update statement includes a second timestamp and a device identifier of each of the N hosts, and the second timestamp is within the first cycle; and send the database update statement to the storage server, so that the storage server executes the database update statement to update the first timestamp corresponding to each of the N hosts stored in the database to a second timestamp by performing an update operation on the database, and the second timestamp is within the first cycle.
9. The device according to claim 8, characterized in that The M hosts include a first host, and the processing unit is used to determine that the state of the first host is an online state if the message identifier included in the check request message is the same as the message identifier included in the check response message sent by the first host.
10. The device according to claim 9, characterized in that The processing unit is further configured to determine that the state of the first host is an offline state if the message identifier included in the check request message is different from the message identifier included in the check response message sent by the first host.
11. The device according to any one of claims 8 to 10, characterized in that: The device further includes: a first sending unit and a first receiving unit; The first sending unit is used to send a check request message to each host in the first host set at a start time of the first cycle; The first receiving unit is configured to receive, within the first period, a check response message corresponding to the check request message sent by a host in the first host set; The processing unit is used to determine that the status of the host sending the check response message is an online status.
12. The device according to any one of claims 8 to 10, characterized in that: The device further includes: a second sending unit, The second sending unit is used to send an update request to the storage server, the update request including the second timestamp and the device identifier of each of the N hosts, and the update request is used by the storage server to update the first timestamp corresponding to each of the N hosts stored in the database to the second timestamp.
13. The device according to any one of claims 8 to 10, characterized in that: The device further includes: a third sending unit and a second receiving unit, The second receiving unit is used to receive a device identification of a host in an offline state sent by the storage server, and the time difference between the timestamp corresponding to the host in the offline state and the current time exceeds a time threshold; The processing unit is further used to determine, according to the device identification of the offline host, a terminal that has subscribed to the service provided by the offline host; The third sending unit is used to send an offline notification message to the terminal, where the offline notification message includes a device identifier of the host in the offline state.
14. The device according to any one of claims 8 to 10, characterized in that: The second timestamp is the end time of the first cycle.
15. A computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions are executed on a processor, the method according to any one of claims 1 to 7 is implemented.
16. A computer program product, comprising a program, which implements the method according to any one of claims 1 to 7 when the program is run on a processor.
Citation Information
Patent Citations
Dynamic strategy updating method and device based on timestamp
CN103561441A
Method and device for managing node devices in distributed system
CN107528703A
Method and system for monitoring the running state of equipment
CN109905286A
Distributed transaction processing method, coordination device, database and electronic equipment
CN110018884A
