Skip to content

Commit 3ac57b6

Browse files
authored
Revert "Revert "add bidirectional streaming support for external snapshot (#276)
1 parent c5607f0 commit 3ac57b6

File tree

5 files changed

+93
-76
lines changed

5 files changed

+93
-76
lines changed

client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestOpen(t *testing.T) {
3535
require.ErrorContains(t, err, "invalid connection string: host url must have both host and port")
3636

3737
_, err = dgo.Open("dgraph://localhost:")
38-
require.ErrorContains(t, err, "missing port after port-separator colon")
38+
require.ErrorContains(t, err, "invalid connection string: missing port after port-separator colon")
3939

4040
_, err = dgo.Open("dgraph://localhost:9180?sslmode=verify-ca")
4141
require.ErrorContains(t, err, "first record does not look like a TLS handshake")
@@ -77,7 +77,7 @@ func TestOpen(t *testing.T) {
7777
require.ErrorContains(t, err, "invalid namespace ID: strconv.ParseUint: parsing \"root\": invalid syntax")
7878

7979
_, err = dgo.Open("dgraph://user:pass@localhost:9180?namespace=1")
80-
require.NoError(t, err)
80+
require.ErrorContains(t, err, "invalid username or password")
8181

8282
_, err = dgo.Open("dgraph://groot:password@localhost:9180")
8383
require.NoError(t, err)

open.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ func Open(connStr string) (*Dgraph, error) {
169169
if apiKey != "" && bearerToken != "" {
170170
return nil, errors.New("invalid connection string: both apikey and bearertoken cannot be provided")
171171
}
172-
if !strings.Contains(u.Host, ":") {
172+
if len(strings.Split(u.Host, ":")) != 2 {
173173
return nil, errors.New("invalid connection string: host url must have both host and port")
174174
}
175+
if strings.Split(u.Host, ":")[1] == "" {
176+
return nil, errors.New("invalid connection string: missing port after port-separator colon")
177+
}
175178

176179
opts := []ClientOption{}
177180
if apiKey != "" {
@@ -257,6 +260,11 @@ func NewRoundRobinClient(endpoints []string, opts ...ClientOption) (*Dgraph, err
257260
}
258261
}
259262

263+
if _, err := dc[0].CheckVersion(context.Background(), &api.Check{}); err != nil {
264+
d.Close()
265+
return nil, fmt.Errorf("failed to ping: %w", err)
266+
}
267+
260268
return d, nil
261269
}
262270

protos/api.proto

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ service Dgraph {
2929
rpc AllocateIDs(AllocateIDsRequest) returns (AllocateIDsResponse) {}
3030

3131
rpc UpdateExtSnapshotStreamingState(UpdateExtSnapshotStreamingStateRequest) returns (UpdateExtSnapshotStreamingStateResponse) {}
32-
rpc StreamExtSnapshot(stream StreamExtSnapshotRequest) returns (StreamExtSnapshotResponse) {}
32+
rpc StreamExtSnapshot(stream StreamExtSnapshotRequest) returns (stream StreamExtSnapshotResponse) {}
3333

3434
rpc CreateNamespace(CreateNamespaceRequest) returns (CreateNamespaceResponse) {}
3535
rpc DropNamespace(DropNamespaceRequest) returns (DropNamespaceResponse) {}
@@ -264,7 +264,9 @@ message StreamExtSnapshotRequest {
264264
StreamPacket pkt = 3;
265265
}
266266

267-
message StreamExtSnapshotResponse {}
267+
message StreamExtSnapshotResponse {
268+
bool finish = 1;
269+
}
268270

269271
message StreamPacket {
270272
bytes data = 1;

protos/api/api.pb.go

Lines changed: 72 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/api/api_grpc.pb.go

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)