From c2872bafde6d6ec2444c293f7a8aa397eb1dbb59 Mon Sep 17 00:00:00 2001
From: unknown <serg@janus.mylan>
Date: Fri, 13 Oct 2006 11:37:27 +0200
Subject: push for trnman review (lockmanager still fails unit tests)

BitKeeper/deleted/.del-Makefile.am~4375ae3d4de2bdf0:
  Delete: unittest/maria/Makefile.am
configure.in:
  silence up configure warnings, don't generate unittest/maria/Makefile
include/atomic/nolock.h:
  s/LOCK/LOCK_prefix/
include/atomic/x86-gcc.h:
  s/LOCK/LOCK_prefix/
include/atomic/x86-msvc.h:
  s/LOCK/LOCK_prefix/
include/lf.h:
  pin asserts, renames
include/my_atomic.h:
  move cleanup
include/my_bit.h:
  s/uint/uint32/
mysys/lf_dynarray.c:
  style fixes, split for() in two, remove if()s
mysys/lf_hash.c:
  renames, minor fixes
mysys/my_atomic.c:
  run-time assert -> compile-time assert
storage/maria/Makefile.am:
  lockman here
storage/maria/unittest/Makefile.am:
  new unit tests
storage/maria/unittest/trnman-t.c:
  lots of changes
