func waitReplies(readers []*bufio.Reader, leader int, n int, done chan bool) { e := false reply := new(genericsmrproto.ProposeReply) for i := 0; i < n; i++ { /*if *noLeader { leader = rarray[i] }*/ if err := reply.Unmarshal(readers[leader]); err != nil { fmt.Println("Error when reading:", err) e = true //continue break } if *check { if rsp[reply.Instance] { fmt.Println("Duplicate reply", reply.Instance) } rsp[reply.Instance] = true } if reply.OK != 0 { successful[leader]++ succLock.Lock() succ++ succLock.Unlock() } } done <- e }
func (r *Replica) ReplyPropose(reply *genericsmrproto.ProposeReply, w *bufio.Writer) { //r.clientMutex.Lock() //defer r.clientMutex.Unlock() //w.WriteByte(genericsmrproto.PROPOSE_REPLY) reply.Marshal(w) w.Flush() }
func (r *Replica) ReplyPropose(reply *genericsmrproto.ProposeReply, propose *Propose) { if propose.Writer == nil || propose.Lock == nil { return } propose.Lock.Lock() defer propose.Lock.Unlock() //w.WriteByte(genericsmrproto.PROPOSE_REPLY) reply.Marshal(propose.Writer) propose.Writer.Flush() }
func waitForReplies(reader *bufio.Reader, repliesChan chan int32) { var reply genericsmrproto.ProposeReply for true { if err := reply.Unmarshal(reader); err != nil || reply.OK == 0 { return //fmt.Println("Error when reading from replica:", err) //continue } repliesChan <- reply.Instance } }
func simulatedClient(rlReply *masterproto.GetReplicaListReply, leader int, readings chan float64, done chan bool) { N := len(rlReply.ReplicaList) servers := make([]net.Conn, N) readers := make([]*bufio.Reader, N) writers := make([]*bufio.Writer, N) rarray := make([]int, *reqsNb) karray := make([]int64, *reqsNb) perReplicaCount := make([]int, N) M := N if *barOne { M = N - 1 } randObj := rand.New(rand.NewSource(42)) zipf := rand.NewZipf(randObj, *s, *v, uint64(*reqsNb)) for i := 0; i < len(rarray); i++ { r := rand.Intn(M) rarray[i] = r perReplicaCount[r]++ if *conflicts >= 0 { r = rand.Intn(100) if r < *conflicts { karray[i] = 42 } else { karray[i] = int64(*startRange + 43 + i) } } else { karray[i] = int64(zipf.Uint64()) } } for i := 0; i < N; i++ { var err error servers[i], err = net.Dial("tcp", rlReply.ReplicaList[i]) if err != nil { log.Printf("Error connecting to replica %d\n", i) } readers[i] = bufio.NewReader(servers[i]) writers[i] = bufio.NewWriter(servers[i]) } var id int32 = 0 args := genericsmrproto.Propose{id, state.Command{state.PUT, 0, 0}} var reply genericsmrproto.ProposeReply n := *reqsNb for i := 0; i < n; i++ { if *noLeader { leader = rarray[i] } args.ClientId = id args.Command.K = state.Key(karray[i]) writers[leader].WriteByte(genericsmrproto.PROPOSE) before := time.Now() args.Marshal(writers[leader]) writers[leader].Flush() if err := reply.Unmarshal(readers[leader]); err != nil || reply.OK == 0 { fmt.Println("Error when reading:", err) continue } after := time.Now() id++ readings <- (after.Sub(before)).Seconds() * 1000 if *sleep > 0 { time.Sleep(100 * 1000 * 1000) } } for _, client := range servers { if client != nil { client.Close() } } done <- true }