func GroupWrite(c *GroupClientConfig) { defer c.wg.Done() var err error var opts []grpc.DialOption var creds credentials.TransportAuthenticator creds = credentials.NewTLS(&tls.Config{ InsecureSkipVerify: true, }) opts = append(opts, grpc.WithTransportCredentials(creds)) conn, err := grpc.Dial(c.addr, opts...) if err != nil { log.Fatalln(fmt.Sprintf("Failed to dial server: %s", err)) } defer conn.Close() client := gp.NewGroupStoreClient(conn) w := &gp.WriteRequest{ Value: *c.value, } empty := []byte("") for i, _ := range c.wm { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) c.wm[i].Value = *c.value w.TimestampMicro = brimtime.TimeToUnixMicro(time.Now()) res, err := client.Write(ctx, c.wm[i]) if err != nil { log.Println("Client", c.id, ":", err) } if res.TimestampMicro > w.TimestampMicro { log.Printf("TSM is newer than attempted, Key %d-%d Got %s, Sent: %s", c.id, i, brimtime.UnixMicroToTime(res.TimestampMicro), brimtime.UnixMicroToTime(w.TimestampMicro)) } c.wm[i].Value = empty } }
func ValueStreamWrite(c *ValueClientConfig) { defer c.wg.Done() var err error var opts []grpc.DialOption var creds credentials.TransportAuthenticator creds = credentials.NewTLS(&tls.Config{ InsecureSkipVerify: true, }) opts = append(opts, grpc.WithTransportCredentials(creds)) conn, err := grpc.Dial(c.addr, opts...) if err != nil { log.Fatalln(fmt.Sprintf("Failed to dial server: %s", err)) } defer conn.Close() client := vp.NewValueStoreClient(conn) empty := []byte("") stream, err := client.StreamWrite(context.Background()) for i, _ := range c.wm { c.wm[i].Value = *c.value if err := stream.Send(c.wm[i]); err != nil { log.Println(err) continue } res, err := stream.Recv() if err == io.EOF { return } if err != nil { log.Println(err) continue } if res.TimestampMicro > c.wm[i].TimestampMicro { log.Printf("TSM is newer than attempted, Key %d-%d Got %s, Sent: %s", c.id, i, brimtime.UnixMicroToTime(res.TimestampMicro), brimtime.UnixMicroToTime(c.wm[i].TimestampMicro)) } c.wm[i].Value = empty } stream.CloseSend() }