storage/maria/lockman.c:
  many changes:
  second meaning of "blocker"
  portability: s/gettimeofday/my_getsystime/
  move mutex/cond out of LOCK_OWNER - it creates a race condition
  that will be fixed in a separate changeset
  increment lm->count for every element, not only for distinct ones -
  because we cannot decrease it for distinct elements only :(
storage/maria/lockman.h:
  move mutex/cond out of LOCK_OWNER
storage/maria/trnman.c:
  move mutex/cond out of LOCK_OWNER
  atomic-ops to access short_trid_to_trn[]
storage/maria/trnman.h:
  move mutex/cond out of LOCK_OWNER
storage/maria/unittest/lockman-t.c:
  unit stress test
---
 storage/maria/lockman.c | 681 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 681 insertions(+)
 create mode 100644 storage/maria/lockman.c

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
new file mode 100644
index 00000000000..e8ddbd1a25a
--- /dev/null
+++ b/storage/maria/lockman.c
@@ -0,0 +1,681 @@
+// TODO lock escalation, instant duration locks
+// automatically place S instead of LS if possible
+/*
+  TODO optimization: table locks - they have completely
+  different characteristics. long lists, few distinct resources -
+  slow to scan, [possibly] high retry rate
+*/
+/* Copyright (C) 2000 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include <my_global.h>
+#include <my_sys.h>
+#include <my_bit.h>
+#include <lf.h>
+#include "lockman.h"
+
+/*
+  Lock compatibility matrix.
+
+  It's asymmetric. Read it as "Somebody has the lock <value in the row
+  label>, can I set the lock <value in the column label> ?"
+
+  ') Though you can take LS lock while somebody has S lock, it makes no
+  sense - it's simpler to take S lock too.
+
+  ") Strictly speaking you can take LX lock while somebody has S lock.
+  But in this case you lock no rows, because all rows are locked by this
+  somebody. So we prefer to define that LX cannot be taken when S
+  exists. Same about LX and X.
+
+  1  - compatible
+  0  - incompatible
+  -1 - "impossible", so that we can assert the impossibility.
+*/
+static int lock_compatibility_matrix[10][10]=
+{ /* N    S   X  IS  IX  SIX LS  LX  SLX LSIX          */
+  {  -1,  1,  1,  1,  1,  1,  1,  1,  1,  1 }, /* N    */
+  {  -1,  1,  0,  1,  0,  0,  1,  0,  0,  0 }, /* S    */
+  {  -1,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* X    */
+  {  -1,  1,  0,  1,  1,  1,  1,  1,  1,  1 }, /* IS   */
+  {  -1,  0,  0,  1,  1,  0,  1,  1,  0,  1 }, /* IX   */
+  {  -1,  0,  0,  1,  0,  0,  1,  0,  0,  0 }, /* SIX  */
+  {  -1,  1,  0,  1,  0,  0,  1,  0,  0,  0 }, /* LS   */
+  {  -1,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* LX   */
+  {  -1,  0,  0,  0,  0,  0,  0,  0,  0,  0 }, /* SLX  */
+  {  -1,  0,  0,  1,  0,  0,  1,  0,  0,  0 }  /* LSIX */
+};
+
+/*
+  Lock combining matrix.
+
+  It's symmetric. Read it as "what lock level L is identical to the
+  set of two locks A and B"
+
+  One should never get N from it, we assert the impossibility
+*/
+static enum lock_type lock_combining_matrix[10][10]=
+{/*    N    S   X    IS    IX  SIX    LS    LX   SLX   LSIX         */
+  {    N,   S,  X,   IS,   IX, SIX,    S,  SLX, SLX,  SIX}, /* N    */
+  {    S,   S,  X,    S,  SIX, SIX,    S,  SLX, SLX,  SIX}, /* S    */
+  {    X,   X,  X,    X,    X,   X,    X,    X,   X,    X}, /* X    */
+  {   IS,   S,  X,   IS,   IX, SIX,   LS,   LX, SLX, LSIX}, /* IS   */
+  {   IX, SIX,  X,   IX,   IX, SIX, LSIX,   LX, SLX, LSIX}, /* IX   */
+  {  SIX, SIX,  X,  SIX,  SIX, SIX,  SIX,  SLX, SLX,  SIX}, /* SIX  */
+  {   LS,   S,  X,   LS, LSIX, SIX,   LS,   LX, SLX, LSIX}, /* LS   */
+  {   LX, SLX,  X,   LX,   LX, SLX,   LX,   LX, SLX,   LX}, /* LX   */
+  {  SLX, SLX,  X,  SLX,  SLX, SLX,  SLX,  SLX, SLX,  SLX}, /* SLX  */
+  { LSIX, SIX,  X, LSIX, LSIX, SIX, LSIX,   LX, SLX, LSIX}  /* LSIX */
+};
+
+#define REPEAT_ONCE_MORE                0
+#define OK_TO_PLACE_THE_LOCK            1
+#define OK_TO_PLACE_THE_REQUEST         2
+#define ALREADY_HAVE_THE_LOCK           4
+#define ALREADY_HAVE_THE_REQUEST        8
+#define PLACE_NEW_DISABLE_OLD          16
+#define REQUEST_NEW_DISABLE_OLD        32
+#define RESOURCE_WAS_UNLOCKED          64
+
+#define NEED_TO_WAIT (OK_TO_PLACE_THE_REQUEST | ALREADY_HAVE_THE_REQUEST |\
+                      REQUEST_NEW_DISABLE_OLD)
+#define ALREADY_HAVE (ALREADY_HAVE_THE_LOCK   | ALREADY_HAVE_THE_REQUEST)
+#define LOCK_UPGRADE (PLACE_NEW_DISABLE_OLD   | REQUEST_NEW_DISABLE_OLD)
+
+
+/*
+  the return codes for lockman_getlock
+
+  It's asymmetric. Read it as "I have the lock <value in the row label>,
+  what value should be returned for <value in the column label> ?"
+
+  0 means impossible combination (assert!)
+
+  Defines below help to preserve the table structure.
+  I/L/A values are self explanatory
+  x means the combination is possible (assert should not crash)
+    but cannot happen in row locks, only in table locks (S,X), or
+    lock escalations (LS,LX)
+*/
+#define I GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE
+#define L GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE
+#define A GOT_THE_LOCK
+#define x GOT_THE_LOCK
+static enum lockman_getlock_result getlock_result[10][10]=
+{/*    N    S   X    IS    IX  SIX    LS    LX   SLX   LSIX         */
+  {    0,   0,  0,    0,    0,   0,    0,    0,   0,    0}, /* N    */
+  {    0,   x,  0,    A,    0,   0,    x,    0,   0,    0}, /* S    */
+  {    0,   x,  x,    A,    A,   0,    x,    x,   0,    0}, /* X    */
+  {    0,   0,  0,    I,    0,   0,    0,    0,   0,    0}, /* IS   */
+  {    0,   0,  0,    I,    I,   0,    0,    0,   0,    0}, /* IX   */
+  {    0,   x,  0,    A,    I,   0,    x,    0,   0,    0}, /* SIX  */
+  {    0,   0,  0,    L,    0,   0,    x,    0,   0,    0}, /* LS   */
+  {    0,   0,  0,    L,    L,   0,    x,    x,   0,    0}, /* LX   */
+  {    0,   x,  0,    A,    L,   0,    x,    x,   0,    0}, /* SLX  */
+  {    0,   0,  0,    L,    I,   0,    x,    0,   0,    0}  /* LSIX */
+};
+#undef I
+#undef L
+#undef A
+#undef x
+
+LF_REQUIRE_PINS(4);
+
+typedef struct lockman_lock {
+  uint64 resource;
+  struct lockman_lock  *lonext;
+  intptr volatile link;
+  uint32 hashnr;
+//#warning TODO - remove hashnr from LOCK
+  uint16 loid;
+  uchar lock;              /* sizeof(uchar) <= sizeof(enum) */
+  uchar flags;
+} LOCK;
+
+#define IGNORE_ME               1
+#define UPGRADED                2
+
+typedef struct {
+  intptr volatile *prev;
+  LOCK *curr, *next;
+  LOCK *blocker, *upgrade_from;
+} CURSOR;
+
+#define PTR(V)      (LOCK *)((V) & (~(intptr)1))
+#define DELETED(V)  ((V) & 1)
+
+/*
+  NOTE
+    cursor is positioned in either case
+    pins[0..3] are used, they are NOT removed on return
+*/
+static int lockfind(LOCK * volatile *head, LOCK *node,
+                    CURSOR *cursor, LF_PINS *pins)
+{
+  uint32        hashnr, cur_hashnr;
+  uint64        resource, cur_resource;
+  intptr        link;
+  my_bool       cur_active, compatible, upgrading, prev_active;
+  enum lock_type lock, prev_lock, cur_lock;
+  uint16        loid, cur_loid;
+  int           upgraded_pairs, cur_flags, flags;
+
+  hashnr= node->hashnr;
+  resource= node->resource;
+  lock= node->lock;
+  loid= node->loid;
+  flags= node->flags;
+
+retry:
+  cursor->prev= (intptr *)head;
+  prev_lock= N;
+  cur_active= TRUE;
+  compatible= TRUE;
+  upgrading= FALSE;
+  cursor->blocker= cursor->upgrade_from= 0;
+  _lf_unpin(pins, 3);
+  upgraded_pairs= 0;
+  do {
+    cursor->curr= PTR(*cursor->prev);
+    _lf_pin(pins,1,cursor->curr);
+  } while(*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);
+  for (;;)
+  {
+    if (!cursor->curr)
+      break;
+    do {
+      link= cursor->curr->link;
+      cursor->next= PTR(link);
+      _lf_pin(pins, 0, cursor->next);
+    } while(link != cursor->curr->link && LF_BACKOFF);
+    cur_hashnr= cursor->curr->hashnr;
+    cur_resource= cursor->curr->resource;
+    cur_lock= cursor->curr->lock;
+    cur_loid= cursor->curr->loid;
+    cur_flags= cursor->curr->flags;
+    if (*cursor->prev != (intptr)cursor->curr)
+    {
+      LF_BACKOFF;
+      goto retry;
+    }
+    if (!DELETED(link))
+    {
+      if (cur_hashnr > hashnr ||
+          (cur_hashnr == hashnr && cur_resource >= resource))
+      {
+        if (cur_hashnr > hashnr || cur_resource > resource)
+        {
+          if (upgraded_pairs != 0)
+            goto retry;
+          break;
+        }
+        /* ok, we have a lock for this resource */
+        DBUG_ASSERT(lock_compatibility_matrix[prev_lock][cur_lock] >= 0);
+        DBUG_ASSERT(lock_compatibility_matrix[cur_lock][lock] >= 0);
+        if (cur_flags & UPGRADED)
+          upgraded_pairs++;
+        if ((cur_flags & IGNORE_ME) && ! (flags & IGNORE_ME))
+        {
+          DBUG_ASSERT(cur_active);
+          upgraded_pairs--;
+          if (cur_loid == loid)
+            cursor->upgrade_from= cursor->curr;
+        }
+        else
+        {
+          prev_active= cur_active;
+          cur_active&= lock_compatibility_matrix[prev_lock][cur_lock];
+          if (upgrading && !cur_active && upgraded_pairs == 0)
+            break;
+          if (prev_active && !cur_active)
+          {
+            cursor->blocker= cursor->curr;
+            _lf_pin(pins, 3, cursor->curr);
+          }
+          if (cur_loid == loid)
+          {
+            /* we already have a lock on this resource */
+            DBUG_ASSERT(lock_combining_matrix[cur_lock][lock] != N);
+            DBUG_ASSERT(!upgrading); /* can happen only once */
+            if (lock_combining_matrix[cur_lock][lock] == cur_lock)
+            {
+              /* new lock is compatible */
+              return cur_active ? ALREADY_HAVE_THE_LOCK
+                                : ALREADY_HAVE_THE_REQUEST;
+            }
+            /* not compatible, upgrading */
+            upgrading= TRUE;
+            cursor->upgrade_from= cursor->curr;
+          }
+          else
+          {
+            if (!lock_compatibility_matrix[cur_lock][lock])
+            {
+              compatible= FALSE;
+              cursor->blocker= cursor->curr;
+              _lf_pin(pins, 3, cursor->curr);
+            }
+            prev_lock= lock_combining_matrix[prev_lock][cur_lock];
+            DBUG_ASSERT(prev_lock != N);
+          }
+        }
+      }
+      cursor->prev= &(cursor->curr->link);
+      _lf_pin(pins, 2, cursor->curr);
+    }
+    else
+    {
+      if (my_atomic_casptr((void **)cursor->prev,
+                           (void **)&cursor->curr, cursor->next))
+        _lf_alloc_free(pins, cursor->curr);
+      else
+      {
+        LF_BACKOFF;
+        goto retry;
+      }
+    }
+    cursor->curr= cursor->next;
+    _lf_pin(pins, 1, cursor->curr);
+  }
+  /*
+    either the end of lock list - no more locks for this resource,
+    or upgrading and the end of active lock list
+  */
+  if (upgrading)
+  {
+    if (compatible)
+      return PLACE_NEW_DISABLE_OLD;
+    else
+      return REQUEST_NEW_DISABLE_OLD;
+  }
+  if (cur_active && compatible)
+  {
+    /*
+      either no locks for this resource or all are compatible.
+      ok to place the lock in any case.
+    */
+    return prev_lock == N ? RESOURCE_WAS_UNLOCKED
+                          : OK_TO_PLACE_THE_LOCK;
+  }
+  /* we have a lock conflict. ok to place a lock request. And wait */
+  return OK_TO_PLACE_THE_REQUEST;
+}
+
+/*
+  NOTE
+    it uses pins[0..3], on return pins 0..2 are removed, pin 3 (blocker) stays
+*/
+static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
+                      LOCK **blocker)
+{
+  CURSOR         cursor;
+  int            res;
+
+  do
+  {
+    res= lockfind(head, node, &cursor, pins);
+    DBUG_ASSERT(res != ALREADY_HAVE_THE_REQUEST);
+    if (!(res & ALREADY_HAVE))
+    {
+      if (res & LOCK_UPGRADE)
+      {
+        node->flags|= UPGRADED;
+        node->lock= lock_combining_matrix[cursor.upgrade_from->lock][node->lock];
+      }
+      node->link= (intptr)cursor.curr;
+      DBUG_ASSERT(node->link != (intptr)node);
+      DBUG_ASSERT(cursor.prev != &node->link);
+      if (!my_atomic_casptr((void **)cursor.prev, (void **)&cursor.curr, node))
+        res= REPEAT_ONCE_MORE;
+      if (res & LOCK_UPGRADE)
+        cursor.upgrade_from->flags|= IGNORE_ME;
+    }
+
+  } while (res == REPEAT_ONCE_MORE);
+  _lf_unpin(pins, 0);
+  _lf_unpin(pins, 1);
+  _lf_unpin(pins, 2);
+  /*
+    note that cursor.curr is NOT pinned on return.
+    this is ok as it's either a dummy node for initialize_bucket
+    and dummy nodes don't need pinning,
+    or it's a lock of the same transaction for lockman_getlock,
+    and it cannot be removed by another thread
+  */
+  *blocker= cursor.blocker ? cursor.blocker : cursor.curr;
+  return res;
+}
+
+/*
+  NOTE
+    it uses pins[0..3], on return pins 0..2 are removed, pin 3 (blocker) stays
+*/
+static int lockpeek(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
+                    LOCK **blocker)
+{
+  CURSOR         cursor;
+  int            res;
+
+  res= lockfind(head, node, &cursor, pins);
+
+  _lf_unpin(pins, 0);
+  _lf_unpin(pins, 1);
+  _lf_unpin(pins, 2);
+  if (blocker)
+    *blocker= cursor.blocker;
+  return res;
+}
+
+/*
+  NOTE
+    it uses pins[0..3], on return all pins are removed.
+
+    One _must_ have the lock (or request) to call this
+*/
+static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
+{
+  CURSOR cursor;
+  int res;
+
+  do
+  {
+    res= lockfind(head, node, &cursor, pins);
+    DBUG_ASSERT(res & ALREADY_HAVE);
+
+    if (cursor.upgrade_from)
+      cursor.upgrade_from->flags&= ~IGNORE_ME;
+
+    if (my_atomic_casptr((void **)&(cursor.curr->link),
+                         (void **)&cursor.next, 1+(char *)cursor.next))
+    {
+      if (my_atomic_casptr((void **)cursor.prev,
+                           (void **)&cursor.curr, cursor.next))
+        _lf_alloc_free(pins, cursor.curr);
+      else
+        lockfind(head, node, &cursor, pins);
+    }
+    else
+      res= REPEAT_ONCE_MORE;
+  } while (res == REPEAT_ONCE_MORE);
+  _lf_unpin(pins, 0);
+  _lf_unpin(pins, 1);
+  _lf_unpin(pins, 2);
+  _lf_unpin(pins, 3);
+  return res;
+}
+
+void lockman_init(LOCKMAN *lm, loid_to_lo_func *func, uint timeout)
+{
+  lf_alloc_init(&lm->alloc,sizeof(LOCK));
+  lf_dynarray_init(&lm->array, sizeof(LOCK **));
+  lm->size= 1;
+  lm->count= 0;
+  lm->loid_to_lo= func;
+  lm->lock_timeout= timeout;
+}
+
+void lockman_destroy(LOCKMAN *lm)
+{
+  LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
+  while (el)
+  {
+    intptr next= el->link;
+    if (el->hashnr & 1)
+      lf_alloc_real_free(&lm->alloc, el);
+    else
+      my_free((void *)el, MYF(0));
+    el= (LOCK *)next;
+  }
+  lf_alloc_destroy(&lm->alloc);
+  lf_dynarray_destroy(&lm->array);
+}
+
+/* TODO: optimize it */
+#define MAX_LOAD 1
+
+static void initialize_bucket(LOCKMAN *lm, LOCK * volatile *node,
+                              uint bucket, LF_PINS *pins)
+{
+  int res;
+  uint parent= my_clear_highest_bit(bucket);
+  LOCK *dummy= (LOCK *)my_malloc(sizeof(LOCK), MYF(MY_WME));
+  LOCK **tmp= 0, *cur;
+  LOCK * volatile *el= _lf_dynarray_lvalue(&lm->array, parent);
+
+  if (*el == NULL && bucket)
+    initialize_bucket(lm, el, parent, pins);
+  dummy->hashnr= my_reverse_bits(bucket);
+  dummy->loid= 0;
+  dummy->lock= X; /* doesn't matter, in fact */
+  dummy->resource= 0;
+  dummy->flags= 0;
+  res= lockinsert(el, dummy, pins, &cur);
+  DBUG_ASSERT(res & (ALREADY_HAVE_THE_LOCK | RESOURCE_WAS_UNLOCKED));
+  if (res & ALREADY_HAVE_THE_LOCK)
+  {
+    my_free((void *)dummy, MYF(0));
+    dummy= cur;
+  }
+  my_atomic_casptr((void **)node, (void **)&tmp, dummy);
+}
+
+static inline uint calc_hash(uint64 resource)
+{
+  const uchar *pos= (uchar *)&resource;
+  ulong nr1= 1, nr2= 4, i;
+  for (i= 0; i < sizeof(resource) ; i++, pos++)
+  {
+    nr1^= (ulong) ((((uint) nr1 & 63)+nr2) * ((uint)*pos)) + (nr1 << 8);
+    nr2+= 3;
+  }
+  return nr1 & INT_MAX32;
+}
+
+/*
+  RETURN
+    see enum lockman_getlock_result
+  NOTE
+    uses pins[0..3], they're removed on return
+*/
+enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
+                                            uint64 resource,
+                                            enum lock_type lock)
+{
+  int res;
+  uint csize, bucket, hashnr;
+  LOCK *node, * volatile *el, *blocker;
+  LF_PINS *pins= lo->pins;
+  enum lock_type old_lock;
+
+  DBUG_ASSERT(lo->loid);
+  lf_rwlock_by_pins(pins);
+  node= (LOCK *)_lf_alloc_new(pins);
+  node->flags= 0;
+  node->lock= lock;
+  node->loid= lo->loid;
+  node->resource= resource;
+  hashnr= calc_hash(resource);
+  bucket= hashnr % lm->size;
+  el= _lf_dynarray_lvalue(&lm->array, bucket);
+  if (*el == NULL)
+    initialize_bucket(lm, el, bucket, pins);
+  node->hashnr= my_reverse_bits(hashnr) | 1;
+  res= lockinsert(el, node, pins, &blocker);
+  if (res & ALREADY_HAVE)
+  {
+    old_lock= blocker->lock;
+    _lf_assert_unpin(pins, 3); /* unpin should not be needed */
+    _lf_alloc_free(pins, node);
+    lf_rwunlock_by_pins(pins);
+    res= getlock_result[old_lock][lock];
+    DBUG_ASSERT(res);
+    return res;
+  }
+  /* a new value was added to the hash */
+  csize= lm->size;
+  if ((my_atomic_add32(&lm->count, 1)+1.0) / csize > MAX_LOAD)
+    my_atomic_cas32(&lm->size, &csize, csize*2);
+  node->lonext= lo->all_locks;
+  lo->all_locks= node;
+  for ( ; res & NEED_TO_WAIT; res= lockpeek(el, node, pins, &blocker))
+  {
+    LOCK_OWNER *wait_for_lo;
+    ulonglong deadline;
+    struct timespec timeout;
+
+    _lf_assert_pin(pins, 3); /* blocker must be pinned here */
+    lf_rwunlock_by_pins(pins);
+
+    wait_for_lo= lm->loid_to_lo(blocker->loid);
+    /*
+      now, this is tricky. blocker is not necessarily a LOCK
+      we're waiting for. If it's compatible with what we want,
+      then we're waiting for a lock that blocker is waiting for
+      (see two places where blocker is set in lockfind)
+      In the latter case, let's "dereference" it
+    */
+    if (lock_compatibility_matrix[blocker->lock][lock])
+    {
+      blocker= wait_for_lo->all_locks;
+      lf_pin(pins, 3, blocker);
+      if (blocker != wait_for_lo->all_locks)
+      {
+        lf_rwlock_by_pins(pins);
+        continue;
+      }
+      wait_for_lo= wait_for_lo->waiting_for;
+    }
+
+    /*
+      note that the blocker transaction may have ended by now,
+      its LOCK_OWNER and short id were reused, so 'wait_for_lo' may point
+      to an unrelated - albeit valid - LOCK_OWNER
+    */
+    if (!wait_for_lo)
+    {
+      /* blocker transaction has ended, short id was released */
+      lf_rwlock_by_pins(pins);
+      continue;
+    }
+    /*
+      We lock a mutex - it may belong to a wrong LOCK_OWNER, but it must
+      belong to _some_ LOCK_OWNER. It means, we can never free() a LOCK_OWNER,
+      if there're other active LOCK_OWNERs.
+    */
+#warning race condition here
+    pthread_mutex_lock(wait_for_lo->mutex);
+    if (DELETED(blocker->link))
+    {
+      /*
+        blocker transaction was ended, or a savepoint that owned
+        the lock was rolled back. Either way - the lock was removed
+      */
+      pthread_mutex_unlock(wait_for_lo->mutex);
+      lf_rwlock_by_pins(pins);
+      continue;
+    }
+    /* yuck. waiting */
+    lo->waiting_for= wait_for_lo;
+
+    deadline= my_getsystime() + lm->lock_timeout * 10000;
+    timeout.tv_sec= deadline/10000000;
+    timeout.tv_nsec= (deadline % 10000000) * 100;
+    do
+    {
+      pthread_cond_timedwait(wait_for_lo->cond, wait_for_lo->mutex, &timeout);
+    } while (!DELETED(blocker->link) && my_getsystime() < deadline);
+    pthread_mutex_unlock(wait_for_lo->mutex);
+    lf_rwlock_by_pins(pins);
+    if (!DELETED(blocker->link))
+    {
+      /*
+        timeout.
+        note that we _don't_ release the lock request here.
+        Instead we're relying on the caller to abort the transaction,
+        and release all locks at once - see lockman_release_locks()
+      */
+      lf_rwunlock_by_pins(pins);
+      return DIDNT_GET_THE_LOCK;
+    }
+    lo->waiting_for= 0;
+  }
+  _lf_assert_unpin(pins, 3); /* unpin should not be needed */
+  lf_rwunlock_by_pins(pins);
+  return getlock_result[lock][lock];
+}
+
+/*
+  RETURN
+    0 - deleted
+    1 - didn't (not found)
+  NOTE
+    see lockdelete() for pin usage notes
+*/
+int lockman_release_locks(LOCKMAN *lm, LOCK_OWNER *lo)
+{
+  LOCK * volatile *el, *node;
+  uint bucket;
+  LF_PINS *pins= lo->pins;
+
+  pthread_mutex_lock(lo->mutex);
+  lf_rwlock_by_pins(pins);
+  for (node= lo->all_locks; node; node= node->lonext)
+  {
+    bucket= calc_hash(node->resource) % lm->size;
+    el= _lf_dynarray_lvalue(&lm->array, bucket);
+    if (*el == NULL)
+      initialize_bucket(lm, el, bucket, pins);
+    lockdelete(el, node, pins);
+    my_atomic_add32(&lm->count, -1);
+  }
+  lf_rwunlock_by_pins(pins);
+  lo->all_locks= 0;
+  /* now signal all waiters */
+  pthread_cond_broadcast(lo->cond);
+  pthread_mutex_unlock(lo->mutex);
+  return 0;
+}
+
+#ifdef MY_LF_EXTRA_DEBUG
+/*
+  NOTE
+    the function below is NOT thread-safe !!!
+*/
+static char *lock2str[]=
+{ "N", "S", "X", "IS", "IX", "SIX", "LS", "LX", "SLX", "LSIX" };
+void print_lockhash(LOCKMAN *lm)
+{
+  LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
+  printf("hash: size=%u count=%u\n", lm->size, lm->count);
+  while (el)
+  {
+    intptr next= el->link;
+    if (el->hashnr & 1)
+      printf("0x%08x { resource %llu, loid %u, lock %s",
+             el->hashnr, el->resource, el->loid, lock2str[el->lock]);
+    else
+    {
+      printf("0x%08x { dummy ", el->hashnr);
+      DBUG_ASSERT(el->resource == 0 && el->loid == 0 && el->lock == X);
+    }
+    if (el->flags & IGNORE_ME) printf(" IGNORE_ME");
+    if (el->flags & UPGRADED) printf(" UPGRADED");
+    printf("}\n");
+    el= (LOCK *)next;
+  }
+}
+#endif
+
-- 
cgit v1.2.1


