The Cassandra lock is a lock implemented in a cassandra row. It’s best used when also using cassandra for some other purpose and contention would likely not be an issue anyway (the lock provides the extra safety gear necessary to perform some operation).
To use the cassandra lock, instantiate using the padlock.get() function. You’ll also need a recent version of pycassa installed:
import padlock, pycassa
pool = pycassa.ConnectionPool('my_keyspsace'
with padlock.get('cassandra', pool=pool, column_family='my_column_family'):
do_some_important_shit()
Success! Please read through the class documentation to get a feel of how to use the lock. It will likely be a little specific to your implementation.
Raised old, stale locks exist on a row and we don’t want them to have existed.
Raised when a lock is already taken on this row.
A lock that is implemented in a row of a Cassandra column family. It’s good to use this type of lock when you want to lock a single row in cassandra for some purpose in a scenario where there will not be a lot of lock contention.
Shamelessly lifted from: Netflix’s Astynax library. Take a look at the implementation (in Java).
Parameters: |
|
---|
The following paramters are optional and all come with defaults:
Parameters: |
|
---|
You can also provide the following keyword arguments which will be passed directly to the ColumnFamily constructor if you didn’t provide the instance yourself:
- read_consistency_level
- write_consistency_level
- autopack_names
- autopack_values
- autopack_keys
- column_class_name
- super_column_name_class
- default_validation_class
- column_validators
- key_validation_class
- dict_class
- buffer_size
- column_bufer_size
- timestamp
Acquire the lock on this row. It will then read immediatly from cassandra, potentially retrying, potentially sleeping the executing thread.
Used internally - fills out pycassa.batch.CfMutator with the necessary steps to acquire the lock.
Used internally - used to fill out a pycassa.batch.CfMutator with the necessary steps to release the lock.
Used internally - serialize a timeout value (a long) to be inserted into a cassandra as a string.
Return all columns in this row with the timeout value deserialized into a long
Return type: | dict |
---|
Used internally - deserialize a timeout value that was stored in cassandra as a string back into a long.
Allow this row to be locked by something (or someone) else. Performs a single write (round trip) to Cassandra.
Clean up after ourselves. Removes all lock columns (everything returned by read_lock_columns()) that is not stale.
Parameters: | force – Remove even non-stale locks |
---|
Used internally - return the current time, as microseconds from the unix epoch (Jan 1 1970 UTC)
Return type: | long |
---|
Whether or not the lock can be verified by reading the row and ensuring the paramters of the lock according to the current CassandraDistributedRowLock instance’s configuration is valid.
This must only be called after acquire() is called, or else you will get a ValueError
Parameters: | cur_time (long) – The current time in microseconds |
---|---|
Return type: | None |