Skip to content

Commit c175edc

Browse files
fix(groot): do not upsert groot for all namespaces on restart (#8561)
Earlier, whenever the alpha starts(or restarts), we were upserting guardian and groot for all the namespaces. This is not actually needed. The change was made in the PR #7759 to fix a bulk loader edge case. This PR fixes that by generating the required RDFs in the bulk loader itself. Essentially, it inserts the ACL RDFs when force loading into non-Galaxy namespace. (cherry picked from commit 6730f10) Co-authored-by: Naman Jain <[email protected]>
1 parent c084617 commit c175edc

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

dgraph/cmd/bulk/mapper.go

+19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/dgraph-io/dgo/v210/protos/api"
3636
"github.com/dgraph-io/dgraph/chunker"
3737
"github.com/dgraph-io/dgraph/dql"
38+
"github.com/dgraph-io/dgraph/ee/acl"
3839
"github.com/dgraph-io/dgraph/posting"
3940
"github.com/dgraph-io/dgraph/protos/pb"
4041
"github.com/dgraph-io/dgraph/tok"
@@ -44,6 +45,10 @@ import (
4445
"github.com/dgraph-io/ristretto/z"
4546
)
4647

48+
var (
49+
aclOnce sync.Once
50+
)
51+
4752
type mapper struct {
4853
*state
4954
shards []shardState // shard is based on predicate
@@ -228,6 +233,20 @@ func (m *mapper) run(inputFormat chunker.InputFormat) {
228233
}
229234
}
230235
}
236+
aclOnce.Do(func() {
237+
if m.opt.Namespace != math.MaxUint64 && m.opt.Namespace != x.GalaxyNamespace {
238+
// Insert ACL related RDFs force uploading the data into non-galaxy namespace.
239+
aclNquads := make([]*api.NQuad, 0)
240+
aclNquads = append(aclNquads, acl.CreateGroupNQuads(x.GuardiansId)...)
241+
aclNquads = append(aclNquads, acl.CreateUserNQuads(x.GrootId, "password")...)
242+
aclNquads = append(aclNquads, &api.NQuad{
243+
Subject: "_:newuser",
244+
Predicate: "dgraph.user.group",
245+
ObjectId: "_:newgroup",
246+
})
247+
nquads.Push(aclNquads...)
248+
}
249+
})
231250
nquads.Flush()
232251
}()
233252

dgraph/cmd/bulk/run.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ func init() {
118118
flag.Bool("new_uids", false,
119119
"Ignore UIDs in load files and assign new ones.")
120120
flag.Uint64("force-namespace", math.MaxUint64,
121-
"Namespace onto which to load the data. If not set, will preserve the namespace.")
121+
"Namespace onto which to load the data. If not set, will preserve the namespace."+
122+
" When using this flag to load data into specific namespace, make sure that the "+
123+
"load data do not have ACL data.")
122124

123125
flag.String("badger", BulkBadgerDefaults, z.NewSuperFlagHelp(BulkBadgerDefaults).
124126
Head("Badger options (Refer to badger documentation for all possible options)").

edgraph/access_ee.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,7 @@ func InitializeAcl(closer *z.Closer) {
434434
// The acl feature is not turned on.
435435
return
436436
}
437-
438-
for ns := range schema.State().Namespaces() {
439-
upsertGuardianAndGroot(closer, ns)
440-
}
437+
upsertGuardianAndGroot(closer, x.GalaxyNamespace)
441438
}
442439

443440
// Note: The handling of closer should be done by caller.

ee/acl/run.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ func init() {
3232
Use: "acl",
3333
Short: "Enterprise feature. Not supported in oss version",
3434
Annotations: map[string]string{"group": "security"},
35-
},
36-
Acl.Cmd.SetHelpTemplate(x.NonRootTemplate)
35+
}
36+
CmdAcl.Cmd.SetHelpTemplate(x.NonRootTemplate)
3737
}

0 commit comments

Comments
 (0)