A method, device and medium for multi-level granularity alarm caching and concurrency control

By implementing a multi-level granularity alarm caching and concurrency control method for network security monitoring systems, and independently configuring read-write locks and cache tables, the resource contention problem in alarm processing under high concurrency scenarios is solved, achieving efficient alarm data management and status tracking.

CN123123104APending Publication Date: 2026-11-17SHENZHEN LEAGSOFT TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610981953.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-02
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In high-concurrency scenarios, existing technologies in network security monitoring systems face resource contention pressures in alarm data processing, leading to database response delays and downtime risks. Furthermore, scripts with different detection cycles interfere with each other when accessing shared data structures, making differentiated isolation management difficult.

Method used

A multi-level granularity alarm caching and concurrency control method is adopted. By independently configuring read locks, write locks, total number of active alarms, cache table and active alarm mapping table for each period granularity, alarm processing at different period granularities is completely isolated. Read-write lock separation and atomic counters are used to ensure the security and accuracy of data modification.

Benefits of technology

It eliminates concurrency interference and resource contention caused by different periodic detection scripts sharing the same data structure, improves system throughput and data consistency in high-concurrency scenarios, and ensures that the resource contention problem in alarm processing is fundamentally solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123104A_ABST
    Figure CN123123104A_ABST
Patent Text Reader

Abstract

This invention discloses a multi-level granularity alarm caching and concurrency control method, device, and medium, belonging to the field of operation and maintenance technology. The method includes: responding to receiving an alarm evaluation request triggered by a detection script, determining the periodic granularity corresponding to the detection script, and obtaining an alarm identifier corresponding to the alarm evaluation request; querying alarm cache data in the cache table corresponding to the periodic granularity based on the periodic granularity and the alarm identifier; determining whether the alarm triggering condition is met based on the alarm cache data; if the alarm triggering condition is met, acquiring a write lock corresponding to the periodic granularity; updating alarm records in the active alarm mapping table corresponding to the periodic granularity under the protection of the write lock, and incrementing the total number of active alarms of the periodic granularity through atomic operations; and releasing the write lock. This invention completely solves the technical problem of resource contention in alarm processing under high concurrency scenarios through multi-level granularity isolation at the architecture level.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of operation and maintenance technology, and in particular to a multi-level granularity alarm caching and concurrency control method, device and medium. Background Technology

[0002] In network security monitoring systems, the generation, storage, and status management of alarm information are crucial for ensuring reliable system operation. As network scale expands and business complexity increases, monitoring systems need to simultaneously handle diverse alarm demands from different detection cycles (such as second-level, minute-level, and hour-level), and a large number of detection scripts may be executed concurrently at the same time, resulting in alarm data exhibiting high frequency, massive volume, and high concurrency characteristics.

[0003] In existing technologies, database write-through or external caching systems like Redis are typically used to store alarm information. The former generates intensive disk I / O operations during peak alarm periods, easily causing database response delays or even system crashes. The latter introduces additional network dependencies and maintenance costs; if the caching service fails, the entire alarm chain risks interruption. Furthermore, existing alarm management systems generally process all alarms with a uniform time granularity. Scripts from different detection cycles interfere with each other when accessing shared data structures, making differentiated isolation management difficult. Moreover, to ensure data consistency, existing solutions often use a single mutex lock to protect the shared alarm set. When a large number of read operations (such as querying the interface) and write operations (such as alarm triggering) occur concurrently, severe lock contention can lead to a sharp drop in system throughput. Alarm deduplication and status tracking operations become performance bottlenecks due to frequent lock waiting. Summary of the Invention

[0004] This invention provides a multi-level granularity alarm caching and concurrency control method, device and medium, aiming to solve the technical problem of how to provide a solution that can effectively alleviate the resource contention pressure of alarm processing in high-concurrency scenarios.

[0005] In a first aspect, the present invention provides a multi-level granularity alarm caching and concurrency control method, comprising: In response to receiving an alarm evaluation request triggered by a detection script, the period granularity corresponding to the detection script is determined, and the alarm identifier corresponding to the alarm evaluation request is obtained. The period granularity is configured with independent read locks, write locks, total number of active alarms, cache table, and active alarm mapping table. Based on the period granularity and the alarm identifier, query the alarm cache data in the cache table corresponding to the period granularity; Based on the alarm cache data, determine whether the alarm triggering conditions are met; If the alarm triggering condition is met, then acquire the write lock corresponding to the period granularity. Under the protection of the write lock, the alarm record is updated in the active alarm mapping table corresponding to the period granularity, and the total number of active alarms at the period granularity is incremented through atomic operations; Release the write lock.

[0006] Optionally, querying alarm cache data in the cache table corresponding to the periodic granularity includes: Using the alarm identifier as the key, perform a query in the cache table corresponding to the periodic granularity; If a corresponding cache entry is found, the cached content is retrieved as the alarm cache data; If no corresponding cache entry is found, a new cache entry is created and used as the alarm cache data.

[0007] Optionally, updating the alarm record in the active alarm mapping table corresponding to the periodic granularity includes: Determine whether the alarm record already exists in the active alarm mapping table corresponding to the period granularity; If the alarm record already exists in the active alarm mapping table corresponding to the period granularity, then update the timestamp and alarm content of the alarm record; If the alarm record does not exist in the active alarm mapping table corresponding to the period granularity, a new alarm record is created in the active alarm mapping table. The new alarm record includes alarm type, alarm level, alarm subtype, current timestamp, and alarm content.

