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

R4R: Don't acquire lock on read-only keybase #2555

Merged
merged 5 commits into from
Oct 23, 2018

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Oct 22, 2018

Expose calls to acquire non-blocking read lock on LevelDB stores.
Change GetKeyBase() so that it opens stores in read-only mode by default.
Add GetKeyBaseWithWritePerm() to acquire write locks on stores.

Closes: #1255

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Oct 22, 2018

Codecov Report

Merging #2555 into develop will decrease coverage by 0.05%.
The diff coverage is 25%.

@@             Coverage Diff             @@
##           develop    #2555      +/-   ##
===========================================
- Coverage    60.32%   60.27%   -0.06%     
===========================================
  Files          150      150              
  Lines         8613     8591      -22     
===========================================
- Hits          5196     5178      -18     
  Misses        3069     3069              
+ Partials       348      344       -4

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Thanks @alessio! I left some minor feedback. Also, how does this relate to #2489? Can we close one of these?

PENDING.md Outdated Show resolved Hide resolved
@@ -63,7 +63,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
return errMissingName()
}
name = args[0]
kb, err = GetKeyBase()
kb, err = GetKeyBaseWithWritePerm()
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the old GetKeyBase is now the one that returns a KeyBase in RO mode. May I suggest renaming GetKeyBaseWithWritePerm to GetWriteKeyBase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial approach was like yours, e.g. "oh, this is quite an API breakage - semantic changed radically". Though I must admit that I quite like the WithWritePerm suffix. It makes clear that you are getting a dB in write mode.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @alessio here.

client/keys/utils.go Outdated Show resolved Hide resolved

// GetKeyBaseWithWritePerm initialize a keybase based on the configuration with write permissions.
func GetKeyBaseWithWritePerm() (keys.Keybase, error) {
rootDir := viper.GetString(cli.HomeFlag)
Copy link
Contributor

@ValarDragon ValarDragon Oct 23, 2018

Choose a reason for hiding this comment

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

Feel free to declare this out of scope of this PR, but it would be super nice to remove this function entirely and instead use GetKeyBaseFromDir variants (probably renamed to remove the FromDir.

Copy link
Member

Choose a reason for hiding this comment

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

I like the API exposed here. It explicitly mentions the permissions you are getting when you open the database.

Copy link
Contributor

Choose a reason for hiding this comment

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

The point I was making was removing the viper global variable, in favor of always explicitly passing in the rootDir, not about the permission itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

++

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I guess it can be a separate PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ValarDragon I agree, let's do it in a separate PR, shall we?

alexanderbez and others added 2 commits October 23, 2018 10:43
Co-Authored-By: alessio <quadrispro@ubuntu.com>
Co-Authored-By: alessio <quadrispro@ubuntu.com>
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

utACK -- thanks @alessio

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Minor comment.

@@ -426,6 +426,11 @@ func (kb dbKeybase) Update(name, oldpass string, getNewpass func() (string, erro
}
}

// CloseDB releases the lock and closes the storage backend.
func (kb dbKeybase) CloseDB() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we call this (e.g. in the code) in places other than the testcase you added? Seems like maybe so...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah maybe


// GetKeyBaseWithWritePerm initialize a keybase based on the configuration with write permissions.
func GetKeyBaseWithWritePerm() (keys.Keybase, error) {
rootDir := viper.GetString(cli.HomeFlag)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I guess it can be a separate PR though.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

utACK, let's split out calling Close() and removing the Viper global usage to a second PR

@cwgoes cwgoes merged commit a231bd8 into develop Oct 23, 2018
@cwgoes cwgoes deleted the alessio/1255-keybase-readonly branch October 23, 2018 19:03
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.

6 participants