Distributed event processing methods and electronic devices

By defining priorities and mutually exclusive execution types for event types, and using priority scheduling queues and global mapping tables for conflict detection, the problem of low event processing efficiency in distributed systems is solved, achieving efficient event processing and data consistency.

CN121349737BActive Publication Date: 2026-03-10INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511882836.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-15
Publication Date
2026-03-10
Estimated Expiration
2045-12-15

AI Technical Summary

Technical Problem

In existing technologies, distributed locks have fixed granularity and a single scheduling strategy, making it difficult to adapt to diverse event processing scenarios. This leads to increased response delays for critical events, intensified resource contention, and overall low event processing efficiency.

Method used

By defining priorities and mutually exclusive execution types for each event type, priority scheduling queues and global mapping tables are used to sort and manage event objects, and concurrent execution status is tracked in real time for conflict detection and business processing.

Benefits of technology

It significantly improves event processing efficiency, ensures the throughput and data consistency of distributed systems, and solves the problem of event resource contention in high-concurrency scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121349737B_ABST
    Figure CN121349737B_ABST
Patent Text Reader

Abstract

This invention provides a distributed event processing method and an electronic device, applicable to the field of distributed technology. The distributed event processing method includes: receiving an event processing request at the request receiving entry point of a distributed system; searching for the priority and mutually exclusive execution type corresponding to the event type from a preset event registration database based on the identifier representing the event type in the event processing request; inserting the event object, encapsulated from the event processing request, into a priority scheduling queue based on the priority and the timestamp of the event processing request; after extracting the event object for execution from the priority scheduling queue, performing conflict detection on the mutually exclusive execution type corresponding to the event type based on a global mapping table maintained in the distributed system; if no conflict is detected, invoking the business processor corresponding to the event type to execute the event object, and updating the current execution count of the event type in the global mapping table based on the execution status.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of distribution, in particular to a distributed event processing method and electronic equipment. BACKGROUND

[0002] With the wide application of distributed systems, event processing scenarios are increasingly complex, event types are diverse, and the requirements for processing timeliness and compliance are continuously improved. In related technologies, a distributed lock is used to coordinate concurrent operations to prevent resource competition and provide basic protection in the event processing process.

[0003] In the process of implementing the present application concept, it is found that the related technologies at least have the following problems: due to the fixed granularity and single scheduling strategy of the distributed lock, it is difficult to adapt to diversified scenarios, which leads to an increase in the response delay of key events and intensifies resource competition, thereby resulting in low overall event processing efficiency. SUMMARY

[0004] In view of the above problems, the present application provides a distributed event processing method, device, equipment, medium and program product.

[0005] According to a first aspect of the present application, a distributed event processing method is provided, comprising: receiving an event processing request at a request receiving interface of a distributed system, and finding a priority and a mutual exclusion execution type corresponding to an event type from a preset event registration library according to an identifier representing the event type in the event processing request; based on the priority and a timestamp of the event processing request, inserting an event object obtained by encapsulating the event processing request into a priority scheduling queue; after extracting the event object for execution from the priority scheduling queue, performing conflict detection on the mutual exclusion execution type corresponding to the event type based on a global mapping table maintained in the distributed system, wherein the global mapping table records different event types and respective concurrent execution counts corresponding to the different event types; in the case of no conflict being detected, calling a business processor corresponding to the event type to execute the event object, and updating a current execution count of the event type in the global mapping table based on an execution state.

[0006] The second aspect of the present application provides a distributed event processing device, comprising: an information searching module, configured to receive an event processing request at a request receiving interface of a distributed system, search for a priority and a mutual exclusion execution type corresponding to an event type from a preset event registration library according to an identifier representing the event type in the event processing request; an event inserting module, configured to insert an event object obtained by encapsulating the event processing request into a priority scheduling queue based on the priority and a timestamp of the event processing request; a conflict detecting module, configured to detect a mutual exclusion execution type corresponding to the event type based on a global mapping table maintained in the distributed system after extracting the event object for execution from the priority scheduling queue, wherein the global mapping table records different event types and respective concurrent execution counts of the different event types; and an event executing module, configured to execute the event object by calling a business processor corresponding to the event type in a case where no conflict is detected, and update a current execution count of the event type in the global mapping table based on an execution state.

[0007] The third aspect of the present application provides an electronic device, comprising: one or more processors; a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method.

[0008] The fourth aspect of the present application further provides a computer readable storage medium having a computer program or instructions stored thereon, wherein the computer program or instructions are executed by a processor to implement the steps of the method.

[0009] The fifth aspect of the present application further provides a computer program product comprising a computer program or instructions, wherein the computer program or instructions are executed by a processor to implement the steps of the method.

[0010] According to the embodiments of the present application, the priority and the mutual exclusion execution type are defined for each event type in advance through an event registration mechanism, and a clear rule basis is established for event processing. The event objects are sorted and managed by using the priority scheduling queue, so that the high-priority events can be preferentially scheduled and executed. The global mapping table of the event types and the concurrent execution counts is maintained to track the concurrent execution state in the distributed environment in real time, and the mutual exclusion execution type is detected based on the global mapping table. This real-time state query mechanism based on the memory effectively improves the detection efficiency. If no conflict is detected, the business processing logic is executed, and the current execution count of the event type is updated synchronously, so that a complete event processing closed loop is formed. This mechanism effectively solves the event resource competition problem in the high-concurrency scenario, guarantees the throughput and data consistency of the distributed system, and significantly improves the event processing efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0011] The above and other objects, features and advantages of the present application will become more apparent from the following description when taken in conjunction with the accompanying drawings, in which:

[0012] Figure 1 An application scenario diagram of a distributed event processing method, apparatus, device, medium and program product according to an embodiment of the present application is shown.

[0013] Figure 2 A flowchart of a distributed event processing method according to an embodiment of the present application is shown.

[0014] Figure 3 A priority scheduling queue diagram of a distributed event processing method according to an embodiment of the present application is shown.

[0015] Figure 4 A flowchart of event object enqueueing of a distributed event processing method according to an embodiment of the present application is shown.

[0016] Figure 5 A flowchart of a distributed event processing method according to another embodiment of the present application is shown.

[0017] Figure 6 A flowchart of a distributed event processing method according to still another embodiment of the present application is shown.

[0018] Figure 7 A structural block diagram of a distributed event processing apparatus according to an embodiment of the present application is shown.