From 12a55aeabc353fdc1c3829ddd8baacb142160c80 Mon Sep 17 00:00:00 2001
From: unknown <serg@janus.mylan>
Date: Wed, 18 Oct 2006 17:24:07 +0200
Subject: lock manager passed unit tests

storage/maria/trnman.c:
  comments
include/my_dbug.h:
  make DBUG_ASSERT always a statement
storage/maria/lockman.h:
  comments
include/lf.h:
  lf_pinbox - don't use a fixed-size purgatory.
mysys/lf_alloc-pin.c:
  lf_pinbox - don't use a fixed-size purgatory.
mysys/lf_hash.c:
  lf_pinbox - don't use a fixed-size purgatory.
storage/maria/lockman.c:
  removed IGNORE_ME/UPGDARED matching - it was wrong in the first place.
  updated for "lf_pinbox - don't use a fixed-size purgatory"
storage/maria/unittest/lockman-t.c:
  IGNORE_ME/UPGRADED pair counting bugtest.
  more tests
unittest/mysys/my_atomic-t.c:
  lf_pinbox - don't use a fixed-size purgatory.
---
 storage/maria/lockman.c | 199 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 144 insertions(+), 55 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index e8ddbd1a25a..1712f6f2221 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -1,4 +1,4 @@
-// TODO lock escalation, instant duration locks
+// TODO instant duration locks
 // automatically place S instead of LS if possible
 /*
   TODO optimization: table locks - they have completely
@@ -21,6 +21,94 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
+/*
+  Generic Lock Manager
+
+  Lock manager handles locks on "resources", a resource must be uniquely
+  identified by a 64-bit number. Lock manager itself does not imply
+  anything about the nature of a resource - it can be a row, a table, a
+  database, or just anything.
+
+  Locks belong to "lock owners". A Lock owner is uniquely identified by a
+  16-bit number. A function loid2lo must be provided by the application
+  that takes such a number as an argument and returns a LOCK_OWNER
+  structure.
+
+  Lock levels are completely defined by three tables. Lock compatibility
+  matrix specifies which locks can be held at the same time on a resource.
+  Lock combining matrix specifies what lock level has the same behaviour as
+  a pair of two locks of given levels. getlock_result matrix simplifies
+  intention locking and lock escalation for an application, basically it
+  defines which locks are intention locks and which locks are "loose"
+  locks.  It is only used to provide better diagnostics for the
+  application, lock manager itself does not differentiate between normal,
+  intention, and loose locks.
+
+  Internally lock manager is based on a lock-free hash, see lf_hash.c for
+  details.  All locks are stored in a hash, with a resource id as a search
+  key, so all locks for the same resource will be considered collisions and
+  will be put in a one (lock-free) linked list.  The main lock-handling
+  logic is in the inner loop that searches for a lock in such a linked
+  list - lockfind().
+
+  This works as follows. Locks generally are added to the end of the list
+  (with one exception, see below). When scanning the list it is always
+  possible to determine what locks are granted (active) and what locks are
+  waiting - first lock is obviously active, the second is active if it's
+  compatible with the first, and so on, a lock is active if it's compatible
+  with all previous locks and all locks before it are also active.
+  To calculate the "compatible with all previous locks" all locks are
+  accumulated in prev_lock variable using lock_combining_matrix.
+
+  Lock upgrades: when a thread that has a lock on a given resource,
+  requests a new lock on the same resource and the old lock is not enough
+  to satisfy new lock requirements (which is defined by
+  lock_combining_matrix[old_lock][new_lock] != old_lock), a new lock is
+  placed in the list. Depending on other locks it is immediately active or
+  it will wait for other locks. Here's an exception to "locks are added
+  to the end" rule - upgraded locks are added after the last active lock
+  but before all waiting locks. Old lock (the one we upgraded from) is
+  not removed from the list, indeed we may need to return to it later if
+  the new lock was in a savepoint that gets rolled back. So old lock is
+  marked as "ignored" (IGNORE_ME flag). New lock gets an UPGRADED flag.
+
+  Loose locks add an important exception to the above. Loose locks do not
+  always commute with other locks. In the list IX-LS both locks are active,
+  while in the LS-IX list only the first lock is active. This creates a
+  problem in lock upgrades. If the list was IX-LS and the owner of the
+  first lock wants to place LS lock (which can be immediately granted), the
+  IX lock is upgraded to LSIX and the list becomes IX-LS-LSIX, which,
+  according to the lock compatibility matrix means that the last lock is
+  waiting - of course it all happened because IX and LS were swapped and
+  they don't commute. To work around this there's ACTIVE flag which is set
+  in every lock that never waited (was placed active), and this flag
+  overrides "compatible with all previous locks" rule.
+
+  When a lock is placed to the end of the list it's either compatible with
+  all locks and all locks are active - new lock becomes active at once, or
+  it conflicts with some of the locks, in this case in the 'blocker'
+  variable a conflicting lock is returned and the calling thread waits on a
+  pthread condition in the LOCK_OWNER structure of the owner of the
+  conflicting lock. Or a new lock is compatible with all locks, but some
+  existing locks are not compatible with previous locks (example: request IS,
+  when the list is S-IX) - that is not all locks are active. In this case a
+  first waiting lock is returned in the 'blocker' variable,
+  lockman_getlock() notices that a "blocker" does not conflict with the
+  requested lock, and "dereferences" it, to find the lock that it's waiting
+  on.  The calling thread than begins to wait on the same lock.
+
+  To better support table-row relations where one needs to lock the table
+  with an intention lock before locking the row, extended diagnostics is
+  provided.  When an intention lock (presumably on a table) is granted,
+  lockman_getlock() returns one of GOT_THE_LOCK (no need to lock the row,
+  perhaps the thread already has a normal lock on this table),
+  GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE (need to lock the row, as usual),
+  GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE (only need to check
+  whether it's possible to lock the row, but no need to lock it - perhaps
+  the thread has a loose lock on this table). This is defined by
+  getlock_result[] table.
+*/
+
 #include <my_global.h>
 #include <my_sys.h>
 #include <my_bit.h>
@@ -36,11 +124,6 @@
   ') Though you can take LS lock while somebody has S lock, it makes no
   sense - it's simpler to take S lock too.
 
-  ") Strictly speaking you can take LX lock while somebody has S lock.
-  But in this case you lock no rows, because all rows are locked by this
-  somebody. So we prefer to define that LX cannot be taken when S
-  exists. Same about LX and X.
-
   1  - compatible
   0  - incompatible
   -1 - "impossible", so that we can assert the impossibility.
