Skip to content

Commit

Permalink
chore(live): fixing live loader abort errors when using force-namespa…
Browse files Browse the repository at this point in the history
…ce (#7553)

* chore(live): fixing live loader abort errors when using force-namespace
  • Loading branch information
aman-bansal authored Mar 11, 2021
1 parent 5c700d0 commit 1a0a501
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions dgraph/cmd/live/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ type request struct {
conflicts []uint64
}

func (l *schema) init(ns uint64) {
func (l *schema) init(ns uint64, galaxyOperation bool) {
l.preds = make(map[string]*predicate)
for _, i := range l.Predicates {
i.ValueType, _ = types.TypeForName(i.Type)
if !opt.preserveNs {
if !galaxyOperation {
i.Predicate = x.NamespaceAttr(ns, i.Predicate)
}
l.preds[i.Predicate] = i
Expand Down Expand Up @@ -191,7 +191,7 @@ func init() {
"specific namespace. Setting it to negative value will preserve the namespace.")
}

func getSchema(ctx context.Context, dgraphClient *dgo.Dgraph, ns uint64) (*schema, error) {
func getSchema(ctx context.Context, dgraphClient *dgo.Dgraph, galaxyOperation bool) (*schema, error) {
txn := dgraphClient.NewTxn()
defer txn.Discard(ctx)

Expand All @@ -206,7 +206,7 @@ func getSchema(ctx context.Context, dgraphClient *dgo.Dgraph, ns uint64) (*schem
}
// If we are not loading data across namespaces, the schema query result will not contain the
// namespace information. Set it inside the init function.
sch.init(ns)
sch.init(opt.namespaceToLoad, galaxyOperation)
return &sch, nil
}

Expand Down Expand Up @@ -724,8 +724,9 @@ func run() error {
opt.namespaceToLoad = uint64(forceNs)
}
default:
if Live.Conf.IsSet("force-namespace") && uint64(forceNs) != creds.GetUint64("namespace") {
return errors.Errorf("cannot load into namespace %#x", forceNs)
if Live.Conf.IsSet("force-namespace") {
return errors.Errorf("cannot force namespace %#x when provided creds are not of"+
" guardian of galaxy user", forceNs)
}
opt.namespaceToLoad = creds.GetUint64("namespace")
}
Expand All @@ -746,9 +747,11 @@ func run() error {
opt.namespaceToLoad != x.GalaxyNamespace {
singleNsOp = false
}
galaxyOperation := false
if !singleNsOp {
// Attach the galaxy to the context to specify that the query/mutations with this context
// will be galaxy-wide.
galaxyOperation = true
ctx = x.AttachGalaxyOperation(ctx, opt.namespaceToLoad)
// We don't support upsert predicate while loading data in multiple namespace.
if len(opt.upsertPredicate) > 0 {
Expand Down Expand Up @@ -800,7 +803,7 @@ func run() error {
fmt.Printf("Processed schema file %q\n\n", opt.schemaFile)
}

if l.schema, err = getSchema(ctx, dg, opt.namespaceToLoad); err != nil {
if l.schema, err = getSchema(ctx, dg, galaxyOperation); err != nil {
fmt.Printf("Error while loading schema from alpha %s\n", err)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions systest/multi-tenancy/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestLiveLoadMulti(t *testing.T) {
forceNs: -1,
})
require.Error(t, err)
require.Contains(t, err.Error(), "cannot load into namespace")
require.Contains(t, err.Error(), "cannot force namespace")

err = liveLoadData(t, &liveOpts{
rdfs: `_:c <name> "ns hola" .`,
Expand All @@ -338,7 +338,7 @@ func TestLiveLoadMulti(t *testing.T) {
forceNs: 10,
})
require.Error(t, err)
require.Contains(t, err.Error(), "cannot load into namespace")
require.Contains(t, err.Error(), "cannot force namespace")

require.NoError(t, liveLoadData(t, &liveOpts{
rdfs: fmt.Sprintf(`
Expand Down

0 comments on commit 1a0a501

Please sign in to comment.