On 23 January 2011 22:34, Joseph Gentle <[email protected]> wrote: > I'm writing a little OT database server, and pulling out some of the > model code to use with it. Each OT document will be an opaque JSON > object. Each OT document type will be defined by the following > functions: > > 1. snapshot = New() > 2. snapshot' = Apply(snapshot, op) > 3. (op1', op2') = Transform(op1, op2) > > Optional: > 4. op' = Invert(op) > > For the wave data types, I'd also like some helper functions for > clients to create the ops. (Nindo and all that). > > > I think I know what types I should be using, but I'm not 100% sure. Do > you mind checking that I'm doing this right? >
I assume from the below that you want this to be interoperable with wave at least at the data model level? > > My plan is: > > Concrete data types: > - Wave document snapshots are WaveletDataImpl objects > - Ops are WaveletOperations > There are two distinct domains that you're confusing: wavelets and documents. The document domain is entirely self-contained and knows nothing about wavelets. A document snapshot is simply an op applying to the empty document. A wavelet snapshot is a bunch of metadata, and not easily expressible as a single op, hence the WaveletData type. Document ops and DocOps, wavelet ops are WaveletOps. The domain of OT is a wavelet. The word "document" above is possibly confusing because a document is not the database object (but sounds like you want it to be). The database stores a tuple of: > - ByteStringMessage<ProtocolAppliedWaveletDelta> applied; > - TransformedWaveletDelta transformed; > > (The applied deltas are signed, and the transformed deltas are what > was actually applied to the snapshot). > > For consistency with the current implementation, null is used for the > doc snapshot until the first op is applied. When that happens, > snapshot = WaveletDataUtil.buildWaveletFromFirstDelta(waveletName, > transformedDelta); > and later, snapshots are applied using: > WaveletDataUtil.applyWaveletDelta(transformedDelta, snapshot); > "Doc snapshot" -> "Wavelet snapshot"? > So thus: > > New() = WaveletDataUtil.buildWaveletFromFirstDelta(waveletName, > op.transformedDelta); > Apply(snapshot, op) = > WaveletDataUtil.applyWaveletDelta(op.transformedDelta, snapshot); > Transform(op1, op2) = > org.waveprotocol.wave.model.operation.wave.Transform.transform(op1, > op2) > > Invert should be trivial, but I can't find it. > Wavelet ops are not invertible. Document ops are. To make the ops in the first place, my understanding is that I want to > create a document, apply nindo to it and get the doc ops out the other > side. Which document class do I want to use? (There's about 20 to > choose from.) > > Do I poll to get the DocOps out or should I make a custom sink class > which gets sent the ops? Use a sink. Almost all the document classes are adaptors of some sort around IndexedDocument. Which one you need depends on details of how you're using it, but try starting with IndexedDocument.
