Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backup): use StreamWriter instead of KVLoader during backup restore #8510

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

mangalaman93
Copy link
Member

@mangalaman93 mangalaman93 commented Dec 13, 2022

cherry-pick PR #7753

This commit is a major rewrite of online restore code. It used to use KVLoader in badger. Now it instead uses StreamWriter that is much faster for writes in the case of restore.

@mangalaman93 mangalaman93 added the slash-to-main PRs which bring slash branch on par with main. label Dec 13, 2022
@mangalaman93 mangalaman93 self-assigned this Dec 13, 2022
@CLAassistant
Copy link

CLAassistant commented Dec 13, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added area/bulk-loader Issues related to bulk loading. area/enterprise Related to proprietary features area/graphql Issues related to GraphQL support on Dgraph. area/live-loader Issues related to live loading. area/testing Testing related issues labels Dec 13, 2022
@all-seeing-code
Copy link
Contributor

Do we want to merge all these in one go or can we split these up in smaller cherry-picks?

@mangalaman93
Copy link
Member Author

no, I was thinking of merging them one by one but I realized that these changes are better merged together. The challenge with these changes is that it has lot of refactoring including file name changes and it become very difficult to make sense of them one commit at a time.

ee/acl/acl_test.go Outdated Show resolved Hide resolved
@skrdgraph
Copy link
Contributor

NIT - could we align titles to our existing format, fix(<area>): <title>?

@mangalaman93 mangalaman93 changed the title cherry-pick PR https://github.com/dgraph-io/dgraph/pull/7753 fix(backup): cherry-pick PR https://github.com/dgraph-io/dgraph/pull/7753 Dec 28, 2022
@coveralls
Copy link

coveralls commented Dec 28, 2022

Coverage Status

Coverage: 66.783% (+0.4%) from 66.343% when pulling dd950f7 on aman/cp into f89eeef on main.

@all-seeing-code
Copy link
Contributor

all-seeing-code commented Dec 29, 2022

A couple of comments -

  1. Code coverage seems to drop by 0.4%, can we check why that happens and if we can add a scenario in tests to cover it?
  2. The change speeds up the back-up and restore. This should be verified on a large dataset (21 million/ldbcsf10) to have some idea on performance gain due to StreamWriter

@mangalaman93
Copy link
Member Author

mangalaman93 commented Jan 1, 2023

  • Code coverage seems to drop by 0.4%, can we check why that happens and if we can add a scenario in tests to cover it?

Most of the normal cases are already covered. I have a few more tests in mind and Siddhesh has a PR for adding more tests. I want to unblock rest of the changes for the slash alignment and I will work on adding tests in parallel.

  • The change speeds up the back-up and restore. This should be verified on a large dataset (21 million/ldbcsf10) to have some idea on performance gain due to StreamWriter

I think StreamWriter is inherently faster than our existing approach. Even if it is not fast, it improves the performance for writes later on. Let's talk more about this in tomorrow's meeting.

ee/backup/run.go Outdated Show resolved Hide resolved
Base automatically changed from aman/sensitive to main January 3, 2023 04:11
@mangalaman93 mangalaman93 changed the title fix(backup): cherry-pick PR https://github.com/dgraph-io/dgraph/pull/7753 fix(backup): use StreamWriter instead of KVLoader during backup restore Jan 3, 2023
@mangalaman93 mangalaman93 force-pushed the aman/cp branch 2 times, most recently from 27861d7 to c51a385 Compare January 3, 2023 14:37
Copy link
Contributor

@billprovince billprovince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still looking over ...

dgraph/cmd/bulk/reduce.go Show resolved Hide resolved
dgraph/cmd/increment/increment.go Show resolved Hide resolved
dgraph/cmd/increment/increment.go Outdated Show resolved Hide resolved
dgraph/cmd/increment/increment.go Show resolved Hide resolved
dgraph/main.go Show resolved Hide resolved
@mangalaman93
Copy link
Member Author

This is how the map reduce phases are implemented in this PR: we create MAP files each of a limited size and write sorted data into it. We may end up creating many such files. Then we take all of these MAP files and read part of the data from each file, sort all of this data and then use streamwriter to write the sorted data into pstore badger. We store some sort of partition keys in the MAP file in the beginning of the file. The partition keys are just intermediate keys among the entries that we store in the map file. When we read data during reduce, we read in the chunks of these partition keys, meaning from one partition key to the next partition key. I am not sure if there is a value in having these partition keys. Maybe, we can live without them.

@all-seeing-code
Copy link
Contributor

This is how the map reduce phases are implemented in this PR: we create MAP files each of a limited size and write sorted data into it. We may end up creating many such files. Then we take all of these MAP files and read part of the data from each file, sort all of this data and then use streamwriter to write the sorted data into pstore badger. We store some sort of partition keys in the MAP file in the beginning of the file. The partition keys are just intermediate keys among the entries that we store in the map file. When we read data during reduce, we read in the chunks of these partition keys, meaning from one partition key to the next partition key. I am not sure if there is a value in having these partition keys. Maybe, we can live without them.

