A distributed lock manager (DLM) provides distributed software applications with a means to synchronize their accesses to shared resources.

DLMs have been used as the foundation for several successful clustered file systems, in which the machines in a cluster can use each other's storage via a unified file system, with significant advantages for performance and availability. The main performance benefit comes from solving the problem of disk cache coherency between participating computers. The DLM is used not only for file locking but also for coordination of all disk access. VMScluster, the first clustering system to come into widespread use, relies on the OpenVMS DLM in just this way.

Contents

  [hide

VMS implementation[edit]

VMS (virtual memory system) was the first widely available operating system to implement a DLM. This became available in Version 4, although the user interface was the same as the single-processor lock manager that was first implemented in Version 3.

Resources[edit]

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.

Lock modes[edit]

A process running within a VMSCluster may obtain a lock on a resource. There are six lock modes that can be granted, and these determine the level of exclusivity of access to the resource. Once a lock has been granted, it is possible to convert the lock to a higher or lower level of lock mode. When all processes have unlocked a resource, the system's information about the resource is destroyed.

  • Null Lock (NL). Indicates interest in the resource, but does not prevent other processes from locking it. It has the advantage that the resource and its lock value block are preserved, even when no processes are locking it.
  • Concurrent Read (CR). Indicates a desire to read (but not update) the resource. It allows other processes to read or update the resource, but prevents others from having exclusive access to it. This is usually employed on high-level resources, in order that more restrictive locks can be obtained on subordinate resources.
  • Concurrent Write (CW). Indicates a desire to read and update the resource. It also allows other processes to read or update the resource, but prevents others from having exclusive access to it. This is also usually employed on high-level resources, in order that more restrictive locks can be obtained on subordinate resources.
  • Protected Read (PR). This is the traditional share lock, which indicates a desire to read the resource but prevents other from updating it. Others can however also read the resource.
  • Protected Write (PW). This is the traditional update lock, which indicates a desire to read and update the resource and prevents others from updating it. Others with Concurrent Read access can however read the resource.
  • 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.

The following truth table shows the compatibility of each lock mode with the others:

Mode
NL
CR
CW
PR
PW
EX

NL
Yes
Yes
Yes
Yes
Yes
Yes

CR
Yes
Yes
Yes
Yes
Yes
No

CW
Yes
Yes
Yes
No
No
No

PR
Yes
Yes
No
Yes
No
No

PW
Yes
Yes
No
No
No
No

EX
Yes
No
No
No
No
No

Obtaining a lock[edit]

A process can obtain a lock on a resource by enqueueing a lock request. This is similar to the QIO technique that is used to perform I/O. The enqueue lock request can either complete synchronously, in which case the process waits until the lock is granted, or asynchronously, in which case an AST occurs when the lock has been obtained.

It is also possible to establish a blocking AST, which is triggered when a process has obtained a lock that is preventing access to the resource by another process. The original process can then optionally take action to allow the other access (e.g. by demoting or releasing the lock).

Lock value block[edit]

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.

It can be used to hold any information about the resource that the application designer chooses. A typical use is to hold a version number of the resource. Each time the associated entity (e.g. a database record) is updated, the holder of the lock increments the lock value block. When another process wishes to read the resource, it obtains the appropriate lock and compares the current lock value with the value it had last time the process locked the resource. If the value is the same, the process knows that the associated entity has not been updated since last time it read it, and therefore it is unnecessary to read it again. Hence, this technique can be used to implement various types of cache in a database or similar application.

Deadlock detection[edit]

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 (E. W. Dijkstra originally called it a deadly embrace).[1]

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.

The OpenVMS DLM periodically checks for deadlock situations. In the example above, the second lock enqueue request of one of the processes would return with a deadlock status. It would then be up to this process to take action to resolve the deadlock—in this case by releasing the first lock it obtained.

Linux clustering[edit]

Both Red Hat and Oracle have developed clustering software for Linux.

OCFS2, the Oracle Cluster File System was added[2] to the official Linux kernel with version 2.6.16, in January 2006. The alpha-quality code warning on OCFS2 was removed in 2.6.19.

Red Hat's cluster software, including their DLM and GFS2 was officially added to the Linux kernel [3] with version 2.6.19, in November 2006.

Both systems use a DLM modeled on the venerable VMS DLM.[4] Oracle's DLM has a simpler API. (the core function, dlmlock(), has eight parameters, whereas the VMSSYS$ENQ service and Red Hat's dlm_lock both have 11.)

Google's Chubby lock service[edit]

Google has developed Chubby, a lock service for loosely-coupled distributed systems.[5] It is designed for coarse-grained locking and also provides a limited but reliable distributed file system. Key parts of Google's infrastructure, including Google File System, BigTable, and MapReduce, use Chubby to synchronize accesses to shared resources. Though Chubby was designed as a lock service, it is now heavily used inside Google as a name server, supplanting DNS.[5]

ZooKeeper[edit]

Apache ZooKeeper, which was born out of Yahoo is open-source software and can be used to perform distributed locks[6] as well.

SSI Systems[edit]

A DLM is also a key component of more ambitious single system image projects such as OpenSSI.

References[edit]

  1. Jump up^ Gehani, Narain (1991). Ada: Concurrent Programming. p. 105. ISBN 9780929306087.
  2. Jump up^ kernel/git/torvalds/linux.git - Linux kernel source tree. Kernel.org. Retrieved on 2013-09-18.
  3. Jump up^ kernel/git/torvalds/linux.git - Linux kernel source tree. Git.kernel.org (2006-12-07). Retrieved on 2013-09-18.
  4. Jump up^ The OCFS2 filesystem. Lwn.net (2005-05-24). Retrieved on 2013-09-18.
  5. ^ Jump up to:a b Google Research Publication: Chubby Distributed Lock Service. Research.google.com. Retrieved on 2013-09-18.
  6. Jump up^ ZooKeeper Recipes and Solutions. Zookeeper.apache.org. Retrieved on 2013-09-18.

