当前位置: 首页>>代码示例>>C#>>正文


C# Data.SourceReplicationInformation类代码示例

本文整理汇总了C#中Raven.Bundles.Replication.Data.SourceReplicationInformation的典型用法代码示例。如果您正苦于以下问题:C# SourceReplicationInformation类的具体用法?C# SourceReplicationInformation怎么用?C# SourceReplicationInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SourceReplicationInformation类属于Raven.Bundles.Replication.Data命名空间,在下文中一共展示了SourceReplicationInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnGet

		private void OnGet(IHttpContext context, string src)
		{
			using (Database.DisableAllTriggersForCurrentThread())
			{
				var document = Database.Get(Constants.RavenReplicationSourcesBasePath + "/" + src, null);

				SourceReplicationInformation sourceReplicationInformation;

				Guid serverInstanceId = Database.TransactionalStorage.Id; // this is my id, sent to the remote serve

				if (document == null)
				{
					sourceReplicationInformation = new SourceReplicationInformation()
					{
						Source = src
					};
				}
				else
				{
					sourceReplicationInformation = document.DataAsJson.JsonDeserialization<SourceReplicationInformation>();
					sourceReplicationInformation.ServerInstanceId = serverInstanceId;
				}

				var currentEtag = context.Request.QueryString["currentEtag"];
				log.Debug("Got replication last etag request from {0}: [Local: {1} Remote: {2}]", src,
						  sourceReplicationInformation.LastDocumentEtag, currentEtag);
				context.WriteJson(sourceReplicationInformation);
			}
		}
开发者ID:robashton,项目名称:ravendb,代码行数:29,代码来源:ReplicationLastEtagResponder.cs

示例2: HandleSource

		private ReplicationTopologySourceNode HandleSource(SourceReplicationInformation source)
		{
			if (from.Contains(source.Source))
			{
				var state = CheckSourceConnectionState(source.Source);
				switch (state)
				{
					case ReplicatonNodeState.Online:
						return ReplicationTopologySourceNode.Online(source.Source, source.ServerInstanceId, source.LastDocumentEtag, source.LastAttachmentEtag);
					case ReplicatonNodeState.Offline:
						return ReplicationTopologySourceNode.Offline(source.Source, source.ServerInstanceId, source.LastDocumentEtag, source.LastAttachmentEtag);
					default:
						throw new NotSupportedException(state.ToString());
				}
			}

			string error;
			ReplicationTopologyRootNode rootNode;
			if (TryGetSchema(source.Source, new RavenConnectionStringOptions(), out rootNode, out error))
			{
				var node = ReplicationTopologySourceNode.Online(source.Source, source.ServerInstanceId, source.LastDocumentEtag, source.LastAttachmentEtag);
				node.Destinations = rootNode.Destinations;
				node.Sources = rootNode.Sources;
				node.Errors = rootNode.Errors;

				return node;
			}

			var offline = ReplicationTopologySourceNode.Online(source.Source, source.ServerInstanceId, source.LastDocumentEtag, source.LastAttachmentEtag);

			if (string.IsNullOrEmpty(error) == false)
				offline.Errors.Add(error);

			return offline;
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:35,代码来源:ReplicationTopologyDiscoverer.cs

示例3: Respond

		public override void Respond(IHttpContext context)
		{
			var src = context.Request.QueryString["from"];
			var currentEtag = context.Request.QueryString["currentEtag"];
			if (string.IsNullOrEmpty(src))
			{
				context.SetStatusToBadRequest();
				return;
			}
			while (src.EndsWith("/"))
				src = src.Substring(0, src.Length - 1);// remove last /, because that has special meaning for Raven
			if (string.IsNullOrEmpty(src))
			{
				context.SetStatusToBadRequest();
				return;
			}
			using (Database.DisableAllTriggersForCurrentThread())
			{
				var document = Database.Get(ReplicationConstants.RavenReplicationSourcesBasePath + "/" + src, null);

				SourceReplicationInformation sourceReplicationInformation;

				if (document == null)
				{
					sourceReplicationInformation = new SourceReplicationInformation()
					{
						ServerInstanceId = Database.TransactionalStorage.Id
					};
				}
				else
				{
					sourceReplicationInformation = document.DataAsJson.JsonDeserialization<SourceReplicationInformation>();
					sourceReplicationInformation.ServerInstanceId = Database.TransactionalStorage.Id;
				}

				log.Debug("Got replication last etag request from {0}: [Local: {1} Remote: {2}]", src, 
					sourceReplicationInformation.LastDocumentEtag, currentEtag);
				context.WriteJson(sourceReplicationInformation);
			}
		}
开发者ID:neiz,项目名称:ravendb,代码行数:40,代码来源:ReplicationLastEtagResponser.cs

示例4: 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;
		}
