diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 9476f6d..8fa4383 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -109,7 +109,7 @@ }, { "ImportPath": "github.com/zr-hebo/util-db", - "Rev": "3ff29f916f7b712b3adc53c4b9b19b13b8bbed87" + "Rev": "06948bca5665b2d80078f9ff5c015eabb43c54f8" }, { "ImportPath": "github.com/zr-hebo/util-http", diff --git a/model/mysql_query_piece.go b/model/mysql_query_piece.go index 19180c5..5ef6791 100644 --- a/model/mysql_query_piece.go +++ b/model/mysql_query_piece.go @@ -62,7 +62,7 @@ func (mqp *MysqlQueryPiece) Bytes() (content []byte) { return mqp.jsonContent } - mqp.jsonContent = marsharQueryPiece(mqp) + mqp.jsonContent = marsharQueryPieceMonopolize(mqp) return mqp.jsonContent } diff --git a/model/query_piece.go b/model/query_piece.go index e0d3a74..80f207d 100644 --- a/model/query_piece.go +++ b/model/query_piece.go @@ -1,13 +1,15 @@ package model import ( - // "github.com/json-iterator/go" "bytes" "encoding/json" + jsoniter "github.com/json-iterator/go" "github.com/pingcap/tidb/util/hack" "time" ) +var jsonIterator = jsoniter.ConfigCompatibleWithStandardLibrary + type QueryPiece interface { String() *string Bytes() []byte @@ -70,7 +72,7 @@ func (bqp *BaseQueryPiece) Bytes() (content []byte) { return bqp.jsonContent } - bqp.jsonContent = marsharQueryPiece(bqp) + bqp.jsonContent = marsharQueryPieceMonopolize(bqp) return bqp.jsonContent } @@ -81,7 +83,7 @@ func (bqp *BaseQueryPiece) GetSQL() (*string) { func (bqp *BaseQueryPiece) Recovery() { } -func marsharQueryPiece(qp interface{}) []byte { +func marsharQueryPieceShareMemory(qp interface{}) []byte { var cacheBuffer = localSliceBufferPool.Dequeue() if len(cacheBuffer) > 0 { panic("there already have bytes in buffer") @@ -95,3 +97,12 @@ func marsharQueryPiece(qp interface{}) []byte { return buffer.Bytes() } + +func marsharQueryPieceMonopolize(qp interface{}) (content []byte) { + content, err := jsonIterator.Marshal(qp) + if err != nil { + return []byte(err.Error()) + } + + return content +} \ No newline at end of file diff --git a/vendor/github.com/zr-hebo/util-db/query_db.go b/vendor/github.com/zr-hebo/util-db/query_db.go index 574ae53..64b0f22 100644 --- a/vendor/github.com/zr-hebo/util-db/query_db.go +++ b/vendor/github.com/zr-hebo/util-db/query_db.go @@ -43,12 +43,14 @@ type MysqlDB struct { DatabaseType string DBName string ConnectTimeout int + QueryTimeout int } // NewMysqlDB 创建MySQL数据库 func NewMysqlDB() (md *MysqlDB) { md = new(MysqlDB) md.DatabaseType = dbTypeMysql + md.QueryTimeout = 5 return } @@ -352,7 +354,7 @@ func (md *MysqlDB) fillConnStr() string { md.UserName, md.Passwd, md.IP, md.Port, md.DBName) if md.ConnectTimeout > 0 { dbServerInfoStr = fmt.Sprintf("%s?timeout=%ds&readTimeout=%ds&writeTimeout=%ds", - dbServerInfoStr, md.ConnectTimeout, md.ConnectTimeout, md.ConnectTimeout) + dbServerInfoStr, md.ConnectTimeout, md.QueryTimeout, md.QueryTimeout) } return dbServerInfoStr diff --git a/vendor/github.com/zr-hebo/util-db/query_pooled_db.go b/vendor/github.com/zr-hebo/util-db/query_pooled_db.go index 051c35d..dbe820e 100644 --- a/vendor/github.com/zr-hebo/util-db/query_pooled_db.go +++ b/vendor/github.com/zr-hebo/util-db/query_pooled_db.go @@ -6,7 +6,6 @@ import ( "time" ) - // PooledMysqlDB Mysql主机实例 type PooledMysqlDB struct { MysqlDB @@ -46,6 +45,7 @@ func NewPooledMysqlDBWithAllParam( func NewPooledMysqlDB() (pmd *PooledMysqlDB) { pmd = new(PooledMysqlDB) pmd.DatabaseType = dbTypeMysql + pmd.QueryTimeout = 5 pmd.lock = new(sync.Mutex) return }