Beispiel #1
0
func test_backend_slowdown(t *BackrunnerTest) error {
	num := 1000
	cnt_smallest, cnt_biggest, err := t.gather_write_stats(num)
	if err != nil {
		return err
	}

	// this should be roughly the same number of write hits per bucket,
	// since no bucket has been slown down
	if float64(cnt_biggest)/float64(cnt_smallest) > 2 {
		return fmt.Errorf("invalid distribution (should be rougly the same, i.e. difference < 0.5) in the equal run test: smallest: %d, biggest: %d",
			cnt_smallest, cnt_biggest)
	}

	s, err := elliptics.NewSession(t.ell.Node)
	if err != nil {
		return fmt.Errorf("could not create elliptics session: %v", err)
	}

	addr, err := elliptics.NewDnetAddrStr(t.elliptics_address[0])
	if err != nil {
		return fmt.Errorf("could not create address from '%s': %v", t.elliptics_address[0], err)
	}

	var backend_id int32 = 1
	var delay uint32 = 100
	for _ = range s.BackendSetDelay(&addr, backend_id, delay) {
	}

	time.Sleep(2 * time.Second)

	cnt_smallest, cnt_biggest, err = t.gather_write_stats(num)
	if err != nil {
		return err
	}

	if cnt_biggest/cnt_smallest < 3 {
		return fmt.Errorf("invalid distribution (diff must be more than several times, 3 in the code) in the slow run test: smallest: %d, biggest: %d",
			cnt_smallest, cnt_biggest)
	}

	delay = 0
	s.BackendSetDelay(&addr, backend_id, delay)

	time.Sleep(2 * time.Second)

	cnt_smallest, cnt_biggest, err = t.gather_write_stats(num)
	if err != nil {
		return err
	}

	// this should be roughly the same number of write hits per bucket,
	// since no bucket has been slown down
	if float64(cnt_biggest)/float64(cnt_smallest) > 2 {
		return fmt.Errorf("invalid distribution (should be rougly the same, i.e. difference < 0.5) in the SECOND equal run test: smallest: %d, biggest: %d",
			cnt_smallest, cnt_biggest)
	}

	return nil
}
Beispiel #2
0
func test_backends_status(t *BackrunnerTest) error {
	s, err := elliptics.NewSession(t.ell.Node)
	if err != nil {
		return fmt.Errorf("could not create elliptics session: %v", err)
	}

	addr, err := elliptics.NewDnetAddrStr(t.elliptics_address[0])
	if err != nil {
		return fmt.Errorf("could not create address from '%s': %v", t.elliptics_address[0], err)
	}

	for i := 0; i < 10; i++ {
		var st *elliptics.DnetBackendsStatus = nil

		for st = range s.BackendsStatus(&addr) {
		}

		if st.Error != nil {
			return st.Error
		}

		for _, back := range st.Backends {
			if back.State != elliptics.BackendStateEnabled {
				return fmt.Errorf("addr: %s, backend: %d, state: %d: state must be %d",
					addr.String(), back.Backend, back.State, elliptics.BackendStateEnabled)
			}
		}

		var backend_id int32 = 1
		for _ = range s.BackendDisable(&addr, backend_id) {
		}
		for st = range s.BackendsStatus(&addr) {
		}
		if st.Error != nil {
			return st.Error
		}

		for _, back := range st.Backends {
			if back.Backend == backend_id {
				if back.State == elliptics.BackendStateEnabled {
					return fmt.Errorf("addr: %s, backend: %d, state: %d: state must be not %d",
						addr.String(), back.Backend, back.State, elliptics.BackendStateEnabled)
				}

				continue
			}

			if back.State != elliptics.BackendStateEnabled {
				return fmt.Errorf("addr: %s, backend: %d, state: %d: state must be 0",
					addr.String(), back.Backend, back.State, elliptics.BackendStateEnabled)
			}
		}

		for _ = range s.BackendEnable(&addr, 1) {
		}
	}

	return nil
}
Beispiel #3
0
func (e *Elliptics) MetadataSession() (ms *elliptics.Session, err error) {
	ms, err = elliptics.NewSession(e.Node)
	if err != nil {
		return
	}

	ms.SetGroups(e.MetadataGroups)
	return
}
Beispiel #4
0
func (e *Elliptics) DataSession(req *http.Request) (*elliptics.Session, error) {
	s, err := elliptics.NewSession(e.Node)
	if err != nil {
		return nil, err
	}

	values := req.URL.Query()
	var val uint64

	var trace_id uint64
	trace, ok := req.Header["X-Request"]
	if !ok {
		trace_id = uint64(rand.Int63())
	} else {
		trace_id, err = strconv.ParseUint(trace[0], 0, 64)
		if err != nil {
			trace_id = uint64(rand.Int63())
		}
	}

	ioflags, ok := values["ioflags"]
	if ok {
		val, err = strconv.ParseUint(ioflags[0], 0, 32)
		if err == nil {
			s.SetIOflags(elliptics.IOflag(val))
		}
	}
	cflags, ok := values["cflags"]
	if ok {
		val, err = strconv.ParseUint(cflags[0], 0, 64)
		if err == nil {
			s.SetCflags(elliptics.Cflag(val))
		}
	}
	trace, ok = values["trace_id"]
	if ok {
		trace_id, err = strconv.ParseUint(trace[0], 0, 64)
		if err != nil {
			trace_id = uint64(rand.Int63())
		}
	}

	s.SetTraceID(elliptics.TraceID(trace_id))

	return s, nil
}
Beispiel #5
0
func (e *Elliptics) Stat() (stat *elliptics.DnetStat, err error) {
	s, err := elliptics.NewSession(e.Node)
	if err != nil {
		return
	}
	defer s.Delete()

	stat = s.DnetStat()

	e.Lock()

	stat.Diff(e.prev_stat)
	e.prev_stat = stat

	e.Unlock()

	return
}
Beispiel #6
0
func TestBackendStatusUpdate(t *BackrunnerTest) error {
	s, err := elliptics.NewSession(t.ell.Node)
	if err != nil {
		return fmt.Errorf("backend-status: could not create elliptics session: %v", err)
	}

	addr, err := elliptics.NewDnetAddrStr(t.elliptics_address[0])
	if err != nil {
		return fmt.Errorf("backend-status: could not create address from '%s': %v", t.elliptics_address[0], err)
	}

	var backend_id int32 = 1

	ch := s.BackendMakeReadOnly(&addr, backend_id)
	err = check_backend(ch, s, &addr, backend_id, true, 0)
	if err != nil {
		return fmt.Errorf("backend-status: make-readonly: %v", err)
	}

	ch = s.BackendMakeWritable(&addr, backend_id)
	err = check_backend(ch, s, &addr, backend_id, false, 0)
	if err != nil {
		return fmt.Errorf("backend-status: make-writable: %v", err)
	}

	var delay uint32 = 1000
	ch = s.BackendSetDelay(&addr, backend_id, delay)
	err = check_backend(ch, s, &addr, backend_id, false, delay)
	if err != nil {
		return fmt.Errorf("backend-status: set-delay: %d: %v", delay, err)
	}

	delay = 0
	ch = s.BackendSetDelay(&addr, backend_id, delay)
	err = check_backend(ch, s, &addr, backend_id, false, delay)
	if err != nil {
		return fmt.Errorf("backend-status: set-delay: %d: %v", delay, err)
	}

	return nil
}