Data Lock in a Space

ActiveSpaces allows users to lock records and keys in the space. The granularity of the locking in ActiveSpaces is a key, meaning that any possible key that could be used in the space can be locked, regardless of whether a tuple is actually stored in the space.

The space's lock function takes a tuple representing the key as an input parameter and can optionally return what is stored in the space at that key (if there is anything) just as a get operation allows you to lock tuples in the space. The space’s lock method is an atomic get and lock, and takes the same argument as the get method.

After a key is locked, it is read-only for all other members of the space except for either the process or the thread that issued the lock command. The lock's scope (the thread or the process) can be specified when the space's lock method is invoked.

If a thread or process other than the locking thread or process tries to do a put, take, lock, or any operation that would modify whatever is stored for the locked key, that operation may block until the lock is cleared.

A locked key is read-only for all space members except the member that has locked it. Only one member can lock a specific key at any given time. If a member other than the lock owner tries to overwrite, take, update, or lock a locked key, that operation may block until the lock is cleared. If you want to implement this behavior, set a lock wait value using the space's LockWait attribute.

After a key is locked, the owner of the lock can unlock it.

You can also iteratively lock all or a filtered subset of the tuples in a space by using a space browser.

Finally, you can specify a maximum time to leave for locks in a space: if a lock is held for longer than the value specified in the space's LockTTL attribute, it is then automatically cleared. Locks are also automatically cleared when the application that has created the lock leaves the metaspace or crashes.

Related reference