Crisp Reading Notes on Latest Technology Trends and Basics

These are notes for VAX/VMS based “Distributed Lock Manager”, which is one of the first systems providing “Locks as a Service”. Most Database manager have followed a variant of this.

In this article, I explain the “Lock Modes”, which is a pluggable logic for the VAX/VMS version. This is a pluggable logic, that varies from System to System.

References

Lock-Modes

Basic Lock Modes

There are three basic Lock Modes

PR Protected Read In this mode, the Readers are guaranteed the data is stableie, There are no Writers changing the data
PW Protected Write In this mode, the Writer is guaranteed the data is stableie, There are no other Writers modifying the data
EX Exclusive In this mode, there is only one application.There are no Readers or Writers modifying the data

The Compatibility Matrix between these modes is as follows

 

PR

PW

EX

Having PR

Yes

No

No

Having PW

No

No

No

Having EX

No

No

No

Basic Non-Lock Modes

In these modes, the entities / threads do not need locks. To these applications, it does not matter what the other applications are doing.

However, this will dilute the commitment made to the other applications that have registered for “Protected Read” or “Protected Write”.

For this reason, these non-locking applications are required to state their Intent, before they execute on the specified operation. This is done by acquiring two weak locks – Concurrent Read (CR), or Concurrent Write (CW)

The two additional “Lock Modes” are

CR Concurrent Read In this mode, the application is allowed to read the dataHowever, no guarantees are made on the isolation
CW Concurrent Write In this mode, the application is allowed to write the dataHowever, no guarantees are made on the isolation

The Compatibility Matrix among these modes is as follows

 

CR

CW

PR

PW

EX

Having CR

Yes(3)

Yes(4)

Yes(3)

Yes(3)

No(2)

Having CW

Yes(3)

Yes(4)

No(1)

No(1)

No(2)

Having PR

Yes(3)

No(1)

Yes

No

No

Having PW

Yes(3)

No(1)

No

No

No

Having EX

No(2)

No(2)

No

No

No

An explanation of the various entries

  1. With a Concurrent Write, neither a Private Read, nor a Private Write is allowed
  2. With an Exclusive Lock, neither Concurrent Read, nor Concurrent Write is allowed
  3. A Concurrent Read is harmless, and is allowed with any lock except “Exclusive”.
  4. With a Concurrent Read, a Concurrent Write is allowed, since neither cares about isolations

Hierarchy

Resource Hierarchy

Each resource in the system is placed in a hierarchy

  • For a database the hierarchy may be
  1. Database
  2. Table
  3. Page
  4. Tuple
  • The hierarchy is usually known from the name of the resource. For example
//financial/expenses/17/85

 

Hierarchical Locking

 

  • Locks may be obtained on objects at all levels in the Object Hierarchy.  The rules for the same can also be specified as set of basic rules

Obtain a CR or CW at a higher level, before you obtain a PR or PW lock at the leaf node.

  • For example, to obtain a Write lock on the record
  1. Obtain CW lock on  Database – //financial
  2. Obtain CW lock on Table – //financial/expenses
  3. Obtain CW lock on Partition – //financial/expenses/
  4. Obtain CW lock on Page – //financial/expenses/17
  5. Obtain PW lock on Tuple – //financial/expenses/17/85

Hierarchical Unlocking

  • In order to avoid deadlocks, either
    • The locks are obtained at one-shot, or
    • The locks are released in reverse order – bottom to top.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: