MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / AllocateIDs

Method AllocateIDs

edgraph/zero.go:20–48  ·  view source on GitHub ↗
(ctx context.Context, req *api.AllocateIDsRequest)

Source from the content-addressed store, hash-verified

18)
19
20func (s *Server) AllocateIDs(ctx context.Context, req *api.AllocateIDsRequest) (
21 *api.AllocateIDsResponse, error) {
22
23 // For now, we only allow users in superadmin group to do this operation in v25
24 if err := AuthSuperAdmin(ctx); err != nil {
25 s := status.Convert(err)
26 return nil, status.Error(s.Code(),
27 "v25.AllocateIDs can only be called by the superadmin group. "+s.Message())
28 }
29
30 num := &pb.Num{Val: req.HowMany}
31 switch req.LeaseType {
32 case api.LeaseType_NS:
33 num.Type = pb.Num_NS_ID
34 case api.LeaseType_UID:
35 num.Type = pb.Num_UID
36 case api.LeaseType_TS:
37 num.Type = pb.Num_TXN_TS
38 default:
39 return nil, fmt.Errorf("invalid lease type: %v", req.LeaseType)
40 }
41
42 resp, err := worker.AssignUidsOverNetwork(ctx, num)
43 if err != nil {
44 return nil, errors.Wrapf(err, "Failed to allocate IDs")
45 }
46
47 return &api.AllocateIDsResponse{Start: resp.StartId, End: resp.EndId}, nil
48}

Callers

nothing calls this directly

Calls 5

AssignUidsOverNetworkFunction · 0.92
AuthSuperAdminFunction · 0.85
CodeMethod · 0.80
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected