为什么要避免版本控制系统中的悲观锁定?

时间:2022-05-19 01:06:10

Based on a few posts I've read concerning version control, it seems people think pessimistic locking in a version control system is a bad thing. Why? I understand that it prevents one developer from submitting a change while another has the file checked out, but so what? If your code files are so big that you constantly have more than one person working on them at the same time, I submit that you should reorganize your code. Break it up into smaller functional units.

基于我读过的关于版本控制的一些帖子,似乎人们认为版本控制系统中的悲观锁定是一件坏事。为什么?据我所知,它可以防止一个开发人员提交更改,而另一个开发人员已经检出文件,但那又怎么样?如果您的代码文件太大,以至于您不断有多个人同时处理它们,我提交您应该重新组织您的代码。将其分解为更小的功能单元。

Integration of concurrent code changes is a tedious and error-prone process even with the tools a good version control system provides to make it easier. I think it should be avoided if at all possible. So, why is pessimistic locking discouraged?

即使使用良好的版本控制系统提供的工具使其更容易,并发代码更改的集成也是一个单调乏味且容易出错的过程。我想如果可能的话应该避免。那么,为什么悲观的锁定气馁呢?

10 个解决方案

#1


7  

It depends on your project and team generally. Pessimistic locking is good because it is easy to understand - one dev at a time, and no merging required!

这通常取决于您的项目和团队。悲观锁定很好,因为它很容易理解 - 一次一个开发,不需要合并!

However, the bad thing about is is exactly that - one dev at a time. I have the situation right now where a colleague has gone on-site, and before he left, he checked everything out so that if he had to fix any bugs, he could return and check all his changes in.... great for him, lousy for me and the rest of the dev team at base.

然而,关键的坏处就是 - 一次一个开发者。我现在有一个同事离开现场的情况,在他离开之前,他检查了所有的东西,如果他必须修复任何错误,他可以返回并检查他所有的变化......对他来说很棒,对我和基地的其他开发团队来说很糟糕。

If you can get around pessimistic locking in your team then its fine to use it, really, the biggest reason people hate it is because its Visual SourceSafe's default practice. If you're not confident in merging lots of changes, then you have another reason to use it - if you've ever used a optimistic locking SCM, and cocked up a merge, you'll know how hard it is to recover.

如果你可以解决你的团队中的悲观锁定然后很好地使用它,真的,人们讨厌它的最大原因是因为它的Visual SourceSafe的默认实践。如果你没有信心合并大量的变化,那么你有另一个理由使用它 - 如果你曾经使用过乐观的锁定SCM,并且合并了,你就会知道恢复有多难。

If you can handle merging, then optimistic locking is superior and I'd recommend it, but you don't have to hand your geek card in if you don't want to use it.

如果你可以处理合并,那么乐观锁定是优越的,我推荐它,但如果你不想使用它,你不必将你的极客卡交给你。

#2


14  

  1. Go play with Source Safe and have a developer leave for a two week vacation. Add to that the VSS admins not being around. Now you have a fix to be posted but you can't because of the developer
  2. 使用Source Safe进行游戏并让开发者离开两周假期。再加上VSS管理员不在身边。现在你有一个可以发布的修复程序,但你不能因为开发人员

  3. If you have multiple features and/or bug fixes being worked on. No matter how small your code is broken up, you will still have contention for a central file.
  4. 如果您正在处理多个功能和/或错误修复程序。无论你的代码多么小,你仍然会争夺一个中心文件。

#3


6  

  1. Bob needs to edit FooBar.java
  2. Bob需要编辑FooBar.java

  3. John has it checked out for editing
  4. 约翰已经检查了编辑

  5. Bob edits his local copy anyway and saves it as FooBar.java.bak
  6. 鲍勃无论如何编辑他的本地副本并将其保存为FooBar.java.bak

  7. When John checks his in, Bob checks it out
  8. 当约翰检查他的时,鲍勃检查了它

  9. Bob copies FooBar.java.bak over it and checks it in
  10. Bob将FooBar.java.bak复制到它上面并将其检入

  11. John gets to reimplement his feature
  12. 约翰重新实现他的功能

I've seen it happen time and time again. Developers do this because this process is annoying:

我已经看到它一次又一次地发生。开发人员这样做是因为这个过程很烦人:

  1. Bob needs to edit FooBar.java
  2. Bob需要编辑FooBar.java

  3. John has it checked out for editing
  4. 约翰已经检查了编辑

  5. Bob has to wait twiddling his thumbs until John is done
  6. 鲍勃不得不等待他的拇指,直到约翰完成

Pessimistic locking feels like amateur hour, sorry.

悲观的锁定感觉像业余时间,对不起。

#4


4  

  • You don't always have the option to break files apart
    • Config Files
    • XML Files
  • 您并不总是可以选择将文件分开配置文件XML文件

  • Even relatively small files can still contain distinct parts that more than one developer needs access to
    • Libraries
    • Utilities
  • 即使是相对较小的文件仍然可以包含多个开发人员需要访问Libraries Utilities的不同部分

  • Merging Tools are much smarter than they have ever been
    • Conflicts are rather rare
    • 冲突相当罕见

  • 合并工具比以往任何时候都更加智能冲突相当罕见

  • Reduces delays due to developers having files "accidentally" checked out
  • 减少因开发人员“意外”签出文件而导致的延迟

#5


3  

If a developer can't handle merging and fixing conflicts, he should be re-educated.

如果开发人员无法处理合并和修复冲突,他应该重新接受教育。

It is common for even small files to get conflicts, for example with JSPs one person (web developer) could be changing the layout code, and someone else could change the API for the model that the JSP is using.

即使是小文件也常常会发生冲突,例如,使用JSP,一个人(Web开发人员)可能会更改布局代码,而其他人可能会更改JSP正在使用的模型的API。

#6


3  

Regarding the case with Bob and John, cooperative systems like svn do not prevent this scenario any more than a locking system does. I can 'update' FooBar.java, which satisfies svn that I have the latest edition, then delete that file locally and overwrite it with my own personal copy that I made without any regard for the baseline version, and check that in, happily destroying the other guy's changes. No system, locking or not, prevents this, so I do not see the point of even bringing it into the debate.

关于Bob和John的案例,像svn这样的合作系统不会阻止这种情况,只不过是锁定系统。我可以'更新'FooBar.java,它满足我拥有最新版本的svn,然后在本地删除该文件并用我自己的个人副本覆盖它,而不考虑基线版本,并检查它,愉快地破坏另一个人的变化。没有系统,无论是否锁定,都可以防止这种情况发生,因此我甚至没有看到将其纳入辩论的重点。

The real issue is deciding what your balance is between

真正的问题是决定你的平衡

likelihood of merge mistakes vs. inconvenience caused by people locking files

合并错误的可能性与人们锁定文件造成的不便之处

The notion that either a locking or non-locking system is "superior" is nonsense.

锁定或非锁定系统“优越”的概念是无稽之谈。

I've used VSS, in its default full locking mode, with 6 developers, and it worked like a dream. Occasionally, somebody would forget to release a lock and we'd have to hunt them down or break the lock manually and hand-merge when they returned, but this was very minimal. I've seen svn screw up its automatic merge more than once, such that I don't really trust it. It doesn't always flag a 'conflict' when two people have changed the same file in a way that cannot be automatically merged together.
Conversely, I've seen people get impatient with VSS's locks, edit their own copies, and sloppily check them in over the top of other peoples' code, and I've seen svn handily catch me when I might accidentally try to check something in that has been changed by somebody else since I last checked it out.

我使用VSS,在其默认的完全锁定模式下,有6个开发人员,它就像一个梦想。偶尔,有人会忘记释放一个锁,我们必须将它们追捕或手动打破锁并在它们返回时手动合并,但这是非常小的。我已经看过svn不止一次搞砸了它的自动合并,这样我真的不相信它。当两个人以不能自动合并在一起的方式更改同一文件时,它并不总是标记“冲突”。相反,我看到人们对VSS的锁定感到不耐烦,编辑他们自己的副本,并在其他人的代码顶部检查它们,我已经看到svn在我不小心尝试检查某些内容时轻易抓住我自从我上次查看以来,其他人已经改变了。

My point is, this is not a sensible debate to have. The success of either system comes down to how you manage the conflict points when they occur, not whether one system or the other is better.

我的观点是,这不是一个明智的辩论。这两种系统的成功归结为如何在冲突点发生时管理冲突点,而不是一个系统或另一个系统是否更好。

#7


2  

Pessimistic locking is (personal experience) in the way of collaboration. It's sometimes easily replaced by good team communication. Just by saying "Hey, I'm gonna work on this few files for a while".

悲观锁定是(个人经验)的协作方式。它有时很容易被良好的团队沟通所取代。只是说“嘿,我会在这几个文件上工作一段时间”。

I've worked in teams of 2 to 6 people without locking and we never had a problem, beyond some usual and necessary merges.

