Answered by:
Metadata store replica is already in use!!!

Question
-
Hi,
I am trying to find the changes in a large folder using sync provider for files. I am getting "Metadata store replica is already in use" exception when I am calling the Synchronize() method of SyncOrchestrator.
I am first detecting the changes. After detecting the changes I am calling the Synchronize() method. Both the providers are set to preview mode to find the changes between source and destination.
The error is thrown only for folders with large number of files. Folder size is not less than 600MB. But it contains around 15000 files and 800 folders.
For the folders with less files it works without any problem.
Following are the exact error details.
OuterException Stack Trace:
Microsoft.Synchronization.SyncException: The Metadata Store replica is already in use.\r\n ---> System.Runtime.InteropServices.COMException (0x80041282): The Metadata Store replica is already in use.\r\n\r\n at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)\r\n at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, Int32& changesApplied, Int32& changesFailed)\r\n --- End of inner exception stack trace ---\r\n at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, IS
yncProvider sourceProxy, ISyncProvider destinationProxy, Int32& changesApplied, Int32& changesFailed)\r\n at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)\r\n at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()\r\n at Microsoft.Synchronization.SyncOrchestrator.Synchronize()\r\n at RemotingServerClient.FullPushSync.PreviewSyncFolders(String source, String dest) in C:\\Nilesh\\Development\\FullPushFinal\\RemotingServer\\ServerClient\\FullPushSync.cs:line 285
InnerException Stack Trace:
System.Runtime.InteropServices.COMException (0x80041282): The Metadata Store replica is already in use.
at Microsoft.Synchronization.CoreInterop.ISyncSession.Start(CONFLICT_RESOLUTION_POLICY resolutionPolicy, _SYNC_SESSION_STATISTICS& pSyncSessionStatistics)
at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, Int32& changesApplied, Int32& changesFailed)
Can you please help in in solving this problem.
Thanks,
Nilesh Patel
- Moved by Max Wang_1983 Thursday, April 21, 2011 9:46 PM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
Friday, June 13, 2008 6:51 AM
Answers
-
Answering very specifically the question about why the file was deleted in the sample - we did that just to start the sample afresh each time and we can start with a clean state everytime. Any real-world provider needs to keep metadata state between sync's so that incremental sync's take place correctly everytime.
Thanks
Deepa
- Proposed as answer by Patrick S. Lee Wednesday, February 18, 2009 12:31 AM
- Marked as answer by Liam Cavanagh - MSFTMicrosoft employee Friday, March 6, 2009 6:03 PM
Tuesday, August 26, 2008 5:49 PMAnswerer
All replies
-
You mentioned you are first detecting the changes.
In this step, if you have opened a SqlMetastore instance, Please check whether you have called Dispose() for it later.
Friday, June 13, 2008 8:39 PMAnswerer -
I've also had the Metadata store replica is already in use error. My problem was that i wasn't using a cleanup function at the start of the sync (or end). Whenever files are synced a Metadata file and File Id are created and then synced between source and destination. In order to sync again those 2 files must be deleted. So the very first sync will work fine but all other syncs won't unless the existing Metadata and File Id files are deleted. Hope this helps!Monday, August 18, 2008 6:04 AM
-
Thanks for your suggestion, in fact I too solved this problem exactly what you have suggested. But If we have to delete and recreate the meta data file every time then what's the benefit in it. On the successive run it agains checks for the differences and eventually takes more time, which it could have saved using the existing meta-data file.
I am not sure whether its a bug or in appropriate coding on ourselves but I tested for the same with Sync Toy 2.0 (Beta) and there its working fine. Still wonder why the MS samples are able to bypass such situations!!!
Neway, Let me know if you came across any better solution.
Thanks,
Nilesh
Monday, August 18, 2008 4:14 PM -
Hi Nilesh -
You are right - deleting and recreating the store file on each sync has no benefit to your sync. You do not have to do this. The error basically indicates that the metadata file is open and you have already accessed the replica which has NOT been closed. Everytime you are done using the metadata file you need to call Dispose() on it when you are done to ensure that the store file is closed.
Thanks
Deepa
Thursday, August 21, 2008 7:39 PMAnswerer -
Thanks Deepa,
Actually I am calling the dispose method on the sync provider objects. But I think its not closing the metadata file. Metadata file is created and managed by this provider in its definition, I am not creating my own inherited class to perform the operations. Following is what I am doing.
Code SnippetFileSyncProvider sourceReplica = null;
FileSyncProvider destReplica = null;try
{
sourceReplica = new FileSyncProvider(Guid.NewGuid(), source, fileFilter, FileSyncOptions.CompareFileStreams,
metadataDirectorySource, metadataFileSource,
tempDirectorySource, conflictLoserDirectorySource);
destReplica = new FileSyncProvider(Guid.NewGuid(), dest, fileFilter, FileSyncOptions.CompareFileStreams,
metadataDirectoryDest, metadataFileDest,
tempDirectoryDest, conflictLoserDirectoryDest);sourceReplica.DetectChanges();
destReplica.DetectChanges();
//Apply the change
syncAgent = new SyncOrchestrator();
syncAgent.LocalProvider = sourceReplica;
syncAgent.RemoteProvider = destReplica;
syncAgent.Direction = SyncDirectionOrder.Upload;//Exception raised here.
syncAgent.Synchronize();
}
catch(Exception ex)
{
//Exception handling
}
finally
{if (File.Exists(Path.Combine(metadataDirectorySource, metadataFileSource)))
File.Delete(Path.Combine(metadataDirectorySource, metadataFileSource));
if (File.Exists(Path.Combine(metadataDirectoryDest, metadataFileDest)))
File.Delete(Path.Combine(metadataDirectoryDest, metadataFileDest));if (sourceReplica != null)
sourceReplica.Dispose();if (destReplica != null)
destReplica.Dispose();
}Once I call the dispose method of the FileSyncProvider it should release the metada file also. Also when I delete the metadata file its not raising any File Access Exception like, File is in use can not delete. If the metadata file is in use then how come its getting deleted?
Any help would be greatly appreciated.
Thanks,
Nilesh
Friday, August 22, 2008 2:58 PM -
My code is very similar to yours. The Dispose method is very curious. My question has been if the Dispose method is suppossed to release the metadata file, why is there a cleanup function in the Sync101 sample specifically to delete the metadata file? The Sync101 sample is where I got the idea to delete the metadata file after synchronization.Saturday, August 23, 2008 4:03 AM
-
Can you change your code like this and let me know if this works?
{
FileSyncProvider sourceReplica = null;
FileSyncProvider destReplica = null;sourceReplica = new FileSyncProvider(Guid.NewGuid(), source, fileFilter, FileSyncOptions.CompareFileStreams,
metadataDirectorySource, metadataFileSource,
tempDirectorySource, conflictLoserDirectorySource);
destReplica = new FileSyncProvider(Guid.NewGuid(), dest, fileFilter, FileSyncOptions.CompareFileStreams,
metadataDirectoryDest, metadataFileDest,
tempDirectoryDest, conflictLoserDirectoryDest);try
{
sourceReplica.DetectChanges();
destReplica.DetectChanges();
}
finally
{
if(sourceReplica != null) { sourceReplica.Dispose(); sourceReplica = null; }
if(destReplica != null) {destReplica.Dispose(); destReplica = null; }
}
sourceReplica = new FileSyncProvider(Guid.NewGuid(), source, fileFilter, FileSyncOptions.CompareFileStreams,
metadataDirectorySource, metadataFileSource,
tempDirectorySource, conflictLoserDirectorySource);
destReplica = new FileSyncProvider(Guid.NewGuid(), dest, fileFilter, FileSyncOptions.CompareFileStreams,
metadataDirectoryDest, metadataFileDest,
tempDirectoryDest, conflictLoserDirectoryDest);try
{
//Apply the change
syncAgent = new SyncOrchestrator();
syncAgent.LocalProvider = sourceReplica;
syncAgent.RemoteProvider = destReplica;
syncAgent.Direction = SyncDirectionOrder.Upload;//Exception raised here.
syncAgent.Synchronize();
}
catch(Exception ex)
{
//Exception handling
}
finally
{// NB: I am leaving this in here because it works for sample/test code that you want to clean up after
// you are done. But in REAL code that you right to keep two folders in sync - this is incorrect - you
// should not delete the metadata file at the end of each sync.
if (File.Exists(Path.Combine(metadataDirectorySource, metadataFileSource)))
File.Delete(Path.Combine(metadataDirectorySource, metadataFileSource));
if (File.Exists(Path.Combine(metadataDirectoryDest, metadataFileDest)))
File.Delete(Path.Combine(metadataDirectoryDest, metadataFileDest));if (sourceReplica != null)
sourceReplica.Dispose();if (destReplica != null)
destReplica.Dispose();
}}
Tuesday, August 26, 2008 5:45 PMAnswerer -
Answering very specifically the question about why the file was deleted in the sample - we did that just to start the sample afresh each time and we can start with a clean state everytime. Any real-world provider needs to keep metadata state between sync's so that incremental sync's take place correctly everytime.
Thanks
Deepa
- Proposed as answer by Patrick S. Lee Wednesday, February 18, 2009 12:31 AM
- Marked as answer by Liam Cavanagh - MSFTMicrosoft employee Friday, March 6, 2009 6:03 PM
Tuesday, August 26, 2008 5:49 PMAnswerer