Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0266cf4b
authored
Jan 12, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复渠道一致性问题
parent
aa8b722a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
2 deletions
+5
-2
middleware/distributor.go
+2
-0
model/ability.go
+1
-0
model/cache.go
+2
-2
No files found.
middleware/distributor.go
View file @
0266cf4b
...
...
@@ -101,10 +101,12 @@ func Distribute() func(c *gin.Context) {
channel
,
err
=
model
.
CacheGetRandomSatisfiedChannel
(
userGroup
,
modelRequest
.
Model
)
if
err
!=
nil
{
message
:=
fmt
.
Sprintf
(
"当前分组 %s 下对于模型 %s 无可用渠道"
,
userGroup
,
modelRequest
.
Model
)
// 如果错误,但是渠道不为空,说明是数据库一致性问题
if
channel
!=
nil
{
common
.
SysError
(
fmt
.
Sprintf
(
"渠道不存在:%d"
,
channel
.
Id
))
message
=
"数据库一致性已被破坏,请联系管理员"
}
// 如果错误,而且渠道为空,说明是没有可用渠道
abortWithMessage
(
c
,
http
.
StatusServiceUnavailable
,
message
)
return
}
...
...
model/ability.go
View file @
0266cf4b
...
...
@@ -159,5 +159,6 @@ func FixAbility() (int, error) {
count
++
}
}
InitChannelCache
()
return
count
,
nil
}
model/cache.go
View file @
0266cf4b
...
...
@@ -258,8 +258,8 @@ func CacheGetRandomSatisfiedChannel(group string, model string) (*Channel, error
return
channel
,
nil
}
}
// return
the last channel if no channel is
found
return
channels
[
endIdx
-
1
],
nil
// return
null if no channel is not
found
return
nil
,
errors
.
New
(
"channel not found"
)
}
func
CacheGetChannel
(
id
int
)
(
*
Channel
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment