Possible to set incoming message processed

74 views
Skip to first unread message

Jerry Shea

unread,
May 9, 2016, 6:52:12 AM5/9/16
to Chronicle
Hi all,

I am using CQ 3.6.1.8 (IndexedChronicle) and would like to understand whether it is safe to mark an incoming message as processed while the chronicle is being appended to by another process.

The Chronicle Queue FAQ says that you cannot safely write to the same Chronicle from multiple processes but Peter has said before that you can set a message as processed after it has been read to ensure you don't process it twice.

Is this safe to do when the chronicle is being appended to by another process?

Thanks, Jerry
 

Peter Lawrey

unread,
May 9, 2016, 9:04:03 AM5/9/16
to java-ch...@googlegroups.com
Hello Jerry,

I have deleted the old FAQ.  The current one is


Is this safe to do when the chronicle is being appended to by another process?

The ExcerptTailer/Excerpt can alter an existing Excerpt whether it is being appended or modified by another thread or process on the same machine.

For modifying the entry in a thread safe manner, I suggest using compareAndSetInt or compareAndSetLong to ensure the change is atomic.  You might want to have the Appender pad the message with 4/8 bytes so you can perform this update later.  I suggest putting in a timestamp so you can also see when a message was processed.

     if (tailer.compareAndSetLong(offset, System.nanoTime())) {
        // updated successfully
     }

 If you have multiple consumers you want to load balance between you can give each one an id like 1,2,3 and 

     if (tailer.compareAndSetInt(offset, workerId)) {
        // work is assigned to me
     } else {
        // some one else got there first
     }

Regards,
  Peter.

--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jerry Shea

unread,
May 10, 2016, 5:26:36 AM5/10/16
to Chronicle
Thanks Peter,

that is great to hear - my tests had shown that this did seem to behave reliably but I'm very pleased to have it confirmed.

Cheers, Jerry
Reply all
Reply to author
Forward
0 new messages