[0019] Figure 8 A block diagram of an electronic device suitable for implementing a distributed event processing method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0020] Hereinafter, embodiments of the present application will be described with reference to the accompanying drawings. It is to be understood, however, that the description is merely exemplary of the present application, and is intended to provide a thorough description for those skilled in the art to understand the present application. Therefore, the description is not intended to limit the scope of the present application. In the following detailed description of the embodiments of the present application, numerous specific details are set forth in order to provide a thorough understanding of the present application. However, it will be apparent to one skilled in the art that the present application can be practiced without these specific details. In other instances, well-known structures and functions have not been described in detail in order to avoid obscuring aspects of the present application.

[0021] The terms used herein are merely used to describe specific embodiments, and are not intended to limit the present application. The terms "include" and "have" and the like used herein indicate the presence of the described features, steps, operations, and / or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.

[0022] All terms used herein, including technical and scientific terms, have the meanings commonly understood by one of ordinary skill in the art unless otherwise defined. It should be further noted that the use of terms such as first and second, etc., is only intended to differentiate a general category of components or steps and not a particular component or step of the application unless it is stated otherwise.

[0023] In the case of using expressions similar to "at least one of A, B, and C, etc.", it should be generally interpreted that the meaning of the expression is the same as that of "one or more of A, B, and C" unless otherwise defined.

[0024] In the technical solutions of the present application, the data involved (including but not limited to data for analysis, stored data, displayed data, etc.) are information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with relevant laws, regulations and standards, necessary security measures are taken, do not violate public order and good customs, and provide corresponding operation portal for user to choose authorization or refusal.

[0025] The embodiment of the present application provides a distributed event processing method, comprising: receiving an event processing request at a request receiving interface of a distributed system, and finding a priority and a mutual exclusion execution type corresponding to an event type from a preset event registration library according to an identifier representing the event type in the event processing request; inserting an event object obtained by encapsulating the event processing request into a priority scheduling queue based on the priority and a timestamp of the event processing request; after extracting an event object for execution from the priority scheduling queue, performing conflict detection on the mutual exclusion execution type corresponding to the event type based on a global mapping table maintained in the distributed system, wherein the global mapping table records different event types and respective concurrent execution counts corresponding to different event types; in the case where no conflict is detected, calling a business processor corresponding to the event type to execute the event object, and updating a current execution count of the event type in the global mapping table based on an execution state.

[0026] Figure 1 An application scenario diagram of the distributed event processing method, apparatus, device, medium and program product according to the embodiment of the present application is shown.

[0027] As Figure 1As shown, the application scenario 100 according to this embodiment can include a first terminal device 101, a second terminal device 102, a third terminal device 103, and a server 105. The network 104 is a medium for providing communication links between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 can include various connection types, such as wired, wireless communication links, or fiber optic cables, and the like.

[0028] A user can use the first terminal device 101, the second terminal device 102, the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, and the like. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, and the like (only as examples).

[0029] The first terminal device 101, the second terminal device 102, the third terminal device 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smartphones, tablet computers, laptop computers, desktop computers, and the like.

[0030] The server 105 can be a server providing various services, such as a background management server supporting websites browsed by a user using the first terminal device 101, the second terminal device 102, the third terminal device 103 (only as an example). The background management server can analyze and process received user requests and the like, and feed back the processing results (such as web pages, information, or data, and the like obtained or generated according to user requests) to the terminal device.

[0031] It should be noted that the distributed event processing method provided by the embodiments of the present application can generally be executed by the server 105. Correspondingly, the distributed event processing apparatus provided by the embodiments of the present application can generally be arranged in the server 105. The distributed event processing method provided by the embodiments of the present application can also be executed by a server or a server cluster different from the server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or the server 105. Correspondingly, the distributed event processing apparatus provided by the embodiments of the present application can also be arranged in a server or a server cluster different from the server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or the server 105.

[0032] It should be understood that, Figure 1The number of first terminal devices, second terminal devices, third terminal devices, networks, and servers in the system is only a certain number. Depending on the implementation requirements, any number of first terminal devices, second terminal devices, third terminal devices, networks, and servers can be included.

[0033] The following will be based on Figure 1 The described scene, through Figures 2-6 The distributed event handling method is described in detail.

[0034] Figure 2 A flowchart of a distributed event processing method according to an embodiment of the present invention is shown.

[0035] like Figure 2 As shown, this embodiment includes operations S210 to S240.

[0036] During operation S210, an event processing request is received at the request receiving entry point of the distributed system. Based on the identifier representing the event type in the event processing request, the priority and mutually exclusive execution type corresponding to the event type are searched from the preset event registration library.

[0037] When operating S220, based on priority and the timestamp of the event processing request, the event object obtained after encapsulating the event processing request is inserted into the priority scheduling queue.

[0038] In operation S230, after retrieving the event object for execution from the priority scheduling queue, conflict detection is performed on the mutual exclusion execution type corresponding to the event type based on the global mapping table maintained in the distributed system. The global mapping table records different event types and their respective concurrent execution counts.

[0039] In operation S240, if no conflict is detected, the business processor corresponding to the event type is invoked to execute the event object, and the current execution count of the event type in the global mapping table is updated based on the execution status.

[0040] According to an embodiment of the present invention, at the request receiving entry point of the distributed system, event processing requests can be received by deploying a gateway or service access layer component. After the event processing request arrives, the identifier used to characterize the event type (such as event type enumeration value, specific string identifier, etc.) in the event processing request is parsed, and a preset event registry is accessed based on the identifier.

[0041] The pre-defined event registry can be implemented based on a distributed configuration center or persistent storage. It pre-stores the mapping relationship between each event type and its corresponding priority (e.g., level 1-10, with higher values ​​indicating higher priority) and mutual exclusion execution type (e.g., "complete mutual exclusion" and "resource-level mutual exclusion"). The priority and mutual exclusion execution type of the event type can be queried by matching the identifiers.

[0042] Simultaneously, the set of mutually exclusive event types corresponding to mutually exclusive execution types also needs to be pre-defined in the event registry, forming an association mapping with the event types. For example, the mutually exclusive execution types of the event type "order payment" may include "order refund" and "order cancellation," etc. These mutually exclusive execution types together constitute the set of mutually exclusive event types for this event type, which can be retrieved in batches from the pre-defined event registry by using the event type's identifier.

[0043] After obtaining the priority and the timestamp inherent in the event handling request, the event handling request is encapsulated into an event object containing information such as request parameters, event type, priority, timestamp, and mutual exclusion execution type. Subsequently, the event object is inserted into a priority scheduling queue, which can be an in-memory queue based on a min-heap data structure or a distributed message queue that supports priority sorting. During insertion, events are first sorted by priority; events with the same priority are then sorted by their timestamps from smallest to largest, ensuring that high-priority event objects and earlier-arriving event objects within the same priority category enter the priority scheduling queue first.

[0044] After retrieving the event objects to be executed from the priority scheduling queue, conflict detection needs to be performed based on a global mapping table maintained in the distributed system. This global mapping table can be implemented using key-value pairs, where the key is the event type and the corresponding value is the current concurrent execution count for that event type.

[0045] When performing conflict detection based on a global mapping table, it is necessary to extract the currently executing event types. By traversing all key-value pairs in the global mapping table, event types with a concurrent execution count greater than zero are filtered out and stored in a thread-safe hash set, forming the set of currently executing event types. This process requires setting a reasonable number of scans (e.g., scanning one hundred records at a time) and using a cursor to iterate through the entire table to ensure that no currently executing event type is missed.

[0046] Subsequently, the set of mutually exclusive event types obtained from the preset event registry is intersected with the set of event types currently being executed. Using the set retention method, event types common to both sets are preserved.

[0047] If the intersection result is an empty set, it means that there is no mutually exclusive event type among the currently executing event types, i.e., no conflict was detected. If the intersection result is a non-empty set (including at least one common event type), it means that there are mutually exclusive event types being executed, i.e., a conflict was detected.

[0048] To avoid the impact of momentary data inconsistencies on detection results in a distributed environment, the entire process can use a distributed lock to lock the read and write operations of the global mapping table. This ensures that the count of the global mapping table will not be modified by other nodes during the extraction of the event type being executed and the execution of the intersection operation, thereby guaranteeing the accuracy of conflict detection.

[0049] During detection, the previously obtained mutual exclusion execution type is used for judgment. If it is a "completely mutual exclusion" type, the concurrent execution count of this event type in the global mapping table is checked to see if it is greater than 0. If it is greater than 0, it is determined to be a conflict. If it is a "resource-level mutual exclusion" type, the resource identifier carried in the event object is further combined to check whether the execution count of this event type under the same resource identifier exceeds the limit, so as to determine whether a conflict exists.

[0050] If no conflict is detected, the business processor corresponding to the event type is invoked to execute the business logic in the event object. Before execution, the current execution count for this event type in the global mapping table is updated to ensure that the count reflects the concurrent execution status in real time. After the business processor completes execution (whether successfully or not), the count is decremented to ensure that the concurrent execution count in the global mapping table is consistent with the actual execution status, reducing the risk of inaccurate conflict detection in subsequent events due to counting errors.

[0051] By employing an event registration mechanism, priorities and mutually exclusive execution types are predefined for each event type, establishing a clear rule foundation for event processing. A priority scheduling queue is used to sort and manage event objects, ensuring that high-priority events are scheduled for execution first. A global mapping table between event types and concurrent execution counts is maintained to track the concurrent execution status in the distributed environment in real time, and conflict detection for mutually exclusive execution types is performed based on this global mapping table. This memory-based real-time status query mechanism effectively improves detection efficiency. If no conflict is detected, business processing logic is executed, and the current execution count of the event type is updated synchronously, thus forming a complete event processing loop. This mechanism effectively solves the event resource contention problem in high-concurrency scenarios, significantly improving event processing efficiency while ensuring the throughput and data consistency of the distributed system.

[0052] According to an embodiment of the present invention, the priority scheduling queue is implemented using a min-heap data structure. Based on the priority and the timestamp of the event processing request, the event object obtained after encapsulating the event processing request is inserted into the priority scheduling queue, including: inserting the event object as the target node at the end of the min-heap data structure; repeating the following operations until the target node reaches the top of the heap or the swap condition is not met, confirming the completion of the insertion of the event object into the priority scheduling queue: comparing the target node with its corresponding parent node in the min-heap data structure from bottom to top according to the priority and timestamp of the event object, wherein the event object corresponding to the parent node has its own priority and timestamp; if it is determined that the target node meets the swap condition, swapping the positions of the target node and its corresponding parent node.

[0053] When a priority scheduling queue is implemented using a min-heap data structure, the underlying layer of the heap can be an array as the storage container. Each element in the array corresponds to an event object and satisfies the structural characteristics of a min-heap. For a node with index i in the array, its left child node index is 2i+1, its right child node index is 2i+2, and its parent node index is (i-1) / 2 (integer division).

[0054] Figure 3 A schematic diagram of a priority scheduling queue for a distributed event processing method according to an embodiment of the present invention is shown.

[0055] like Figure 3 As shown, when the encapsulated event object needs to be inserted into the priority scheduling queue, the event object is first placed at the end of the array as the target node 301 (corresponding to node index 7), that is, at the last leaf node of the heap. At this time, the complete binary tree structure of the heap is maintained, but the order of the min-heap may be destroyed.

[0056] Next, a bottom-up heap adjustment (i.e., a float operation) needs to be performed on the target node 301 to restore the heap's order. Specifically, starting from the target node 301, the index of its corresponding parent node 302 (corresponding node index 3) in the array is obtained, and the event object corresponding to the parent node 302 is extracted. The priority and timestamp of the target node 301 and the parent node 302 are compared.

[0057] If the target node 301 has a higher priority than its parent node 302, the swap condition is met. If both have the same priority, their timestamps are compared. If the timestamp of the target node 301 is smaller (i.e., the event occurred earlier), the swap condition is also met. When the swap condition is met, the positions of the target node 301 and the parent node 302 in the array are swapped. At this time, the position of the target node 301 is moved up to the original position of the parent node 302.

[0058] Repeat the above comparison and swap operations, using the moved target node 301 as the current node, obtain its new parent node again, and re-compare the priority and timestamp to determine whether the swap condition is met and perform the corresponding swap. This process continues until the target node 301 moves to the top of the heap (i.e., the position with node index 0), or the swap condition is not met in a certain comparison. At this point, the order of the heap has been restored, and the insertion operation of the event object in the priority scheduling queue is completed.

[0059] By using a bottom-up heap sort algorithm, combined with a dual comparison rule of event priority and arrival timestamp, it ensures that high-priority event objects can be scheduled efficiently and accurately, while strictly adhering to the first-come-first-served fairness principle when priorities are the same.

[0060] According to an embodiment of the present invention, based on the priority and timestamp of the event object, the target node is compared with its corresponding parent node sequentially from bottom to top in the min-heap data structure, including: comparing the priority of the target node with the priority of the parent node to obtain a first comparison result; if the priority of the target node is determined to be higher than that of the parent node, the target node is determined to satisfy the swap condition; if the first comparison result indicates that the priorities are the same, the timestamp of the target node is compared with that of the parent node to obtain a second comparison result; if the second comparison result indicates that the timestamp of the target node is earlier than that of the parent node, the target node is determined to satisfy the swap condition.

[0061] Figure 4 A flowchart illustrating the queuing of event objects in a distributed event processing method according to an embodiment of the present invention is shown.

[0062] like Figure 4 As shown, this embodiment includes operations S401 to S407.

[0063] In operation S401, the event object is inserted as the target node into the min-heap data structure.

[0064] In operation S402, the priority of the target node is compared with the priority of the parent node.

[0065] In operation S403, determine whether the target node's priority is lower than that of the parent node. If yes, execute operation S407; otherwise, execute operation S404.

[0066] In operation S404, determine whether the priority of the target node is equal to that of the parent node. If yes, proceed to operation S405; otherwise, terminate.

[0067] In operation S405, the timestamp of the target node is compared with the timestamp of the parent node.

[0068] In operation S406, determine whether the timestamp of the target node is earlier than that of the parent node. If yes, proceed to operation S407; otherwise, end the process.

[0069] In operation S407, the target node is swapped with its corresponding parent node.

[0070] When comparing the target node and the parent node, the priority carried by each node is first extracted and directly compared at the numerical level to obtain the first comparison result. Assuming that the priority is represented by integers, and the larger the value, the higher the priority, then when the priority value of the target node is greater than the priority value of the parent node, it is determined that the priority of the target node is higher than that of the parent node, and at this time, it is directly determined that the target node meets the swap condition.

[0071] If the first comparison shows that the priority values ​​of the two nodes are equal, it means that the target node and the parent node have the same priority. In this case, it is necessary to further compare the timestamps to determine the order. Extract the timestamps of the target node and the parent node (usually millisecond or nanosecond timestamps, stored as integers) and compare their values ​​to obtain the second comparison result.

[0072] Since a smaller timestamp value indicates an earlier event, when the timestamp value of the target node is less than that of the parent node, it means that the timestamp of the target node is earlier than that of the parent node. In this case, it is determined that the target node meets the exchange condition.

[0073] By employing a two-tiered comparison mechanism based on priority and timestamp, precise sorting according to the arrival order of events is achieved during the min-heap insertion process when priorities are the same, thereby ensuring fairness while prioritizing high-priority tasks.

[0074] According to an embodiment of the present invention, retrieving an event object for execution from a priority scheduling queue includes: incrementing the current length of the priority scheduling queue by a counter when it is determined that an event object has been inserted into the priority scheduling queue; sending an activation signal to the scheduling module via an unbuffered synchronous ready notification channel in response to detecting a change in the value of the counter; and retrieving the event object for execution from the priority scheduling queue when it is determined that the scheduling module has received the activation signal.

[0075] After the event object is inserted into the priority scheduling queue, an increment operation is performed using a thread-safe counter to update the current length of the priority scheduling queue. This counter can be an atomic counter, and it must ensure the accuracy of the counting result in a multi-threaded concurrent insertion scenario to avoid length statistics distortion due to race conditions.

[0076] To ensure timely processing of event objects in the queue by the scheduling module, a buffered, synchronized ready notification channel is maintained in the distributed system. When the value of a counter changes due to an insertion operation, an activation signal is immediately sent to the scheduling module through this ready notification channel. Because the ready notification channel is unbuffered, the sending operation will block until the scheduling module successfully receives the signal, ensuring that the signal is not cached or lost, thus achieving strong synchronization between the insertion operation and the scheduling activation.

[0077] Under normal conditions, the scheduling module is in a blocked waiting state, continuously listening to the ready notification channel. Upon receiving an activation signal, the scheduling module wakes up from the blocked state and immediately performs the event object retrieval operation. At this time, the scheduling module acquires access to the priority scheduling queue through a locking mechanism and retrieves the highest priority event object from the top of the min-heap (i.e., the position with array index 0). Simultaneously, it performs a decrement operation on the counter to update the current length of the queue and triggers a heap sinking adjustment operation to maintain the structure of the min-heap, ensuring that subsequent retrieval operations can correctly retrieve the next highest priority event object.

[0078] By using a collaborative mechanism between a counter and an unbuffered synchronous ready notification channel, real-time perception and immediate scheduling of changes in the priority scheduling queue status are achieved, effectively eliminating polling overhead and ensuring low-latency processing of high-priority events.

[0079] According to an embodiment of the present invention, before performing conflict detection on the mutual exclusion execution type corresponding to the event type based on the global mapping table maintained in the distributed system, the method further includes: distributing the event object to the persistence module through a buffered asynchronous channel, and decrementing a counter after successful distribution; wherein, the persistence module is configured to perform the following operations: continuously listening to the buffered asynchronous channel through a worker thread in the thread pool of the distributed system to receive the event object; for the received event object, using the worker thread to obtain an idle connection from the database connection pool of the distributed system, so as to write the event object to the database through the idle connection.

[0080] Before performing conflict detection on the mutual exclusion execution type of the event type, the event objects must first be distributed to the persistence module through a buffered asynchronous channel. This asynchronous channel can be implemented based on an array blocking queue or a buffered channel. The buffer size is preset according to the concurrency of the distributed system (e.g., a capacity of 1000 elements) to balance the production speed of event objects with the persistence processing speed and avoid distribution blocking due to instantaneous high concurrency.

[0081] The dispatch operation is performed in a non-blocking manner. If the asynchronous channel buffer is not full, the event object is directly placed into the asynchronous channel and a dispatch success is returned. If the buffer is full, a preset degradation strategy (such as temporarily caching to the local disk) can be triggered to ensure that the event object is not lost.

