| 194 | ) |
| 195 | |
| 196 | func readSchema(pdir string, dType dataType) ([]string, error) { |
| 197 | db, err := openDgraph(pdir) |
| 198 | if err != nil { |
| 199 | return nil, err |
| 200 | } |
| 201 | defer db.Close() |
| 202 | values := make([]string, 0) |
| 203 | |
| 204 | txn := db.NewTransactionAt(math.MaxUint64, false) |
| 205 | defer txn.Discard() |
| 206 | itr := txn.NewIterator(badger.DefaultIteratorOptions) |
| 207 | defer itr.Close() |
| 208 | |
| 209 | for itr.Rewind(); itr.Valid(); itr.Next() { |
| 210 | item := itr.Item() |
| 211 | pk, err := x.Parse(item.Key()) |
| 212 | x.Check(err) |
| 213 | |
| 214 | switch { |
| 215 | case item.UserMeta() != posting.BitSchemaPosting: |
| 216 | continue |
| 217 | case pk.IsSchema() && dType != schemaPredicate: |
| 218 | continue |
| 219 | case pk.IsType() && dType != schemaType: |
| 220 | continue |
| 221 | } |
| 222 | |
| 223 | values = append(values, x.ParseAttr(pk.Attr)) |
| 224 | } |
| 225 | return values, nil |
| 226 | } |
| 227 | |
| 228 | // GetPredicateNames returns the list of all the predicates stored in the restored pdir. |
| 229 | func GetPredicateNames(pdir string) ([]string, error) { |