MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / exportInternal

Function exportInternal

worker/export.go:775–944  ·  view source on GitHub ↗

exportInternal contains the core logic to export a Dgraph database. If skipZero is set to false, the parts of this method that require to talk to zero will be skipped. This is useful when exporting a p directory directly from disk without a running cluster. It uses stream framework to export the dat

(ctx context.Context, in *pb.ExportRequest, db *badger.DB,
	skipZero bool)

Source from the content-addressed store, hash-verified

773// It uses stream framework to export the data. While it uses an iterator for exporting the schema
774// and types.
775func exportInternal(ctx context.Context, in *pb.ExportRequest, db *badger.DB,
776 skipZero bool) (ExportedFiles, error) {
777
778 uts := time.Unix(in.UnixTs, 0)
779 exportStorage, err := NewExportStorage(in,
780 fmt.Sprintf("dgraph.r%d.u%s", in.ReadTs, uts.UTC().Format("0102.1504")))
781 if err != nil {
782 return nil, err
783 }
784 writers, err := InitWriters(exportStorage, in)
785 if err != nil {
786 return nil, errors.Wrap(err, "exportInternal failed")
787 }
788 // This stream exports only the data and the graphQL schema.
789 stream := db.NewStreamAt(in.ReadTs)
790 stream.Prefix = []byte{x.DefaultPrefix}
791 if in.Namespace != math.MaxUint64 {
792 // Export a specific namespace.
793 stream.Prefix = append(stream.Prefix, x.NamespaceToBytes(in.Namespace)...)
794 }
795 stream.LogPrefix = "Export"
796 stream.ChooseKey = func(item *badger.Item) bool {
797 // Skip exporting delete data including Schema and Types.
798 if item.IsDeletedOrExpired() {
799 return false
800 }
801 pk, err := x.Parse(item.Key())
802 if err != nil {
803 glog.Errorf("error %v while parsing key %v during export. Skip.", err,
804 hex.EncodeToString(item.Key()))
805 return false
806 }
807
808 // Do not pick keys storing parts of a multi-part list. They will be read
809 // from the main key.
810 if pk.HasStartUid {
811 return false
812 }
813 // _predicate_ is deprecated but leaving this here so that users with a
814 // binary with version >= 1.1 can export data from a version < 1.1 without
815 // this internal data showing up.
816 if pk.Attr == "_predicate_" {
817 return false
818 }
819
820 if !skipZero {
821 if servesTablet, err := groups().ServesTablet(pk.Attr); err != nil || !servesTablet {
822 return false
823 }
824 }
825
826 if strings.Contains(pk.Attr, hnsw.VecKeyword) {
827 return false
828 }
829 return pk.IsData()
830 }
831
832 stream.KeyToList = func(key []byte, itr *badger.Iterator) (*bpb.KVList, error) {

Callers 2

StoreExportFunction · 0.85
exportFunction · 0.85

Calls 15

FinishWritingMethod · 0.95
NamespaceToBytesFunction · 0.92
ParseFunction · 0.92
ReadPostingListFunction · 0.92
NewExportStorageFunction · 0.85
InitWritersFunction · 0.85
groupsFunction · 0.85
ToExportKvListFunction · 0.85
WriteExportFunction · 0.85
SchemaExportKvFunction · 0.85
TypeExportKvFunction · 0.85
FormatMethod · 0.80

Tested by

no test coverage detected