• No results found

1.4 Real-time collaborative editing

1.4.4 Operational transformation

Because operational transformation technique is the foundation of our research, we would like to briefly introduce some background knowledge about operational trans- formation [137, 136]. In a real-time collaborative editing system that uses operational transformation technique for optimistic concurrency control, concurrent operations need to be transformed against each other before execution. The concurrent relation between two operations is defined as follows.

Definition 1.2. Concurrent relation “k”

Given two operations Oa and Ob, Oa is concurrent with Ob, denoted as Oa k Ob,

iff neitherOa → Ob nor Ob → Oa.

Concurrent operations are transformed against each other by two types of prim- itive transformation functions [137]: one is the Inclusion Transformation function – IT(Oa,Ob), which transforms operation Oa against operation Ob in such a way that

the impact of Ob is effectively included in the parameters of the output operation

O0

a; and the other is the Exclusion Transformation function – ET(Oa, Ob), which

transformsOa against Ob in such a way that the impact of Ob is effectively excluded

from the parameters of the output operation O0

a.

The following definitions are used to describe the precondition and the postcon- dition of primitive transformation functions.

Definition 1.3. Operation context “CT”

Given an operation O, its context, denoted as CTO, is the document state on

which O is defined.

Definition 1.4. Context preceding relation “7→”

Given two operationsOaand Ob,Oaiscontext precedingOb, denoted as Oa 7→Ob,

iff CTOb =CTOa ◦[Oa].

Given two operationsOaand Ob,Oaiscontext equivalentOb, denoted as Oa tOb,

iff CTOa =CTOb.

The precondition for O0

a = IT(Oa, Ob) transformation is Oa t Ob and its post-

condition isOb 7→O0a. Furthermore, transformation has the following two properties

to meet:

Definition 1.6. List equivalent relation“≡”

Given any two lists of operations La and Lb storing editing operations performed

on the document stateS0, thenLa and Lb are equivalent, denoted as La ≡Lb, iffS0

◦ La = S0 ◦ Lb.

Based on the definition of list equivalent relation, two transformation properties are described as follows:

Property 1.1. Transformation Property 1(TP1)

Given two operations Oa and Ob, ifO0a =IT(Oa, Ob) and Ob0 =IT(Ob, Oa), then

[Oa, O0b] ≡ [Ob, Oa0].

Property 1.2. Transformation Property 2(TP2)

Given three operations O, Oa and Ob, if O0a =IT(Oa,Ob) and Ob0 = IT(Ob,Oa),

then IT(IT(O,Oa), Ob0)) = IT(IT(O, Ob), Oa0)).

Furthermore, the precondition for O0

a = ET(Oa, Ob) transformation is Ob 7→ Oa

and its postcondition isOb tO0a. In addition, inclusion transformation and exclusion

transformation has the following reversibility property to meet:

Property 1.3. Reversibility Property (RP)

Given any two operations Oa andOb, ifOb0 =ET(Ob,Oa), thenOb =IT(Ob0,Oa).

The reversibility property should be met in defining exclusion transformation func- tions. But in reality, it is difficult to define exclusion transformation functions that always meet the reversibility property due to the information loss in defining inclusion transformation functions [137].

28

Various transformation control algorithms have been devised to control the trans- formation process in order to meet the above preconditions, postconditions, and transformation properties. Representative algorithms aredOPT[46], adOPTed[109],

GOT[137], andGOTO [136]. But none of them is able to always meet all those con- ditions and properties. adOPTed [109], GOT [137], and GOTO [136] algorithms are able to meet transformation preconditions and postconditions but may violate trans- formation property 2(TP2). The dOPT algorithm could even violate transformation preconditions and postconditions.

Site 1 Site 2 12 12 O1= Ins[0, x] x12 O2= Ins[2, y] 12y O'2 = OT(O2 , O 1) = Ins[3, y] x1y2 (O2) x12y(O' 2) O' 1 = OT(O1 , O 2) = Ins[0, x] x12y(O 1) x12y(O' 1) Site 1 Site 2 12 12 O1= Ins[0, x] x12 O2= Ins[2, y] 12y x1y2 O2in order: execute O2 O1out of order: 1. undo O2 2. execute O1 3. redo O2 x1y2

(a) Operational transformation for preserving both intention and convergence

(b) Serialization for preserving convergence only

Figure 1.6: Operational transformation versus serialization

An example is given to show how operational transformation technique can be used to preserve intention and convergence. As shown in Figure 1.6(a), the shared document initially contains characters 1 and 2, replicated at two sitesSite 1 andSite 2. Site 1performs an operationO1 =Ins[0, x] to insert characterxat position 0 (i.e.,

before character 1) whileSite 2concurrently performs another operationO2 =Ins[2,

y] to insert character y at position 2 (i.e., after character 2). Because O2 k O1, when

the transformation function O0

2 = IT(O2,O1) = Ins[3, y] before execution. Because

CTO2 tCTO1 withCTO2 =CTO1 =12, the precondition ofIT(O2,O1) has been met.

As a result, execution of O0

2 on the current document state x12 is able to preserve

O2’s intention of inserting charactery after character 2, and preserve convergence in

the document state x12y. In contrast, if O2 were executed as-is, character y would

be inserted before character 2, which violates O2’s intention and leads to divergent

document states: x1y2 atSite 1 and x12y at Site 2.

By comparison, if optimistic serialization is applied to the same example, pre- suming O1 is totally before O2 according to the global ordering, Figure 1.6(b) shows

how convergence is maintained while intention is not preserved. When O2 arrives at

Site 1, it is in the correct order and therefore is executed as-is, leading to the result that character y has been inserted before character 2, which apparently violatesO2’s

intention. When O1 arrives at Site 2, it is out of the order. So O2 is first undone,

then O1 is executed, and finally O2 is redone. O2 inserted charactery after character

2, but when it is undone and then redone, it inserts character y before character 2, which apparently violates O2’s intention. Nevertheless, the two sites are convergent

since their document states are the same: x1y2.