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

Allow for using and working with offset locks #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harlowja
Copy link
Owner

Offset locks allow for lock inside a single file
using byte offsets, this avoids having to create hundreds
of lock files for each use case, and instead allows for
an application to be smarter, and shard locks from a single
file for its use-cases (assuming the file can pick a large
enough file with enough offsets to satisfy its needs).

This makes it much easier to cleanup lock files, track them
and know when to delete them (because deleting per-lock lock
files is hard to do when an application is always online, because
knowing when to delete a lock file is a non-trivial problem when
an application has no interface to tell which locks are alive or
dead and which are safe to delete).

@rishi-freshbooks
Copy link

We would find this feature very useful since we are looking to create many locks (i.e. a lock per id).
Any chance this is ready?

@harlowja
Copy link
Owner Author

harlowja commented Mar 7, 2017

So currently I was looking at waiting for #26 (comment) (see comment here).

@BoPeng
Copy link

BoPeng commented Aug 8, 2018

Is there any reason why this PR has not been merged? I visited this issue a year ago and I ended up using thousands of lock files in my project. I really need to address this problem now but the PR is still not merged.

@harlowja
Copy link
Owner Author

Only reason was I was waiting for someone to review :)

@harlowja harlowja force-pushed the offset-locks branch 5 times, most recently from a6cbbd4 to 5cfeee4 Compare August 16, 2018 21:45
Offset locks allow for lock inside a single file
using byte offsets, this avoids having to create hundreds
of lock files for each use case, and instead allows for
an application to be smarter, and shard locks from a single
file for its use-cases (assuming the file can pick a large
enough file with enough offsets to satisfy its needs).

This makes it much easier to cleanup lock files, track them
and know when to delete them (because deleting per-lock lock
files is hard to do when an application is always online, because
knowing when to delete a lock file is a non-trivial problem when
an application has no interface to tell which locks are alive or
dead and which are safe to delete).
Copy link

@4383 4383 left a comment

Choose a reason for hiding this comment

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

Hello,

Some feedback from my side.

I guess you need to adapt the interprocess_locked function too to allow user to use offset through the decorator approach too.

I mean this decorator use the InterProcessLock which represents _FcntLock and _WindowsLock under the hood.

Only _FcntLock really handle offsets but _WindowsLock inherit from _InterProcessLock so the_trylock and _unlock methods both accept the use_offset params.

In the nt case (Windows) offset features will be ignored due to the SUPPORTS_OFFSETS = False but with posix environments it can be useful to activate this kind of features through the decorator approach.

Maybe in the windows side it can be useful to log some info/debug messages to the logger to inform user that even if the offset is not None it will be ignored, to avoid misleading.

Thoughts?

I started to play with these changes few days ago through a direct usage and also through the oslo.concurrency scope so I will surely send more comments soon.

@4383
Copy link

4383 commented Nov 7, 2019

Hello,

I designed some pocs/tools to test these changes and to help other to review/test it.

Please find them here (https://github.com/4383/oslo.concurrency.lab).

For the moment this poc test these changes outside of the oslo scope (direct use of fasteners).
2 files are in use there:

You can a look to them for more details and infos.

Also for more infos on how to use this POC you can read the related doc:

Except my previous comment these changes look fine for the moment.

Now I will spend time to test this through the oslo scope and implement some related pocs.

@4383
Copy link

4383 commented Jan 22, 2020

Any feedbacks related to my previous messages?

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.

4 participants