3.1.4.3 Algorithm for Creating the ChangeSetEntryList for a Participant Given Another Participant’s Destination Knowledge

The inputs for this algorithm are the following:

  • DestinationKnowledge: The SYNC_KNOWLEDGE structure provided by the destination replica with which this Participant is synchronizing.

  • FileItemList: The list of zero or more FileItemEntries describing the detailed version state known for each item in the replica managed by this Participant.

  • ReplicaList: The list of one or more ReplicaEntries providing ReplicaKey to ReplicaGid mapping for all replicas from the synchronization community known by this Participant. This list will always have an entry for the replica managed by this Participant and this entry is always the first entry in the list. The ReplicaKey used by other data structures to identify a ReplicaEntry is the index into this list, with the first index being assigned the value of 0.

On completion, the Participant store MUST return:

  • ChangeSetEntryList: The list of changes known by this replica that are not yet known by the destination replica.

The algorithm uses the following local variables:

  • SYNC_KNOWLEDGE structure DestinationSyncKnowledge.

  • Integer value (initialized to 0) CurrentRangeIndex, CurrentReplicaKey, DestinationReplicaKey, DestinationReplicaKeyFound, CurrentClockVector, CurrentClockVectorElementIndex

  • Boolean value AddToChangeList.

  • RANGE value ItemRange.

Pseudocode for the operation is as follows:

  • Set DestinationSyncKnowledge to DestinationKnowledge.

  • Clear all current entries in the ChangeSetEntryList.

  • For each FileItemEntry in the FileItemList:

  • Set AddToChangeList to FALSE.

  • Set CurrentRangeIndex to 0.

  • While CurrentRangeIndex < DestinationSyncKnowledge.RangeSetTable.RangeSet[0].NumEntries:

    • If FileItemEntry.SyncGid > DestinationSyncKnowledge.RangeSetTable.RangeSet[0].Ranges[CurrentRangeIndex].SyncGid:

      • Set CurrentRangeIndex to CurrentRangeIndex + 1.

    • Else

      • Break while loop.

    • End If

  • End While

  • Set ItemRange to DestinationSyncKnowledge.RangeSetTable.RangeSets[0].Ranges[CurrentRangeIndex].

  • Set ItemChangeReplicaGid to ReplicaList[FileItemEntry].ChangeReplicaKey.

  • Set CurrentReplicaKey to 0.

  • Set DestinationReplicaKey to 0.

  • While CurrentReplicaKey < DestinationSyncKnowledge.ReplicaKeyMap.ReplicaKeys.NumEntries:

    • If ItemChangeReplicaGid == DestinationSyncKnowledge. ReplicaKeyMap.ReplicaKeys.ReplicaGids[CurrentReplicaKey]:

      • Set DestinationReplicaKey to CurrentReplicaKey.

      • Set DestinationReplicaKeyFound to TRUE.

      • Break while loop.

    • Else

      • Set CurrentReplicaKey to CurrentReplicaKey + 1.

    • End If

  • End While

  • If DestinationReplicaKeyFound is TRUE:

    • Set CurrentClockVector to DestinationSyncKnowledge.ClockVectorTable.ClockVectorEntries[DestinationItemRange.ClockTableVectorIndex].

    • Set CurrentClockVectorElementIndex to 0.

    • Set DestinationReplicaKeyFound to FALSE.

    • While CurrentClockVectorElementIndex < CurrentClockVector.ClockVectorElementEntries.NumElements:

      • If CurrentClockVector.ClockVectorElementEntries.ClockVectorElement[CurrentClockVectorElementIndex].ReplicaKey == DestinationReplicaKey:

        • Set DestinationReplicaKeyFound to TRUE.

        • If CurrentClockVector.ClockVectorElementEntries.ClockVectorElement[CurrentClockVectorElementIndex].TickCount < FileItemEntry.ChangeTickCount:

        • Set AddToChangeList to TRUE.

        • End If.

      • Else:

        • Set CurrentClockVectorElementIndex to CurrentClockVectorElementIndex + 1.

      • End If.

    • End While.

    • If DestinationReplicaKeyFound is FALSE

      • Set AddToChangeList to TRUE.

    • End If.

  • Else:

    • Set AddToChangeList to TRUE.

  • End If

  • If AddToChangeList == TRUE:

    • Add a new ChangeSetEntry to the ChangeSetEntryList with the following values:

    • Set ChangeSetEntry.ReplicaGid to ReplicaList[0].ReplicaGid.

    • Set ChangeSetEntry.ChangeReplicaKey to FileItemEntry.ChangeReplicaKey.

    • Set ChangeSetEntry.ChangeTickCount to FileItemEntry.ChangeTickcount.

    • Set ChangeSetEntry.CreateReplicaKey to FileItemEntry.CreateReplicaKey.

    • Set ChangeSetEntry.CreateTickCount to FileItemEntry.CreateTickCount.

    • Set ChangeSetEntry.SyncGid to FileItemEntry.SyncGid.

    • Set ChangeSetEntry.WinnerExists to FileItemEntry.WinnerExists.

    • Set ChangeSetEntry.WinnerSyncGid to FileItemEntry.WinningFileItem.

    • If FileItemEntry.IsDeleted == TRUE:

      • Set ChangeSetEntry.SyncChange to 0x00000001.

    • Else

      • Set ChangeSetEntry.SyncChange to 0x00000000.

    • End If

  • End If

  • End For