当前位置: 首页>>代码示例>>Golang>>正文


Golang viewservice.MakeClerk函数代码示例

本文整理汇总了Golang中viewservice.MakeClerk函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeClerk函数的具体用法?Golang MakeClerk怎么用?Golang MakeClerk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MakeClerk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: StartServer

func StartServer(vshost string, me string) *PBServer {
	pb := new(PBServer)
	pb.me = me
	pb.vs = viewservice.MakeClerk(me, vshost)
	// Your pb.* initializations here.
	pb.view = viewservice.View{}
	pb.content = make(map[string]string)
	pb.client = make(map[string]string)

	rpcs := rpc.NewServer()
	rpcs.Register(pb)

	os.Remove(pb.me)
	l, e := net.Listen("unix", pb.me)
	if e != nil {
		log.Fatal("listen error: ", e)
	}
	pb.l = l

	// please do not change any of the following code,
	// or do anything to subvert it.

	go func() {
		for pb.isdead() == false {
			conn, err := pb.l.Accept()
			if err == nil && pb.isdead() == false {
				if pb.isunreliable() && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if pb.isunreliable() && (rand.Int63()%1000) < 200 {
					// process the request but force discard of reply.
					c1 := conn.(*net.UnixConn)
					f, _ := c1.File()
					err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
					if err != nil {
						fmt.Printf("shutdown: %v\n", err)
					}
					go rpcs.ServeConn(conn)
				} else {
					go rpcs.ServeConn(conn)
				}
			} else if err == nil {
				conn.Close()
			}
			if err != nil && pb.isdead() == false {
				fmt.Printf("PBServer(%v) accept: %v\n", me, err.Error())
				pb.kill()
			}
		}
	}()

	go func() {
		for pb.isdead() == false {
			pb.tick()
			time.Sleep(viewservice.PingInterval)
		}
	}()

	return pb
}
开发者ID:EdisonCodeKeeper,项目名称:course-6.824-distributed-systems,代码行数:60,代码来源:server.go

示例2: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.me = me
	return ck
}
开发者ID:salibrandi,项目名称:mexos,代码行数:7,代码来源:client.go

示例3: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	ck.view, _ = ck.vs.Get()

	return ck
}
开发者ID:salmanahmad,项目名称:6.824,代码行数:7,代码来源:client.go

示例4: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.me = fmt.Sprintf("%s%d", me, nrand())

	return ck
}
开发者ID:ChenLingPeng,项目名称:6.824,代码行数:8,代码来源:client.go

示例5: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.me = "client: " + strconv.Itoa(int(nrand()))

	return ck
}
开发者ID:ctliu3,项目名称:yds,代码行数:8,代码来源:client.go

示例6: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.currentView = viewservice.View{0, "", ""}

	return ck
}
开发者ID:NickYoungFDU,项目名称:Distributed-System-Lab,代码行数:8,代码来源:client.go

示例7: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.id = nrand()
	ck.seq_num = 0
	return ck
}
开发者ID:kissingurami,项目名称:MIT6.824_DistributedSystems,代码行数:8,代码来源:client.go

示例8: TestAtMostOnce

func TestAtMostOnce(t *testing.T) {
	runtime.GOMAXPROCS(4)

	tag := "csu"
	vshost := port(tag+"v", 1)
	vs := viewservice.StartServer(vshost)
	time.Sleep(time.Second)
	vck := viewservice.MakeClerk("", vshost)

	fmt.Printf("Test: at-most-once Put; unreliable ...\n")

	const nservers = 1
	var sa [nservers]*PBServer
	for i := 0; i < nservers; i++ {
		sa[i] = StartServer(vshost, port(tag, i+1))
		sa[i].unreliable = true
	}

	for iters := 0; iters < viewservice.DeadPings*2; iters++ {
		view, _ := vck.Get()
		if view.Primary != "" && view.Backup != "" {
			break
		}
		time.Sleep(viewservice.PingInterval)
	}

	// give p+b time to ack, initialize
	time.Sleep(viewservice.PingInterval * viewservice.DeadPings)

	ck := MakeClerk(vshost, "")
	k := "counter"
	val := ""
	for i := 0; i < 100; i++ {
		v := strconv.Itoa(i)
		pv := ck.PutHash(k, v)
		if pv != val {
			fmt.Println(i)
			t.Fatalf("ck.Puthash() returned %v but expected %v\n", pv, val)
		}
		h := hash(val + v)
		val = strconv.Itoa(int(h))
	}

	v := ck.Get(k)
	if v != val {
		fmt.Println("101")
		t.Fatalf("ck.Get() returned %v but expected %v\n", v, val)
	}

	fmt.Printf("  ... Passed\n")

	for i := 0; i < nservers; i++ {
		sa[i].kill()
	}
	time.Sleep(time.Second)
	vs.Kill()
	time.Sleep(time.Second)
}
开发者ID:parvathythilak,项目名称:MIT-6.824,代码行数:58,代码来源:test_test.go

