Example #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
}
Example #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
}
Example #3
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
}