Skip to content

Commit

Permalink
Use txn writer to write schema postings (#4296)
Browse files Browse the repository at this point in the history
Fixes #3916

Although I was not able to reproduce this. Stacktrace suggests, while writing schema to Badger, it 
got crashed with error: Txn is too big to fit into one request. This might be because, we are using single transaction to write schema for all predicates.
This PR, replaces single transaction with TxnWriter to write schema.
  • Loading branch information
ashish-goswami authored Nov 28, 2019
1 parent ae679e6 commit a7dec1e
Showing 1 changed file with 6 additions and 14 deletions.
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())
}

0 comments on commit a7dec1e

Please sign in to comment.