Skip to content

Commit

Permalink
Add uuid to request contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
aminst committed Jun 6, 2023
1 parent 86c1fb8 commit 6fa37eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (

require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0
github.com/hashicorp/raft v1.5.0
github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702
golang.org/x/net v0.8.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
Expand Down
9 changes: 7 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

routerpb "github.com/dsg-uwaterloo/oblishard/api/router"
"github.com/dsg-uwaterloo/oblishard/pkg/config"
"github.com/google/uuid"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand All @@ -16,7 +17,9 @@ type RouterRPCClient struct {
}

func (c *RouterRPCClient) Read(block string) (value string, err error) {
reply, err := c.ClientAPI.Read(context.Background(),
requestID := uuid.New().String()
ctx := context.WithValue(context.Background(), "requestID", requestID)
reply, err := c.ClientAPI.Read(ctx,
&routerpb.ReadRequest{Block: block})
if err != nil {
return "", err
Expand All @@ -25,7 +28,9 @@ func (c *RouterRPCClient) Read(block string) (value string, err error) {
}

func (c *RouterRPCClient) Write(block string, value string) (success bool, err error) {
reply, err := c.ClientAPI.Write(context.Background(),
requestID := uuid.New().String()
ctx := context.WithValue(context.Background(), "requestID", requestID)
reply, err := c.ClientAPI.Write(ctx,
&routerpb.WriteRequest{Block: block, Value: value})
if err != nil {
return false, err
Expand Down

0 comments on commit 6fa37eb

Please sign in to comment.