@@ -107,8 +190,8 @@ static enum lock_type lock_combining_matrix[10][10]=
   Defines below help to preserve the table structure.
   I/L/A values are self explanatory
   x means the combination is possible (assert should not crash)
-    but cannot happen in row locks, only in table locks (S,X), or
-    lock escalations (LS,LX)
+    but it cannot happen in row locks, only in table locks (S,X),
+    or lock escalations (LS,LX)
 */
 #define I GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE
 #define L GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE
@@ -138,8 +221,7 @@ typedef struct lockman_lock {
   uint64 resource;
   struct lockman_lock  *lonext;
   intptr volatile link;
-  uint32 hashnr;
-//#warning TODO - remove hashnr from LOCK
+  uint32 hashnr; // TODO - remove hashnr from LOCK
   uint16 loid;
   uchar lock;              /* sizeof(uchar) <= sizeof(enum) */
   uchar flags;
@@ -147,6 +229,7 @@ typedef struct lockman_lock {
 
 #define IGNORE_ME               1
 #define UPGRADED                2
+#define ACTIVE                  4
 
 typedef struct {
   intptr volatile *prev;
@@ -171,7 +254,7 @@ static int lockfind(LOCK * volatile *head, LOCK *node,
   my_bool       cur_active, compatible, upgrading, prev_active;
   enum lock_type lock, prev_lock, cur_lock;
   uint16        loid, cur_loid;
-  int           upgraded_pairs, cur_flags, flags;
+  int           cur_flags, flags;
 
   hashnr= node->hashnr;
   resource= node->resource;
@@ -187,7 +270,6 @@ retry:
   upgrading= FALSE;
   cursor->blocker= cursor->upgrade_from= 0;
   _lf_unpin(pins, 3);
-  upgraded_pairs= 0;
   do {
     cursor->curr= PTR(*cursor->prev);
     _lf_pin(pins,1,cursor->curr);
@@ -217,28 +299,24 @@ retry:
           (cur_hashnr == hashnr && cur_resource >= resource))
       {
         if (cur_hashnr > hashnr || cur_resource > resource)
-        {
-          if (upgraded_pairs != 0)
-            goto retry;
           break;
-        }
         /* ok, we have a lock for this resource */
         DBUG_ASSERT(lock_compatibility_matrix[prev_lock][cur_lock] >= 0);
         DBUG_ASSERT(lock_compatibility_matrix[cur_lock][lock] >= 0);
-        if (cur_flags & UPGRADED)
-          upgraded_pairs++;
         if ((cur_flags & IGNORE_ME) && ! (flags & IGNORE_ME))
         {
           DBUG_ASSERT(cur_active);
-          upgraded_pairs--;
           if (cur_loid == loid)
             cursor->upgrade_from= cursor->curr;
         }
         else
         {
           prev_active= cur_active;
-          cur_active&= lock_compatibility_matrix[prev_lock][cur_lock];
-          if (upgrading && !cur_active && upgraded_pairs == 0)
+          if (cur_flags & ACTIVE)
+            DBUG_ASSERT(prev_active == TRUE);
+          else
+            cur_active&= lock_compatibility_matrix[prev_lock][cur_lock];
+          if (upgrading && !cur_active)
             break;
           if (prev_active && !cur_active)
           {
@@ -253,8 +331,14 @@ retry:
             if (lock_combining_matrix[cur_lock][lock] == cur_lock)
             {
               /* new lock is compatible */
-              return cur_active ? ALREADY_HAVE_THE_LOCK
-                                : ALREADY_HAVE_THE_REQUEST;
+              if (cur_active)
+              {
+                cursor->blocker= cursor->curr;  /* loose-locks! */
+                _lf_unpin(pins, 3);             /* loose-locks! */
+                return ALREADY_HAVE_THE_LOCK;
+              }
+              else
+                return ALREADY_HAVE_THE_REQUEST;
             }
             /* not compatible, upgrading */
             upgrading= TRUE;
@@ -268,9 +352,9 @@ retry:
               cursor->blocker= cursor->curr;
               _lf_pin(pins, 3, cursor->curr);
             }
-            prev_lock= lock_combining_matrix[prev_lock][cur_lock];
-            DBUG_ASSERT(prev_lock != N);
           }
+          prev_lock= lock_combining_matrix[prev_lock][cur_lock];
+          DBUG_ASSERT(prev_lock != N);
         }
       }
       cursor->prev= &(cursor->curr->link);
@@ -335,6 +419,10 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
         node->flags|= UPGRADED;
         node->lock= lock_combining_matrix[cursor.upgrade_from->lock][node->lock];
       }
+      if (!(res & NEED_TO_WAIT))
+        node->flags|= ACTIVE;
+      else
+        node->flags&= ~ACTIVE; /* if we're retrying on REPEAT_ONCE_MORE */
       node->link= (intptr)cursor.curr;
       DBUG_ASSERT(node->link != (intptr)node);
       DBUG_ASSERT(cursor.prev != &node->link);
@@ -349,13 +437,13 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
   _lf_unpin(pins, 1);
   _lf_unpin(pins, 2);
   /*
-    note that cursor.curr is NOT pinned on return.
-    this is ok as it's either a dummy node for initialize_bucket
+    note that blocker is not necessarily pinned here (when it's == curr).
+    this is ok as it's either a dummy node then for initialize_bucket
     and dummy nodes don't need pinning,
     or it's a lock of the same transaction for lockman_getlock,
     and it cannot be removed by another thread
   */
-  *blocker= cursor.blocker ? cursor.blocker : cursor.curr;
+  *blocker= cursor.blocker;
   return res;
 }
 
@@ -419,7 +507,7 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
 
 void lockman_init(LOCKMAN *lm, loid_to_lo_func *func, uint timeout)
 {
-  lf_alloc_init(&lm->alloc,sizeof(LOCK));
+  lf_alloc_init(&lm->alloc,sizeof(LOCK), offsetof(LOCK,lonext));
   lf_dynarray_init(&lm->array, sizeof(LOCK **));
   lm->size= 1;
   lm->count= 0;
@@ -516,13 +604,13 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
   res= lockinsert(el, node, pins, &blocker);
   if (res & ALREADY_HAVE)
   {
+    int r;
     old_lock= blocker->lock;
-    _lf_assert_unpin(pins, 3); /* unpin should not be needed */
     _lf_alloc_free(pins, node);
     lf_rwunlock_by_pins(pins);
-    res= getlock_result[old_lock][lock];
-    DBUG_ASSERT(res);
-    return res;
+    r= getlock_result[old_lock][lock];
+    DBUG_ASSERT(r);
+    return r;
   }
   /* a new value was added to the hash */
   csize= lm->size;
@@ -537,9 +625,8 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
     struct timespec timeout;
 
     _lf_assert_pin(pins, 3); /* blocker must be pinned here */
-    lf_rwunlock_by_pins(pins);
-
     wait_for_lo= lm->loid_to_lo(blocker->loid);
+
     /*
       now, this is tricky. blocker is not necessarily a LOCK
       we're waiting for. If it's compatible with what we want,
@@ -550,12 +637,9 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
     if (lock_compatibility_matrix[blocker->lock][lock])
     {
       blocker= wait_for_lo->all_locks;
-      lf_pin(pins, 3, blocker);
+      _lf_pin(pins, 3, blocker);
       if (blocker != wait_for_lo->all_locks)
-      {
-        lf_rwlock_by_pins(pins);
         continue;
-      }
       wait_for_lo= wait_for_lo->waiting_for;
     }
 
@@ -565,11 +649,11 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
       to an unrelated - albeit valid - LOCK_OWNER
     */
     if (!wait_for_lo)
-    {
-      /* blocker transaction has ended, short id was released */
-      lf_rwlock_by_pins(pins);
       continue;
-    }
+
+    lo->waiting_for= wait_for_lo;
+    lf_rwunlock_by_pins(pins);
+
     /*
       We lock a mutex - it may belong to a wrong LOCK_OWNER, but it must
       belong to _some_ LOCK_OWNER. It means, we can never free() a LOCK_OWNER,
@@ -587,9 +671,8 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
       lf_rwlock_by_pins(pins);
       continue;
     }
-    /* yuck. waiting */
-    lo->waiting_for= wait_for_lo;
 
+    /* yuck. waiting */
     deadline= my_getsystime() + lm->lock_timeout * 10000;
     timeout.tv_sec= deadline/10000000;
     timeout.tv_nsec= (deadline % 10000000) * 100;
@@ -607,11 +690,12 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
         Instead we're relying on the caller to abort the transaction,
         and release all locks at once - see lockman_release_locks()
       */
+      _lf_unpin(pins, 3);
       lf_rwunlock_by_pins(pins);
       return DIDNT_GET_THE_LOCK;
     }
-    lo->waiting_for= 0;
   }
+  lo->waiting_for= 0;
   _lf_assert_unpin(pins, 3); /* unpin should not be needed */
   lf_rwunlock_by_pins(pins);
   return getlock_result[lock][lock];
