func ValueWrite(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) w := &vp.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 ValueStreamRead(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) stream, err := client.StreamRead(context.Background()) for i, _ := range c.rm { if err := stream.Send(c.rm[i]); err != nil { log.Println(err) continue } _, err := stream.Recv() if err == io.EOF { return } if err != nil { log.Println(err) continue } } stream.CloseSend() }
func (stor *valueStore) startup() error { if stor.conn != nil { return nil } var err error creds, err := ftls.NewGRPCClientDialOpt(stor.ftlsc) if err != nil { stor.conn = nil return err } opts := make([]grpc.DialOption, len(stor.opts)) copy(opts, stor.opts) opts = append(opts, creds) stor.conn, err = grpc.Dial(stor.addr, opts...) if err != nil { stor.conn = nil return err } stor.client = pb.NewValueStoreClient(stor.conn) return nil }
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() }
func ValueRead(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) for i, _ := range c.rm { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) _, err := client.Read(ctx, c.rm[i]) if err != nil { log.Println("Client", c.id, ":", err) } } }