cookbook 'lock_rdlm', '~> 0.1.3'
lock_rdlm (2) Versions 0.1.3 Follow0
Installs/Configures lock_rdlm
cookbook 'lock_rdlm', '~> 0.1.3', :supermarket
knife supermarket install lock_rdlm
knife supermarket download lock_rdlm
lock_rdlm cookbook
Uses RDLM to enforce critical sections between Chef clients.
Also supports managing the RDLM server.
Supported Platforms
For clients: Nothing native, so anything goes I guess.
For lock server: Tested on CentOS 6.7.
Attributes
Key | Type | Used by | Description | Default |
---|---|---|---|---|
['lock_rdlm']['scheme'] |
String | Clients | Default for lock scheme | http |
['lock_rdlm']['hostname'] |
String | Clients | Default for lock server name | nil |
['lock_rdlm']['port'] |
Integer | Server and Clients | Port for lock server. Used as default by clients | 7305 |
['lock_rdlm']['wait'] |
Integer | Clients | Default for number of seconds to wait to acquire the lock before raising an error | 5 |
['lock_rdlm']['lifetime'] |
Integer | Clients | Default for how logn the lock hols before expiring by itself | 300 |
Recipes
lock_rdlm::server
Installs and configures the simple RDLM server.
It uses the ['lock_rdlm']['port']
attribute to determine the port the daemon will be listening on.
I'm using an init file tested on CentOS 6.7.
Library resources
Common parameters
Used to locate the lock server, appear under additional_config
in method descriptions:
-
lock_url
: How to reach the lock server. Defaults to building the url from attributes (if possible) -
lock_wait
: Number of seconds to wait to acquire the lock before raising an error. Defaults tonode['lock_rdlm']['wait']
-
lock_lifetime
: Number of seconds before the lock will expire on its own. Defaults tonode['lock_rdlm']['lifetime']
LockRDLM::with_lock
Yields (runs a code block) while locking the resource specified on the lock.
Parameters:
-
node
: Calling node's object -
lock_resource
: name for lock - "additional_config" detailed above
Can be thought of like the synchronized keyword in java.
Example:
# Add apple to databag if it has none LockRDLM::with_lock(node,'dbvendingjuice') do db=data_bag_item('vending','juice') db['kinds']<<'apple' unless db['kinds'].member? 'apple' db.save end
This will ensure the databag has only one apple
item, even if several clients run this recipe at the same time.
LockRDLM::assign_identity
Used to assign a unique identity.
Parameters:
-
node
: Calling node's object -
assignment_path
: Path for attribute to store unique value in -
range
: Pool of possibe values -
additional_config
: Detailed above
Resulting effects
Upon successful completion of the function, this node will be assigned a unique identity in its node object.
The identity will be stored as a node attribute specified by assignment_path
, where [:a,0,'bla']
is used to address the node attribute node[:a][0]['bla']
.
The value is selected from range
and is guranteed to be different from any value currently present on other nodes in the Chef server.
Selection is done without concurrency, thanks to the lock.
The resulting value is saved on both the current node
object (for use in other parts of the recipe) and in the server's version of the node
object immediately, to stop other nodes from choosing the same value. This is important to mention because by default, Chef client only updates the server's version of the node
object if the run is successful. In our case, this attribute is updated during resource compilation.
There are several ways this method can fail:
- Can't talk to lock server
Fix the server, firewalls etc. - Can't get lock lock (other client is busy with lock).
- My library might be buggy and not release the lock for some reason. Create a PR/Issue :)
- Enumerating all of the nodes takes longer than the lock time constraints. Allow more
wait
time.
- Range is exhausted
- Increase the range
- Delete dead nodes from the Chef server
Basic walk-through
Assuming a working and reachable lock server:
- Function is called with the following:
assignment_path = [:slasher,:id]
range = (1..5).to_a
lock_url = 'http://lock:8080/'
lock_wait = 5
lock_lifetime = 300
- Current value of attribute is checked (
node[:slasher][:id]
). If not-empty, function returns. Assuming empty - Lock is locked for a normalized version of the
assignment_path
(slasherid
) - If lock can't be locked for some reason, raise error
- All node objects on Chef server are enumerated for that value. Resulting collection is filtered out from range.
- Take a single element from range (
first
). If empty, raise error (release lock before). Assuming got3
. - Load our node object from Chef server, modify the node attribute and save it.
- Update the current node's attribute (
node.normal[:slasher][:id]=3
) - Release lock
- Return 3
LockRDLM::find_duplicate_identity
Parameters:
-
node
: Calling node's object -
assignment_path
: Path for attribute unique value is stored in -
only_me
: Only check for conflicts involving my node -
additional_config
: Detailed above
Used to enforce uniqueness of the identity attribute without modifying anything.
Is useful in monitoring.
Return value
Empty hash ({}
) if there are no duplicates.
If there are duplicates, the hash is composed of a key for the duplicate identity and the value is an array of nodes holding said value, like this:
{ 3 => ['node1.backslasher.net', 'node2.backslasher.net'] }
License and Authors
Licensed GPL v2
Author:: Nitzan Raz (backslasher)
Dependent cookbooks
poise-python ~> 1.1 |
Contingent cookbooks
There are no cookbooks that are contingent upon this one.
0.1.3
- [backslasher] Updated README
0.1.2
- [backslasher] mutex to lock
0.1.1
- [backslasher] Updated README
0.1.0
Initial release of mutex_rdlm
Collaborator Number Metric
0.1.3 failed this metric
Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.
Contributing File Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file
Foodcritic Metric
0.1.3 failed this metric
FC064: Ensure issues_url is set in metadata: lock_rdlm/metadata.rb:1
FC065: Ensure source_url is set in metadata: lock_rdlm/metadata.rb:1
FC066: Ensure chef_version is set in metadata: lock_rdlm/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: lock_rdlm/metadata.rb:1
FC069: Ensure standardized license defined in metadata: lock_rdlm/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
No Binaries Metric
0.1.3 passed this metric
Testing File Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
0.1.3 failed this metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file
Foodcritic Metric
0.1.3 failed this metric
FC064: Ensure issues_url is set in metadata: lock_rdlm/metadata.rb:1
FC065: Ensure source_url is set in metadata: lock_rdlm/metadata.rb:1
FC066: Ensure chef_version is set in metadata: lock_rdlm/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: lock_rdlm/metadata.rb:1
FC069: Ensure standardized license defined in metadata: lock_rdlm/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
No Binaries Metric
0.1.3 passed this metric
Testing File Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
0.1.3 failed this metric
FC065: Ensure source_url is set in metadata: lock_rdlm/metadata.rb:1
FC066: Ensure chef_version is set in metadata: lock_rdlm/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: lock_rdlm/metadata.rb:1
FC069: Ensure standardized license defined in metadata: lock_rdlm/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
0.1.3 passed this metric
Testing File Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
0.1.3 failed this metric
0.1.3 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number