db fail 当前打开连接数
This commit is contained in:
parent
70dbaf72c0
commit
2c131e30c8
|
|
@ -52,7 +52,9 @@ func db(data *conf.Data_Database) (*gorm.DB, func()) {
|
||||||
// SetMaxOpenConns sets the maximum number of openapi connections to the database.
|
// SetMaxOpenConns sets the maximum number of openapi connections to the database.
|
||||||
sqlDB.SetMaxOpenConns(int(data.MaxOpen))
|
sqlDB.SetMaxOpenConns(int(data.MaxOpen))
|
||||||
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
|
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
|
||||||
sqlDB.SetConnMaxLifetime(1 * time.Hour)
|
//sqlDB.SetConnMaxLifetime(1 * time.Hour)
|
||||||
|
sqlDB.SetConnMaxLifetime(7200 * time.Second)
|
||||||
|
sqlDB.SetConnMaxIdleTime(15 * time.Minute)
|
||||||
|
|
||||||
return gormDB, func() {
|
return gormDB, func() {
|
||||||
if mysqlConn != nil {
|
if mysqlConn != nil {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package repoimpl
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
@ -84,9 +85,13 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB
|
||||||
func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) {
|
func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) {
|
||||||
info := &model.Order{}
|
info := &model.Order{}
|
||||||
|
|
||||||
tx := p.DB(ctx).Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).Find(&info)
|
db := p.DB(ctx)
|
||||||
|
tx := db.Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).Find(&info)
|
||||||
|
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
|
sqlDB, _ := db.DB()
|
||||||
|
log.Warnf("order 当前打开连接数: %d ,空闲连接数: ", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
||||||
|
|
||||||
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package repoimpl
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
err2 "voucher/api/err"
|
err2 "voucher/api/err"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
|
|
@ -29,9 +30,13 @@ func (p *ProductRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error) {
|
func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error) {
|
||||||
var item model.Product
|
var item model.Product
|
||||||
|
|
||||||
tx := r.DB(ctx).Where(model.Product{ProductNo: PNO}).Find(&item)
|
db := r.DB(ctx)
|
||||||
|
tx := db.Where(model.Product{ProductNo: PNO}).Find(&item)
|
||||||
|
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
|
sqlDB, _ := db.DB()
|
||||||
|
log.Warnf("当前打开连接数: %d ,空闲连接数: ", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
||||||
|
|
||||||
return nil, fmt.Errorf("product db fail %w", tx.Error)
|
return nil, fmt.Errorf("product db fail %w", tx.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue