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

Added support for no timeout locks on db files #34

Closed
wants to merge 2 commits into from
Closed

Added support for no timeout locks on db files #34

wants to merge 2 commits into from

Conversation

dmoklaf
Copy link
Contributor

@dmoklaf dmoklaf commented Sep 4, 2017

Pull request has been added to boltdb/bolt (#494) but has been queued for processing.

So I submit it there in the hope that it can be merged into a reasonably maintained repo so I dont have anymore to maintain a separate repo on the side.

Beside my application needs, I think this change is beneficial to the community as it completes the timeout locking API which didn't support an obvious case (failing right away if the database lock file can not be acquired instead of having to wait a given duration). I took the opportunity to refactor slightly these few lines of code to make them cleaner.

Full discussion of the initial boltdb/bolt pull request is there:
boltdb/bolt#494

@codecov-io
Copy link

Codecov Report

Merging #34 into master will decrease coverage by 0.24%.
The diff coverage is 22.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
- Coverage   85.01%   84.76%   -0.25%     
==========================================
  Files           9        9              
  Lines        1848     1851       +3     
==========================================
- Hits         1571     1569       -2     
- Misses        164      168       +4     
- Partials      113      114       +1
Impacted Files Coverage Δ
bolt_unix.go 63.63% <0%> (-9.54%) ⬇️
db.go 80.14% <100%> (ø) ⬆️

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...bd4e362. Read the comment docs.

@heyitsanthony
Copy link
Contributor

@rgeronimi negative durations seem iffy as an interface. Would it be possible to rearrange the lock code so it checks the timeout before issuing the sleep? That way timeout can be time.Nanosecond and would have the same effect as the negative duration in this patch.

Something like:

    ... flock(...) ...
    ... 
    if time.Since(t) > timeout-(50 * time.Millisecond) {
        return ErrTimeout
    }
    time.Sleep(50 * time.Millisecond)
}

@dmoklaf
Copy link
Contributor Author

dmoklaf commented Sep 5, 2017

I agree. I implemented the changes, will be pushed through a separate pull request

@dmoklaf dmoklaf closed this Sep 5, 2017
@dmoklaf dmoklaf deleted the corechange branch September 5, 2017 16:12
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

3 participants