Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use initial schema during bulk load. #3333

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dgraph/cmd/bulk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/dgraph-io/badger"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/schema"
wk "github.com/dgraph-io/dgraph/worker"
"github.com/dgraph-io/dgraph/x"
)
Expand All @@ -45,6 +46,15 @@ func newSchemaStore(initial []*pb.SchemaUpdate, opt options, state *state) *sche
},
state: state,
}

// Load all initial predicates. Some predicates that might not be used when
// the alpha is started (e.g ACL predicates) might be included but it's
// better to include them in case the input data contains triples with these
// predicates.
for _, update := range schema.CompleteInitialSchema() {
s.m[update.Predicate] = update
}

if opt.StoreXids {
s.m["xid"] = &pb.SchemaUpdate{
ValueType: pb.Posting_STRING,
Expand Down
18 changes: 17 additions & 1 deletion schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,23 @@ func LoadTypesFromDb() error {
return nil
}

// InitialSchema returns the schema updates to insert at the beginning of
// Dgraph's execution. It looks at the worker options to determine which
// attributes to insert.
func InitialSchema() []*pb.SchemaUpdate {
return initialSchemaInternal(false)
}

// CompleteInitialSchema returns all the schema updates regardless of the worker
// options. This is useful in situations where the worker options are not known
// in advance and it's better to create all the reserved predicates and remove
// them later than miss some of them. An example of such situation is during bulk
// loading.
func CompleteInitialSchema() []*pb.SchemaUpdate {
return initialSchemaInternal(true)
}

func initialSchemaInternal(all bool) []*pb.SchemaUpdate {
var initialSchema []*pb.SchemaUpdate

// propose the schema for _predicate_
Expand All @@ -428,7 +444,7 @@ func InitialSchema() []*pb.SchemaUpdate {
List: true,
})

if x.WorkerConfig.AclEnabled {
if all || x.WorkerConfig.AclEnabled {
// propose the schema update for acl predicates
initialSchema = append(initialSchema, []*pb.SchemaUpdate{
{
Expand Down