[0008] Optionally, the method further includes: In response to receiving a release request for an alarm, determine the periodic granularity corresponding to the release request; Obtain the write lock corresponding to the specified period granularity; Under the protection of the write lock, the alarm record corresponding to the release request is searched in the active alarm mapping table corresponding to the period granularity; If an alarm record corresponding to the release request is found, the alarm record is marked as released, the alarm end timestamp is recorded, the alarm record is removed from the active alarm mapping table, and the total number of active alarms at the periodic granularity is decremented through atomic operations. Release the write lock.

[0009] Optionally, the method further includes: In response to receiving a query request for alarm information, determine the period granularity and filtering conditions corresponding to the query request; Obtain the read lock corresponding to the period granularity; Under the protection of the read lock, the active alarm mapping table at the periodic granularity is traversed to filter alarm records that meet the filtering conditions; Release the read lock.

[0010] Optionally, after releasing the write lock, the method further includes: storing the alarm record in a local database in association with the periodic granularity; the alarm record includes an alarm start timestamp and an alarm end timestamp.

[0011] Optionally, storing the alarm record in a local database in association with the periodic granularity includes: Generate the cache key corresponding to the alarm record; Query the cache mapping table in memory to determine if the cache key exists; If the cache key exists, it is determined that the alarm record already exists in the local database, and the alarm count of the corresponding record in the local database is updated; If the cache key does not exist, a new record is inserted into the local database, and a new entry corresponding to the new record is created in the cache mapping table.

[0012] Optionally, the local database is configured with multi-dimensional indexes, and the method further includes: In response to receiving a combined query request containing multiple conditions, the alarm data table in the local database is jointly filtered based on the multi-dimensional index to obtain alarm records that simultaneously satisfy the multiple conditions as the query result.

[0013] Secondly, the present invention also provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.

[0014] Thirdly, the present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, can implement the above-described method.

[0015] This invention provides a multi-level granularity alarm caching and concurrency control method, device, and medium. By independently configuring read locks, write locks, the total number of active alarms, the cache table, and the active alarm mapping table for each period granularity, alarm processing at different period granularities is completely isolated. This architectural design fundamentally eliminates the concurrency interference and resource contention caused by different period detection scripts sharing the same data structure in existing technologies. When multiple period granularity detection scripts run simultaneously in high-concurrency scenarios, each script only operates on its own dedicated read lock, write lock, cache table, and active alarm mapping table, without affecting each other, thus fundamentally solving the lock contention and data conflict problems caused by period differences. Furthermore, the combination of the exclusiveness of write locks and atomic counters further ensures the security and accuracy of shared data modifications. Therefore, this invention, through multi-level granularity isolation at the architectural level, completely solves the technical problem of resource contention in alarm processing under high-concurrency scenarios. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 A flowchart illustrating a multi-level granularity alarm caching and concurrency control method provided in an embodiment of the present invention; Figure 2 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0020] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0021] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0022] As used in this specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."

[0023] Please see Figure 1 This invention provides a multi-level granularity alarm caching and concurrency control method. This method runs on a node device in a network security monitoring system and is used for efficient caching, accurate deduplication, and status management of network alarms in a high-concurrency environment. The node device can be a server or terminal in the network security monitoring system, which at least has a processor, memory, and network communication capabilities, and is used to deploy and run the method of this invention. Specifically, the method includes the following steps: S1, in response to receiving an alarm evaluation request triggered by a detection script, determine the period granularity corresponding to the detection script, and obtain the alarm identifier corresponding to the alarm evaluation request, wherein the period granularity is configured with independent read locks, write locks, total number of active alarms, cache table and active alarm mapping table.

[0024] In practice, when a node device receives an alarm evaluation request triggered by a detection script, it first determines the period granularity corresponding to the detection script and obtains the alarm identifier corresponding to the alarm evaluation request.

[0025] A detection script is a set of program instructions pre-deployed in the node devices of a network security monitoring system. It is used to periodically detect and evaluate network traffic, system logs, or device status according to a preset periodic granularity. During runtime, the detection script analyzes the collected data in real time according to its configured detection logic. When abnormal behavior is identified or preset alarm conditions are met, it generates and outputs an alarm evaluation request to the node device. Each detection script is associated with a specific periodic granularity, which determines the script's execution frequency, such as every minute, every 5 minutes, every hour, or daily, thereby achieving differentiated alarm detection at different time precisions. The execution result of the detection script is used to trigger the generation, updating, or release of alarms, serving as the starting point for the entire alarm management process.

[0026] Furthermore, the period granularity refers to the execution interval of the detection script, used to identify the frequency and timeliness requirements of alarm detection. This invention supports multiple period granularities, such as per minute, every 5 minutes, per hour, or per day. Different period granularities correspond to different cache tables, active alarm mapping tables, and read-write lock instances, enabling independent management and isolation of alarm data.

[0027] Furthermore, the alarm identifier is a string used to uniquely identify a specific alarm, typically generated by combining information such as alarm type, entity identifier, and period granularity, for example, "port scan_192.168.1.100_per minute". This identifier ensures that the same alarm can be accurately distinguished at different periods. In a specific implementation, the node device reads the running mode parameters of the detection script from the configuration file, calculates the period granularity corresponding to the script in combination with the current system time, and extracts the alarm identifier from the trigger request.

[0028] Furthermore, to support multi-level granular management, each periodic granularity is independently configured with a complete set of resources, including read locks, write locks, the total number of active alarms, a cache table, and an active alarm mapping table. The read locks and write locks are both read-write lock instances. A write lock is an exclusive lock; when a thread holds a write lock, any other thread (whether requesting a read lock or a write lock) is blocked and cannot access the protected shared resource. Write locks are used to ensure that when modifying shared data structures (such as the active alarm mapping table or the total number of active alarms), data cannot be read or modified simultaneously by other threads, thereby guaranteeing the atomicity of operations and data consistency.

[0029] Furthermore, a read lock is a shared lock that allows multiple threads to hold a read lock simultaneously for read operations. When a thread holds a read lock, other threads can also acquire the read lock, but cannot acquire the write lock. Read locks are used to protect shared data from modification by write operations during reading, while allowing multiple read operations to be executed concurrently, thereby improving the system's concurrent read performance. This design achieves read-read concurrency, meaning multiple read operations can be performed simultaneously. Compared to the traditional mutex lock's method of serializing all read and write operations, it significantly improves system throughput in high-concurrency read scenarios.

[0030] Furthermore, the total number of active alarms is an atomic integer variable used to accurately record the total number of alarms in the active state at the current period granularity. The atomic operation ensures that the increase or decrease of the count value is thread-safe when modified concurrently by multiple threads, and there will be no counting errors caused by race conditions.

[0031] Furthermore, the cache table is a key-value pair storage structure residing in memory, used to temporarily store cached data required for alarm evaluation. Its key is the alarm identifier string, and the value is the cached content string. The cache table is designed to reduce frequent access to persistent storage, improving the efficiency of alarm evaluation by maintaining a fast-accessible intermediate state data in memory.

[0032] Furthermore, the active alarm mapping table is also a key-value pair storage structure used to maintain detailed records of all active alarms at the current period granularity. The key is an alarm identifier string, and the value is an alarm structure containing alarm type, alarm level, alarm subtype, alarm timestamp, and alarm content, wherein the alarm content is stored in JSON format.

[0033] S2, based on the period granularity and the alarm identifier, query the alarm cache data in the cache table corresponding to the period granularity.

[0034] In practice, after determining the period granularity and alarm identifier, the node device queries the alarm cache data in the cache table corresponding to the period granularity. Specifically, the node device uses the alarm identifier as the key to search the cache table. If a corresponding cache entry is found, i.e., a cache hit occurs, the node device directly retrieves the stored cache content as the alarm cache data. This cache content is usually state information left from the last evaluation. For example, in a continuous alarm scenario, the cache content may record the time of the last trigger and the cumulative number of alarms. This information is crucial for evaluating whether the current alarm needs to be upgraded or downgraded.

[0035] Furthermore, if no corresponding cache entry is found, i.e., a cache miss occurs, the node device first creates a new cache entry. This involves inserting a new key-value pair into the cache table using the alarm identifier as the key, and setting the initial cache content to an empty object or a default state indicating the first trigger. This newly created cache entry is then used as the alarm cache data. This query operation is the starting point of the alarm evaluation process, and its purpose is to obtain historical evaluation states as the basis for this evaluation.

[0036] In some preferred embodiments, querying alarm cache data in the cache table corresponding to the period granularity includes: querying the cache table corresponding to the period granularity using the alarm identifier as the key; if a corresponding cache entry is found, the cached content is obtained as the alarm cache data; if no corresponding cache entry is found, a new cache entry is created and the new cache entry is used as the alarm cache data.

[0037] In practice, this embodiment clarifies the processing logic for both cache hits and misses in cache queries, ensuring the integrity and efficiency of the alarm assessment process.

[0038] Specifically, when performing a query operation, the node device uses the alarm identifier as the key to search the cache table corresponding to the periodic granularity. The cache table can be implemented using a hash table to achieve O(1) fast access. A hash table is a key-value pair mapping data structure that maps keys to storage buckets using a hash function, thereby enabling efficient insertion and search operations. In a specific implementation, the node device calls the hash table's search interface, passing the alarm identifier as a parameter.

[0039] Furthermore, if a corresponding cache entry is found, i.e., a cache hit occurs, the node device directly retrieves the stored cached content as the alarm cache data. This cached content is typically state information left from the last evaluation. For example, in a continuous alarm scenario, the cached content may record the time of the last trigger and the cumulative number of alarms. This information is crucial for assessing whether the current alarm needs to be escalated or downgraded. For instance, the cached content may contain a counter that records the number of times the alarm has been triggered consecutively. When this number exceeds a preset threshold, the node device can escalate the alarm level from "low risk" to "high risk" accordingly.

[0040] Furthermore, if no corresponding cache entry is found, i.e., a cache miss occurs, the node device first creates a new cache entry. Specifically, the node device inserts a new key-value pair into the cache table using the alarm identifier as the key, and sets the initial cache content to an empty object or a default state indicating the first trigger. For example, the initial cache content could be a JSON object containing a "first trigger" flag and the current timestamp. The node device then uses this newly created cache entry as the alarm cache data for subsequent evaluation processes.

