A method, device and equipment for synchronizing distributed cache in session process

By processing business requests of target sessions in the process cache and synchronizing the results to the distributed session cache, the problem that the prior art is difficult to adapt to high localization processing and high distributed cache pressure is solved, and the performance and reliability of the system are improved.

CN114443761BActive Publication Date: 2025-02-11CHINA TELECOM CLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111615115.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2025-02-11
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

The prior art is difficult to apply to scenarios where localization processing requirements are high and distributed cache pressure overload is required.

Method used

By acquiring the service request and distributed lock of the target session, it is determined whether the target session exists in the process cache. If it exists, data processing is performed and the processing results are synchronized into the distributed session cache to continuously renew the distributed lock.

Benefits of technology

It realizes that in scenarios where localization processing requirements and distributed cache pressure are high, the access pressure of distributed cache is appropriately alleviated and system performance is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443761B_ABST
    Figure CN114443761B_ABST
Patent Text Reader

Abstract

The present invention provides a method, device and equipment for synchronizing a distributed cache during a session, the method comprising: obtaining a business request and a distributed lock of a target session; judging whether the target session exists in a process cache based on the business request and the distributed lock; if the target session exists in the process cache, performing data processing on the target session based on the business request to obtain a data processing result, and synchronously storing key updates of the target session in a distributed session cache based on the data processing result, and continuously renewing its distributed lock. The present invention processes the business request of the target session in the process cache and stores the processed target session in the distributed cache, so that it can be applied to scenarios with high requirements for localized processing and overloaded distributed cache pressure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information processing technology, and in particular to a method, device and equipment for synchronizing distributed cache in a session process. Background Art

[0002] With the development of the Internet, the user scale and data scale are getting larger and larger, which puts higher requirements on the performance of the system. Cache is one of the key components. Distributed cache, as a kind of cache, is increasingly widely used due to its better performance.

[0003] Under the pressure of query per second (QPS), service-oriented frameworks often use distributed cache to save and update long session contexts to maximize the local processing of sessions and reduce the access pressure of distributed cache. However, existing distributed cache methods are difficult to apply to scenarios with high local processing requirements and distributed cache overload. Summary of the invention

[0004] Therefore, the technical problem to be solved by the present invention is to overcome the defect that the prior art is difficult to apply to scenarios with high local processing requirements and distributed cache pressure overload, thereby providing a session process distributed cache synchronization method, device and equipment.

[0005] According to the first aspect, an embodiment of the present invention provides a method for synchronizing a distributed cache during a session, comprising the following steps: obtaining a business request and a distributed lock of a target session; judging whether the target session exists in a process cache based on the business request and the distributed lock; if the target session exists in the process cache, performing data processing on the target session based on the business request to obtain a data processing result; synchronizing key updates of the target session to the distributed session cache based on the data processing result, and continuously renewing its distributed lock. .

[0006] Optionally, the session process distributed cache synchronization method further includes: the validity period of the distributed lock is determined based on the interval time of the update request of the target session.

[0007] Optionally, performing data processing on the target session based on the business request to obtain a data processing result includes: performing business processing on the target session based on the business request to obtain a business processing result; updating the target session based on the business processing result to obtain a new target session; obtaining key updates based on the new target session, and synchronously updating the distributed session cache based on the key updates to obtain the data processing result.

[0008] Optionally, synchronously storing the target session in a distributed session cache includes: synchronously storing the new target session in an updated distributed session cache.

[0009] Optionally, the determining whether the target session exists in the process cache based on the business request and the distributed lock further includes: if the target session does not exist in the process cache, determining whether there is a new distributed lock based on the target session; if there is a new distributed lock, acquiring the new distributed lock, and updating the process cache based on the new distributed lock to obtain a new process cache; performing data processing based on the new process cache to obtain a second data processing result.

[0010] Optionally, judging whether there is a new distributed lock based on the target session further includes: sending a session switching signal if there is no new distributed lock; and storing the target session in a delayed processing queue based on the session switching signal.

[0011] Optionally, the session process distributed cache synchronization method further includes: obtaining a session switching notification based on the distributed lock; switching to another target session based on the session switching notification, and releasing the distributed lock.

[0012] According to the second aspect, an embodiment of the present invention provides a session process distributed cache synchronization device, including: an acquisition module, used to acquire a business request and a distributed lock of a target session; a judgment module, used to judge whether the target session exists in the process cache based on the business request and the distributed lock; a data processing module, used to perform data processing on the target session based on the business request if the target session exists in the process cache, and obtain a data processing result; a storage module, used to synchronize the key update of the target session to the distributed session cache based on the data processing result, and continuously renew its distributed lock. .

[0013] According to a third aspect, an embodiment of the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the method described in the first aspect or any optional embodiment by executing the computer instructions.

[0014] According to a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method described in the first aspect or any optional implementation manner.

[0015] The technical solution of the present invention has the following advantages:

[0016] The embodiments of the present invention provide a method, device and equipment for synchronizing a distributed cache during a session. The method includes the following steps: obtaining a business request of a target session and a corresponding distributed lock, determining whether the target session exists in a process cache based on the distributed lock and the business request, and if the target session exists in the process cache, performing data processing on the target session based on the business request to obtain a data processing result, synchronizing key updates of the target session to the distributed session cache based on the data processing result, and continuously renewing its distributed lock. The present invention processes the business request of the target session in the process cache and stores the processed target session in the distributed cache, so that it can be applied to scenarios with high requirements for localized processing and overloaded distributed cache pressure. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 A schematic diagram of the session storage system architecture in the distributed cache synchronization method for the session process according to an embodiment of the present invention;

[0019] Figure 2 A specific example flow chart of a method for synchronizing a distributed cache during a session according to an embodiment of the present invention;

[0020] Figure 3 It is another specific example flow chart of the distributed cache synchronization method during the session process according to an embodiment of the present invention;

[0021] Figure 4 This is a schematic diagram of the structure of a distributed cache synchronization device for a session process according to an embodiment of the present invention;

[0022] Figure 5 It is a structural diagram of a distributed cache synchronization device in a session process according to an embodiment of the present invention. DETAILED DESCRIPTION

[0023] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0024] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0025] The embodiment of the present invention processes the business request of the target session in the process cache, and stores the processed target session in the distributed cache. In the following embodiments, the target session takes the system architecture where the long session is located as an example. The service node establishes a communication connection with the gateway, and sends the business request of the long session sent by the gateway to the same business node through a consistent hashing operation. The gateway establishes connections with multiple service nodes, and can switch to another long session after processing one long session, and then store the long session in the distributed session cache (Cache). At the same time, the distributed lock of the corresponding long session is obtained in each service node, and the distributed lock is stored in the remote dictionary service (Redis). If the service node receives a notification sent by the message queue MQ, the corresponding process of the notification is executed. The system architecture is as follows Figure 1 As shown, the present invention is not limited thereto.

[0026] The embodiment of the present invention provides a method for synchronizing a distributed cache during a session. Figure 2 As shown, the method comprises the following steps:

[0027] S100: Obtain the service request and distributed lock of the target session.

[0028] Specifically, the service node for processing the target session establishes a connection with the service gateway, obtains the target session from the service gateway, extracts the service request of the target session and the corresponding distributed lock, and sends the service request of the target session to the same service node using a consistent hashing algorithm. In actual applications, the target session may be a long session containing multiple service requests.

[0029] S200: Determine whether the target session exists in the process cache based on the service request and the distributed lock.

[0030] Specifically, it is determined whether the target session exists in the in-process cache through the business request and the distributed lock. The in-process cache is to cache some data in the process of the site or service, and the implementation carrier of the in-process cache can be, for example, a locked Map or a third-party library.

[0031] S300: If the target session exists in the process cache, data processing is performed on the target session based on the service request to obtain a data processing result.

[0032] Specifically, the in-process cache is used as a secondary cache of the distributed cache. The target session is stored in the in-process cache. The service request of the target session is processed in the in-process cache to reduce the access pressure of the distributed cache. Therefore, it is necessary to determine whether the target session is in the in-process cache. If the target session exists in the in-process cache, the target session is processed based on the service request to obtain a new target session.

[0033] S400: Synchronize the key updates of the target session into the distributed session cache based on the data processing result, and continue to renew its distributed lock.

[0034] Specifically, based on the data processing result, the key update of the target session is obtained, and the key update is synchronized to the distributed session cache, and the service node automatically renews its distributed lock.

[0035] In an embodiment of the present invention, based on the acquired service request and distributed lock of the target session, it is determined whether the target session exists in the process cache. If the target session exists in the process cache, data processing is performed on the target session based on the service request to obtain a data processing result, and a key update of the target session is obtained based on the data processing result, and the key update is synchronized to the distributed session cache, and its distributed lock is automatically renewed. By caching the service request of the target session synchronously in the same distributed session cache, it can be applied to scenarios with high requirements for localized processing and overloaded distributed cache pressure.

[0036] In an optional embodiment of the present invention, the validity period of the distributed lock involved in the session process distributed cache synchronization method is determined based on the interval time of the update request of the target session.

[0037] In this embodiment, the effective time of the distributed lock is set based on the update request time interval of the target session. In practical applications, the effective time of the distributed lock can be set to, for example, 5 times the target session update request time interval, and the distributed lock of the corresponding session can be automatically renewed after the effective time expires until the target session ends or a session switching notification is received. By setting the effective time of the distributed lock, the validity of the corresponding target session can be effectively guaranteed, and the confidentiality of the session can be increased.

[0038] In an optional embodiment of the present invention, the above step S300 processes data on the target session based on the service request to obtain a data processing result, such as Figure 3 As shown, the following steps are included:

[0039] S301: Performing service processing on the target session based on the service request to obtain a service processing result;

[0040] S302: updating the target session based on the business processing result to obtain a new target session;

[0041] S303: Acquire key updates based on the new target session, and synchronously update the distributed session cache based on the key updates to obtain the data processing result.

[0042] Specifically, an in-process session lock critical section is preset, and business processing is performed in the in-process session lock critical section based on the business request of the target session to obtain a business processing result, and a key update is obtained based on the business processing result. The key update is a session sensitive field that needs to ensure distributed consistency, and then the target session is synchronously updated to a processed new target session based on the key update. The target session is stored in a distributed session cache to obtain the data processing result.

[0043] In this embodiment, by performing corresponding business processing on the business request of the target session, a new target session is obtained, and the corresponding stored distributed session cache is updated, thereby reducing the access pressure of the distributed cache and improving system performance.

[0044] In an optional embodiment of the present invention, synchronously storing the target session in a distributed session cache includes:

[0045] (1) Synchronously storing the new target session in the updated distributed session cache.

[0046] In the embodiment of the present invention, the distributed session cache of the target session is synchronously updated through the new target session, and the new target session is synchronously stored in the updated distributed session cache, so that the distributed session cache can be synchronously updated to improve the localized processing of the service.

[0047] In an optional embodiment of the present invention, the determination of whether the target session exists in the process cache based on the service request and the distributed lock is as follows: Figure 2 As shown, the following steps are also included:

[0048] S201: If the target session does not exist in the process cache, determine whether there is a new distributed lock based on the target session;

[0049] S202: If there is a new distributed lock, the new distributed lock is acquired, and the process cache is updated based on the new distributed lock to obtain a new process cache;

[0050] S203: Perform data processing based on the new process cache to obtain a second data processing result.

[0051] Specifically, if the target session does not exist in the in-process cache, a new distributed lock is obtained based on the target session; if there is a new distributed lock, the new distributed lock is extracted, and the corresponding in-process cache is updated based on the new distributed lock to obtain a new in-process cache; data processing is performed based on the new in-process cache, and corresponding business processing is performed on the business request of the target session to obtain a second data processing result.

[0052] In an embodiment of the present invention, if the target session does not exist in the in-process cache, it is determined whether the target session has a new session lock. If so, the distributed lock is re-extracted and data processing is performed, so that the session process can continue and the local processing capability of the business is improved.

[0053] In an optional embodiment of the present invention, the determination of whether there is a new distributed lock based on the target session is as follows: Figure 2 As shown, the following steps are also included:

[0054] S2011: If there is no new distributed lock, a session switching signal is sent;

[0055] S2012: Storing the target session in a delay processing queue based on the session switching signal.

[0056] Specifically, if the target session cannot extract a new distributed lock, a session switching signal is sent to the service node, the processing process is sent to another session, and based on the session switching signal, the target session is stored in a delayed processing queue and processing of the target session is suspended.

[0057] In an embodiment of the present invention, by determining whether the target session has a new session lock, if no new distributed lock exists, a session switching signal is sent, and the target session is stored in a delayed processing queue, so that the distributed cache can continue to operate, thereby improving the local processing capability of the business.

[0058] In an optional embodiment of the present invention, the session process distributed cache synchronization further includes the following steps:

[0059] (1) obtaining a session switching notification based on the distributed lock;

[0060] (2) Switch to another target session based on the session switching notification and release the distributed lock.

[0061] Specifically, during the process of storing the target session in the distributed cache, a session switching notification is received based on the distributed lock, and the target session is switched to another target session based on the session switching notification, and the distributed lock of the target session is released. In practical applications, during the process of storing the target session in the distributed cache, there are two triggering conditions for the session switching notification. One is that when an operation and maintenance operation occurs, the service node automatically releases the distributed lock of the session held by the target session in batches after sensing it, so as to adapt to the situation where the session is routed to other service nodes. The other is that when other service nodes receive the target session update service request for the first time, they first query the distributed cache to obtain the service node where the target session originally resides, send the session switching notification to it, and then store the service request of the current target session in the delay processing queue for processing; after the service node of the original target session receives the session switching notification, it releases the distributed lock of the session; in the delay processing logic of the new service node where the other target session is stored, it retries and obtains the distributed lock of the other target session, and then automatically renews the distributed lock at the new service node, and processes subsequent service requests until the condition for releasing the distributed lock of the session is met.

[0062] The embodiment of the present invention provides a session process distributed cache synchronization device, such as Figure 4 As shown, the device includes an acquisition module 1, a judgment module 2, a data processing module 3, and a storage module 4, wherein:

[0063] Acquisition module 1, used to acquire the service request and distributed lock of the target session, for details, please refer to the relevant description of step S100 of any of the above method embodiments;

[0064] A determination module 2 is used to determine whether the target session exists in the process cache based on the service request and the distributed lock. For details, please refer to the relevant description of step S200 of any of the above method embodiments;

[0065] A data processing module 3 is used for performing data processing on the target session based on the service request to obtain a data processing result if the target session exists in the process cache. For details, please refer to the relevant description of step S300 of any of the above method embodiments;

[0066] Storage module 4 is used to synchronize the key updates of the target session to the distributed session cache based on the data processing result, and continuously renew its distributed lock. For details, please refer to the relevant description of step S400 of any of the above method embodiments.

[0067] In an embodiment of the present invention, based on the acquired service request and distributed lock of the target session, it is determined whether the target session exists in the process cache. If the target session exists in the process cache, data processing is performed on the target session based on the service request to obtain a data processing result, and a key update of the target session is obtained based on the data processing result, and the key update is synchronized to the distributed session cache, and its distributed lock is automatically renewed. By caching the service request of the target session synchronously in the same distributed session cache, it can be applied to scenarios with high requirements for localized processing and overloaded distributed cache pressure.

[0068] For the specific limitations and beneficial effects of the distributed cache synchronization device for the session process, please refer to the limitations of the distributed cache synchronization method for the session process above, which will not be repeated here. The various modules of the above-mentioned distributed cache synchronization device for the session process can be implemented in whole or in part through software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the electronic device in the form of hardware, or can be stored in the memory of the electronic device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0069] The embodiment of the present invention also provides a computer device, such as Figure 5 As shown, Figure 5 It is a structural diagram of a session process distributed cache synchronization device provided by an optional embodiment of the present invention. The computer device may include at least one processor 41, at least one communication interface 42, at least one communication bus 43 and at least one memory 44, wherein the communication interface 42 may include a display screen (Display) and a keyboard (Keyboard), and the optional communication interface 42 may also include a standard wired interface and a wireless interface. The memory 44 may be a high-speed RAM memory (Random Access Memory, volatile random access memory) or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 44 may optionally be at least one storage device located away from the aforementioned processor 41. The processor 41 may be combined with Figure 4 In the described device, the memory 44 stores an application program, and the processor 41 calls the program code stored in the memory 44 to execute the steps of the session process distributed cache synchronization method of any of the above method embodiments.

