fix bug
This commit is contained in:
parent
79e49306ef
commit
c1b56c8472
@ -18,6 +18,7 @@ type t_uid struct {
|
||||
F_range_length int `gorm:"column:F_range_length"` // ID范围的长度
|
||||
F_range_owner string `gorm:"column:F_range_owner"` // ID范围的拥有者,一般是机器id
|
||||
F_create_time time.Time `gorm:"column:F_create_time"` // 记录创建时间
|
||||
F_modify_time time.Time `gorm:"column:F_modify_time"` // 记录更新时间
|
||||
}
|
||||
|
||||
type typeInfo struct {
|
||||
@ -46,11 +47,15 @@ func (id *t_uid) TableName() string {
|
||||
}
|
||||
|
||||
func (id *t_uid) BeforeCreate(db *gorm.DB) error {
|
||||
if id.F_create_time.IsZero() {
|
||||
id.F_create_time = time.Now()
|
||||
id.F_modify_time = time.Now()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (id *t_uid) BeforeUpdate(db *gorm.DB) (err error) {
|
||||
id.F_modify_time = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
16
uid.go
16
uid.go
@ -206,7 +206,21 @@ func (idg *idCreator) createNewRange(prefix string) error {
|
||||
|
||||
func (idg *idCreator) getCurrentRange(prefix string) (r *Range) {
|
||||
// Step 0. get ranges queue by prefix.
|
||||
var queue, ok = idg.Ranges[prefix]
|
||||
var (
|
||||
trycount = 0
|
||||
queue *rangeQueue = nil
|
||||
ok = false
|
||||
)
|
||||
for trycount = 0; !ok && trycount < 3; trycount++ {
|
||||
if queue, ok = idg.Ranges[prefix]; !ok {
|
||||
idg.createNewRange(prefix)
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
panic("maybe something bug, cannot found range queue after createNewRange")
|
||||
}
|
||||
|
||||
queue, ok = idg.Ranges[prefix]
|
||||
if !ok {
|
||||
idg.createNewRange(prefix)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user