I am working on implementing a persistent queue system based on
Berkeley DB queue access method.
For my new queue implementation I need to implement a 'peek' method.
This method should return the next available record from the head of
the queue, but not delete it.
The desired behavior is much like doing a 'get' with 'DB_CONSUME' or
'DB_CONSUME_WAIT', but without the CONSUME part.
How would I go about implementing such behavior?
For now I only see two alternatives - both having problems:
1. I can use a cursor starting at the head of the queue, and working
my way down (using 'DB_NEXT').
The problem with this method is that in parallel to the 'peek'
operations, pop operations are done (actually more like delete).
This causes the tail of the queue to become a hotspot - locking the
cursor.
Also I have cases where the cursor skips records despite the use of
' DB_INORDER'.
2. I can use a 'get' operation with 'DB_CONSUME_WAIT', and then
rollback the transaction.
This seems both inelegant and IO wasteful.
Any ideas?
- Thanks, Yoav.