Few questions as I try to wade through the change:

we create MAP files each of a limited size

  • Is this size configurable or hard-coded?
  • Can you point to where this size is picked up from?
  • Is this correct to assume that the individual Map file size would decide how many such map files are generated

We store some sort of partition keys in the MAP file in the beginning of the file. The partition keys are just intermediate keys among the entries that we store in the map file. When we read data during reduce, we read in the chunks of these partition keys, meaning from one partition key to the next partition key.

  • Is this because we want to make use of some buffered reader which can read certain amount in memory, we process that and then move on to a different chunk?

@mangalaman93
Copy link
Member Author

Few questions as I try to wade through the change:

we create MAP files each of a limited size

* Is this size configurable or hard-coded?

hard coded

* Can you point to where this size is picked up from?

restore_reduce.go, it is set to 2GB

* Is this correct to assume that the individual `Map file` size would decide how many such map files are generated

correct

We store some sort of partition keys in the MAP file in the beginning of the file. The partition keys are just intermediate keys among the entries that we store in the map file. When we read data during reduce, we read in the chunks of these partition keys, meaning from one partition key to the next partition key.

* Is this because we want to make use of some buffered reader which can read certain amount in memory, we process that and then move on to a different chunk?

correct. We need to sort data in all the map files while each map file is already sorted. We read data until the partition key from each map file sort that data and then write it to badger.

Copy link
Contributor

@harshil-goel harshil-goel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Minor nitpicks here and there. I haven't really looked that deeply into the algorithm yet.

ee/backup/run.go Show resolved Hide resolved
ee/backup/run.go Show resolved Hide resolved
ee/backup/run.go Show resolved Hide resolved
type predicateSet map[string]struct{}

// Manifest records backup details, these are values used during restore.
// Since is the timestamp from which the next incremental backup should start (it's set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something like SinceTs is the the timestamp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

worker/restore_reduce.go Show resolved Hide resolved
worker/restore_reduce.go Show resolved Hide resolved
worker/restore_map.go Show resolved Hide resolved
@mangalaman93 mangalaman93 force-pushed the aman/cp branch 2 times, most recently from 2ac2673 to 3307aab Compare January 17, 2023 19:18
dgraph/cmd/increment/increment.go Show resolved Hide resolved
dgraph/main.go Show resolved Hide resolved
"/state": true,
"/health": true,
"/state": true,
"/probe/graphql": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this require a doc update in the audit log section that this endpoint will not be audited?
I think it does require a doc update:
https://dgraph.io/docs/enterprise-features/audit-logs/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make a note of it. Thanks

worker/backup.go Outdated Show resolved Hide resolved
ee/backup/run.go Outdated Show resolved Hide resolved
worker/backup_ee.go Show resolved Hide resolved
@all-seeing-code
Copy link
Contributor

It changes export as well. I think we can mention that in the description.

This commit is a major rewrite of backup and online restore
code. It used to use KVLoader in badger. Now it instead uses
StreamWriter that is much faster for writes.

cherry-pick PR #7753

following commits are cherry-picked (in reverse order):
 * opt(restore): Sort the buffer before spinning the writeToDisk goroutine (#7984) (#7996)
 * fix(backup): Fix full backup request (#7932) (#7933)
 * fix: fixing graphql schema update when the data is restored +
        skipping /probe/graphql from audit (#7925)
 * fix(restore): return nil if there is error (#7899)
 * Don't ban namespace in export_backup
 * reset the kv.StreamId before sending to stream writer (#7833) (#7837)
 * fix(restore): Bump uid and namespace after restore (#7790) (#7800)
 * fix(ee): GetKeys should return an error (#7713) (#7797)
 * fix(backup): Free the UidPack after use (#7786)
 * fix(export-backup): Fix double free in export backup (#7780) (#7783)
 * fix(lsbackup): Fix profiler in lsBackup (#7729)
 * Bring back "perf(Backup): Improve backup performance (#7601)"
 * Opt(Backup): Make backups faster (#7680)
 * Fix s3 backup copy (#7669)
 * [BREAKING] Opt(Restore): Optimize Restore's new map-reduce based design (#7666)
 * Perf(restore): Implement map-reduce based restore (#7664)
 * feat(backup): Merge backup refactoring
 * Revert "perf(Backup): Improve backup performance (#7601)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bulk-loader Issues related to bulk loading. area/enterprise Related to proprietary features area/graphql Issues related to GraphQL support on Dgraph. area/live-loader Issues related to live loading. area/testing Testing related issues slash-to-main PRs which bring slash branch on par with main.
Development

Successfully merging this pull request may close these issues.

9 participants