# 2.5 Selecting Changes with Digest

SData uses two passes to synchronize two nodes Nj and Nk: one pass to propagate Nj’s changes to Nk and a second pass in the other direction to propagate Nk’s changes to Nj.

The following table describes how the algorithm selects resources from N1 when synchronizing from N1 to N2, and then how it selects resources from N2 when synchronizing in the other direction.

Direction Node Digest Before Digest After Select clause Comments
N1->N2 N1 (N1 6 1) (N2 7 2) (N3 9 3) (N1 6 1) (N2 7 2) (N3 9 3) SELECT * FROM N1.K WHERE (node = N1 and tick in [5, 6[) or (node = N3 and tick in [8, 9[) The selection criteria only takes into account the pairs that have a higher tick on N1.  For these pairs, the N2 tick is the selection threshold.
N2 (N1 5 1) (N2 8 2) (N3 8 3) (N1 **6** 1) (N2 8 2) (N3 **9** 3)
N2->N1 N1 (N1 6 1) (N2 7 2) (N3 9 3) (N1 6 1) (N2 **8** 2) (N3 9 3) SELECT * FROM N2.K WHERE (node = N2 and tick in [7, 8[) Same as above, reversing the roles of N1 and N2. The digests are equal at the end of the operation.
N2 (N1 6 1) (N2 8 2) (N3 9 3) (N1 6 1) (N2 8 2) (N3 9 3)
The interval tests can be reduced to simple inequality tests. For example, instead of testing for tick in [5, 6[, we could simply test for tick >= 5. The second form is more practical when the resource ticks are incremented at the time the sync pass is run rather than at the time the resource is modified (see Tick Management section because, in this case, the upper bound of the tick is not know until we have scanned all modified resources.

At the end of the bidirectional synchronization, the digests are identical on N1 and N2. Of course, this is only true if resources are not modified concurrently with the synchronization passes.