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


Golang shardmaster.MakeClerk函数代码示例

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


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

示例1: doConcurrent

func doConcurrent(t *testing.T, unreliable bool) {
	smPorts, gids, kvPorts := setup("conc"+strconv.FormatBool(unreliable),
		unreliable, numGroups, numReplicas)

	// Start listening on reboot channel in case we're testing persistence
	//rebootDone := 0
	//go rebootListener(&rebootDone, unreliable, smPorts, gids, kvPorts, kvServers, numGroups, numReplicas)

	smClerk := shardmaster.MakeClerk(smPorts, false)
	for i := 0; i < len(gids); i++ {
		smClerk.Join(gids[i], kvPorts[i])
	}

	const npara = 11
	var doneChannels [npara]chan bool
	for i := 0; i < npara; i++ {
		doneChannels[i] = make(chan bool)
		go func(me int) {
			ok := true
			defer func() { doneChannels[me] <- ok }()
			kvClerk := shardkv.MakeClerk(smPorts, false)
			mysmClerk := shardmaster.MakeClerk(smPorts, false)
			key := strconv.Itoa(me)
			last := ""
			for iters := 0; iters < 3; iters++ {
				nv := strconv.Itoa(rand.Int())
				v := kvClerk.PutHash(key, nv)
				if v != last {
					ok = false
					t.Fatalf("PutHash(%v) expected %v got %v\n",
						key, last, v)
				}
				last = NextValue(last, nv)
				v = kvClerk.Get(key)
				if v != last {
					ok = false
					t.Fatalf("Get(%v) expected %v got %v\n",
						key, last, v)
				}

				mysmClerk.Move(rand.Int()%shardmaster.NShards,
					gids[rand.Int()%len(gids)])

				time.Sleep(time.Duration(rand.Int()%30) * time.Millisecond)
			}
		}(i)
	}

	for i := 0; i < npara; i++ {
		x := <-doneChannels[i]
		if x == false {
			t.Fatalf("something is wrong")
		}
	}

	//rebootDone = 1
	time.Sleep(2 * time.Second)
}
开发者ID:salibrandi,项目名称:mexos,代码行数:58,代码来源:test_test.go

示例2: doConcurrent

func doConcurrent(t *testing.T, unreliable bool) {
	smh, gids, ha, _, clean := setup("conc"+strconv.FormatBool(unreliable), unreliable)
	defer clean()

	mck := shardmaster.MakeClerk(smh)
	for i := 0; i < len(gids); i++ {
		mck.Join(gids[i], ha[i])
	}

	const npara = 11
	var ca [npara]chan bool
	for i := 0; i < npara; i++ {
		ca[i] = make(chan bool)
		go func(me int) {
			ok := true
			defer func() { ca[me] <- ok }()
			ck := MakeClerk(smh)
			mymck := shardmaster.MakeClerk(smh)
			key := strconv.Itoa(me)
			last := ""
			for iters := 0; iters < 3; iters++ {
				nv := strconv.Itoa(rand.Int())
				v := ck.PutHash(key, nv)
				if v != last {
					ok = false
					t.Fatalf("PutHash(%v) expected %v got %v\n", key, last, v)
				}
				last = NextValue(last, nv)
				v = ck.Get(key)
				if v != last {
					ok = false
					t.Fatalf("Get(%v) expected %v got %v\n", key, last, v)
				}

				mymck.Move(rand.Int()%shardmaster.NShards,
					gids[rand.Int()%len(gids)])

				time.Sleep(time.Duration(rand.Int()%30) * time.Millisecond)
			}
		}(i)
	}

	for i := 0; i < npara; i++ {
		x := <-ca[i]
		if x == false {
			t.Fatalf("something is wrong")
		}
	}
}
开发者ID:jefesaurus,项目名称:6824final,代码行数:49,代码来源:test_test.go

示例3: main

func main() {
	defer clean()

	mck := shardmaster.MakeClerk(smh)
	mck.Join(gids[0], ha[0])

	ck.Subscribe("a")
	ck.Subscribe("b")
	ck.Subscribe("c")
	ck.Subscribe("d")
	ck.Subscribe("e")
	defer cleanupClerk(ck)

	go listener(ck)
	go h.run()

	m := martini.Classic()
	m.Use(render.Renderer())

	m.Get("/", func(r render.Render) {
		r.HTML(200, "index", "")
	})

	m.Get("/ws", wsHandler)

	m.Run()
}
开发者ID:jeffchan,项目名称:pushydb,代码行数:27,代码来源:server.go

示例4: TestExpiryBasic

func TestExpiryBasic(t *testing.T) {
  smh, gids, ha, _, clean, _ := setup("expiry-move", false, false)
  defer clean()

  fmt.Printf("Test: Expiry Basic ...\n")
  mck := shardmaster.MakeClerk(smh)
  mck.Join(gids[0], ha[0])

  ck := MakeClerk(smh)
  defer cleanupClerk(ck)

  ttl := 2 * time.Second
  ck.PutExt("a", "x", false, ttl)

  v := ck.Get("a")
  if v != "x" {
    t.Fatalf("Get got wrong value")
  }
  time.Sleep(ttl)

  ov := ck.Get("a")
  if ov != "" {
    t.Fatalf("Get got value, should've expired")
  }

  ov = ck.PutHash("a", "b")
  if ov != "" {
    t.Fatalf("Put got value, should've expired")
  }

  fmt.Printf("  ... Passed\n")
}
开发者ID:jeffchan,项目名称:pushydb,代码行数:32,代码来源:test_test.go

示例5: MakeClerk

func MakeClerk(shardmasters []string) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters)
	// You'll have to modify MakeClerk.
	ck.clientID = nrand() // Unique ID for this client
	return ck
}
开发者ID:salibrandi,项目名称:mexos,代码行数:7,代码来源:client.go

示例6: MakeClerk

func MakeClerk(shardmasters []string) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters)
	// You'll have to modify MakeClerk.
	ck.me = strconv.FormatInt(nrand(), 16)
	return ck
}
开发者ID:william-cheung,项目名称:mit-6.824-2015,代码行数:7,代码来源:client.go

示例7: MakeClerk

func MakeClerk(shardmasters []string) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters)
	// You'll have to modify MakeClerk.
	ck.me = nrandint()
	return ck
}
开发者ID:jefesaurus,项目名称:6824final,代码行数:7,代码来源:client.go

示例8: TestBasic

func TestBasic(t *testing.T) {
	smh, gids, ha, _, clean := setup("basic", false)
	defer clean()

	fmt.Printf("Test: Basic Join/Leave ...\n")

	mck := shardmaster.MakeClerk(smh)
	mck.Join(gids[0], ha[0])

	ck := MakeClerk(smh)

	ck.Put("a", "x")
	v := ck.PutHash("a", "b")
	if v != "x" {
		t.Fatalf("Puthash got wrong value")
	}
	ov := NextValue("x", "b")
	if ck.Get("a") != ov {
		t.Fatalf("Get got wrong value")
	}

	keys := make([]string, 10)
	vals := make([]string, len(keys))
	for i := 0; i < len(keys); i++ {
		keys[i] = strconv.Itoa(rand.Int())
		vals[i] = strconv.Itoa(rand.Int())
		ck.Put(keys[i], vals[i])
	}
	// are keys still there after joins?
	for g := 1; g < len(gids); g++ {
		mck.Join(gids[g], ha[g])
		time.Sleep(1 * time.Second)
		for i := 0; i < len(keys); i++ {
			v := ck.Get(keys[i])
			if v != vals[i] {
				t.Fatalf("joining; wrong value; g=%v k=%v wanted=%v got=%v",
					g, keys[i], vals[i], v)
			}
			vals[i] = strconv.Itoa(rand.Int())
			ck.Put(keys[i], vals[i])
		}
	}

	// are keys still there after leaves?
	for g := 0; g < len(gids)-1; g++ {
		mck.Leave(gids[g])
		time.Sleep(1 * time.Second)
		for i := 0; i < len(keys); i++ {
			v := ck.Get(keys[i])
			if v != vals[i] {
				t.Fatalf("leaving; wrong value; g=%v k=%v wanted=%v got=%v",
					g, keys[i], vals[i], v)
			}
			vals[i] = strconv.Itoa(rand.Int())
			ck.Put(keys[i], vals[i])
		}
	}

	fmt.Printf("  ... Passed\n")
}
开发者ID:bohaoist,项目名称:mit-6.824-distributed-system-2014spring,代码行数:60,代码来源:test_test.go

示例9: MakeClerk

//
// the tester calls MakeClerk.
//
// masters[] is needed to call shardmaster.MakeClerk().
//
// make_end(servername) turns a server name from a
// Config.Groups[gid][i] into a labrpc.ClientEnd on which you can
// send RPCs.
//
func MakeClerk(masters []*labrpc.ClientEnd, make_end func(string) *labrpc.ClientEnd) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(masters)
	ck.make_end = make_end
	// You'll have to add code here.
	return ck
}
开发者ID:scv119,项目名称:6.824,代码行数:16,代码来源:client.go

示例10: MakeClerk

func MakeClerk(shardmasters []string) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters)
	ck.id = rand.Int()
	ck.get_request_id = make_int_generator()
	return ck
}
开发者ID:dghubble,项目名称:6.824,代码行数:7,代码来源:client.go

示例11: MakeClerk

