Esempio n. 1
0
// syncTo syncs the contents in p to all of the shards in urls
// returns the first error if there are multiple
func syncTo(dataRepo string, urls []string) error {
	var errs []error
	var lock sync.Mutex
	addErr := func(err error) {
		lock.Lock()
		errs = append(errs, err)
		lock.Unlock()
	}
	lr := btrfs.NewLocalReplica(dataRepo)
	var wg sync.WaitGroup
	for _, url := range urls {
		wg.Add(1)
		go func(url string) {
			defer wg.Done()
			sr := newShardReplica(url)
			from, err := sr.From()
			if err != nil {
				addErr(err)
			}
			err = lr.Pull(from, sr)
			if err != nil {
				addErr(err)
			}
		}(url)
	}
	wg.Wait()
	if len(errs) != 0 {
		return errs[0]
	}
	return nil
}
Esempio n. 2
0
func syncFromUrl(dataRepo string, url string) error {
	sr := newShardReplica(url)
	lr := btrfs.NewLocalReplica(dataRepo)
	from, err := lr.From()
	if err != nil {
		return err
	}
	return sr.Pull(from, lr)
}
Esempio n. 3
0
func (s *shard) Pull(from string, p btrfs.Pusher) error {
	return btrfs.NewLocalReplica(s.dataRepo).Pull(from, p)
}
Esempio n. 4
0
func (s *shard) Push(diff io.Reader) error {
	return btrfs.NewLocalReplica(s.dataRepo).Push(diff)
}