Exemple #1
0
func LoadAllPods(db *daemondb.DaemonDB) chan *types.PersistPodLayout {
	kvchan := db.PrefixList2Chan([]byte(LAYOUT_KEY_PREFIX), nil)
	if kvchan == nil {
		return nil
	}
	ch := make(chan *types.PersistPodLayout, 128)
	go func() {
		for {
			kv, ok := <-kvchan
			if !ok {
				hlog.Log(INFO, "layout loading finished")
				close(ch)
				return
			}
			hlog.Log(TRACE, "loading layout of container %s", string(kv.K))

			var layout types.PersistPodLayout
			err := proto.Unmarshal(kv.V, &layout)
			if err != nil {
				hlog.Log(ERROR, "failed to decode layout of contaienr %s: %v", string(kv.K), err)
				continue
			}
			ch <- &layout
		}
	}()
	return ch
}
Exemple #2
0
func loadMessage(db *daemondb.DaemonDB, key string, message proto.Message, owner hlog.LogOwner, op string) error {
	v, err := db.Get([]byte(key))
	if err != nil {
		hlog.HLog(ERROR, owner, 2, "failed to load %s: %v", op, err)
		return err
	}
	err = proto.Unmarshal(v, message)
	if err != nil {
		hlog.HLog(ERROR, owner, 2, "failed to unpack loaded %s: %v", op, err)
		return err
	}
	return nil
}
Exemple #3
0
func saveMessage(db *daemondb.DaemonDB, key string, message proto.Message, owner hlog.LogOwner, op string) error {
	pm, err := proto.Marshal(message)
	if err != nil {
		hlog.HLog(ERROR, owner, 2, "failed to serialize %s: %v", op, err)
		return err
	}
	err = db.Update([]byte(key), pm)
	if err != nil {
		hlog.HLog(ERROR, owner, 2, "failed to write %s to db: %v", op, err)
		return err
	}
	hlog.HLog(DEBUG, owner, 2, "%s serialized to db", op)
	return nil
}