如果数据库连接闲置一段时间,HPE Vertica(天蓝色市场)查询会在没有任何响应的情况下卡住

时间:2017-08-08 11:36:24

标签: sql azure go odbc vertica

我一直在尝试启动使用vertica存储数据的服务器。所以我将数据库指针传递给http handler func。它最初工作一两分钟,但在一段时间后甚至没有响应。

Pupil.order('level = 2 DESC, level = 0 DESC, level = 1 DESC, id ASC').collect { |pupil| [pupil.id, pupil.level] }
# Pupil Load (0.9ms)  SELECT "pupils".* FROM "pupils" ORDER BY level = 2 DESC, level = 0 DESC, level = 1 DESC, id ASC
# => [[4, "level_1"], [5, "level_1"], [6, "level_1"], [8, "level_1"], [2, "level_2"], [7, "level_2"], [1, "level_3"], [3, "level_3"], [9, "level_3"], [10, "level_3"]]

我在linux(ubuntu)中运行这个服务器

//main func runs perfectly fine
func main() {
    //ODBC connection to vertica via DSN
    db, err := sql.Open("odbc", "DSN=HPVerticaDSN")
    if err != nil {
        panic(err)
    }
    defer db.Close()

    if err := db.Ping(); err != nil {
        fmt.Printf("ping err: %v", err)
    }

    //start gin
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        handler(c, db)
    })
    r.Run() // listen and serve on 0.0.0.0:8080
}

我上面的 GO 代码http服务器正在运行。它在第一分钟或第二分钟时完美运行,如果我执行 / ping GET请求一段时间后,则无法从vertica数据库中获得响应。它停留在 tx,错误:= db.Begin()

最后它给出了这个错误:

  

SQLSetConnectUIntPtrAttr:{HY000} [Vertica] [DSI]尝试检索密钥“VPropertySetFailed”和组件ID 101的错误消息时发生错误:无法打开错误消息文件 - 请检查“/ opt / vertica / opt /vertica/lib64/en-US/VerticaMessages.xml“或”/opt/vertica/opt/vertica/lib64/VerticaMessages_en-US.xml“存在且可访问。 MessageParameters = [“无法从服务器接收数据:连接超时   “]

但是如果我在处理程序函数中创建或打开一个连接,那么它会在每个请求上创建一个新连接,然后就可以正常工作

插入查询成功时

ODBC跟踪:

//handler func is a http handler for '/ping' get request
func handler(c *gin.Context, db *sql.DB) {
    //start transaction
    tx, err := db.Begin()
    //it is here where the process gets stuck after a while
    if err != nil {
        log.Printf("tx begin error: %v", err)
        return
    }
    defer func() {
        if err != nil {
            log.Printf("error sql: %v", err)
            tx.Rollback()
            return
        }
        err = tx.Commit()
        if err != nil {
            log.Printf("commit err: %v", err)
        }
    }()
    fmt.Println("start prepare statment")
    stmt, err := tx.Prepare("insert /*+direct*/ into events (id, game_id, created_at) values(?,?,?)")
    if err != nil {
        log.Printf("Insert prepare statement: %v", err)
        c.JSON(500, gin.H{
            "message": err.Error(),
        })
        return
    }
    fmt.Println("exec prepare statment start...")
    res, err := stmt.Exec(uuid.NewV4().String(), uuid.NewV4().String(), time.Now().Format(time.RFC3339))
    if err != nil {
        fmt.Printf("Insert record: %v", err)
        return
    }
    defer stmt.Close()
    fmt.Println("exec prepare statment end")
    num, err := res.RowsAffected()
    if err != nil {
        fmt.Printf("Rows affected err: %v", err)
        return
    }
    if num != 1 {
        fmt.Printf("Rows affected: %v, must be 1", num)
        err = errors.New("Rows affected must be 1")
        return
    }
    c.JSON(200, gin.H{
        "message": "pong",
    })
}
插入查询无响应时

ODBC跟踪:

[ODBC][61608][1502281990.419123][SQLSetConnectAttr.c][842]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.643292][SQLSetConnectAttr.c][396]
        Entry:
            Connection = 0x7f71840008c0
            Attribute = SQL_ATTR_AUTOCOMMIT
            Value = (nil)
            StrLen = -5
[ODBC][61608][1502282121.644409][SQLSetConnectAttr.c][842]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.644794][SQLAllocHandle.c][540]
        Entry:
            Handle Type = 3
            Input Handle = 0x7f71840008c0
[ODBC][61608][1502282121.644996][SQLAllocHandle.c][1085]
        Exit:[SQL_SUCCESS]
            Output Handle = 0x5564cb6408e0
[ODBC][61608][1502282121.645018][SQLPrepareW.c][165]
        Entry:
            Statement = 0x5564cb6408e0
            SQL = [insert /*+direct*/ into events (.....][length = 147 (SQL_NTS)]
[ODBC][61608][1502282121.649229][SQLPrepareW.c][346]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.649256][SQLNumParams.c][144]
        Entry:
            Statement = 0x5564cb6408e0
            Param Count = 0xc4201d0f0e
[ODBC][61608][1502282121.649266][SQLNumParams.c][231]
        Exit:[SQL_SUCCESS]
            Count = 0xc4201d0f0e -> 8