@@ -626,14 +710,15 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
 */
 int lockman_release_locks(LOCKMAN *lm, LOCK_OWNER *lo)
 {
-  LOCK * volatile *el, *node;
+  LOCK * volatile *el, *node, *next;
   uint bucket;
   LF_PINS *pins= lo->pins;
 
   pthread_mutex_lock(lo->mutex);
   lf_rwlock_by_pins(pins);
-  for (node= lo->all_locks; node; node= node->lonext)
+  for (node= lo->all_locks; node; node= next)
   {
+    next= node->lonext;
     bucket= calc_hash(node->resource) % lm->size;
     el= _lf_dynarray_lvalue(&lm->array, bucket);
     if (*el == NULL)
@@ -650,12 +735,12 @@ int lockman_release_locks(LOCKMAN *lm, LOCK_OWNER *lo)
 }
 
 #ifdef MY_LF_EXTRA_DEBUG
+static char *lock2str[]=
+{ "N", "S", "X", "IS", "IX", "SIX", "LS", "LX", "SLX", "LSIX" };
 /*
   NOTE
     the function below is NOT thread-safe !!!
 */
-static char *lock2str[]=
-{ "N", "S", "X", "IS", "IX", "SIX", "LS", "LX", "SLX", "LSIX" };
 void print_lockhash(LOCKMAN *lm)
 {
   LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
@@ -664,17 +749,21 @@ void print_lockhash(LOCKMAN *lm)
   {
     intptr next= el->link;
     if (el->hashnr & 1)
+    {
       printf("0x%08x { resource %llu, loid %u, lock %s",
              el->hashnr, el->resource, el->loid, lock2str[el->lock]);
+      if (el->flags & IGNORE_ME) printf(" IGNORE_ME");
+      if (el->flags & UPGRADED) printf(" UPGRADED");
+      if (el->flags & ACTIVE) printf(" ACTIVE");
+      if (DELETED(next)) printf(" ***DELETED***");
+      printf("}\n");
+    }
     else
     {
-      printf("0x%08x { dummy ", el->hashnr);
+      /*printf("0x%08x { dummy }\n", el->hashnr);*/
       DBUG_ASSERT(el->resource == 0 && el->loid == 0 && el->lock == X);
     }
-    if (el->flags & IGNORE_ME) printf(" IGNORE_ME");
-    if (el->flags & UPGRADED) printf(" UPGRADED");
-    printf("}\n");
-    el= (LOCK *)next;
+    el= PTR(next);
   }
 }
 #endif
-- 
cgit v1.2.1


From aea73116c14da8e946422de8e49c93acc85817d0 Mon Sep 17 00:00:00 2001
From: unknown <serg@janus.mylan>
Date: Thu, 19 Oct 2006 12:21:30 +0200
Subject: post-review fixes (style)

include/lf.h:
  comments
---
 storage/maria/lockman.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 1712f6f2221..b37c31fb52c 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -5,7 +5,7 @@
   different characteristics. long lists, few distinct resources -
   slow to scan, [possibly] high retry rate
 */
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -272,7 +272,7 @@ retry:
   _lf_unpin(pins, 3);
   do {
     cursor->curr= PTR(*cursor->prev);
-    _lf_pin(pins,1,cursor->curr);
+    _lf_pin(pins, 1, cursor->curr);
   } while(*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);
   for (;;)
   {
@@ -507,7 +507,7 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
 
 void lockman_init(LOCKMAN *lm, loid_to_lo_func *func, uint timeout)
 {
-  lf_alloc_init(&lm->alloc,sizeof(LOCK), offsetof(LOCK,lonext));
+  lf_alloc_init(&lm->alloc, sizeof(LOCK), offsetof(LOCK, lonext));
   lf_dynarray_init(&lm->array, sizeof(LOCK **));
   lm->size= 1;
   lm->count= 0;
@@ -744,7 +744,7 @@ static char *lock2str[]=
 void print_lockhash(LOCKMAN *lm)
 {
   LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
-  printf("hash: size=%u count=%u\n", lm->size, lm->count);
+  printf("hash: size:%u count:%u\n", lm->size, lm->count);
   while (el)
   {
     intptr next= el->link;
-- 
cgit v1.2.1


From fb818dd7b0be3b4facd159de14bc3d9afcbcf16e Mon Sep 17 00:00:00 2001
From: unknown <serg@janus.mylan>
Date: Fri, 20 Oct 2006 14:02:18 +0200
Subject: more post-review fixes - comments, renames, error checks in unit
 tests concurrency bug in lock manager

include/my_global.h:
  compile-time assert macro
mysys/my_atomic.c:
  use compile_time_assert() macro
storage/maria/lockman.c:
  bug in concurrent lockdelete (with retries)
storage/maria/trnman.c:
  more post-review fixes - comments, renames
storage/maria/trnman.h:
  more post-review fixes - comments
storage/maria/unittest/lockman-t.c:
  friendlier error checks
storage/maria/unittest/trnman-t.c:
  friendlier error checks
---
 storage/maria/lockman.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index b37c31fb52c..937c61021cc 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -421,13 +421,14 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
       }
       if (!(res & NEED_TO_WAIT))
         node->flags|= ACTIVE;
-      else
-        node->flags&= ~ACTIVE; /* if we're retrying on REPEAT_ONCE_MORE */
       node->link= (intptr)cursor.curr;
       DBUG_ASSERT(node->link != (intptr)node);
       DBUG_ASSERT(cursor.prev != &node->link);
       if (!my_atomic_casptr((void **)cursor.prev, (void **)&cursor.curr, node))
+      {
         res= REPEAT_ONCE_MORE;
+        node->flags&= ~ACTIVE;
+      }
       if (res & LOCK_UPGRADE)
         cursor.upgrade_from->flags|= IGNORE_ME;
     }
@@ -496,7 +497,11 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
         lockfind(head, node, &cursor, pins);
     }
     else
+    {
       res= REPEAT_ONCE_MORE;
+      if (cursor.upgrade_from) /* to satisfy the assert in lockfind */
+        cursor.upgrade_from->flags|= IGNORE_ME;
+    }
   } while (res == REPEAT_ONCE_MORE);
   _lf_unpin(pins, 0);
   _lf_unpin(pins, 1);
@@ -744,7 +749,7 @@ static char *lock2str[]=
 void print_lockhash(LOCKMAN *lm)
 {
   LOCK *el= *(LOCK **)_lf_dynarray_lvalue(&lm->array, 0);
-  printf("hash: size:%u count:%u\n", lm->size, lm->count);
+  printf("hash: size %u count %u\n", lm->size, lm->count);
   while (el)
   {
     intptr next= el->link;
-- 
cgit v1.2.1


From 96d3604d99f366903c0e3e543858957211071d5a Mon Sep 17 00:00:00 2001
From: unknown <serg@janus.mylan>
Date: Thu, 9 Nov 2006 16:20:40 +0100
Subject: lock manager optimized for table locks

storage/maria/unittest/lockman1-t.c:
  New BitKeeper file ``storage/maria/unittest/lockman1-t.c''
storage/maria/tablockman.c:
  New BitKeeper file ``storage/maria/tablockman.c''
storage/maria/tablockman.h:
  New BitKeeper file ``storage/maria/tablockman.h''
storage/maria/unittest/lockman2-t.c:
  New BitKeeper file ``storage/maria/unittest/lockman2-t.c''
---
 storage/maria/lockman.c | 55 +++++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 937c61021cc..31867d3903d 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -1,10 +1,6 @@
+// TODO - allocate everything from dynarrays !!! (benchmark)
 // TODO instant duration locks
 // automatically place S instead of LS if possible
-/*
-  TODO optimization: table locks - they have completely
-  different characteristics. long lists, few distinct resources -
-  slow to scan, [possibly] high retry rate
-*/
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -68,9 +64,9 @@
   it will wait for other locks. Here's an exception to "locks are added
   to the end" rule - upgraded locks are added after the last active lock
   but before all waiting locks. Old lock (the one we upgraded from) is
-  not removed from the list, indeed we may need to return to it later if
-  the new lock was in a savepoint that gets rolled back. So old lock is
-  marked as "ignored" (IGNORE_ME flag). New lock gets an UPGRADED flag.
+  not removed from the list, indeed it may be needed if the new lock was
+  in a savepoint that gets rolled back. So old lock is marked as "ignored"
+  (IGNORE_ME flag). New lock gets an UPGRADED flag.
 
   Loose locks add an important exception to the above. Loose locks do not
   always commute with other locks. In the list IX-LS both locks are active,
@@ -90,12 +86,12 @@
   variable a conflicting lock is returned and the calling thread waits on a
   pthread condition in the LOCK_OWNER structure of the owner of the
   conflicting lock. Or a new lock is compatible with all locks, but some
-  existing locks are not compatible with previous locks (example: request IS,
+  existing locks are not compatible with each other (example: request IS,
   when the list is S-IX) - that is not all locks are active. In this case a
-  first waiting lock is returned in the 'blocker' variable,
-  lockman_getlock() notices that a "blocker" does not conflict with the
-  requested lock, and "dereferences" it, to find the lock that it's waiting
-  on.  The calling thread than begins to wait on the same lock.
+  first waiting lock is returned in the 'blocker' variable, lockman_getlock()
+  notices that a "blocker" does not conflict with the requested lock, and
+  "dereferences" it, to find the lock that it's waiting on.  The calling
+  thread than begins to wait on the same lock.
 
   To better support table-row relations where one needs to lock the table
   with an intention lock before locking the row, extended diagnostics is
@@ -107,6 +103,10 @@
   whether it's possible to lock the row, but no need to lock it - perhaps
   the thread has a loose lock on this table). This is defined by
   getlock_result[] table.
+
+  TODO optimization: table locks - they have completely
+  different characteristics. long lists, few distinct resources -
+  slow to scan, [possibly] high retry rate
 */
 
 #include <my_global.h>
@@ -316,7 +316,7 @@ retry:
             DBUG_ASSERT(prev_active == TRUE);
           else
             cur_active&= lock_compatibility_matrix[prev_lock][cur_lock];
-          if (upgrading && !cur_active)
+          if (upgrading && !cur_active /*&& !(cur_flags & UPGRADED)*/)
             break;
           if (prev_active && !cur_active)
           {
@@ -327,7 +327,7 @@ retry:
           {
             /* we already have a lock on this resource */
             DBUG_ASSERT(lock_combining_matrix[cur_lock][lock] != N);
-            DBUG_ASSERT(!upgrading); /* can happen only once */
+            DBUG_ASSERT(!upgrading || (flags & IGNORE_ME));
             if (lock_combining_matrix[cur_lock][lock] == cur_lock)
             {
               /* new lock is compatible */
@@ -380,7 +380,7 @@ retry:
   */
   if (upgrading)
   {
-    if (compatible)
+    if (compatible /*&& prev_active*/)
       return PLACE_NEW_DISABLE_OLD;
     else
       return REQUEST_NEW_DISABLE_OLD;
@@ -431,6 +431,9 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
       }
       if (res & LOCK_UPGRADE)
         cursor.upgrade_from->flags|= IGNORE_ME;
+#warning is this OK ? if a reader has already read upgrade_from, \
+         it may find it conflicting with node :(
+//#error another bug - see the last test from test_lockman_simple()
     }
 
   } while (res == REPEAT_ONCE_MORE);
@@ -439,8 +442,8 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
   _lf_unpin(pins, 2);
   /*
     note that blocker is not necessarily pinned here (when it's == curr).
-    this is ok as it's either a dummy node then for initialize_bucket
-    and dummy nodes don't need pinning,
+    this is ok as in such a case it's either a dummy node for
+    initialize_bucket() and dummy nodes don't need pinning,
     or it's a lock of the same transaction for lockman_getlock,
     and it cannot be removed by another thread
   */
@@ -484,9 +487,15 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
     res= lockfind(head, node, &cursor, pins);
     DBUG_ASSERT(res & ALREADY_HAVE);
 
-    if (cursor.upgrade_from)
-      cursor.upgrade_from->flags&= ~IGNORE_ME;
-
+    /*
+      XXX this does not work with savepoints, as old lock is left ignored.
+      It cannot be unignored, as would basically mean moving the lock back
+      in the lock chain (from upgraded). And the latter is not allowed -
+      because it breaks list scanning. So old ignored lock must be deleted,
+      new - same - lock must be installed right after the lock we're deleting,
+      then we can delete. Good news is - this is only required when rolling
+      back a savepoint.
+    */
     if (my_atomic_casptr((void **)&(cursor.curr->link),
                          (void **)&cursor.next, 1+(char *)cursor.next))
     {
@@ -497,11 +506,7 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
         lockfind(head, node, &cursor, pins);
     }
     else
-    {
       res= REPEAT_ONCE_MORE;
-      if (cursor.upgrade_from) /* to satisfy the assert in lockfind */
-        cursor.upgrade_from->flags|= IGNORE_ME;
-    }
   } while (res == REPEAT_ONCE_MORE);
   _lf_unpin(pins, 0);
   _lf_unpin(pins, 1);
-- 
cgit v1.2.1


From 41f890bc98fe26128ab18737e4acc846db09b74f Mon Sep 17 00:00:00 2001
From: unknown <serg@janus.mylan>
Date: Sun, 12 Nov 2006 14:44:12 +0100
Subject: minor unittest fixes

storage/maria/lockman.c:
  restore removed lines
storage/maria/unittest/lockman2-t.c:
  fix the plan
---
 storage/maria/lockman.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 31867d3903d..7a6b97b3d51 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -103,10 +103,6 @@
   whether it's possible to lock the row, but no need to lock it - perhaps
   the thread has a loose lock on this table). This is defined by
   getlock_result[] table.
-
-  TODO optimization: table locks - they have completely
-  different characteristics. long lists, few distinct resources -
-  slow to scan, [possibly] high retry rate
 */
 
 #include <my_global.h>
@@ -487,6 +483,9 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
     res= lockfind(head, node, &cursor, pins);
     DBUG_ASSERT(res & ALREADY_HAVE);
 
+    if (cursor.upgrade_from)
+      cursor.upgrade_from->flags&= ~IGNORE_ME;
+
     /*
       XXX this does not work with savepoints, as old lock is left ignored.
       It cannot be unignored, as would basically mean moving the lock back
@@ -506,7 +505,11 @@ static int lockdelete(LOCK * volatile *head, LOCK *node, LF_PINS *pins)
         lockfind(head, node, &cursor, pins);
     }
     else
+    {
       res= REPEAT_ONCE_MORE;
+      if (cursor.upgrade_from)
+        cursor.upgrade_from->flags|= IGNORE_ME;
+    }
   } while (res == REPEAT_ONCE_MORE);
   _lf_unpin(pins, 0);
   _lf_unpin(pins, 1);
-- 
cgit v1.2.1


From c86be6303bbc9d85c564876c1f9507ab634b442b Mon Sep 17 00:00:00 2001
From: unknown <guilhem@gbichot2.(none)>
Date: Thu, 30 Nov 2006 15:43:15 +0100
Subject: Maria - fixes for gcc -ansi (no //)

storage/maria/lockman.c:
  no //
storage/maria/trnman.c:
  no //
---
 storage/maria/lockman.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 7a6b97b3d51..54ea95c6b61 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -1,6 +1,6 @@
-// TODO - allocate everything from dynarrays !!! (benchmark)
-// TODO instant duration locks
-// automatically place S instead of LS if possible
+#warning TODO - allocate everything from dynarrays !!! (benchmark)
+#warning TODO instant duration locks
+#warning automatically place S instead of LS if possible
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -217,7 +217,8 @@ typedef struct lockman_lock {
   uint64 resource;
   struct lockman_lock  *lonext;
   intptr volatile link;
-  uint32 hashnr; // TODO - remove hashnr from LOCK
+  uint32 hashnr;
+#warning TODO - remove hashnr from LOCK
   uint16 loid;
   uchar lock;              /* sizeof(uchar) <= sizeof(enum) */
   uchar flags;
@@ -429,7 +430,7 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
         cursor.upgrade_from->flags|= IGNORE_ME;
 #warning is this OK ? if a reader has already read upgrade_from, \
          it may find it conflicting with node :(
-//#error another bug - see the last test from test_lockman_simple()
+#warning another bug - see the last test from test_lockman_simple()
     }
 
   } while (res == REPEAT_ONCE_MORE);
-- 
cgit v1.2.1


From ad29d5520b1ba379a75adc447f301851ff4588a4 Mon Sep 17 00:00:00 2001
From: unknown <guilhem@gbichot3.local>
Date: Thu, 7 Dec 2006 15:23:50 +0100
Subject: Maria - fix for "statement with no effect" warning

mysys/lf_hash.c:
  fix for "statement with no effect" warning
storage/maria/lockman.c:
  fix for "statement with no effect" warning
---
 storage/maria/lockman.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 54ea95c6b61..7672fadb068 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -287,7 +287,7 @@ retry:
     cur_flags= cursor->curr->flags;
     if (*cursor->prev != (intptr)cursor->curr)
     {
-      LF_BACKOFF;
+      (void)LF_BACKOFF;
       goto retry;
     }
     if (!DELETED(link))
@@ -364,7 +364,7 @@ retry:
         _lf_alloc_free(pins, cursor->curr);
       else
       {
-        LF_BACKOFF;
+        (void)LF_BACKOFF;
         goto retry;
       }
     }
-- 
cgit v1.2.1


From 7412f0fa0cd498f06fe04966a6f6161e8b32d0a2 Mon Sep 17 00:00:00 2001
From: unknown <monty@mysql.com/narttu.mysql.fi>
Date: Fri, 26 Jan 2007 13:32:02 +0200
Subject: After merge fixes Removed compiler warnings Fixed clashing function
 name in maria Disable maria tests from MySQL level for now

BitKeeper/deleted/.del-ha_maria.cc:
  Rename: libmysqld/ha_maria.cc -> BitKeeper/deleted/.del-ha_maria.cc
BitKeeper/etc/ignore:
  added libmysqld/ha_maria.cc
  ---
  added storage/maria/unittest/maria_control unittest/maria_control
  ---
  added *.Tpo
  ---
  added unittest/page_cache_test_file_1
  ---
  added unittest/pagecache_debug.log
  ---
  added unittest/mysys/mf_pagecache_consist_1k-t-big unittest/mysys/mf_pagecache_consist_1kHC-t-big unittest/mysys/mf_pagecache_consist_1kRD-t-big unittest/mysys/mf_pagecache_consist_1kWR-t-big unittest/mysys/mf_pagecache_consist_64k-t-big unittest/mysys/mf_pagecache_consist_64kHC-t-big unittest/mysys/mf_pagecache_consist_64kRD-t-big unittest/mysys/mf_pagecache_consist_64kWR-t-big
  ---
  added unittest/mysys/mf_pagecache_single_64k-t-big
Makefile.am:
  Don't run 'test-unit' by default (takes too long time)
client/mysqldump.c:
  Fixed compiler warning
include/lf.h:
  Remove compiler warnings about not used require_pins constant
include/pagecache.h:
  LSN should be of type ulonglong
  (This fixes some compiler warnings)
mysql-test/r/events_logs_tests.result:
  Make test predictable
mysql-test/r/view.result:
  Make test results predictable
mysql-test/t/disabled.def:
  Disable maria tests for a while
mysql-test/t/events_logs_tests.test:
  Make test predictable
mysql-test/t/view.test:
  Make test results predictable
mysys/lf_alloc-pin.c:
  #warning ->QQ
mysys/lf_hash.c:
  #warning ->QQ
  Removed compiler warnings
mysys/mf_pagecache.c:
  Removed compiler warnings
mysys/my_rename.c:
  Removed compiler warnings
plugin/daemon_example/daemon_example.c:
  Remove compiler warning
sql/ha_ndbcluster.cc:
  Remove compiler warning
sql/udf_example.c:
  Remove compiler warning
storage/maria/lockman.c:
  Changed #warnings to QQ comment
  Removed compiler warnings
storage/maria/ma_blockrec.c:
  Removed compiler warnings
storage/maria/ma_check.c:
  After merge fixes
storage/maria/ma_key.c:
  After merge fixes
storage/maria/ma_packrec.c:
  After merge fixes
storage/maria/ma_rkey.c:
  After merge fixes
storage/maria/ma_sort.c:
  After merge fixes
storage/maria/ma_sp_defs.h:
  Rename clashing function name
storage/maria/ma_sp_key.c:
  Rename clashing function name
storage/maria/ma_test_all.res:
  New test results
storage/maria/ma_unique.c:
  Fixed compiler warning
storage/maria/tablockman.c:
  #warning -> QQ
storage/maria/tablockman.h:
  #warning -> QQ
storage/maria/trnman.c:
  #warning -> QQ
storage/maria/unittest/lockman2-t.c:
  Removed compiler warnings
storage/maria/unittest/ma_control_file-t.c:
  Removed warning for 'maria_control' file not found
storage/maria/unittest/trnman-t.c:
  Removed compiler warnings
storage/ndb/src/mgmapi/mgmapi.cpp:
  Remove compiler warnings
unittest/mysys/mf_pagecache_consist.c:
  Removed compiler warnings
unittest/mysys/my_atomic-t.c:
  Removed compiler warnings
---
 storage/maria/lockman.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 7672fadb068..fdacda84875 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -1,6 +1,7 @@
-#warning TODO - allocate everything from dynarrays !!! (benchmark)
-#warning TODO instant duration locks
-#warning automatically place S instead of LS if possible
+/* QQ: TODO - allocate everything from dynarrays !!! (benchmark) */
+/* QQ: TODO instant duration locks */
+/* QQ: #warning automatically place S instead of LS if possible */
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -218,7 +219,7 @@ typedef struct lockman_lock {
   struct lockman_lock  *lonext;
   intptr volatile link;
   uint32 hashnr;
-#warning TODO - remove hashnr from LOCK
+  /* QQ: TODO - remove hashnr from LOCK */
   uint16 loid;
   uchar lock;              /* sizeof(uchar) <= sizeof(enum) */
   uchar flags;
@@ -428,9 +429,11 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
       }
       if (res & LOCK_UPGRADE)
         cursor.upgrade_from->flags|= IGNORE_ME;
-#warning is this OK ? if a reader has already read upgrade_from, \
-         it may find it conflicting with node :(
-#warning another bug - see the last test from test_lockman_simple()
+      /*
+        QQ: is this OK ? if a reader has already read upgrade_from, 
+        it may find it conflicting with node :(
+        - see the last test from test_lockman_simple()
+      */
     }
 
   } while (res == REPEAT_ONCE_MORE);