我已经在2到6人的团队中工作而没有锁定,除了一些通常和必要的合并之外我们从未遇到过问题。

I also worked once with locking in a Visual SourceSafe hosted project. It was IMHO counter-productive.

我还曾在Visual SourceSafe托管项目中锁定过一次。这是恕我直言,适得其反。

#8


1  

Software developers are always optimists -- just look at their estimating skils!

软件开发人员总是乐观主义者 - 只需看看他们的估算技巧!

In practice we find conflicts are rare and the benefits of not having to worry about locking outweigh the occasional conflict resolution step.

在实践中,我们发现冲突是罕见的,不必担心锁定的好处超过偶尔的冲突解决步骤。

#9


1  

if your code files are so big that you constantly have more than one person working on them at the same time

如果您的代码文件太大,以至于您不断有多个人同时处理它们

If this is the case it's time for 'human beings' to take charge and coordinate any changes. In the ideal case, and if your project management is any good, you will rarely hit a time where you're trying to change a locked file because someone will have coordinated things so this won't practically happen.

如果是这种情况,那么'人类'应该负责并协调任何变化。在理想的情况下,如果你的项目管理有任何好处,你很少会碰到你试图更改锁定文件的时间,因为有人会协调一些事情,所以这实际上不会发生。

In other words you'll know 'Bob' is doing a large set of changes in components X/Y/Z, if you have a bug fix in component X you'll know to talk to Bob before trying to submit your changes.

换句话说,你会知道'Bob'正在对组件X / Y / Z进行大量更改,如果你在组件X中有一个bug修复,你会在尝试提交更改之前与Bob交谈。

As I say this is ideal ;)

正如我所说这是理想的;)

#10


1  

Pessimistic locking is a good idea if serious conflicts are going to be likely. For most programming you won't see any serious conflicts, so pessimistic locking is fairly pointless. Exceptions to this would be if you are:

如果可能发生严重冲突,悲观锁定是一个好主意。对于大多数编程,你不会看到任何严重的冲突,所以悲观锁定是毫无意义的。例如,如果您是:

  • Working on binary files where you can't really merge - art assets (models, textures, etc) are a good example.
  • 处理无法真正合并的二进制文件 - 艺术资产(模型,纹理等)就是一个很好的例子。

  • Working with non-technical users who don't know how to merge, and don't want to learn (mostly artists, but some technical writers will throw a fit about this too).
  • 与不懂技术的用户合作,他们不知道如何合并,也不想学习(主要是艺术家,但是一些技术作家也会对此有所了解)。

  • Working on very large files which can't easily be merged or broken into smaller files due to the high degree of complexity (never seen a situation like that first hand, but I'm sure it's possible).
  • 处理非常大的文件,由于高度复杂性,不能轻易地合并或分解成较小的文件(从未见过像第一手的情况,但我确信它是可能的)。

Otherwise...

#1


7  

It depends on your project and team generally. Pessimistic locking is good because it is easy to understand - one dev at a time, and no merging required!

这通常取决于您的项目和团队。悲观锁定很好,因为它很容易理解 - 一次一个开发,不需要合并!

However, the bad thing about is is exactly that - one dev at a time. I have the situation right now where a colleague has gone on-site, and before he left, he checked everything out so that if he had to fix any bugs, he could return and check all his changes in.... great for him, lousy for me and the rest of the dev team at base.

然而,关键的坏处就是 - 一次一个开发者。我现在有一个同事离开现场的情况,在他离开之前,他检查了所有的东西,如果他必须修复任何错误,他可以返回并检查他所有的变化......对他来说很棒,对我和基地的其他开发团队来说很糟糕。

If you can get around pessimistic locking in your team then its fine to use it, really, the biggest reason people hate it is because its Visual SourceSafe's default practice. If you're not confident in merging lots of changes, then you have another reason to use it - if you've ever used a optimistic locking SCM, and cocked up a merge, you'll know how hard it is to recover.

如果你可以解决你的团队中的悲观锁定然后很好地使用它,真的,人们讨厌它的最大原因是因为它的Visual SourceSafe的默认实践。如果你没有信心合并大量的变化,那么你有另一个理由使用它 - 如果你曾经使用过乐观的锁定SCM,并且合并了,你就会知道恢复有多难。

If you can handle merging, then optimistic locking is superior and I'd recommend it, but you don't have to hand your geek card in if you don't want to use it.

如果你可以处理合并,那么乐观锁定是优越的,我推荐它,但如果你不想使用它,你不必将你的极客卡交给你。

#2


14  

  1. Go play with Source Safe and have a developer leave for a two week vacation. Add to that the VSS admins not being around. Now you have a fix to be posted but you can't because of the developer
  2. 使用Source Safe进行游戏并让开发者离开两周假期。再加上VSS管理员不在身边。现在你有一个可以发布的修复程序,但你不能因为开发人员

  3. If you have multiple features and/or bug fixes being worked on. No matter how small your code is broken up, you will still have contention for a central file.
  4. 如果您正在处理多个功能和/或错误修复程序。无论你的代码多么小,你仍然会争夺一个中心文件。

#3


6  

  1. Bob needs to edit FooBar.java
  2. Bob需要编辑FooBar.java

  3. John has it checked out for editing
  4. 约翰已经检查了编辑

  5. Bob edits his local copy anyway and saves it as FooBar.java.bak
  6. 鲍勃无论如何编辑他的本地副本并将其保存为FooBar.java.bak

  7. When John checks his in, Bob checks it out
  8. 当约翰检查他的时,鲍勃检查了它

  9. Bob copies FooBar.java.bak over it and checks it in
  10. Bob将FooBar.java.bak复制到它上面并将其检入

  11. John gets to reimplement his feature
  12. 约翰重新实现他的功能

I've seen it happen time and time again. Developers do this because this process is annoying:

我已经看到它一次又一次地发生。开发人员这样做是因为这个过程很烦人:

  1. Bob needs to edit FooBar.java
  2. Bob需要编辑FooBar.java

  3. John has it checked out for editing
  4. 约翰已经检查了编辑

  5. Bob has to wait twiddling his thumbs until John is done
  6. 鲍勃不得不等待他的拇指,直到约翰完成

Pessimistic locking feels like amateur hour, sorry.

悲观的锁定感觉像业余时间,对不起。

#4


4  

  • You don't always have the option to break files apart
    • Config Files
    • XML Files
  • 您并不总是可以选择将文件分开配置文件XML文件

  • Even relatively small files can still contain distinct parts that more than one developer needs access to
    • Libraries
    • Utilities
  • 即使是相对较小的文件仍然可以包含多个开发人员需要访问Libraries Utilities的不同部分

  • Merging Tools are much smarter than they have ever been
    • Conflicts are rather rare
    • 冲突相当罕见

  • 合并工具比以往任何时候都更加智能冲突相当罕见

  • Reduces delays due to developers having files "accidentally" checked out
  • 减少因开发人员“意外”签出文件而导致的延迟

#5


3  

If a developer can't handle merging and fixing conflicts, he should be re-educated.

如果开发人员无法处理合并和修复冲突,他应该重新接受教育。

It is common for even small files to get conflicts, for example with JSPs one person (web developer) could be changing the layout code, and someone else could change the API for the model that the JSP is using.

即使是小文件也常常会发生冲突,例如,使用JSP,一个人(Web开发人员)可能会更改布局代码,而其他人可能会更改JSP正在使用的模型的API。

#6


3  

Regarding the case with Bob and John, cooperative systems like svn do not prevent this scenario any more than a locking system does. I can 'update' FooBar.java, which satisfies svn that I have the latest edition, then delete that file locally and overwrite it with my own personal copy that I made without any regard for the baseline version, and check that in, happily destroying the other guy's changes. No system, locking or not, prevents this, so I do not see the point of even bringing it into the debate.

关于Bob和John的案例,像svn这样的合作系统不会阻止这种情况,只不过是锁定系统。我可以'更新'FooBar.java,它满足我拥有最新版本的svn,然后在本地删除该文件并用我自己的个人副本覆盖它,而不考虑基线版本,并检查它,愉快地破坏另一个人的变化。没有系统,无论是否锁定,都可以防止这种情况发生,因此我甚至没有看到将其纳入辩论的重点。

The real issue is deciding what your balance is between

真正的问题是决定你的平衡

likelihood of merge mistakes vs. inconvenience caused by people locking files

合并错误的可能性与人们锁定文件造成的不便之处

The notion that either a locking or non-locking system is "superior" is nonsense.

锁定或非锁定系统“优越”的概念是无稽之谈。

I've used VSS, in its default full locking mode, with 6 developers, and it worked like a dream. Occasionally, somebody would forget to release a lock and we'd have to hunt them down or break the lock manually and hand-merge when they returned, but this was very minimal. I've seen svn screw up its automatic merge more than once, such that I don't really trust it. It doesn't always flag a 'conflict' when two people have changed the same file in a way that cannot be automatically merged together.
Conversely, I've seen people get impatient with VSS's locks, edit their own copies, and sloppily check them in over the top of other peoples' code, and I've seen svn handily catch me when I might accidentally try to check something in that has been changed by somebody else since I last checked it out.

