Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,9 @@ func loadFromDB(ctx context.Context, loadType int) error {
err := item.Value(func(val []byte) error {
if len(val) == 0 {
s = pb.SchemaUpdate{Predicate: pk.Attr, ValueType: pb.Posting_DEFAULT}
} else {
x.Checkf(proto.Unmarshal(val, &s), "Error while loading schema from db")
}
x.Checkf(proto.Unmarshal(val, &s), "Error while loading schema from db")
State().Set(pk.Attr, &s)
return nil
})
Expand All @@ -627,8 +628,9 @@ func loadFromDB(ctx context.Context, loadType int) error {
err := item.Value(func(val []byte) error {
if len(val) == 0 {
t = pb.TypeUpdate{TypeName: pk.Attr}
} else {
x.Checkf(proto.Unmarshal(val, &t), "Error while loading types from db")
}
x.Checkf(proto.Unmarshal(val, &t), "Error while loading types from db")
State().SetType(pk.Attr, &t)
return nil
})
Expand Down
35 changes: 35 additions & 0 deletions worker/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ func writePostingListToDisk(kvs []*bpb.KV) error {
return writer.Flush()
}

func TestEmptyTypeSchema(t *testing.T) {
dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
defer os.RemoveAll(dir)

opt := badger.DefaultOptions(dir)
ps, err := badger.OpenManaged(opt)
x.Check(err)
pstore = ps
posting.Init(ps, 0, false)
Init(ps)

typeName := "1-temp"
ts := uint64(10)
txn := pstore.NewTransactionAt(ts, true)
defer txn.Discard()
e := &badger.Entry{
Key: x.TypeKey(typeName),
Value: make([]byte, 0),
UserMeta: posting.BitSchemaPosting,
}
require.Nil(t, txn.SetEntry(e.WithDiscard()))
require.Nil(t, txn.CommitAt(ts, nil))

schema.Init(ps)
require.Nil(t, schema.LoadFromDb(context.Background()))

req := &pb.SchemaRequest{}
types, err := GetTypes(context.Background(), req)
require.Nil(t, err)

require.Equal(t, 1, len(types))
x.ParseNamespaceAttr(types[0].TypeName)
}

func TestMultipleTxnListCount(t *testing.T) {
dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
Expand Down