MCPcopy
hub / github.com/dgraph-io/dgraph / CreateNamespaceInternal

Method CreateNamespaceInternal

edgraph/multi_tenancy.go:85–116  ·  view source on GitHub ↗

CreateNamespaceInternal creates a new namespace. Only superadmin is authorized to do so. Authorization is handled by middlewares.

(ctx context.Context, passwd string)

Source from the content-addressed store, hash-verified

83// CreateNamespaceInternal creates a new namespace. Only superadmin is authorized to do so.
84// Authorization is handled by middlewares.
85func (s *Server) CreateNamespaceInternal(ctx context.Context, passwd string) (uint64, error) {
86 glog.V(2).Info("Got create namespace request.")
87
88 num := &pb.Num{Val: 1, Type: pb.Num_NS_ID}
89 ids, err := worker.AssignNsIdsOverNetwork(ctx, num)
90 if err != nil {
91 return 0, errors.Wrapf(err, "Creating namespace, got error:")
92 }
93
94 ns := ids.StartId
95 glog.V(2).Infof("Got a lease for NsID: %d", ns)
96
97 // Attach the newly leased NsID in the context in order to create guardians/groot for it.
98 ctx = x.AttachNamespace(ctx, ns)
99 m := &pb.Mutations{StartTs: worker.State.GetTimestamp(false)}
100 m.Schema = schema.InitialSchema(ns)
101 m.Types = schema.InitialTypes(ns)
102 _, err = query.ApplyMutations(ctx, m)
103 if err != nil {
104 return 0, err
105 }
106
107 err = x.RetryUntilSuccess(10, 100*time.Millisecond, func() error {
108 return createGuardianAndGroot(ctx, passwd)
109 })
110 if err != nil {
111 return 0, errors.Wrapf(err, "Failed to create guardian and groot: ")
112 }
113
114 glog.V(2).Infof("Created namespace: %d", ns)
115 return ns, nil
116}
117
118// This function is used while creating new namespace. New namespace creation is only allowed
119// by the guardians of the galaxy group.

Callers 2

CreateNamespaceMethod · 0.80
resolveAddNamespaceFunction · 0.80

Calls 10

AssignNsIdsOverNetworkFunction · 0.92
AttachNamespaceFunction · 0.92
InitialSchemaFunction · 0.92
InitialTypesFunction · 0.92
ApplyMutationsFunction · 0.92
RetryUntilSuccessFunction · 0.92
createGuardianAndGrootFunction · 0.85
InfoMethod · 0.80
InfofMethod · 0.80
GetTimestampMethod · 0.80

Tested by

no test coverage detected