本文整理汇总了C#中Raven.Bundles.Replication.Tasks.ReplicationStrategy类的典型用法代码示例。如果您正苦于以下问题:C# ReplicationStrategy类的具体用法?C# ReplicationStrategy怎么用?C# ReplicationStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReplicationStrategy类属于Raven.Bundles.Replication.Tasks命名空间,在下文中一共展示了ReplicationStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplicateTo
private bool ReplicateTo(ReplicationStrategy destination)
{
try
{
if (docDb.Disposed)
return false;
using (docDb.DisableAllTriggersForCurrentThread())
using (var stats = new ReplicationStatisticsRecorder(destination, destinationStats))
{
SourceReplicationInformation destinationsReplicationInformationForSource;
using (var scope = stats.StartRecording("Destination"))
{
try
{
destinationsReplicationInformationForSource = GetLastReplicatedEtagFrom(destination);
if (destinationsReplicationInformationForSource == null)
return false;
scope.Record(RavenJObject.FromObject(destinationsReplicationInformationForSource));
}
catch (Exception e)
{
scope.RecordError(e);
log.WarnException("Failed to replicate to: " + destination, e);
return false;
}
}
bool? replicated = null;
using (var scope = stats.StartRecording("Documents"))
{
switch (ReplicateDocuments(destination, destinationsReplicationInformationForSource, scope))
{
case true:
replicated = true;
break;
case false:
return false;
}
}
using (var scope = stats.StartRecording("Attachments"))
{
switch (ReplicateAttachments(destination, destinationsReplicationInformationForSource, scope))
{
case true:
replicated = true;
break;
case false:
return false;
}
}
return replicated ?? false;
}
}
finally
{
var holder = activeReplicationTasks.GetOrAdd(destination.ConnectionStringOptions.Url, new IntHolder());
Thread.VolatileWrite(ref holder.Value, 0);
}
}
示例2: TryReplicationAttachments
private bool TryReplicationAttachments(ReplicationStrategy destination, RavenJArray jsonAttachments, out string errorMessage)
{
try
{
var url = destination.ConnectionStringOptions.Url + "/replication/replicateAttachments?from=" +
UrlEncodedServerUrl() + "&dbid=" + docDb.TransactionalStorage.Id;
var sp = Stopwatch.StartNew();
using (HttpRavenRequestFactory.Expect100Continue(destination.ConnectionStringOptions.Url))
{
var request = httpRavenRequestFactory.Create(url, "POST", destination.ConnectionStringOptions, GetRequestBuffering(destination));
request.WriteBson(jsonAttachments);
request.ExecuteRequest(docDb.WorkContext.CancellationToken);
log.Info("Replicated {0} attachments to {1} in {2:#,#;;0} ms", jsonAttachments.Length, destination, sp.ElapsedMilliseconds);
errorMessage = "";
return true;
}
}
catch (WebException e)
{
HandleRequestBufferingErrors(e, destination);
var response = e.Response as HttpWebResponse;
if (response != null)
{
using (var streamReader = new StreamReader(response.GetResponseStreamWithHttpDecompression()))
{
var error = streamReader.ReadToEnd();
try
{
var ravenJObject = RavenJObject.Parse(error);
log.WarnException("Replication to " + destination + " had failed\r\n" + ravenJObject.Value<string>("Error"), e);
errorMessage = error;
return false;
}
catch (Exception)
{
}
log.WarnException("Replication to " + destination + " had failed\r\n" + error, e);
errorMessage = error;
}
}
else
{
log.WarnException("Replication to " + destination + " had failed", e);
errorMessage = e.Message;
}
return false;
}
catch (Exception e)
{
log.WarnException("Replication to " + destination + " had failed", e);
errorMessage = e.Message;
return false;
}
}
示例3: TryReplicationDocuments
private bool TryReplicationDocuments(ReplicationStrategy destination, RavenJArray jsonDocuments, out string lastError)
{
try
{
log.Debug("Starting to replicate {0} documents to {1}", jsonDocuments.Length, destination);
var url = destination.ConnectionStringOptions.Url + "/replication/replicateDocs?from=" + UrlEncodedServerUrl()
+ "&dbid=" + docDb.TransactionalStorage.Id +
"&count=" + jsonDocuments.Length;
var sp = Stopwatch.StartNew();
using (HttpRavenRequestFactory.Expect100Continue(destination.ConnectionStringOptions.Url))
{
var request = httpRavenRequestFactory.Create(url, "POST", destination.ConnectionStringOptions, GetRequestBuffering(destination));
request.Write(jsonDocuments);
request.ExecuteRequest(docDb.WorkContext.CancellationToken);
log.Info("Replicated {0} documents to {1} in {2:#,#;;0} ms", jsonDocuments.Length, destination, sp.ElapsedMilliseconds);
lastError = "";
return true;
}
}
catch (WebException e)
{
HandleRequestBufferingErrors(e, destination);
var response = e.Response as HttpWebResponse;
if (response != null)
{
var responseStream = response.GetResponseStream();
if (responseStream != null)
{
using (var streamReader = new StreamReader(responseStream))
{
var error = streamReader.ReadToEnd();
log.WarnException("Replication to " + destination + " had failed\r\n" + error, e);
}
}
else
{
log.WarnException("Replication to " + destination + " had failed", e);
}
}
else
{
log.WarnException("Replication to " + destination + " had failed", e);
}
lastError = e.Message;
return false;
}
catch (Exception e)
{
log.WarnException("Replication to " + destination + " had failed", e);
lastError = e.Message;
return false;
}
}
示例4: UpdateReplicationPerformance
private void UpdateReplicationPerformance(ReplicationStrategy destination, DateTime startTime, TimeSpan elapsed, int batchSize)
{
if (batchSize > 0)
{
var queue = docDb.WorkContext.MetricsCounters.GetReplicationPerformanceStats(destination);
queue.Enqueue(new ReplicationPerformanceStats
{
Duration = elapsed,
Started = startTime,
BatchSize = batchSize
});
while (queue.Count() > 25)
{
ReplicationPerformanceStats _;
queue.TryDequeue(out _);
}
}
}
示例5: ReplicateDocuments
private bool? ReplicateDocuments(ReplicationStrategy destination, SourceReplicationInformationWithBatchInformation destinationsReplicationInformationForSource, ReplicationStatisticsRecorder.ReplicationStatisticsRecorderScope recorder, out int replicatedDocuments)
{
replicatedDocuments = 0;
JsonDocumentsToReplicate documentsToReplicate = null;
var sp = Stopwatch.StartNew();
IDisposable removeBatch = null;
var prefetchingBehavior = prefetchingBehaviors.GetOrAdd(destination.ConnectionStringOptions.Url,
x => docDb.Prefetcher.CreatePrefetchingBehavior(PrefetchingUser.Replicator, autoTuner, string.Format("Replication for URL: {0}" ,destination.ConnectionStringOptions.DefaultDatabase) ));
prefetchingBehavior.AdditionalInfo = string.Format("For destination: {0}. Last replicated etag: {1}", destination.ConnectionStringOptions.Url, destinationsReplicationInformationForSource.LastDocumentEtag);
try
{
using (var scope = recorder.StartRecording("Get"))
{
documentsToReplicate = GetJsonDocuments(destinationsReplicationInformationForSource, destination, prefetchingBehavior, scope);
if (documentsToReplicate.Documents == null || documentsToReplicate.Documents.Length == 0)
{
if (documentsToReplicate.LastEtag != destinationsReplicationInformationForSource.LastDocumentEtag)
{
// we don't notify remote server about updates to system docs, see: RavenDB-715
if (documentsToReplicate.CountOfFilteredDocumentsWhichAreSystemDocuments == 0
|| documentsToReplicate.CountOfFilteredDocumentsWhichAreSystemDocuments > SystemDocsLimitForRemoteEtagUpdate
|| documentsToReplicate.CountOfFilteredDocumentsWhichOriginFromDestination > DestinationDocsLimitForRemoteEtagUpdate) // see RavenDB-1555
{
using (scope.StartRecording("Notify"))
{
SetLastReplicatedEtagForServer(destination, lastDocEtag: documentsToReplicate.LastEtag);
scope.Record(new RavenJObject
{
{ "LastDocEtag", documentsToReplicate.LastEtag.ToString() }
});
}
}
}
RecordLastEtagChecked(destination.ConnectionStringOptions.Url, documentsToReplicate.LastEtag);
return null;
}
}
// if the db is idling in all respect except sending out replication, let us keep it that way.
docDb.WorkContext.UpdateFoundWork();
removeBatch = prefetchingBehavior.UpdateCurrentlyUsedBatches(documentsToReplicate.LoadedDocs);
using (var scope = recorder.StartRecording("Send"))
{
string lastError;
if (TryReplicationDocuments(destination, documentsToReplicate.Documents, out lastError) == false) // failed to replicate, start error handling strategy
{
if (IsFirstFailure(destination.ConnectionStringOptions.Url))
{
log.Info(
"This is the first failure for {0}, assuming transient failure and trying again",
destination);
if (TryReplicationDocuments(destination, documentsToReplicate.Documents, out lastError)) // success on second fail
{
RecordSuccess(destination.ConnectionStringOptions.Url, documentsToReplicate.LastEtag, documentsToReplicate.LastLastModified);
return true;
}
}
// if we had an error sending to this endpoint, it might be because we are sending too much data, or because
// the request timed out. This will let us know that the next time we try, we'll use just the initial doc counts
// and we'll be much more conservative with increasing the sizes
prefetchingBehavior.OutOfMemoryExceptionHappened();
scope.RecordError(lastError);
RecordFailure(destination.ConnectionStringOptions.Url, lastError);
return false;
}
}
}
finally
{
if (documentsToReplicate != null && documentsToReplicate.LoadedDocs != null)
{
prefetchingBehavior.UpdateAutoThrottler(documentsToReplicate.LoadedDocs, sp.Elapsed);
replicatedDocuments = documentsToReplicate.LoadedDocs.Count;
}
if (removeBatch != null)
removeBatch.Dispose();
}
RecordSuccess(destination.ConnectionStringOptions.Url, documentsToReplicate.LastEtag, documentsToReplicate.LastLastModified);
return true;
}
示例6: CreateReplicationStrategyFromDocument
private static ReplicationStrategy CreateReplicationStrategyFromDocument(ReplicationDestination x, ReplicationStrategy replicationStrategy)
{
var url = x.Url;
if (string.IsNullOrEmpty(x.Database) == false)
{
url = url + "/databases/" + x.Database;
}
replicationStrategy.ConnectionStringOptions = new RavenConnectionStringOptions
{
Url = url,
ApiKey = x.ApiKey,
AuthenticationScheme = x.AuthenticationScheme
};
if (string.IsNullOrEmpty(x.Username) == false)
{
replicationStrategy.ConnectionStringOptions.Credentials = string.IsNullOrEmpty(x.Domain)
? new NetworkCredential(x.Username, x.Password)
: new NetworkCredential(x.Username, x.Password, x.Domain);
}
return replicationStrategy;
}
示例7: IsNotFailing
private bool IsNotFailing(ReplicationStrategy dest, int currentReplicationAttempts)
{
var jsonDocument = docDb.Documents.Get(Constants.RavenReplicationDestinationsBasePath + EscapeDestinationName(dest.ConnectionStringOptions.Url), null);
if (jsonDocument == null)
return true;
var failureInformation = jsonDocument.DataAsJson.JsonDeserialization<DestinationFailureInformation>();
if (failureInformation.FailureCount > 1000)
{
var shouldReplicateTo = currentReplicationAttempts % 10 == 0;
log.Debug("Failure count for {0} is {1}, skipping replication: {2}",
dest, failureInformation.FailureCount, shouldReplicateTo == false);
return shouldReplicateTo;
}
if (failureInformation.FailureCount > 100)
{
var shouldReplicateTo = currentReplicationAttempts % 5 == 0;
log.Debug("Failure count for {0} is {1}, skipping replication: {2}",
dest, failureInformation.FailureCount, shouldReplicateTo == false);
return shouldReplicateTo;
}
if (failureInformation.FailureCount > 10)
{
var shouldReplicateTo = currentReplicationAttempts % 2 == 0;
log.Debug("Failure count for {0} is {1}, skipping replication: {2}",
dest, failureInformation.FailureCount, shouldReplicateTo == false);
return shouldReplicateTo;
}
return true;
}
示例8: ReplicateTo
private bool ReplicateTo(ReplicationStrategy destination)
{
try
{
if (docDb.Disposed)
return false;
using (docDb.DisableAllTriggersForCurrentThread())
using (var stats = new ReplicationStatisticsRecorder(destination, destinationStats))
{
SourceReplicationInformation destinationsReplicationInformationForSource;
using (var scope = stats.StartRecording("Destination"))
{
try
{
destinationsReplicationInformationForSource = GetLastReplicatedEtagFrom(destination);
if (destinationsReplicationInformationForSource == null)
return false;
scope.Record(RavenJObject.FromObject(destinationsReplicationInformationForSource));
}
catch (Exception e)
{
scope.RecordError(e);
log.WarnException("Failed to replicate to: " + destination, e);
return false;
}
}
bool? replicated = null;
using (var scope = stats.StartRecording("Documents"))
{
switch (ReplicateDocuments(destination, destinationsReplicationInformationForSource, scope))
{
case true:
replicated = true;
break;
case false:
return false;
}
}
using (var scope = stats.StartRecording("Attachments"))
{
switch (ReplicateAttachments(destination, destinationsReplicationInformationForSource, scope))
{
case true:
replicated = true;
break;
case false:
return false;
}
}
docDb.WorkContext.MetricsCounters.GetReplicationDurationMetric(destination).Mark((long)stats.ElapsedTime.TotalMilliseconds);
docDb.WorkContext.MetricsCounters.GetReplicationDurationHistogram(destination).Update((long)stats.ElapsedTime.TotalMilliseconds);
return replicated ?? false;
}
}
finally
{
var holder = activeReplicationTasks.GetOrAdd(destination.ConnectionStringOptions.Url, s => new SemaphoreSlim(0,1));
holder.Release();
}
}
示例9: ReplicateDocuments
private bool? ReplicateDocuments(ReplicationStrategy destination, SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStatisticsRecorder.ReplicationStatisticsRecorderScope recorder)
{
JsonDocumentsToReplicate documentsToReplicate;
using (var scope = recorder.StartRecording("Get"))
{
documentsToReplicate = GetJsonDocuments(destinationsReplicationInformationForSource, destination, scope);
if (documentsToReplicate.Documents == null || documentsToReplicate.Documents.Length == 0)
{
if (documentsToReplicate.LastEtag != destinationsReplicationInformationForSource.LastDocumentEtag)
{
// we don't notify remote server about updates to system docs, see: RavenDB-715
if (documentsToReplicate.CountOfFilteredDocumentsWhichAreSystemDocuments == 0
|| documentsToReplicate.CountOfFilteredDocumentsWhichAreSystemDocuments > SystemDocsLimitForRemoteEtagUpdate
|| documentsToReplicate.CountOfFilteredDocumentsWhichOriginFromDestination > DestinationDocsLimitForRemoteEtagUpdate) // see RavenDB-1555
{
using (scope.StartRecording("Notify"))
{
SetLastReplicatedEtagForServer(destination, lastDocEtag: documentsToReplicate.LastEtag);
scope.Record(new RavenJObject
{
{ "LastDocEtag", documentsToReplicate.LastEtag.ToString() }
});
}
}
}
RecordLastEtagChecked(destination.ConnectionStringOptions.Url, documentsToReplicate.LastEtag);
return null;
}
}
using (var scope = recorder.StartRecording("Send"))
{
string lastError;
if (TryReplicationDocuments(destination, documentsToReplicate.Documents, out lastError) == false) // failed to replicate, start error handling strategy
{
if (IsFirstFailure(destination.ConnectionStringOptions.Url))
{
log.Info(
"This is the first failure for {0}, assuming transient failure and trying again",
destination);
if (TryReplicationDocuments(destination, documentsToReplicate.Documents, out lastError)) // success on second fail
{
RecordSuccess(destination.ConnectionStringOptions.Url, documentsToReplicate.LastEtag, documentsToReplicate.LastLastModified);
return true;
}
}
scope.RecordError(lastError);
RecordFailure(destination.ConnectionStringOptions.Url, lastError);
return false;
}
}
RecordSuccess(destination.ConnectionStringOptions.Url, documentsToReplicate.LastEtag, documentsToReplicate.LastLastModified);
return true;
}
示例10: GetJsonDocuments
private JsonDocumentsToReplicate GetJsonDocuments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
{
var result = new JsonDocumentsToReplicate();
try
{
var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();
docDb.TransactionalStorage.Batch(actions =>
{
var synchronizationEtag = etagSynchronizer.GetSynchronizationEtag();
var lastEtag = etagSynchronizer.CalculateSynchronizationEtag(
synchronizationEtag,
destinationsReplicationInformationForSource.LastDocumentEtag);
int docsSinceLastReplEtag = 0;
List<JsonDocument> docsToReplicate;
List<JsonDocument> filteredDocsToReplicate;
result.LastEtag = lastEtag;
while (true)
{
docsToReplicate = GetDocsToReplicate(actions, result);
filteredDocsToReplicate =
docsToReplicate
.Where(document =>
{
var info = docDb.GetRecentTouchesFor(document.Key);
if (info != null)
{
if (info.PreTouchEtag.CompareTo(result.LastEtag) <= 0)
{
log.Debug("Will not replicate document '{0}' to '{1}' because the updates after etag {2} are related document touches", document.Key, destinationId, info.PreTouchEtag);
return false;
}
}
return destination.FilterDocuments(destinationId, document.Key, document.Metadata) && prefetchingBehavior.FilterDocuments(document);
})
.ToList();
docsSinceLastReplEtag += docsToReplicate.Count;
result.CountOfFilteredDocumentsWhichAreSystemDocuments += docsToReplicate.Count(doc => destination.IsSystemDocumentId(doc.Key));
if (docsToReplicate.Count > 0)
{
var lastDoc = docsToReplicate.Last();
Debug.Assert(lastDoc.Etag != null);
result.LastEtag = lastDoc.Etag;
if (lastDoc.LastModified.HasValue)
result.LastLastModified = lastDoc.LastModified.Value;
}
if (docsToReplicate.Count == 0 || filteredDocsToReplicate.Count != 0)
{
break;
}
log.Debug("All the docs were filtered, trying another batch from etag [>{0}]", result.LastEtag);
}
log.Debug(() =>
{
if (docsSinceLastReplEtag == 0)
return string.Format("No documents to replicate to {0} - last replicated etag: {1}", destination,
lastEtag);
if (docsSinceLastReplEtag == filteredDocsToReplicate.Count)
return string.Format("Replicating {0} docs [>{1}] to {2}.",
docsSinceLastReplEtag,
lastEtag,
destination);
var diff = docsToReplicate.Except(filteredDocsToReplicate).Select(x => x.Key);
return string.Format("Replicating {1} docs (out of {0}) [>{4}] to {2}. [Not replicated: {3}]",
docsSinceLastReplEtag,
filteredDocsToReplicate.Count,
destination,
string.Join(", ", diff),
lastEtag);
});
result.Documents = new RavenJArray(filteredDocsToReplicate
.Select(x =>
{
DocumentRetriever.EnsureIdInMetadata(x);
return x;
})
.Select(x => x.ToJson()));
});
}
catch (Exception e)
{
log.WarnException("Could not get documents to replicate after: " + destinationsReplicationInformationForSource.LastDocumentEtag, e);
}
return result;
}
示例11: GetAttachments
private Tuple<RavenJArray, Etag> GetAttachments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
{
RavenJArray attachments = null;
Etag lastAttachmentEtag = Etag.Empty;
try
{
var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();
docDb.TransactionalStorage.Batch(actions =>
{
int attachmentSinceLastEtag = 0;
List<AttachmentInformation> attachmentsToReplicate;
List<AttachmentInformation> filteredAttachmentsToReplicate;
lastAttachmentEtag = destinationsReplicationInformationForSource.LastAttachmentEtag;
while (true)
{
attachmentsToReplicate = GetAttachmentsToReplicate(actions, lastAttachmentEtag);
filteredAttachmentsToReplicate = attachmentsToReplicate.Where(attachment => destination.FilterAttachments(attachment, destinationId)).ToList();
attachmentSinceLastEtag += attachmentsToReplicate.Count;
if (attachmentsToReplicate.Count == 0 ||
filteredAttachmentsToReplicate.Count != 0)
{
break;
}
AttachmentInformation jsonDocument = attachmentsToReplicate.Last();
Etag attachmentEtag = jsonDocument.Etag;
log.Debug("All the attachments were filtered, trying another batch from etag [>{0}]", attachmentEtag);
lastAttachmentEtag = attachmentEtag;
}
log.Debug(() =>
{
if (attachmentSinceLastEtag == 0)
return string.Format("No attachments to replicate to {0} - last replicated etag: {1}", destination,
destinationsReplicationInformationForSource.LastDocumentEtag);
if (attachmentSinceLastEtag == filteredAttachmentsToReplicate.Count)
return string.Format("Replicating {0} attachments [>{1}] to {2}.",
attachmentSinceLastEtag,
destinationsReplicationInformationForSource.LastDocumentEtag,
destination);
var diff = attachmentsToReplicate.Except(filteredAttachmentsToReplicate).Select(x => x.Key);
return string.Format("Replicating {1} attachments (out of {0}) [>{4}] to {2}. [Not replicated: {3}]",
attachmentSinceLastEtag,
filteredAttachmentsToReplicate.Count,
destination,
string.Join(", ", diff),
destinationsReplicationInformationForSource.LastDocumentEtag);
});
attachments = new RavenJArray(filteredAttachmentsToReplicate
.Select(x =>
{
var data = new byte[0];
if (x.Size > 0)
{
data = actions.Attachments.GetAttachment(x.Key).Data().ReadData();
}
return new RavenJObject
{
{"@metadata", x.Metadata},
{"@id", x.Key},
{"@etag", x.Etag.ToByteArray()},
{"data", data}
};
}));
});
}
catch (Exception e)
{
log.WarnException("Could not get attachments to replicate after: " + destinationsReplicationInformationForSource.LastAttachmentEtag, e);
}
return Tuple.Create(attachments, lastAttachmentEtag);
}
示例12: ReplicateDocuments
private bool? ReplicateDocuments(ReplicationStrategy destination, SourceReplicationInformation destinationsReplicationInformationForSource)
{
var documentsToReplicate = GetJsonDocuments(destinationsReplicationInformationForSource, destination);
if (documentsToReplicate.Documents == null || documentsToReplicate.Documents.Length == 0)
{
if (documentsToReplicate.LastEtag != destinationsReplicationInformationForSource.LastDocumentEtag)
{
// we don't notify remote server about updates to system docs, see: RavenDB-715
if (documentsToReplicate.CountOfFilteredDocumentsWhichAreSystemDocuments == 0 ||
documentsToReplicate.CountOfFilteredDocumentsWhichAreSystemDocuments > 15)
{
SetLastReplicatedEtagForServer(destination, lastDocEtag: documentsToReplicate.LastEtag);
}
}
RecordLastEtagChecked(destination.ConnectionStringOptions.Url,
documentsToReplicate.LastEtag);
return null;
}
string lastError;
if (TryReplicationDocuments(destination, documentsToReplicate.Documents, out lastError) == false)// failed to replicate, start error handling strategy
{
if (IsFirstFailure(destination.ConnectionStringOptions.Url))
{
log.Info(
"This is the first failure for {0}, assuming transient failure and trying again",
destination);
if (TryReplicationDocuments(destination, documentsToReplicate.Documents, out lastError))// success on second fail
{
RecordSuccess(destination.ConnectionStringOptions.Url,
documentsToReplicate.LastEtag, documentsToReplicate.LastLastModified);
return true;
}
}
RecordFailure(destination.ConnectionStringOptions.Url, lastError);
return false;
}
RecordSuccess(destination.ConnectionStringOptions.Url,
documentsToReplicate.LastEtag, documentsToReplicate.LastLastModified);
return true;
}
示例13: ReplicateAttachments
private bool? ReplicateAttachments(ReplicationStrategy destination, SourceReplicationInformation destinationsReplicationInformationForSource)
{
var tuple = GetAttachments(destinationsReplicationInformationForSource, destination);
var attachments = tuple.Item1;
if (attachments == null || attachments.Length == 0)
{
if (tuple.Item2 != destinationsReplicationInformationForSource.LastAttachmentEtag)
{
SetLastReplicatedEtagForServer(destination, lastAttachmentEtag: tuple.Item2);
}
return null;
}
string lastError;
if (TryReplicationAttachments(destination, attachments, out lastError) == false)// failed to replicate, start error handling strategy
{
if (IsFirstFailure(destination.ConnectionStringOptions.Url))
{
log.Info(
"This is the first failure for {0}, assuming transient failure and trying again",
destination);
if (TryReplicationAttachments(destination, attachments, out lastError))// success on second fail
{
RecordSuccess(destination.ConnectionStringOptions.Url, lastReplicatedEtag: tuple.Item2);
return true;
}
}
RecordFailure(destination.ConnectionStringOptions.Url, lastError);
return false;
}
RecordSuccess(destination.ConnectionStringOptions.Url,
lastReplicatedEtag: tuple.Item2);
return true;
}
示例14: ReplicateTo
private bool ReplicateTo(ReplicationStrategy destination)
{
try
{
if (docDb.Disposed)
return false;
using (docDb.DisableAllTriggersForCurrentThread())
{
SourceReplicationInformation destinationsReplicationInformationForSource;
try
{
destinationsReplicationInformationForSource = GetLastReplicatedEtagFrom(destination);
if (destinationsReplicationInformationForSource == null)
return false;
}
catch (Exception e)
{
log.WarnException("Failed to replicate to: " + destination, e);
return false;
}
bool? replicated = null;
switch (ReplicateDocuments(destination, destinationsReplicationInformationForSource))
{
case true:
replicated = true;
break;
case false:
return false;
}
switch (ReplicateAttachments(destination, destinationsReplicationInformationForSource))
{
case true:
replicated = true;
break;
case false:
return false;
}
return replicated ?? false;
}
}
finally
{
var holder = activeReplicationTasks.GetOrAdd(destination.ConnectionStringOptions.Url, new IntHolder());
Thread.VolatileWrite(ref holder.Value, 0);
}
}
示例15: GetLastReplicatedEtagFrom
internal SourceReplicationInformationWithBatchInformation GetLastReplicatedEtagFrom(ReplicationStrategy destination)
{
try
{
Etag currentEtag = Etag.Empty;
docDb.TransactionalStorage.Batch(accessor => currentEtag = accessor.Staleness.GetMostRecentDocumentEtag());
var url = destination.ConnectionStringOptions.Url + "/replication/lastEtag?from=" + UrlEncodedServerUrl() +
"¤tEtag=" + currentEtag + "&dbid=" + docDb.TransactionalStorage.Id;
var request = httpRavenRequestFactory.Create(url, "GET", destination.ConnectionStringOptions);
var lastReplicatedEtagFrom = request.ExecuteRequest<SourceReplicationInformationWithBatchInformation>();
log.Debug("Received last replicated document Etag {0} from server {1}", lastReplicatedEtagFrom.LastDocumentEtag, destination.ConnectionStringOptions.Url);
return lastReplicatedEtagFrom;
}
catch (WebException e)
{
var response = e.Response as HttpWebResponse;
if (response != null && (response.StatusCode == HttpStatusCode.BadRequest || response.StatusCode == HttpStatusCode.NotFound))
log.WarnException("Replication is not enabled on: " + destination, e);
else
log.WarnException("Failed to contact replication destination: " + destination, e);
RecordFailure(destination.ConnectionStringOptions.Url, e.Message);
}
catch (Exception e)
{
log.WarnException("Failed to contact replication destination: " + destination, e);
RecordFailure(destination.ConnectionStringOptions.Url, e.Message);
}
return null;
}