Skip to content

Commit 60a0127

Browse files
authored
Rename v25 APIs to v2 APIs (#9418)
1 parent 8a774a0 commit 60a0127

File tree

14 files changed

+1008
-1009
lines changed

14 files changed

+1008
-1009
lines changed

dgraph/cmd/alpha/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939

4040
"github.com/dgraph-io/badger/v4"
4141
"github.com/dgraph-io/dgo/v250/protos/api"
42-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
42+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
4343
_ "github.com/dgraph-io/gqlparser/v2/validator/rules" // make gql validator init() all rules
4444
"github.com/dgraph-io/ristretto/v2/z"
4545
"github.com/hypermodeinc/dgraph/v25/audit"
@@ -467,7 +467,7 @@ func serveGRPC(l net.Listener, tlsCfg *tls.Config, closer *z.Closer) {
467467

468468
s := grpc.NewServer(opt...)
469469
api.RegisterDgraphServer(s, &edgraph.Server{})
470-
apiv25.RegisterDgraphServer(s, &edgraph.ServerV25{})
470+
apiv2.RegisterDgraphServer(s, &edgraph.ServerV25{})
471471
hapi.RegisterHealthServer(s, health.NewServer())
472472
worker.RegisterZeroProxyServer(s)
473473

dgraph/cmd/dgraphimport/import_client.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"path/filepath"
1616

1717
"github.com/dgraph-io/badger/v4"
18-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
18+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
1919
"github.com/dgraph-io/ristretto/v2/z"
2020

2121
"github.com/golang/glog"
@@ -24,14 +24,14 @@ import (
2424
)
2525

2626
// newClient creates a new import client with the specified endpoint and gRPC options.
27-
func newClient(endpoint string, opts grpc.DialOption) (apiv25.DgraphClient, error) {
27+
func newClient(endpoint string, opts grpc.DialOption) (apiv2.DgraphClient, error) {
2828
conn, err := grpc.NewClient(endpoint, opts)
2929
if err != nil {
3030
return nil, fmt.Errorf("failed to connect to endpoint [%s]: %w", endpoint, err)
3131
}
3232

3333
glog.Infof("Successfully connected to Dgraph endpoint: %s", endpoint)
34-
return apiv25.NewDgraphClient(conn), nil
34+
return apiv2.NewDgraphClient(conn), nil
3535
}
3636

3737
func Import(ctx context.Context, endpoint string, opts grpc.DialOption, bulkOutDir string) error {
@@ -48,9 +48,9 @@ func Import(ctx context.Context, endpoint string, opts grpc.DialOption, bulkOutD
4848
}
4949

5050
// startPDirStream initiates a snapshot stream session with the Dgraph server.
51-
func startPDirStream(ctx context.Context, dc apiv25.DgraphClient) (*apiv25.InitiatePDirStreamResponse, error) {
51+
func startPDirStream(ctx context.Context, dc apiv2.DgraphClient) (*apiv2.InitiatePDirStreamResponse, error) {
5252
glog.Info("Initiating pdir stream")
53-
req := &apiv25.InitiatePDirStreamRequest{}
53+
req := &apiv2.InitiatePDirStreamRequest{}
5454
resp, err := dc.InitiatePDirStream(ctx, req)
5555
if err != nil {
5656
glog.Errorf("failed to initiate pdir stream: %v", err)
@@ -63,7 +63,7 @@ func startPDirStream(ctx context.Context, dc apiv25.DgraphClient) (*apiv25.Initi
6363
// sendPDir takes a p directory and a set of group IDs and streams the data from the
6464
// p directory to the corresponding group IDs. It first scans the provided directory for
6565
// subdirectories named with numeric group IDs.
66-
func sendPDir(ctx context.Context, dg apiv25.DgraphClient, baseDir string, groups []uint32) error {
66+
func sendPDir(ctx context.Context, dg apiv2.DgraphClient, baseDir string, groups []uint32) error {
6767
glog.Infof("Starting to stream pdir from directory: %s", baseDir)
6868

6969
errG, ctx := errgroup.WithContext(ctx)
@@ -94,7 +94,7 @@ func sendPDir(ctx context.Context, dg apiv25.DgraphClient, baseDir string, group
9494

9595
// streamData handles the actual data streaming process for a single group.
9696
// It opens the BadgerDB at the specified directory and streams all data to the server.
97-
func streamData(ctx context.Context, dg apiv25.DgraphClient, pdir string, groupId uint32) error {
97+
func streamData(ctx context.Context, dg apiv2.DgraphClient, pdir string, groupId uint32) error {
9898
glog.Infof("Opening stream for group %d from directory %s", groupId, pdir)
9999

100100
// Initialize stream with the server
@@ -118,7 +118,7 @@ func streamData(ctx context.Context, dg apiv25.DgraphClient, pdir string, groupI
118118

119119
// Send group ID as the first message in the stream
120120
glog.Infof("Sending group ID [%d] to server", groupId)
121-
groupReq := &apiv25.StreamPDirRequest{GroupId: groupId}
121+
groupReq := &apiv2.StreamPDirRequest{GroupId: groupId}
122122
if err := out.Send(groupReq); err != nil {
123123
return fmt.Errorf("failed to send group ID [%d]: %w", groupId, err)
124124
}
@@ -129,8 +129,8 @@ func streamData(ctx context.Context, dg apiv25.DgraphClient, pdir string, groupI
129129
stream.LogPrefix = fmt.Sprintf("Sending P dir for group [%d]", groupId)
130130
stream.KeyToList = nil
131131
stream.Send = func(buf *z.Buffer) error {
132-
p := &apiv25.StreamPacket{Data: buf.Bytes()}
133-
if err := out.Send(&apiv25.StreamPDirRequest{StreamPacket: p}); err != nil && !errors.Is(err, io.EOF) {
132+
p := &apiv2.StreamPacket{Data: buf.Bytes()}
133+
if err := out.Send(&apiv2.StreamPDirRequest{StreamPacket: p}); err != nil && !errors.Is(err, io.EOF) {
134134
return fmt.Errorf("failed to send data chunk: %w", err)
135135
}
136136
return nil
@@ -143,9 +143,9 @@ func streamData(ctx context.Context, dg apiv25.DgraphClient, pdir string, groupI
143143

144144
// Send the final 'done' signal to mark completion
145145
glog.Infof("Sending completion signal for group [%d]", groupId)
146-
done := &apiv25.StreamPacket{Done: true}
146+
done := &apiv2.StreamPacket{Done: true}
147147

148-
if err := out.Send(&apiv25.StreamPDirRequest{StreamPacket: done}); err != nil && !errors.Is(err, io.EOF) {
148+
if err := out.Send(&apiv2.StreamPDirRequest{StreamPacket: done}); err != nil && !errors.Is(err, io.EOF) {
149149
return fmt.Errorf("failed to send 'done' signal for group [%d]: %w", groupId, err)
150150
}
151151
// Wait for acknowledgment from the server

edgraph/alter.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/dgraph-io/dgo/v250/protos/api"
14-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
14+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
1515
"github.com/hypermodeinc/dgraph/v25/dql"
1616
"github.com/hypermodeinc/dgraph/v25/protos/pb"
1717
"github.com/hypermodeinc/dgraph/v25/query"
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
type ServerV25 struct {
31-
apiv25.UnimplementedDgraphServer
31+
apiv2.UnimplementedDgraphServer
3232
}
3333

3434
func validateAlterReq(ctx context.Context) error {
@@ -74,7 +74,7 @@ func executeDropAll(ctx context.Context, startTs uint64) error {
7474
return nil
7575
}
7676

77-
func executeDropAllInNs(ctx context.Context, startTs uint64, req *apiv25.AlterRequest) error {
77+
func executeDropAllInNs(ctx context.Context, startTs uint64, req *apiv2.AlterRequest) error {
7878
ctx = x.AttachJWTNamespace(ctx)
7979

8080
nsID, err := getNamespaceIDFromName(ctx, req.NsName)
@@ -117,7 +117,7 @@ func executeDropAllInNs(ctx context.Context, startTs uint64, req *apiv25.AlterRe
117117
return nil
118118
}
119119

120-
func executeDropData(ctx context.Context, startTs uint64, req *apiv25.AlterRequest) error {
120+
func executeDropData(ctx context.Context, startTs uint64, req *apiv2.AlterRequest) error {
121121
nsID, err := getNamespaceIDFromName(x.AttachJWTNamespace(ctx), req.NsName)
122122
if err != nil {
123123
return err
@@ -153,7 +153,7 @@ func executeDropData(ctx context.Context, startTs uint64, req *apiv25.AlterReque
153153
return nil
154154
}
155155

156-
func executeDropPredicate(ctx context.Context, startTs uint64, req *apiv25.AlterRequest) error {
156+
func executeDropPredicate(ctx context.Context, startTs uint64, req *apiv2.AlterRequest) error {
157157
if len(req.PredicateToDrop) == 0 {
158158
return errors.Errorf("PredicateToDrop cannot be empty")
159159
}
@@ -195,7 +195,7 @@ func executeDropPredicate(ctx context.Context, startTs uint64, req *apiv25.Alter
195195
return nil
196196
}
197197

198-
func executeDropType(ctx context.Context, startTs uint64, req *apiv25.AlterRequest) error {
198+
func executeDropType(ctx context.Context, startTs uint64, req *apiv2.AlterRequest) error {
199199
if len(req.TypeToDrop) == 0 {
200200
return errors.Errorf("TypeToDrop cannot be empty")
201201
}
@@ -219,7 +219,7 @@ func executeDropType(ctx context.Context, startTs uint64, req *apiv25.AlterReque
219219
return nil
220220
}
221221

222-
func executeSetSchema(ctx context.Context, startTs uint64, req *apiv25.AlterRequest) error {
222+
func executeSetSchema(ctx context.Context, startTs uint64, req *apiv2.AlterRequest) error {
223223
nsID, err := getNamespaceIDFromName(x.AttachJWTNamespace(ctx), req.NsName)
224224
if err != nil {
225225
return err
@@ -250,7 +250,7 @@ func executeSetSchema(ctx context.Context, startTs uint64, req *apiv25.AlterRequ
250250
}
251251

252252
// Alter handles requests to change the schema or remove parts or all of the data.
253-
func (s *ServerV25) Alter(ctx context.Context, req *apiv25.AlterRequest) (*apiv25.AlterResponse, error) {
253+
func (s *ServerV25) Alter(ctx context.Context, req *apiv2.AlterRequest) (*apiv2.AlterResponse, error) {
254254
ctx, span := otel.Tracer("").Start(ctx, "ServerV25.Alter")
255255
defer span.End()
256256
span.AddEvent("Alter operation", trace.WithAttributes(attribute.String("request", req.String())))
@@ -274,19 +274,19 @@ func (s *ServerV25) Alter(ctx context.Context, req *apiv25.AlterRequest) (*apiv2
274274
// but is required if it lies on some other machine. Let's get it for safety.
275275
startTs := worker.State.GetTimestamp(false)
276276

277-
empty := &apiv25.AlterResponse{}
277+
empty := &apiv2.AlterResponse{}
278278
switch req.Op {
279-
case apiv25.AlterOp_DROP_ALL:
279+
case apiv2.AlterOp_DROP_ALL:
280280
return empty, executeDropAll(ctx, startTs)
281-
case apiv25.AlterOp_DROP_ALL_IN_NS:
281+
case apiv2.AlterOp_DROP_ALL_IN_NS:
282282
return empty, executeDropAllInNs(ctx, startTs, req)
283-
case apiv25.AlterOp_DROP_DATA_IN_NS:
283+
case apiv2.AlterOp_DROP_DATA_IN_NS:
284284
return empty, executeDropData(ctx, startTs, req)
285-
case apiv25.AlterOp_DROP_PREDICATE_IN_NS:
285+
case apiv2.AlterOp_DROP_PREDICATE_IN_NS:
286286
return empty, executeDropPredicate(ctx, startTs, req)
287-
case apiv25.AlterOp_DROP_TYPE_IN_NS:
287+
case apiv2.AlterOp_DROP_TYPE_IN_NS:
288288
return empty, executeDropType(ctx, startTs, req)
289-
case apiv25.AlterOp_SCHEMA_IN_NS:
289+
case apiv2.AlterOp_SCHEMA_IN_NS:
290290
return empty, executeSetSchema(ctx, startTs, req)
291291
default:
292292
return empty, errors.Errorf("invalid operation in Alter Request")

edgraph/namespace.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"google.golang.org/protobuf/proto"
2121

2222
"github.com/dgraph-io/dgo/v250/protos/api"
23-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
23+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
2424
"github.com/hypermodeinc/dgraph/v25/schema"
2525
"github.com/hypermodeinc/dgraph/v25/x"
2626
)
@@ -61,7 +61,7 @@ type resultNamespaces struct {
6161
}
6262

6363
func (s *ServerV25) SignInUser(ctx context.Context,
64-
request *apiv25.SignInUserRequest) (*apiv25.SignInUserResponse, error) {
64+
request *apiv2.SignInUserRequest) (*apiv2.SignInUserResponse, error) {
6565

6666
req := &api.LoginRequest{Userid: request.UserId, Password: request.Password, Namespace: 0}
6767
resp, err := (&Server{}).Login(ctx, req)
@@ -73,11 +73,11 @@ func (s *ServerV25) SignInUser(ctx context.Context,
7373
return nil, err
7474
}
7575

76-
return &apiv25.SignInUserResponse{AccessJwt: jwt.AccessJwt, RefreshJwt: jwt.RefreshJwt}, nil
76+
return &apiv2.SignInUserResponse{AccessJwt: jwt.AccessJwt, RefreshJwt: jwt.RefreshJwt}, nil
7777
}
7878

79-
func (s *ServerV25) CreateNamespace(ctx context.Context, in *apiv25.CreateNamespaceRequest) (
80-
*apiv25.CreateNamespaceResponse, error) {
79+
func (s *ServerV25) CreateNamespace(ctx context.Context, in *apiv2.CreateNamespaceRequest) (
80+
*apiv2.CreateNamespaceResponse, error) {
8181

8282
if err := AuthSuperAdmin(ctx); err != nil {
8383
s := status.Convert(err)
@@ -112,11 +112,11 @@ func (s *ServerV25) CreateNamespace(ctx context.Context, in *apiv25.CreateNamesp
112112
}
113113

114114
glog.Infof("Created namespace [%v] with id [%d]", in.NsName, ns)
115-
return &apiv25.CreateNamespaceResponse{}, nil
115+
return &apiv2.CreateNamespaceResponse{}, nil
116116
}
117117

118-
func (s *ServerV25) DropNamespace(ctx context.Context, in *apiv25.DropNamespaceRequest) (
119-
*apiv25.DropNamespaceResponse, error) {
118+
func (s *ServerV25) DropNamespace(ctx context.Context, in *apiv2.DropNamespaceRequest) (
119+
*apiv2.DropNamespaceResponse, error) {
120120

121121
if err := AuthSuperAdmin(ctx); err != nil {
122122
s := status.Convert(err)
@@ -152,7 +152,7 @@ func (s *ServerV25) DropNamespace(ctx context.Context, in *apiv25.DropNamespaceR
152152

153153
if nsID == 0 {
154154
glog.Infof("Namespace [%v] not found", in.NsName)
155-
return &apiv25.DropNamespaceResponse{}, nil
155+
return &apiv2.DropNamespaceResponse{}, nil
156156
}
157157

158158
// If we crash at this point, it is possible that namespace is deleted
@@ -167,11 +167,11 @@ func (s *ServerV25) DropNamespace(ctx context.Context, in *apiv25.DropNamespaceR
167167
}
168168

169169
glog.Infof("Dropped namespace [%v] with id [%d]", in.NsName, nsID)
170-
return &apiv25.DropNamespaceResponse{}, nil
170+
return &apiv2.DropNamespaceResponse{}, nil
171171
}
172172

173-
func (s *ServerV25) UpdateNamespace(ctx context.Context, in *apiv25.UpdateNamespaceRequest) (
174-
*apiv25.UpdateNamespaceResponse, error) {
173+
func (s *ServerV25) UpdateNamespace(ctx context.Context, in *apiv2.UpdateNamespaceRequest) (
174+
*apiv2.UpdateNamespaceResponse, error) {
175175

176176
if err := AuthSuperAdmin(ctx); err != nil {
177177
s := status.Convert(err)
@@ -188,19 +188,19 @@ func (s *ServerV25) UpdateNamespace(ctx context.Context, in *apiv25.UpdateNamesp
188188

189189
if isLgacyNamespace(in.NsName) {
190190
err := renameLeagcyNamespace(ctx, in.NsName, in.RenameToNs)
191-
return &apiv25.UpdateNamespaceResponse{}, err
191+
return &apiv2.UpdateNamespaceResponse{}, err
192192
}
193193

194194
if err := renameNamespace(x.AttachJWTNamespace(ctx), in.NsName, in.RenameToNs); err != nil {
195195
return nil, err
196196
}
197197

198198
glog.Infof("Renamed namespace [%v] to [%v]", in.NsName, in.RenameToNs)
199-
return &apiv25.UpdateNamespaceResponse{}, nil
199+
return &apiv2.UpdateNamespaceResponse{}, nil
200200
}
201201

202-
func (s *ServerV25) ListNamespaces(ctx context.Context, in *apiv25.ListNamespacesRequest) (
203-
*apiv25.ListNamespacesResponse, error) {
202+
func (s *ServerV25) ListNamespaces(ctx context.Context, in *apiv2.ListNamespacesRequest) (
203+
*apiv2.ListNamespacesResponse, error) {
204204

205205
if err := AuthSuperAdmin(ctx); err != nil {
206206
s := status.Convert(err)
@@ -224,13 +224,13 @@ func (s *ServerV25) ListNamespaces(ctx context.Context, in *apiv25.ListNamespace
224224
}
225225

226226
schNsList := schema.State().Namespaces()
227-
result := &apiv25.ListNamespacesResponse{NsList: make(map[string]*apiv25.Namespace)}
227+
result := &apiv2.ListNamespacesResponse{NsList: make(map[string]*apiv2.Namespace)}
228228
for id := range schNsList {
229229
if name, ok := dataNsList[id]; !ok {
230230
name = fmt.Sprintf("dgraph-%d", id)
231-
result.NsList[name] = &apiv25.Namespace{Name: name, Id: id}
231+
result.NsList[name] = &apiv2.Namespace{Name: name, Id: id}
232232
} else {
233-
result.NsList[name] = &apiv25.Namespace{Name: name, Id: id}
233+
result.NsList[name] = &apiv2.Namespace{Name: name, Id: id}
234234
}
235235
}
236236

edgraph/query.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ import (
1010
"fmt"
1111

1212
"github.com/dgraph-io/dgo/v250/protos/api"
13-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
13+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
1414
"github.com/hypermodeinc/dgraph/v25/dql"
1515
"github.com/hypermodeinc/dgraph/v25/x"
1616

1717
"google.golang.org/grpc/status"
1818
)
1919

20-
func (s *ServerV25) Ping(ctx context.Context, req *apiv25.PingRequest) (*apiv25.PingResponse, error) {
20+
func (s *ServerV25) Ping(ctx context.Context, req *apiv2.PingRequest) (*apiv2.PingResponse, error) {
2121
if err := x.HealthCheck(); err != nil {
2222
return nil, err
2323
}
2424

25-
return &apiv25.PingResponse{Version: x.Version()}, nil
25+
return &apiv2.PingResponse{Version: x.Version()}, nil
2626
}
2727

2828
// Alter handles requests to change the schema or remove parts or all of the data.
29-
func (s *ServerV25) RunDQL(ctx context.Context, req *apiv25.RunDQLRequest) (*apiv25.RunDQLResponse, error) {
29+
func (s *ServerV25) RunDQL(ctx context.Context, req *apiv2.RunDQLRequest) (*apiv2.RunDQLResponse, error) {
3030
// For now, we only allow guardian of galaxies to do this operation in v25
3131
if err := AuthSuperAdmin(ctx); err != nil {
3232
s := status.Convert(err)
@@ -48,7 +48,7 @@ func (s *ServerV25) RunDQL(ctx context.Context, req *apiv25.RunDQLRequest) (*api
4848
apiReq.ReadOnly = req.ReadOnly
4949
apiReq.BestEffort = req.BestEffort
5050
apiReq.RespFormat = api.Request_JSON
51-
if req.RespFormat == apiv25.RespFormat_RDF {
51+
if req.RespFormat == apiv2.RespFormat_RDF {
5252
apiReq.RespFormat = api.Request_RDF
5353
}
5454
if len(apiReq.Mutations) > 0 {
@@ -61,8 +61,8 @@ func (s *ServerV25) RunDQL(ctx context.Context, req *apiv25.RunDQLRequest) (*api
6161
return nil, err
6262
}
6363

64-
resp := &apiv25.RunDQLResponse{
65-
Txn: &apiv25.TxnContext{
64+
resp := &apiv2.RunDQLResponse{
65+
Txn: &apiv2.TxnContext{
6666
StartTs: apiResp.Txn.StartTs,
6767
CommitTs: apiResp.Txn.CommitTs,
6868
Aborted: apiResp.Txn.Aborted,
@@ -71,21 +71,21 @@ func (s *ServerV25) RunDQL(ctx context.Context, req *apiv25.RunDQLRequest) (*api
7171
Hash: apiResp.Txn.Hash,
7272
},
7373
BlankUids: apiResp.Uids,
74-
Latency: &apiv25.Latency{
74+
Latency: &apiv2.Latency{
7575
ParsingNs: apiResp.Latency.ParsingNs,
7676
ProcessingNs: apiResp.Latency.ProcessingNs,
7777
RespEncodingNs: apiResp.Latency.EncodingNs,
7878
AssignTimestampNs: apiResp.Latency.AssignTimestampNs,
7979
TotalNs: apiResp.Latency.TotalNs,
8080
},
81-
Metrics: &apiv25.Metrics{
81+
Metrics: &apiv2.Metrics{
8282
UidsTouched: apiResp.Metrics.NumUids,
8383
},
8484
}
8585

86-
if req.RespFormat == apiv25.RespFormat_JSON {
86+
if req.RespFormat == apiv2.RespFormat_JSON {
8787
resp.QueryResult = apiResp.Json
88-
} else if req.RespFormat == apiv25.RespFormat_RDF {
88+
} else if req.RespFormat == apiv2.RespFormat_RDF {
8989
resp.QueryResult = apiResp.Rdf
9090
}
9191

0 commit comments

Comments
 (0)