mirror of https://github.com/jackc/pgx.git
Conn.PID accessed through method
parent
e871ccfca2
commit
ec513248ac
11
conn.go
11
conn.go
|
@ -48,7 +48,7 @@ type Conn struct {
|
|||
reader *bufio.Reader // buffered reader to improve read performance
|
||||
wbuf [1024]byte
|
||||
writeBuf WriteBuf
|
||||
PID int32 // backend pid
|
||||
pid int32 // backend pid
|
||||
SecretKey int32 // key to use to send a cancel query message to the server
|
||||
RuntimeParams map[string]string // parameters that have been reported by the server
|
||||
PgTypes map[OID]PgType // oids to PgTypes
|
||||
|
@ -381,6 +381,11 @@ func (c *Conn) loadInetConstants() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// PID returns the backend PID for this connection.
|
||||
func (c *Conn) PID() int32 {
|
||||
return c.pid
|
||||
}
|
||||
|
||||
// Close closes a connection. It is safe to call Close on a already closed
|
||||
// connection.
|
||||
func (c *Conn) Close() (err error) {
|
||||
|
@ -1140,7 +1145,7 @@ func (c *Conn) rxErrorResponse(r *msgReader) (err PgError) {
|
|||
}
|
||||
|
||||
func (c *Conn) rxBackendKeyData(r *msgReader) {
|
||||
c.PID = r.readInt32()
|
||||
c.pid = r.readInt32()
|
||||
c.SecretKey = r.readInt32()
|
||||
}
|
||||
|
||||
|
@ -1251,7 +1256,7 @@ func (c *Conn) shouldLog(lvl int) bool {
|
|||
}
|
||||
|
||||
func (c *Conn) log(lvl int, msg string, ctx ...interface{}) {
|
||||
if c.PID != 0 {
|
||||
if c.pid != 0 {
|
||||
ctx = append(ctx, "pid", c.PID)
|
||||
}
|
||||
|
||||
|
|
|
@ -428,7 +428,7 @@ func TestPoolReleaseDiscardsDeadConnections(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
if _, err = c2.Exec("select pg_terminate_backend($1)", c1.PID); err != nil {
|
||||
if _, err = c2.Exec("select pg_terminate_backend($1)", c1.PID()); err != nil {
|
||||
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
|
||||
}
|
||||
|
||||
|
@ -599,7 +599,7 @@ func TestConnPoolBeginRetry(t *testing.T) {
|
|||
pool.Release(victimConn)
|
||||
|
||||
// Terminate connection that was released to pool
|
||||
if _, err = killerConn.Exec("select pg_terminate_backend($1)", victimConn.PID); err != nil {
|
||||
if _, err = killerConn.Exec("select pg_terminate_backend($1)", victimConn.PID()); err != nil {
|
||||
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ func TestConnPoolBeginRetry(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("tx.QueryRow Scan failed: %v", err)
|
||||
}
|
||||
if txPID == victimConn.PID {
|
||||
if txPID == victimConn.PID() {
|
||||
t.Error("Expected txPID to defer from killed conn pid, but it didn't")
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestConnect(t *testing.T) {
|
|||
t.Error("Runtime parameters not stored")
|
||||
}
|
||||
|
||||
if conn.PID == 0 {
|
||||
if conn.PID() == 0 {
|
||||
t.Error("Backend PID not stored")
|
||||
}
|
||||
|
||||
|
@ -1255,7 +1255,7 @@ func TestFatalRxError(t *testing.T) {
|
|||
}
|
||||
defer otherConn.Close()
|
||||
|
||||
if _, err := otherConn.Exec("select pg_terminate_backend($1)", conn.PID); err != nil {
|
||||
if _, err := otherConn.Exec("select pg_terminate_backend($1)", conn.PID()); err != nil {
|
||||
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
|
||||
}
|
||||
|
||||
|
@ -1281,7 +1281,7 @@ func TestFatalTxError(t *testing.T) {
|
|||
}
|
||||
defer otherConn.Close()
|
||||
|
||||
_, err = otherConn.Exec("select pg_terminate_backend($1)", conn.PID)
|
||||
_, err = otherConn.Exec("select pg_terminate_backend($1)", conn.PID())
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
|
||||
}
|
||||
|
|
2
v3.md
2
v3.md
|
@ -16,6 +16,8 @@ Replace BeginIso with BeginEx. BeginEx adds support for read/write mode and defe
|
|||
|
||||
Transaction isolation level constants are now typed strings instead of bare strings.
|
||||
|
||||
Conn.Pid changed to accessor method Conn.PID()
|
||||
|
||||
## TODO / Possible / Investigate
|
||||
|
||||
Organize errors better
|
||||
|
|
Loading…
Reference in New Issue