基于serf的数据库同步模块库
liuxiaolong
2019-09-27 a2d9de39e35663578861385fca686944857d473b
add sync_serf init
1个文件已修改
25 ■■■■■ 已修改文件
dbself.go 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dbself.go
@@ -141,16 +141,23 @@
    if localDb != nil {
        var syncSerf []SyncSerf
        err := localDb.Raw("select * from sync_serf").Scan(&syncSerf).Error
        if err == nil && len(syncSerf) > 0 {
            ltStr := syncSerf[0].LamportTime
            logger.Info("db.LamportTime str:", ltStr)
            t, e := strconv.ParseUint(ltStr, 10, 64)
            if e != nil {
                logger.Error("db.LamportTime parseUint err:", e)
            } else {
                curLTime = t
        if err == nil {
            if len(syncSerf) > 0{
                ltStr := syncSerf[0].LamportTime
                logger.Info("db.LamportTime str:", ltStr)
                t, e := strconv.ParseUint(ltStr, 10, 64)
                if e != nil {
                    logger.Error("db.LamportTime parseUint err:", e)
                } else {
                    curLTime = t
                }
                logger.Info("db.LamportTime:", ltStr)
            }else {
                err = localDb.Exec("insert into sync_serf values('0')").Error
                if err !=nil {
                    logger.Error("sync_serf lamport_time init err:",err)
                }
            }
            logger.Info("db.LamportTime:", ltStr)
        } else {
            logger.Error("get db.LamportTime err:", err)