distributed lock manager (DLM)(分布式管理锁)的更多相关文章

  1. DLM分布式锁的实现机制

    1.AST简介 DLM进程(LMON.LMD)之间的跨实例通信是使用高速互联上的IPC层实现的.为了传递锁资源的状态,DLM使用了异步陷阱(AST),它在操作系统处理程序例程中实现为中断.纯粹主义者可 ...

  2. 安装配置 Kafka Manager 分布式管理工具

    Kafka Manager 特性,它支持以下内容(官方译解): 管理多个群集容易检查集群状态(主题,消费者,偏移量,经纪人,副本分发,分区分配)运行首选副本选举使用选项生成分区分配,以选择要使用的代理 ...

  3. 单机Redis实现分布式互斥锁

    代码地址如下:http://www.demodashi.com/demo/12520.html 0.准备工作 0-1 运行环境 jdk1.8 gradle 一个能支持以上两者的代码编辑器,作者使用的是 ...

  4. .net core 下的分布式事务锁

    原文:.net core 下的分布式事务锁 目录 系统分布式锁的用法 锁的实现 锁的使用 API内的范例: 引用链接 系统分布式锁的用法 公司框架新增功能分布式锁: 锁的性能之王: 缓存 > Z ...

  5. 【redis】基于redis实现分布式并发锁

    基于redis实现分布式并发锁(注解实现) 说明 前提, 应用服务是分布式或多服务, 而这些"多"有共同的"redis"; (2017-12-04) 笑哭, 写 ...

  6. 基于Zookeeper实现的分布式互斥锁 - InterProcessMutex

    Curator是ZooKeeper的一个客户端框架,其中封装了分布式互斥锁的实现,最为常用的是InterProcessMutex,本文将对其进行代码剖析 简介 InterProcessMutex基于Z ...

  7. DHT(Distributed Hash Table,分布式哈希表)

    DHT(Distributed Hash Table,分布式哈希表)类似Tracker的根据种子特征码返回种子信息的网络. DHT全称叫分布式哈希表(Distributed Hash Table),是 ...

  8. 高并发场景系列(一) 利用redis实现分布式事务锁,解决高并发环境下减库存

    原文:http://blog.csdn.net/heyewu4107/article/details/71009712 高并发场景系列(一) 利用redis实现分布式事务锁,解决高并发环境下减库存 问 ...

  9. Network Lock Manager Protocol (NLM)

    资料来源 https://wiki.wireshark.org/Network_Lock_Manager 目的 The purpose of the NLM protocol is to provid ...

随机推荐

  1. 11.Python使用Scrapy爬虫小Demo(新手入门)

    1.前提:已安装好scrapy,且已新建好项目,编写小Demo去获取美剧天堂的电影标题名 2.在项目中创建一个python文件 3.代码如下所示: import scrapy class movies ...

  2. ngnix+uwsgi+django 部署mezzanine

    以下是我用ngnix+uwsgi+django 部署mezzanine全过程,其中ngnix+uwsgi这块是看了虫师大神的博客(http://www.cnblogs.com/fnng/p/52686 ...

  3. 基于Oracle的EntityFramework的WEBAPI2的实现(三)—— 建立APIController及设置返回类型JSON、XML等

    建立普通的ApiControler 右击项目中的controller文件夹·添加·控制器·包含操作的webapi2控制器(使用entity framework),写个名字,如果:Test.然后选择类, ...

  4. golang的https服务器

    先生成ssl证书 openssl genrsa - openssl req - 然后,大概这样 package main import ( "log" "net/http ...

  5. MySQL查询优化器工作原理解析

    手册上查询优化器概述 查询优化器的任务是发现执行SQL查询的最佳方案.大多数查询优化器,包括MySQL的查询优化器,总或多或少地在所有可能的查询评估方案中搜索最佳方案.对于联接查询,MySQL优化器所 ...

  6. 皆在FPGA之外

    最近做电力方面的项目,由于跨行业,所以很长一段时间都在做前期准备工作. 项目设计前应尽量做到面面俱到,否则会在项目设计中遇到下面大概率问题: 性能不满足需求,然后为了提升性能,资源又成了瓶颈: 功能设 ...

  7. GOF23设计模式之装饰模式(decorator)

    一.装饰模式概述 (1)动态的为一个对象增加新的功能. (2)装饰模式是一种用于代替继承的技术,无需通过继承增加子类就能扩展对象的新功能.   使用对象的关联关系代替继承关系,更加灵活,同时避免类型体 ...

  8. 52道Python面试题

    1.python中is和==的区别 Python中对象包含的三个基本要素,分别是:id(身份标识) .type(数据类型)和value(值).‘==’比较的是value值‘is’比较的是id 2.简述 ...

  9. 第七周作业——简单FTP

    开发简单的FTP: 1. 用户登陆 2. 上传/下载文件 3. 不同用户家目录不同 4. 查看当前目录下文件 5. 充分使用面向对象知识 1.目录结构zuoye-ftp├── chenliang #用 ...

  10. Vim编辑器基本操作学习(二)

    操作符+位移 x命令可以删除一个字符,4x可以删除4个字符. dw可以删除一个word,w事实上是向后移动一个word的命令:dw可以接上一个任意一个位移命令,它将删除从当前光标开始到位移终点处的文本 ...