Esempio n. 1
0
 public void RaiseNotifications(DocumentChangeNotification obj, RavenJObject metadata)
 {
     Database.TransportState.Send(obj);
     var onDocumentChange = OnDocumentChange;
     if (onDocumentChange != null)
         onDocumentChange(Database, obj, metadata);
 }
Esempio n. 2
0
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			OnDocumentChangeNotification(this, documentChangeNotification);
			foreach (var connectionState in connections)
			{
				connectionState.Value.Send(documentChangeNotification);
			}
		}
Esempio 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);
		}
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			var onOnDocumentChangeNotification = OnDocumentChangeNotification;
			if (onOnDocumentChangeNotification != null)
				onOnDocumentChangeNotification(documentChangeNotification);
		}
Esempio n. 5
0
		public void RaiseNotifications(DocumentChangeNotification obj)
		{
			TransportState.Send(obj);
			var onDocumentChange = OnDocumentChange;
			if (onDocumentChange != null)
				onDocumentChange(this, obj);

		}
		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"));
				}
			}
		}
Esempio 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
                };
            }
        }
Esempio 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);
        }
		public void RaiseNotifications(DocumentChangeNotification obj)
		{
			TransportState.Send(obj);
		}
Esempio n. 10
0
		public void Send(DocumentChangeNotification documentChangeNotification)
		{
			OnDocumentChangeNotification(documentChangeNotification);
		}
Esempio 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);
		}
Esempio n. 12
0
 private void QueueFiller(DocumentChangeNotification notification)
 {
     if (notification.Type == DocumentChangeTypes.Put)
         _queue.Add(notification.Id);
 }
Esempio n. 13
0
 private static void AdjustSleep(DocumentChangeNotification change)
 {
     if (change.Type != DocumentChangeTypes.Put) return;
     LoadSleepConfiguration();
 }