Load reads the latest schema for the given predicate from the DB.
(predicate string)
| 529 | |
| 530 | // Load reads the latest schema for the given predicate from the DB. |
| 531 | func Load(predicate string) error { |
| 532 | if len(predicate) == 0 { |
| 533 | return errors.Errorf("Empty predicate") |
| 534 | } |
| 535 | State().DeleteMutSchema(predicate) |
| 536 | key := x.SchemaKey(predicate) |
| 537 | txn := pstore.NewTransactionAt(math.MaxUint64, false) |
| 538 | defer txn.Discard() |
| 539 | item, err := txn.Get(key) |
| 540 | if err == badger.ErrKeyNotFound || err == badger.ErrBannedKey { |
| 541 | return nil |
| 542 | } |
| 543 | if err != nil { |
| 544 | return err |
| 545 | } |
| 546 | var s pb.SchemaUpdate |
| 547 | err = item.Value(func(val []byte) error { |
| 548 | x.Check(proto.Unmarshal(val, &s)) |
| 549 | return nil |
| 550 | }) |
| 551 | if err != nil { |
| 552 | return err |
| 553 | } |
| 554 | State().Set(predicate, &s) |
| 555 | State().elog.Printf(logUpdate(&s, predicate)) |
| 556 | glog.Infoln(logUpdate(&s, predicate)) |
| 557 | return nil |
| 558 | } |
| 559 | |
| 560 | // LoadFromDb reads schema information from db and stores it in memory |
| 561 | func LoadFromDb(ctx context.Context) error { |