Skip to content

Commit a7dec1e

Browse files
Use txn writer to write schema postings (#4296)
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.
1 parent ae679e6 commit a7dec1e

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

dgraph/cmd/bulk/schema.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ func (s *schemaStore) getPredicates(db *badger.DB) []string {
143143
}
144144

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

162160
// Write all the types as all groups should have access to all the types.
163161
for _, typ := range s.types {
164162
k := x.TypeKey(typ.TypeName)
165163
v, err := typ.Marshal()
166164
x.Check(err)
167-
x.Check(txn.SetEntry(&badger.Entry{
168-
Key: k,
169-
Value: v,
170-
UserMeta: posting.BitSchemaPosting,
171-
}))
165+
x.Check(w.SetAt(k, v, posting.BitSchemaPosting, 1))
172166
}
173167

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

0 commit comments

Comments
 (0)