Example #1
0
func checkEtcdEquals(t *testing.T, conn db.Conn, exp db.Etcd) {
	timeout := time.After(1 * time.Second)
	var actual db.Etcd
	for {
		conn.Transact(func(view db.Database) error {
			actual, _ = view.GetEtcd()
			return nil
		})
		actual.ID = 0
		if reflect.DeepEqual(exp, actual) {
			return
		}
		select {
		case <-timeout:
			t.Errorf("Expected etcd row to be %v, but got %v\n", exp, actual)
			return
		default:
			time.Sleep(100 * time.Millisecond)
		}
	}
}
Example #2
0
func (s server) BootEtcd(ctx context.Context,
	members *pb.EtcdMembers) (*pb.Reply, error) {
	go s.Transact(func(view db.Database) error {
		etcdSlice := view.SelectFromEtcd(nil)
		var etcdRow db.Etcd
		switch len(etcdSlice) {
		case 0:
			log.Info("Received boot etcd request.")
			etcdRow = view.InsertEtcd()
		case 1:
			etcdRow = etcdSlice[0]
		default:
			panic("Not Reached")
		}

		etcdRow.EtcdIPs = members.IPs
		sort.Strings(etcdRow.EtcdIPs)
		view.Commit(etcdRow)

		return nil
	})

	return &pb.Reply{Success: true}, nil
}