本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}