MCPcopy Create free account
hub / github.com/apecloud/myduckserver / HandleConnection

Method HandleConnection

pgserver/connection_handler.go:128–184  ·  view source on GitHub ↗

HandleConnection handles a connection's session, reading messages, executing queries, and sending responses. Expected to run in a goroutine per connection.

()

Source from the content-addressed store, hash-verified

126}
127
128// Set this env var to disable panic handling in the connection, which is useful when debugging a panic
129const disablePanicHandlingEnvVar = "DOLT_PGSQL_PANIC"
130
131// HandlePanics determines whether panics should be handled in the connection handler. See |disablePanicHandlingEnvVar|.
132var HandlePanics = true
133
134func init() {
135 if _, ok := os.LookupEnv(disablePanicHandlingEnvVar); ok {
136 HandlePanics = false
137 }
138}
139
140// NewConnectionHandler returns a new ConnectionHandler for the connection provided
141func NewConnectionHandler(conn net.Conn, handler mysql.Handler, engine *gms.Engine, sm *server.SessionManager, connID uint32, server *Server, readOnly bool) *ConnectionHandler {
142 mysqlConn := &mysql.Conn{
143 Conn: conn,
144 PrepareData: make(map[uint32]*mysql.PrepareData),
145 }
146 mysqlConn.ConnectionID = connID
147
148 // Postgres has a two-stage procedure for prepared queries. First the query is parsed via a |Parse| message, and
149 // the result is stored in the |preparedStatements| map by the name provided. Then one or more |Bind| messages
150 // provide parameters for the query, and the result is stored in |portals|. Finally, a call to |Execute| executes
151 // the named portal.
152 preparedStatements := make(map[string]PreparedStatementData)
153 portals := make(map[string]PortalData)
154
155 // TODO: possibly should define engine and session manager ourselves
156 // instead of depending on the GetRunningServer method.
157 duckHandler := &DuckHandler{
158 e: engine,
159 sm: sm,
160 readTimeout: 0, // cfg.ConnReadTimeout,
161 encodeLoggedQuery: false, // cfg.EncodeLoggedQuery,
162 }
163
164 connectionHandler := ConnectionHandler{
165 mysqlConn: mysqlConn,
166 preparedStatements: preparedStatements,
167 portals: portals,
168 duckHandler: duckHandler,
169 backend: pgproto3.NewBackend(conn, conn),
170 pgTypeMap: pgtype.NewMap(),
171 txStatus: ReadyForQueryTransactionIndicator_Idle,
172
173 server: server,
174 readOnly: readOnly,
175 logger: logrus.WithFields(logrus.Fields{
176 "connectionID": connID,
177 "protocol": "pg",
178 }),
179 }
180 connectionHandler.duckHandler.SetConnectionHandler(&connectionHandler)
181 return &connectionHandler
182}
183
184// readyForQueryStatus returns a valid PostgreSQL transaction indicator. Keep
185// the zero value usable for tests and for any handler constructed without the

Callers 1

AcceptMethod · 0.95

Calls 8

endOfMessagesMethod · 0.95
closeBackendConnMethod · 0.95
ConnMethod · 0.95
handleStartupMethod · 0.95
receiveMessageMethod · 0.95
ConnectionClosedMethod · 0.65
CloseMethod · 0.65
NewConnectionMethod · 0.65

Tested by

no test coverage detected