func check_backend(ch *elliptics.DChannel, s *elliptics.Session, addr *elliptics.DnetAddr, backend_id int32, ro bool, delay uint32) error { checked := false for t := range ch.Out { st := t.(*elliptics.DnetBackendsStatus) if st.Error != nil { return st.Error } for _, b := range st.Backends { if b.Backend == backend_id { if b.RO != ro { return fmt.Errorf("backend: %d: read-only mismatch: read: %v, must be: %v", backend_id, b.RO, ro) } if b.Delay != delay { return fmt.Errorf("backend: %d: delay mismatch: read: %v, must be: %v", backend_id, b.Delay, delay) } checked = true break } } } if !checked { return fmt.Errorf("backend: %d: could not find backend", backend_id) } checked = false for t := range s.BackendsStatus(addr).Out { st := t.(*elliptics.DnetBackendsStatus) if st.Error != nil { return st.Error } for _, b := range st.Backends { if b.Backend == backend_id { if b.RO != ro { return fmt.Errorf("backend: %d: check: read-only mismatch: read: %v, must be: %v", backend_id, b.RO, ro) } if b.Delay != delay { return fmt.Errorf("backend: %d: check: delay mismatch: read: %v, must be: %v", backend_id, b.Delay, delay) } checked = true break } } } if !checked { return fmt.Errorf("backend: %d: could not find backend", backend_id) } return nil }
func (bctl *BucketCtl) SetGroupsTimeout(s *elliptics.Session, bucket *Bucket, key string) { // sort groups by defrag state, increase timeout if needed groups := make([]uint32, 0) defrag_groups := make([]uint32, 0) timeout := 30 for group_id, sg := range bucket.Group { sb, err := sg.FindStatBackendKey(s, key, group_id) if err != nil { continue } if sb.DefragState != 0 { defrag_groups = append(defrag_groups, group_id) } else { groups = append(groups, group_id) } } // Not being defragmented backends first, then those which are currently being defragmented groups = append(groups, defrag_groups...) if len(groups) == len(defrag_groups) { timeout = 90 } // if there are no backends being defragmented, use weights to mix read states // if there are such backends, use strict order and read from non-defragmented backends first ioflags := elliptics.IOflag(bctl.Conf.Proxy.ReaderIOFlags) | s.GetIOflags() if len(defrag_groups) == 0 { ioflags |= elliptics.DNET_IO_FLAGS_MIX_STATES } s.SetIOflags(ioflags) // there are no stats for bucket groups, use what we have in metadata if len(groups) == 0 { groups = bucket.Meta.Groups } s.SetGroups(groups) s.SetTimeout(timeout) }