Ejemplo n.º 1
0
 public void RaiseNotifications(DocumentChangeNotification obj, RavenJObject metadata)
 {
     Database.TransportState.Send(obj);
     var onDocumentChange = OnDocumentChange;
     if (onDocumentChange != null)
         onDocumentChange(Database, obj, metadata);
 }
Ejemplo n.º 2
0
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			OnDocumentChangeNotification(this, documentChangeNotification);
			foreach (var connectionState in connections)
			{
				connectionState.Value.Send(documentChangeNotification);
			}
		}
Ejemplo n.º 3
0
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			var value = new { Value = documentChangeNotification, Type = "DocumentChangeNotification" };
			if (watchAllDocuments > 0)
			{
				Enqueue(value);
				return;
			}

			if (matchingDocuments.Contains(documentChangeNotification.Id))
			{
				Enqueue(value);
				return;
			}

			var hasPrefix = matchingDocumentPrefixes.Any(x => documentChangeNotification.Id.StartsWith(x, StringComparison.InvariantCultureIgnoreCase));
			if (hasPrefix == false)
				return;

			Enqueue(value);
		}
Ejemplo n.º 4
0
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			var onOnDocumentChangeNotification = OnDocumentChangeNotification;
			if (onOnDocumentChangeNotification != null)
				onOnDocumentChangeNotification(documentChangeNotification);
		}
Ejemplo n.º 5
0
		public void RaiseNotifications(DocumentChangeNotification obj)
		{
			TransportState.Send(obj);
			var onDocumentChange = OnDocumentChange;
			if (onDocumentChange != null)
				onDocumentChange(this, obj);

		}
Ejemplo n.º 6
0
		private void HandleChangeNotification(DocumentChangeNotification notification)
		{
			if (notification.Id.Equals(DocumentKey, StringComparison.InvariantCulture))
			{
				if (notification.Type == DocumentChangeTypes.Put && notification.Etag != Etag)
				{
					ApplicationModel.Current.AddNotification(
						new Notification("Document " + Key + " was changed on the server"));
				}
				else if (notification.Type == DocumentChangeTypes.Delete)
				{
					ApplicationModel.Current.AddNotification(
						new Notification("Document " + Key + " was deleted on the server"));
				}
			}
		}
Ejemplo n.º 7
0
        public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            WorkContext.MetricsCounters.DocsPerSecond.Mark();
            key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
            RemoveReservedProperties(document);
            RemoveMetadataReservedProperties(metadata);
            Etag newEtag = Etag.Empty;

            using (Database.DocumentLock.Lock())
            {
                TransactionalStorage.Batch(actions =>
                {
                    if (key.EndsWith("/"))
                    {
                        key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions);
                    }
                    AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
                    if (transactionInformation == null)
                    {
                        if (Database.InFlightTransactionalState.IsModified(key))
                            throw new ConcurrencyException("PUT attempted on : " + key +
                                                           " while it is being locked by another transaction");

                        Database.PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));

                        var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
                        newEtag = addDocumentResult.Etag;

                        Database.Indexes.CheckReferenceBecauseOfDocumentUpdate(key, actions);
                        metadata[Constants.LastModified] = addDocumentResult.SavedAt;
                        metadata.EnsureSnapshot(
                            "Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
                        document.EnsureSnapshot(
                            "Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");

                        actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument
                        {
                            Metadata = metadata,
                            Key = key,
                            DataAsJson = document,
                            Etag = newEtag,
                            LastModified = addDocumentResult.SavedAt,
                            SkipDeleteFromIndex = addDocumentResult.Updated == false
                        }, documents =>
                        {
							if(Database.IndexDefinitionStorage.IndexesCount == 0 || Database.WorkContext.RunIndexing == false)
								return;

	                        Database.Prefetcher.AfterStorageCommitBeforeWorkNotifications(PrefetchingUser.Indexer, documents);
                        });

                        if (addDocumentResult.Updated)
                            Database.Prefetcher.AfterUpdate(key, addDocumentResult.PrevEtag);

                        Database.PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));

                        TransactionalStorage
                            .ExecuteImmediatelyOrRegisterForSynchronization(() =>
                            {
                                Database.PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
	                            
								var newDocumentChangeNotification =
		                            new DocumentChangeNotification
		                            {
			                            Id = key,
			                            Type = DocumentChangeTypes.Put,
			                            TypeName = metadata.Value<string>(Constants.RavenClrType),
			                            CollectionName = metadata.Value<string>(Constants.RavenEntityName),
			                            Etag = newEtag
		                            };
	                            
								Database.Notifications.RaiseNotifications(newDocumentChangeNotification, metadata);
                            });

                        WorkContext.ShouldNotifyAboutWork(() => "PUT " + key);
                    }
                    else
                    {
                        var doc = actions.Documents.DocumentMetadataByKey(key);
                        newEtag = Database.InFlightTransactionalState.AddDocumentInTransaction(key, etag, document, metadata,
                                                                                      transactionInformation,
                                                                                      doc == null
                                                                                          ? Etag.Empty
                                                                                          : doc.Etag,
                                                                                      UuidGenerator);
                    }
                });

                Log.Debug("Put document {0} with etag {1}", key, newEtag);
                return new PutResult
                {
                    Key = key,
                    ETag = newEtag
                };
            }
        }
Ejemplo n.º 8
0
        private void OnDocumentChange(DocumentDatabase db, DocumentChangeNotification notification, RavenJObject doc)
        {
            var docId = notification.Id;
            if (docId == null)
                return;

            if (docId.StartsWith(Constants.IndexReplacePrefix, StringComparison.OrdinalIgnoreCase) == false)
                return;

            if (notification.Type != DocumentChangeTypes.Put)
                return;

            var replaceIndexName = docId.Substring(Constants.IndexReplacePrefix.Length);
            var instance = Database.IndexStorage.GetIndexInstance(replaceIndexName);
            if (instance == null)
                return;

            var indexDefinition = Database.Indexes.GetIndexDefinition(replaceIndexName);
            if (indexDefinition == null)
                return;

            var indexToAdd = new IndexToAdd
            {
                Name = replaceIndexName,
                Definition = indexDefinition,
                Priority = instance.Priority,
            };

            SetIndexReplaceInfo(replaceIndexName, indexToAdd);

            StartReplicatingSideBySideIndexAsync(indexToAdd);
        }
Ejemplo n.º 9
0
		public void RaiseNotifications(DocumentChangeNotification obj)
		{
			TransportState.Send(obj);
		}
Ejemplo n.º 10
0
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			OnDocumentChangeNotification(documentChangeNotification);
		}
Ejemplo n.º 11
0
	    public void Send(DocumentChangeNotification documentChangeNotification)
		{
			var value = new { Value = documentChangeNotification, Type = "DocumentChangeNotification" };
			if (watchAllDocuments > 0)
			{
				Enqueue(value);
				return;
			}

			if (documentChangeNotification.Id != null && matchingDocuments.Contains(documentChangeNotification.Id))
			{
				Enqueue(value);
				return;
			}

			var hasPrefix = documentChangeNotification.Id != null && matchingDocumentPrefixes
				.Any(x => documentChangeNotification.Id.StartsWith(x, StringComparison.InvariantCultureIgnoreCase));

			if (hasPrefix)
			{
				Enqueue(value);
				return;
			}

			var hasCollection = documentChangeNotification.CollectionName != null && matchingDocumentsInCollection
				.Any(x => string.Equals(x, documentChangeNotification.CollectionName, StringComparison.InvariantCultureIgnoreCase));

			if (hasCollection)
			{
				Enqueue(value);
				return;
			}

			var hasType = documentChangeNotification.TypeName != null && matchingDocumentsOfType
				.Any(x => string.Equals(x, documentChangeNotification.TypeName, StringComparison.InvariantCultureIgnoreCase));

			if (hasType)
			{
				Enqueue(value);
				return;
			}

			if (documentChangeNotification.Id != null || documentChangeNotification.CollectionName != null || documentChangeNotification.TypeName != null)
			{
				return;
			}

			Enqueue(value);
		}
Ejemplo n.º 12
0
 private void QueueFiller(DocumentChangeNotification notification)
 {
     if (notification.Type == DocumentChangeTypes.Put)
         _queue.Add(notification.Id);
 }
Ejemplo n.º 13
0
 private static void AdjustSleep(DocumentChangeNotification change)
 {
     if (change.Type != DocumentChangeTypes.Put) return;
     LoadSleepConfiguration();
 }