Ejemplo n.º 1
0
func setup(tag string, unreliable bool, sudden bool) ([]string, []int64, [][]string, [][]*ShardKV, func(), []string) {
  runtime.GOMAXPROCS(4)

  const nmasters = 3
  var sma []*shardmaster.ShardMaster = make([]*shardmaster.ShardMaster, nmasters)
  var smh []string = make([]string, nmasters)
  // defer mcleanup(sma)
  for i := 0; i < nmasters; i++ {
    smh[i] = port(tag+"m", i)
  }
  for i := 0; i < nmasters; i++ {
    sma[i] = shardmaster.StartServer(smh, i)
  }

  var mba []*messagebroker.MBServer = make([]*messagebroker.MBServer, nmasters)
  var mbh []string = make([]string, nmasters)
  for i := 0; i < nmasters; i++ {
    mbh[i] = port(tag+"messagebroker", i)
  }
  for i := 0; i < nmasters; i++ {
    mba[i] = messagebroker.StartServer(mbh, i)
  }

  const ngroups = 3                 // replica groups
  const nreplicas = 3               // servers per group
  gids := make([]int64, ngroups)    // each group ID
  ha := make([][]string, ngroups)   // ShardKV ports, [group][replica]
  sa := make([][]*ShardKV, ngroups) // ShardKVs
  // defer cleanup(sa)
  for i := 0; i < ngroups; i++ {
    gids[i] = int64(i + 100)
    sa[i] = make([]*ShardKV, nreplicas)
    ha[i] = make([]string, nreplicas)
    for j := 0; j < nreplicas; j++ {
      ha[i][j] = port(tag+"s", (i*nreplicas)+j)
    }
    for j := 0; j < nreplicas; j++ {
      // if sudden {
      //   var procAttr os.ProcAttr
      //   procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
      //   process, err := os.StartProcess(os.Args[1], os.Args[1:], &procAttr)
      //   if err != nil {
      //     println("start process failed:" + err.String())
      //     return
      //   }
      //   _, err = process.Wait(0)
      // } else {
      sa[i][j] = StartServer(gids[i], smh, ha[i], j, mbh)
      sa[i][j].unreliable = unreliable
      // }
    }
  }

  clean := func() { cleanup(sa); mcleanup(sma); mbcleanup(mba) }
  return smh, gids, ha, sa, clean, mbh
}
Ejemplo n.º 2
0
func setupb(tag string, unreliable bool, sudden bool) ([]string, []int64, [][]string, [][]*ShardKV, func(), []string) {
	runtime.GOMAXPROCS(4)

	const nmasters = 3
	var sma []*shardmaster.ShardMaster = make([]*shardmaster.ShardMaster, nmasters)
	var smh []string = make([]string, nmasters)
	// defer mcleanup(sma)
	for i := 0; i < nmasters; i++ {
		smh[i] = port(tag+"m", i)
	}
	for i := 0; i < nmasters; i++ {
		sma[i] = shardmaster.StartServer(smh, i)
	}

	var mba []*messagebroker.MBServer = make([]*messagebroker.MBServer, nmasters)
	var mbh []string = make([]string, nmasters)
	for i := 0; i < nmasters; i++ {
		mbh[i] = port(tag+"messagebroker", i)
	}
	for i := 0; i < nmasters; i++ {
		mba[i] = messagebroker.StartServer(mbh, i)
	}

	const ngroups = 3                 // replica groups
	const nreplicas = 3               // servers per group
	gids := make([]int64, ngroups)    // each group ID
	ha := make([][]string, ngroups)   // ShardKV ports, [group][replica]
	sa := make([][]*ShardKV, ngroups) // ShardKVs
	// defer cleanup(sa)
	for i := 0; i < ngroups; i++ {
		gids[i] = int64(i + 100)
		sa[i] = make([]*ShardKV, nreplicas)
		ha[i] = make([]string, nreplicas)
		for j := 0; j < nreplicas; j++ {
			ha[i][j] = port(tag+"s", (i*nreplicas)+j)
		}
		for j := 0; j < nreplicas; j++ {
			sa[i][j] = StartServer(gids[i], smh, ha[i], j, mbh)
			sa[i][j].unreliable = unreliable
		}
	}

	clean := func() { cleanup(sa); mcleanup(sma); mbcleanup(mba) }
	return smh, gids, ha, sa, clean, mbh
}
Ejemplo n.º 3
0
func setup(tag string, unreliable bool) ([]string, []*messagebroker.MBServer, func()) {
	runtime.GOMAXPROCS(4)

	const nbrokers = 3
	var mbservers []*messagebroker.MBServer = make([]*messagebroker.MBServer, nbrokers)
	var hosts []string = make([]string, nbrokers)

	for i := 0; i < nbrokers; i++ {
		hosts[i] = port(tag+"m", i)
	}
	for i := 0; i < nbrokers; i++ {
		mbservers[i] = messagebroker.StartServer(hosts, i)
	}

	clean := func() { cleanup(mbservers) }

	return hosts, mbservers, clean
}