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

Support no timeout locks on db files #35

Merged
merged 2 commits into from
Sep 6, 2017
Merged

Conversation

dmoklaf
Copy link
Contributor

@dmoklaf dmoklaf commented Sep 5, 2017

This is continuation of pull request #34 with same name, itself derived from boltdb/bolt#494
I implemented the changes proposed by @heyitsanthony. I ended up with conflicts between my version derived from boltdb/bolt and the coreos/bbolt master. I resolved them and committed them into a clean branch based on coreos/bbolt master

@codecov-io
Copy link

codecov-io commented Sep 5, 2017

Codecov Report

Merging #35 into master will increase coverage by 0.55%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #35      +/-   ##
==========================================
+ Coverage   85.01%   85.56%   +0.55%     
==========================================
  Files           9        9              
  Lines        1848     1857       +9     
==========================================
+ Hits         1571     1589      +18     
+ Misses        164      159       -5     
+ Partials      113      109       -4
Impacted Files Coverage Δ
db.go 82.83% <100%> (+2.69%) ⬆️
bolt_unix.go 70.45% <58.33%> (-2.72%) ⬇️
tx.go 76.21% <83.33%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a148de8...f1ea5d8. Read the comment docs.

Copy link
Contributor

@heyitsanthony heyitsanthony left a comment

Choose a reason for hiding this comment

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

the duplicated code looks like it can be simplified some

db.go Outdated
@@ -40,6 +40,9 @@ const (
// default page size for db is set to the OS page size.
var defaultPageSize = os.Getpagesize()

// The step used by the timeout mechanisms.
const timeoutStep = 50 * time.Millisecond
Copy link
Contributor

Choose a reason for hiding this comment

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

const flockRetryTimeout = 50 * time.Millisecond?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good for me. Will push an update

if err == nil {
return nil
} else if err != syscall.EAGAIN {
return err
}

// If we timed out then return an error.
if timeout != 0 && (maxSleep < 0 || time.Since(t) > maxSleep) {
Copy link
Contributor

@heyitsanthony heyitsanthony Sep 5, 2017

Choose a reason for hiding this comment

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

can get rid of maxSleep:

func flock(...) error {
    t := time.Now()
    fd := db.file.Fd()
...

         if timeout != 0 && time.Since(t) > (timeout - flockRetryTimeout) {
             return ErrTimeout
         }
         time.Sleep(flockRetryTimeout)
    }

Copy link
Contributor Author

@dmoklaf dmoklaf Sep 6, 2017

Choose a reason for hiding this comment

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

The goal of the initial pull request was specifically to allow the API user to not depend upon any time logic - return directly with an error if the database file cannot be locked, without depending on the OS time settings.

That proposed code change would specifically create a hidden dependency with the time module. I checked it for correctness, it would work under Go 1.9 which brings monotonic guarantees. However under previous Go version, there are no monotonic guarantees and the code could result in a time.Sleep call (e.g., if the OS time is changed for whatever reason).

So it boils down to which version of Go do we support to guarantee that boltdb work. Do we want this patch to work for Go versions before 1.9 too, or do we design only for the latest version of Go? In the latter case, fine for me, I can push an update.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think relying on >=1.9 is OK since this is a new feature that won't interfere with old behavior.

@dmoklaf
Copy link
Contributor Author

dmoklaf commented Sep 6, 2017

I implemented the proposed changes

Copy link
Contributor

@heyitsanthony heyitsanthony left a comment

Choose a reason for hiding this comment

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

lgtm after squashing, thanks!

@dmoklaf
Copy link
Contributor Author

dmoklaf commented Sep 6, 2017

Will you use github's Squash and merge feature to squash the commits?
Or are you expected a manual squash from me?
Thx

Copy link
Contributor

@gyuho gyuho left a comment

Choose a reason for hiding this comment

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

lgtm.

@heyitsanthony heyitsanthony merged commit 3a49aac into etcd-io:master Sep 6, 2017
@gyuho gyuho changed the title Added support for no timeout locks on db files Support no timeout locks on db files Sep 27, 2017
@kwf2030 kwf2030 mentioned this pull request Oct 23, 2017
a-palchikov added a commit to gravitational/bolt that referenced this pull request May 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants