A Lossless Version Upgrade Method and Storage Medium for Database Agents Based on Connection Migration
By modifying the kernel connection allocation strategy and using Unix socket migration technology via eBPF, the problems of new connection failures and high overhead in migrating existing connections during database proxy middleware version upgrades were solved, achieving lossless and rapid version upgrades and ensuring business continuity and the integrity of connection logic information.
Patent Information
- Application Number
- CN202611296749.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-25
- Publication Date
- 2026-11-17
AI Technical Summary
During the upgrade process of existing database proxy middleware versions, the failure to allocate new connections and the high overhead of migrating existing connections make it difficult to achieve lossless and rapid version upgrades, thus affecting business continuity.
A connection migration method based on eBPF is adopted. By modifying the kernel connection allocation strategy through eBPF, the connection state is migrated across processes using Unix Socket. A multi-level exception handling and retry mechanism is designed, and migration rules are designed for special connections. This ensures that new connections are allocated to new agents, old connections are serialized and migrated to new agents through Unix Socket, and connection logic information is restored.
It enables lossless version upgrades of database proxy middleware, avoids new connection failures, reduces the overhead of migrating existing connections, ensures business transparency and the integrity of connection logic information, and improves the efficiency and reliability of version upgrades.
Smart Images

Figure CN123115087A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of database technology, and more specifically, relates to a lossless version upgrade method and storage medium for database agents based on connection migration. Background Technology
[0002] With the widespread adoption of cloud-native technologies, cloud-native databases have become the core data storage hub for enterprise digital businesses. Database proxy middleware, as the central link connecting application clients and database clusters, has become an indispensable component of high-availability data service architectures due to its core capabilities such as resource decoupling, traffic scheduling, protocol parsing, and failover. Statistics show that over 79% of enterprises use multiple database platforms in combination, further amplifying the irreplaceable role of proxy middleware in unifying traffic entry points and shielding the complexity of the underlying architecture.
[0003] With rapid business iteration and increasingly stringent security and compliance requirements, online database proxy middleware faces increasingly frequent version upgrade needs, including patching high-risk security vulnerabilities, introducing new protocol features, and performance optimization iterations. However, database proxy processes typically need to maintain a massive number of active TCP long connections to clients simultaneously. This "state-heavy" characteristic brings significant risks and challenges to version upgrades. The stability of proxy version upgrades directly determines the business continuity of the entire data access chain.
[0004] Currently, mainstream proxy version upgrade solutions mainly fall into two categories, both of which have significant technical flaws. The first category is the shutdown upgrade solution, with the open-source Redis proxy Twemproxy as a typical example. Its operation process involves stopping the old version proxy process, replacing the new version binary file, and then restarting the service. This solution causes all TCP connections held by the old process to be forcibly reset by the kernel. The collective disconnection of massive connections can trigger a severe "reconnection storm," instantly exhausting the connection resources and CPU quotas of the backend database, causing service interruption and business degradation. It can only be executed during the operation and maintenance window during off-peak business periods and cannot adapt to 24 / 7 uninterrupted operation of globalized businesses.
[0005] The second type is the rolling upgrade solution, typically represented by Codis and OceanBase's OBProxy. This solution uses parallel services from both old and new proxy instances. New connections are routed to the new instance via the registry center, while the old instance stops accepting new requests and gracefully shuts down after existing connections are naturally closed. While this solution avoids a simultaneous interruption of the entire cluster, in typical database long-connection scenarios, the old process often takes hours or even days to clear existing connections, indefinitely extending the upgrade cycle. Forcibly terminating the old process can still cause abnormal interruptions to existing connections. Furthermore, in the rolling upgrade solution, when new and old processes listen to the same port in parallel, the kernel's default hash allocation strategy will still assign some new connections to the old process that is about to close the port, causing client connection failures and creating a lossy interruption window.
[0006] In addition, most existing research on connection migration focuses on failover scenarios between servers, which requires the full transmission of the connection context over the entire network stack. This results in high transmission overhead and high latency, and cannot be directly adapted to version upgrade scenarios of proxy processes within the same host. While transport layer protocols such as QUIC and SCTP natively support connection migration, they are not widely supported by mainstream database clients and servers, and cannot solve the problem of application layer state recovery of database sessions, making it difficult to implement in practical applications.
[0007] In summary, existing technologies cannot simultaneously solve the performance bottlenecks of lossy incremental connection allocation at the kernel layer and the reconstruction of existing connections at the system call layer during database proxy middleware version upgrades, making it difficult to meet the core requirements of cloud-native businesses for proxy upgrades to be "transparent and lossless for business operations, and lightweight and efficient for the system". Summary of the Invention
[0008] To address the shortcomings and improvement needs of existing technologies, this invention provides a lossless version upgrade method and storage medium for database agents based on connection migration. Its purpose is to achieve lossless upgrade of agent versions through smooth cross-process migration of connection states, while solving the problems of failed new connection allocation and high overhead of existing connection migration during the upgrade process. Under the premise of zero awareness of upper-layer business, it realizes fast, low-overhead, and full-connection version upgrade of agent middleware.
[0009] To achieve the above objectives, according to one aspect of the present invention, a method for lossless version upgrade of a database proxy based on connection migration is provided, comprising: After system initialization, it enters the normal state; in the normal state, threads for creating new connections are allocated according to the default allocation strategy. Under normal circumstances, upon receiving an upgrade command, the new agent is started and enters the preparation state; in the preparation state, system environment verification is performed, eBPF bytecode is prepared, and system resources required for loading the eBPF program are pre-allocated. In the preparation state, after the system environment verification is passed, it enters the activation state; in the activation state, the eBPF program is loaded, and the thread allocation strategy is modified through the loaded eBPF program so that when a new connection request is received, the task of creating a new connection is allocated to the thread in the new agent in a round-robin manner, and the connections in the old agent are migrated to the new agent. In the active state, when all threads in the old agent are shut down, it enters the monitoring state; in the monitoring state, it checks the health status of each thread in the new agent. In monitoring mode, when the health status of each thread in the new agent meets the requirements, unload the loaded eBPF program, clean up the resources occupied by the eBPF program, and restore the normal state. In any state, if an exception occurs, the system enters a rollback state; in the rollback state, the loaded eBPF program is unloaded, and threads for new connections are allocated according to the default allocation strategy; when the exception is resolved, the system returns to normal. The default allocation strategy allocates threads for creating new connections based on the thread number in the connection's 5-tuple.
[0010] Furthermore, the threads of the old agent and the threads of the new agent are numbered sequentially. Furthermore, in the ready state, it also includes: Initialize the polling pointer to current_pos=0; Furthermore, in the active state, upon receiving a request to establish a new connection, the task of establishing the new connection is assigned to a thread in the new agent in a round-robin manner, including: The thread number SI for creating a new connection is calculated according to SI=(Nk)+current_pos, and the task of creating a new connection is assigned to thread SI. When all connections on a thread in the old agent are migrated to the new agent, that thread is closed, and the thread numbers of all threads are adjusted accordingly so that the threads of the old agent and the threads of the new agent are numbered consecutively, and the polling pointer is updated according to current_pos=(current_pos + 1) %M. Where N is the original number of threads in the old agent, M is the number of threads in the new agent, k is the number of threads that have been closed in the old agent, and "%" represents the modulo operation.
[0011] Furthermore, while in the active state, the connections in the old proxy are migrated to the new proxy, including: In the old proxy, for each connection to be migrated, perform the following steps: S1: Serialize the connection metadata to be migrated into a byte stream; S2: Divide the byte stream into multiple data blocks, with the size of each data block not exceeding the maximum packet length minus the fixed header size; S3: Construct a packet header for each data block, and encapsulate the packet header and data block into a packet; for the last packet, allocate an auxiliary data buffer and fill it with the file descriptor corresponding to the concatenation 5-tuple; S4: Call sendmsg to send data packets to the new agent via Unix Socket; The information recorded in the packet header includes: packet length (packet_len), packet type (packet_type), packet sequence number (packet_no), last packet identifier (flags), unique identifier of the connection (conn_id), and connection type (conn_type). In the new agent, recvmsg is called repeatedly to receive data packets sent by the old agent from the Unix socket. The data blocks in the data packets corresponding to the same connection are concatenated in order and deserialized to obtain the connection metadata. The file descriptor is extracted from the auxiliary data buffer. The connection object is reconstructed using the file descriptor and the connection metadata to complete the migration of the connection.
[0012] Furthermore, in the new agent, `recvmsg` is called repeatedly to receive data packets sent by the old agent. Data blocks from the data packets corresponding to the same connection are concatenated sequentially and then deserialized to obtain connection metadata. File descriptors are extracted from the auxiliary data buffer. The connection object is reconstructed using the file descriptors and connection metadata to complete the connection migration, including: Maintain a hash table with the connection identifier `conn_id` as the key, used to store a list of data blocks currently received for each connection and a bitmap of received packet sequence numbers; repeatedly call `recvmsg` to receive packets sent by the old proxy; for each received packet, perform the following steps: R1: Parse the packet header to extract the information recorded in the packet header; R2: Find the corresponding connection cache structure based on the parsed conn_id. If it does not exist, create the corresponding connection cache structure. R3: Store the data blocks in the data packet in the corresponding connection cache structure and update the hash table; R4: Determine whether the received data packet is the last data packet in the connection based on the parsed flags. If yes, proceed to R5; otherwise, proceed to R6. R5: Determine whether the sequence numbers of data packets in the same connection are consecutive based on the hash table. If so, concatenate the data blocks in the corresponding connection cache structure in order and then deserialize them to obtain the connection metadata. Extract the file descriptor from the auxiliary data buffer. Reconstruct the connection object using the file descriptor and connection metadata to complete the migration of the connection and remove the corresponding connection information from the hash table. R6: Processing of the current data packet has ended.
[0013] Furthermore, in the old agent, data packets for the same connection are sent sequentially, and data packets for multiple connections are sent interleaved.
[0014] Furthermore, in the ready state, it also includes: Send a signal to the old agent to shut down the control port; Signal the new agent to listen on the same data and control ports as the old agent; Send a signal to the old agent to shut down its data port; Furthermore, before migrating connections from the old proxy to the new proxy while the proxy is active, the following steps are also included: Send a signal to the new agent to make it listen on the default Unix socket port; The old agent sends data packets through the Unix socket port that the new agent is listening on; Furthermore, in the active state, before entering the monitoring state, when all threads in the old agent are shut down, the following steps are also included: Send a signal to the new agent to close the Unix socket port, and send a signal to the old agent to shut down the process.
[0015] Furthermore, the database proxy lossless version upgrade method based on connection migration provided by this invention also includes: ensuring the atomicity and data integrity of connection migration based on a multi-level exception handling and retry mechanism; the multi-level exception handling and retry mechanism includes: In the old agency: If a temporary error message is returned after calling sendmsg, an exponential backoff strategy will be used to retry, and the number of retries will not exceed the preset retry limit. If a fatal error message is returned after calling sendmsg, or if the retry count fails after reaching the retry limit, the migration of the current batch is determined to have failed. All file descriptors that have been attempted to be sent in the current batch are closed, and all connections in the current batch are marked as "connection failed". Connections that have not been migrated in the current batch are retained in the old proxy and error logs are recorded. If the current batch of migration does not receive a confirmation message from the new agent after the set timeout threshold, it is determined whether the corresponding file descriptor has been closed. If yes, the migration is abandoned; otherwise, S1~S4 are re-executed to retransmit the corresponding connection. In the new agency: If the packet_len and packet_type in the packet header fail to be validated, or if the packet_no of the packets corresponding to the same connection is not consecutive, the received packets are discarded and an error response is sent to the old proxy. If the file descriptor corresponding to the connection is found to be non-existent, close all received file descriptors and send an error response to the old agent; If resources are insufficient or the connection status is abnormal when rebuilding the connection object, the corresponding file descriptor is closed, and an acknowledgment response is sent only for successfully rebuilt connections; for connections that fail to rebuild, a retransmission response is sent to the old agent or the rebuild is abandoned.
[0016] Furthermore, before migrating connections from the old proxy to the new proxy while in the active state, the process includes: determining whether the migration conditions are met; if so, creating multiple lock-free migration queues, each corresponding to a connection type, and placing each connection from the old proxy into the corresponding migration queue according to the connection type; if not, prohibiting migration. Maintain a timer. Whenever the timer expires, organize all connections in the migration queue into a batch, migrate them, and then reset the timer. The migration conditions include: requests from clients are in the old proxy and have not been successfully passed to the database or the client.
[0017] Furthermore, if the connection to be migrated is a transactional connection and the requests on the connection are in a transaction, then before executing S1~S4 to migrate the connection, the process also includes: marking "in progress of a transaction" in its metadata and adding the set of preceding commands that have not yet been committed to the migration metadata; If the connection to be migrated is a regular command with an expiration time, it will not be migrated before the expiration time expires. After the expiration time expires, it will be migrated through S1~S4. If the connection to be migrated is a subscription type connection, then when executing S1~S4 to migrate the connection, S1 and S2 also include: serializing the database-side connection information bound to the connection into a byte stream; If the connection to be migrated is a monitoring type connection, then when executing S1~S4 to migrate the connection, S1 and S2 also include: serializing the database-side connection information bound to the connection into a byte stream.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, including a stored computer program; when the computer program is executed by a processor, it implements the connection migration-based database agent lossless version upgrade method provided by the present invention.
[0019] In summary, the above-described technical solutions conceived in this invention can achieve the following beneficial effects: (1) This invention uses connection migration to upgrade the database proxy middleware version. It can achieve lossless upgrade of the proxy version through smooth cross-process migration of connection states. On this basis, this invention uses eBPF to forcibly modify the kernel's connection allocation strategy, allocating all newly created connections to threads in the new proxy, ensuring that there will be no connection reconstruction failure during the version upgrade, effectively solving the problem of new connection allocation failure in traditional upgrade methods. Overall, this invention can simultaneously solve the problems of new connection allocation failure and high overhead of existing connection migration during the upgrade process, achieving fast, low-overhead, and full-connection version upgrade of the proxy middleware without any awareness of the upper-layer business.
[0020] (2) Based on using eBPF to forcibly modify the kernel's connection allocation strategy, this invention uses a polling method to dynamically calculate the thread number used to execute the new connection task, which can further realize load balancing among new agent threads.
[0021] (3) In this invention, the connection metadata to be migrated is serialized in the old agent, divided into network data packets, and the sendmsg function is called to send the data packets to the new agent via a Unix Socket. At the same time, the new agent calls recvmsg to receive the data packets sent by the old agent via a Unix Socket, thus realizing lightweight connection migration and solving the connection reconstruction bottleneck problem in the traditional rolling upgrade scheme. On this basis, this invention makes the last data packet in a series of data packets corresponding to the same connection carry the descriptor FD as a separator, avoiding the insertion of additional separators in the data stream and eliminating the need for complex boundary scanning at the receiving end, which greatly saves the memory consumed by the total tail identification information of the traditional packet segmentation method.
[0022] (4) In the old agent, the data packets of multiple connections are interleaved and sent, and the data packets of the same connection are sent in sequence, thereby improving the sending efficiency while ensuring that the new agent can accurately rebuild the connection.
[0023] (5) The present invention proposes a multi-level exception handling and retry mechanism, which designs specific identification and handling methods for exceptions that occur in the old agent and the new agent, and can effectively guarantee the atomicity of connection migration and data integrity.
[0024] (6) The present invention designs corresponding migration rules for the specific characteristics of special connections, ensuring that after the special connection is migrated to the new agent, the new agent can complete the connection reconstruction, thus solving the problem of loss of special connection semantics in the traditional rolling upgrade scheme. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of a database proxy lossless version upgrade method based on connection migration provided in an embodiment of the present invention.
[0026] Figure 2 The state transition diagram corresponding to the lossless allocation intervention strategy based on eBPF provided in the embodiments of the present invention.
[0027] Figure 3 This is a sequence diagram for lossless version upgrade of a database agent based on connection migration, provided for an embodiment of the present invention.
[0028] Figure 4 This is a schematic diagram illustrating the file descriptor transfer process provided in an embodiment of the present invention.
[0029] Figure 5 This is a schematic diagram illustrating the screening process before connection migration operations provided in an embodiment of the present invention.
[0030] Figure 6 This is a schematic diagram of a special connection migration provided for an embodiment of the present invention. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0032] In this invention, the terms "first," "second," etc. (if present) in the invention and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0033] To address several issues with existing database proxy version upgrade methods, this invention provides a lossless database proxy version upgrade method and storage medium based on connection migration. Its core concept is to: reconstruct the version upgrade process; ensure lossless connection creation during the upgrade process through eBPF refactoring allocation strategies; complete the transfer of inter-process connection resources through Unix Sockets; and design an efficient connection migration network packet processing mechanism to further reduce the cost and latency of connection migration. Finally, restore and reconstruct the logical information carried by each type of connection to ensure the correctness of connection logic functions on the database proxy middleware before and after the upgrade.
[0034] During the upgrade of the database proxy middleware version, new connection establishment may fail. The reason is that during the entire proxy upgrade process, a new proxy is started to listen on the same port as the old proxy, and then the old proxy's listening port is closed. However, at this time, TCP connections that have undergone handshake but have not been formally established in the TCP half-connection queue and full-connection queue are forced to close. Therefore, from the client's perspective, new connection establishment fails within this time window.
[0035] To address the issue of connection creation failures in existing version upgrade schemes, this invention proposes a lossless connection allocation intervention strategy based on eBPF. This strategy modifies the kernel connection allocation policy using eBPF, ensuring that the modification is completed before the old proxy process shuts down. This guarantees that all new connections are allocated to the new proxy process, preventing connection creation failures within the time window when the old proxy closes its ports. Specifically, a connection allocation trigger and its complete state machine are designed. During the version upgrade operation, the trigger calculates the connection creation process on a specific thread of the proxy and uses eBPF to load code into the kernel to directly modify the kernel connection allocation policy, thus ensuring the correctness and robustness of kernel connection allocation throughout the entire version upgrade process.
[0036] Connection migration refers to the process of transferring control, state information, and related resources of a network connection from one execution entity (process, thread, or host) to another during the connection's lifecycle, while maintaining the connection's transparency to the application; that is, maintaining logical continuity before and after the migration. For middleware like database proxies, it is necessary not only to ensure low transmission overhead and high efficiency, but also to guarantee the correctness of the logical state information stored in various database connections without significant performance impact. Therefore, inspired by existing achievements in connection migration, this invention aims to achieve high transmission efficiency, low transmission latency, and complete connection state maintenance and recovery for database proxy version upgrades.
[0037] Connection reconstruction is the main overhead of traditional methods. The number of system calls to establish new connections during the entire TCP three-way handshake is enormous, and it is impossible to rebuild new connections in batches. In contrast, connection migration-based methods only need to pass the file descriptor representing TCP and then reconstruct the structure, while the latency of transmitting connection information to the same host is extremely low. To avoid the huge system overhead of connection reconstruction, this invention adopts connection migration, which is more efficient and has lower overhead, as the connection handling method to solve the bottleneck problem of existing connections in traditional version upgrade schemes.
[0038] Building upon the above concepts, this invention further considers the potential loss of specific semantics during database proxy middleware version upgrades. Specifically, for database connections, in addition to maintaining the session-level connection state, the application-level connection logic information is also crucial. Each database has special types of connections, carrying several special requests. After a proxy version upgrade, the logical information carried on these connections must be restored to maintain semantic consistency for these special connections. To address the loss of specific semantics in traditional rolling upgrade schemes, this invention further proposes special connection migration rules for special connection types. In addition to migrating ordinary connections, special transmission and information recovery processing are performed on the application-level logical information of special connections to maintain semantic consistency for these special connection types.
[0039] The lossless version upgrade method and storage medium for database proxies based on connection migration provided by this invention can be applied to version upgrades of proxy middleware for any database. Without loss of generality, the following embodiments will use Redis database as an example for illustration.
[0040] The following is an example.
[0041] Example 1: A lossless version upgrade method for database proxies based on connection migration, such as Figure 1 As shown, this includes: lossless allocation intervention strategies based on eBPF.
[0042] Traditional operating system kernels use a default connection allocation strategy that determines the target process or the target thread within a process by deriving a fixed Socket Index from the TCP 5-tuple value. This calculation is fixed and does not dynamically adjust, so during version upgrades, new connections may be assigned to older proxy processes, causing connection creation failures. In this embodiment, the lossless allocation intervention strategy based on eBPF recalculates the Socket Index for each new connection and allows it to cycle within the new proxy's thread number range, rather than continuously decrementing. This adaptively allocates connections to threads in the new proxy, ignoring kernel modifications to thread numbering.
[0043] In this embodiment, the lossless allocation intervention strategy based on eBPF involves switching between multiple states during execution, as shown in the specific state diagram below. Figure 2 As shown, it specifically includes: After system initialization, it enters the normal state; in the normal state, threads for creating new connections are allocated according to the default allocation strategy. Under normal circumstances, upon receiving an upgrade command, the new agent is started and enters the preparation state; in the preparation state, system environment verification is performed, eBPF bytecode is prepared, and system resources required for loading the eBPF program are pre-allocated. In the preparation state, after the system environment verification is passed, it enters the activation state; in the activation state, the eBPF program is loaded, and the thread allocation strategy is modified through the loaded eBPF program so that when a new connection request is received, the task of creating a new connection is allocated to the thread in the new agent in a round-robin manner, and the connections in the old agent are migrated to the new agent. In the active state, when all threads in the old agent are shut down, it enters the monitoring state; in the monitoring state, it checks the health status of each thread in the new agent. In monitoring mode, when the health status of each thread in the new agent meets the requirements, unload the loaded eBPF program, clean up the resources occupied by the eBPF program, and restore the normal state. In any state, if an exception occurs, the system enters a rollback state; in the rollback state, the loaded eBPF program is unloaded, and threads for new connections are allocated according to the default allocation strategy; when the exception is resolved, the system returns to normal. The default allocation strategy allocates threads for creating new connections based on the thread number in the connection's 5-tuple.
[0044] In terms of computational logic, the lossless allocation intervention strategy based on eBPF employs a polling-based dynamic index allocation strategy before the old proxy is shut down. The system maintains a polling pointer `current_pos`, initially set to 0. For each new connection, the kernel assigns it to thread `SI`, where `SI = (N - k) + current_pos`, where N is the number of threads in the old proxy and k is the number of closed old threads. After allocation, the polling pointer is updated to `(current_pos + 1) % M`, where M is the number of new proxy threads. When the old proxy threads are shut down, all thread numbers are adjusted accordingly, but the polling logic remains unchanged, and all threads in the new proxy process can be evenly and fairly allocated to connections. This ensures a strictly uniform distribution of new connections among all threads in the new proxy, achieving load balancing and smooth migration.
[0045] Corresponding to the above calculation logic, in this embodiment, the threads of the old agent and the threads of the new agent are numbered sequentially. Furthermore, in the ready state, it also includes: Initialize the polling pointer to current_pos=0; Furthermore, in the active state, upon receiving a request to establish a new connection, the task of establishing the new connection is assigned to a thread in the new agent in a round-robin manner, including: The thread number SI for creating a new connection is calculated according to SI=(Nk)+current_pos, and the task of creating a new connection is assigned to thread SI. When all connections on a thread in the old agent are migrated to the new agent, that thread is closed, and the thread numbers of all threads are adjusted accordingly so that the threads of the old agent and the threads of the new agent are numbered consecutively, and the polling pointer is updated according to current_pos=(current_pos + 1) %M. Where N is the original number of threads in the old agent, M is the number of threads in the new agent, k is the number of threads that have been closed in the old agent, and "%" represents the modulo operation.
[0046] This embodiment uses eBPF to forcibly modify the kernel's connection allocation strategy, assigning all newly created connections to threads in the new agent, ensuring that connection reconstruction will not fail during version upgrades.
[0047] To achieve connection migration, this embodiment provides a specific proxy version upgrade process based on connection migration. The general process is as follows: A UDS communication channel is established between the old and new proxies. Then, the connections on the old proxy are traversed and file descriptors (FDs) and serialized connection information are sent via UnixSocket. The receiving new proxy deserializes the byte stream to obtain the connection information and restores the connection state based on the FD.
[0048] The aforementioned connection migration version upgrade process involves many challenges and details. Connection migration requires transmitting file descriptors representing unique TCP connections and several characteristic information stored on the connection. Therefore, Unix domain sockets, which support inter-process file descriptor (FD) transfer on the same host, must be chosen as the inter-process communication method. Furthermore, to ensure the efficiency of large-scale connection migration, lightweight and efficient system calls must be used to transmit information. Therefore, this embodiment uses the sendmsg and recvmsg system calls.
[0049] Simultaneously transmitting multiple connection information and handling the concatenation and splitting of multiple network packets presents a challenge. Furthermore, there is no standardized network packet processing template available for connection migration. Therefore, it is necessary to design a network packet processing mechanism suitable for connection migration to encapsulate all control data and metadata during the connection migration process, while simultaneously transmitting FD (File Deposit).
[0050] The reconstructed version upgrade process sequence diagram in this embodiment is as follows: Figure 3 As shown, the general process is as follows: First, the management control service triggers the entire version upgrade operation. The first step is to send a signal to the old proxy to close its management port, maintaining the uniqueness of the management port. Then, the new proxy is started and listens on the same data port and management port as the old proxy. Next, the management control service sends a signal to the old proxy to close its data port, thus rejecting new connection establishments, while old connections remain unaffected. After completing the preparation work, connection transmission begins. The management control service sends a signal to the new proxy to listen on the designated Unix socket port, and then sends a signal to the old proxy to begin migrating its connections. The old proxy sends file descriptors (FDs) and connection information (sessions) via the Unix socket, while the receiving new proxy deserializes the session to obtain the connection information and reconstructs the connection structure based on the FD. After several connection migrations until all connections on the old proxy have been sent, the management control service sends a signal to the new proxy to close the listening Unix socket and a signal to the old proxy to terminate its process. At this point, the entire version upgrade is complete.
[0051] Traditional rolling upgrade schemes can cause connection storms and QPS drops when reconnecting to large numbers of connections. The root cause is that the file descriptors of TCP connections belong to the address space of the old proxy process and cannot be directly accessed by the new proxy. Therefore, passing file descriptors across processes is the fundamental solution. Among the various inter-process communication (IPC) mechanisms provided by the Linux operating system, only the SCM_RIGHTS control message based on Unix domain sockets is the standard solution for passing file descriptors.
[0052] This embodiment utilizes the SCM_RIGHTS feature to maintain the TCP connection state. The transferred file descriptors point to the same kernel socket structure `struct sock`, thus the TCP connection state (ESTABLISHED, sequence number, window size, etc.) can be completely preserved, and socket options (TCP_NODELAY, SO_KEEPALIVE, etc.) do not need to be reconfigured. Regarding data integrity requests on the connection, the kernel receive buffer is used to accept unread data during the migration. After migrating to the new proxy and re-registering the read event, data can be read directly, eliminating issues such as data loss and inconsistency.
[0053] In this embodiment, the UDS SCM_RIGHTS control message is used to transmit file descriptors. The kernel only copies an integer handle and does not involve copying kernel data in the connection buffer, thus achieving true zero-copy migration.
[0054] The essence of file descriptor passing is allocating a new free slot in the receiving process's file descriptor table and pointing that slot to an existing kernel file object. The entire process is completed in kernel space, requiring only a few instructions and one `sendmsg` / `recvmsg` system call pair. The latency for a single file descriptor passing is approximately 0.1~0.5μs, far lower than the millisecond latency of connection reconstruction or the microsecond latency of data forwarding. Furthermore, a single `SCM_RIGHTS` message can carry multiple file descriptors, enabling batch connection migrations and significantly reducing the number of system calls and IPC communication overhead.
[0055] Specifically, such as Figure 4 As shown, in this embodiment, in the active state, migrating connections from the old proxy to the new proxy includes: In the old proxy, for each connection to be migrated, perform the following steps: S1: Serialize the connection metadata to be migrated into a byte stream; For each connection to be migrated, its metadata includes: IP address, port, TCP state, socket options, application layer data, etc. S2: Divide the byte stream into multiple data blocks, with the size of each data block not exceeding the maximum packet length minus the fixed header size; Optionally, in this embodiment, the maximum packet length is 1024 bytes, which is the optimal value obtained from Unix domain socket performance testing; in other embodiments of the present invention, it can also be set to other lengths, such as 1500 bytes. S3: Construct a packet header for each data block, and encapsulate the packet header and data block into a packet; for the last packet, allocate an auxiliary data buffer and fill it with the file descriptor corresponding to the concatenation 5-tuple; S4: Call sendmsg to send data packets to the new agent via Unix Socket; The packet header records the following information: packet length (packet_len), packet type (packet_type), packet sequence number (packet_no), last packet identifier (flags), unique connection identifier (conn_id), and connection type (conn_type). The flags of the packet to which the last data block belongs are 0x01, while the flags of the packets to which other data blocks belong are 0. In this embodiment, the data block and packet header information are combined into a data structure msg_iov. For the last packet, an auxiliary data buffer is allocated, and the file descriptor of the connection is filled in using CMSG_DATA.
[0056] In the new agent, a hash table is maintained, with the connection identifier `conn_id` as the key, to store a list of data blocks currently received for each connection and a bitmap of received packet sequence numbers; `recvmsg` is called repeatedly to receive data packets sent by the old agent via UnixSocket; for each received data packet, the following steps are performed: R1: Parse the packet header to extract the information recorded in the packet header; R2: Find the corresponding connection cache structure based on the parsed conn_id. If it does not exist, create the corresponding connection cache structure. R3: Store the data blocks in the data packet in the corresponding connection cache structure and update the hash table; R4: Determine whether the received data packet is the last data packet in the connection based on the parsed flags. If yes, proceed to R5; otherwise, proceed to R6. R5: Determine whether the sequence numbers of data packets in the same connection are consecutive based on the hash table. If so, concatenate the data blocks in the corresponding connection cache structure in order and then deserialize them to obtain the connection metadata. Extract the file descriptor from the auxiliary data buffer. Reconstruct the connection object using the file descriptor and connection metadata to complete the migration of the connection and remove the corresponding connection information from the hash table. R6: Processing of the current data packet has ended.
[0057] Traditionally, the File Descriptor (FD) carried by SCM_RIGHTS is transmitted as an "out-of-band control message," while connection metadata is transmitted as "in-band ordinary data." In batches and interleaved byte streams, accurately and sequentially re-matching and mapping each individual FD with its corresponding metadata is crucial for reconstructing the connection context. To address this, this embodiment utilizes the file descriptor carrying natural boundary segmentation mechanism in the SCM_RIGHTS feature. This allows the last packet in this series of data packets to carry the FD as a delimiter, avoiding the insertion of additional delimiters into the data stream and eliminating the need for complex boundary scanning at the receiving end. This significantly saves the memory consumed by the total tail identifier information in traditional packet segmentation methods.
[0058] It is easy to understand that if the metadata of a connection is exactly less than or equal to the maximum packet length, then the connection will only send one packet, and the packet will carry the file descriptor (FD). In this embodiment, the current packet_no of each connection is maintained, and the local file descriptor is closed after the last packet is sent (indicating that ownership has been transferred).
[0059] As a preferred implementation, in order to improve transmission efficiency, in this embodiment, in the old agent, data packets of the same connection are sent sequentially, and data packets of multiple connections are sent interleaved.
[0060] This embodiment leverages the Unix domain stream socket's characteristic that the entire message sent by `sendmsg` (including ordinary data and auxiliary data) is transmitted atomically and that the messages maintain their order. Specifically, the sending order of packets within the same connection is strictly maintained, and the receiver receives them in the same order. Packets between different connections may interleave, but they can be correctly grouped using `conn_id`, thus ensuring the sequential transmission of the entire network packet across multiple threads.
[0061] Although Unix domain sockets provide reliable local transmission, meaning that UDS itself implements reliable transmission features such as data consistency guarantees and flow control, message loss or corruption can still occur due to abnormal situations such as application layer process crashes, buffer overflows, and system resource shortages. To ensure the atomicity of migration and data integrity, this embodiment designs a multi-level exception handling and retry mechanism.
[0062] First, for the exception handling of the sending end, there are several common special exception scenarios: (1) Temporary failure retry: If sendmsg returns EAGAIN or EINTR, it means that the socket send buffer is temporarily full or the system call is interrupted by a signal. The sending end will use an exponential backoff strategy to retry, with a maximum of 5 retries. (2) Permanent failure handling: If it still fails after 5 consecutive retries, or returns other fatal errors (such as EPIPE indicating that the other end is closed), it is considered that the batch migration has failed. The sending end will close all file descriptors that have been tried to send this time (to avoid leakage), and mark all connections in the batch as "migration failed". Unmigrated connections will be retained in the old Proxy to continue to serve. Finally, the error log is recorded. (3) Timeout control: The sending end sets a timeout timer for each batch (default 500ms). If no acknowledgment message is received from the receiver before the timeout, the retransmission logic is triggered. The message needs to be reconstructed during retransmission. Before retransmission, it is necessary to ensure that the original file descriptor has not been closed. Otherwise, the migration must be abandoned.
[0063] Secondly, for receiving end exception handling, there are several common special exception scenarios: (1) Message integrity verification: After receiving a message, first verify the packet_len and packet_type headers, then check the order of packet_no and the rationality of subsequent logical fields. If an error is found after several checks, discard the message and send an error response. (2) File descriptor separation verification failure: If the FD is found to be missing during the parsing process, it indicates that the data is corrupted or the connection status is incorrect. The receiver immediately closes all received file descriptors and sends an error response to the sender. (3) Reconstruction failure handling: When reconstructing the connection object, if insufficient resources (such as memory allocation failure) or abnormal connection status (such as TCP being closed) are encountered, the receiver should close the corresponding file descriptor and only send an acknowledgment for the successfully reconstructed connection. For the failed part, the sender needs to decide whether to retransmit or abandon it based on the acknowledgment information.
[0064] During version upgrades, many special commands encounter exceptional situations that require handling. Traditional rolling upgrade solutions cannot handle special connections with complex application-layer contexts, such as those involving transactions, subscriptions, and monitoring. Connection reconstruction can lead to semantic breaks, causing business errors such as transaction rollbacks, message loss, and monitoring failures. This problem is known as the special connection semantic loss problem. Taking Redis database as an example, three special connection semantic loss scenarios and problems are as follows: (1) First, there are transaction-type connections. The corresponding requests are all consecutive requests of the transaction type and are all related to the previous requests. After the rolling version upgrade, several previous commands held on the Proxy have been lost, which means that the result of this transaction must be wrong, which may lead to problems such as data inconsistency.
[0065] (2) Then there are subscription-type connections, and the corresponding requests are all requests that bind the publisher and the subscriber. The client-side connection of the proxy middleware is bound to several database-side connections. After the rolling version upgrade, the binding relationship maintained above it has been lost. At this time, the upper-layer client-side connection continues to publish messages, but the database-side connection can no longer receive the messages, which may lead to data loss and other problems.
[0066] (3) Finally, there is the monitoring type connection. The corresponding request is similar to the subscription type, but the difference is that the monitoring type is a client-side connection bound to a database-side connection, used by the client-side connection to monitor certain data changes in the database. After a rolling version upgrade, the monitoring relationship maintained above it has been lost. At this time, changes to the monitored keys in the database cannot be notified to the upper-layer client, which may lead to problems such as misjudgment in business.
[0067] To address the issue of lost semantics in special connections, this embodiment provides a mechanism for restoring semantic consistency in special connections. This mechanism establishes the following rules for three special connection types: (1) For transaction type connections, refer to the way AWS Proxy handles changes in the backend database. For transaction type commands (such as MULTI), save the sequence of preceding requests and serialize them together before sending them to the new Proxy for restoration.
[0068] (2) For subscription type connections, since each subscription type connection is a publisher corresponding to several subscribers, in addition to the normal connection transmission, the subscription type connection needs to transmit the front-end and back-end connection binding relationship and the file descriptor and connection characteristic information of the back-end database side connection. The above information needs to be serialized together and sent to the new Proxy so that the new Proxy can restore the database side connection and rebuild the binding relationship.
[0069] (3) For monitoring type connections, since each monitoring type connection corresponds to one monitor and one monitored, the logic is similar to that of the subscription type connection. Similarly, monitoring type connections need to additionally transmit the front-end and back-end connection binding relationship, as well as the file descriptor and connection characteristic information of the back-end database side connection. The above information needs to be serialized together and sent to the new Proxy so that the new Proxy can restore the database side connection and rebuild the binding relationship.
[0070] The role of a database proxy is to receive requests sent from client-side connections, forward those requests to the database for processing via a database-side connection, and then retrieve the processing results and return them to the client. This involves two full-duplex data paths: the connection between the client and the proxy process, and the connection between the proxy process and the database.
[0071] For all connections, the basic condition for connection migration is that there are no requests being processed on either of the two data paths of the connection. It's easy to understand that "requests being processed" refers to requests that are currently in the proxy process and have not been successfully transmitted to either end. This includes requests that have already been received by the proxy and are being forwarded to the database, as well as requests that have been received by the proxy but have not yet been responded to by the client. Ensuring that there are no such requests being processed on either path guarantees the data integrity of the connection before and after migration.
[0072] Accordingly, in this embodiment, before migrating the connections in the old agent to the new agent in the active state, the method further includes: determining whether the migration conditions are met; if so, creating multiple lock-free migration queues, each migration queue corresponding to a connection type, and placing each connection in the old agent into the corresponding migration queue according to the connection type; if not, prohibiting migration. The migration conditions include: the request from the client is in the old proxy and has not been successfully passed to the database or the client. In other words, the migration can only occur if there are no requests being processed in the two data paths corresponding to the connection.
[0073] Under the condition that the above migration conditions are met, this embodiment designs additional rules for the four types of connections, as shown in Table 1.
[0074] Table 1
[0075] Based on the migration strategies shown in Table 1, such as Figure 5 As shown, before performing the connection migration operation, this embodiment filters migrateable connections from all connections of the old proxy, removes their read events, stops accepting requests, and adds them to the corresponding migration queue. Connections in the migration queue are then migrated in batches at regular intervals. Accordingly, this embodiment maintains a timer. Whenever the timer expires, all connections in the migration queue are organized into a batch for migration, and the timer is reset to zero.
[0076] In terms of data structure, the core data structures maintained in this embodiment include a connection descriptor table and a migration queue. This embodiment periodically scans the global connection hash table maintained by the old proxy, checks the connection descriptor table entries generated by each active connection, and checks ordinary connections using general rules and special connections using corresponding special rules. Once the check is passed, the connection is added to the migration queue. The migration queue is a lock-free queue. When all connections are added to the queue, read events are removed and requests are stopped. When the timer reaches the preset timeout limit (e.g., 10ms), all connections are batch-processed and sent to the new proxy together.
[0077] The connection migration process combined with migration conditions includes: (1) Traversing the connection table: periodically scanning the global connection hash table maintained by the old proxy, which records the existing connection information in the old proxy. (2) Rule filtering: performing rule checks on each connection in turn: checking the connection liveness status; checking whether there is a request being executed in the connection dual channel; checking whether the connection type is in the macro definition; checking whether the data to be processed in the receive buffer is less than the maximum capacity (to prevent data loss); checking whether the rules corresponding to special connections are met. (3) Classification and queuing: the filtered connections are put into the corresponding migration queue according to their type, and the metadata is recorded at the same time. (4) Triggering migration: when the timer expires, all connections in the queue are passed to the downstream for processing.
[0078] Regarding concurrency and consistency, the main considerations are the state of the connection during the migration process: the threads performing the above operations run concurrently with the business threads, and read-write locks are needed to protect the connection table to prevent the connection from being destroyed during the capture process; secondly, when a connection is enqueued, its reference count in the kernel needs to be increased to prevent it from being accidentally closed before the migration.
[0079] In this embodiment, the connection type is identified by conn_type in the data packet. conn_type is an enumeration type used to represent normal connection, transaction type connection, subscription type connection and monitoring type connection.
[0080] For transactional connections, there are two types of requests above the connection. The first type is a set of preceding commands that are in a transaction but have not yet been committed, which are serialized and sent together with the user-side connection information. The second type is a normal command with an expiration time. This second type is not migrated for the time being. After the backend database returns the processing result after the command expires, the connection can be treated as a normal connection.
[0081] For subscription-type connections, after the user-side connection information is serialized and packetized, the information of the database-side connection bound to that connection must be sent immediately after the front-end connection using the same serialization method and sending method. The new agent identifies the relevant information, deserializes it, and uses the information to reconstruct the database-side connection and complete the restoration of the user-side connection binding.
[0082] Finally, for monitoring type connections, the migration logic is highly similar to that of subscription type connections, both involving the migration and reconstruction of connection binding information, with only some connection logic information differing.
[0083] Accordingly, such as Figure 6As shown, in this embodiment, if the connection to be migrated is a transaction type connection and the request on the connection is in a transaction, then before executing S1~S4 to migrate the connection, it also includes: marking "in progress of transaction" in its metadata and adding the set of pre-committed commands that have not yet been committed to the migration metadata; If the connection to be migrated is a regular command with an expiration time, it will not be migrated before the expiration time expires. After the expiration time expires, it will be migrated through S1~S4. If the connection to be migrated is a subscription type connection, then when executing S1~S4 to migrate the connection, S1 and S2 also include: serializing the database-side connection information bound to the connection into a byte stream; If the connection to be migrated is a monitoring type connection, then when executing S1~S4 to migrate the connection, S1 and S2 also include: serializing the database-side connection information bound to the connection into a byte stream.
[0084] Example 2: A computer-readable storage medium includes a stored computer program; when executed by a processor, the computer program implements the connection migration-based lossless version upgrade method for database agents provided in Embodiment 1 above.
[0085] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A lossless version upgrade method for a database proxy based on connection migration, characterized in that, include: After system initialization, it enters normal operation. Under the normal state, threads for creating new connections are allocated according to the default allocation strategy; In the normal state, upon receiving an upgrade command, the new agent is started and enters the preparation state; in the preparation state, system environment verification is performed, eBPF bytecode is prepared, and system resources required for loading the eBPF program are pre-allocated. In the preparation state, after the system environment verification is passed, it enters the activation state; in the activation state, the eBPF program is loaded, and the thread allocation strategy is modified through the loaded eBPF program so that when a new connection request is received, the task of creating a new connection is allocated to the thread in the new agent in a round-robin manner, and the connection in the old agent is migrated to the new agent. In the active state, when all threads in the old agent are shut down, the system enters the monitoring state. Under the monitoring state, check the health status of each thread in the new agent; In the monitoring state, when the health status of each thread in the new agent meets the requirements, the loaded eBPF program is unloaded, the resources occupied by the eBPF program are cleaned up, and the normal state is restored. In any state, if an exception occurs, the system enters a rollback state; in the rollback state, the loaded eBPF program is unloaded, and threads for creating new connections are allocated according to the default allocation strategy; when the exception is resolved, the system returns to the normal state. The default allocation strategy allocates threads for creating new connections based on the thread number in the connection's quintuple.
2. The database proxy lossless version upgrade method based on connection migration as described in claim 1, characterized in that, The threads of the old agent and the threads of the new agent are numbered sequentially. Furthermore, the prepared state also includes: Initialize the polling pointer to current_pos=0; Furthermore, in the active state, upon receiving a request to establish a new connection, the task of establishing the new connection is assigned to a thread in the new agent in a round-robin manner, including: The thread number SI for creating a new connection is calculated according to SI=(Nk)+current_pos, and the task of creating a new connection is assigned to thread SI. When all connections on a thread in the old agent are migrated to the new agent, that thread is closed, and the thread numbers of all threads are adjusted accordingly so that the threads of the old agent and the threads of the new agent are numbered consecutively, and the polling pointer is updated according to current_pos = (current_pos + 1) %M. Where N is the original number of threads in the old agent, M is the number of threads in the new agent, k is the number of threads that have been closed in the old agent, and "%" represents the modulo operation.
3. The database proxy lossless version upgrade method based on connection migration as described in claim 1, characterized in that, In the activated state, migrating connections from the old proxy to the new proxy includes: In the old agent, for each connection to be migrated, the following steps are performed: S1: Serialize the connection metadata to be migrated into a byte stream; S2: Divide the byte stream into multiple data blocks, with the size of each data block not exceeding the maximum packet length minus the fixed header size; S3: Construct a packet header for each data block, and encapsulate the packet header and data block into a packet; for the last packet, allocate an auxiliary data buffer and fill it with the file descriptor corresponding to the concatenation 5-tuple; S4: Call sendmsg to send data packets to the new agent via Unix Socket; The information recorded in the packet header includes: packet length (packet_len), packet type (packet_type), packet sequence number (packet_no), last packet identifier (flags), unique identifier of the connection (conn_id), and connection type (conn_type). In the new agent, recvmsg is called repeatedly to receive data packets sent by the old agent via Unix Socket. Data blocks in the data packets corresponding to the same connection are concatenated in order and deserialized to obtain connection metadata. File descriptors are extracted from the auxiliary data buffer. The connection object is reconstructed using the file descriptors and connection metadata to complete the migration of the connection.
4. The database proxy lossless version upgrade method based on connection migration as described in claim 3, characterized in that, In the new agent, recvmsg is called repeatedly to receive data packets sent by the old agent through a Unix socket. The data blocks in the data packets corresponding to the same connection are concatenated in order and then deserialized to obtain the connection metadata. Extract the file descriptor from the auxiliary data buffer; The connection object is rebuilt using file descriptors and connection metadata to complete the connection migration, including: Maintain a hash table with connection identifier conn_id as the key to store a list of data blocks currently received for each connection and a bitmap of received packet sequence numbers; repeatedly call recvmsg to receive data packets sent by the old proxy; for each received data packet, perform the following steps: R1: Parse the packet header to extract the information recorded in the packet header; R2: Find the corresponding connection cache structure based on the parsed conn_id. If it does not exist, create the corresponding connection cache structure. R3: Store the data blocks in the data packet in the corresponding connection cache structure and update the hash table; R4: Determine whether the received data packet is the last data packet in the connection based on the parsed flags. If yes, proceed to R5; otherwise, proceed to R6. R5: Determine whether the sequence numbers of data packets in the same connection are consecutive according to the hash table. If so, concatenate the data blocks in the corresponding connection cache structure in order and then deserialize them to obtain connection metadata; extract the file descriptor from the auxiliary data buffer; reconstruct the connection object using the file descriptor and connection metadata to complete the migration of the connection, and remove the corresponding connection information from the hash table. R6: Processing of the current data packet has ended.
5. The database proxy lossless version upgrade method based on connection migration as described in claim 3, characterized in that, In the old agent, data packets for the same connection were sent sequentially, and data packets from multiple connections were sent interleaved.
6. The database proxy lossless version upgrade method based on connection migration as described in claim 5, characterized in that, In the prepared state, it also includes: Send a signal to the old agent to shut down the control port; Send a signal to the new agent to make it listen on the same data port and control port as the old agent; Send a signal to the old agent to shut down its data port; Furthermore, before migrating connections from the old proxy to the new proxy in the activated state, the process also includes: The new agent is signaled to listen on a preset Unix socket port; The old agent sends data packets through the Unix socket port that the new agent is listening on; Furthermore, in the active state, before entering the monitoring state when all threads in the old agent are shut down, the following steps are also included: The new agent is signaled to close the Unix socket port, and the old agent is signaled to shut down its process.
7. The database proxy lossless version upgrade method based on connection migration as described in claim 4, characterized in that, Also includes: The atomicity of connection migration and data integrity are guaranteed by multi-level exception handling and retry mechanisms. The multi-level exception handling and retry mechanism includes: In the old agent: If a temporary error message is returned after calling sendmsg, an exponential backoff strategy will be used to retry, and the number of retries will not exceed the preset retry limit. If a fatal error message is returned after calling sendmsg, or if the retry count reaches the retry limit and the process still fails, the migration of the current batch is determined to have failed. All file descriptors that have been attempted to be sent in the current batch are closed, and all connections in the current batch are marked as "connection failed". Connections that have not been migrated in the current batch are retained in the old proxy and error logs are recorded. If the current batch of migration does not receive a confirmation message from the new agent after the set timeout threshold, it is determined whether the corresponding file descriptor has been closed. If yes, the migration is abandoned; otherwise, S1~S4 are re-executed to retransmit the corresponding connection. In the new agent: If the packet_len and packet_type in the packet header fail to be validated, or if the packet_no of the packets corresponding to the same connection is not consecutive, the received packets are discarded and an error response is sent to the old proxy. If the file descriptor corresponding to the connection is found to be non-existent, all received file descriptors are closed, and an error response is sent to the old agent. If resources are insufficient or the connection status is abnormal when rebuilding the connection object, the corresponding file descriptor is closed, and an acknowledgment response is sent only for successfully rebuilt connections; for connections that fail to rebuild, a retransmission response is sent to the old agent or the rebuild is abandoned.
8. The database proxy lossless version upgrade method based on connection migration as described in any one of claims 1 to 7, characterized in that, Before migrating connections from the old proxy to the new proxy in the active state, the process further includes: determining whether the migration conditions are met; if so, creating multiple lock-free migration queues, each corresponding to a connection type, and placing each connection from the old proxy into the corresponding migration queue according to the connection type; if not, prohibiting migration. Maintain a timer. Whenever the timer expires, organize all connections in the migration queue into a batch, migrate them, and then reset the timer. The migration conditions include: requests from clients are in the old proxy and have not been successfully delivered to the database or the client.
9. The database proxy lossless version upgrade method based on connection migration as described in claim 8, characterized in that, If the connection to be migrated is a transactional connection and the requests on the connection are in a transaction, then before executing S1~S4 to migrate the connection, the following steps are also taken: mark "in progress with transaction" in its metadata and add the set of preceding commands that have not yet been committed to the migration metadata. If the connection to be migrated is a regular command with an expiration time, it will not be migrated before the expiration time expires. After the expiration time expires, it will be migrated through S1~S4. If the connection to be migrated is a subscription type connection, then when executing S1~S4 to migrate the connection, S1 and S2 also include: serializing the database-side connection information bound to the connection into a byte stream; If the connection to be migrated is a monitoring type connection, then when executing S1~S4 to migrate the connection, S1 and S2 also include: serializing the database-side connection information bound to the connection into a byte stream.
10. A computer-readable storage medium, characterized in that, Includes a stored computer program; when the computer program is executed by a processor, it implements the database agent lossless version upgrade method based on connection migration as described in any one of claims 1 to 9.