[0082] After confirming that the event object has been successfully dispatched to the asynchronous channel, a decrement operation is performed through a counter to correct the current length statistics of the priority scheduling queue, ensuring that the value of the counter is consistent with the actual number of event objects to be executed in the priority scheduling queue.

[0083] The core logic of the persistence module is supported by a thread pool in the distributed system. The thread pool parameters (such as the number of core threads, the maximum number of threads, and the idle time) are dynamically configured based on the database write performance (for example, the number of core threads is set to twice the number of processor cores). After the worker threads in the thread pool start, they enter an infinite loop to listen to the asynchronous channel with a buffer. They continuously wait for event objects in the asynchronous channel using a blocking method. Once an event object is received, the subsequent persistence process is immediately triggered.

[0084] Before writing event objects to the database, the persistence module compresses them. Based on the event type, it dynamically selects a suitable compression algorithm from a pre-defined library. For example, a high compression ratio algorithm might be used for text events, while a faster algorithm is chosen for binary data events, thus achieving a balance between compression efficiency and processing performance.

[0085] During the database writing process, the persistence module employs a batch commit mechanism. When a certain number of event objects accumulate, or a preset time threshold is reached, these event objects are combined into a single transaction for batch commit, avoiding frequent single data write operations, reducing the number of database interactions, and lowering the overhead of transaction commits.

[0086] For the received event object, the worker thread obtains an idle connection from the database connection pool of the distributed system. The database connection pool avoids the performance overhead caused by frequently creating connections by pre-creating and maintaining a certain number of database connections (e.g., a minimum of 10 idle connections and a maximum of 50 connections).

[0087] After a worker thread acquires an idle connection, it writes the key information in the event object (such as event type, timestamp, request parameters, encapsulation time, priority, mutual exclusion execution type, etc.) into the database according to a preset table structure. During the writing process, a transaction is started to ensure atomicity. After the writing is successful, the transaction is committed and the connection is returned to the database connection pool.

[0088] After the event object is written to the database, the persistence module extracts the event object's metadata, including key information such as the event identifier, processing status, and timestamp, and updates this metadata in the distributed cache. This way, when other modules or business processes need to query event-related information, they can quickly retrieve it directly from the distributed cache without frequent database access, thus improving query response speed.

[0089] If a write operation fails, the transaction is rolled back and an error log is logged. A retry mechanism (e.g., up to 3 retries) is triggered to improve the persistence success rate. Through the collaborative design of a buffered asynchronous channel and a thread-pooled persistent storage mechanism, event scheduling and database writes are decoupled. This smooths out traffic spikes through buffering and ensures persistence efficiency and system reliability under high concurrency by reusing idle connections.

[0090] According to an embodiment of the present invention, after writing the event object to the database via an idle connection, the method further includes: obtaining the change log corresponding to the persisted event object through a database change monitoring mechanism, and adding it to a local memory linked list, wherein the change log includes the priority of the event object, the mutual exclusion execution type, and the business data required to execute the event object; polling the local memory linked list by an event execution controller deployed in the distributed system, and if the change log is found, performing a conflict detection operation on the mutual exclusion execution type corresponding to the event type based on the global mapping table maintained in the distributed system.

[0091] After writing the event object to the database via an idle connection, the corresponding data changes need to be captured using the database's change monitoring mechanism. Taking a relational database as an example, a component can be deployed as a change monitoring client to track the write operations of the event object table in real time by parsing the database's change log. When the event object is successfully written to the table, the component will capture the new event of that record, extract the priority, mutual exclusion execution type, and business data (such as request parameters, resource identifiers, etc.) fields, and encapsulate them into a structured change log.

[0092] Captured change logs need to be added to a local memory linked list. This local memory linked list is implemented using a thread-safe concurrent linked list queue, supporting concurrent writing and reading by multiple threads. After generating the change log, the listening thread inserts it at the end of the local memory linked list to avoid element loss or linked list structure corruption due to concurrent operations. Simultaneously, a maximum capacity threshold (e.g., 10,000 entries) is set for the local memory linked list. When the threshold is reached, an eviction policy is triggered (e.g., removing the oldest added log) to prevent memory overflow.

[0093] In a distributed system, an event execution controller (which can be implemented based on a standalone process or a scheduled task module within a service) is responsible for polling a local in-memory linked list. The controller creates a scheduled task to perform the polling operation at fixed intervals (e.g., every 50 milliseconds). Specifically, it calls the dequeue method of the linked list to attempt to retrieve the change log at the head of the list. If the retrieval is successful (i.e., a valid log is found), subsequent conflict detection is performed based on that change log.

[0094] Specifically, the controller parses information such as event type and mutual exclusion execution type from the change log, and then accesses the global mapping table maintained by the distributed system. Depending on the mutual exclusion execution type, it executes the corresponding conflict detection logic. If it is a fully mutual exclusion type, it checks whether the count of this event type in the global mapping table is 0. If it is a resource-level mutual exclusion type, it combines the resource identifier in the log to check whether the count of this event type under the same resource has exceeded the limit, thereby determining whether an execution conflict exists.

[0095] By efficiently coordinating database change monitoring with local memory linked lists, persistent event information is synchronized to memory in real time, enabling subsequent conflict detection to be completed directly based on log data at memory-level access speed, reducing the overhead of repeated database queries.

[0096] According to an embodiment of the present invention, in the absence of a conflict, invoking the business processor corresponding to the event type to execute the event object includes: in the absence of a conflict, obtaining a change log from a local memory linked list and extracting the business data required to execute the event object from the change log; and submitting the business data to the business processor corresponding to the event type to execute the corresponding business processing logic.

[0097] If no conflict is detected, the event execution controller retrieves the corresponding change log from the local memory linked list. The local memory linked list is implemented using a thread-safe concurrent linked list queue. The controller atomically retrieves the change log from the head of the local memory linked list using a dequeue method, thus avoiding resource contention during multi-threaded concurrent operations. After retrieving the change log, its completeness is first verified (e.g., checking for required fields such as event type and business data). If any fields are missing, the log is marked as an exception and moved to the error queue; otherwise, further processing continues.

[0098] When extracting the business data required for the execution event object from the change log, the log content needs to be parsed according to a predefined data structure. For example, if the change log uses an object abbreviation format, the business data fields can be extracted using a parsing tool. These fields may contain specific business information such as user ID, order information, and operation parameters. During the extraction process, type conversion is also required (e.g., converting strings to integers or date objects) to ensure that the data format conforms to the input requirements of the business processor.

