diff --git a/go/mysql/conn.go b/go/mysql/conn.go index d61549c92ef..9164e658111 100644 --- a/go/mysql/conn.go +++ b/go/mysql/conn.go @@ -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 diff --git a/go/vt/vttablet/tabletserver/connpool/dbconn.go b/go/vt/vttablet/tabletserver/connpool/dbconn.go index 18476adfc3f..61816b16d08 100644 --- a/go/vt/vttablet/tabletserver/connpool/dbconn.go +++ b/go/vt/vttablet/tabletserver/connpool/dbconn.go @@ -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() } diff --git a/go/vt/vttablet/tabletserver/dt_executor.go b/go/vt/vttablet/tabletserver/dt_executor.go index c7d91af5b6c..1fd1df12d56 100644 --- a/go/vt/vttablet/tabletserver/dt_executor.go +++ b/go/vt/vttablet/tabletserver/dt_executor.go @@ -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") } diff --git a/go/vt/vttablet/tabletserver/stateful_connection.go b/go/vt/vttablet/tabletserver/stateful_connection.go index 067f2194655..9b34cfce737 100644 --- a/go/vt/vttablet/tabletserver/stateful_connection.go +++ b/go/vt/vttablet/tabletserver/stateful_connection.go @@ -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() @@ -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() @@ -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() +}