Session sharing method and device, electronic equipment, medium and computer program product
By deploying an embedded database on the service cluster nodes and using a distributed consistency protocol, the problem of service unavailability caused by centralized database failures is solved, and distributed storage and high reliability of session information are achieved, ensuring the continuity of user sessions and identity recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NETSUNION CLEARING CORP
- Filing Date
- 2024-10-11
- Publication Date
- 2026-04-17
AI Technical Summary
A failure in a centralized database can prevent a distributed system from accessing or verifying user session information in a timely manner, affecting the user login experience and potentially causing the IAM system to crash.
An embedded database is deployed on the service nodes in the service cluster. A distributed consensus protocol is used to achieve distributed storage of session information, reducing dependence on external systems and ensuring the consistency and reliability of session information across nodes.
It improves the reliability and availability of the service cluster, avoids service cluster paralysis caused by single point of failure of centralized database, and ensures the continuity of session information and the identification of user identity.
Smart Images

Figure CN121887780A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to a session sharing method, apparatus, electronic device, medium, and computer program product. Background Technology
[0002] With the rapid development of information technology and network applications, some distributed systems have implemented session sharing functionality to meet high availability requirements. However, many related technologies use centralized databases to store user session information for session sharing. While this approach facilitates centralized management and maintenance, a failure of the centralized database will render the distributed system unable to provide services to users. Taking an Identity and Access Management (IAM) system as an example, a failure of the centralized database will prevent the IAM system from accessing or verifying user session information in a timely manner, directly impacting the user's login experience and potentially even paralyzing the entire IAM login function. Summary of the Invention
[0003] This disclosure provides a session sharing method, apparatus, electronic device, medium, and computer program product to at least partially solve one of the technical problems in the related art. The technical solution of this disclosure is as follows:
[0004] According to a first aspect of the present disclosure, a session sharing method is provided, applied to any service node in a service cluster, wherein the service node is deployed with an embedded database, comprising: receiving a first access request sent by a target user through a client node; generating session information based on the first access request; and storing the session information in the embedded database deployed by each of the service nodes in the service cluster based on a distributed consensus protocol, so as to realize session sharing.
[0005] According to a second aspect of the present disclosure, a session sharing apparatus is provided, applied to any service node in a service cluster, wherein the service node is deployed with an embedded database, comprising: a receiving module for receiving a first access request sent by a target user through a client node; a generating module for generating session information based on the first access request; and a storage module for storing the session information in the embedded database deployed by each of the service nodes in the service cluster based on a distributed consensus protocol, so as to realize session sharing.
[0006] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement a session sharing method as described in the first aspect of the present disclosure.
[0007] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, which stores computer-executable instructions that, when executed by a processor, are used to implement a session sharing method as described in the first aspect of the present disclosure.
[0008] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements a session sharing method as described in the first aspect of the present disclosure.
[0009] The technical solution provided by the embodiments of this disclosure offers at least the following beneficial effects: receiving a first access request sent by a target user through a client node; generating session information based on the first access request; and storing the session information in an embedded database deployed on each service node in the service cluster based on a distributed consensus protocol to achieve session sharing. This disclosure reduces dependence on external systems by embedding a database in the service nodes, achieves distributed storage of session information, avoids the risk of a single point of failure in a centralized database causing service cluster paralysis, and improves the reliability and availability of the service cluster.
[0010] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0011] The above and / or additional aspects and advantages of this disclosure will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, in which:
[0012] Figure 1 A flowchart illustrating a session sharing method provided in the first embodiment of this disclosure;
[0013] Figure 2 A flowchart illustrating a session sharing method provided in the second embodiment of this disclosure;
[0014] Figure 3 A flowchart illustrating a session sharing method provided in the third embodiment of this disclosure;
[0015] Figure 4 This is a schematic diagram of the service cluster architecture provided in the fourth embodiment of this disclosure;
[0016] Figure 5 This is a schematic diagram of the structure of a session sharing device provided in the fifth embodiment of the present disclosure;
[0017] Figure 6 This is a block diagram of the electronic device provided in the sixth embodiment of this disclosure. Detailed Implementation
[0018] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0019] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0020] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the technical solution disclosed herein are all carried out with the consent of the user, and all comply with the provisions of relevant laws and regulations, and do not violate public order and good morals.
[0021] The following description, with reference to the accompanying drawings, outlines a session sharing method, apparatus, electronic device, medium, and computer program product according to embodiments of the present disclosure.
[0022] It should be noted that the execution subject of the session sharing method in this embodiment is a session sharing device, which can be implemented by software and / or hardware and can be configured in an electronic device.
[0023] Figure 1 This is a flowchart illustrating a session sharing method provided in the first embodiment of this disclosure. The method is applied to any service node in a service cluster, and the service node is equipped with an embedded database.
[0024] The service cluster provides services to the distributed system. It comprises multiple service nodes, each running the Raft distributed consensus protocol. All service nodes together form a Raft service cluster. It's important to note that a service node can refer to a server node, and the embedded database can refer to an H2 database. As an example, a load balancer is deployed within the service cluster. The load balancer distributes access requests from client nodes to the various service nodes based on a load balancing algorithm.
[0025] like Figure 1 As shown, the session sharing method includes the following steps:
[0026] Step 101: Receive the first access request sent by the target user through the client node.
[0027] Here, the client node can refer to a browser, mobile application, etc., and the first access request can refer to a login request, business request, or other request that requires establishing a session. As an example and not a limitation, the first access request may include user identity information (user ID, login password) and client node identifier, etc.; if the first access request is a business request, it may also include business request information, such as form filling information, user preference settings information, data retrieval information, etc.
[0028] It should be noted that the first access request can refer to the first request from a target user to access the distributed system within a set time period.
[0029] Step 102: Generate session information based on the first access request.
[0030] Upon receiving the first access request, the service node creates a session based on the request and generates session information. As an example, if the first access request is a login request, the session information may include information such as the session identifier (ID), session creation time, session validity period, and user permissions.
[0031] After generating the session information, the session information can be sent to the server node.
[0032] Step 103: Based on the distributed consensus protocol, the session information is stored in the embedded database deployed on each service node in the service cluster to achieve session sharing.
[0033] As an example, after generating session information, the session information can be broadcast to service nodes in the service cluster based on a distributed consensus protocol, so that the service nodes that listen to the broadcast will store the session information in their own embedded database.
[0034] An embedded database is a lightweight database system that can be directly embedded into applications to run without requiring a separate database server. By deploying an embedded database on each service node, dependence on external systems is reduced, ensuring that the overall service is available as long as the distributed service itself is available. Furthermore, embedding the database within the service nodes also enables distributed storage of session information, avoiding the risk of a single point of failure in a centralized database causing service cluster paralysis, thus improving the reliability and availability of the service cluster.
[0035] It's important to note that after storing session information in the embedded database of each service node, when a target user accesses the distributed system again, regardless of which service node the access request is routed to, the stored session information can be retrieved. This information is then used to identify the target user's identity and permissions, restore their session state, and maintain session continuity. The session state can refer to things like shopping cart contents, form completion progress, and user preference settings.
[0036] In summary, the system receives the first access request sent by the target user through the client node; generates session information based on the first access request; and stores the session information in the embedded database deployed on each service node in the service cluster based on a distributed consistency protocol to achieve session sharing. This disclosure reduces dependence on external systems by embedding a database in the service nodes, achieves distributed storage of session information, avoids the risk of a single point of failure in a centralized database causing service cluster paralysis, and improves the reliability and availability of the service cluster.
[0037] To clearly illustrate how session information is stored in the embedded database deployed on each service node in the service cluster in the above embodiments, this disclosure proposes another session sharing method.
[0038] Figure 2 This is a schematic flowchart of a session sharing method provided in the second embodiment of this disclosure.
[0039] like Figure 2 As shown, the session sharing method may include the following steps:
[0040] Step 201: Receive the first access request sent by the target user through the client node.
[0041] Step 202: Generate session information based on the first access request.
[0042] Step 203: In the case that this service node is the master node, store the session information in the embedded database deployed on the master node, and send information storage instructions to each slave node to instruct each slave node to store the session information in the corresponding embedded database.
[0043] Among them, slave nodes refer to service nodes in the service cluster other than the master node.
[0044] It should be noted that after the service cluster starts, each service node in the service cluster elects a master node based on the set election protocol. The master node then copies the session information to all service nodes for storage, thereby achieving session sharing.
[0045] When this service node is the master node, the master node stores session information in its own embedded database based on the distributed consensus protocol, and sends information storage instructions to other service nodes in the service cluster, so that other service nodes store session information in their own embedded databases, thus completing the session information replication.
[0046] When this service node acts as the master node, it is responsible for storing session information directly in its own embedded database and simultaneously sending information storage instructions to all slave nodes. This mechanism ensures the consistency of session information between the master node and all slave nodes, so that session information will not be lost even if a slave node is temporarily unavailable or fails.
[0047] Step 204: If this service node is a slave node, send a session storage request to the master node so that the master node stores the session information in the embedded database deployed by the master node, and so that the master node sends information storage instructions to each slave node.
[0048] When this service node is a slave node, the slave node sends a session storage request to the master node based on the distributed consensus protocol. After receiving the session storage request from the slave node, the master node stores the session information in its own embedded database based on the distributed consensus protocol, and sends information storage instructions to other service nodes in the service cluster to copy the session information to other service nodes for storage.
[0049] When this service node acts as a slave node, it further strengthens data consistency management by forwarding session storage requests to the master node. The master node, as the center of session information management, is responsible for handling the storage and distribution of all session information, thereby ensuring data reliability and integrity.
[0050] It should be noted that the execution processes of steps 201 and 202 can be implemented in any of the various embodiments of this disclosure. This disclosure does not limit these processes and will not elaborate further.
[0051] In summary, the system receives the first access request sent by the target user through the client node; based on the first access request, it generates session information; when the service node is the master node, it stores the session information in the embedded database deployed on the master node based on a distributed consensus protocol, and sends information storage instructions to each slave node to instruct each slave node to store the session information in its corresponding embedded database; when the service node is a slave node, it sends a session storage request to the master node based on a distributed consensus protocol, causing the master node to store the session information in the embedded database deployed on the master node, and causes the master node to send information storage instructions to each slave node. The master node, as the center of session information management, is responsible for handling the storage and distribution of all session information, ensuring the consistency of session information between the master node and all slave nodes.
[0052] To clearly illustrate how session information is read in the above embodiments, this disclosure proposes another session sharing method.
[0053] Figure 3 This is a flowchart illustrating a session sharing method provided in the third embodiment of this disclosure.
[0054] like Figure 3 As shown, the session sharing method may include the following steps:
[0055] Step 301: Receive the first access request sent by the target user through the client node.
[0056] Step 302: Generate session information based on the first access request.
[0057] Step 303: Based on the distributed consensus protocol, the session information is stored in the embedded database deployed on each service node in the service cluster to achieve session sharing.
[0058] Step 304: Receive the second access request sent by the target user through the client node. The second access request is sent later than the first access request.
[0059] The second access request can refer to the request made by the target user when accessing the distributed system for the second time or subsequent times. The second access request may include information such as the session ID returned by the service node based on the first access request.
[0060] Step 305: In the case that this service node is the master node, based on the second access request, read the session information from the embedded database deployed on the master node.
[0061] When this service node is the master node, it can directly read the target user's session information from its own embedded database based on the second access request.
[0062] The master node is responsible for storing and distributing all session information and can maintain the latest data state. Therefore, the session information read from the master node is up-to-date and consistent.
[0063] It should be noted that after reading the session information, the identity and permissions of the target user can be identified based on the session information, and their session state can be restored.
[0064] Step 306: If this service node is a slave node, send an information read request to the master node based on the second access request, and receive session information returned by the master node based on the information read request.
[0065] The master node stores the latest session information. To ensure that the latest and consistent session information is read, as an example, when this service node is a slave node, a message read request can be sent directly to the master node, and the master node can read the target user's session information from its own embedded database.
[0066] Handling all information read requests by the master node may overload it. To reduce the load on the master node and improve read efficiency, as another example, based on the second access request, the service node queries the embedded database to find session information that matches the second access request; if no session information is found in the embedded database, the service node sends an information read request to the master node.
[0067] When this service node is a slave node, it first reads the session information from its own embedded database based on the second access request. If the session information is read, the identity and permissions of the target user can be identified based on the session information, and its session state can be restored. If the session information is not read, it sends an information reading request to the master node to request the master node to read the session information from its own embedded database.
[0068] The master node in the service cluster may fail. In order to avoid the inability to achieve session sharing due to the failure of the master node, this disclosure proposes that a new master node can be re-elected.
[0069] As an example, when this service node is a slave node, in response to the fact that this service node has not received a heartbeat message from the master node within a set time period, it sends a voting request message to the service nodes in the service cluster based on the distributed consensus protocol; obtains the voting results of each service node in the service cluster; and if it is determined based on the voting results that this service node has been elected as the new master node, it sends a heartbeat message to the service nodes in the service cluster.
[0070] After obtaining the voting results, the votes can be counted based on the voting results. If the number of votes is greater than or equal to the set vote threshold, the service node is determined to be elected as the new master node; if the number of votes is less than the set vote threshold, the election of the service node is determined to have failed.
[0071] When a service node is elected as the new master node, the heartbeat message sent to the service nodes in the service cluster is used to inform other service nodes that the current leader (master node) is still active and effective, in order to maintain its leadership position and prevent other service nodes from thinking that the leader may have failed and initiating a new election process.
[0072] When the master node fails and cannot continue providing services, a new master node can be quickly elected from the service cluster through heartbeat detection and election mechanisms, thereby ensuring service continuity and availability. Furthermore, by setting reasonable heartbeat timeout times and election procedures, service interruption time can be minimized, improving the overall availability of the system.
[0073] It should be noted that the execution process of steps 301-303 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.
[0074] In summary, the system receives a second access request sent by the target user through a client node. If the service node is the master node, it reads session information from the embedded database deployed on the master node based on the second access request. If the service node is a slave node, it sends an information read request to the master node based on the second access request and receives session information returned by the master node according to the information read request. The master node stores the latest session information, and reading the session information by the master node ensures that the latest and consistent session information is retrieved.
[0075] Figure 4 This is a schematic diagram of the service cluster architecture provided in the fourth embodiment of this disclosure.
[0076] like Figure 4 As shown, the service cluster includes three service nodes: Node1, Node2, and Node3. Each service node consists of a RaftNode running the Raft protocol and an H2 database. When a service node updates session information (for example, when a user logs in through any of the three service nodes), the session information is copied to other service nodes in the service cluster via the Raft protocol, thus realizing the session sharing function.
[0077] The following is combined with Figure 4 Explain the session sharing process:
[0078] 1. When the service cluster starts, a master node (Leader node) is elected according to the Raft protocol, such as Node1.
[0079] 2. Storing session information: When user A is initially routed to Node2 through load balancing, session information is generated. Node2 sends a session storage request to the leader node Node1. After receiving the session storage request, Node1 stores the session information in the H2 database on Node1 and replicates the session information to Node2 and Node3 through the Raft protocol. Node2 and Node3 then store the session information in their own H2 databases, thus completing the session information replication.
[0080] 3. Read session information. When user A accesses the distributed system for the second time through load balancing and is routed to Node3, it is necessary to read A's session information. Node3 initiates an information read request to the Leader node Node1 through the Raft protocol. Node1 returns the session information to Node3, completing the session information sharing.
[0081] 4. Failover: When Node1 fails, Node2 and Node3 initiate another election to select a new Leader node. Since the previous session data has been replicated to all service nodes through the Raft protocol, the new Leader node can still provide the session sharing function in step 3.
[0082] First, this disclosure differs from conventional centralized storage solutions by introducing the Raft protocol and H2 database into each service node, enabling conventional distributed services to form a cluster that supports embedded distributed databases. This allows the nodes themselves to participate in storing session information, which can be used to store non-critical temporary data, thus improving the overall availability of the system. Second, this disclosure supports failover while implementing session sharing, avoiding data consistency issues after a single point of failure. Finally, this disclosure reduces database dependencies and lowers system deployment costs.
[0083] To implement the above embodiments, this disclosure also proposes a session sharing device.
[0084] Figure 5 This is a schematic diagram of a session sharing device provided in the fifth embodiment of the present disclosure. The device is applied to any service node in a service cluster, and the service node is equipped with an embedded database.
[0085] like Figure 5 As shown, the session sharing device 500 includes: a receiving module 501, a generating module 502, and a storage module 503.
[0086] The receiving module 501 is used to receive the first access request sent by the target user through the client node; the generating module 502 is used to generate session information based on the first access request; and the storage module 503 is used to store the session information in the embedded database deployed on each service node in the service cluster based on the distributed consensus protocol, so as to realize session sharing.
[0087] As one possible implementation of this disclosure, the storage module 503 is used to: store session information in an embedded database deployed on the master node when the service node is the master node, and send information storage instructions to each slave node to instruct each slave node to store session information in the corresponding embedded database; wherein, a slave node refers to a service node in the service cluster other than the master node.
[0088] As one possible implementation of this disclosure, the storage module 503 is used to: send a session storage request to the master node when the service node is a slave node, so that the master node stores the session information in the embedded database deployed by the master node, and to send information storage instructions to each slave node.
[0089] As one possible implementation of this disclosure, the receiving module 501 is further configured to: receive a second access request sent by the target user through the client node, wherein the second access request is sent later than the first access request;
[0090] The device also includes a reading module, used for: reading session information from an embedded database deployed on the master node based on a second access request when the service node is the master node; sending an information reading request to the master node based on the second access request when the service node is the slave node; and receiving session information returned by the master node based on the information reading request.
[0091] As one possible implementation of this disclosure, the reading module is further configured to: query session information matching the second access request in the embedded database deployed on this service node based on the second access request; and send an information reading request to the master node in response to the failure to find session information in the embedded database deployed on this service node.
[0092] As one possible implementation of this disclosure, the device further includes an election module, configured to: when the service node is a slave node, in response to the service node not receiving heartbeat information from the master node within a set time period, send voting request information to the service nodes in the service cluster based on a distributed consensus protocol; obtain the voting results of each service node in the service cluster; and, if it is determined based on the voting results that the service node has been elected as the new master node, send heartbeat information to the service nodes in the service cluster.
[0093] It should be noted that the foregoing explanation of the session sharing method embodiment also applies to the session sharing device of this embodiment, and will not be repeated here.
[0094] Figure 6 This is a schematic diagram of the structure of an electronic device provided according to a sixth embodiment of the present disclosure. The electronic device 600 in this embodiment is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0095] like Figure 6 As shown, the above-mentioned electronic device 600 includes:
[0096] The memory 601 and the processor 602 are connected by a bus 603, which connects the different components (including the memory 601 and the processor 602). The memory 601 stores a computer program, and when the processor 602 executes the program, it implements the session sharing method of the present disclosure embodiment.
[0097] Bus 603 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0098] Electronic device 600 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by electronic device 600, including volatile and non-volatile media, removable and non-removable media.
[0099] Memory 601 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 604 and / or cache memory 605. Electronic device 600 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 606 can be used to read and write non-removable, non-volatile magnetic media (… Figure 6 Not shown; usually referred to as a "hard drive"). Although Figure 6Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 603 via one or more data media interfaces. Memory 601 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this disclosure.
[0100] A program / utility 608 having a set (at least one) of program modules 607 may be stored, for example, in memory 601. Such program modules 607 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 607 typically perform the functions and / or methods described in the embodiments of this disclosure.
[0101] Electronic device 600 can also communicate with one or more external devices 609 (e.g., keyboard, pointing device, display 611, etc.), and with one or more devices that enable a user to interact with the electronic device 600, and / or with any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed through input / output (I / O) interface 612. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) through network adapter 613. Figure 6 As shown, network adapter 613 communicates with other modules of electronic device 600 via bus 603. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0102] The processor 602 executes various functional applications and data processing by running programs stored in the memory 601.
[0103] It should be noted that the implementation process and technical principles of the electronic device in this embodiment are explained in the foregoing description of the session sharing method of this disclosure embodiment, and will not be repeated here.
[0104] To implement the above embodiments, this disclosure also proposes a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the methods provided in the foregoing embodiments. The computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, or optical data storage device, etc.
[0105] To implement the above embodiments, this disclosure also proposes a computer program product, including a computer program that, when executed by a processor, implements the methods provided in the foregoing embodiments.
[0106] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0107] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A session sharing method, characterized in that, Applied to any service node in a service cluster, wherein the service node is equipped with an embedded database, the process includes the following steps: Receive the first access request sent by the target user through the client node; Based on the first access request, session information is generated; Based on a distributed consensus protocol, the session information is stored in an embedded database deployed on each service node in the service cluster to achieve session sharing.
2. The method according to claim 1, characterized in that, The step of storing the session information in the embedded database deployed on each of the service nodes in the service cluster includes: When this service node is the master node, the session information is stored in the embedded database deployed by the master node, and information storage instructions are sent to each slave node to instruct each slave node to store the session information in the corresponding embedded database. The slave node refers to any service node in the service cluster other than the master node.
3. The method according to claim 2, characterized in that, The step of storing the session information in the embedded database deployed on each of the service nodes in the service cluster includes: When this service node is a slave node, a session storage request is sent to the master node so that the master node stores the session information in the embedded database deployed by the master node, and the master node sends the information storage instruction to each slave node.
4. The method according to claim 3, characterized in that, The method further includes: Receive a second access request sent by the target user through a client node, wherein the second access request is sent later than the first access request; When this service node is the master node, the session information is read from the embedded database deployed on the master node based on the second access request; When this service node is a slave node, it sends an information read request to the master node based on the second access request, and receives the session information returned by the master node based on the information read request.
5. The method according to claim 4, characterized in that, The step of sending an information read request to the master node based on the second access request includes: Based on the second access request, query the session information that matches the second access request in the embedded database deployed on this service node; In response to the fact that the session information was not found in the embedded database deployed on this service node, the information read request is sent to the master node.
6. The method according to any one of claims 2-5, characterized in that, The method further includes: When this service node is a slave node, in response to the fact that this service node has not received the heartbeat information sent by the master node within a set time period, it sends a voting request information to the service nodes in the service cluster based on the distributed consensus protocol; Obtain the voting results of each service node in the service cluster; If, based on the voting results, this service node is elected as the new master node, a heartbeat message is sent to the service nodes in the service cluster.
7. A session sharing device, characterized in that, Applied to any service node in a service cluster, wherein the service node is equipped with an embedded database, including: The receiving module is used to receive the first access request sent by the target user through the client node; The generation module is used to generate session information based on the first access request; The storage module is used to store the session information in the embedded database deployed on each of the service nodes in the service cluster based on a distributed consensus protocol, so as to realize session sharing.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-6.
10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1-6.