@@ -673,7 +676,7 @@ enum lockman_getlock_result lockman_getlock(LOCKMAN *lm, LOCK_OWNER *lo,
       belong to _some_ LOCK_OWNER. It means, we can never free() a LOCK_OWNER,
       if there're other active LOCK_OWNERs.
     */
-#warning race condition here
+    /* QQ: race condition here */
     pthread_mutex_lock(wait_for_lo->mutex);
     if (DELETED(blocker->link))
     {
@@ -749,7 +752,7 @@ int lockman_release_locks(LOCKMAN *lm, LOCK_OWNER *lo)
 }
 
 #ifdef MY_LF_EXTRA_DEBUG
-static char *lock2str[]=
+static const char *lock2str[]=
 { "N", "S", "X", "IS", "IX", "SIX", "LS", "LX", "SLX", "LSIX" };
 /*
   NOTE
@@ -764,8 +767,9 @@ void print_lockhash(LOCKMAN *lm)
     intptr next= el->link;
     if (el->hashnr & 1)
     {
-      printf("0x%08x { resource %llu, loid %u, lock %s",
-             el->hashnr, el->resource, el->loid, lock2str[el->lock]);
+      printf("0x%08lx { resource %lu, loid %u, lock %s",
+             (long) el->hashnr, (ulong) el->resource, el->loid,
+             lock2str[el->lock]);
       if (el->flags & IGNORE_ME) printf(" IGNORE_ME");
       if (el->flags & UPGRADED) printf(" UPGRADED");
       if (el->flags & ACTIVE) printf(" ACTIVE");
@@ -781,4 +785,3 @@ void print_lockhash(LOCKMAN *lm)
   }
 }
 #endif
-
-- 
cgit v1.2.1


From 46922b5125e1cdbc0a79e7ba161aaa5fc515ae6b Mon Sep 17 00:00:00 2001
From: unknown <guilhem@gbichot3.local>
Date: Fri, 2 Mar 2007 11:20:23 +0100
Subject: GPL license update (same change as was done for all files in 5.1).

storage/maria/Makefile.am:
  GPL license update
storage/maria/ft_maria.c:
  GPL license update
storage/maria/ha_maria.cc:
  GPL license update
storage/maria/ha_maria.h:
  GPL license update
storage/maria/lockman.c:
  GPL license update
storage/maria/lockman.h:
  GPL license update
storage/maria/ma_bitmap.c:
  GPL license update
storage/maria/ma_blockrec.c:
  GPL license update
storage/maria/ma_blockrec.h:
  GPL license update
storage/maria/ma_cache.c:
  GPL license update
storage/maria/ma_changed.c:
  GPL license update
storage/maria/ma_check.c:
  GPL license update
storage/maria/ma_checkpoint.c:
  GPL license update
storage/maria/ma_checkpoint.h:
  GPL license update
storage/maria/ma_checksum.c:
  GPL license update
storage/maria/ma_close.c:
  GPL license update
storage/maria/ma_control_file.c:
  GPL license update
storage/maria/ma_control_file.h:
  GPL license update
storage/maria/ma_create.c:
  GPL license update
storage/maria/ma_dbug.c:
  GPL license update
storage/maria/ma_delete.c:
  GPL license update
storage/maria/ma_delete_all.c:
  GPL license update
storage/maria/ma_delete_table.c:
  GPL license update
storage/maria/ma_dynrec.c:
  GPL license update
storage/maria/ma_extra.c:
  GPL license update
storage/maria/ma_ft_boolean_search.c:
  GPL license update
storage/maria/ma_ft_eval.c:
  GPL license update
storage/maria/ma_ft_eval.h:
  GPL license update
storage/maria/ma_ft_nlq_search.c:
  GPL license update
storage/maria/ma_ft_parser.c:
  GPL license update
storage/maria/ma_ft_stem.c:
  GPL license update
storage/maria/ma_ft_test1.c:
  GPL license update
storage/maria/ma_ft_test1.h:
  GPL license update
storage/maria/ma_ft_update.c:
  GPL license update
storage/maria/ma_ftdefs.h:
  GPL license update
storage/maria/ma_fulltext.h:
  GPL license update
storage/maria/ma_info.c:
  GPL license update
storage/maria/ma_init.c:
  GPL license update
storage/maria/ma_key.c:
  GPL license update
storage/maria/ma_keycache.c:
  GPL license update
storage/maria/ma_least_recently_dirtied.c:
  GPL license update
storage/maria/ma_least_recently_dirtied.h:
  GPL license update
storage/maria/ma_locking.c:
  GPL license update
storage/maria/ma_open.c:
  GPL license update
storage/maria/ma_packrec.c:
  GPL license update
storage/maria/ma_page.c:
  GPL license update
storage/maria/ma_panic.c:
  GPL license update
storage/maria/ma_preload.c:
  GPL license update
storage/maria/ma_range.c:
  GPL license update
storage/maria/ma_recovery.c:
  GPL license update
storage/maria/ma_recovery.h:
  GPL license update
storage/maria/ma_rename.c:
  GPL license update
storage/maria/ma_rfirst.c:
  GPL license update
storage/maria/ma_rkey.c:
  GPL license update
storage/maria/ma_rlast.c:
  GPL license update
storage/maria/ma_rnext.c:
  GPL license update
storage/maria/ma_rnext_same.c:
  GPL license update
storage/maria/ma_rprev.c:
  GPL license update
storage/maria/ma_rrnd.c:
  GPL license update
storage/maria/ma_rsame.c:
  GPL license update
storage/maria/ma_rsamepos.c:
  GPL license update
storage/maria/ma_rt_index.c:
  GPL license update
storage/maria/ma_rt_index.h:
  GPL license update
storage/maria/ma_rt_key.c:
  GPL license update
storage/maria/ma_rt_key.h:
  GPL license update
storage/maria/ma_rt_mbr.c:
  GPL license update
storage/maria/ma_rt_mbr.h:
  GPL license update
storage/maria/ma_rt_split.c:
  GPL license update
storage/maria/ma_rt_test.c:
  GPL license update
storage/maria/ma_scan.c:
  GPL license update
storage/maria/ma_search.c:
  GPL license update
storage/maria/ma_sort.c:
  GPL license update
storage/maria/ma_sp_defs.h:
  GPL license update
storage/maria/ma_sp_key.c:
  GPL license update
storage/maria/ma_sp_test.c:
  GPL license update
storage/maria/ma_static.c:
  GPL license update
storage/maria/ma_statrec.c:
  GPL license update
storage/maria/ma_test1.c:
  GPL license update
storage/maria/ma_test2.c:
  GPL license update
storage/maria/ma_test3.c:
  GPL license update
storage/maria/ma_unique.c:
  GPL license update
storage/maria/ma_update.c:
  GPL license update
storage/maria/ma_write.c:
  GPL license update
storage/maria/maria_chk.c:
  GPL license update
storage/maria/maria_def.h:
  GPL license update
storage/maria/maria_ftdump.c:
  GPL license update
storage/maria/maria_pack.c:
  GPL license update
storage/maria/tablockman.c:
  GPL license update
storage/maria/tablockman.h:
  GPL license update
storage/maria/trnman.c:
  GPL license update
storage/maria/trnman.h:
  GPL license update
---
 storage/maria/lockman.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index fdacda84875..cb305dc9bd6 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -6,8 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
+   the Free Software Foundation; version 2 of the License.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-- 
cgit v1.2.1


From 8f39541e7d8ba812d1198af5d4179ba44d6693fa Mon Sep 17 00:00:00 2001
From: unknown <monty@mysql.com/narttu.mysql.fi>
Date: Tue, 29 May 2007 20:13:56 +0300
Subject: This patch is a collection of patches from from Sanja, Sergei and
 Monty.

Added logging and pinning of pages to block format.
Integration of transaction manager, log handler.
Better page cache intergration
Split trnman.h into two files, so that we don't have to include my_atomic.h into C++ programs.
Renaming of structures, more comments, more debugging etc.
Fixed problem with small head block + long varchar.
Added extra argument to delete_record() and update_record() (needed for UNDO logging)
Small changes to interface of pagecache and log handler.
Change initialization of log_record_type_descriptors to not be depending on enum order.
Use array of LEX_STRING's to send data to log handler
Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists.


include/lf.h:
  Interface fixes
  Rename of structures
  (Patch from Sergei via Sanja)
include/my_atomic.h:
  More comments
include/my_global.h:
  Added MY_ERRPTR
include/pagecache.h:
  Added undo LSN when unlocking pages
mysql-test/r/maria.result:
  Updated results
mysql-test/t/maria.test:
  Added autocommit around lock tables
  (Patch from Sanja)
mysys/lf_alloc-pin.c:
  Post-review fixes, simple optimizations
  More comments
  Struct slot renames
  Check amount of memory on stack
  (Patch from Sergei)
mysys/lf_dynarray.c:
  More comments
mysys/lf_hash.c:
  More comments
  After review fixes
  (Patch from Sergei)
storage/maria/ha_maria.cc:
  Split trnman.h into two files, so that we don't have to include my_atomic.h into the .cc program.
  (Temporary fix to avoid bug in gcc)
  Move out all deferencing of the transaction structure.
  Transaction manager integrated (Patch from Sergei)
storage/maria/ha_maria.h:
  Added prototype for start_stmt()
storage/maria/lockman.c:
  Function call rename
storage/maria/ma_bitmap.c:
  Mark deleted pages free from page cache
storage/maria/ma_blockrec.c:
  Offset -> rownr
  More debugging
  Fixed problem with small head block + long varchar
  Added logging of changed pages
  Added logging of undo (Including only loggging of changed fields in case of update)
  Added pinning/unpinning of all changed pages
  More comments
  Added free_full_pages() as the same code was used in several places.
  fill_rows_parts() renamed as fill_insert_undo_parts()
  offset -> rownr
  Added some optimization of not transactional tables
  _ma_update_block_record() has new parameter, as we need original row to do efficent undo for update
storage/maria/ma_blockrec.h:
  Added ROW_EXTENTS_ON_STACK
  Changed prototype for update and delete of row
storage/maria/ma_check.c:
  Added original row to delete_record() call
storage/maria/ma_control_file.h:
  Added ifdefs for C++
storage/maria/ma_delete.c:
  Added original row to delete_record() call
  (Needed for efficent undo logging)
storage/maria/ma_dynrec.c:
  Added extra argument to delete_record() and update_record()
  Removed not used variable
storage/maria/ma_init.c:
  Initialize log handler
storage/maria/ma_loghandler.c:
  Removed not used variable
  Change initialization of log_record_type_descriptors to not be depending on enum order
  Use array of LEX_STRING's to send data to log handler
storage/maria/ma_loghandler.h:
  New defines
  Use array of LEX_STRING's to send data to log handler
storage/maria/ma_open.c:
  Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists.
  Store in MARIA_SHARE->page_type if pages will have up to date LSN's
storage/maria/ma_pagecache.c:
  Don't decrease number of readers when using pagecache_write()/pagecache_read()
  In pagecache_write() decrement request count if page was left pinned
  Added pagecache_delete_pages()
  Removed some casts
  Make trace output consistent with rest of code
  Simplify calling of DBUG_ASSERT(0)
  Only update LSN if the LSN is bigger than what's already on the page
  Added LSN parameter pagecache_unpin_page(), pagecache_unpin(), and pagecache_unlock()
  (Part of patch from Sanja)
storage/maria/ma_static.c:
  Added 'dummy' transaction option to MARIA_INFO so that we can always assume 'trn' exists.
  Added default page cache
storage/maria/ma_statrec.c:
  Added extra argument to delete_record() and update_record()
storage/maria/ma_test1.c:
  Added option -T for transactions
storage/maria/ma_test2.c:
  Added option -T for transactions
storage/maria/ma_test_all.sh:
  Test with transactions
storage/maria/ma_update.c:
  Changed prototype for update of row
storage/maria/maria_def.h:
  Changed prototype for update & delete of row as block records need to access the old row
  Store in MARIA_SHARE->page_type if pages will have up to date LSN's
  Added MARIA_MAX_TREE_LEVELS to allow us to calculate the number of possible pinned pages we may need.
  Removed not used 'empty_bits_buffer'
  Added pointer to transaction object
  Added array for pinned pages
  Added log_row_parts array for logging of field data.
  Added MARIA_PINNED_PAGE to store pinned pages
storage/maria/trnman.c:
  Added accessor functions to transaction object
  Added missing DBUG_RETURN()
  More debugging
  More comments
  Changed // comment of code to #ifdef NOT_USED
  Transaction manager integrated.
  Post review fixes
  Part of patch originally from Sergei
storage/maria/trnman.h:
  Split trnman.h into two files, so that we don't have to include my_atomic.h into the .cc program.
  (Temporary fix to avoid bug in gcc)
storage/maria/unittest/ma_pagecache_single.c:
  Added missing argument
  Added SKIP_BIG_TESTS
  (Patch from Sanja)
storage/maria/unittest/ma_test_loghandler-t.c:
  Test logging with new LEX_STRING parameter
  (Patch from Sanja)
storage/maria/unittest/ma_test_loghandler_multigroup-t.c:
  Test logging with new LEX_STRING parameter
  (Patch from Sanja)
storage/maria/unittest/ma_test_loghandler_multithread-t.c:
  Test logging with new LEX_STRING parameter
  (Patch from Sanja)
storage/maria/unittest/ma_test_loghandler_pagecache-t.c:
  Test logging with new LEX_STRING parameter
  (Patch from Sanja)
storage/maria/unittest/trnman-t.c:
  Stack overflow detection
  (Patch from Sergei)
unittest/unit.pl:
  Command-line options --big and --verbose
  (Patch from Sergei)
unittest/mytap/tap.c:
  Detect --big
  (Patch from Sergei)
unittest/mytap/tap.h:
  Skip_big_tests and SKIP_BIG_TESTS
  (Patch from Sergei)
storage/maria/trnman_public.h:
  New BitKeeper file ``storage/maria/trnman_public.h''
---
 storage/maria/lockman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index cb305dc9bd6..8316d70bb29 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -538,7 +538,7 @@ void lockman_destroy(LOCKMAN *lm)
   {
     intptr next= el->link;
     if (el->hashnr & 1)
-      lf_alloc_real_free(&lm->alloc, el);
+      lf_alloc_direct_free(&lm->alloc, el);
     else
       my_free((void *)el, MYF(0));
     el= (LOCK *)next;
-- 
cgit v1.2.1


From 21fd2a5a3656813c3d97760a5e7eef987dc6879d Mon Sep 17 00:00:00 2001
From: unknown <monty@mysql.com/narttu.mysql.fi>
Date: Wed, 14 Nov 2007 19:08:06 +0200
Subject: First part of redo/undo for key pages Added key_nr to st_maria_keydef
 for faster keyinfo->keynr conversion For transactional tables, shift record
 number in keys up with 1 bit to have place to indicate if transid follows
 Checksum for MyISAM now ignores NULL and not used part of VARCHAR Renamed
 some variables that caused shadow compiler warnings Moved extra() call when
 waiting for tables to not be used to after tables are removed from cache.
 Fixed crashing bugs when using Maria TEMPORARY tables with TRUNCATE. Removed
 'hack' code in sql directory to go around this bug.
 pagecache_unlock_by_ulink() now has extra argument to say if page was
 changed. Give error message if we fail to open control file Mark page cache
 variables as not flushable

include/maria.h:
  Made min page cache larger (needed for pinning key page)
  Added key_nr to st_maria_keydef for faster keyinfo->keynr conversion
  Added write_comp_flag to move some runtime code to maria_open()
include/my_base.h:
  Added new error message to be used when handler initialization failed
include/my_global.h:
  Renamed dummy to swap_dummy to avoid conflicts with local 'dummy' variables
include/my_handler.h:
  Added const to some parameters
mysys/array.c:
  More DBUG
mysys/my_error.c:
  Fixed indentation
mysys/my_handler.c:
  Added const to some parameters
  Added missing error messages
sql/field.h:
  Renamed variables to avoid variable shadowing
sql/handler.h:
  Renamed parameter to avoid variable name conflict
sql/item.h:
  Renamed variables to avoid variable shadowing
sql/log_event_old.h:
  Renamed variables to avoid variable shadowing
sql/set_var.h:
  Renamed variables to avoid variable shadowing
sql/sql_delete.cc:
  Removed maria hack for temporary tables
  Fixed indentation
sql/sql_table.cc:
  Moved extra() call when waiting for tables to not be used to after tables are removed from cache.
  This was needed to ensure we don't do a PREPARE_FOR_DROP or similar call while the table is still in use.
sql/table.cc:
  Copy page_checksum from share
  Removed Maria hack
storage/maria/Makefile.am:
  Added new files
storage/maria/ha_maria.cc:
  Renamed records -> record_count and info -> create_info to avoid variable name conflicts
  Mark page cache variables as not flushable
storage/maria/ma_blockrec.c:
  Moved _ma_unpin_all_pages() to ma_key_recover.c
  Moved init of info->pinned_pages to ma_open.c
  Moved _ma_finalize_row() to maria_key_recover.h
  Renamed some variables to avoid variable name conflicts
  Mark page_link.changed for blocks we change directly
  Simplify handling of undo link when writing LOGREC_UNDO_ROW_INSERT (old code crashed when having redo for index)
storage/maria/ma_blockrec.h:
  Removed extra empty line
storage/maria/ma_checkpoint.c:
  Remove not needed trnman.h
storage/maria/ma_close.c:
  Free pinned pages (which are now always allocated)
storage/maria/ma_control_file.c:
  Give error message if we fail to open control file
storage/maria/ma_delete.c:
  Changes for redo logging (first part, logging of underflow not yet done)
  - Log undo-key-delete
  - Log delete of key
  - Updated arguments to _ma_fetch_keypage(), _ma_dispose(), _ma_write_keypage(), _ma_insert()
  - Added new arguments to some functions to be able to write redo information
  - Mark key pages as changed when we write with PAGECACHE_LOCK_LEFT_WRITELOCKED

  Remove one not needed _ma_write_keypage() in d_search() when upper level will do the write anyway
  Changed 2 bmove_upp() to bmove() as this made code easer to understand
  More function comments
  Indentation fixes
storage/maria/ma_ft_update.c:
  New arguments to _ma_write_keypage()
storage/maria/ma_loghandler.c:
  Fixed some DBUG_PRINT messages
  Simplify code
  Added new log entrys for key page redo
  Renamed some variables to avoid variable name shadowing
storage/maria/ma_loghandler.h:
  Moved some defines here
  Added define for storing key number on key pages
  Added new translog record types
  Added enum for type of operations in LOGREC_REDO_INDEX
storage/maria/ma_open.c:
  Always allocate info.pinned_pages (we need now also for normal key page usage)
  Update keyinfo->key_nr
  Added virtual functions to convert record position o number to be stored on key pages
  Update keyinfo->write_comp_flag to value of search flag to be used when writing key
storage/maria/ma_page.c:
  Added redo for key pages
  - Extended _ma_fetch_keypage() with type of lock to put on page and address to used MARIA_PINNED_PAGE
  - _ma_fetch_keypage() now pin's pages if needed
  - Extended _ma_write_keypage() with type of locks to be used
  - ma_dispose() now locks info->s->state.key_del from other threads
  - ma_dispose() writes redo log record
  - ma_new() locks info->s->state.key_del from other threads if it was used
  - ma_new() now pins read page

  Other things:
  - Removed some not needed arguments from _ma_new() and _ma_dispose)
  - Added some new variables to simplify code
  - If EXTRA_DEBUG is used, do crc on full page to catch not unitialized bytes
storage/maria/ma_pagecache.h:
  Applied patch from Sanja to add extra argument to pagecache_unlock_by_ulink() to mark if page was changed
  Added some defines for pagecache priority levels that one can use
storage/maria/ma_range.c:
  Added new arguments for call to _ma_fetch_keypage()
storage/maria/ma_recovery.c:
  - Added hooks for new translog types:
    REDO_INDEX, REDO_INDEX_NEW_PAGE, REDO_INDEX_FREE_PAGE, UNDO_KEY_INSERT, UNDO_KEY_DELETE and
    UNDO_KEY_DELETE_WITH_ROOT.
  - Moved variable declarations to start of function (portability fixes)
  - Removed some not needed initializations
  - Set only relevant state changes for each redo/undo entry
storage/maria/lockman.c:
  Removed end space
storage/maria/ma_check.c:
  Removed end space
storage/maria/ma_create.c:
  Removed end space
storage/maria/ma_locking.c:
  Removed end space
storage/maria/ma_packrec.c:
  Removed end space
storage/maria/ma_pagecache.c:
  Removed end space
storage/maria/ma_panic.c:
  Removed end space
storage/maria/ma_rt_index.c:
  Added new arguments for call to _ma_fetch_keypage(), _ma_write_keypage(), _ma_dispose() and _ma_new()
  Fixed indentation
storage/maria/ma_rt_key.c:
  Added new arguments for call to _ma_fetch_keypage()
storage/maria/ma_rt_split.c:
  Added new arguments for call to _ma_new()
  Use new keypage header
  Added new arguments for call to _ma_write_keypage()
storage/maria/ma_search.c:
  Updated comments & indentation
  Added new arguments for call to _ma_fetch_keypage()
  Made some variables and arguments const
  Added virtual functions for converting row position to number to be stored in key
  use MARIA_RECORD_POS of record position instead of my_off_t
  Record in MARIA_KEY_PARAM how page was changed one key insert (needed for REDO)
storage/maria/ma_sort.c:
  Removed end space
storage/maria/ma_statrec.c:
  Updated arguments for call to _ma_rec_pos()
storage/maria/ma_test1.c:
  Fixed too small buffer to init_pagecache()
  Fixed bug when using insert_count and test_flag
storage/maria/ma_test2.c:
  Use more resonable pagecache size
  Remove not used code
  Reset blob_length to fix wrong output message
storage/maria/ma_test_all.sh:
  Fixed wrong test
storage/maria/ma_write.c:
  Lots of new code to handle REDO of key pages
  No logic changes because of REDO code, mostly adding new arguments and adding new code for logging

  Added new arguments for calls to _ma_fetch_keypage(), _ma_write_keypage() and similar functions
  Move setting of comp_flag in ma_ck_wrte_btree() from runtime to maria_open()
  Zerofill new used pages for:
  - To remove possible sensitive data left in buffer
  - To get idenitical data on pages after running redo
  - Better compression of pages if archived
storage/maria/maria_chk.c:
  Added information if table is crash safe
storage/maria/maria_def.h:
  New virtual function to convert between record position on key and normal record position
  Aded mutex and extra variables to handle locking of share->state.key_del
  Moved some structure variables to get things more aligned
  Added extra arguments to MARIA_KEY_PARAM to be able to remember what was changed on key page on key insert
  Added argument to MARIA_PINNED_PAGE to indicate if page was changed
  Updated prototypes for functions
  Added some structures for signaling changes in REDO handling
storage/maria/unittest/ma_pagecache_single.c:
  Updated arguments for changed function calls
storage/myisam/mi_check.c:
  Made calc_check_checksum virtual
storage/myisam/mi_checksum.c:
  Update checksums to ignore null columns
storage/myisam/mi_create.c:
  Mark if table has null column (to know when we have to use mi_checksum())
storage/myisam/mi_open.c:
  Added virtual function for calculating checksum to be able to easily ignore NULL fields
storage/myisam/mi_test2.c:
  Fixed bug
storage/myisam/myisamdef.h:
  Added virtual function for calculating checksum during check table
  Removed ha_key_cmp() as this is in handler.h
storage/maria/ma_key_recover.c:
  New BitKeeper file ``storage/maria/ma_key_recover.c''
storage/maria/ma_key_recover.h:
  New BitKeeper file ``storage/maria/ma_key_recover.h''
storage/maria/ma_key_redo.c:
  New BitKeeper file ``storage/maria/ma_key_redo.c''
---
 storage/maria/lockman.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

(limited to 'storage/maria/lockman.c')

diff --git a/storage/maria/lockman.c b/storage/maria/lockman.c
index 8316d70bb29..c9b753fb492 100644
--- a/storage/maria/lockman.c
+++ b/storage/maria/lockman.c
@@ -247,7 +247,7 @@ static int lockfind(LOCK * volatile *head, LOCK *node,
 {
   uint32        hashnr, cur_hashnr;
   uint64        resource, cur_resource;
-  intptr        link;
+  intptr        cur_link;
   my_bool       cur_active, compatible, upgrading, prev_active;
   enum lock_type lock, prev_lock, cur_lock;
   uint16        loid, cur_loid;
@@ -276,10 +276,10 @@ retry:
     if (!cursor->curr)
       break;
     do {
-      link= cursor->curr->link;
-      cursor->next= PTR(link);
+      cur_link= cursor->curr->link;
+      cursor->next= PTR(cur_link);
       _lf_pin(pins, 0, cursor->next);
-    } while(link != cursor->curr->link && LF_BACKOFF);
+    } while (cur_link != cursor->curr->link && LF_BACKOFF);
     cur_hashnr= cursor->curr->hashnr;
     cur_resource= cursor->curr->resource;
     cur_lock= cursor->curr->lock;
@@ -290,7 +290,7 @@ retry:
       (void)LF_BACKOFF;
       goto retry;
     }
-    if (!DELETED(link))
+    if (!DELETED(cur_link))
     {
       if (cur_hashnr > hashnr ||
           (cur_hashnr == hashnr && cur_resource >= resource))
@@ -429,7 +429,7 @@ static int lockinsert(LOCK * volatile *head, LOCK *node, LF_PINS *pins,
       if (res & LOCK_UPGRADE)
         cursor.upgrade_from->flags|= IGNORE_ME;
       /*
-        QQ: is this OK ? if a reader has already read upgrade_from, 
+        QQ: is this OK ? if a reader has already read upgrade_from,
         it may find it conflicting with node :(
         - see the last test from test_lockman_simple()
       */
-- 
cgit v1.2.1