From a6b770ac935c17134fa8addcb883d25e21a92eca Mon Sep 17 00:00:00 2001 From: Ashish Goswami Date: Wed, 20 Nov 2019 14:49:34 +0530 Subject: [PATCH 1/2] Use txn writer to write schema postings --- dgraph/cmd/bulk/schema.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/dgraph/cmd/bulk/schema.go b/dgraph/cmd/bulk/schema.go index 53051e416bf..36911639e8f 100644 --- a/dgraph/cmd/bulk/schema.go +++ b/dgraph/cmd/bulk/schema.go @@ -143,8 +143,9 @@ 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() + // Write schema always at timestamp 1, s.state.writeTs may not be equal to 1 + // if bulk loader was restarted or other similar scenarios. + w := posting.NewTxnWriter(db) for _, pred := range preds { sch, ok := s.schemaMap[pred] if !ok { @@ -153,10 +154,7 @@ 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})) + x.Check(w.SetAt(k, v, posting.BitSchemaPosting, 1)) } // Write all the types as all groups should have access to all the types. @@ -164,14 +162,8 @@ func (s *schemaStore) write(db *badger.DB, preds []string) { 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()) } From db9d250ff48eb0fde78a69d10278cad5c6b92fbd Mon Sep 17 00:00:00 2001 From: Ashish Goswami Date: Fri, 22 Nov 2019 13:11:56 +0530 Subject: [PATCH 2/2] Address review comments --- dgraph/cmd/bulk/schema.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dgraph/cmd/bulk/schema.go b/dgraph/cmd/bulk/schema.go index 36911639e8f..a062b4bed6a 100644 --- a/dgraph/cmd/bulk/schema.go +++ b/dgraph/cmd/bulk/schema.go @@ -143,8 +143,6 @@ func (s *schemaStore) getPredicates(db *badger.DB) []string { } func (s *schemaStore) write(db *badger.DB, preds []string) { - // Write schema always at timestamp 1, s.state.writeTs may not be equal to 1 - // if bulk loader was restarted or other similar scenarios. w := posting.NewTxnWriter(db) for _, pred := range preds { sch, ok := s.schemaMap[pred] @@ -154,6 +152,8 @@ func (s *schemaStore) write(db *badger.DB, preds []string) { k := x.SchemaKey(pred) v, err := sch.Marshal() x.Check(err) + // 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)) }