mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
fix: 防止给v强转int时溢出,导致取余结果为负,从而获取到错误的index
This commit is contained in:
parent
090d749dc4
commit
894682fcde
@ -38,7 +38,7 @@ var (
|
||||
type DB struct {
|
||||
write *conn
|
||||
read []*conn
|
||||
idx int64
|
||||
idx uint64
|
||||
master *DB
|
||||
}
|
||||
|
||||
@ -217,8 +217,8 @@ func (db *DB) readIndex() int {
|
||||
if len(db.read) == 0 {
|
||||
return 0
|
||||
}
|
||||
v := atomic.AddInt64(&db.idx, 1)
|
||||
return int(v) % len(db.read)
|
||||
v := atomic.AddUint64(&db.idx, 1)
|
||||
return int(v % uint64(len(db.read)))
|
||||
}
|
||||
|
||||
// Close closes the write and read database, releasing any open resources.
|
||||
|
Loading…
x
Reference in New Issue
Block a user