コード例 #1
0
ファイル: keeper_2.go プロジェクト: ymqytw/cse223_distSys_lab
func (self *Keeper) Init() error {
	// start rpc server
	s := store.NewStorage()
	conf := trib.BackConfig{self.Keepers[self.This], s, nil}
	//fmt.Println("serve on keeper ", self.Keepers[self.This])
	go ServeBack(&conf)
	// help init chord: this operation is idempotent, bad efficiency but ok to go...
	err := self.InitChord()
	if err != nil {
		return err
	}
	// sleep to wait for other RPC server to start
	time.Sleep(time.Millisecond * 1)
	// create keeper clients
	for _, keeper := range self.Keepers {
		self.KeeperClients = append(self.KeeperClients, &client{keeper})
	}
	// ping keepers with rpc call
	// change keeper states
	keeperCnt := self.ChangeKeeperStates()
	// create job table
	self.CreateJobTable(keeperCnt)
	// ping backs on the job table
	// change back states
	self.ChangeBackStates()

	// done here?

	// debug
	//fmt.Println("Keeper states: ", self.KeeperStates)
	//fmt.Println("Backend states: ", self.BackStates)

	return nil
}
コード例 #2
0
ファイル: main.go プロジェクト: ymqytw/cse223_distFileSys
func main() {
	flag.Parse()

	store.Logging = *verbose

	rc, e := trib.LoadRC(*frc)
	noError(e)

	run := func(i int) {
		if i > len(rc.Backs) {
			noError(fmt.Errorf("back-end index out of range: %d", i))
		}

		backConfig := rc.BackConfig(i, store.NewStorage())

		if *readyAddr != "" {
			backConfig.Ready = ready.Chan(*readyAddr, backConfig.Addr)
		}

		log.Printf("bin storage back-end serving on %s", backConfig.Addr)
		noError(triblab.ServeBack(backConfig))
	}

	args := flag.Args()

	n := 0
	if len(args) == 0 {
		// scan for addresses on this machine
		for i, b := range rc.Backs {
			if local.Check(b) {
				go run(i)
				n++
			}
		}

		if n == 0 {
			log.Fatal("no back-end found for this host")
		}
	} else {
		// scan for indices for the addresses
		for _, a := range args {
			i, e := strconv.Atoi(a)
			noError(e)
			go run(i)
			n++
		}
	}

	if n > 0 {
		select {}
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: ymqytw/cse223_distFileSys
func main() {
	flag.Parse()

	*addr = "localhost:9900" //randaddr.Resolve(*addr)

	s := store.NewStorage()

	log.Printf("key-value store serving on %s", *addr)

	e := entries.ServeBackSingle(*addr, s, nil)
	if e != nil {
		log.Fatal(e)
	}
}
コード例 #4
0
func TestRPC(t *testing.T) {
	addr := randaddr.Local()
	ready := make(chan bool)

	go func() {
		e := entries.ServeBackSingle(addr, store.NewStorage(), ready)
		if e != nil {
			t.Fatal(e)
		}
	}()

	r := <-ready
	if !r {
		t.Fatal("not ready")
	}

	c := triblab.NewClient(addr)

	tribtest.CheckStorage(t, c)
}
コード例 #5
0
func TestServer(t *testing.T) {
	if os.Getenv("TRIB_LAB") == "lab1" {
		t.SkipNow()
	}

	addr := randaddr.Local()
	ready := make(chan bool)
	go func() {
		e := entries.ServeBackSingle(addr, store.NewStorage(), ready)
		if e != nil {
			t.Fatal(e)
		}
	}()
	<-ready

	startKeeper(t, addr)

	server := entries.MakeFrontSingle(addr)

	tribtest.CheckServer(t, server)
}
コード例 #6
0
func TestBinStorage(t *testing.T) {
	if os.Getenv("TRIB_LAB") == "lab1" {
		t.SkipNow()
	}

	addr1 := randaddr.Local()
	addr2 := randaddr.Local()
	for addr2 == addr1 {
		addr2 = randaddr.Local()
	}

	ready1 := make(chan bool)
	ready2 := make(chan bool)

	run := func(addr string, ready chan bool) {
		e := entries.ServeBackSingle(addr,
			store.NewStorage(), ready)
		if e != nil {
			t.Fatal(e)
		}
	}

	go run(addr1, ready1)
	go run(addr2, ready2)

	r := <-ready1 && <-ready2
	if !r {
		t.Fatal("not ready")
	}

	readyk := make(chan bool)
	addrk := randaddr.Local()
	for addrk == addr1 || addrk == addr2 {
		addrk = randaddr.Local()
	}
	go func() {
		e := triblab.ServeKeeper(&trib.KeeperConfig{
			Backs: []string{addr1, addr2},
			Addrs: []string{addrk},
			This:  0,
			Id:    0,
			Ready: readyk,
		})
		if e != nil {
			t.Fatal(e)
		}
	}()

	if !<-readyk {
		t.Fatal("keeper not ready")
	}

	bc := triblab.NewBinClient(
		[]string{addr1, addr2},
	)

	done := make(chan bool, 10)

	for i := 0; i < 10; i++ {
		c := bc.Bin(fmt.Sprintf("b%d", i))
		go func(s trib.Storage) {
			tribtest.CheckStorage(t, s)
			done <- true
		}(c)
	}

	for i := 0; i < 10; i++ {
		<-done
	}
}