func MakeClerk(shardmasters []string) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters)
	// You'll have to modify MakeClerk.
	ck.uid = fmt.Sprintf("%d_%d", time.Now().UnixNano(), rand.Int63())
	return ck
}
开发者ID:bohaoist,项目名称:mit-6.824-distributed-system-2014spring,代码行数:7,代码来源:client.go

示例12: TestMove

func TestMove(t *testing.T) {
  smh, gids, ha, _, clean, _ := setup("move", false, false)
  defer clean()

  fmt.Printf("Test: Shards really move ...\n")

  mck := shardmaster.MakeClerk(smh)
  mck.Join(gids[0], ha[0])

  ck := MakeClerk(smh)
  defer cleanupClerk(ck)

  // insert one key per shard
  for i := 0; i < shardmaster.NShards; i++ {
    ck.Put(string('0'+i), string('0'+i))
  }

  // add group 1.
  mck.Join(gids[1], ha[1])
  time.Sleep(5 * time.Second)

  // check that keys are still there.
  for i := 0; i < shardmaster.NShards; i++ {
    if ck.Get(string('0'+i)) != string('0'+i) {
      t.Fatalf("missing key/value")
    }
  }

  // remove sockets from group 0.
  for i := 0; i < len(ha[0]); i++ {
    os.Remove(ha[0][i])
  }

  count := 0
  var mu sync.Mutex
  for i := 0; i < shardmaster.NShards; i++ {
    go func(me int) {
      myck := MakeClerk(smh)
      defer cleanupClerk(myck)
      v := myck.Get(string('0' + me))
      if v == string('0'+me) {
        mu.Lock()
        count++
        mu.Unlock()
      } else {
        t.Fatalf("Get(%v) yielded %v\n", i, v)
      }
    }(i)
  }

  time.Sleep(10 * time.Second)

  if count > shardmaster.NShards/3 && count < 2*(shardmaster.NShards/3) {
    fmt.Printf("  ... Passed\n")
  } else {
    t.Fatalf("%v keys worked after killing 1/2 of groups; wanted %v",
      count, shardmaster.NShards/2)
  }
}
开发者ID:jeffchan,项目名称:pushydb,代码行数:59,代码来源:test_test.go

示例13: MakeClerk

func MakeClerk(shardmasters []string, network bool) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters, network)
	ck.me = nrand()
	ck.network = network
	ck.clientID = nrand()
	return ck
}
开发者ID:salibrandi,项目名称:mexos,代码行数:8,代码来源:client.go

示例14: MakeClerk

func MakeClerk(shardmasters []string) *Clerk {
	ck := new(Clerk)
	ck.sm = shardmaster.MakeClerk(shardmasters)
	// You'll have to modify MakeClerk.
	ck.cid = nrand()
	ck.seq = -1
	return ck
}
开发者ID:kennyhlam,项目名称:6824,代码行数:8,代码来源:client.go

示例15: TestManyClientOneShard

func TestManyClientOneShard(t *testing.T) {
	nclients := 35
	nseconds := 10
	smPorts, gids, kvPorts := setup("basic", false, numGroups, numReplicas)
	//defer clean()

	fmt.Printf("\nBenchmark: many clients, one shard...\n")

	smClerk := shardmaster.MakeClerk(smPorts, true)
	for i := 0; i < len(gids); i++ {
		smClerk.Join(gids[i], kvPorts[i])
	}

	counts := make([]int, nclients)
	for i := 0; i < nclients; i++ {
		go func(i int) {
			ck := shardkv.MakeClerk(smPorts, true)
			tStart := time.Now()
			count := 0
			for time.Since(tStart).Seconds() < float64(nseconds) {
				ck.PutHash("a", strconv.Itoa(rand.Int()))
				count++
			}
			counts[i] = count
		}(i)
	}
	toWait := 12 * time.Second
	time.Sleep(toWait)

	tot := 0
	for _, c := range counts {
		tot += c
	}
	fmt.Printf("%f operations per second\n", float64(tot)/float64(nseconds))

	fmt.Printf("\nBenchmark: many clients, many shards...\n")
	for i := 0; i < nclients; i++ {
		go func(i int) {
			ck := shardkv.MakeClerk(smPorts, true)
			tStart := time.Now()
			count := 0
			for time.Since(tStart).Seconds() < float64(nseconds) {
				ck.PutHash(strconv.Itoa(rand.Int()),
					strconv.Itoa(rand.Int()))
				count++
			}
			counts[i] = count
		}(i)
	}

	time.Sleep(toWait)

	tot = 0
	for _, c := range counts {
		tot += c
	}
	fmt.Printf("%f operations per second\n", float64(tot)/float64(nseconds))
}
开发者ID:salibrandi,项目名称:mexos,代码行数:58,代码来源:test_test.go


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