A method for maintaining data and state consistency in security software systems
Through the design of interface idempotence and retry, registration and heartbeat, and automatic restart, the problem of data and status consistency in the security software system is solved, automatic recovery of data and status is realized, the implementation process is simplified, and the learning cost is reduced. And improve the reliability of the system.
Patent Information
- Application Number
- CN202210194034.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-01
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2042-03-01
AI Technical Summary
In security software systems, the distributed transaction framework is complex and difficult to apply, making it difficult to achieve data and state consistency. Especially in large software projects, the early and late undertaking units are different, and the learning cost of the distributed transaction framework is high and cannot be widely introduced. .
Adopting the design of interface idempotence and retry, registration and heartbeat, and automatic restart, the business service regularly resends requests, records abnormal data, automatically restarts the service, keeps the device access service status consistent, and achieves the ultimate consistency of data and status. .
It realizes automatic recovery of data and status, is simpler than the distributed transaction framework, has low learning cost, has high reliability, is suitable for most software systems, and has practical value especially in system integration projects.
Smart Images

Figure CN114666250B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of security, and in particular relates to a method for maintaining data and state consistency in a security software system. Background Art
[0002] As the complexity of application scenarios increases, software systems become larger and larger, and the problems encountered in software systems become more and more complex. Therefore, problems that have a small impact in traditional software have become pain points that must be solved in system-level software. For example, network jitter problems. Traditional software is small in scale, and data and status management is relatively simple, so the problems caused by network jitter can be left unsolved. In system-level software, request timeouts caused by network jitter will directly lead to inconsistent internal states of various services in the system, especially since software systems often involve interaction with hardware, which will further complicate the problem. Therefore, how to ensure the consistency of data and status in the system has become an urgent problem to be solved.
[0003] A typical security software system usually includes four parts: gateway, business service, device access service, and security equipment. In actual use, the gateway, business service, and device access service may exit at any time, such as manual restart, abnormal service crash, etc., which may cause the service to be offline or the service to be online but the request is sent successfully but the processing result cannot be returned. The network jitter and network interruption caused by the complex network environment can also cause the same problem.
[0004] In distributed transaction processing, when the device access service fails, the business service rolls back the data and status and returns failure. At this time, the status of the device access service and the business service are consistent. Or if the business service times out and returns failure, and the device access service successfully receives a notification of distributed transaction failure and then rolls back the data and status, the data and status can be kept consistent. This distributed transaction processing method is currently used more in the Internet industry, but it is not very practical in the security field for the following reasons:
[0005] 1) The use of distributed transaction frameworks is complex, and the learning cost of introducing such frameworks is high.
[0006] 2) Failure of data and status rollback in a distributed transaction framework usually requires manual intervention to correct the data and status, but some software projects may not require manual intervention for a period of time.
[0007] 3) Large-scale software projects in the security field are carried out in phases, which usually means that the project contractors in the early and late stages are not the same. If all project contractors are required to use the same distributed transaction framework according to the new requirements, this will obviously cause significant changes to the functions that have been implemented in the early stages of the project. In addition, in most cases, the various project contractors are distributed across the country and are independent of each other, so they do not have the conditions to introduce the same distributed transaction framework.
[0008] Based on the above reasons, the distributed transaction framework cannot be introduced into the security field, which means that the problem of solving the consistency of data and status in software systems in the security field still needs to be solved. Summary of the invention
[0009] The purpose of the present invention is to provide a method for maintaining data and state consistency in a security software system, so as to achieve the unification of data and state in a simpler and more reliable way than a distributed transaction framework.
[0010] To achieve the above object, the technical solution adopted by the present invention is:
[0011] A method for maintaining data and state consistency in a security software system, the security software system comprising a gateway, a business service, a device access service and a security device, the method for maintaining data and state consistency in the security software system is used to maintain data and state consistency between the business service and the device access service, the method for maintaining data and state consistency in the security software system comprising:
[0012] When the device access service performs an operation on a security device but cannot return the operation result to the business service due to a network anomaly, the business service periodically re-initiates a device operation request to the device access service with the same parameters until the operation result returned by the device access service based on idempotence is received and saved locally;
[0013] When the device access service crashes and exits abnormally, the business service re-initiates the device operation request based on the operation performed before the device access service crashes and exits after the device access service is restarted, receives the operation result returned by the device access service and saves it locally.
[0014] Several optional methods are also provided below, but they are not intended to be additional limitations on the above-mentioned overall solution, but are merely further supplements or preferences. Under the premise that there are no technical or logical contradictions, each optional method can be combined with the above-mentioned overall solution separately, and multiple optional methods can also be combined.
[0015] Preferably, the business service locally stores the status of the device accessing the service;
[0016] When the business service is started, the device access service status is set to offline;
[0017] The business service receives the registration initiated when the device access service is started and sets the status of the locally saved device access service to online;
[0018] The business service periodically initiates heartbeats to the device access service, and keeps the device access service online based on the heartbeat responses returned by the device access service.
[0019] Preferably, the business service periodically re-initiates a device operation request to the device access service with the same parameters, including:
[0020] When the business service initiates a device operation request to the device access service and times out without receiving the operation result returned by the device access service, the abnormal data related to the device operation request is recorded in the local database;
[0021] The business service periodically queries the local database for abnormal data and re-initiates device operation requests with the same parameters based on the abnormal data.
[0022] Preferably, the business service re-initiates the device operation request after the device access service is restarted according to the operation performed before the device access service crashes and exits, including:
[0023] After the business service fails to receive the heartbeat response from the device access service for multiple consecutive times, the status of the device access service is changed to offline;
[0024] The business service receives the registration initiated by the device access service after it is restarted and sets the status of the locally saved device access service to online;
[0025] The business service periodically initiates a heartbeat to the device access service, and keeps the device access service online based on the heartbeat response returned by the device access service;
[0026] The business service re-initiates the device operation request based on the operation performed before the device access service crashed and exited.
[0027] Preferably, the device operation request includes a device add request and a device delete request;
[0028] If the device operation request is a request to add a device, the business service re-initiates the device operation request according to the operation performed before the device access service crashes and exits, including: the business service re-initiates the request to add a device according to all security devices connected before the device access service crashes and exits;
[0029] If the device operation request is a device deletion request, the business service re-initiates the device operation request based on the operation performed before the device access service crashes and exits, including: the business service re-initiates a device deletion request to the device access service based on the security device that needs to be deleted before the device access service crashes and exits, and re-initiates a device addition request based on the security devices other than the security devices that need to be deleted that were accessed before the device access service crashes and exits.
[0030] Preferably, when the device access service does not have idempotency, the device access service performs an idempotency simulation operation, and the idempotency simulation operation includes:
[0031] If the device operation request received by the device access service is a request to add a device, the successful result returned by the request and the error result returned by the request indicating that the device already exists will be combined for processing;
[0032] If the device operation request received by the device access service is a request to delete a device, the successful result returned for the request and the error result returned for the request indicating that the device does not exist will be merged and processed.
[0033] Preferably, when the business service does not support registration and heartbeat mechanism, the business service performs a registration heartbeat simulation operation, and the registration heartbeat simulation operation includes:
[0034] The business service selects a query interface from the interfaces provided by the device access service as the simulation interface;
[0035] When the business service is started, the device access service status is set to offline;
[0036] If the business service successfully calls the simulation interface for the first time, the device access service is considered to be successfully registered and the status of the locally saved device access service is updated to online;
[0037] If the business service successfully calls the simulation interface continuously, it is considered that the heartbeat response returned by the device access service is received and the status of the device access service is kept online;
[0038] If the business service fails to call the simulation interface continuously, it is considered that the heartbeat has failed and the status of the device access service is updated to offline.
[0039] The method for maintaining data and state consistency in the security software system provided by the present invention enables data and state to be automatically restored to achieve final consistency by introducing interface idempotence and retry, registration and heartbeat, and automatic restart designs. Compared with the introduction of a distributed transaction framework, it is simpler and has a lower learning cost. It also has higher reliability. Although it mainly describes the design in the security system, it is also applicable to software systems in most fields. Secondly, in large software projects, existing services do not need to be modified, and the cost of implementation is low, which is particularly useful in system integration projects and software projects that need to reuse old ones. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a schematic diagram of the framework of the security software system of the present invention. DETAILED DESCRIPTION
[0041] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0043] like Figure 1 As shown, a typical security software system usually includes four parts: gateway, business service, device access service, and security equipment. Security software systems such as the intelligent perception networking platform (AIOT PNP) (https: / / www.hikvision.com / cn / software-product / AIoT-PNP / ) in the prior art include four key functional parts: device access, device management, resource networking, and open sharing. The services carried by the device access function correspond to the device access service of this application, and the services carried by the device management, resource networking, and open sharing functions correspond to the business services of this application.
[0044] The main function of the gateway is to forward client requests to the designated business service for processing according to the specified rules. The main function of the business service is to accept requests to process business logic. If the business logic is hardware-related, the request is sent to the device access service. The main function of the device access service is to manage devices, accept business service requests and send the requests to security devices for processing, and send the events reported by the security devices to the business service for business logic processing.
[0045] In order to overcome the problem that the distributed transaction framework in the prior art cannot be well applied in the security software system to solve the problem of maintaining data and status consistency, this embodiment provides a method for achieving final data consistency by introducing interface idempotence and retry, registration and heartbeat, and automatic restart designs so that the data and status of each service in the system can be automatically restored.
[0046] The method for maintaining data and state consistency in a security software system provided in this embodiment includes the following steps:
[0047] When the device access service performs an operation on a security device but cannot return the operation result to the business service due to a network anomaly, the business service periodically re-initiates a device operation request to the device access service with the same parameters until the operation result returned by the device access service based on idempotence is received and saved locally.
[0048] When the device access service crashes and exits abnormally, the business service re-initiates the device operation request based on the operation performed before the device access service crashes and exits after the device access service is restarted, receives the operation result returned by the device access service and saves it locally.
[0049] In this embodiment, the data and status of both the business service and the device access service are kept consistent. The device access service will record the added security devices, and the business service will also record the added security devices. These records are data that need to be consistent. In addition, the online and offline status of the added security devices also need to be consistent. After an abnormal crash and restart, the records of the added security devices recorded in the device access service are lost. When the device access service is re-registered and receives the device add request sent by the business service, it will re-record the added security devices and their status.
[0050] In order to maintain the communication between the business service and the device access service, the business service saves the status of the device access service locally. When the business service starts, the status of the device access service is set to offline; the business service receives the registration initiated when the device access service starts and sets the locally saved status of the device access service to online; the business service periodically initiates heartbeats to the device access service, and keeps the status of the device access service online according to the heartbeat response returned by the device access service.
[0051] The idempotence of an interface means that as long as the parameters are the same, the returned results must be consistent. It can be combined with retries to solve the problem that the request is sent successfully but the processing result cannot be returned due to service exceptions or network failures.
[0052] Therefore, when the business service initiates a device operation request to the device access service and times out without receiving the operation result returned by the device access service, the abnormal data related to the device operation request is recorded in the local database; the business service periodically queries the local database for abnormal data, and re-initiates the device operation request with the same parameters based on the abnormal data.
[0053] Network abnormalities may be just momentary jitters, which will only cause the operation results to fail to be returned at the moment of jitter, while the network is normal at other times. The heartbeat mechanism will only be set offline if multiple heartbeat responses are not received. Therefore, the device access service will not be set offline due to momentary network jitters.
[0054] In this embodiment, the abnormal data related to the device operation request includes the type of device operation request, the device unique identifier, the device operation result (success, failure or abnormality), and the operation time. It is easy to understand that the above is the content included in the abnormal data of the device in this embodiment, and corresponding content can be added or deleted in other embodiments.
[0055] The following uses the example of adding a device (or deleting a device) in a security software system to describe the entire process of interface idempotence and retry. In this example, the interface for device access services has achieved idempotence.
[0056] a. The user initiates a request to add a device (or delete a device), which is transmitted to the business service through the gateway;
[0057] b. The business service initiates a request to add a device (or delete a device) to the device access service;
[0058] c. Device access service accesses (or deletes) security devices based on add device request (or delete device request);
[0059] d. The device access service successfully accesses (or deletes) the security device, but an abnormality occurs in the network and the processing result cannot be returned to the business service;
[0060] e. The business service cannot receive the processing result. After the timeout, the exception is recorded in the database and the user is notified that an offline device has been added (or the exception is deleted);
[0061] f. The business service periodically queries the database for abnormal records, and sends a device add request (or device delete request) to the device access service with the same parameters based on the abnormal records to re-add (or delete) the security device;
[0062] g. The device access service has idempotence and returns the processing result to the business service directly if it finds that the same parameters have been processed before;
[0063] h. The business service successfully obtains the processing result and corrects the abnormal record in the database;
[0064] i. Notify the user of the correct result. It can be seen that when an operation is abnormal, it will be automatically retried until the processing result is successfully obtained to keep the data and status in the business service and device access service consistent.
[0065] The registration and heartbeat mechanisms are used to detect whether the service is online. Only online services can process requests. Usually, after the device access service is started, it will initiate a registration request to the upstream business service. When the business service receives the registration request, it will be set to online, which means that the device access service can normally process the business service's requests. After successful registration, the business service and the device access service maintain an online state through heartbeat requests. Once multiple heartbeats fail, the status of the device access service is offline, which means that the device access service can no longer normally process the business service's requests. The following briefly describes the entire process.
[0066] a. The device access service initiates registration with the business service;
[0067] b. The business service sets the status of the device access service saved locally to online;
[0068] c. The business service initiates a heartbeat to the device access service;
[0069] d. Device access service response heartbeat;
[0070] e. The business service keeps the status of the locally saved device access service online;
[0071] f. The business service initiates a heartbeat to the device access service;
[0072] g. The business service fails to receive the heartbeat response of the device access service for many times;
[0073] h. The business service modifies the status of the locally saved device access service to offline.
[0074] In this embodiment, the device access service is kept alive through registration and heartbeat mechanisms, and related operations are performed on the premise that the device access service is online.
[0075] In practice, services may crash due to various abnormal situations such as bugs, insufficient memory, etc. In the prior art, when faced with abnormal crashes, manual intervention is usually required to restart the service. Considering that most projects have indicators that require unattended operation within a certain period of time. Therefore, this embodiment introduces a technology similar to a watchdog to monitor the service, and automatically restarts it once a service crash is found.
[0076] When the business service fails to receive the heartbeat response from the device access service for multiple consecutive times, the device access service status is changed to offline. At this time, the device access service is likely to crash due to an abnormality. After the watchdog detects the abnormal crash, it automatically restarts the device access service. The business service receives the registration initiated after the device access service restarts and sets the locally saved device access service status to online. The business service periodically initiates a heartbeat to the device access service, and keeps the device access service status online according to the heartbeat response returned by the device access service.
[0077] After the device access service is restarted, it re-registers with the business service and maintains the heartbeat to ensure that normal operation is restored. After the device access service is restored to normal, the business service re-initiates the device operation request based on the operation performed before the device access service crashed and exited.
[0078] Usually, the device access service usually has four interfaces: adding devices, deleting devices, modifying devices, and querying devices. However, since modifying devices and querying devices do not require high efficiency in business scenarios, it is not necessary to save device information (such as device coordinates and other information) in business services and device access services, that is, these two situations do not involve the consistency of data and status. Therefore, this embodiment focuses on adding devices and deleting devices to describe how to maintain the consistency of data and status.
[0079] Therefore, if the device operation request is a request to add a device, the business service re-initiates the device operation request based on the operation performed before the device access service crashes and exits, including: the business service re-initiates the request to add a device based on all security devices connected before the device access service crashes and exits;
[0080] Taking a specific device as an example, if the device access service crashes while executing a device add request for security device D after the three security devices A, B, and C have been added, then after the device access service is restarted and registered to keep alive, the business service re-initiates a device add request to the device access service for device D and the three security devices A, B, and C that were originally added.
[0081] Of course, the device adding requests for A, B, C, and D can be initiated simultaneously, or one by one according to the business scenario.
[0082] If the device operation request is a device deletion request, the business service re-initiates the device operation request based on the operation performed before the device access service crashes and exits, including: the business service re-initiates a device deletion request to the device access service based on the security device that needs to be deleted before the device access service crashes and exits, and re-initiates a device addition request based on the security devices other than the security devices that need to be deleted that were accessed before the device access service crashes and exits.
[0083] Taking a specific device as an example, if the device access service crashes when executing a request to delete the device for security device B after adding three security devices A, B, and C, then after the device access service is restarted and registered to keep alive, the business service will re-initiate a request to delete the device for device B and a request to add the device for security devices A and C to the device access service. This ensures that the data and status in the business service and the device access service are consistent.
[0084] This embodiment does not need to introduce a distributed transaction framework, and only uses conventional technical means (interface idempotence and retry, registration and heartbeat, automatic restart) to achieve the purpose of maintaining data and state consistency. Compared with the existing technology, it has lower requirements on the application system and is more applicable.
[0085] Based on this, taking adding devices in a security software system as an example, this paper describes how to automatically restore the data and status of each service in the system through the design of interface idempotence and retry, registration and heartbeat, and automatic restart, which specifically includes the following steps:
[0086] a. The device access service initiates registration with the business service;
[0087] b. The business service sets the status of the device access service saved locally to online;
[0088] c. The business service initiates a heartbeat to the device access service;
[0089] d. Device access service response heartbeat;
[0090] e. The business service keeps the status of the locally saved device access service online;
[0091] f. The user initiates a request to add a device, which is transmitted to the business service through the gateway;
[0092] g. The business service initiates a request to add a device to the device access service;
[0093] h. The device access service successfully accesses the security device (the device access service internally records that the security device is online);
[0094] i. The device access service successfully accesses the device, but an abnormality occurs in the network and the processing result cannot be returned to the business service;
[0095] j. The business service cannot receive the processing result. After the timeout, the exception will be recorded in the database and the user will be notified that an offline device has been added (the business service internally records that the security device is offline. At this time, the status recorded for the same security device in the business service and the device access service is inconsistent);
[0096] k. The business service periodically queries the database for abnormal records, and sends a device add request to the device access service with the same parameters to re-add the device according to the abnormal records;
[0097] l. The device access service has idempotence and returns the processing result directly if it finds that the same parameters have been processed before;
[0098] m. The business service successfully obtains the processing result and corrects the abnormal record in the database (the business service and device access service internally record that the security device is online. At this time, the recorded status of the same security device in the business service and device access service is consistent);
[0099] n. The device access service crashes and exits due to an exception (at this time, the business service still believes that the security device is online, but the device access service crashes and exits, resulting in the loss of recorded data and status. At this time, the recorded status of the same security device in the business service and the device access service is inconsistent);
[0100] o. The business service initiates a heartbeat to the device access service;
[0101] p. The business service cannot receive the heartbeat response of the device access service for many times;
[0102] q. The business service modifies the status of the device access service to offline (at this time, the status recorded for the same security device in the business service and the device access service is inconsistent);
[0103] r. If the monitoring program finds that the device access service has crashed, it restarts the device access service (at this time, the business service believes that the security device is online, and the device access service has no record of the security device. At this time, the recorded status of the same security device in the business service and the device access service is inconsistent);
[0104] s. The device access service initiates registration with the business service;
[0105] t. The business service sets the status of the device access service saved locally to online;
[0106] u. The business service re-initiates a request to add a device to the device access service based on the security device that has been previously added to the device access service;
[0107] v. The device access service successfully accesses the security device (the situation where the device access service fails to return a result due to an exception is not described here);
[0108] w. At this time, both the business service and the device access service record that the device is online, and the recorded status of the same security device in the business service and the device access service is restored to be consistent.
[0109] During the entire process, network anomalies and service crashes occurred, but the business services and device access services ultimately remained consistent and recovered to the correct state and the devices were online.
[0110] In addition, taking the deletion of devices in the security software system as an example, this paper describes how to automatically restore the data and status of each service in the system through the design of interface idempotence and retry, registration and heartbeat, and automatic restart. The specific steps include:
[0111] a. The device access service initiates registration with the business service;
[0112] b. The business service sets the status of the device access service saved locally to online;
[0113] c. The business service initiates a heartbeat to the device access service;
[0114] d. Device access service response heartbeat;
[0115] e. Business services keep the device access service status online;
[0116] f. The user initiates a request to delete a device (the prerequisite is that the security device to be deleted has been successfully added), and the request is transmitted to the business service through the gateway;
[0117] g. The business service initiates a device deletion request to the device access service;
[0118] h. The device access service successfully deletes the security device (the device access service no longer communicates with the security device and removes the device information internally);
[0119] i. The device access service successfully accesses and deletes the device, but the network is abnormal or crashes, and the processing result cannot be returned to the business service;
[0120] j. The business service cannot receive the result. After the timeout, the exception will be recorded in the database and the user will be notified of the deletion failure (the business service still has the record and online status of the security device. At this time, the recorded status of the same security device in the business service and the device access service is inconsistent);
[0121] k. The business service periodically queries the database for abnormal records and deletes the device with the same parameters based on the abnormal records;
[0122] l. If the device access service does not crash abnormally and restarts, the processing result is directly returned if the same parameter has been processed due to idempotence;
[0123] If the device access service has crashed and restarted abnormally, the restart and re-registration process refers to steps o to t of adding a device (at this time, the business service has a record of the device, but the device access service has no record of the device). When receiving a request to delete a device, it directly returns a successful result.
[0124] m. The business service successfully obtains the processing result and corrects the abnormal record in the database (the device information is removed from both the business service and the device access service. At this time, the recorded status for the same security device in the business service and the device access service is consistent).
[0125] In actual project implementation, it is often encountered that the existing services in the early stage of the project do not support idempotency, registration and heartbeat mechanisms, which means that if these services are not compatible, the new services still cannot guarantee data and status consistency. After careful research, it is found that existing services can be compatible by simulating idempotence, registration and heartbeat mechanisms.
[0126] The simulation of interface idempotency includes: the interfaces provided by the service are mainly divided into four types: add, delete, modify, and query. Among them, the modification type and query type interfaces must return the same results because of the same parameters, so these two types of interfaces usually have idempotency without special processing. The call of the same parameter of the add type interface either returns success or returns an existing error. In this case, as long as the existing error and success are merged, it can be considered to have idempotency. The call of the same parameter of the delete type interface either returns success or returns a non-existent error. As long as the non-existent error and success are merged, it can also be considered to have idempotency.
[0127] Through the above analysis, we can draw a conclusion that most services, without changing their own codes, can be considered to have idempotency in disguise as long as the new service performs special processing on the interface return value of the existing service (combining some error return values with successful return values), and the interface idempotency has been achieved.
[0128] That is, in the security software system, if the device access service does not have idempotency, the device access service performs idempotency simulation operations, which include:
[0129] If the device operation request received by the device access service is a request to add a device, the successful result returned by the request and the error result returned by the request indicating that the device already exists will be merged and processed.
[0130] If the device operation request received by the device access service is a request to delete a device, the successful result returned for the request and the error result returned for the request indicating that the device does not exist will be merged and processed.
[0131] The merge processing can be understood as treating the existing (or non-existent) error as a success, and in the specific implementation logic, the existing (or non-existent) error result is handled in the same way as the successful result.
[0132] In addition, the simulation of registration heartbeat includes: For the situation that the existing service does not support registration and heartbeat mechanism, we can simulate it by frequently calling the specified interface. Usually, we can select a query interface from the interface provided by the existing service to call frequently. Due to the high frequency of calling, the interface should have low performance consumption. The new service will record the online and offline status of the existing service, and update the status according to the result of calling the interface. When the new service is just started, the status of the existing service is offline. After the interface is called successfully, it is considered that the registration is successful and the status is updated to online. If the existing service is offline due to various abnormal conditions, the new service call interface will inevitably return failure. Multiple failures are considered to be heartbeat failures and are set to offline. It should be noted that during project implementation, the frequency of interface calls and the number of failed calls must be selected according to the actual situation to ensure that the existing service can respond normally to the outside world.
[0133] That is, in the security software system, if the business service does not support the registration and heartbeat mechanism, the business service performs the registration heartbeat simulation operation, which includes:
[0134] The business service selects a query class interface from the interfaces provided by the device access service as a simulation interface; when the business service starts, the status of the device access service is set to offline; if the business service successfully calls the simulation interface for the first time, it is considered that the device access service registration is successful and the locally saved status of the device access service is updated to online; if the business service successfully calls the simulation interface continuously, it is considered that the heartbeat response returned by the device access service is received and the status of the device access service is kept online; if the business service fails to call the simulation interface continuously, it is considered that the heartbeat has failed and the status of the device access service is updated to offline.
[0135] This embodiment introduces interface idempotence and retry, registration and heartbeat, and automatic restart designs so that data and status can be automatically restored to achieve final consistency. Compared with the introduction of a distributed transaction framework, it is simpler and has a lower learning cost. It also has higher reliability. Although it mainly describes the design in security systems, it is also applicable to software systems in most fields. Secondly, in large software projects, existing services do not need to be modified, and the implementation cost is low, which is especially useful in system integration projects and software projects that need to reuse old software.
[0136] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0137] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A method for maintaining data and state consistency in a security software system, wherein the security software system comprises a gateway, a business service, a device access service and a security device, wherein the method for maintaining data and state consistency in the security software system is used to maintain data and state consistency between the business service and the device access service, and is characterized in that: The method for maintaining data and state consistency in a security software system comprises: When the device access service performs an operation on a security device but cannot return the operation result to the business service due to a network anomaly, the business service periodically re-initiates a device operation request to the device access service with the same parameters until the operation result returned by the device access service based on idempotence is received and saved locally; When the device access service crashes and exits abnormally, the business service re-initiates the device operation request according to the operation performed before the device access service crashes and exits after the device access service is restarted, receives the operation result returned by the device access service and saves it locally; The business service re-initiates a device operation request after the device access service is restarted according to the operation performed before the device access service crashes and exits, including: After the business service fails to receive the heartbeat response from the device access service for multiple consecutive times, the status of the device access service is changed to offline; The business service receives the registration initiated by the device access service after it is restarted and sets the status of the locally saved device access service to online; The business service periodically initiates a heartbeat to the device access service, and keeps the device access service online based on the heartbeat response returned by the device access service; The business service re-initiates the device operation request based on the operation performed before the device access service crashed and exited; Wherein, the device operation request includes a device add request and a device delete request; If the device operation request is a request to add a device, the business service re-initiates the device operation request according to the operation performed before the device access service crashes and exits, including: the business service re-initiates the request to add a device according to all security devices connected before the device access service crashes and exits; If the device operation request is a device deletion request, the business service re-initiates the device operation request based on the operation performed before the device access service crashes and exits, including: the business service re-initiates a device deletion request to the device access service based on the security device that needs to be deleted before the device access service crashes and exits, and re-initiates a device addition request based on the security devices other than the security devices that need to be deleted that were accessed before the device access service crashes and exits.
2. The method for maintaining data and state consistency in a security software system according to claim 1, characterized in that: The business service locally stores the status of the device access service; When the business service is started, the device access service status is set to offline; The business service receives the registration initiated when the device access service is started and sets the status of the locally saved device access service to online; The business service periodically initiates heartbeats to the device access service, and keeps the device access service online based on the heartbeat responses returned by the device access service.
3. The method for maintaining data and state consistency in a security software system according to claim 1, characterized in that: The business service periodically re-initiates a device operation request to the device access service with the same parameters, including: When the business service initiates a device operation request to the device access service and times out without receiving the operation result returned by the device access service, the abnormal data related to the device operation request is recorded in the local database; The business service periodically queries the local database for abnormal data and re-initiates device operation requests with the same parameters based on the abnormal data.
4. The method for maintaining data and state consistency in a security software system according to claim 1, characterized in that: When the device access service does not have idempotency, the device access service performs an idempotency simulation operation, and the idempotency simulation operation includes: If the device operation request received by the device access service is a request to add a device, the successful result returned by the request and the error result returned by the request indicating that the device already exists will be combined for processing; If the device operation request received by the device access service is a request to delete a device, the successful result returned for the request and the error result returned for the request indicating that the device does not exist will be merged and processed.
5. The method for maintaining data and state consistency in a security software system according to claim 1, characterized in that: When the business service does not support the registration and heartbeat mechanism, the business service performs a registration heartbeat simulation operation, and the registration heartbeat simulation operation includes: The business service selects a query interface from the interfaces provided by the device access service as the simulation interface; When the business service is started, the device access service status is set to offline; If the business service successfully calls the simulation interface for the first time, the device access service is considered to be successfully registered and the status of the locally saved device access service is updated to online; If the business service successfully calls the simulation interface continuously, it is considered that the heartbeat response returned by the device access service is received and the status of the device access service is kept online; If the business service fails to call the simulation interface continuously, it is considered that the heartbeat has failed and the status of the device access service is updated to offline.
Citation Information
Patent Citations
Final consistency guaranteeing method and system for transactions
CN108874587A
Security implementation method, security equipment and APP client
CN110460627A
Interface access method and device, equipment and medium
CN113656473A
Real-time database API (Application Program Interface) non-interruption calling method and system, storage medium and server
CN113986501A
Function as a service (FAAS) system enhancements
US20210263779A1
