提交 65afbe11 编写于 作者: D dongzhihong

"fix gob register error"

上级 e6c98e49
...@@ -25,7 +25,7 @@ const ( ...@@ -25,7 +25,7 @@ const (
) )
const ( const (
checkpoint_path = "/checkpoints/" checkpoint_path = "./checkpoints/"
) )
// Supported element types // Supported element types
...@@ -67,10 +67,10 @@ type Service struct { ...@@ -67,10 +67,10 @@ type Service struct {
optMap map[string]*optimizer optMap map[string]*optimizer
} }
type Checkpoint struct { type checkpoint struct {
uuid string Uuid string
md5sum string Md5sum string
timestamp string Timestamp string
} }
//serialize ParameterWithConfig to byte stream //serialize ParameterWithConfig to byte stream
...@@ -93,6 +93,8 @@ func NewService(idx int) (*Service, error) { ...@@ -93,6 +93,8 @@ func NewService(idx int) (*Service, error) {
} }
s.optMap = make(map[string]*optimizer) s.optMap = make(map[string]*optimizer)
s.initialized = make(chan struct{}) s.initialized = make(chan struct{})
gob.Register(ParameterWithConfig{})
gob.Register(checkpoint{})
return s, nil return s, nil
} }
...@@ -190,32 +192,33 @@ func (s *Service) Save(path string, dummy *int) error { ...@@ -190,32 +192,33 @@ func (s *Service) Save(path string, dummy *int) error {
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
} }
ck := Checkpoint{} ck := checkpoint{}
h := md5.New() h := md5.New()
ck.md5sum = hex.EncodeToString(h.Sum(content)) ck.Md5sum = hex.EncodeToString(h.Sum(content))
ck.timestamp = time.Now().String() ck.Timestamp = time.Now().String()
ck.uuid = checkpoint_path + strconv.Itoa(s.idx) ck.Uuid = checkpoint_path + strconv.Itoa(s.idx)
ckbytes, err := GetBytes(ck) ckbytes, err := GetBytes(ck)
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
} }
// TODO: according design doc, need to save uuid to etcd in json format // TODO: according design doc, need to save Uuid to etcd in json format
// {\"uuid\": [UUID], \"md5\", \"MD5 sum\", \"timestamp\": xxxx} // {\"Uuid\": [UUID], \"md5\", \"MD5 sum\", \"Timestamp\": xxxx}
log.Infof("parameter checkpoint %s", ckbytes) log.Infof("parameter checkpoint %s", ckbytes)
if _, err = os.Stat(ck.uuid); os.IsNotExist(err) { if _, err = os.Stat(ck.Uuid); os.IsNotExist(err) {
log.Info("checkpoint not exists.") log.Info("checkpoint not exists.")
} else { } else {
err = os.Remove(ck.uuid) err = os.Remove(ck.Uuid)
log.Infof("remove %s", ck.uuid) log.Infof("remove %s", ck.Uuid)
} }
f, err := os.Create(ck.uuid) f, err := os.Create(ck.Uuid)
defer f.Close() defer f.Close()
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
} }
writer := bufio.NewWriter(f) writer := bufio.NewWriter(f)
_, err = writer.Write(content) _, err = writer.Write(content)
writer.Flush()
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册