基于serf的数据库同步模块库
liuxiaolong
2019-10-10 974a818237c989fa7e4a5accaf848c49f97a5ca0
dbself.go
@@ -6,7 +6,6 @@
   "os"
   "os/exec"
   "path/filepath"
   "strconv"
   "strings"
   "sync"
   "github.com/jinzhu/gorm"
@@ -131,39 +130,6 @@
      return true,nil
   }
   return false,errors.New("localDb is nil")
}
type SyncSerf struct {
   LamportTime string `json:"lamport_time"`
}
func QueryLTimeFromDbByGorm() uint64 {
   if localDb != nil {
      var syncSerf []SyncSerf
      err := localDb.Raw("select * from sync_serf").Scan(&syncSerf).Error
      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)
            }
         }
      } else {
         logger.Error("get db.LamportTime err:", err)
      }
   }
   return 0
}
type TableDesc struct {