fix: resolve concurrent read/write issue in model meta data (#2359)
This commit is contained in:
@ -76,26 +76,26 @@ func initOldModelConf(ctx context.Context, oss storage.Storage, c *ModelConfig)
|
||||
}
|
||||
}
|
||||
|
||||
for _, m := range oldModels {
|
||||
if m.ID <= 0 {
|
||||
logs.CtxWarnf(ctx, "model id is invalid, model: %v", m.ID)
|
||||
for _, old := range oldModels {
|
||||
if old.ID <= 0 {
|
||||
logs.CtxWarnf(ctx, "model id is invalid, model: %v", old.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
_, err := c.getModelByID(ctx, m.ID)
|
||||
_, err := c.getModelByID(ctx, old.ID)
|
||||
if err == nil {
|
||||
logs.CtxInfof(ctx, "model id %d - %s already exists", m.ID, m.DisplayInfo.Name)
|
||||
logs.CtxInfof(ctx, "model id %d - %s already exists", old.ID, old.DisplayInfo.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
id, err1 := c.createModel(ctx, &m.ID,
|
||||
m.Provider.ModelClass, m.DisplayInfo.Name, m.Connection, &ModelExtra{EnableBase64URL: false})
|
||||
id, err1 := c.createModel(ctx, &old.ID,
|
||||
old.Provider.ModelClass, old.DisplayInfo.Name, old.Connection, &ModelExtra{EnableBase64URL: false})
|
||||
if err1 != nil {
|
||||
return fmt.Errorf("sync old model to db failed, err: %w", err1)
|
||||
}
|
||||
|
||||
logs.CtxInfof(ctx, "sync old model id %d - %s to db success, new id: %d", m.ID, m.DisplayInfo.Name, id)
|
||||
logs.CtxInfof(ctx, "sync old model id %d - %s to db success, new id: %d ", old.ID, old.DisplayInfo.Name, id)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -242,7 +242,6 @@ func (c *ModelConfig) SetDoNotUseOldModelConf(ctx context.Context) error {
|
||||
|
||||
func toNewModel(old *OldModel) (*Model, error) {
|
||||
// to new model, old: {"ID":68010,"Name":"Test_Ollama_Qwen2.5vl-7b","Description":{"zh":"ollama 模型简介","en":"ollama model description"},"Meta":{"Protocol":"ollama","ConnConfig":null}}
|
||||
logs.Debugf("to new model, old: %v", conv.DebugJsonToStr(old))
|
||||
modelClass := strProtocolToModelClass(old.Meta.Protocol)
|
||||
provider, _ := GetModelProvider(modelClass)
|
||||
|
||||
@ -271,9 +270,7 @@ func toNewModel(old *OldModel) (*Model, error) {
|
||||
},
|
||||
}
|
||||
|
||||
if old.Name != "" {
|
||||
m.DisplayInfo.Name = old.Name
|
||||
}
|
||||
|
||||
if modelMeta.Connection != nil {
|
||||
m.Connection.Ark = modelMeta.Connection.Ark
|
||||
@ -285,6 +282,9 @@ func toNewModel(old *OldModel) (*Model, error) {
|
||||
m.Connection.Claude = modelMeta.Connection.Claude
|
||||
}
|
||||
|
||||
logs.Debugf("to new model, old: %v \n new %v",
|
||||
conv.DebugJsonToStr(old), conv.DebugJsonToStr(m))
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
|
||||
config "github.com/coze-dev/coze-studio/backend/api/model/admin/config"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/developer_api"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
@ -71,15 +73,28 @@ func (c *ModelMetaConf) GetModelMeta(modelClass developer_api.ModelClass, modelN
|
||||
modelMeta, ok := modelName2Meta[modelName]
|
||||
if ok {
|
||||
logs.Infof("get model meta for model class %v and model name %v", modelClass, modelName)
|
||||
return &modelMeta, nil
|
||||
return deepCopyModelMeta(&modelMeta)
|
||||
}
|
||||
|
||||
const defaultKey = "default"
|
||||
modelMeta, ok = modelName2Meta[defaultKey]
|
||||
if ok {
|
||||
logs.Infof("use default model meta for model class %v and model name %v", modelClass, modelName)
|
||||
return &modelMeta, nil
|
||||
return deepCopyModelMeta(&modelMeta)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("model meta not found for model class %v and model name %v", modelClass, modelName)
|
||||
}
|
||||
|
||||
func deepCopyModelMeta(meta *ModelMeta) (*ModelMeta, error) {
|
||||
if meta == nil {
|
||||
return nil, nil
|
||||
}
|
||||
newObj := &ModelMeta{}
|
||||
err := copier.CopyWithOption(newObj, meta, copier.Option{DeepCopy: true, IgnoreEmpty: true})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error copy model meta: %w", err)
|
||||
}
|
||||
|
||||
return newObj, nil
|
||||
}
|
||||
|
||||
@ -42,15 +42,15 @@ func GetBuiltinChatModel(ctx context.Context, envPrefix string) (bcm BaseChatMod
|
||||
}
|
||||
|
||||
model, err := config.ModelConf().GetBuiltinChatModelConfig(ctx, knowledgeConf.BuiltinModelID)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("get builtin chat model config failed: %w", err)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
bcm, err = BuildModelWithConf(ctx, model)
|
||||
if err == nil {
|
||||
ctxcache.Store(ctx, ctxCacheKey, bcm)
|
||||
return bcm, true, nil
|
||||
}
|
||||
} else {
|
||||
logs.CtxWarnf(ctx, "GetBuiltinChatModelConfig failed : %v", err)
|
||||
}
|
||||
|
||||
modelList, err := config.ModelConf().GetOnlineModelList(ctx)
|
||||
if err != nil {
|
||||
|
||||
@ -16,7 +16,7 @@ RUN npm config set registry https://registry.npmmirror.com
|
||||
COPY rush.json ./
|
||||
|
||||
# Install rush with retry logic
|
||||
RUN npm install -g @microsoft/rush
|
||||
RUN npm install -g @microsoft/rush --registry=https://registry.npmjs.org
|
||||
|
||||
# Copy the frontend source code (excluding node_modules and build artifacts)
|
||||
COPY frontend/ ./frontend/
|
||||
|
||||
Reference in New Issue
Block a user