[0070] The communication bus 43 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 43 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0071] Among them, the memory 44 may include a volatile memory (English: volatile memory), such as a random access memory (English: random-access memory, abbreviated: RAM); the memory may also include a non-volatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk drive (English: hard disk drive, abbreviated: HDD) or a solid-state drive (English: solid-state drive, abbreviated: SSD); the memory 44 may also include a combination of the above types of memory.

[0072] The processor 41 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP.

[0073] The processor 41 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0074] Optionally, the memory 44 is also used to store program instructions. The processor 41 can call the program instructions to implement the session process distributed cache synchronization method in any embodiment of the present invention.

[0075] The embodiment of the present invention also provides a non-transitory computer storage medium, which stores computer executable instructions, and the computer executable instructions can execute the session process distributed cache synchronization method in any of the above method embodiments. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.

[0076] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the invention.

Claims

1. A method for synchronizing a distributed cache during a session, characterized in that: The steps include: Get the business request and distributed lock of the target session; Determining whether the target session exists in the process cache based on the business request and the distributed lock; If the target session exists in the process cache, data processing is performed on the target session based on the service request to obtain a data processing result; Based on the data processing result, the key updates of the target session are synchronized into the distributed session cache, and the distributed lock thereof is continuously renewed; The key updates are session-sensitive fields that need to ensure distributed consistency.

2. The method for synchronizing a session distributed cache according to claim 1, characterized in that: Also includes: The validity period of the distributed lock is determined based on the interval time of the update request of the target session.

3. The session process distributed cache synchronization method according to claim 1, characterized in that: The performing data processing on the target session based on the service request to obtain a data processing result includes: Performing business processing on the target session based on the business request to obtain a business processing result; Update the target session based on the business processing result to obtain a new target session; A key update is obtained based on the new target session, and the distributed session cache is synchronously updated based on the key update to obtain the data processing result.

4. The method for synchronizing a session process distributed cache according to claim 3, characterized in that: The synchronously storing the target session in a distributed session cache includes: The new target session is synchronously stored in the updated distributed session cache.

5. The method for synchronizing a session process distributed cache according to claim 1, characterized in that: The determining whether the target session exists in the process cache based on the business request and the distributed lock further includes: If the target session does not exist in the process cache, determining whether there is a new distributed lock based on the target session; If there is a new distributed lock, the new distributed lock is acquired, and the process cache is updated based on the new distributed lock to obtain a new process cache; Data processing is performed based on the new process cache to obtain a second data processing result.

6. The method for synchronizing a session distributed cache according to claim 5, characterized in that: The determining whether there is a new distributed lock based on the target session also includes: If there is no new distributed lock, a session switching signal is sent; The target session is stored in a delay processing queue based on the session switching signal.

7. The method for synchronizing a session distributed cache according to claim 1, characterized in that: Also includes: Obtaining a session switching notification based on the distributed lock; Switch to another target session based on the session switching notification, and release the distributed lock.

8. A session process distributed cache synchronization device, characterized in that: include: The acquisition module is used to obtain the business request and distributed lock of the target session; A determination module, configured to determine whether the target session exists in a process cache based on the service request and the distributed lock; A data processing module, configured to perform data processing on the target session based on the service request to obtain a data processing result if the target session exists in the process cache; A storage module, configured to synchronize key updates of the target session into a distributed session cache based on the data processing result, and continuously renew its distributed lock; The key updates are session-sensitive fields that need to ensure distributed consistency.

9. A session process distributed cache synchronization device, characterized in that: include: A communication unit, a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the steps of the method described in any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to cause the computer to execute the steps of any one of claims 1-7.

Citation Information

Patent Citations

  • Session management method and system

    CN106603713A

  • Access manager session management strategy

    US20170118218A1