Subject RE: [firebird-support] Deadlock when 2 session update the same 01 row
Author Nicolas Timmers
Good explanation

-----Mensagem Original-----
De: Ann Harrison
Enviada em: 28/11/2012 19:08
Assunto: Re: [firebird-support] Deadlock when 2 session update the same 01 row

On Wed, Nov 28, 2012 at 9:42 AM, Andr´┐Ż Knappstein <
Knappstein@...> wrote:

> FWIW there seems to be a related question in the .net list.
> Jiri confirmed that the default is "NoWait". This makes my
> misunderstanding of the term "deadlock" complete, because in NoWait I
> usually get an exception right off, which is all but a deadlock in the
> way I used to understand it.

There's a some history and a bit of theory here.

The history is that in the early 1980's DEC had two groups writing
relational databases. One group used traditional record-lock based
concurrency control and one used MVCC. Guess which one Jim Starkey led,
and for extra points, how there happened to be two projects. At the time
DEC was pushing VAX clusters, which were groups of separate machines that
shared storage through a thing called the HSC. Part of the VAX Cluster
architecture was a distributed lock manager. Very clever bit of software,
which made locking possible in shared nothing, but locks were both slow and
available in limited quantities. Anyway, that's why a non-lock based
solution was attractive.

Having competing projects has some benefits - easy to do performance
testing side by side, and develops some real identification with the
project. Releasing two relational databases and making customers choose
between them was less attractive, so a rule emerged. The interfaces had to
be identical. Not just the API, but the system tables, and the error codes
- everything had to be consistent, so you could take an application running
against one database, change the logical name that lead to the database
shared library and magically you'd be running the other database. And, of
course, a common backup format so you back up one and restore as the other.

Error codes were a real trial. Some errors only occur with record-locking
system (e.g. out of locks) and some only with MVCC - update conflict. The
two project leaders and I met with a mediator, David Hartzband - he has a
doctorate in philosophy from Heidelberg (the one in Germany), is a database
expert, and worked as a bouncer at the Buckets of Blood bar outside the
gates of a steel mill in either Pittsburg PA or Youngstown Ohio. I forget
which. A man who could be very convincing. Errors were divided into
groups by the way a program could deal with them. Codes common to both
system and the top code for a group of similar codes became primary error
codes. Codes that were specific to a database were secondary codes.
That's how Update Conflict got to be a secondary code under Deadlock.

The theory is that if you encounter an update conflict, you're going to see
that same conflict if you retry your transaction before the other
transaction commits. That's pretty much live-lock: try, fail, try again,
fail again, use all the system resources and don't get anywhere. That's
why the original default was WAIT. If you wait, then there's a chance your
next attempt will succeed. Yes, it's a problem if the other guy is running
long update transactions (why would he do that?) and you've got a user
waiting for an answer. Lots of interfaces use NO_WAIT as the default.

Good luck,


[Non-text portions of this message have been removed]

<!-- #ygrp-mkp { border: 1px solid #d8d8d8; font-family: Arial; margin: 10px 0; padding: 0 10px; } #ygrp-mkp hr { border: 1px solid #d8d8d8; } #ygrp-mkp #hd { color: #628c2a; font-size: 85%; font-weight: 700; line-height: 122%; margin: 10px 0; } #ygrp-mkp #ads { margin-bottom: 10px; } #ygrp-mkp .ad { padding: 0 0; } #ygrp-mkp .ad p { margin: 0; } #ygrp-mkp .ad a { color: #0000ff; text-decoration: none; } #ygrp-sponsor #ygrp-lc { font-family: Arial; } #ygrp-sponsor #ygrp-lc #hd { margin: 10px 0px; font-weight: 700; font-size: 78%; line-height: 122%; } #ygrp-sponsor #ygrp-lc .ad { margin-bottom: 10px; padding: 0 0; } #actions { font-family: Verdana; font-size: 11px; padding: 10px 0; } #activity { background-color: #e0ecee; float: left; font-family: Verdana; font-size: 10px; padding: 10px; } #activity span { font-weight: 700; } #activity span:first-child { text-transform: uppercase; } #activity span a { color: #5085b6; text-decoration: none; } #activity span span { color: #ff7900; } #activity span .underline { text-decoration: underline; } .attach { clear: both; display: table; font-family: Arial; font-size: 12px; padding: 10px 0; width: 400px; } .attach div a { text-decoration: none; } .attach img { border: none; padding-right: 5px; } .attach label { display: block; margin-bottom: 5px; } .attach label a { text-decoration: none; } blockquote { margin: 0 0 0 4px; } .bold { font-family: Arial; font-size: 13px; font-weight: 700; } .bold a { text-decoration: none; } dd.last p a { font-family: Verdana; font-weight: 700; } dd.last p span { margin-right: 10px; font-family: Verdana; font-weight: 700; } dd.last p span.yshortcuts { margin-right: 0; } div.attach-table div div a { text-decoration: none; } div.attach-table { width: 400px; } div.file-title a, div.file-title a:active, div.file-title a:hover, div.file-title a:visited { text-decoration: none; } a, a:active, a:hover, a:visited { text-decoration: none; } div#ygrp-mlmsg #ygrp-msg p a span.yshortcuts { font-family: Verdana; font-size: 10px; font-weight: normal; } .green { color: #628c2a; } .MsoNormal { margin: 0 0 0 0; } o { font-size: 0; } #photos div { float: left; width: 72px; } #photos div div { border: 1px solid #666666; height: 62px; overflow: hidden; width: 62px; } #photos div label { color: #666666; font-size: 10px; overflow: hidden; text-align: center; white-space: nowrap; width: 64px; } #reco-category { font-size: 77%; } #reco-desc { font-size: 77%; } .replbq { margin: 4px; } #ygrp-actbar div a:first-child { /* border-right: 0px solid #000;*/ margin-right: 2px; padding-right: 5px; } #ygrp-mlmsg { font-size: 13px; font-family: Arial, helvetica,clean, sans-serif; *font-size: small; *font: x-small; } #ygrp-mlmsg table { font-size: inherit; font: 100%; } #ygrp-mlmsg select, input, textarea { font: 99% Arial, Helvetica, clean, sans-serif; } #ygrp-mlmsg pre, code { font:115% monospace; *font-size:100%; } #ygrp-mlmsg * { line-height: 1.22em; } #ygrp-mlmsg #logo { padding-bottom: 10px; } #ygrp-msg p a { font-family: Verdana; } #ygrp-msg p#attach-count span { color: #1E66AE; font-weight: 700; } #ygrp-reco #reco-head { color: #ff7900; font-weight: 700; } #ygrp-reco { margin-bottom: 20px; padding: 0px; } #ygrp-sponsor #ov li a { font-size: 130%; text-decoration: none; } #ygrp-sponsor #ov li { font-size: 77%; list-style-type: square; padding: 6px 0; } #ygrp-sponsor #ov ul { margin: 0; padding: 0 0 0 8px; } #ygrp-text { font-family: Georgia; } #ygrp-text p { margin: 0 0 1em 0; } #ygrp-text tt { font-size: 120%; } #ygrp-vital ul li:last-child { border-right: none !important; } -->

[Non-text portions of this message have been removed]