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 txn writer to write schema postings #4296

Merged
merged 2 commits into from
Nov 28, 2019
Merged
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
20 changes: 6 additions & 14 deletions dgraph/cmd/bulk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ func (s *schemaStore) getPredicates(db *badger.DB) []string {
}

func (s *schemaStore) write(db *badger.DB, preds []string) {
txn := db.NewTransactionAt(math.MaxUint64, true)
defer txn.Discard()
w := posting.NewTxnWriter(db)
for _, pred := range preds {
sch, ok := s.schemaMap[pred]
if !ok {
Expand All @@ -153,25 +152,18 @@ func (s *schemaStore) write(db *badger.DB, preds []string) {
k := x.SchemaKey(pred)
v, err := sch.Marshal()
x.Check(err)
x.Check(txn.SetEntry(&badger.Entry{
Key: k,
Value: v,
UserMeta: posting.BitSchemaPosting}))
// Write schema and types always at timestamp 1, s.state.writeTs may not be equal to 1
// if bulk loader was restarted or other similar scenarios.
x.Check(w.SetAt(k, v, posting.BitSchemaPosting, 1))
}

// Write all the types as all groups should have access to all the types.
for _, typ := range s.types {
k := x.TypeKey(typ.TypeName)
v, err := typ.Marshal()
x.Check(err)
x.Check(txn.SetEntry(&badger.Entry{
Key: k,
Value: v,
UserMeta: posting.BitSchemaPosting,
}))
x.Check(w.SetAt(k, v, posting.BitSchemaPosting, 1))
}

// Write schema always at timestamp 1, s.state.writeTs may not be equal to 1
// if bulk loader was restarted or other similar scenarios.
x.Check(txn.CommitAt(1, nil))
x.Check(w.Flush())
}