SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
Locks In Distributed
Systems
Mridul K Mishra(170303201015)
What is it?
 In computer science, a lock is a synchronization mechanism for enforcing
limits on access to a resource in an environment where there are many
threads of execution. A lock is designed to enforce a mutual exclusion
concurrency control policy.
 In Distributed Systems(referred to as DS from now on), lock is a mechanism
that allows only one of the innumerable nodes(or process) to access and
modify a resource or data that is being shared commonly to prevent execution
of same task twice and also maintain data integrity.
 In the common database of a bank, at a given instance of time only one node(at
bank branch or user himself using personal banking) should be able to carry out a
transaction on a given bank account ( Data Integrity).
Why is it needed?
 Any DS always uses a database, and concurrent tasks are always performed by different
nodes, so analogous to the relational database,
 R-W anomaly
 W-R anomaly
 W-W anomaly
may occur. This ensures integrity and consistency of data. This lock is for Correctness.
 In addition to this, the system has to ensure that only one process is fired for
execution of a single task, e.g. in an inventory, upon shortage of a needed
resource, order should be placed only once. This increases the efficiency and
throughput of the system. And similar to single computer OS, problems like
Deadlock can occur, which have to be prevented. This lock is for Efficiency.
 The basic idea behind locks is to decrease the cost of carrying out operations in a
DS by ensuring that among several nodes trying to do a task only one does it(at a
given instance of time).
 Although locks are valid in DS for both above stated scenarios, the locking
mechanism should be chosen wisely according to the need. E.g. In many cases
applying the lock to prevent repetition of task might be costlier than task itself.
How Is It Implemented?
 Compared to conventional OS and relational database, the locking mechanism in a DS is quite
complicated as the network itself or the nodes can independently fail at any time.
 There are various algorithms deployed for this in different DS, E.g. Redlock, Paxos. The lock
managers are generally referred to as Distributed Lock Managers(DLM)
 The DLM uses a generalized concept of a resource, which is some entity to which shared
access must be controlled. This can relate to a file, a record, an area of shared memory, or
anything else that the application designer chooses. A hierarchy of resources may be defined,
so that a number of levels of locking can be implemented. For instance, a hypothetical
database might define a resource hierarchy as follows:
 Database
 Table
 Record
 Field
 A process can then acquire locks on the database as a whole, and then on particular parts of
the database. A lock must be obtained on a parent resource before a subordinate resource
can be locked.
 Various types of Locks that are granted by DLM in order of their hierarchy are:
 Null(NL):Process wants to lock resource, but does not stop others from getting lock
on it.
 Concurrent Read(CR):Multiple processes can read a resource but not update it.
 Concurrent Write(CW):Multiple processes can read and update a resource but no
exclusive access provide.
 Protected Read(PR):A process( or multiple) reads a resource but prevents others
from updating it
 Protected Write(PW):Indicates that a process will read and update a resource.
Prevents others from updating it. CW lock holders can read it.
 Exclusive(EX):This is the traditional exclusive lock which allows read and update
access to the resource, and prevents others from having any access to it
 A process can upgrade its lock as per need and permission of DLM.
 The following table explains the relation between above stated locks:
 A lock value block is associated with each resource. This can be read by any
process that has obtained a lock on the resource (other than a null lock) and
can be updated by a process that has obtained a protected update or
exclusive lock on it. And based on above tables locks can be updated.
Issues
Although DLMs provide for data integrity some issues that might arise are:
 Lost Update: say we have an application in which a client needs to update a
file in shared storage. A client first acquires the lock, then reads the file,
makes some changes, writes the modified file back, and finally releases the
lock and in meantime the lock/lease expires. Another client acquires the lock
The lock prevents two clients from performing this read-modify-write cycle
concurrently, which would result in lost updates. Explained by diagram.
 Using Timestamps/tokens can solve this issue.
 Deadlock: When one or more processes have obtained locks on resources, it
is possible to produce a situation where each is preventing another from
obtaining a lock, and none of them can proceed. This is known as a deadlock.
 A simple example is when Process 1 has obtained an exclusive lock on Resource A,
and Process 2 has obtained an exclusive lock on Resource B. If Process 1 then tries
to lock Resource B, it will have to wait for Process 2 to release it. But if Process 2
then tries to lock Resource A, both processes will wait forever for each other.
Advantages:
 Ensures the Correctness of
transactions.
 System becomes more robust i.e.
prevents system failures
Illustrations:
 Chubby- Designed by Google for
loosely coupled DS
 Apache ZooKeeper- An open source
manager designed by Yahoo.
 Redis - an open source, BSD
licensed, advanced key-value
cache and store
References
 Wikipedia
 https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-
locking.html
Thank You

More Related Content

PPTX
Optimistic concurrency control in Distributed Systems
PDF
Distributed deadlock
PPTX
Replication in Distributed Systems
PPT
System models in distributed system
PPT
Directory and discovery services
DOC
Naming in Distributed System
PPSX
Congestion avoidance in TCP
PPTX
Transactions and Concurrency Control
Optimistic concurrency control in Distributed Systems
Distributed deadlock
Replication in Distributed Systems
System models in distributed system
Directory and discovery services
Naming in Distributed System
Congestion avoidance in TCP
Transactions and Concurrency Control

What's hot (20)

PPTX
Vector clock algorithm
DOC
Distributed Mutual exclusion algorithms
PPTX
Distributed shred memory architecture
PPT
Types of Load distributing algorithm in Distributed System
PPTX
Domain model Refinement
PPT
Distributed Deadlock Detection.ppt
PPT
Distributed System-Multicast & Indirect communication
PPTX
01 - Introduction to Distributed Systems
PPT
Chapter 14 replication
PPTX
Developing a Map Reduce Application
PPTX
Introduction to Distributed System
PPTX
Distributed Transactions(flat and nested) and Atomic Commit Protocols
PPT
File models and file accessing models
PPTX
Communication And Synchronization In Distributed Systems
PPTX
Multi processor scheduling
PPT
Clock synchronization in distributed system
PPTX
Multiprocessor Architecture (Advanced computer architecture)
PPTX
Active and Passive Network Attacks
DOCX
Group Communication in distributed Systems.docx
PPTX
Congestion on computer network
Vector clock algorithm
Distributed Mutual exclusion algorithms
Distributed shred memory architecture
Types of Load distributing algorithm in Distributed System
Domain model Refinement
Distributed Deadlock Detection.ppt
Distributed System-Multicast & Indirect communication
01 - Introduction to Distributed Systems
Chapter 14 replication
Developing a Map Reduce Application
Introduction to Distributed System
Distributed Transactions(flat and nested) and Atomic Commit Protocols
File models and file accessing models
Communication And Synchronization In Distributed Systems
Multi processor scheduling
Clock synchronization in distributed system
Multiprocessor Architecture (Advanced computer architecture)
Active and Passive Network Attacks
Group Communication in distributed Systems.docx
Congestion on computer network
Ad

Similar to Locks In Disributed Systems (20)