开发者ID:robashton,项目名称:ravendb,代码行数:40,代码来源:ReplicationTask.cs

示例5: 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;
		}
开发者ID:robashton,项目名称:ravendb,代码行数:35,代码来源:ReplicationTask.cs

示例6: GetJsonDocuments

		private RavenJArray GetJsonDocuments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
		{
			RavenJArray jsonDocuments = null;
			try
			{
				var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

				docDb.TransactionalStorage.Batch(actions =>
				{
					int docsSinceLastReplEtag = 0;
					List<JsonDocument> docsToReplicate;
					List<JsonDocument> filteredDocsToReplicate;
					Guid lastDocumentEtag = destinationsReplicationInformationForSource.LastDocumentEtag;
					while (true)
					{
						docsToReplicate = actions.Documents.GetDocumentsAfter(lastDocumentEtag, 100).ToList();
						filteredDocsToReplicate = docsToReplicate.Where(document => destination.FilterDocuments(document, destinationId)).ToList();

						docsSinceLastReplEtag += docsToReplicate.Count;

						if (docsToReplicate.Count == 0 || 
							filteredDocsToReplicate.Count != 0)
						{
							break;
						}

						JsonDocument jsonDocument = docsToReplicate.Last();
						Debug.Assert(jsonDocument.Etag != null);
						Guid documentEtag = jsonDocument.Etag.Value;
						log.Debug("All the docs were filtered, trying another batch from etag [>{0}]", docsToReplicate);
						lastDocumentEtag = documentEtag;
					}

					log.Debug(() =>
					{
						if (docsSinceLastReplEtag == 0)
							return string.Format("Nothing to replicate to {0} - last replicated etag: {1}", destination,
							                     destinationsReplicationInformationForSource.LastDocumentEtag);
											 
						if(docsSinceLastReplEtag == filteredDocsToReplicate.Count)
							return string.Format("Replicating {0} docs [>{1}] to {2}.",
											 docsSinceLastReplEtag,
											 destinationsReplicationInformationForSource.LastDocumentEtag,
											 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),
											 destinationsReplicationInformationForSource.LastDocumentEtag);
					});

					jsonDocuments = 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 jsonDocuments;
		}
开发者ID:neiz,项目名称:ravendb,代码行数:69,代码来源:ReplicationTask.cs

示例7: GetJsonDocuments

		private RavenJArray GetJsonDocuments(SourceReplicationInformation destinationsReplicationInformationForSource)
		{
			RavenJArray jsonDocuments = null;
			try
			{
				var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

				docDb.TransactionalStorage.Batch(actions =>
				{
					jsonDocuments = new RavenJArray(actions.Documents.GetDocumentsAfter(destinationsReplicationInformationForSource.LastDocumentEtag)
						.Where(x => x.Key.StartsWith("Raven/") == false) // don't replicate system docs
						.Where(x => x.Metadata.Value<string>(ReplicationConstants.RavenReplicationSource) != destinationId) // prevent replicating back to source
						.Where(x=> x.Metadata[ReplicationConstants.RavenReplicationConflict] == null) // don't replicate conflicted documents, that just propgate the conflict
						.Select(x=>
						{
							DocumentRetriever.EnsureIdInMetadata(x);
							return x;
						})
						.Take(100)
						.Select(x => x.ToJson()));
				});
			}
			catch (Exception e)
			{
				log.WarnException("Could not get documents to replicate after: " + destinationsReplicationInformationForSource.LastDocumentEtag, e);
			}
			return jsonDocuments;
		}
开发者ID:richSourceShaper,项目名称:ravendb,代码行数:28,代码来源:ReplicationTask.cs

示例8: GetJsonDocuments

		private JsonDocumentsToReplicate GetJsonDocuments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination, ReplicationStatisticsRecorder.ReplicationStatisticsRecorderScope scope)
		{
			var result = new JsonDocumentsToReplicate();
			try
			{
				var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

				docDb.TransactionalStorage.Batch(actions =>
				{
					var lastEtag = 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.Documents.GetRecentTouchesFor(document.Key);
									if (info != null)
									{
										if (info.TouchedEtag.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.TouchedEtag);
											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));
						result.CountOfFilteredDocumentsWhichOriginFromDestination +=
							docsToReplicate.Count(doc => destination.OriginsFromDestination(destinationId, doc.Metadata));

						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);
					});

					scope.Record(new RavenJObject
					{
						{"StartEtag", lastEtag.ToString()},
						{"EndEtag", result.LastEtag.ToString()},
						{"Count", docsSinceLastReplEtag},
						{"FilteredCount", filteredDocsToReplicate.Count}
					});

					docDb.WorkContext.MetricsCounters.GetReplicationBatchSizeMetric(destination).Mark(docsSinceLastReplEtag);
					docDb.WorkContext.MetricsCounters.GetReplicationBatchSizeHistogram(destination).Update(docsSinceLastReplEtag);

					result.Documents = new RavenJArray(filteredDocsToReplicate
						.Select(x =>
						{
							DocumentRetriever.EnsureIdInMetadata(x);
							return x;
						})
						.Select(x => x.ToJson()));
				});
