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

Fixes applied to migration process #862

Merged
merged 7 commits into from
Dec 10, 2021
Merged

Conversation

emmanuelm41
Copy link
Contributor

It solves issues reported on #855

@emmanuelm41 emmanuelm41 linked an issue Nov 30, 2021 that may be closed by this pull request
@hsanjuan
Copy link
Contributor

It's probably best practice (and likely faster), to wrap the reader/writers with bufio. Also, perhaps it would be more solid to do os.Rename and then copy back the file into the original location, and if that fails, perhaps rename the files back.

In one case, the node can go on without the backup, even on error when creating it. On the other, it cannot go on. One likely scenario might be a node with little disk space left, that cannot duplicate the DB. It will fail again and again to upgrade with the current approach. When renaming, it will upgrade just fine and could potentially continue.

Copy link
Collaborator

@nikkolasg nikkolasg left a comment

Choose a reason for hiding this comment

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

I'm personally fine for this change - the DB should not be THAT big, the problem is more out of memory error, which is a recurrent drand issue about go routine leakage I think.
So using io.Copy with streams is good for me.

fs/fs.go Show resolved Hide resolved
@hsanjuan
Copy link
Contributor

hsanjuan commented Dec 1, 2021

So using io.Copy with streams is good for me.

So with bare io.Copy we cannot control how much is read and written. Ideally we will be writing in large enough chunks that our copy does not take longer than needed (this can be actually benchmarked). bufio potenitally solves that with a large enough buffer. (This assumption can be tested).

I think the patch potentially solves the issue, but if we can level-up the quality as much as possible while doing that, I don't see the problem in the extra 2 lines of code.

@nikkolasg
Copy link
Collaborator

nikkolasg commented Dec 1, 2021 via email

@emmanuelm41
Copy link
Contributor Author

It's probably best practice (and likely faster), to wrap the reader/writers with bufio. Also, perhaps it would be more solid to do os.Rename and then copy back the file into the original location, and if that fails, perhaps rename the files back.

In one case, the node can go on without the backup, even on error when creating it. On the other, it cannot go on. One likely scenario might be a node with little disk space left, that cannot duplicate the DB. It will fail again and again to upgrade with the current approach. When renaming, it will upgrade just fine and could potentially continue.

The original files are left untouched as the process must allow to execute a rollback if something goes wrong. That is something the team wanted. I try not to touch the original files so the risk is minimum. I personally think that is a good approach in this case.

Talking about bufio, I can add it to the migration process.

What do you think about just using the "cp" cmd actually instead of re
implementing cp again ? Letting the OS do it is probably the easiest and
fastest way no ?

I am not sure if the control we have over the copy process is better or not. I feel confortable to copy files from golang

@hsanjuan
Copy link
Contributor

hsanjuan commented Dec 1, 2021

What do you think about just using the "cp" cmd actually instead of re
implementing cp again ? Letting the OS do it is probably the easiest and
fastest way no ?

No, we don't call the OS for these things. Nothing tells you that there is a shell to invoke, a cp command present in the system etc. In general invoking shell commands is going to be a bad thing in 99% of cases, if there is an alternative.

@emmanuelm41
Copy link
Contributor Author

@hsanjuan could you please approve it if you see it is correct now? 😄 Thanks!

@nikkolasg
Copy link
Collaborator

nikkolasg commented Dec 2, 2021

Fine if we want to use buffered io - in this use case I dont see it as a requirement since we are reading from a local file so we already have all the data to fill the buffer, not like TCP socket etc- But I am not fine to re-implement things that golang already provides. The copy method from Go is much more fine grained tested and we should use that.
If we want to control the size of the buffer (which is the only detail that differ between using io.Copy and buff writer from what I see), can we use native features such as https://pkg.go.dev/io#CopyBuffer ? It actually uses the same logic as io.Copy but with the buffer we want which is exactly what @emmanuelm41 has implemented here.

@emmanuelm41
Copy link
Contributor Author

@nikkolasg I just applied the change you suggested. What do you think now?

fs/fs.go Outdated Show resolved Hide resolved
fs/fs.go Outdated Show resolved Hide resolved
@emmanuelm41 emmanuelm41 merged commit 02bf053 into drand:master Dec 10, 2021
@emmanuelm41 emmanuelm41 deleted the migration-fix branch December 10, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Devnet was reset to round 1 and continued from there
5 participants