Skip to content

Commit

Permalink
reset acls for all the namespaces instead of only ns 0
Browse files Browse the repository at this point in the history
  • Loading branch information
NamanJain8 committed Apr 28, 2021
1 parent aff03e5 commit 213fae2
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 108 deletions.
2 changes: 2 additions & 0 deletions dgraph/cmd/bulk/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func run() {

loader.prog.mapEdgeCount = bulkMeta.EdgeCount
loader.schema.schemaMap = bulkMeta.SchemaMap
loader.schema.types = bulkMeta.Types
} else {
loader.mapStage()
mergeMapShardsIntoReduceShards(&opt)
Expand All @@ -336,6 +337,7 @@ func run() {
bulkMeta := pb.BulkMeta{
EdgeCount: loader.prog.mapEdgeCount,
SchemaMap: loader.schema.schemaMap,
Types: loader.schema.types,
}
bulkMetaData, err := bulkMeta.Marshal()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/bulk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func newSchemaStore(initial *schema.ParsedSchema, opt *options, state *state) *s
// whenever we see data for a new namespace.
s.checkAndSetInitialSchema(x.GalaxyNamespace)

s.types = initial.Types
// This is from the schema read from the schema file.
for _, sch := range initial.Preds {
p := sch.Predicate
Expand All @@ -63,8 +64,6 @@ func newSchemaStore(initial *schema.ParsedSchema, opt *options, state *state) *s
s.schemaMap[p] = sch
}

s.types = initial.Types

return s
}

Expand Down Expand Up @@ -102,6 +101,7 @@ func (s *schemaStore) checkAndSetInitialSchema(namespace uint64) {
for _, update := range schema.CompleteInitialSchema(namespace) {
s.schemaMap[update.Predicate] = update
}
s.types = append(s.types, schema.CompleteInitialTypes(namespace)...)

if s.opt.StoreXids {
s.schemaMap[x.NamespaceAttr(namespace, "xid")] = &pb.SchemaUpdate{
Expand Down
45 changes: 26 additions & 19 deletions edgraph/access_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,28 +413,35 @@ func ResetAcl(closer *z.Closer) {
// The acl feature is not turned on.
return
}
for closer.Ctx().Err() == nil {
ctx, cancel := context.WithTimeout(closer.Ctx(), time.Minute)
defer cancel()
ctx = x.AttachNamespace(ctx, x.GalaxyNamespace)
if err := upsertGuardian(ctx); err != nil {
glog.Infof("Unable to upsert the guardian group. Error: %v", err)
time.Sleep(100 * time.Millisecond)
continue

upsertGuardianAndGroot := func(ns uint64) {
for closer.Ctx().Err() == nil {
ctx, cancel := context.WithTimeout(closer.Ctx(), time.Minute)
defer cancel()
ctx = x.AttachNamespace(ctx, ns)
if err := upsertGuardian(ctx); err != nil {
glog.Infof("Unable to upsert the guardian group. Error: %v", err)
time.Sleep(100 * time.Millisecond)
continue
}
break
}
break
}

for closer.Ctx().Err() == nil {
ctx, cancel := context.WithTimeout(closer.Ctx(), time.Minute)
defer cancel()
ctx = x.AttachNamespace(ctx, x.GalaxyNamespace)
if err := upsertGroot(ctx, "password"); err != nil {
glog.Infof("Unable to upsert the groot account. Error: %v", err)
time.Sleep(100 * time.Millisecond)
continue
for closer.Ctx().Err() == nil {
ctx, cancel := context.WithTimeout(closer.Ctx(), time.Minute)
defer cancel()
ctx = x.AttachNamespace(ctx, ns)
if err := upsertGroot(ctx, "password"); err != nil {
glog.Infof("Unable to upsert the groot account. Error: %v", err)
time.Sleep(100 * time.Millisecond)
continue
}
break
}
break
}

for ns := range schema.State().Namespaces() {
upsertGuardianAndGroot(ns)
}
}

Expand Down
1 change: 1 addition & 0 deletions protos/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ message UpdateGraphQLSchemaResponse {
message BulkMeta {
int64 edge_count = 1;
map<string, SchemaUpdate> schema_map = 2;
repeated TypeUpdate types = 3;
}

message DeleteNsRequest {
Expand Down
226 changes: 144 additions & 82 deletions protos/pb/pb.pb.go

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ func (s *state) DeleteType(typeName string) error {
return nil
}

// Namespaces returns the active namespaces based on the current types.
func (s *state) Namespaces() map[uint64]struct{} {
if s == nil {
return nil
}

s.RLock()
defer s.RUnlock()

ns := make(map[uint64]struct{})
for typ := range s.types {
ns[x.ParseNamespace(typ)] = struct{}{}
}
return ns
}

// DeletePredsForNs deletes the predicate information for the namespace from the schema.
func (s *state) DeletePredsForNs(delNs uint64) {
if s == nil {
Expand Down
5 changes: 0 additions & 5 deletions x/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,20 @@ func GalaxyAttr(attr string) string {

// ParseNamespaceAttr returns the namespace and attr from the given value.
func ParseNamespaceAttr(attr string) (uint64, string) {
AssertTrue(len(attr) >= 8)
return binary.BigEndian.Uint64([]byte(attr[:8])), attr[8:]
}

func ParseNamespaceBytes(attr string) ([]byte, string) {
AssertTrue(len(attr) >= 8)
return []byte(attr[:8]), attr[8:]
}

// ParseAttr returns the attr from the given value.
func ParseAttr(attr string) string {
AssertTrue(len(attr) >= 8)
return attr[8:]
}

// ParseNamespace returns the namespace from the given value.
func ParseNamespace(attr string) uint64 {
AssertTrue(len(attr) >= 8)
return binary.BigEndian.Uint64([]byte(attr[:8]))
}

Expand All @@ -114,7 +110,6 @@ func ParseAttrList(attrs []string) []string {
}

func IsReverseAttr(attr string) bool {
AssertTrue(len(attr) >= 8)
return attr[8] == '~'
}

Expand Down

0 comments on commit 213fae2

Please sign in to comment.