Using a Lock Protocol

Meta Data Services Programming

Meta Data Services Programming

Using a Lock Protocol

Executing transactions concurrently can adversely affect the integrity of repository data if a locking protocol is not used. For example, consider two concurrently executing transactions that both increment an integer property of a repository object. This property represents a sequential counter.

  1. Transaction A reads the value of the property. The current value is six.

  2. Transaction B reads the same current value of the property.

  3. Transaction A increments the retrieved property value by one and writes it back to the repository database. The value in the database is now seven.

  4. Transaction B increments its copy of the retrieved property value by one and writes it back to the repository database. The value in the database is still seven. It should be eight.

To avoid this problem, use the Lock method in concurrently executing transactions to serialize access to a repository item. The Lock method sets an exclusive lock on the item, and refreshes any unchanged cache data for the item. The lock is effective across processes and across computers. If the repository item is already locked, the lock request waits until the lock becomes available. The item is unlocked when the transaction is ended, either by the Abort method or by the final invocation of the Commit method for the transaction.

By invoking the Lock method, the caller has exclusive access to a repository item, as long as all other concurrently executing transactions also obtain a lock on that repository item before updating it.

By default, the repository engine will wait up to 20 seconds to get a lock on a repository object. If this lock time-out value is insufficient, you can increase it by setting a transaction flag. For more information, see TransactionFlags Enumeration.

Caution  Calling the Lock method on a repository item only prevents other transactions from executing the Lock method on the item. It does not block other transactions that are not using the locking protocol from changing the item.

See Also

IRepositoryItem::Lock

IRepositoryTransaction::abort

Managing Transactions and Threads

RepositoryObjectVersion Lock Method

Workspace Lock Method

VersionedRelationship Lock Method