示例9: TestAtMostOnce

func TestAtMostOnce(t *testing.T) {
	runtime.GOMAXPROCS(4)

	tag := "tamo"
	vshost := port(tag+"v", 1)
	vs := viewservice.StartServer(vshost)
	time.Sleep(time.Second)
	vck := viewservice.MakeClerk("", vshost)

	fmt.Printf("Test: at-most-once Append; unreliable ...\n")

	const nservers = 1
	var sa [nservers]*PBServer
	for i := 0; i < nservers; i++ {
		sa[i] = StartServer(vshost, port(tag, i+1))
		sa[i].setunreliable(true)
	}

	for iters := 0; iters < viewservice.DeadPings*2; iters++ {
		view, _ := vck.Get()
		if view.Primary != "" && view.Backup != "" {
			break
		}
		time.Sleep(viewservice.PingInterval)
	}

	view1, _ := vck.Get()

	// give p+b time to ack, initialize
	time.Sleep(viewservice.PingInterval * viewservice.DeadPings)

	view, _ := vck.Get()
	fmt.Println("->", view.Primary, view.Backup)
	fmt.Println("->", view1.Primary, view1.Backup)

	ck := MakeClerk(vshost, "")
	k := "counter"
	val := ""
	for i := 0; i < 100; i++ {
		v := strconv.Itoa(i)
		ck.Append(k, v)
		val = val + v
	}

	v := ck.Get(k)
	if v != val {
		t.Fatalf("ck.Get() returned %v but expected %v\n", v, val)
	}

	fmt.Printf("  ... Passed\n")

	for i := 0; i < nservers; i++ {
		sa[i].kill()
	}
	time.Sleep(time.Second)
	vs.Kill()
	time.Sleep(time.Second)
}
开发者ID:karanjude,项目名称:mr,代码行数:58,代码来源:test_test.go

示例10: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)

	ck.me = me
	ck.id = nrand()
	ck.seqNum = 0
	return ck
}
开发者ID:parvathythilak,项目名称:MIT-6.824,代码行数:9,代码来源:client.go

示例11: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here

	ck.currentView = viewservice.View{0, "", ""}
	ck.id = strconv.FormatInt(nrand(), 10)
	return ck
}
开发者ID:lmatz,项目名称:Distributed-Systems,代码行数:9,代码来源:client.go

示例12: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.id = nrand() // For debug.
	ck.setNewPrimary()

	return ck
}
开发者ID:willx8,项目名称:6.824lab,代码行数:9,代码来源:client.go

示例13: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	ok := false
	for !ok {
		ck.view, ok = ck.vs.Get()
		time.Sleep(viewservice.PingInterval)
	}
	return ck
}
开发者ID:songgao,项目名称:mit-ds-lab-2013,代码行数:10,代码来源:client.go

示例14: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)
	// Your ck.* initializations here
	ck.me = me
	ck.primary = ck.vs.Primary()
	ck.rpc_id = 1

	return ck
}
开发者ID:gitter-badger,项目名称:haze-kv,代码行数:10,代码来源:client.go

示例15: MakeClerk

func MakeClerk(vshost string, me string) *Clerk {
	ck := new(Clerk)
	ck.vs = viewservice.MakeClerk(me, vshost)

	// Your ck.* initializations here
	view, _ := ck.vs.Ping(0)
	newPrimary := view.Primary
	ck.primary = newPrimary
	return ck
}
开发者ID:salibrandi,项目名称:mexos,代码行数:10,代码来源:client.go


注:本文中的viewservice.MakeClerk函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。