phpbar.de logo

Mailinglisten-Archive

Re: Locking von Datensaetzen
Archiv Mailingliste mysql-de

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Locking von Datensaetzen



Florian Kieling schrieb am Samstag, den 14. August 1999:
> kann mir jemand sagen (schreiben), ob und wann MySQL das locken von
> einzelnen Datensaetzen erlaubt? Wird evtl. daran schon gearbeitet?

Geht bisher nicht und ist auch nicht geplant.

Aber mit Hilfe von GET_LOCK() und RELEASE_LOCK() ließe sich sowas
kooperativ auf der Anwendungsseite machen.

Anbei ein aktueller Text von Paul DuBois zu diesen Funtionen.

Ciao,
  Martin
-- 
Martin Ramsch <m.ramsch_(at)_computer.org> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7

---- Begin included message ----
In the wake of some recent discussion about the operation of GET_LOCK(),
I've written the following as an attempt to clarify how it works.  I'd
appreciate any comments or corrections.  Thanks.


GET_LOCK(str,timeout)

   GET_LOCK() is used in conjunction with RELEASE_LOCK() to perform
   advisory (cooperative) locking. You can use the two functions to write
   applications that cooperate based on the status of an agreed-upon lock
   name.

   GET_LOCK() is called with a lock name indicated by the string str and
   a timeout value of timeout seconds. It returns 1 if the lock was
   obtained successfully within the timeout period, 0 if the lock attempt
   failed due to timing out, or NULL if an error occurred. The timeout
   value determines how long to wait while attempting to obtain the lock,
   not the duration of the lock; once obtained, the lock remains in force
   until released.

   The following call acquires a lock named "my lock", waiting up to 10
   seconds for it:

      GET_LOCK("my lock", 10)

   The lock applies only to the string itself. It does not lock a
   database, a table, or any rows or columns within a table. In other
   words, the lock does not prevent any other client from doing anything
   to database tables, which is why GET_LOCK() locking is advisory only -
   it simply allows other cooperating clients to determine whether or not
   the lock is in force. A client that has a lock on a name blocks
   attempts by other clients to lock the name (or attempts by other
   threads within a multi-threaded client that maintains multiple
   connections to the server). Suppose client 1 locks the string "my
   lock". If client 2 attempts to lock the same string, it will block
   waiting for the lock until client 1 releases it or until the timeout
   period expires. In the former case, client 2 will acquire the lock
   successfully; in the latter case, it will fail.

   Since two clients cannot lock a given string at the same time,
   applications that agree on a name can use the lock status of that name
   as an indicator of when it is safe to perform operations related to
   the name. For example, you can construct a lock name based on a unique
   key value for a row in a table to allow cooperative locking of that
   row.

   A lock is released explicitly by calling RELEASE_LOCK() with the lock
   name.

      RELEASE_LOCK("my lock")

   RELEASE_LOCK() returns 1 if the lock was released successfully, 0 if
   the lock was held by another connection (you can only release your own
   locks), or NULL if no such lock exists.

   Any lock held by a client connection is also automatically released
   when the connection terminates, or if the client issues another
   GET_LOCK() call (a client connection can lock only one string at a
   time). In the latter case, the lock being held is released before the
   new lock is obtained, even if the lock name is the same.

   GETLOCK(str,0) may be used as a simple poll to determine without
   waiting whether or not a lock on str is in force. (This will of course
   lock the string if it is not currently locked, so remember to call
   RELEASE_LOCK() as appropriate.)

-- 
Paul DuBois, paul_(at)_snake.net

---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail mysql-thread10063_(at)_lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail mysql-unsubscribe_(at)_lists.mysql.com instead.

---- End included message ----

Home | Main Index | Thread Index

php::bar PHP Wiki   -   Listenarchive