[0041] This embodiment ensures smooth execution of the alarm evaluation process in any initial state by covering both complete branches of cache lookup. When the cache is hit, redundant calculations and state reconstruction are avoided, significantly improving evaluation efficiency. When the cache is missed, new cache entries are proactively created, establishing a data foundation for subsequent continuous evaluations, enabling the alarm system to smoothly transition from the initial state to a stable operating state. This mechanism is the basis for alarm deduplication and state tracking, and is also key to achieving efficient memory caching.

[0042] S3. Based on the alarm cache data, determine whether the alarm triggering conditions are met.

[0043] In practice, after acquiring the alarm cache data, the node device determines whether the alarm triggering conditions are met based on the alarm cache data. The alarm triggering conditions are logically defined within the detection script, and this invention does not specifically limit them. For example, the condition is considered met when the same abnormal behavior is detected in N consecutive detection cycles, or when the value of a certain indicator exceeds a preset threshold. Specifically, the node device reads historical state data from the cached content, combines it with the currently detected abnormal behavior characteristics, executes a preset evaluation algorithm, and finally outputs a Boolean value to indicate whether the alarm triggering conditions are met.

[0044] S4. If the alarm triggering condition is met, then acquire the write lock corresponding to the period granularity.

[0045] In practice, if the alarm triggering condition is met, the node device acquires the write lock corresponding to the periodic granularity. Acquiring the write lock is the first step in entering the critical section, protecting subsequent modifications to the shared data structure (i.e., the active alarm mapping table and the total number of active alarms) through exclusive access and preventing data contention. Further, in the specific implementation, the node device calls the read-write lock's locking interface, which blocks the current thread until it successfully acquires the write lock. After acquiring the write lock, other threads attempting to acquire read or write locks will be blocked until the current thread releases the write lock.

[0046] S5, under the protection of the write lock, update the alarm record in the active alarm mapping table corresponding to the period granularity, and increment the total number of active alarms of the period granularity through atomic operations.

[0047] In practice, under the protection of a write lock, the node device updates the alarm record in the active alarm mapping table corresponding to the periodic granularity. Specifically, the node device first determines whether the alarm record already exists in the active alarm mapping table. If the alarm record already exists, it means that the alarm has been triggered before and has not yet been released, and this triggering is a duplicate trigger. At this time, the node device performs an update operation, which specifically includes updating the timestamp of the alarm record to the current system time, and updating relevant fields in the alarm content, such as increasing the accumulated value of the alarm count or appending new context information. This update method ensures that the alarm status always reflects the latest situation, while avoiding the creation of redundant records.

[0048] Furthermore, if the alarm record does not exist, it means that this is the first time the alarm has been triggered. At this time, the node device creates a new alarm record in the active alarm mapping table. The new record contains core fields such as alarm type, alarm level, alarm subtype, current timestamp, and alarm content.

[0049] Furthermore, while updating or creating alarm records, the node device increments the total number of active alarms at the specified periodic granularity using atomic operations. An atomic operation is an indivisible operation in a multi-threaded environment; it either completes entirely or is not executed at all, without being interrupted by other threads. In computer systems, atomic operations are typically implemented using special instructions provided by the processor (such as compare-and-swap instructions) or lock-prefix instructions. In this invention, both the increment and decrement operations on the total number of active alarms employ atomic operations to ensure the accuracy and consistency of the count value during concurrent modification by multiple threads, avoiding counting errors caused by race conditions. Specifically, the node device calls an atomic increment function, which atomically increments the total number of active alarms by 1 and returns the updated value.

[0050] In some preferred embodiments, updating the alarm record in the active alarm mapping table corresponding to the periodic granularity includes: determining whether the alarm record already exists in the active alarm mapping table corresponding to the periodic granularity; if the alarm record already exists in the active alarm mapping table corresponding to the periodic granularity, then updating the timestamp and alarm content of the alarm record; if the alarm record does not exist in the active alarm mapping table corresponding to the periodic granularity, then creating a new alarm record in the active alarm mapping table, wherein the new alarm record includes alarm type, alarm level, alarm subtype, current timestamp, and alarm content.

[0051] In practice, this embodiment distinguishes between different processing logics for the first trigger and repeated trigger scenarios, thereby achieving refined management of the alarm lifecycle.

[0052] Under the protection of a write lock, the node device first determines whether the alarm record already exists in the active alarm mapping table corresponding to the periodic granularity. This determination is achieved by searching the active alarm mapping table using the alarm identifier as the key. The active alarm mapping table can also be implemented using a hash table to support efficient key-value lookups. The node device calls the lookup interface; if a non-empty result is returned, it means the alarm record already exists; if an empty result is returned, it means it does not exist.

[0053] Furthermore, if the alarm record already exists in the active alarm mapping table corresponding to the periodic granularity, it indicates that the alarm has been previously triggered and has not yet been released, and this triggering is a duplicate trigger. In this case, the node device performs an update operation, specifically including updating the timestamp of the alarm record to the current system time and updating relevant fields in the alarm content. For example, for malware communication alarms, different communication characteristics may be captured each time the alarm is triggered. The node device can append these new characteristics to the alarm content to form a more complete attack chain. In addition, the node device can also increase the accumulated value of the alarm count for subsequent analysis of the persistence and severity of the alarms. This update method ensures that the alarm status always reflects the latest situation while avoiding the creation of redundant records.

[0054] Furthermore, if the alarm record does not exist in the active alarm mapping table corresponding to the periodic granularity, it indicates that this alarm is being triggered for the first time. In this case, the node device creates a new alarm record in the active alarm mapping table. The newly created alarm record contains the following core fields: alarm type, used to identify the category of the alarm, such as port scanning, malware communication, or distributed denial-of-service attack; alarm level, used to identify the severity of the alarm, such as high-risk, medium-risk, or low-risk; alarm subtype, used to further refine the alarm category, such as SYN flood, DNS tunnel, or HTTP anomaly; current timestamp, recording the time when the alarm was first triggered; alarm content, storing detailed alarm information in JSON format, including source IP address, destination IP address, protocol type, port number, traffic feature vector, etc.

[0055] This embodiment achieves full lifecycle management of alarm status by determining whether an alarm record already exists and performing update and creation operations accordingly. The update operation ensures that repeatedly triggered alarms reflect the latest timestamps and content, avoiding redundancy caused by multiple duplicate records; furthermore, the creation operation ensures that the first-time triggered alarm is fully recorded and enters an active state. This differentiated processing method improves the accuracy and efficiency of alarm management, avoids a storm of duplicate alarms, and ensures that no first-time alarm is missed.

[0056] S6, release the write lock.

[0057] In practice, after completing the above operations, the node device releases the write lock. After the write lock is released, other waiting threads (whether read or write threads) can continue to access resources at that periodic granularity, thereby restoring normal concurrent processing.

[0058] Through the above steps, this embodiment achieves independent management and concurrent control of alarm data with different periodic granularities in memory, eliminating mutual interference between scripts of different periods. Simultaneously, it ensures performance and data consistency in high-concurrency scenarios through read-write lock separation and atomic operations. The technical effects of this embodiment are as follows: First, multi-level granularity isolation allows detection scripts of different periods to run concurrently without interfering with each other, solving the logical confusion problem caused by periodic conflicts in existing technologies. Second, the read-write lock separation mechanism allows multiple read operations to be executed concurrently without blocking each other. Compared to the traditional mutex lock method of serializing all read and write operations, this significantly improves the system throughput in high-concurrency query scenarios. At the same time, the mutual exclusion mechanism of read-write locks ensures the exclusivity of write operations when modifying shared data, avoiding data inconsistency problems caused by read-write conflicts. Third, atomic counters ensure accurate statistics of the total number of active alarms in a multi-threaded environment, avoiding counting errors caused by race conditions.

[0059] In some preferred embodiments, the method further includes: in response to receiving a release request for an alarm, determining the period granularity corresponding to the release request; acquiring a write lock corresponding to the period granularity; under the protection of the write lock, searching for an alarm record corresponding to the release request in the active alarm mapping table corresponding to the period granularity; if an alarm record corresponding to the release request is found, marking the alarm record as released, recording the alarm end timestamp, removing the alarm record from the active alarm mapping table, and decrementing the total number of active alarms for the period granularity through atomic operations; and releasing the write lock.

[0060] In practice, when the alarm conditions are no longer met, this embodiment solves the problem of how to gracefully terminate the alarm state and reclaim resources.

[0061] First, upon receiving a release request for an alarm, the node device determines the corresponding period granularity. The release request is proactively issued by the detection script when it determines that the alarm conditions are no longer met, typically after several consecutive detection cycles have passed without detecting any abnormal behavior. The release request contains the alarm identifier and period granularity information. The node device parses this information from the request to determine which period granularity the alarm to be released belongs to.

[0062] Furthermore, to ensure the atomicity of the release operation, the node device acquires the write lock corresponding to the specified period granularity. After acquiring the write lock, all read and write operations within that period granularity will be blocked until the write lock is released. This exclusive access ensures that the release operation will not be interfered with by other concurrent threads.

[0063] Further, under the protection of the write lock, the node device searches for the alarm record corresponding to the release request in the active alarm mapping table corresponding to the periodic granularity. The search operation is also performed using the alarm identifier as the key. If the alarm record corresponding to the release request is found, the node device performs the following steps: First, the alarm record is marked as released, indicating that the alarm is no longer active; second, the alarm end timestamp is recorded, which precisely marks the time when the alarm is cleared, and together with the alarm start timestamp, constitutes the complete lifecycle of the alarm; third, the alarm record is removed from the active alarm mapping table, releasing the occupied memory space; finally, the total number of active alarms at the periodic granularity is decremented through atomic operations to maintain consistency between the count and the actual number of active alarms. After completing the above operations, the node device releases the write lock.

[0064] Furthermore, if no corresponding alarm record is found during the search step, it indicates that the alarm may have been processed in advance or the release request is abnormal. The node device will directly release the write lock and terminate the process without making any modifications.

[0065] This embodiment achieves secure and reliable alarm release through a series of atomic operations—search, marking, recording, removing, and decrementing—protected by write locks. Recording the alarm end timestamp is a key innovation of this invention, enabling the system to fully track the duration of each alarm and providing crucial data for advanced functions such as alarm duration statistics, root cause analysis, and service level agreement evaluation. Simultaneously, removing records from the active mapping table and atomically decrementing the count ensures timely release of system resources and maintains consistent internal state.

[0066] In some preferred embodiments, the method further includes: in response to receiving a query request for alarm information, determining the period granularity and filtering conditions corresponding to the query request; acquiring a read lock corresponding to the period granularity; under the protection of the read lock, traversing the active alarm mapping table of the period granularity and filtering alarm records that meet the filtering conditions; and releasing the read lock.

[0067] In practice, the node device responds to a query request for alarm information, which may originate from an external web interface, application programming interface, or internal monitoring panel. The node device first parses the query request to determine its corresponding period granularity and filtering conditions. For example, the query request might ask for "retriev all high-risk alarms with a period granularity of one minute," where the period granularity is "one minute" and the filtering condition is "alarm level = high risk."

[0068] Furthermore, the node device acquires the read lock corresponding to the periodic granularity. Unlike write locks, read locks are shared locks, allowing multiple threads to hold them simultaneously. This means that when a large number of query requests flood in at the same time, they can all successfully acquire the read lock without blocking each other. In the specific implementation, the node device calls the read lock acquisition interface of the read-write lock, which allows multiple threads to successfully acquire the read lock simultaneously, and only blocks when the write lock is held.

[0069] Furthermore, under the protection of a read lock, the node device traverses the active alarm mapping table at the specified periodic granularity, filtering out all alarm records that meet the filtering conditions. The traversal operation starts from the first record in the active alarm mapping table, checking each record's field values ​​to see if they meet the filtering conditions. For example, for the filtering condition "alarm level = high risk," the node device checks the alarm level field of each record; if it is high risk, it retains the record; otherwise, it skips it. After filtering, the node device serializes the results into an output format, such as a JSON array or an XML document.

[0070] Furthermore, during the read lock holding period, any alarm triggering or release operation attempting to acquire a write lock will be blocked. This ensures that the data in the mapping table is not concurrently modified during traversal, thereby guaranteeing the integrity and consistency of the query results. After filtering is complete, the node device releases the read lock. Only after all read locks at this periodic granularity have been released can waiting write operations acquire write locks. Before this, if other read operations still hold read locks, write operations will continue to wait.

[0071] This embodiment achieves read-read concurrency by allocating read locks to query operations, meaning multiple query operations can be executed simultaneously without blocking each other. In existing technologies, a single mutex lock forces all read and write operations to be serialized, resulting in slow system response during high-concurrency queries. This invention, by separating read and write locks, allows alarm queries (read operations) to be executed concurrently, with strict mutual exclusion rules between read and write operations: when a read operation holds a read lock, a write operation must wait; when a write operation holds a write lock, a read operation must wait. This design maximizes the parallelism of read operations while ensuring data consistency, resulting in a significant improvement in system throughput compared to a single mutex lock solution in high-concurrency query scenarios. When a write operation is executed, a new read operation is briefly blocked, but once the write operation completes and releases the write lock, all waiting read operations can resume execution, thus achieving efficient resource scheduling under mixed read and write loads. This design greatly improves the overall system throughput, especially in scenarios with a large number of alarms and frequent queries, where its performance advantages are particularly prominent.

[0072] In some preferred embodiments, after releasing the write lock, the method further includes: storing the alarm record in a local database in association with the periodic granularity; the alarm record includes an alarm start timestamp and an alarm end timestamp.

[0073] In practical implementation, the local database refers to an embedded database system, such as SQLite, deployed locally on the node device. This local database requires no external service dependencies, stores all data in a single file, and features low latency, high reliability, and lightweight operation. The local database is used for persistent storage of alarm records, ensuring that alarm data is not lost after system restarts or power outages, and also supports efficient historical queries based on indexes.

[0074] Furthermore, after releasing the write lock, the node device associates the alarm record with the periodic granularity and stores it in a local database. The local database uses an embedded database, such as SQLite, which requires no external dependencies and features high reliability and low latency. SQLite is a lightweight embedded relational database that does not require a separate server process; all data is stored in a single ordinary disk file, making it ideal for resource-constrained deployment environments.

[0075] Furthermore, the core of the storage operation lies in mapping the data structure of alarm records to database tables. The alarm record includes an alarm start timestamp and an alarm end timestamp. The alarm start timestamp is written upon first triggering, while the alarm end timestamp is written upon alarm release. These two timestamps together precisely define the entire lifecycle of each alarm from its generation to its cancellation. For an active alarm, its alarm end timestamp can be empty or a special value (such as 0), indicating that the alarm has not yet ended.

[0076] In practice, the node device writes each field from the alarm record—alarm type, subtype, granularity (i.e., periodic granularity), entity type, entity value, level, start timestamp, end timestamp, count, and content—into the alarm data table in the database. Simultaneously, the association between the alarm record and the periodic granularity is also stored. For example, a "granularity" column can be added to the database table specifically to store periodic granularity information. This enables the system to efficiently retrieve and statistically analyze historical alarms according to granularity.

[0077] This embodiment addresses the memory volatility issue by storing alarm records in a local database with periodic granularity, ensuring that alarm data is not lost after a system restart. Storing alarm start and end timestamps allows alarm management to go beyond the current state, providing full lifecycle historical traceability. Operations personnel can use this data to accurately calculate average alarm recovery times, analyze alarm trends, and review security incidents, thus providing data support for optimizing security strategies.