//.........这里部分代码省略.........
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:101,代码来源:ReplicationTask.cs

示例9: GetJsonDocuments

		private JsonDocumentsToReplicate GetJsonDocuments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
		{
			var result = new JsonDocumentsToReplicate();
			try
			{
				var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

				docDb.TransactionalStorage.Batch(actions =>
				{
					int docsSinceLastReplEtag = 0;
					List<JsonDocument> docsToReplicate;
					List<JsonDocument> filteredDocsToReplicate;
					result.LastEtag = destinationsReplicationInformationForSource.LastDocumentEtag;
					while (true)
					{
						docsToReplicate = actions.Documents.GetDocumentsAfter(result.LastEtag, 100, 1024*1024*10)
							.Concat(actions.Lists.Read("Raven/Replication/Docs/Tombstones", result.LastEtag, 100)
								        .Select(x => new JsonDocument
								        {
									        Etag = x.Etag,
									        Key = x.Key,
									        Metadata = x.Data,
									        DataAsJson = new RavenJObject()
								        }))
							.OrderBy(x => x.Etag)
							.ToList();

						filteredDocsToReplicate =
							docsToReplicate.Where(document => destination.FilterDocuments(destinationId, document.Key, document.Metadata)).
								ToList();

						docsSinceLastReplEtag += docsToReplicate.Count;
						result.AllFilteredDocumentsAreSystemDocuments =
							docsToReplicate.All(doc => destination.IsSystemDocumentId(doc.Key));

						if (docsToReplicate.Count == 0 || filteredDocsToReplicate.Count != 0)
						{
							break;
						}

						JsonDocument jsonDocument = docsToReplicate.Last();
						Debug.Assert(jsonDocument.Etag != null);
						Guid documentEtag = jsonDocument.Etag.Value;
						log.Debug("All the docs were filtered, trying another batch from etag [>{0}]", documentEtag);
						result.LastEtag = documentEtag;
					}

					log.Debug(() =>
					{
						if (docsSinceLastReplEtag == 0)
							return string.Format("No documents to replicate to {0} - last replicated etag: {1}", destination,
												 destinationsReplicationInformationForSource.LastDocumentEtag);

						if (docsSinceLastReplEtag == filteredDocsToReplicate.Count)
							return string.Format("Replicating {0} docs [>{1}] to {2}.",
											 docsSinceLastReplEtag,
											 destinationsReplicationInformationForSource.LastDocumentEtag,
											 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),
											 destinationsReplicationInformationForSource.LastDocumentEtag);
					});

					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;
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:83,代码来源:ReplicationTask.cs

示例10: GetAttachments

		private RavenJArray GetAttachments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
		{
			RavenJArray jsonAttachments = null;
			try
			{
				string destinationInstanceId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();
				
				docDb.TransactionalStorage.Batch(actions =>
				{
					jsonAttachments = new RavenJArray(actions.Attachments.GetAttachmentsAfter(destinationsReplicationInformationForSource.LastAttachmentEtag)
						.Where(destination.FilterAttachments)
						// we don't replicate stuff that was created there
						.Where(x=>x.Metadata.Value<string>(ReplicationConstants.RavenReplicationSource) != destinationInstanceId)
						.Take(100)
						.Select(x => new RavenJObject
						{
							{"@metadata", x.Metadata},
							{"@id", x.Key},
							{"@etag", x.Etag.ToByteArray()},
							{"data", actions.Attachments.GetAttachment(x.Key).Data().ReadData()}
						}));
				});
			}
			catch (Exception e)
			{
				log.WarnException("Could not get documents to replicate after: " + destinationsReplicationInformationForSource.LastAttachmentEtag, e);
			}
			return jsonAttachments;
		}
开发者ID:friism,项目名称:ravendb,代码行数:29,代码来源:ReplicationTask.cs

示例11: GetJsonDocuments

		private RavenJArray GetJsonDocuments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
		{
			RavenJArray jsonDocuments = null;
			try
			{
				var destinationId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

				docDb.TransactionalStorage.Batch(actions =>
				{
					jsonDocuments = new RavenJArray(actions.Documents.GetDocumentsAfter(destinationsReplicationInformationForSource.LastDocumentEtag)
						.Where(destination.FilterDocuments)
						.Where(x => x.Metadata.Value<string>(ReplicationConstants.RavenReplicationSource) != destinationId) // prevent replicating back to source
						.Select(x=>
						{
							DocumentRetriever.EnsureIdInMetadata(x);
							return x;
						})
						.Take(100)
						.Select(x => x.ToJson()));
				});
			}
			catch (Exception e)
			{
				log.WarnException("Could not get documents to replicate after: " + destinationsReplicationInformationForSource.LastDocumentEtag, e);
			}
			return jsonDocuments;
		}
开发者ID:friism,项目名称:ravendb,代码行数:27,代码来源:ReplicationTask.cs

示例12: ReplicateAttachments

        private bool? ReplicateAttachments(string destination, SourceReplicationInformation sourceReplicationInformation)
        {
            var attachments = GetAttachments(sourceReplicationInformation.LastAttachmentEtag);

            if (attachments == null || attachments.Count == 0)
                return null;

            if (TryReplicationAttachments(destination, attachments) == false)// failed to replicate, start error handling strategy
            {
                if (IsFirstFailue(destination))
                {
                    log.InfoFormat(
                        "This is the first failure for {0}, assuming transinet failure and trying again",
                        destination);
                    if (TryReplicationAttachments(destination, attachments))// success on second faile
                        return true;
                }
                IncrementFailureCount(destination);
                return false;
            }

            return true;
        }
开发者ID:dplaskon,项目名称:ravendb,代码行数:23,代码来源:ReplicationTask.cs

示例13: GetAttachments

		private RavenJArray GetAttachments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
		{
			RavenJArray jsonAttachments = null;
			try
			{
				string destinationInstanceId = destinationsReplicationInformationForSource.ServerInstanceId.ToString();

				docDb.TransactionalStorage.Batch(actions =>
				{
					jsonAttachments = new RavenJArray(actions.Attachments.GetAttachmentsAfter(destinationsReplicationInformationForSource.LastAttachmentEtag,100)
						.Where(information => destination.FilterAttachments(information, destinationInstanceId))
						.Select(x => new RavenJObject
						{
							{"@metadata", x.Metadata},
							{"@id", x.Key},
							{"@etag", x.Etag.ToByteArray()},
							{"data", actions.Attachments.GetAttachment(x.Key).Data().ReadData()}
						}));
				});
			}
			catch (Exception e)
			{
				log.WarnException("Could not get attachments to replicate after: " + destinationsReplicationInformationForSource.LastAttachmentEtag, e);
			}
			return jsonAttachments;
		}
开发者ID:neiz,项目名称:ravendb,代码行数:26,代码来源:ReplicationTask.cs

示例14: ReplicateAttachments

		private bool? ReplicateAttachments(ReplicationStrategy destination, SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStatisticsRecorder.ReplicationStatisticsRecorderScope recorder)
		{
			Tuple<RavenJArray, Etag> tuple;
			RavenJArray attachments;

			using (var scope = recorder.StartRecording("Get"))
			{
				tuple = GetAttachments(destinationsReplicationInformationForSource, destination, scope);
				attachments = tuple.Item1;

				if (attachments == null || attachments.Length == 0)
				{
					if (tuple.Item2 != destinationsReplicationInformationForSource.LastAttachmentEtag)
					{
						SetLastReplicatedEtagForServer(destination, lastAttachmentEtag: tuple.Item2);
					}
					return null;
				}
			}

			using (var scope = recorder.StartRecording("Send"))
			{
				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;
						}
					}

					scope.RecordError(lastError);
					RecordFailure(destination.ConnectionStringOptions.Url, lastError);
					return false;
				}
			}

			RecordSuccess(destination.ConnectionStringOptions.Url,
				lastReplicatedEtag: tuple.Item2);

			return true;
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:46,代码来源:ReplicationTask.cs

示例15: GetAttachments

		private Tuple<RavenJArray, Guid> GetAttachments(SourceReplicationInformation destinationsReplicationInformationForSource, ReplicationStrategy destination)
		{
			RavenJArray attachments = null;
			Guid lastAttachmentEtag = Guid.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 = actions.Attachments.GetAttachmentsAfter(lastAttachmentEtag, 100, 1024 * 1024 * 10)
							.Concat(actions.Lists.Read(Constants.RavenReplicationAttachmentsTombstones, lastAttachmentEtag, 100)
										.Select(x => new AttachmentInformation
										{
											Key = x.Key,
											Etag = x.Etag,
											Metadata = x.Data,
											Size = 0,
										}))
							.OrderBy(x => x.Etag)

							.ToList();

						filteredAttachmentsToReplicate = attachmentsToReplicate.Where(attachment => destination.FilterAttachments(attachment, destinationId)).ToList();

						attachmentSinceLastEtag += attachmentsToReplicate.Count;

						if (attachmentsToReplicate.Count == 0 ||
							filteredAttachmentsToReplicate.Count != 0)
						{
							break;
						}

						AttachmentInformation jsonDocument = attachmentsToReplicate.Last();
						Guid 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);
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:90,代码来源:ReplicationTask.cs


注:本文中的Raven.Bundles.Replication.Data.SourceReplicationInformation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。