mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
启动时自动设置MySQL的max_prepared_stmt_count为65535
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
@@ -25,6 +26,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -55,6 +57,14 @@ func (this *APINode) Start() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动设置数据库
|
||||||
|
err = this.setupDB()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[API_NODE]setup database '" + err.Error() + "'")
|
||||||
|
|
||||||
|
// 不阻断执行
|
||||||
|
}
|
||||||
|
|
||||||
// 数据库通知启动
|
// 数据库通知启动
|
||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
@@ -286,6 +296,34 @@ func (this *APINode) autoUpgrade() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动设置数据库
|
||||||
|
func (this *APINode) setupDB() error {
|
||||||
|
db, err := dbs.Default()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调整预处理语句数量
|
||||||
|
{
|
||||||
|
result, err := db.FindOne("SHOW VARIABLES WHERE variable_name='max_prepared_stmt_count'")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
value := result.GetString("Value")
|
||||||
|
if regexp.MustCompile(`^\d+$`).MatchString(value) {
|
||||||
|
valueInt := types.Int(value)
|
||||||
|
if valueInt < 65535 {
|
||||||
|
_, err := db.Exec("SET GLOBAL max_prepared_stmt_count=65535")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 启动端口
|
// 启动端口
|
||||||
func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) {
|
||||||
// HTTP
|
// HTTP
|
||||||
|
|||||||
Reference in New Issue
Block a user