[0078] In some preferred embodiments, the step of storing the alarm record in a local database in association with the periodic granularity includes: generating a cache key corresponding to the alarm record; querying the cache mapping table in memory to determine whether the cache key exists; if the cache key exists, determining that the alarm record already exists in the local database and updating the alarm count of the corresponding record in the local database; if the cache key does not exist, inserting a new record in the local database and creating a new entry corresponding to the new record in the cache mapping table.

[0079] In practice, before performing persistent storage, the node device first generates a cache key corresponding to the alarm record. The cache key is a unique identifier, calculated by combining the alarm identifier and the periodicity granularity, for example, by concatenating the two using a hash function and then extracting the digest. A hash function converts an input of arbitrary length into a fixed-length output; common hash functions include MD5 and SHA-256. In one specific implementation, the node device concatenates the alarm identifier string with the periodicity granularity string and then calculates its MD5 value as the cache key.

[0080] Furthermore, the node device queries the cache mapping table in memory to determine if the cache key exists. The cache mapping table is a key-value data structure residing in memory, such as a hash table, used to quickly determine whether a particular alarm record has been persisted. The key in the cache mapping table is the cache key, and the value is either the database record ID or a record status flag.

[0081] Furthermore, if the cache key exists, the node device determines that the alarm record already exists in the local database. In this case, there is no need to insert a new record; only the alarm count of the corresponding record in the local database needs to be updated. Specifically, the node device locates the corresponding record based on the database record ID stored in the cache mapping table, increments the alarm count field of that record by 1, and updates the last trigger time. This significantly reduces the database write load and avoids duplicate insertions.

[0082] Furthermore, if the cache key does not exist, the node device determines that this is a completely new alarm record. At this time, a new record is inserted into the local database, and a new entry corresponding to the new record is created in the cache mapping table, with the cache key as the key and the unique identifier of the new record as the value (e.g., the auto-incrementing primary key of the database record).

[0083] The core innovation of this embodiment lies in achieving in-database deduplication through a memory cache mapping table. For repeatedly triggered alarms, it avoids duplicate database insertion operations, degrading high-frequency database writes to in-memory state updates and extremely low-frequency database updates. This two-level caching design (memory cache mapping table plus local database) perfectly balances performance and reliability, significantly reducing the I / O pressure on the local database and preventing the disk from becoming a performance bottleneck, while also ensuring the accuracy of alarm counts. This is the key technology for achieving efficient persistence in high-concurrency scenarios in this invention.

[0084] In some preferred embodiments, the local database is configured with a multi-dimensional index, and the method further includes: in response to receiving a combined query request containing multiple conditions, performing joint filtering on the alarm data table in the local database based on the multi-dimensional index, and obtaining alarm records that simultaneously satisfy the multiple conditions as query results.

[0085] In practice, the local database is configured with multi-dimensional indexes. Specifically, multi-dimensional indexes refer to independent indexes created on the alarm data table of the local database for multiple key fields, including type indexes, subtype indexes, granularity indexes, entity indexes, level indexes, and timestamp indexes. These indexes are organized in the form of B+ trees, which can effectively support equality queries and range queries. A B+ tree is a balanced tree data structure in which all data is stored in the leaf nodes, and the internal nodes only store key-value pairs for navigation. This structure is particularly suitable for disk storage and can effectively reduce the number of disk I / O operations required for queries. For example, a timestamp index can quickly locate all records within a certain time window, while a granularity index can quickly filter alarms with a specific period granularity.

[0086] Furthermore, the node device responds to receiving a combined query request containing multiple conditions. The combined query request may simultaneously contain multiple filtering conditions, such as "granularity = hourly", "level = high risk", and "timestamp > 2026-01-01". The node device parses the query request and extracts all conditions and their corresponding fields.

[0087] Furthermore, the node device performs joint filtering on the alarm data table in the local database based on the multi-dimensional index. The database query optimizer selects the most efficient execution plan based on index statistics. For example, if the query conditions include both timestamp range and granularity conditions, the optimizer may first use the timestamp index to narrow down the data range, and then use the granularity index for further filtering. If the conditions contain multiple equality conditions (such as level and granularity), the optimizer may use an index merging algorithm, simultaneously utilizing multiple indexes for intersection operations. Through the combined use of indexes, the node device can quickly locate and return alarm records that simultaneously satisfy the multiple conditions as the query result.

[0088] This embodiment transforms complex queries that previously required full table scans into efficient index-based retrieval by establishing multi-dimensional indexes on the local database, resulting in an exponential improvement in query performance. Even with hundreds of millions of historical alert data entries, the system can still respond to complex combined query requests within milliseconds. Furthermore, this design makes the alert system not only a real-time monitoring tool but also a powerful security data warehouse, providing security analysts with robust data mining and tracing capabilities. Combined with the full lifecycle timestamps from the previous embodiment, users can accurately trace alert activities of any historical period, at any specific granularity, and of any type, greatly improving the efficiency and depth of security operations and maintenance.

[0089] Please see Figure 2 , Figure 2This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 500 can be a terminal or a server, wherein the server can be a standalone server or a server cluster composed of multiple servers.

[0090] The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.