我使用VSS,在其默认的完全锁定模式下,有6个开发人员,它就像一个梦想。偶尔,有人会忘记释放一个锁,我们必须将它们追捕或手动打破锁并在它们返回时手动合并,但这是非常小的。我已经看过svn不止一次搞砸了它的自动合并,这样我真的不相信它。当两个人以不能自动合并在一起的方式更改同一文件时,它并不总是标记“冲突”。相反,我看到人们对VSS的锁定感到不耐烦,编辑他们自己的副本,并在其他人的代码顶部检查它们,我已经看到svn在我不小心尝试检查某些内容时轻易抓住我自从我上次查看以来,其他人已经改变了。

My point is, this is not a sensible debate to have. The success of either system comes down to how you manage the conflict points when they occur, not whether one system or the other is better.

我的观点是,这不是一个明智的辩论。这两种系统的成功归结为如何在冲突点发生时管理冲突点,而不是一个系统或另一个系统是否更好。

#7


2  

Pessimistic locking is (personal experience) in the way of collaboration. It's sometimes easily replaced by good team communication. Just by saying "Hey, I'm gonna work on this few files for a while".

悲观锁定是(个人经验)的协作方式。它有时很容易被良好的团队沟通所取代。只是说“嘿,我会在这几个文件上工作一段时间”。

I've worked in teams of 2 to 6 people without locking and we never had a problem, beyond some usual and necessary merges.

我已经在2到6人的团队中工作而没有锁定,除了一些通常和必要的合并之外我们从未遇到过问题。

I also worked once with locking in a Visual SourceSafe hosted project. It was IMHO counter-productive.

我还曾在Visual SourceSafe托管项目中锁定过一次。这是恕我直言,适得其反。

#8


1  

Software developers are always optimists -- just look at their estimating skils!

软件开发人员总是乐观主义者 - 只需看看他们的估算技巧!

In practice we find conflicts are rare and the benefits of not having to worry about locking outweigh the occasional conflict resolution step.

在实践中,我们发现冲突是罕见的,不必担心锁定的好处超过偶尔的冲突解决步骤。

#9


1  

if your code files are so big that you constantly have more than one person working on them at the same time

如果您的代码文件太大,以至于您不断有多个人同时处理它们

If this is the case it's time for 'human beings' to take charge and coordinate any changes. In the ideal case, and if your project management is any good, you will rarely hit a time where you're trying to change a locked file because someone will have coordinated things so this won't practically happen.

如果是这种情况,那么'人类'应该负责并协调任何变化。在理想的情况下,如果你的项目管理有任何好处,你很少会碰到你试图更改锁定文件的时间,因为有人会协调一些事情,所以这实际上不会发生。

In other words you'll know 'Bob' is doing a large set of changes in components X/Y/Z, if you have a bug fix in component X you'll know to talk to Bob before trying to submit your changes.

换句话说,你会知道'Bob'正在对组件X / Y / Z进行大量更改,如果你在组件X中有一个bug修复,你会在尝试提交更改之前与Bob交谈。

As I say this is ideal ;)

正如我所说这是理想的;)

#10


1  

Pessimistic locking is a good idea if serious conflicts are going to be likely. For most programming you won't see any serious conflicts, so pessimistic locking is fairly pointless. Exceptions to this would be if you are:

如果可能发生严重冲突,悲观锁定是一个好主意。对于大多数编程,你不会看到任何严重的冲突,所以悲观锁定是毫无意义的。例如,如果您是:

  • Working on binary files where you can't really merge - art assets (models, textures, etc) are a good example.
  • 处理无法真正合并的二进制文件 - 艺术资产(模型,纹理等)就是一个很好的例子。

  • Working with non-technical users who don't know how to merge, and don't want to learn (mostly artists, but some technical writers will throw a fit about this too).
  • 与不懂技术的用户合作,他们不知道如何合并,也不想学习(主要是艺术家,但是一些技术作家也会对此有所了解)。

  • Working on very large files which can't easily be merged or broken into smaller files due to the high degree of complexity (never seen a situation like that first hand, but I'm sure it's possible).
  • 处理非常大的文件,由于高度复杂性,不能轻易地合并或分解成较小的文件(从未见过像第一手的情况,但我确信它是可能的)。

Otherwise...