Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Science of Etherpad

The Science of Etherpad

How does Operational Transform work?

Tim Cameron Ryan

May 14, 2012
Tweet

More Decks by Tim Cameron Ryan

Other Decks in Programming

Transcript

  1. app

  2. apple Operation 2 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  insertCharacter “l” 5.  insertCharacter “e“
  3. applecore Operation 2 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  retain (skip character) 5.  retain (skip character) 6.  insertCharacter “c” 7.  insertCharacter “o“ 8.  insertCharacter “r“ 9.  insertCharacter “e“
  4. appl Operation 1 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  insertCharacter “l” apple Operation 2 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  retain (skip character) 5.  insertCharacter “e”
  5. Operation 1+2 1.  retain (skip character) 2.  retain (skip character)

    3.  retain (skip character) 4.  insertCharacter “l” 5.  insertCharacter “e“ appl apple
  6. appl Operation A 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  insertCharacter “l” appe Operation B 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “e” CLIENT A CLIENT B
  7. appl Operation B 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  insertCharacter “e” appe Operation A 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “l” CLIENT A CLIENT B
  8. appel Operation B 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  insertCharacter “e” apple Operation A 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “l” CLIENT A CLIENT B
  9. “A theoretical framework of concurrency control” that “provides a mechanism

    for sanely resolving [editing] conflicts so that neither user intervention or locking become necessary.” A mechanism to “transform” two operations in conflict, resulting in two new operations which bring both clients into a common state.
  10. appl Operation A 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  insertCharacter “l” CLIENT A SERVER 1 appe Operation B 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “e” CLIENT B 2
  11. Operation A 1.  retain (skip character) 2.  retain (skip character)

    3.  retain (skip character) 4.  insertCharacter “l” SERVER TRANSFORM Operation B 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “e” Operation B` 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  retain (skip character) 5.  insertCharacter “e” Operation A` 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “l” 5.  retain (skip character)
  12. appl Operation B` 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  retain (skip character) 5.  insertCharacter “e” CLIENT A SERVER appe Operation A` 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “l” 5.  retain (skip character) CLIENT B B` A`
  13. apple Operation B` 1.  retain (skip character) 2.  retain (skip

    character) 3.  retain (skip character) 4.  retain (skip character) 5.  insertCharacter “e” CLIENT A SERVER apple Operation A` 1.  retain (skip character) 2.  retain (skip character) 3.  retain (skip character) 4.  insertCharacter “l” 5.  retain (skip character) CLIENT B B` A`
  14. CLIENT A CLIENT B SERVER A1: retain 3, insert “l”

    B1: retain 3, insert “e” Transform A1 x B1 Apply A1` Apply B1`
  15. CLIENT A CLIENT B SERVER A1: retain 3, insert “l”

    B1: retain 3, insert “e” A2: retain 4, insert “core” Transform A1 x B1 Apply A1` Transform A2 x B1` Apply B1`` Broadcast A2 Apply A2`
  16. CLIENT A CLIENT B SERVER A1: retain 3, insert “l”

    B1: retain 3, insert “e” A2: retain 4, insert “core” Transform A1 x B1 B2: retain 4, insert “sauce” Transform B2 x A1` Apply A1`` Transform A2 x B1` Apply B1`` Transform A2` x B2` Apply A2`` Apply B2``
  17. CLIENT A CLIENT B SERVER A1: retain 3, insert “l”

    B1: retain 3, insert “e” A2: retain 4, insert “core” Transform A1 x B1 B2: retain 4, insert “sauce” Transform B2 x A1` Apply A1`` Transform A2 x B1` Apply B1`` Transform A2` x B2` Apply A2`` Apply B2``
  18. <i>big</i> <b>apple</b> Operation 1.  insertStartTag “i” 2.  insertCharacter “b” 3. 

    insertCharacter “i” 4.  insertCharacter “g” 5.  insertEndTag “i” 6.  insertCharacter “ ” 7.  insertStartTag “b” 8.  insertCharacter “a” 9.  insertCharacter “p” 10.  insertCharacter “p” 11.  insertCharacter “l” 12.  insertCharacter “e” 13.  insertEndTag “b”
  19. a <b>big</b> word Operation A 1.  retain 2 2.  insertStartTag

    “b” 3.  retain 3 4.  insertEndTag “b” a biiiiig word Operation B 1.  retain 3 2.  insertCharacters “iiii” CLIENT A CLIENT B
  20. a <b>big</b> word Operation B` 1.  retain 4 2.  insertCharacters

    “iiii” a biiiiig word Operation A` 1.  retain 2 2.  insertStartTag “b” 3.  retain 5 4.  insertEndTag “b” CLIENT A CLIENT B
  21. a <b>biiiiig</b> word Operation B` 1.  retain 4 2.  insertCharacters

    “iiii” a <b>biiiiig</b> word Operation A` 1.  retain 2 2.  insertStartTag “b” 3.  retain 5 4.  insertEndTag “b” CLIENT A CLIENT B
  22. CLIENT A CLIENT B Desired Word1 Word2 Word3 <ol> <li>

    Word4 Word5 Word6 </li> </ol> <ol> <li> Word1 Word2 Word3 Word4 </li> </ol> Word5 Word6 <ol> <li> Word1 Word2 Word3 Word4 Word5 Word6 </li> </ol>
  23. CLIENT A CLIENT B Desired Word1 Word2 <p> Word3 Word4

    Word5 Word6 </p> <h1> Word1 Word2 Word3 Word4 </h1> Word5 Word6 <h1> Word1 Word2 </h1> <p> Word3 Word4 </p> <p> Word5 Word6 </p>
  24. CLIENT A CLIENT B Desired Word1 Word2 Word3 <i> Word4

    Word5 Word6 Word7 Word8 </i> <b> Word1 Word2 Word3 Word4 Word5 </b> Word6 Word7 Word8 <b> Word1 Word2 Word3 </b> <bi> Word4 Word5 </bi> <i> Word6 Word7 Word8 </i>
  25. •  retain •  deleteCharacter •  deleteStartTag(tag, attrs) •  deleteEndTag() • 

    deleteEmptyTag() •  insertCharacter •  insertStartTag(tag, attrs) •  insertEndTag() •  insertEmptyTag() •  modifyAttrs(attrs) Deletion Phase Insertion Phase OPERATION ATOMS
  26. Containers like: preserve unlike: priority Blocks like: priority unlike: priority

    Styles like: preserve unlike: merge Inline <ul> <li> <ol> <blockquote> <p> <div> <h1> <h2> <h3> <pre> <b> <i> <span> <u> <s> “text” <br> DOCUMENT SCHEMA