Connection Lifecycle
The connection lifecycle is the process of establishing a connection between a client and a server. This process is initiated by the client and is completed when the client disconnects from the server. In doing so, the client and server exchange data, in the form of queries and responses, which are sent over the connection and processed by the GatewayD and its plugins.
The connection lifecycle is composed of the following steps:
- GatewayD starts with a pool of client connections to database server.
- The database client initiates a connection to the GatewayD.
- GatewayD accepts the connection and assigns it to a client connection.
- The client sends a query to the GatewayD.
- GatewayD proxies (forwards) the query to the database server.
- GatewayD receives the response from the database server.
- GatewayD sends the response to the client.
- Database client disconnects from GatewayD.
- The client connection closes and a new client connection is created.
- The new client connection is added to the pool of client connections.
- The process repeats from step 2.
The above steps are partially illustrated in traffic handling diagram of the proxies page.
Connection lifecycle diagram
sequenceDiagram
participant Database Client
participant Server
participant Proxy
participant Pool
participant Client
participant Plugins
participant Database Server
Database Client->>+Server: Connect
Server->>Plugins: OnOpening (notification)
Server->>Proxy: Connect
Proxy->>Pool: Get a connected client
Pool->>Proxy: Here is a client
Proxy->>Server: Connected
Server->>Plugins: OnOpened (notification)
Server->>Database Client: Connected
Database Client->>Server: Authenticate/Query
Server->>Plugins: OnTraffic (notification)
Server->>Proxy: Incoming traffic
Proxy->>Pool: Get connected client
Proxy->>Plugins: OnTrafficFromClient (traffic)
Proxy->>Client: Send auth/query data to database server
Client->>Database Server: Send auth/query data to database server
Proxy->>Plugins: OnTrafficToServer (traffic)
Database Server->>Client: Receive auth/query response from database server
Client->>Proxy: Received auth/query response from database server
Proxy->>Plugins: OnTrafficFromServer (traffic)
Proxy->>Server: Send auth/query response to database client
Server->>Database Client: Send auth/query response to database client
Proxy->>Plugins: OnTrafficToClient (traffic)