home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.databases:6271 comp.databases.theory:378
- Newsgroups: comp.databases,comp.databases.theory
- Path: sparky!uunet!decwrl!world!edwards
- From: edwards@world.std.com (Jonathan Edwards)
- Subject: How to make a relational queue
- Message-ID: <BtGon0.KsF@world.std.com>
- Organization: The World Public Access UNIX, Brookline, MA
- Date: Mon, 24 Aug 1992 00:13:48 GMT
- Lines: 36
-
- Well, my previous post turned up no adequate solutions.
- In fact, it may not be possible at all. This is such a damning conclusion
- (at least to me) that I feel obliged to post my conclusion in the hope
- that someone will contradict me.
-
- The problem is implementing a FIFO queue as a relational table. Lets assume
- that there is a column containing the datetime of arrival in the queue to
- provide the correct ordering. The tricky part is to come up with a way of
- removing the oldest row in the queue. Constraints: there are many dequeuers
- running asynchronously, and each row must go to only ONE of them.
- Further constraint: TRANSACTIONS. Dequeuing is just one operation in a
- transaction that might take minutes. The entry must be returned to the queue
- automatically if the transaction aborts or the system fails.
-
- The obvious approach is to do a SELECT MIN(datetime) followed by a DELETE.
- But what if someone else has already dequeued that row but not yet commited
- their transaction? We can't wait for the end of the transaction. So we
- could specify that we don't want to wait on this lock and retry the operation.
- We could retry by issuing a
- SELECT MIN(datetime) WHERE datetime > locked-item-datetime.
- [I don't know SQL from shinola, so pardon my syntax]
- We iterate over all uncommited dequeues till we find a winner.
-
- But I think this won't work, at least on RDB/VMS. As I understand it,
- RDB puts a read-lock on all rows visited by a transaction, so that our first
- SELECT statement would fail with a lock conflict. Thus we have no way of
- finding out just what the 'locked-item-datetime' is, because we can't even
- look at it.
-
- Am I missing something? Do other databases permit more lenient locking to
- allow this? Thanks, Jonathan
-
-
-
-
-
-