[ODBC][61608][1502282121.649274][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 1
            SQL Type = 0xc4200ba600
            Param Def = 0xc4200ba608
            Scale = 0xc4200ba602
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649284][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649290][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 2
            SQL Type = 0xc4200ba630
            Param Def = 0xc4200ba638
            Scale = 0xc4200ba632
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649296][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649302][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 3
            SQL Type = 0xc4200ba660
            Param Def = 0xc4200ba668
            Scale = 0xc4200ba662
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649308][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649313][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 4
            SQL Type = 0xc4200ba690
            Param Def = 0xc4200ba698
            Scale = 0xc4200ba692
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649319][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649324][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 5
            SQL Type = 0xc4200ba6c0
            Param Def = 0xc4200ba6c8
            Scale = 0xc4200ba6c2
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649330][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649335][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 6
            SQL Type = 0xc4200ba6f0
            Param Def = 0xc4200ba6f8
            Scale = 0xc4200ba6f2
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649341][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649347][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 7
            SQL Type = 0xc4200ba720
            Param Def = 0xc4200ba728
            Scale = 0xc4200ba722
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649360][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.649365][SQLDescribeParam.c][185]
        Entry:
            Statement = 0x5564cb6408e0
            Parameter Number = 8
            SQL Type = 0xc4200ba750
            Param Def = 0xc4200ba758
            Scale = 0xc4200ba752
            Nullable = 0xc4201d0f40
[ODBC][61608][1502282121.649371][SQLDescribeParam.c][341]
        Exit:[SQL_SUCCESS]                
            SQL Type = 0x7ffd05d6ad80                
            Param Def = 0x7ffd05d6ae70                
            Scale = 0x7ffd05d6af60                
            Nullable = 0x7ffd05d6b050
[ODBC][61608][1502282121.650523][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 1
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = -8 SQL_WCHAR
            Col Def = 36
            Scale = 0
            Rgb Value = 0xc42004df40
            Value Max = 72
            StrLen Or Ind = 0xc4200ba628
[ODBC][61608][1502282121.650546][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650557][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 2
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = -9 SQL_WVARCHAR
            Col Def = 24
            Scale = 0
            Rgb Value = 0xc4201df180
            Value Max = 48
            StrLen Or Ind = 0xc4200ba658
[ODBC][61608][1502282121.650569][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650585][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 3
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = -8 SQL_WCHAR
            Col Def = 36
            Scale = 0
            Rgb Value = 0xc42004df90
            Value Max = 72
            StrLen Or Ind = 0xc4200ba688
[ODBC][61608][1502282121.650593][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650600][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 4
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = -9 SQL_WVARCHAR
            Col Def = 10
            Scale = 0
            Rgb Value = 0xc4201d3200
            Value Max = 20
            StrLen Or Ind = 0xc4200ba6b8
[ODBC][61608][1502282121.650607][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650614][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 5
            Param Type = 1
            C Type = 4 SQL_C_LONG
            SQL Type = 4 SQL_INTEGER
            Col Def = 4
            Scale = 0
            Rgb Value = 0xc4201d1000
            Value Max = 0
            StrLen Or Ind = (nil)
[ODBC][61608][1502282121.650627][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650636][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 6
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = -9 SQL_WVARCHAR
            Col Def = 11
            Scale = 0
            Rgb Value = 0xc4201d3240
            Value Max = 22
            StrLen Or Ind = 0xc4200ba718
[ODBC][61608][1502282121.650642][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650650][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 7
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = 93 SQL_TYPE_TIMESTAMP
            Col Def = 20
            Scale = 0
            Rgb Value = 0xc4201f0180
            Value Max = 40
            StrLen Or Ind = 0xc4200ba748
[ODBC][61608][1502282121.650656][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650663][SQLBindParameter.c][217]
        Entry:
            Statement = 0x5564cb6408e0
            Param Number = 8
            Param Type = 1
            C Type = -8 SQL_C_WCHAR
            SQL Type = 93 SQL_TYPE_TIMESTAMP
            Col Def = 20
            Scale = 0
            Rgb Value = 0xc4201f01b0
            Value Max = 40
            StrLen Or Ind = 0xc4200ba778
[ODBC][61608][1502282121.650670][SQLBindParameter.c][422]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.650676][SQLExecute.c][187]
        Entry:
            Statement = 0x5564cb6408e0
[ODBC][61608][1502282121.678544][SQLExecute.c][357]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.678624][SQLRowCount.c][173]
        Entry:
            Statement = 0x5564cb6408e0
            Row Count = 0xc4201d1008
[ODBC][61608][1502282121.678643][SQLRowCount.c][247]
        Exit:[SQL_SUCCESS]
            Row Count = 0xc4201d1008 -> 1
[ODBC][61608][1502282121.678845][SQLFreeHandle.c][381]
        Entry:
            Handle Type = 3
            Input Handle = 0x5564cb6408e0
[ODBC][61608][1502282121.695732][SQLFreeHandle.c][494]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.695847][SQLEndTran.c][417]
        Entry:                
            Connection = 0x7f71840008c0                
            Completion Type = 0
[ODBC][61608][1502282121.702404][SQLEndTran.c][566]
        Exit:[SQL_SUCCESS]
[ODBC][61608][1502282121.702506][SQLSetConnectAttr.c][396]
        Entry:
            Connection = 0x7f71840008c0
            Attribute = SQL_ATTR_AUTOCOMMIT
            Value = 0x1
            StrLen = -5
[ODBC][61608][1502282121.702962][SQLSetConnectAttr.c][842]
        Exit:[SQL_SUCCESS]

0 个答案:

没有答案