Skip to content

Commit e4b7425

Browse files
authored
remove depecrated code used from grpc library (#9345)
1 parent 630d596 commit e4b7425

24 files changed

Lines changed: 39 additions & 57 deletions

File tree

conn/pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func newPool(addr string, tlsClientConf *tls.Config) (*Pool, error) {
173173
conOpts = append(conOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
174174
}
175175

176-
conn, err := grpc.Dial(addr, conOpts...)
176+
conn, err := grpc.NewClient(addr, conOpts...)
177177
if err != nil {
178178
glog.Errorf("unable to connect with %s : %s", addr, err)
179179
return nil, err
@@ -284,7 +284,7 @@ func (p *Pool) MonitorHealth() {
284284
return
285285
}
286286
ctx, cancel := context.WithTimeout(p.closer.Ctx(), 10*time.Second)
287-
conn, err := grpc.DialContext(ctx, p.Addr, p.dialOpts...)
287+
conn, err := grpc.NewClient(p.Addr, p.dialOpts...)
288288
if err == nil {
289289
// Make a dummy request to test out the connection.
290290
client := pb.NewRaftClient(conn)

dgraph/cmd/alpha/mutations_mode/mutations_mode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func mutateExistingAllowed2(t *testing.T, dg *dgo.Dgraph) {
140140

141141
func TestMutationsDisallow(t *testing.T) {
142142
a := testutil.ContainerAddr("alpha1", 9080)
143-
conn, err := grpc.Dial(a, grpc.WithTransportCredentials(insecure.NewCredentials()))
143+
conn, err := grpc.NewClient(a, grpc.WithTransportCredentials(insecure.NewCredentials()))
144144
if err != nil {
145145
t.Fatalf("Cannot perform drop all op: %s", err.Error())
146146
}
@@ -158,14 +158,14 @@ func TestMutationsDisallow(t *testing.T) {
158158

159159
func TestMutationsStrict(t *testing.T) {
160160
a1 := testutil.ContainerAddr("alpha2", 9080)
161-
conn1, err := grpc.Dial(a1, grpc.WithTransportCredentials(insecure.NewCredentials()))
161+
conn1, err := grpc.NewClient(a1, grpc.WithTransportCredentials(insecure.NewCredentials()))
162162
if err != nil {
163163
t.Fatalf("Cannot perform drop all op: %s", err.Error())
164164
}
165165
defer conn1.Close()
166166

167167
a2 := testutil.ContainerAddr("alpha3", 9080)
168-
conn2, err := grpc.Dial(a2, grpc.WithTransportCredentials(insecure.NewCredentials()))
168+
conn2, err := grpc.NewClient(a2, grpc.WithTransportCredentials(insecure.NewCredentials()))
169169
if err != nil {
170170
t.Fatalf("Cannot perform drop all op: %s", err.Error())
171171
}

dgraph/cmd/bulk/loader.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,16 @@ func newLoader(opt *options) *loader {
103103
}
104104

105105
fmt.Printf("Connecting to zero at %s\n", opt.ZeroAddr)
106-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
107-
defer cancel()
108106

109107
tlsConf, err := x.LoadClientTLSConfigForInternalPort(Bulk.Conf)
110108
x.Check(err)
111-
dialOpts := []grpc.DialOption{
112-
grpc.WithBlock(),
113-
}
109+
dialOpts := []grpc.DialOption{}
114110
if tlsConf != nil {
115111
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(tlsConf)))
116112
} else {
117113
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
118114
}
119-
zero, err := grpc.DialContext(ctx, opt.ZeroAddr, dialOpts...)
115+
zero, err := grpc.NewClient(opt.ZeroAddr, dialOpts...)
120116
x.Checkf(err, "Unable to connect to zero, Is it running at %s?", opt.ZeroAddr)
121117
st := &state{
122118
opt: opt,

dgraph/cmd/zero/zero_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ func TestIdLeaseOverflow(t *testing.T) {
4747
}
4848

4949
func TestIdBump(t *testing.T) {
50-
dialOpts := []grpc.DialOption{
51-
grpc.WithBlock(),
52-
grpc.WithTransportCredentials(insecure.NewCredentials()),
53-
}
50+
dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
5451
ctx := context.Background()
55-
con, err := grpc.DialContext(ctx, testutil.SockAddrZero, dialOpts...)
52+
con, err := grpc.NewClient(testutil.SockAddrZero, dialOpts...)
5653
require.NoError(t, err)
5754

5855
zc := pb.NewZeroClient(con)

dgraphtest/local_cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ func (c *LocalCluster) Client() (*dgraphapi.GrpcClient, func(), error) {
774774
if err != nil {
775775
return nil, nil, errors.Wrap(err, "error getting health URL")
776776
}
777-
conn, err := grpc.Dial(url,
777+
conn, err := grpc.NewClient(url,
778778
grpc.WithTransportCredentials(insecure.NewCredentials()),
779779
grpc.WithDefaultServiceConfig(retryPolicy))
780780
if err != nil {
@@ -804,7 +804,7 @@ func (c *LocalCluster) AlphaClient(id int) (*dgraphapi.GrpcClient, func(), error
804804
if err != nil {
805805
return nil, nil, errors.Wrap(err, "error getting health URL")
806806
}
807-
conn, err := grpc.Dial(url, grpc.WithTransportCredentials(insecure.NewCredentials()))
807+
conn, err := grpc.NewClient(url, grpc.WithTransportCredentials(insecure.NewCredentials()))
808808
if err != nil {
809809
return nil, nil, errors.Wrap(err, "error connecting to alpha")
810810
}

ee/backup/run.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,17 @@ func runRestoreCmd() error {
182182
var zc pb.ZeroClient
183183
if opt.zero != "" {
184184
fmt.Println("Updating Zero timestamp at:", opt.zero)
185-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
186-
defer cancel()
187185

188186
tlsConfig, err := x.LoadClientTLSConfigForInternalPort(Restore.Conf)
189187
x.Checkf(err, "Unable to generate helper TLS config")
190-
callOpts := []grpc.DialOption{grpc.WithBlock()}
188+
callOpts := []grpc.DialOption{}
191189
if tlsConfig != nil {
192190
callOpts = append(callOpts, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
193191
} else {
194192
callOpts = append(callOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
195193
}
196194

197-
zero, err := grpc.DialContext(ctx, opt.zero, callOpts...)
195+
zero, err := grpc.NewClient(opt.zero, callOpts...)
198196
if err != nil {
199197
return errors.Wrapf(err, "Unable to connect to %s", opt.zero)
200198
}

graphql/e2e/common/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const (
152152
)
153153

154154
func admin(t *testing.T) {
155-
d, err := grpc.Dial(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
155+
d, err := grpc.NewClient(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
156156
require.NoError(t, err)
157157

158158
oldCounter := RetryProbeGraphQL(t, Alpha1HTTP, nil).SchemaUpdateCounter

graphql/e2e/common/common.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,7 @@ func BootstrapServer(schema, data []byte) {
744744
"Got last error %+v", err.Error()))
745745
}
746746

747-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
748-
defer cancel()
749-
d, err := grpc.DialContext(ctx, Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
747+
d, err := grpc.NewClient(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
750748
if err != nil {
751749
x.Panic(err)
752750
}

graphql/e2e/common/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func graphQLCompletionOn(t *testing.T) {
5151
// The schema states type Country `{ ... name: String! ... }`
5252
// so a query error will be raised if we ask for the country's name in a
5353
// query. Don't think a GraphQL update can do this ATM, so do through Dgraph.
54-
d, err := grpc.Dial(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
54+
d, err := grpc.NewClient(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
5555
require.NoError(t, err)
5656
client := dgo.NewDgraphClient(api.NewDgraphClient(d))
5757
mu := &api.Mutation{

graphql/e2e/common/mutation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ func manyMutationsWithQueryError(t *testing.T) {
21382138
// The schema states type Country `{ ... name: String! ... }`
21392139
// so a query error will be raised if we ask for the country's name in a
21402140
// query. Don't think a GraphQL update can do this ATM, so do through Dgraph.
2141-
d, err := grpc.Dial(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
2141+
d, err := grpc.NewClient(Alpha1gRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
21422142
require.NoError(t, err)
21432143
client := dgo.NewDgraphClient(api.NewDgraphClient(d))
21442144
mu := &api.Mutation{

0 commit comments

Comments
 (0)