-
Notifications
You must be signed in to change notification settings - Fork 65
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
Datastore copy util #469
Datastore copy util #469
Conversation
Signed-off-by: Sander Pick <sanderpick@gmail.com>
75147de
to
bdd8cab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I left two somewhat important comments to consider.
util/datastore/dscopy/main.go
Outdated
for r := range results.Next() { | ||
if err := to.Put(ds.NewKey(r.Key), r.Value); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between these two lines we need to add:
if r.Error != nil {
log.Fatal(...)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, thanks!
util/datastore/dscopy/main.go
Outdated
for r := range results.Next() { | ||
if err := to.Put(ds.NewKey(r.Key), r.Value); err != nil { | ||
log.Fatalf("copying %s: %v", r.Key, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered while working and testing Powergate migrations that this is too slow for copying (at least for my taste).
Here is what I did for migrations; which reduced times by some orders of magnitude. Nothing crazy, ignoring the migration logic, basically some rate-limiting to Read-and-Put up to 1000 in concurrently instead of serially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, copied your approach there
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Sorry the big code update post review here, but I realized using this tool would be much easier if it wasn't a generic datastore copier, but was specific to the structure of |
}, | ||
{ | ||
name: "ipfslite", | ||
files: []string{"key"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the key as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Left a comment.
lock.Lock() | ||
count++ | ||
lock.Unlock() | ||
if count%parallel == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: move lock.Unlock()
to include the if case since count
is being read without lock and might be a data-race with other goroutine owning the lock. (tongue twister)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, done
Signed-off-by: Sander Pick <sanderpick@gmail.com>
Adds a small program for copying a badger/mongo datastore to another badger/mongo datastore.