Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export: Ignore deleted predicates from schema (#5302)
Browse files Browse the repository at this point in the history
Fixes #5053
Fixes DGRAPH-1260

The current implementation of export would add dropped
predicates and deleted types to the exported schema.
This PR fixes it by ignoring the deleted predicates and types.

(cherry picked from commit 23140a9)
Ibrahim Jarif committed Apr 29, 2020
1 parent b349242 commit 34541f2
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions worker/export.go
Original file line number Diff line number Diff line change
@@ -438,6 +438,10 @@ func export(ctx context.Context, in *pb.ExportRequest) error {
stream := pstore.NewStreamAt(in.ReadTs)
stream.LogPrefix = "Export"
stream.ChooseKey = func(item *badger.Item) bool {
// Skip exporting delete data including Schema and Types.
if item.IsDeletedOrExpired() {
return false
}
pk, err := x.Parse(item.Key())
if err != nil {
glog.Errorf("error %v while parsing key %v during export. Skip.", err, hex.EncodeToString(item.Key()))
@@ -567,6 +571,7 @@ func export(ctx context.Context, in *pb.ExportRequest) error {
// prepended
hasDataBefore = true
}

if _, err := writer.gw.Write(kv.Value); err != nil {
return err
}
22 changes: 14 additions & 8 deletions worker/export_test.go
Original file line number Diff line number Diff line change
@@ -125,29 +125,32 @@ func initTestExport(t *testing.T, schemaStr string) {
require.NoError(t, txn.Set(x.SchemaKey("friend"), val))
// Schema is always written at timestamp 1
require.NoError(t, txn.CommitAt(1, nil))
txn.Discard()

require.NoError(t, err)
val, err = (&pb.SchemaUpdate{ValueType: pb.Posting_UID}).Marshal()
require.NoError(t, err)

txn = pstore.NewTransactionAt(math.MaxUint64, true)
txn.Set(x.SchemaKey("http://www.w3.org/2000/01/rdf-schema#range"), val)
err = txn.Set(x.SchemaKey("http://www.w3.org/2000/01/rdf-schema#range"), val)
require.NoError(t, err)
txn.Set(x.SchemaKey("friend_not_served"), val)
require.NoError(t, txn.Set(x.SchemaKey("friend_not_served"), val))
require.NoError(t, txn.Set(x.SchemaKey("age"), val))
require.NoError(t, txn.CommitAt(1, nil))
txn.Discard()

val, err = personType.Marshal()
require.NoError(t, err)

txn = pstore.NewTransactionAt(math.MaxUint64, true)
txn.Set(x.TypeKey("Person"), val)
require.NoError(t, err)
require.NoError(t, txn.Set(x.TypeKey("Person"), val))
require.NoError(t, txn.CommitAt(1, nil))
txn.Discard()

populateGraphExport(t)

// Drop age predicate after populating DB.
// age should not exist in the exported schema.
txn = pstore.NewTransactionAt(math.MaxUint64, true)
require.NoError(t, txn.Delete(x.SchemaKey("age")))
require.NoError(t, txn.CommitAt(1, nil))
}

func getExportFileList(t *testing.T, bdir string) (dataFiles, schemaFiles []string) {
@@ -197,7 +200,10 @@ func checkExportSchema(t *testing.T, schemaFileList []string) {

func TestExportRdf(t *testing.T) {
// Index the name predicate. We ensure it doesn't show up on export.
initTestExport(t, "name:string @index .")
initTestExport(t, `
name:string @index .
age:int.
`)

bdir, err := ioutil.TempDir("", "export")
require.NoError(t, err)

0 comments on commit 34541f2

Please sign in to comment.