locked
Mapping remote knowledge to local RRS feed

  • Question

  • Greetings,

    I've got an MSF v1.0 custom KnowledgeSyncProvider and a custom metadata store. I'm attempting to determine local changes based on the knowledge from a remote replica. How do I know what has changed? It's not at all clear how ReplicaKeyMap is created and used by SyncKnowledge to map the remote clock vectors to local versions. Where does this information get tracked/stored in the metadata? Why can't I create a ReplicaKeyMap which could map existing knowledge of the remote replica?

    Thanks!
    • Moved by Max Wang_1983 Thursday, April 21, 2011 1:08 AM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Thursday, August 6, 2009 8:25 PM

Answers

  • I've figured out a way to do this.  It works, but not documented by MS.  The "knowledge" is for the remote peer.

     

    ulong? localTickCount = null;

     

    ulong remoteTickCount = knowledge.FindMinTickCountForReplica(knowledge.ReplicaId);

     

    foreach (Range rs in new KnowledgeFragmentInspector(knowledge).ScopeRangeSet)

    {

     

    foreach (IClockVectorElement k in rs.ClockVector)

    {

     

    if (k.TickCount != remoteTickCount)

    localTickCount = k.TickCount;

    }

    }

    • Marked as answer by codekaizen Monday, August 10, 2009 1:52 PM
    Sunday, August 9, 2009 11:47 PM

All replies

  • I've figured out a way to do this.  It works, but not documented by MS.  The "knowledge" is for the remote peer.

     

    ulong? localTickCount = null;

     

    ulong remoteTickCount = knowledge.FindMinTickCountForReplica(knowledge.ReplicaId);

     

    foreach (Range rs in new KnowledgeFragmentInspector(knowledge).ScopeRangeSet)

    {

     

    foreach (IClockVectorElement k in rs.ClockVector)

    {

     

    if (k.TickCount != remoteTickCount)

    localTickCount = k.TickCount;

    }

    }

    • Marked as answer by codekaizen Monday, August 10, 2009 1:52 PM
    Sunday, August 9, 2009 11:47 PM
  • Ah, well done!

    I knew the SyncKnowledge instance from the destination had what I needed, since calling ToString() on it printed it out... I just couldn't figure out how to get the Range. Nice find indeed!

    Thanks,
    -rory
    Monday, August 10, 2009 1:52 PM
  • SyncKnowledge mappedRemoteKnowledge = localKnowledge.MapRemoteKnowledgeToLocal(remoteKnowledge);
    foreach(Item item in store.Items)
    {
    	if (!mappedRemoteKnowledge.Contains(localReplicaId, item.GlobalId, item.CurrentVersion))
    	{
    		AddToChangeBatch(batch, item);
    	}
    }
    
    The above code sample is to detect changes on local side. MapRemoteKnowledgeToLocal() did the mapping of remote clock vectors to local version. The mappedRemoteKnowledge has a same ReplicaKeyMap as localKnowledge so it is safe to do Contains() check against local items.
    Microsoft Sync Framework
    Tuesday, August 11, 2009 9:54 PM
  • Xiongbo,

    In your code sample, how and where could I get the "localKnowledge" and "store" instance?  When SqlSyncProvider is used.

    Thanks,

    Michael
    Tuesday, August 11, 2009 11:46 PM
  • Michael,

    The code sample is for change enumeration on KnowledgeSyncProvider. If you are using SqlSyncProvider, it doesn't have the "store" concept since its end point is Database and provider's knowledge is stored as part of sync metadata that will be managed by SqlSyncProvider internally. In other words, SqlSyncProvider will handle change enumeration and users won't have to get instance of local knowledge and store and do change enumeration by themselves.
    Microsoft Sync Framework
    Wednesday, August 12, 2009 8:41 PM
  • Lu -

    I'm trying to avoid doing a full enumeration. That's why I want the range - to start enumerating at the end of the last range. There appears to be no way to do this with "MapRemoteKnowledgeToLocal" - correct?

    -rory
    Thursday, August 13, 2009 5:45 PM
  • Ah, sadly KnowledgeFrameworkInspector is only in v2.0, which isn't yet out for devices.

    MS: any word on Sync v2.0 on devices? Need some help getting that done?
    Thursday, August 13, 2009 6:04 PM