Skip to content

Commit

Permalink
retrieve connection type information
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Aug 13, 2024
1 parent cd95a48 commit b67204a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion go/mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1624,12 +1624,18 @@ func (c *Conn) TLSEnabled() bool {
return c.Capabilities&CapabilityClientSSL > 0
}

// IsUnixSocket returns true if this connection is over a Unix socket.
// IsUnixSocket returns true if the server connection is over a Unix socket.
func (c *Conn) IsUnixSocket() bool {
_, ok := c.listener.listener.(*net.UnixListener)
return ok
}

// IsClientUnixSocket returns true if the client connection is over a Unix socket with the server.
func (c *Conn) IsClientUnixSocket() bool {
_, ok := c.conn.(*net.UnixConn)
return ok
}

// GetRawConn returns the raw net.Conn for nefarious purposes.
func (c *Conn) GetRawConn() net.Conn {
return c.conn
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/connpool/dbconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,5 +600,5 @@ func (dbc *Conn) applySameSetting(ctx context.Context) error {
}

func (dbc *Conn) IsUnixSocket() bool {
return dbc.conn.Conn.IsUnixSocket()
return dbc.conn.IsClientUnixSocket()
}
4 changes: 3 additions & 1 deletion go/vt/vttablet/tabletserver/dt_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func (dte *DTExecutor) Prepare(transactionID int64, dtid string) error {
return nil
}

if !conn.dbConn.Conn.IsUnixSocket() {
// We can only prepare on a Unix socket connection.
// Unix socket are reliable and we can be sure that the connection is not lost with the server after prepare.
if !conn.IsUnixSocket() {
dte.te.txPool.RollbackAndRelease(dte.ctx, conn)
return vterrors.VT10002("cannot prepare the transaction on a network connection")
}
Expand Down
9 changes: 7 additions & 2 deletions go/vt/vttablet/tabletserver/stateful_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (sc *StatefulConnection) IsTainted() bool {
// LogTransaction logs transaction related stats
func (sc *StatefulConnection) LogTransaction(reason tx.ReleaseReason) {
if sc.txProps == nil {
return //Nothing to log as no transaction exists on this connection.
return // Nothing to log as no transaction exists on this connection.
}
sc.txProps.Conclusion = reason.Name()
sc.txProps.EndTime = time.Now()
Expand All @@ -288,7 +288,7 @@ func (sc *StatefulConnection) SetTimeout(timeout time.Duration) {
// logReservedConn logs reserved connection related stats.
func (sc *StatefulConnection) logReservedConn() {
if sc.reservedProps == nil {
return //Nothing to log as this connection is not reserved.
return // Nothing to log as this connection is not reserved.
}
duration := time.Since(sc.reservedProps.StartTime)
username := sc.getUsername()
Expand All @@ -315,3 +315,8 @@ func (sc *StatefulConnection) ApplySetting(ctx context.Context, setting *smartco
func (sc *StatefulConnection) resetExpiryTime() {
sc.expiryTime = time.Now().Add(sc.timeout)
}

// IsUnixSocket returns true if the connection is using a unix socket
func (sc *StatefulConnection) IsUnixSocket() bool {
return sc.dbConn.Conn.IsUnixSocket()
}

0 comments on commit b67204a

Please sign in to comment.