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


Golang paxos.Make函数代码示例

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


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

示例1: StartServer

//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant key/value service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *KVPaxos {
	// call gob.Register on structures you want
	// Go's RPC library to marshall/unmarshall.
	gob.Register(Op{})

	kv := new(KVPaxos)
	kv.me = me

	// initialization
	kv.kvData = make(map[string]string)
	kv.preReply = make(map[string]*Op)
	kv.seqChan = make(map[int]chan *Op)
	kv.maxInstanceID = -1

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

	kv.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for kv.dead == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.dead == false {
				if kv.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.unreliable && (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 && kv.dead == false {
				fmt.Printf("KVPaxos(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()
	go kv.updateStatus()
	return kv
}
开发者ID:parvathythilak,项目名称:MIT-6.824,代码行数:66,代码来源:server.go

示例2: StartServer

//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant key/value service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *KVPaxos {
	// Go's RPC library to marshall/unmarshall.
	gob.Register(Op{})
	kv := new(KVPaxos)
	kv.me = me
	kv.seenMap = make(map[int64]bool)
	kv.kvData = make(map[string]string)
	kv.toprocess = 1
	rpcs := rpc.NewServer()
	rpcs.Register(kv)
	kv.px = paxos.Make(servers, me, rpcs)
	os.Remove(servers[me])
	l, e := net.Listen("unix", servers[me])
	if e != nil {
		glog.Fatal("listen error: ", e)
	}
	kv.l = l

	go func() {
		for kv.isdead() == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.isdead() == false {
				go rpcs.ServeConn(conn)
			} else if err == nil {
				conn.Close()
			}
			if err != nil && kv.isdead() == false {
				glog.Warningln("KVPaxos(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()

	return kv
}
开发者ID:anupamaggarwal,项目名称:yak,代码行数:41,代码来源:server.go

示例3: StartServer

//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant key/value service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *KVPaxos {
	// this call is all that's needed to persuade
	// Go's RPC library to marshall/unmarshall
	// struct Op.
	gob.Register(Op{})

	kv := new(KVPaxos)
	kv.me = me

	// Your initialization code here.
	kv.mydb = map[string]string{}
	kv.history = map[int64]string{}
	kv.DoneInst = 0

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

	kv.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for kv.dead == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.dead == false {
				if kv.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.unreliable && (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 && kv.dead == false {
				fmt.Printf("KVPaxos(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()

	return kv
}
开发者ID:bigaditya,项目名称:mit-ds-course,代码行数:66,代码来源:server.go

示例4: StartServer

func StartServer(servers []string, me int) *ShardMaster {
	gob.Register(Op{})
	sm := new(ShardMaster)

	path_parts := strings.Split(servers[me], "/")
	sm.db_path = db_path + path_parts[len(path_parts)-1]
	os.Remove(sm.db_path)
	sm.db = dbaccess.GetDatabase(sm.db_path)

	// Put my index
	sm.db.PutInt(METADATA, "me", me)
	sm.me = me

	// Enter peers
	sm.db.PutStringList(METADATA, "servers", servers)

	first_conf := new(Config)
	first_conf.Groups = map[int64][]string{}
	sm.DBPutConfig(0, first_conf)
	sm.db.PutInt(METADATA, "num_configs", 1)

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

	sm.px = paxos.Make(servers, me, rpcs)
	FinishStartServer(sm, servers, me, rpcs)
	return sm
}
开发者ID:jefesaurus,项目名称:6824final,代码行数:28,代码来源:server.go

示例5: StartServer

//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant shardmaster service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *ShardMaster {
	gob.Register(Op{})

	sm := new(ShardMaster)
	sm.me = me

	sm.configs = make([]Config, 1)
	sm.configs[0].Groups = map[int64][]string{}

	//your initialization
	sm.cfgnum = 0

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

	sm.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for sm.dead == false {
			conn, err := sm.l.Accept()
			if err == nil && sm.dead == false {
				if sm.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if sm.unreliable && (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 && sm.dead == false {
				fmt.Printf("ShardMaster(%v) accept: %v\n", me, err.Error())
				sm.Kill()
			}
		}
	}()

	return sm
}
开发者ID:pokerG,项目名称:6.824,代码行数:64,代码来源:server.go

示例6: NewKVPaxosMap

func NewKVPaxosMap(peers []string, me int) *KVPaxosMap {
	m := &KVPaxosMap{}
	m.lock = sync.Mutex{}
	m.px = paxos.Make(peers, me, nil)
	m.done = 0
	m.data = make(map[string]string)
	m.dead = false
	return m
}
开发者ID:fakeloveyy,项目名称:Proj4,代码行数:9,代码来源:kvpaxos.go

示例7: NewEPServer

func NewEPServer(pxpeers []string, me int, sio *socketio.Server) *EPServer {
	gob.Register(PxLogEntry{})

	es := &EPServer{}
	es.sio = sio
	es.px = paxos.Make(pxpeers, me, nil)
	es.skts = make(map[string]string)
	es.pads = make(map[string]*PadManager)
	es.commitPoint = 0

	return es
}
开发者ID:syb7573330,项目名称:sharedoc-paxos,代码行数:12,代码来源:epServer.go

示例8: StartWhanauPaxos

func StartWhanauPaxos(servers []string, me int, uid string,
	rpcs *rpc.Server) *WhanauPaxos {

	wp := new(WhanauPaxos)

	if rpcs != nil {
		// caller will create socket &c
		rpcs.Register(wp)
	} else {
		rpcs := rpc.NewServer()
		rpcs.Register(wp)
	}

	newservers := make([]string, len(servers))
	for i, _ := range servers {
		newservers[i] = port(uid+"-wp", i)
	}

	wp.handledRequests = make(map[int64]interface{})
	wp.px = paxos.Make(newservers, me, nil)
	wp.db = make(map[KeyType]TrueValueType)
	wp.pending_writes = make(map[PendingInsertsKey]string)
	wp.currSeq = 0
	wp.currView = 0
	wp.me = me
	wp.myaddr = servers[me]
	wp.uid = uid

	gob.Register(Op{})
	gob.Register(PaxosGetArgs{})
	gob.Register(PaxosPutArgs{})
	gob.Register(PaxosGetReply{})
	gob.Register(PaxosPutReply{})
	gob.Register(PaxosPendingInsertsArgs{})
	gob.Register(PaxosPendingInsertsReply{})

	return wp
}
开发者ID:csukuangfj,项目名称:speedy,代码行数:38,代码来源:whanau_paxos.go

示例9: MakeServer

func MakeServer(servers []string, me int, dc DeveloperCoord, numTaskReplicas int, seed int64, socktype string) *Coordinator {
	gob.Register(Op{})
	gob.Register(map[string]interface{}{})
	gob.Register([]interface{}{})

	co := new(Coordinator)
	co.socktype = socktype
	co.me = me
	co.dc = dc
	co.currentView = View{0, false, nil, map[TaskID]TaskParams{}, map[TaskID][]ClientID{}, map[TaskID][]ClientID{}, map[TaskID]TaskInfo{}, map[ClientID]string{}}
	co.initialized = false
	co.leaderID = 0
	co.leaderNum = 0
	co.currentSeq = -1
	co.lastQueries = map[ClientID]int{}
	co.lastLeaderElection = time.Now()

	co.seed = seed
	co.numTaskReplicas = numTaskReplicas
	co.unassignedTasks = list.New()
	co.activeTasks = map[ClientID]map[TaskID]bool{}
	co.availableClients = map[ClientID]int{}
	co.killedTasks = map[TaskID]bool{}
	co.finishedTasks = map[TaskID]bool{}

	co.isFinished = false

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

	co.px = paxos.Make(servers, me, rpcs, socktype)

	// TODO: change this implementation for TCP sockets when necessary
	os.Remove(servers[me])
	l, e := net.Listen(co.socktype, servers[me])
	if e != nil {
		log.Fatal("listen error: ", e)
	}
	co.l = l

	// Code to listen and serve requests
	go func() {
		for !co.dead {
			conn, err := co.l.Accept()
			if err == nil && !co.dead {
				if co.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request
					conn.Close()
				} else if co.unreliable && (rand.Int63()%1000) < 200 {
					// process request but discard 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 && !co.dead {
				fmt.Printf("Coordinator(%v) accept: %v\n", me, err.Error())
				co.Kill()
			}
		}
	}()

	return co
}
开发者ID:alect,项目名称:TaskSprint,代码行数:72,代码来源:server.go

示例10: StartServer

//
// Start a shardkv server.
// gid is the ID of the server's replica group.
// shardmasters[] contains the ports of the
//   servers that implement the shardmaster.
// servers[] contains the ports of the servers
//   in this replica group.
// me is the index of this server in servers[].
//
func StartServer(gid int64, shardmasters []string,
	servers []string, me int) *ShardKV {
	gob.Register(Op{})
	gob.Register(GetArgs{})
	gob.Register(PutArgs{})
	gob.Register(ReConfigStartArgs{})
	gob.Register(ReConfigEndArgs{})
	gob.Register(ReceiveShardArgs{})
	gob.Register(SentShardArgs{})
	gob.Register(NoopArgs{})
	gob.Register(KVPair{})

	kv := new(ShardKV)
	kv.me = me
	kv.gid = gid
	kv.sm = shardmaster.MakeClerk(shardmasters)
	// Your initialization code here.
	// Don't call Join().
	kv.config_prior = shardmaster.Config{}        // initial prior Config
	kv.config_prior.Groups = map[int64][]string{} // initialize map
	kv.config_now = shardmaster.Config{}          // initial prior Config
	kv.config_now.Groups = map[int64][]string{}   // initialize map
	kv.shards = make([]bool, shardmaster.NShards)
	kv.transition_to = -1
	kv.storage = map[string]string{} // key/value data storage
	kv.cache = map[string]Reply{}    // "client_id:request_id" -> reply cache
	kv.operation_number = -1         // first agreement number will be 0

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

	kv.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for kv.dead == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.dead == false {
				if kv.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.unreliable && (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 && kv.dead == false {
				fmt.Printf("ShardKV(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()

	go func() {
		for kv.dead == false {
			kv.tick()
			time.Sleep(250 * time.Millisecond)
		}
	}()

	return kv
}
开发者ID:dghubble,项目名称:6.824,代码行数:90,代码来源:server.go

示例11: StartServer

//
// Start a shardkv server.
// gid is the ID of the server's replica group.
// shardmasters[] contains the ports of the
//   servers that implement the shardmaster.
// servers[] contains the ports of the servers
//   in this replica group.
// Me is the index of this server in servers[].
//
func StartServer(gid int64, shardmasters []string,
	servers []string, me int) *ShardKV {
	gob.Register(Op{})
	DPrintf("%d.%d starting", me, gid)
	kv := new(ShardKV)
	kv.me = me
	kv.gid = gid
	kv.sm = shardmaster.MakeClerk(shardmasters)
	kv.contOK = make(chan bool)

	// Your initialization code here.
	// Don't call Join().
	kv.config = &shardmaster.Config{}
	kv.shards = &shards{shards: make([]map[int]map[string]string,
		shardmaster.NShards), latest: 0}
	for i, _ := range kv.shards.shards {
		kv.shards.shards[i] = make(map[int]map[string]string)
	}
	kv.states = &clientStates{states: make([]map[int]map[string]*Op,
		shardmaster.NShards), latest: 0}
	for i, _ := range kv.states.states {
		kv.states.states[i] = make(map[int]map[string]*Op)
	}
	kv.outstanding = make(map[int]chan *Op)
	kv.highestApplied = -1
	kv.count = 0

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

	kv.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for kv.dead == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.dead == false {
				if kv.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.unreliable && (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 && kv.dead == false {
				fmt.Printf("ShardKV(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()

	go func() {
		for kv.dead == false {
			kv.tick()
			time.Sleep(250 * time.Millisecond)
		}
	}()

	go kv.getStatus()
	return kv
}
开发者ID:salibrandi,项目名称:mexos,代码行数:90,代码来源:server.go

示例12: main

func main() {
	var npaxos = flag.Int("npaxos", 3, "number of paxos instances")
	var ngroups = flag.Int("ngroups", 3, "number of shard groups")
	var nmasters = flag.Int("nmasters", 3, "number of shardmasters per shard group")
	var nreplicas = flag.Int("nreplicas", 3, "number of kvshard replicas per group")
	var clean = flag.Bool("clean", false, "clean the db")

	flag.Parse()
	args := flag.Args()
	if len(args) < 1 {
		fmt.Printf("Not enough arguments, must specify program type:\n" +
			"   paxos|shardmaster|shardkv\n")
		os.Exit(1)
	}

	switch args[0] {
	case "paxos":
		fmt.Println("Attempting to start paxos server...")
		if *clean {
			cleanDB("paxos")
		}
		peers := test.GetPaxos(*npaxos)
		me := whoami(peers)
		if me == -1 {
			fmt.Println("Host didn't find own IP in peer list! Exiting!")
			os.Exit(1)
		}
		paxos.Make(peers, me, nil, network, "somedbtag")
		fmt.Println("peers: ", peers)
		fmt.Println("me: ", me)
		fmt.Printf("Started paxos server.\n")

	case "shardmaster":
		fmt.Println("Attempting to start shardmaster server...")
		if *clean {
			cleanDB("shardmaster")
		}
		peers, _ := test.GetShardmasters(*nmasters, *ngroups)
		me := whoami(peers)
		if me == -1 {
			fmt.Println("Host didn't find own IP in peer list! Exiting!")
			os.Exit(1)
		}
		shardmaster.StartServer(peers, me, network)
		fmt.Println("peers: ", peers)
		fmt.Println("me: ", me)
		fmt.Printf("Started shardmaster.\n")

	case "shardkv":
		fmt.Println("------------------------------------------")
		fmt.Println(getIP(), "attempting to start shardkv server...")
		//---------Default Shardmaster Servers------------
		//group 100: 10.0.0.101
		//group 101: 10.0.0.102
		//group 102: 10.0.0.103
		//-----------Default ShardKV Servers--------------
		//group 100: 10.0.0.104, 10.0.0.105, 10.0.0.106
		//group 101: 10.0.0.107, 10.0.0.108, 10.0.0.109
		//group 102: 10.0.0.110, 10.0.0.111, 10.0.0.112
		metapeers, masters, _ := test.GetShardkvs(*nreplicas, *nmasters, *ngroups)
		fmt.Printf("peers: %v\n", metapeers)

		me := whoami(masters)
		if me != -1 {
			fmt.Println("Starting shardmaster instead.")
			if *clean {
				cleanDB("shardmaster")
			}
			shardmaster.StartServer(masters, me, network)
			fmt.Printf("peers: %v\n", masters)
			fmt.Printf("me: %d\n", me)
			fmt.Println("Success!")
			select {}
		}
		var gid int64
		peers := make([]string, *ngroups)
		for i, v := range metapeers {
			peers = v
			me = whoami(v)
			gid = int64(100 + i)
			if me != -1 {
				break
			}
		}
		if me == -1 {
			fmt.Printf("Exiting! Host didn't find own IP %s in peer list: %v! "+
				"or masters: %v\n",
				getIP(), metapeers, masters)
			os.Exit(1)
		}
		if *clean {
			cleanDB("shardkv")
		}
		fmt.Println("masters:", masters)
		fmt.Printf("peers: %v\n", peers)
		fmt.Printf("me: %d, gid :%d\n", me, gid)
		shardkv.StartServer(gid, masters, peers, me, network)

	default:
		fmt.Printf("Invalid program type, choose one:" +
//.........这里部分代码省略.........
开发者ID:salibrandi,项目名称:mexos,代码行数:101,代码来源:start.go

示例13: StartServer

//
// Start a shardkv server.
// gid is the ID of the server's replica group.
// shardmasters[] contains the ports of the
//   servers that implement the shardmaster.
// servers[] contains the ports of the servers
//   in this replica group.
// Me is the index of this server in servers[].
//
func StartServer(gid int64,
	shardmasters []string,
	servers []string, me int,
	messagebrokers []string) *ShardKV {
	gob.Register(Op{})
	gob.Register(PutArgs{})
	gob.Register(GetArgs{})
	gob.Register(SubscribeArgs{})
	gob.Register(ReconfigArgs{})
	gob.Register(TransferArgs{})

	kv := new(ShardKV)
	kv.me = me
	kv.gid = gid
	kv.sm = shardmaster.MakeClerk(shardmasters)
	kv.mb = messagebroker.MakeNotifier(messagebrokers)
	kv.config = kv.sm.Query(0)

	kv.table = make(map[string]*Entry)
	kv.tableCache = make(map[int]map[string]*Entry)
	kv.reqs = make(map[string]*Result)
	kv.reqsCache = make(map[int]map[string]*Result)

	kv.lastAppliedSeq = -1

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

	kv.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for kv.dead == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.dead == false {
				if kv.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.unreliable && (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 && kv.dead == false {
				fmt.Printf("ShardKV(%v) accept: %v\n", me, err.Error())
				kv.Kill()
			}
		}
	}()

	go func() {
		for !kv.dead {
			kv.tick()
			time.Sleep(250 * time.Millisecond)
		}
	}()

	go kv.logSync()

	return kv
}
开发者ID:jeffchan,项目名称:pushydb,代码行数:89,代码来源:server.go

示例14: StartServer

//
// Start a shardkv server.
// gid is the ID of the server's replica group.
// shardmasters[] contains the ports of the
//   servers that implement the shardmaster.
// servers[] contains the ports of the servers
//   in this replica group.
// Me is the index of this server in servers[].
// dir is the directory name under which this
//   replica should store all its files.
//   each replica is passed a different directory.
// restart is false the very first time this server
//   is started, and true to indicate a re-start
//   after a crash or after a crash with disk loss.
//
func StartServer(gid int64, shardmasters []string,
	servers []string, me int, dir string, restart bool) *DisKV {

	kv := new(DisKV)
	kv.me = me
	kv.gid = gid
	kv.sm = shardmaster.MakeClerk(shardmasters)
	kv.dir = dir

	// Your initialization code here.
	// Don't call Join().

	// log.SetOutput(ioutil.Discard)

	gob.Register(Op{})

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

	kv.px = paxos.Make(servers, me, rpcs)

	// log.SetOutput(os.Stdout)

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

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

	go func() {
		for kv.isdead() == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.isdead() == false {
				if kv.isunreliable() && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.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 && kv.isdead() == false {
				fmt.Printf("DisKV(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()

	go func() {
		for kv.isdead() == false {
			kv.tick()
			time.Sleep(250 * time.Millisecond)
		}
	}()

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

示例15: StartServer

//
// Start a shardkv server.
// gid is the ID of the server's replica group.
// shardmasters[] contains the ports of the
//   servers that implement the shardmaster.
// servers[] contains the ports of the servers
//   in this replica group.
// Me is the index of this server in servers[].
//
func StartServer(gid int64, shardmasters []string,
	servers []string, me int) *ShardKV {
	gob.Register(Op{})
	gob.Register(&ConfigBid{})
	gob.Register(&StartHandoff{})
	gob.Register(&EndHandoff{})
	gob.Register(&ShardData{})
	gob.Register(&PutArgs{})
	gob.Register(&GetArgs{})
	gob.Register(&GetShardArgs{})
	gob.Register(&PingArgs{})

	kv := new(ShardKV)
	kv.me = me
	kv.gid = gid
	kv.sm = shardmaster.MakeClerk(shardmasters)

	for i := range kv.dataForShard {
		kv.dataForShard[i] = &ShardData{
			Id:   i,
			Data: make(map[string]string),
		}
	}

	kv.cond = sync.NewCond(&kv.dataForShard[shardmaster.NShards].mu)

	kv.dataForShard[shardmaster.NShards].active = true
	kv.dataForShard[shardmaster.NShards].Num = -1

	kv.requests = make(map[int64]*RequestState)

	kv.subscribe = make(chan ExecuteRequest)
	kv.commitRequest = make(chan Op)
	kv.commitResponse = make(chan int)
	kv.ping = make(chan PingArgs, 100)

	go kv.commitRequests()

	go kv.executeStateMachine()

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

	kv.px = paxos.Make(servers, me, rpcs)

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

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

	go func() {
		for kv.dead == false {
			conn, err := kv.l.Accept()
			if err == nil && kv.dead == false {
				if kv.unreliable && (rand.Int63()%1000) < 100 {
					// discard the request.
					conn.Close()
				} else if kv.unreliable && (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 && kv.dead == false {
				fmt.Printf("ShardKV(%v) accept: %v\n", me, err.Error())
				kv.kill()
			}
		}
	}()

	go func() {
		for kv.dead == false {
			kv.tick()
			time.Sleep(250 * time.Millisecond)
		}
	}()

//.........这里部分代码省略.........
开发者ID:byrlhb,项目名称:mit-6.824-labs,代码行数:101,代码来源:server.go


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