-
Notifications
You must be signed in to change notification settings - Fork 0
LockBox - Collection structure for managing multiple locks #5
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
Comments
I've already written And EFS has it's own system too. So I can port this here first, and see how I can make |
Using |
The |
Given our lock IDs, we have to convert them to string AND also sort and filter out duplicates: let ids_ = ids.map((id) =>
( typeof id === 'string') ? id : id.toString()
);
ids_.sort();
ids_ = ids_.filter((id, i, arr) => {
return i === 0 || id !== arr[i - 1];
}); |
Uh oh!
There was an error while loading. Please reload this page.
Specification
Both EFS and PK are currently using collections of locks structure. This is necessary when dealing with multiple locks, and some tricks to eliminate deadlocks.
One of the things is to have locks identified by string keys. Sorting these string keys deterministically, so that multiple locks are always locked in the same order. It's also important to filter these locks by uniqueness, so the request of the same lock twice is prevented. Thus the locks requested is always an "ordered set".
As an extension, it's also possible to introduce structured locks. This enables a more detailed fine-grained locking to avoid https://en.wikipedia.org/wiki/Giant_lock problems. And by this I mean that you can lock
['a', 'b']
and['a']
, where'a'
is on top of['a', 'b']
. Think of a prefix trie, where each element of the array identifies a level. This can be applied to nested structures for example where you may have a level identifying a file, and within each file, there are blocks. You can lock specific blocks, or you can lock the entire file. To do this you now have a vertical axis to consider as well. To prevent deadlocks, you need to sort them by shortest-prefix and remove duplicates, but also remove longer-prefixes.For example:
Is equivalent to:
There's no need to lock
['a', 'b', 'c']
if you're already locking['a', 'b']
.This would require implementing a prefix trie structure, it's bit more complex, so we will add this as an extension later.
The first part is just flat
LockBox
based on what we already have implemented inEFS
andPK
.The
LockBox
should be generic, or it can deal with all of the lock classes that we already have. If generic, a lockbox can only contain one specific type of locks. If heterogenous, we would need to have a type specifier on what kind of lock to use. We could do something like:But the exact "acquisition" of the lock resource is different. In
RWLockReader
, there'sread
andwrite
. WhileLock
only haslock
. You would also need to pass in the themethod
:Along with
T
so thatLockBox
knows how to lock it.Given that this would make the API quite verbose like:
One could instead pre-program the lockbox to have the necessary utilities ahead of time and have it default.
Later DB could inherit this, or programs can combine all of these together with
js-resources
andjs-db
.Additional context
Tasks
withF
The text was updated successfully, but these errors were encountered: