Monday, June 15, 2009

Google Wave and Race Condition

Character-level protocol

Google wave is the new platform for real-time communication that allows both parties to edit the same wavlet (you can think of wavelet as conversation or document). If you are a software developer, you might be thinking about how Wave is going to deal with race condition. I just found a good video from a Google engineer David Wang that might help clarify how wave can avoid race condition on protocol level when both sides are transmitting changes. Bascially, the protocol will specify the changes at the character level.

Race condition on Wave Gadget
That said, it seems that Wave Gadget may run into race condition.
If one participant write "gamestate"=1 into wave gadget state and the other party write "gamestate"=5. Then whoever writes later will overwrite the other's change.

To make it more concrete:
Let's say that both party check state to see if a host for the game is selected. If not, claim to be host and save it to state.
  1. party1 calls wave.getState() to and sees that "gamehost" property is absent. So gamehost is not selected.
  2. party2 calls wave.getState() to and sees that "gamehost" property is absent. So gamehost is not selected.
  3. party1 go ahead and claim to be gamehost and write the state "gamehost=party1" (by calling wave.getState().submitDelta())
  4. party2 go ahead and claim to be gamehost and write the state "gamehost=party2"
  5. Now both side think they are the host. Whoever writes last will overwrite the other side's state.
Hopefully there will be better control about race condition in Wave Gadget later.

No comments:

Post a Comment