[0099] After extracting business data, it needs to be submitted to the business processor corresponding to the event type. The distributed system manages the mapping relationship between various event types and business processors through a business processor factory. The business processor factory maintains a local cache with the event type as the key and the business processor instance as the value, so that the corresponding business processor can be quickly located by event type.

[0100] The business processor supports dual concurrency dimensions when executing event objects. At the event level, parallel processing across events is achieved through a multi-process mechanism, significantly improving system throughput. Within a single event, three collaboration strategies are supported: serial execution is suitable for scenarios with strong dependencies between modules (e.g., the output of module A is the input of module B), and a strict sequential triggering mechanism (A→B→C), where subsequent modules are only dispatched after the preceding module has completed.

[0101] Parallel execution is suitable for scenarios where there are no dependencies between modules or eventual consistency is allowed (such as log recording and data updates). The event dispatch module simultaneously delivers events to all related modules (A, B, and C are processed in parallel).

[0102] Hybrid execution is suitable for scenarios where some modules need to be triggered serially while others can be executed in parallel (e.g., authentication before multi-branch processing). The critical path (e.g., A) is executed serially first, and subsequent modules (B and C in parallel) are triggered concurrently upon completion. Through the flexible combination of these three strategies, the process orchestration needs of different business scenarios can be met.

[0103] When submitting a task, if the business processor is a stateless instance, its processing method is directly invoked along with the business data. If it is a stateful instance, the task is submitted through a thread pool, which allocates worker threads to execute the processing logic, thus avoiding blocking the controller's polling process due to the business processor's long execution time. During execution, the business processor performs specific business operations (such as order creation, data updates, etc.) based on the business data and returns the processing results for subsequent state updates.

[0104] By directly retrieving business data from the local memory linked list and submitting it to the business processor, the business logic is executed quickly, effectively reducing the read and write overhead caused by repeated database queries, thereby ensuring the system's processing performance in high-concurrency scenarios.

[0105] According to an embodiment of the present invention, the method further includes: if a conflict is detected, re-inserting the event object into the priority scheduling queue based on the priority and timestamp of the event object; after retrieving the event object for execution from the priority scheduling queue again, performing a conflict detection operation on the mutual exclusion execution type corresponding to the event type based on a global mapping table maintained in the distributed system.

[0106] Figure 5 A flowchart of a distributed event processing method according to another embodiment of the present invention is shown.

[0107] like Figure 5 As shown, this embodiment includes operations S501 to S509.

[0108] In operation S501, the priority and mutually exclusive execution type corresponding to the event type are searched from the preset event registry.

[0109] In operation S502, the event object is inserted into the priority scheduling queue based on the event object's priority and timestamp.

[0110] When operating S503, event objects are extracted from the priority scheduling queue for persistent storage.

[0111] When operating S504, the change log of the event object is written to the local memory linked list.

[0112] When operating S505, conflict detection is performed on the mutual exclusion execution type corresponding to the event type based on the global mapping table.

[0113] In step S506, determine if a conflict exists. If so, proceed to step S507; otherwise, proceed to step S508.

[0114] In operation S507, the event object is reinserted into the priority scheduling queue based on its priority and timestamp.

[0115] When operating S508, the business processor corresponding to the event type is invoked to execute the event object.

[0116] In operation S509, update the current execution count of the event type in the global mapping table.

[0117] Upon detecting a conflict, the event object's priority and original timestamp are extracted from the event object or its corresponding change log to ensure that the original priority and time order are maintained during re-insertion. Then, the event object is re-inserted into the priority scheduling queue following the same logic as the initial insertion. The event object is placed at the end of the min-heap as the target node, and the heap structure is adjusted through bottom-up comparison and swap operations (first comparing priorities, then comparing timestamps if priorities are the same) to move the target node to a position that conforms to the min-heap's order, thus completing the re-insertion.

[0118] After the re-insertion operation is completed, the current length of the priority scheduling queue is incremented using a counter to reflect the change in the number of pending event objects in the queue. Simultaneously, an activation signal is sent to the scheduling module via an unbuffered synchronous ready notification channel to ensure that the scheduling module promptly detects changes in the queue status.

[0119] Once the scheduling module receives the activation signal and retrieves the event object again from the priority scheduling queue, it repeats the conflict detection process. Based on the global mapping table maintained by the distributed system, and combined with the mutual exclusion execution type corresponding to the event type, it checks whether the current concurrent execution count conforms to the mutual exclusion rules (e.g., a count of 0 is required for a completely mutual exclusion type, and the count under a specific resource identifier must not exceed the limit for a resource-level mutual exclusion type).

[0120] If a conflict still exists, the re-insertion logic is triggered again. If the conflict is resolved, the subsequent business processor call proceeds. Throughout the process, a locking mechanism (such as a distributed lock) ensures the atomicity of accessing the global mapping table, preventing counting errors in concurrent scenarios from affecting the conflict detection results.

[0121] By using a retry mechanism for conflict events, conflict events are re-queued and rescheduled while maintaining their original priority and timestamp, which reduces resource deadlock and ensures system throughput and fairness.

[0122] Figure 6 A flowchart of a distributed event processing method according to another embodiment of the present invention is shown.

[0123] In another embodiment, for end-to-end optimization of event priority scheduling, such as... Figure 6 As shown, it receives event processing requests from external or internal sources, and then performs an integrity check to verify whether necessary fields (such as event identifier, initiator information, core business data, etc.) are complete, and verifies whether the format of each field conforms to the preset specifications to ensure that there is no missing data or format errors.

[0124] After the integrity check is completed, the business compliance verification stage begins. Based on the preset business rules and compliance requirements, the operation permissions and business data of the event initiator are reviewed to ensure they meet industry regulations and internal constraints, preventing unauthorized or illegal operations.

[0125] After successful verification, valid information is extracted and encapsulated into standardized event objects. Then, the "event object push" operation is performed, inserting the event object into a priority scheduling queue based on a min-heap. In the priority scheduling queue, event objects are sorted by priority, with higher-priority objects near the top of the heap, and objects of the same priority arranged in ascending order of timestamps, achieving efficient and orderly scheduling.

[0126] Upon receiving the activation signal, the event distribution relay retrieves the event object to be processed from the heap and distributes it to the persistence module via the ready channel 610. The persistence module internally has multiple worker threads that concurrently receive event objects via the distribution channel 620 and ultimately persist them to the database, completing the end-to-end processing.

[0127] This embodiment, through integrity checks, compliance verification, and standardized encapsulation, combined with priority heap sorting and multi-threaded persistence mechanisms, significantly improves the efficiency of event scheduling and system throughput while ensuring business compliance and data consistency. It is suitable for high-concurrency, multi-priority distributed event processing scenarios.

[0128] According to an embodiment of the present invention, updating the current execution count of an event type in a global mapping table based on the execution status includes: incrementing the current execution count of the event type in the global mapping table when a business processor is invoked to execute an event object; and decrementing the current execution count of the event type in the global mapping table when it is determined that the business processor has completed the execution of the event object, wherein completing the execution of the event object includes successful execution or execution termination.

[0129] During the execution of an event object by invoking a business processor, the current execution count of that event type in the global mapping table needs to be incremented. The global mapping table is typically implemented using a hash data structure based on a remote dictionary service, where the key is the event type identifier and the corresponding value is the count of currently concurrent executions.

[0130] At this point, the increment command from the remote dictionary service performs an atomic increment on the count corresponding to this event type, ensuring accurate counting results in a distributed, multi-node concurrent execution scenario. Even if multiple nodes simultaneously increment the same event type, the single-threaded execution characteristic of the increment command can prevent counting distortion.

[0131] Once it is determined that the business processor has completed the execution of the event object (including all execution completion scenarios such as normal successful execution, termination due to business exception, or interruption due to system failure), the count in the global mapping table needs to be decremented.

[0132] To ensure the reliability of the decrement operation, an attempt-final block is wrapped around the execution logic of the business processor. Regardless of whether an exception occurs during execution, the final block will atomically decrement the count of the event type using the decrement command from the remote dictionary service.

[0133] This mechanism ensures that the execution count reflects the actual concurrent execution status in real time, preventing the count from remaining too high due to execution interruptions, which could affect the accuracy of conflict detection for subsequent events. After the decrement operation is completed, the count in the global mapping table will be restored to the current actual concurrent execution count for that event type, providing a reliable basis for the next conflict detection.

[0134] Maintaining the real-time accuracy of the event type execution counter through atomic increment and decrement operations provides a reliable state basis for concurrent conflict detection.

[0135] Based on the above-described distributed event processing method, this invention also provides a distributed event processing device. The following will be combined with... Figure 7 The device is described in detail.

[0136] Figure 7 A structural block diagram of a distributed event processing apparatus according to an embodiment of the present invention is shown.

[0137] like Figure 7 As shown, the distributed event processing device 700 of this embodiment includes an information lookup module 710, an event insertion module 720, a conflict detection module 730, and an event execution module 740.

[0138] The information lookup module 710 is used to receive an event processing request at the request receiving entry point of the distributed system, and, based on the identifier representing the event type in the event processing request, search for the priority and mutually exclusive execution type corresponding to the event type from a preset event registration database. In one embodiment, the information lookup module 710 can be used to perform the operation S210 described above, which will not be repeated here.

[0139] The event insertion module 720 is used to insert the event object obtained by encapsulating the event processing request into the priority scheduling queue based on the priority and the timestamp of the event processing request. In one embodiment, the event insertion module 720 can be used to perform the operation S220 described above, which will not be repeated here.

[0140] The conflict detection module 730, after retrieving the event objects for execution from the priority scheduling queue, performs conflict detection on the mutually exclusive execution types corresponding to the event types based on the global mapping table maintained in the distributed system. The global mapping table records different event types and their respective concurrent execution counts. In one embodiment, the conflict detection module 730 can be used to perform the operation S230 described above, which will not be repeated here.

[0141] The event execution module 740 is used to invoke the business processor corresponding to the event type to execute the event object when no conflict is detected, and to update the current execution count of the event type in the global mapping table based on the execution status. In one embodiment, the event execution module 740 can be used to execute the operation S240 described above, which will not be repeated here.

[0142] According to embodiments of the present invention, any plurality of modules among the information lookup module 710, event insertion module 720, conflict detection module 730, and event execution module 740 may be combined into one module, or any one of these modules may be split into multiple modules. Alternatively, at least a portion of the functionality of one or more of these modules may be combined with at least a portion of the functionality of other modules and implemented in one module. According to embodiments of the present invention, at least one of the information lookup module 710, event insertion module 720, conflict detection module 730, and event execution module 740 may be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or any other reasonable means of integrating or packaging circuitry, or implemented in software, hardware, or firmware, or in any one of the three implementation methods, or in a suitable combination of any of them. Alternatively, at least one of the information retrieval module 710, event insertion module 720, conflict detection module 730, and event execution module 740 may be implemented at least partially as a computer program module, which can perform corresponding functions when the computer program module is run.

[0143] Figure 8 A block diagram of an electronic device suitable for implementing a distributed event processing method according to an embodiment of the present invention is shown.

[0144] like Figure 8 As shown, an electronic device 800 according to an embodiment of the present invention includes a processor 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage portion 808 into a random access memory (RAM) 803. The processor 801 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 801 may also include onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.

[0145] RAM 803 stores various programs and data required for the operation of electronic device 800. Processor 801, ROM 802, and RAM 803 are interconnected via bus 804. Processor 801 executes various operations of the method flow according to embodiments of the present invention by executing programs in ROM 802 and / or RAM 803. It should be noted that programs may also be stored in one or more memories other than ROM 802 and RAM 803. Processor 801 may also execute various operations of the method flow according to embodiments of the present invention by executing programs stored in one or more memories.

[0146] According to an embodiment of the present invention, the electronic device 800 may further include an input / output (I / O) interface 805, which is also connected to a bus 804. The electronic device 800 may also include one or more of the following components connected to the input / output (I / O) interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the input / output (I / O) interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 810 as needed so that computer programs read from it can be installed into the storage section 808 as needed.

[0147] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of the present invention.

[0148] According to embodiments of the present invention, a computer-readable storage medium may be a non-volatile computer-readable storage medium, such as including, but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of the present invention, a computer-readable storage medium may include ROM 802 and / or RAM 803 and / or one or more memories other than ROM 802 and RAM 803 described above.

[0149] Embodiments of the present invention also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to enable the computer system to implement the distributed event processing method provided in the embodiments of the present invention.

