Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

On disposal, wait for pending requests to replication information.

Better error handling if we can't save
  • Loading branch information...
commit 86a1f21d219b16175a75d221ac0554e464b86af9 1 parent f34cbe7
@ayende ayende authored
Showing with 27 additions and 16 deletions.
  1. +27 −16 Raven.Client.Lightweight/Connection/ReplicationInformer.cs
View
43 Raven.Client.Lightweight/Connection/ReplicationInformer.cs
@@ -28,7 +28,7 @@ namespace Raven.Client.Connection
/// <summary>
/// Replication and failover management on the client side
/// </summary>
- public class ReplicationInformer
+ public class ReplicationInformer : IDisposable
{
private readonly Logger log = LogManager.GetCurrentClassLogger();
@@ -113,21 +113,18 @@ public Task UpdateReplicationInformationIfNeeded(ServerClient serverClient)
if (conventions.FailoverBehavior == FailoverBehavior.FailImmediately)
return new CompletedTask();
- var taskCopy = refreshReplicationInformationTask;
- if (taskCopy != null)
- return taskCopy;
-
if (lastReplicationUpdate.AddMinutes(5) > SystemTime.UtcNow)
return new CompletedTask();
+
lock (replicationLock)
{
- taskCopy = refreshReplicationInformationTask;
- if (taskCopy != null)
- return taskCopy;
-
if (lastReplicationUpdate.AddMinutes(5) > SystemTime.UtcNow)
return new CompletedTask();
+ var taskCopy = refreshReplicationInformationTask;
+ if (taskCopy != null)
+ return taskCopy;
+
return refreshReplicationInformationTask = Task.Factory.StartNew(() => RefreshReplicationInformation(serverClient))
.ContinueWith(task =>
{
@@ -280,7 +277,6 @@ public void RefreshReplicationInformation(ServerClient commands)
TrySavingReplicationInformationToLocalCache(serverHash, document);
-
var replicationDocument = document.DataAsJson.JsonDeserialization<ReplicationDocument>();
replicationDestinations = replicationDocument.Destinations.Select(x => x.Url)
// filter out replication destination that don't have the url setup, we don't know how to reach them
@@ -313,7 +309,6 @@ private JsonDocument TryLoadReplicationInformationFromLocalCache(string serverHa
{
return stream.ToJObject().ToJsonDocument();
}
-
}
}
catch (Exception e)
@@ -323,16 +318,23 @@ private JsonDocument TryLoadReplicationInformationFromLocalCache(string serverHa
}
}
- private static void TrySavingReplicationInformationToLocalCache(string serverHash, JsonDocument document)
+ private void TrySavingReplicationInformationToLocalCache(string serverHash, JsonDocument document)
{
- using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
+ try
{
- var path = "RavenDB Replication Information For - " + serverHash;
- using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, machineStoreForApplication))
+ using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
{
- document.ToJson().WriteTo(stream);
+ var path = "RavenDB Replication Information For - " + serverHash;
+ using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, machineStoreForApplication))
+ {
+ document.ToJson().WriteTo(stream);
+ }
}
}
+ catch (Exception e)
+ {
+ log.ErrorException("Could not persist the replication information", e);
+ }
}
private static string GetServerHash(ServerClient commands)
@@ -368,6 +370,15 @@ public int GetReadStripingBase()
{
return Interlocked.Increment(ref readStripingBase);
}
+
+ public void Dispose()
+ {
+#if !NET_3_5
+ var replicationInformationTaskCopy = refreshReplicationInformationTask;
+ if (replicationInformationTaskCopy != null)
+ replicationInformationTaskCopy.Wait();
+#endif
+ }
}
/// <summary>
Please sign in to comment.
Something went wrong with that request. Please try again.