[0091] The non-volatile storage medium 503 can store the operating system 5031 and the computer program 5032. When the computer program 5032 is executed, it causes the processor 502 to execute a multi-level granularity alarm caching and concurrency control method.

[0092] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.

[0093] The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a multi-level granular alarm caching and concurrency control method.

[0094] The network interface 505 is used for network communication with other devices. Those skilled in the art will understand that the above structure is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. A specific computer device 500 may include more or fewer components than shown in the figures, or combine certain components, or have different component arrangements.

[0095] The processor 502 is used to run a computer program 5032 stored in a memory to implement the steps of a multi-level granularity alarm caching and concurrency control method provided in any of the above embodiments.

[0096] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0097] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program may be stored in a storage medium, which is a computer-readable storage medium. The computer program is executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0098] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program. When executed by a processor, the computer program causes the processor to perform the steps of the multi-level granularity alarm caching and concurrency control method provided in any of the above embodiments.

[0099] The storage medium is a physical, non-transient storage medium, such as a USB flash drive, external hard drive, read-only memory (ROM), magnetic disk, or optical disk, or any other physical storage medium capable of storing program code. The computer-readable storage medium can be non-volatile or volatile.

[0100] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0101] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0102] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0103] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0104] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0105] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, this invention is also intended to include these modifications and variations as long as they fall within the scope of the claims of this invention and their equivalents.

[0106] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A multi-level granularity alarm caching and concurrency control method, characterized in that, include: In response to receiving an alarm evaluation request triggered by a detection script, the period granularity corresponding to the detection script is determined, and the alarm identifier corresponding to the alarm evaluation request is obtained. The period granularity is configured with independent read locks, write locks, total number of active alarms, cache table, and active alarm mapping table. Based on the period granularity and the alarm identifier, query the alarm cache data in the cache table corresponding to the period granularity; Based on the alarm cache data, determine whether the alarm triggering conditions are met; If the alarm triggering condition is met, then acquire the write lock corresponding to the period granularity. Under the protection of the write lock, the alarm record is updated in the active alarm mapping table corresponding to the period granularity, and the total number of active alarms at the period granularity is incremented through atomic operations; Release the write lock.

2. The multi-level granular alarm buffering and concurrency control method of claim 1, wherein, The step of querying alarm cache data in the cache table corresponding to the periodic granularity includes: Using the alarm identifier as the key, perform a query in the cache table corresponding to the periodic granularity; If a corresponding cache entry is found, the cached content is retrieved as the alarm cache data; If no corresponding cache entry is found, a new cache entry is created and used as the alarm cache data.

3. The multi-level granular alarm buffering and concurrency control method of claim 1, wherein, Updating the alarm record in the active alarm mapping table corresponding to the periodic granularity includes: Determine whether the alarm record already exists in the active alarm mapping table corresponding to the period granularity; If the alarm record already exists in the active alarm mapping table corresponding to the period granularity, then update the timestamp and alarm content of the alarm record; If the alarm record does not exist in the active alarm mapping table corresponding to the period granularity, a new alarm record is created in the active alarm mapping table. The new alarm record includes alarm type, alarm level, alarm subtype, current timestamp, and alarm content.

4. The multi-level granular alarm buffering and concurrency control method of claim 1, wherein, The method further includes: In response to receiving a release request for an alarm, determine the periodic granularity corresponding to the release request; Obtain the write lock corresponding to the specified period granularity; Under the protection of the write lock, the alarm record corresponding to the release request is searched in the active alarm mapping table corresponding to the period granularity; If an alarm record corresponding to the release request is found, the alarm record is marked as released, the alarm end timestamp is recorded, the alarm record is removed from the active alarm mapping table, and the total number of active alarms at the periodic granularity is decremented through atomic operations. Release the write lock.

5. The multi-level granular alarm buffering and concurrency control method of claim 1, wherein, The method further includes: In response to receiving a query request for alarm information, determine the period granularity and filtering conditions corresponding to the query request; Obtain the read lock corresponding to the period granularity; Under the protection of the read lock, the active alarm mapping table at the periodic granularity is traversed to filter alarm records that meet the filtering conditions; Release the read lock.

6. The multi-level granular alarm buffering and concurrency control method of claim 1, wherein, After releasing the write lock, the method further includes: storing the alarm record in a local database in association with the periodic granularity; the alarm record includes an alarm start timestamp and an alarm end timestamp.

7. The multi-level granular alarm buffering and concurrency control method of claim 6, wherein, The step of associating the alarm record with the periodic granularity and storing it in a local database includes: Generate the cache key corresponding to the alarm record; Query the cache mapping table in memory to determine if the cache key exists; If the cache key exists, it is determined that the alarm record already exists in the local database, and the alarm count of the corresponding record in the local database is updated; If the cache key does not exist, a new record is inserted into the local database, and a new entry corresponding to the new record is created in the cache mapping table.

8. The multi-level granular alarm buffering and concurrency control method of claim 6, wherein, The local database is configured with multi-dimensional indexes, and the method further includes: In response to receiving a combined query request containing multiple conditions, the alarm data table in the local database is jointly filtered based on the multi-dimensional index to obtain alarm records that simultaneously satisfy the multiple conditions as the query result.

9. A computer device, comprising: The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1-8.

10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, can implement the method as described in any one of claims 1-8.