I have a time series scenario:
One thread is pushing in key,record pairs at the end. Another thread is reading key,record pairs from the end or inside the list of pairs.
The key is a 64bit unsigned int coding of the current time.
The write task is done by a dedicated transaction where a (write) cursor is created within an transaction, the cursor is used to insert the new pair, then the cursor is closed and finally the transaction is committed. The cursor is used to put in a key,record pair, that is at the end of the contained data. The key is the highest value that is inserted into the db. (As time moves on ...)
The read task is done with a local (read) cursor inside a method, but still using the automatic transactions.
At first the cursor is created on stack for each read.
The cursor normally is put at the end of the tile series by asking for the last entry: cursor.move_last();
This request is done repeatedly to have a polling for the newest entry....
For the read cursor there is an option to walk "backward" in time to see old entries. This is realized by requesting the key/records by giving a time key and the option
HAM_FIND_LT_MATCH in the cursor find call.
This works well.
But if the cursor is used to step forward in time by the same technique: Give a key for a time and ask for the
HAM_FIND_GT_MATCH in the cursor find call.
Then the cursor gives the same key as result, but the record of the
last entry of the time line.
But it should have provided the next younger entry instead....
Example: The time series is created sequentially by inserting (1,1) (2,2) (3,3) ...
Key, Value
1,1
2,2
3,3
4,4
5,5
6,6
The read cursor is put at the end via cursor.move_last() to be at the end of the series shortly after a new entry is inserted. So the read cursor is at the end while a new entry is put "behind" the end.
This seems to be a critical action, because if this is not this constellation the following does not happen!
Read cursor is at position 5.
Write cursor puts in (6,6).
Read cursor is positioned via cursor.move_last().
Now the read cursor is put again at position 6 (ok)
Now the read cursor is asked to find(key,record,HAM_FIND_LT_MATCH) with key = 6. The result is key=5 and record=5 (ok)
Now repeat the step backward in time: find(key,record,HAM_FIND_LT_MATCH) with key=5. The result is key=4 and record = 4 (ok)
Now ask for the step forward in time: find(key,record,HAM_FIND_GT_MATCH) with key=4.
The result is key=4 and record=6 (?????)All this is
NOT happening, if the last entry is put at the end and
the read cursor is not at the last position.
Is this a problem with the automatic transaction?
Next I will try to have a manually instanced transaction for the read cursor, too... Maybe this helps?