ZK-1931/javazab — pull request #76 by EasonLiao (2014-07-15 21:06:03+00:00)
Title: How does the application identify transactions?

Application needs to be able to identify transactions and match them up with pending requests. Using zabkv as an example, zabkv needs to match up delivered transactions with HTTP request contexts so that it knows which HTTP request to respond to.

Since zab delivers transactions in the same order it receives them, I'm thinking that zabkv can store the HTTP request context in a queue so long as it can identify the origin of the transaction. To identify the origin, we can either change the deliver method to pass the origin or let zabkv encode the origin into the message. So the request flow looks like this:

1. zabkv receives an HTTP PUT request to create a key-value pair.
2. zabkv calls zab.send() and puts the HTTP request context in a queue.
3. When the transaction is committed, zab calls deliver().
4. In deliver(), zabkv updates the state machine. If the origin of the transaction is itself, zabkv dequeues the HTTP request context and responds to the HTTP request.
5. When zab goes back to LOOKING state, zabkv responds to all the HTTP requests in the queue with a 5xx error and clear the queue.

Does this sound reasonable? There is a related discussion in zookeeper-30:

https://issues.apache.org/jira/browse/ZOOKEEPER-30?focusedCommentId=12688994&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12688994