Beispiel #1
0
func (vc *VolumeClock) Put(parentInode uint64, name string, c *clock.Clock) error {
	key := vc.pathToKey(parentInode, name)
	buf, err := c.MarshalBinary()
	if err != nil {
		return err
	}
	if err := vc.b.Put(key, buf); err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
func (vc *VolumeConflicts) Add(parentInode uint64, c *clock.Clock, de *wirepeer.Dirent) error {
	clockBuf, err := c.MarshalBinary()
	if err != nil {
		return fmt.Errorf("error marshaling clock: %v", err)
	}
	key := vc.pathToKey(parentInode, de.Name, clockBuf)

	tmp := *de
	tmp.Name = ""
	buf, err := proto.Marshal(&tmp)
	if err != nil {
		return fmt.Errorf("error marshaling dirent: %v", err)
	}

	if err := vc.b.Put(key, buf); err != nil {
		return err
	}
	return nil
}
Beispiel #3
0
func (vc *VolumeClock) UpdateFromChild(parentInode uint64, name string, child *clock.Clock) (changed bool, err error) {
	key := vc.pathToKey(parentInode, name)
	val := vc.b.Get(key)
	if val == nil {
		return false, &ClockNotFoundError{ParentInode: parentInode, Name: name}
	}
	var parentClock clock.Clock
	if err := parentClock.UnmarshalBinary(val); err != nil {
		return false, fmt.Errorf("corrupt clock for %d:%q", parentInode, name)
	}
	if changed := parentClock.UpdateFromChild(child); !changed {
		// no need to persist anything
		return false, nil
	}
	buf, err := parentClock.MarshalBinary()
	if err != nil {
		return false, err
	}
	if err := vc.b.Put(key, buf); err != nil {
		return false, err
	}
	return true, nil
}