[0150] When the computer program is executed by the processor 801, it performs the functions defined in the system / apparatus of this invention. According to embodiments of the invention, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0151] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 809, and / or installed from a removable medium 811. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.

[0152] In such an embodiment, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by processor 801, it performs the functions defined in the system of this embodiment of the invention. According to embodiments of the invention, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.

[0153] According to embodiments of the present invention, program code for executing the computer programs provided in the embodiments of the present invention can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, languages ​​such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0154] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0155] Those skilled in the art will understand that the features described in the various embodiments of the present invention can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, the features described in the various embodiments of the present invention can be combined and / or combined in various ways without departing from the spirit and teachings of the present invention. All such combinations and / or combinations fall within the scope of the present invention.

[0156] The embodiments of the present invention have been described above. However, these embodiments are merely illustrative and not intended to limit the scope of the invention. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Various substitutions and modifications can be made by those skilled in the art without departing from the scope of the invention, and all such substitutions and modifications should fall within the scope of the invention.

Claims

1. A method of distributed event processing, characterized by, The method comprises: An event processing request is received at a request receiving interface of a distributed system, and a priority and a mutual exclusion execution type corresponding to an event type are found from a preset event registration library according to an identifier representing the event type in the event processing request; An event object obtained after encapsulation of the event processing request is inserted into a priority scheduling queue based on the priority and a timestamp of the event processing request; After the event object for execution is extracted from the priority scheduling queue, a mutual exclusion execution type corresponding to the event type is subjected to conflict detection based on a global mapping table maintained in the distributed system, wherein different event types and respective concurrent execution counts corresponding to the different event types are recorded in the global mapping table; The conflict detection comprises: if the mutual exclusion execution type is a complete mutual exclusion type, checking whether the concurrent execution count of the event type in the global mapping table is greater than 0, and if greater than 0, determining that there is a conflict; if the mutual exclusion execution type is a resource-level mutual exclusion type, checking whether the execution count of the event type under the same resource identifier is over limit in combination with a resource identifier carried in the event object, to determine whether there is a conflict; In the case where no conflict is detected, a business processor corresponding to the event type is called to execute the event object, and a current execution count of the event type in the global mapping table is updated based on an execution state.

2. The method of claim 1, wherein, The priority scheduling queue is implemented by a minimum heap data structure; and the event object obtained after encapsulation of the event processing request is inserted into the priority scheduling queue based on the priority and the timestamp of the event processing request, which comprises: The event object is inserted as a target node into a tail position of the minimum heap data structure; The following operations are repeatedly performed until the target node reaches a top of the heap or a swap condition is not met, to confirm completion of the insertion of the event object into the priority scheduling queue: The target node is compared with a corresponding parent node in the minimum heap data structure from bottom to top in sequence according to the priority and the timestamp of the event object, wherein the event object corresponding to the parent node has its own priority and timestamp; In a case where it is determined that the target node meets the swap condition, the target node and the corresponding parent node are swapped.

3. The method of claim 2, wherein, The comparison of the target node with the corresponding parent node in the minimum heap data structure from bottom to top according to the priority and the timestamp of the event object comprises: The priority of the target node is compared with the priority of the parent node to obtain a first comparison result; In a case where it is determined that the priority of the target node is higher than that of the parent node, it is determined that the target node meets the swap condition; In a case where the first comparison result indicates that the priorities are the same, the timestamp of the target node is compared with the timestamp of the parent node to obtain a second comparison result; In a case where the second comparison result indicates that the timestamp of the target node is earlier than that of the parent node, it is determined that the target node meets the swap condition.

4. The method of claim 1, wherein, The extracting the event object for execution from the priority scheduling queue comprises: in the case of determining that the event object is inserted into the priority scheduling queue, incrementing a current length of the priority scheduling queue by a counter; in response to detecting that the value of the counter changes, sending an activation signal to a scheduling module through a ready notification channel of a non-buffered synchronization; in the case of determining that the scheduling module receives the activation signal, extracting the event object for execution from the priority scheduling queue.

5. The method of claim 4, wherein, Before the conflict detection on the mutual exclusive execution type corresponding to the event type based on the global mapping table maintained in the distributed system, further comprising: distributing the event object to a persistence module through an asynchronous channel with a buffer, and decrementing the counter after successful distribution; wherein the persistence module is configured to perform the following operations: continuously listening to the asynchronous channel with a buffer by a worker thread in a thread pool of the distributed system to receive the event object; for the received event object, obtaining an idle connection from a database connection pool of the distributed system by the worker thread to write the event object into the database through the idle connection.

6. The method of claim 5, wherein, After the event object is written into the database through the idle connection, further comprising: obtaining a change log corresponding to the event object persisted through a change listening mechanism of the database, and adding to a local memory linked list, wherein the change log comprises a priority of the event object, a mutual exclusive execution type, and business data required for executing the event object; polling the local memory linked list by an event execution controller deployed in the distributed system, and in the case of polling the change log, performing the operation of the conflict detection on the mutual exclusive execution type corresponding to the event type based on the global mapping table maintained in the distributed system based on the change log.

7. The method of claim 6, wherein, The calling a business processor corresponding to the event type to execute the event object in the case of not detecting a conflict comprises: in the case of not detecting a conflict, obtaining the change log from the local memory linked list, and extracting the business data required for executing the event object from the change log; submitting the business data to the business processor corresponding to the event type to execute corresponding business processing logic.

8. The method of claim 1, wherein, The method further comprises: in the case of detecting a conflict, re-inserting the event object into the priority scheduling queue based on a priority and a timestamp of the event object; after the event object for execution is extracted from the priority scheduling queue again, performing the operation of the conflict detection on the mutual exclusive execution type corresponding to the event type based on the global mapping table maintained in the distributed system.

9. The method of claim 1, wherein, The updating the current execution count of the event type in the global mapping table based on the execution state comprises: in the case of calling the business processor to execute the event object, incrementing the current execution count of the event type in the global mapping table; decrementing a current execution count for the event type in the global map table upon determining that the business processor completes execution of the event object, wherein the completing execution of the event object comprises either a successful execution or a terminated execution. 10.An electronic device comprising: one or more processors; memory storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method of any one of claims 1-9.

Citation Information

Patent Citations

  • Grid governance event management method and system based on event circulation mechanism and medium

    CN119718689A

  • Front-end task scheduling and event processing method and device, equipment and storage medium

    CN120045298A