Asked by:
Metadata store replica already in use, still!

Question
-
Hi,
Got a slightly infuriating, but not entirely uncommon problem which has been brought up before however not solved in a way that works in my application.
I have a method which does the following:
public void InitiateSync() { FileSyncProvider sourceReplica; FileSyncProvider destReplica; SyncOrchestrator so; String MetaDataDirectory = "./Metadata"; sourceReplica = new FileSyncProvider(this.LocalDirectory, this.filter, this.options, MetaDataDirectory, "source.metadata", Path.GetTempPath(), this.ConflictDirectory); destReplica = new FileSyncProvider( this.RemoteDirectory, this.filter, this.options, MetaDataDirectory, "remote.metadata", Path.GetTempPath(), this.ConflictDirectory); so = new SyncOrchestrator(); try { so.LocalProvider = sourceReplica; so.RemoteProvider = destReplica; so.Direction = SyncDirectionOrder.DownloadAndUpload; // Explicitly detect changes on both replicas upfront, to avoid two change // detection passes for the two-way sync //sourceReplica.DetectChanges(); //destReplica.DetectChanges(); so.Synchronize(); OnComplete(); // Fire the Complete event to notify clients } catch (Exception e) { OnError("Sync Exception: " + e.ToString()); // notify clients of an error } finally { if (sourceReplica != null) { sourceReplica.Dispose(); sourceReplica = null; } if (destReplica != null) { destReplica.Dispose(); destReplica = null; } } }
I am getting a ReplicaMetadataInUseException thrown at me, either from the constructors of FileSyncProvider, or by SyncOrchestrator.Synchronize(). It appears to mainly happen if one of the replicas change when my application is not running. Why this makes any difference I don't know - the FileSyncProvider objects should be garbage collected as soon as the method ends, and I have .Dispose()'d them and even set them to null (as recommended in the other post, Metadata store replica is already in use!!!)So it looks like something is not closing the metadata store properly when I'm disposing of the FileSyncProvider objects. As you can see, it's just the standard builtin metadata source, which to make life a bit easier I'm putting in a specified local directory.
Also, there's definitely not any other processes accessing the metadata stores.
I've also looked at Overcome Error: "The metadata store replica is already in use" which also hasn't really helped a lot.
Thanks!
Wednesday, November 30, 2011 3:23 AM
All replies
-
Hi,
I got stuck with similar issue (Metadata store replica is already in use) details as below
I am using one power shell script to synchronize users profiles' IE favorite content to a particualr folder in his/her home profile path in file server.
I have Download and install Microsoft Sync Framework 2.1(x86 or x64) from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=19502 with following sequence: Install 1 and then 2
- Synchronization.msi: includes managed and native API for the synchronization runtime, core components, and Web synchronization components. This package is a pre-requisite for the other packages and must be installed first.
- ProviderServices.msi: includes managed and native API for simple custom providers, the file synchronization provider, the metadata storage service, and also DLLs for the lightweight database that the storage service uses.
I have also used the .dispose() fundtion to release resources, but not result.
My script is as below:-
##################################################################################
# Powershell script Syncing IE favorites #
# Using Microsoft Sync Framework 2.1 #
# #
##################################################################################
#---------------------------------------------------------------------------------
#Global varables here
$LocalIEFavoritesFolder = $env:Userprofile + "\Favorites"
$ServerIEFavoritesFolder = "F:\syscfg\IE\Favorites"[reflection.assembly]::LoadWithPartialName('Microsoft.Synchronization')| Out-Null
[reflection.assembly]::LoadWithPartialName('Microsoft.Synchronization.Files')| Out-Null
$filter = New-Object Microsoft.Synchronization.Files.FileSyncScopeFilter
$filter.FileNameIncludes.Add("*.url")
$options = [Microsoft.Synchronization.Files.FileSyncOptions]::ExplicitDetectChanges
#$options = $options -bor [Microsoft.Synchronization.Files.FileSyncOptions]::RecycleDeletedFiles
#$options = $options -bor [Microsoft.Synchronization.Files.FileSyncOptions]::RecyclePreviousFileOnUpdates
$options = $options -bor [Microsoft.Synchronization.Files.FileSyncOptions]::RecycleConflictLoserFiles$LocalIEprovider = new-object Microsoft.Synchronization.Files.FileSyncProvider -ArgumentList $LocalIEFavoritesFolder, $filter, $options
$ServerIEprovider = new-object Microsoft.Synchronization.Files.FileSyncProvider -ArgumentList $ServerIEFavoritesFolder, $filter, $options$agent = New-Object Microsoft.Synchronization.SyncOrchestrator
$agent.LocalProvider = $LocalIEprovider
$agent.RemoteProvider = $ServerIEprovider
#---------------------------------------------------------------------------------
#Functions here
#---------------------------------------------------------------------------------Function SyncServertoLocal
{
$ServerIEprovider.DetectChanges()
$agent.Direction = [Microsoft.Synchronization.SyncDirectionOrder]::Download
$agent.Synchronize();
}Function SyncLocaltoServer
{
$LocalIEprovider.DetectChanges()
$agent.Direction = [Microsoft.Synchronization.SyncDirectionOrder]::Upload
$agent.Synchronize();
}
#---------------------------------------------------------------------------------
#Main
Write-Host "-------------------------------------------------"
Write-Host "[IE Favorites Sync Script.]" -ForegroundColor Yellow
$Runtime = Get-Date -Format sif ((get-ItemProperty "HKCU:\Software\TestDom\System\").IEFavoritesLastRun -eq $Null){
New-Item "HKCU:\Software\TestDom\" -ErrorAction SilentlyContinue
New-Item "HKCU:\Software\TestDom\System\" -ErrorAction SilentlyContinue
New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesLastRun" -Value $Runtime -PropertyType "String" -ErrorAction SilentlyContinue
New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesScriptVersion" -Value "3" -PropertyType "String" -ErrorAction SilentlyContinue
$LastRun = Get-Date
}
else{
$LastRun = (get-ItemProperty "HKCU:\Software\TestDom\System\").IEFavoritesLastRun
$LastRun = [DateTime]::Parse($LastRun, $(Get-culture))
}if (((Get-Date) - $LastRun).TotalMinutes -gt 45){
if (Test-Path "F:\syscfg\IE" -PathType Container){
$Null = New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesLastRun" -Value $Runtime -PropertyType "String" -ErrorAction SilentlyContinue -Force
$Null = New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesScriptVersion" -Value "3" -PropertyType "String" -ErrorAction SilentlyContinue -Force
Write-Host "[Online Sync Started]" -ForegroundColor Yellow
Write-Host "-------------------------------------------------"
Write-Host "Running: Local to server sync"
SyncLocaltoServer
sleep -Seconds 5
Write-Host "-------------------------------------------------"
Write-Host "Running: Server to local sync."
SyncServertoLocal
Write-Host "-------------------------------------------------"
}Else{
Write-Host "[Offline Sync Cancelled]" -ForegroundColor Yellow
Write-Host "-------------------------------------------------"
}
}
Else{
Write-Host "[Sync Just Run This run Cancelled]" -ForegroundColor Yellow
Write-Host "-------------------------------------------------"
}# Powershell script Syncing IE favorites #
# Using Microsoft Sync Framework 2.1 #
# #
##################################################################################
#---------------------------------------------------------------------------------
#Global varables here
$LocalIEFavoritesFolder = $env:Userprofile + "\Favorites"
$ServerIEFavoritesFolder = "F:\syscfg\IE\Favorites"[reflection.assembly]::LoadWithPartialName('Microsoft.Synchronization')| Out-Null
[reflection.assembly]::LoadWithPartialName('Microsoft.Synchronization.Files')| Out-Null
$filter = New-Object Microsoft.Synchronization.Files.FileSyncScopeFilter
$filter.FileNameIncludes.Add("*.url")
$options = [Microsoft.Synchronization.Files.FileSyncOptions]::ExplicitDetectChanges
#$options = $options -bor [Microsoft.Synchronization.Files.FileSyncOptions]::RecycleDeletedFiles
#$options = $options -bor [Microsoft.Synchronization.Files.FileSyncOptions]::RecyclePreviousFileOnUpdates
$options = $options -bor [Microsoft.Synchronization.Files.FileSyncOptions]::RecycleConflictLoserFiles$LocalIEprovider = new-object Microsoft.Synchronization.Files.FileSyncProvider -ArgumentList $LocalIEFavoritesFolder, $filter, $options
$ServerIEprovider = new-object Microsoft.Synchronization.Files.FileSyncProvider -ArgumentList $ServerIEFavoritesFolder, $filter, $options$agent = New-Object Microsoft.Synchronization.SyncOrchestrator
$agent.LocalProvider = $LocalIEprovider
$agent.RemoteProvider = $ServerIEprovider
#---------------------------------------------------------------------------------
#Functions here
#---------------------------------------------------------------------------------Function SyncServertoLocal
{
$ServerIEprovider.DetectChanges()
$agent.Direction = [Microsoft.Synchronization.SyncDirectionOrder]::Download
$agent.Synchronize();
}Function SyncLocaltoServer
{
$LocalIEprovider.DetectChanges()
$agent.Direction = [Microsoft.Synchronization.SyncDirectionOrder]::Upload
$agent.Synchronize();
}
#---------------------------------------------------------------------------------
#Main
Write-Host "-------------------------------------------------"
Write-Host "[IE Favorites Sync Script.]" -ForegroundColor Yellow
$Runtime = Get-Date -Format sif ((get-ItemProperty "HKCU:\Software\TestDom\System\").IEFavoritesLastRun -eq $Null){
New-Item "HKCU:\Software\TestDom\" -ErrorAction SilentlyContinue
New-Item "HKCU:\Software\TestDom\System\" -ErrorAction SilentlyContinue
New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesLastRun" -Value $Runtime -PropertyType "String" -ErrorAction SilentlyContinue
New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesScriptVersion" -Value "3" -PropertyType "String" -ErrorAction SilentlyContinue
$LastRun = Get-Date
}
else{
$LastRun = (get-ItemProperty "HKCU:\Software\TestDom\System\").IEFavoritesLastRun
$LastRun = [DateTime]::Parse($LastRun, $(Get-culture))
}if (((Get-Date) - $LastRun).TotalMinutes -gt 45){
if (Test-Path "F:\syscfg\IE" -PathType Container){
$Null = New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesLastRun" -Value $Runtime -PropertyType "String" -ErrorAction SilentlyContinue -Force
$Null = New-ItemProperty "HKCU:\Software\TestDom\System\" -Name "IEFavoritesScriptVersion" -Value "3" -PropertyType "String" -ErrorAction SilentlyContinue -Force
Write-Host "[Online Sync Started]" -ForegroundColor Yellow
Write-Host "-------------------------------------------------"
Write-Host "Running: Local to server sync"
SyncLocaltoServer
sleep -Seconds 5
Write-Host "-------------------------------------------------"
Write-Host "Running: Server to local sync."
SyncServertoLocal
Write-Host "-------------------------------------------------"
}Else{
Write-Host "[Offline Sync Cancelled]" -ForegroundColor Yellow
Write-Host "-------------------------------------------------"
}
}
Else{
Write-Host "[Sync Just Run This run Cancelled]" -ForegroundColor Yellow
Write-Host "-------------------------------------------------"
}Thankswsoumen
Soumen Ghosh
Thursday, February 16, 2012 10:28 AM