PPTX
BCT 2312 - Chapter 3 - Concurrency Control Techniques in DBMSs.pptx
PPTX
Transaction and NOSQL Chapter-Module 5.pptx
PPTX
Concurrency Control in Database Management System
PPTX
CHapter four database managementm04.pptx
PPTX
concurrency control
DOCX
Concurrency Control Techniques
PDF
Unit 5 rdbms study_material
PPTX
Concurrency Control in RDBMS for Students.pptx
PPTX
Concurrency Control in Databases.Database management systems
PPTX
Type LocK based in Concurrency Control.pptx
PPT
concurrency-control
PDF
Module 5 part-2 concurrency control in dbms
PDF
PPT-concurrency Control database management system DBMS concurrent control (U...
PPTX
Concurrency control PPT
PDF
Concurrency Control in Database Management System
PPTX
DBMS (Deadlock, deadlock prevention, 2phase locking)
PPT
Concurrency control
DOCX
Locking base concurrency control
PPT
Dbms ii mca-ch10-concurrency-control-2013
BCT 2312 - Chapter 3 - Concurrency Control Techniques in DBMSs.pptx
Transaction and NOSQL Chapter-Module 5.pptx
Concurrency Control in Database Management System
CHapter four database managementm04.pptx
concurrency control
Concurrency Control Techniques
Unit 5 rdbms study_material
Concurrency Control in RDBMS for Students.pptx
Concurrency Control in Databases.Database management systems
Type LocK based in Concurrency Control.pptx
concurrency-control
Module 5 part-2 concurrency control in dbms
PPT-concurrency Control database management system DBMS concurrent control (U...
Concurrency control PPT
Concurrency Control in Database Management System
DBMS (Deadlock, deadlock prevention, 2phase locking)
Concurrency control
Locking base concurrency control
Dbms ii mca-ch10-concurrency-control-2013
Ad

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Structure & Organelles in detailed.
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Lesson notes of climatology university.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Basic Mud Logging Guide for educational purpose
PDF
Pre independence Education in Inndia.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Sports Quiz easy sports quiz sports quiz
VCE English Exam - Section C Student Revision Booklet
Cell Structure & Organelles in detailed.
O7-L3 Supply Chain Operations - ICLT Program
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
Basic Mud Logging Guide for educational purpose
Pre independence Education in Inndia.pdf
TR - Agricultural Crops Production NC III.pdf
Computing-Curriculum for Schools in Ghana
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Complications of Minimal Access Surgery at WLH
Renaissance Architecture: A Journey from Faith to Humanism
Sports Quiz easy sports quiz sports quiz

Locks In Disributed Systems

  • 1. Locks In Distributed Systems Mridul K Mishra(170303201015)
  • 2. What is it?  In computer science, a lock is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy.  In Distributed Systems(referred to as DS from now on), lock is a mechanism that allows only one of the innumerable nodes(or process) to access and modify a resource or data that is being shared commonly to prevent execution of same task twice and also maintain data integrity.  In the common database of a bank, at a given instance of time only one node(at bank branch or user himself using personal banking) should be able to carry out a transaction on a given bank account ( Data Integrity).
  • 3. Why is it needed?  Any DS always uses a database, and concurrent tasks are always performed by different nodes, so analogous to the relational database,  R-W anomaly  W-R anomaly  W-W anomaly may occur. This ensures integrity and consistency of data. This lock is for Correctness.  In addition to this, the system has to ensure that only one process is fired for execution of a single task, e.g. in an inventory, upon shortage of a needed resource, order should be placed only once. This increases the efficiency and throughput of the system. And similar to single computer OS, problems like Deadlock can occur, which have to be prevented. This lock is for Efficiency.
  • 4.  The basic idea behind locks is to decrease the cost of carrying out operations in a DS by ensuring that among several nodes trying to do a task only one does it(at a given instance of time).  Although locks are valid in DS for both above stated scenarios, the locking mechanism should be chosen wisely according to the need. E.g. In many cases applying the lock to prevent repetition of task might be costlier than task itself.
  • 5. How Is It Implemented?  Compared to conventional OS and relational database, the locking mechanism in a DS is quite complicated as the network itself or the nodes can independently fail at any time.  There are various algorithms deployed for this in different DS, E.g. Redlock, Paxos. The lock managers are generally referred to as Distributed Lock Managers(DLM)  The DLM uses a generalized concept of a resource, which is some entity to which shared access must be controlled. This can relate to a file, a record, an area of shared memory, or anything else that the application designer chooses. A hierarchy of resources may be defined, so that a number of levels of locking can be implemented. For instance, a hypothetical database might define a resource hierarchy as follows:  Database  Table  Record  Field  A process can then acquire locks on the database as a whole, and then on particular parts of the database. A lock must be obtained on a parent resource before a subordinate resource can be locked.
  • 6.  Various types of Locks that are granted by DLM in order of their hierarchy are:  Null(NL):Process wants to lock resource, but does not stop others from getting lock on it.  Concurrent Read(CR):Multiple processes can read a resource but not update it.  Concurrent Write(CW):Multiple processes can read and update a resource but no exclusive access provide.  Protected Read(PR):A process( or multiple) reads a resource but prevents others from updating it  Protected Write(PW):Indicates that a process will read and update a resource. Prevents others from updating it. CW lock holders can read it.  Exclusive(EX):This is the traditional exclusive lock which allows read and update access to the resource, and prevents others from having any access to it
  • 7.  A process can upgrade its lock as per need and permission of DLM.  The following table explains the relation between above stated locks:
  • 8.  A lock value block is associated with each resource. This can be read by any process that has obtained a lock on the resource (other than a null lock) and can be updated by a process that has obtained a protected update or exclusive lock on it. And based on above tables locks can be updated.
  • 9. Issues Although DLMs provide for data integrity some issues that might arise are:  Lost Update: say we have an application in which a client needs to update a file in shared storage. A client first acquires the lock, then reads the file, makes some changes, writes the modified file back, and finally releases the lock and in meantime the lock/lease expires. Another client acquires the lock The lock prevents two clients from performing this read-modify-write cycle concurrently, which would result in lost updates. Explained by diagram.
  • 10.  Using Timestamps/tokens can solve this issue.  Deadlock: When one or more processes have obtained locks on resources, it is possible to produce a situation where each is preventing another from obtaining a lock, and none of them can proceed. This is known as a deadlock.  A simple example is when Process 1 has obtained an exclusive lock on Resource A, and Process 2 has obtained an exclusive lock on Resource B. If Process 1 then tries to lock Resource B, it will have to wait for Process 2 to release it. But if Process 2 then tries to lock Resource A, both processes will wait forever for each other.
  • 11. Advantages:  Ensures the Correctness of transactions.  System becomes more robust i.e. prevents system failures Illustrations:  Chubby- Designed by Google for loosely coupled DS  Apache ZooKeeper- An open source manager designed by Yahoo.  Redis - an open source, BSD licensed, advanced key-value cache and store