Example #1
0
 public void Send(IndexChangeNotification indexChangeNotification)
 {
     OnIndexChangeNotification(this, indexChangeNotification);
     foreach (var connectionState in connections)
     {
         connectionState.Value.Send(indexChangeNotification);
     }
 }
Example #2
0
        public void Send(IndexChangeNotification indexChangeNotification)
        {
            var onOnIndexChangeNotification = OnIndexChangeNotification;

            if (onOnIndexChangeNotification != null)
            {
                onOnIndexChangeNotification(indexChangeNotification);
            }
        }
Example #3
0
 public void OnNext(IndexChangeNotification change)
 {
     if (change.Type == IndexChangeTypes.MapCompleted ||
         change.Type == IndexChangeTypes.ReduceCompleted ||
         change.Type == IndexChangeTypes.IndexRemoved)
     {
         evictCacheOldItems(databaseName);
     }
 }
        public void RaiseNotifications(IndexChangeNotification indexChangeNotification)
        {
            OnIndexChange?.Invoke(indexChangeNotification);

            foreach (var connection in Connections)
            {
                connection.Value.SendIndexChanges(indexChangeNotification);
            }
        }
Example #5
0
        public void RaiseNotifications(IndexChangeNotification obj)
        {
            Database.TransportState.Send(obj);
            var onIndexChange = OnIndexChange;

            if (onIndexChange != null)
            {
                onIndexChange(Database, obj);
            }
        }
Example #6
0
        public void SendIndexChanges(IndexChangeNotification notification)
        {
            if (_watchAllIndexes > 0)
            {
                Send(notification);
                return;
            }

            if (notification.Name != null && _matchingIndexes.Contains(notification.Name))
            {
                Send(notification);
                return;
            }
        }
Example #7
0
        private void OnIndexChange(DocumentDatabase documentDatabase, IndexChangeNotification eventArgs)
        {
            switch (eventArgs.Type)
            {
            case IndexChangeTypes.IndexAdded:
                //if created index with the same name as deleted one, we should prevent its deletion replication
                database.TransactionalStorage.Batch(
                    accessor =>
                {
                    var li = accessor.Lists.Read(Constants.RavenReplicationIndexesTombstones, eventArgs.Name);
                    if (li == null)
                    {
                        return;
                    }
                    int version;
                    string versionStr = li.Data.Value <string>("IndexVersion");
                    if (int.TryParse(versionStr, out version))
                    {
                        if (eventArgs.Version.HasValue && version < eventArgs.Version.Value)
                        {
                            accessor.Lists.Remove(Constants.RavenReplicationIndexesTombstones, eventArgs.Name);
                        }
                    }
                    else
                    {
                        Log.Error("Failed to parse index version of index {0}", eventArgs.Name);
                    }
                });
                break;

            case IndexChangeTypes.IndexRemoved:
                //If we don't have any destination to replicate to (we are probably slave node)
                //we shouldn't keep a tombstone since we are not going to remove it anytime
                //and keeping it prevents us from getting that index created again.
                if (replication.GetReplicationDestinations().Length == 0)
                {
                    return;
                }
                var metadata = new RavenJObject
                {
                    { Constants.RavenIndexDeleteMarker, true },
                    { Constants.RavenReplicationSource, database.TransactionalStorage.Id.ToString() },
                    { Constants.RavenReplicationVersion, ReplicationHiLo.NextId(database) },
                    { "IndexVersion", eventArgs.Version }
                };

                database.TransactionalStorage.Batch(accessor => accessor.Lists.Set(Constants.RavenReplicationIndexesTombstones, eventArgs.Name, metadata, UuidType.Indexing));
                break;
            }
        }
Example #8
0
        public void Send(IndexChangeNotification indexChangeNotification)
        {
            if (watchAllIndexes > 0)
            {
                Enqueue(new { Value = indexChangeNotification, Type = "IndexChangeNotification" });
                return;
            }

            if (matchingIndexes.Contains(indexChangeNotification.Name) == false)
            {
                return;
            }

            Enqueue(new { Value = indexChangeNotification, Type = "IndexChangeNotification" });
        }
Example #9
0
        private void OnIndexChange(IndexChangeNotification notification)
        {
            if (notification.Type != IndexChangeTypes.IndexAdded &&
                notification.Type != IndexChangeTypes.IndexRemoved)
            {
                return;
            }

            if (_log.IsInfoEnabled)
            {
                _log.Info($"Received index {notification.Type} event, index name = {notification.Name}, etag = {notification.Etag}");
            }

            if (IncomingReplicationHandler.IsIncomingReplicationThread)
            {
                return;
            }
            _waitForChanges.Set();
        }
Example #10
0
        private void OnIndexChange(DocumentDatabase documentDatabase, IndexChangeNotification notification)
        {
            var indexName = notification.Name;

            switch (notification.Type)
            {
            case IndexChangeTypes.IndexAdded:
                //if we created index with the same name as deleted one, we should prevent its deletion replication
                Database.TransactionalStorage.Batch(accessor =>
                                                    accessor.Lists.Remove(Constants.RavenReplicationIndexesTombstones, indexName));
                break;

            case IndexChangeTypes.IndexRemoved:
                var indexDefinition = Database.IndexDefinitionStorage.GetIndexDefinition(indexName);
                if (indexDefinition != null)
                {
                    //the side by side index was deleted
                    IndexToAdd _;
                    sideBySideIndexesToReplicate.TryRemove(indexDefinition.IndexId, out _);
                }

                //If we don't have any destination to replicate to (we are probably slave node)
                //we shouldn't keep a tombstone since we are not going to remove it anytime
                //and keeping it prevents us from getting that index created again.
                if (GetReplicationDestinations().Count == 0)
                {
                    return;
                }

                var metadata = new RavenJObject
                {
                    { Constants.RavenIndexDeleteMarker, true },
                    { Constants.RavenReplicationSource, Database.TransactionalStorage.Id.ToString() },
                    { Constants.RavenReplicationVersion, ReplicationHiLo.NextId(Database) },
                    { IndexDefinitionStorage.IndexVersionKey, notification.Version }
                };

                Database.TransactionalStorage.Batch(accessor => accessor.Lists.Set(Constants.RavenReplicationIndexesTombstones, indexName, metadata, UuidType.Indexing));
                break;
            }
        }
Example #11
0
        private void Send(IndexChangeNotification notification)
        {
            var value = new DynamicJsonValue
            {
                ["Type"]  = "IndexChangeNotification",
                ["Value"] = new DynamicJsonValue
                {
                    [nameof(IndexChangeNotification.Etag)] = notification.Etag,
                    [nameof(IndexChangeNotification.Name)] = notification.Name,
                    [nameof(IndexChangeNotification.Type)] = notification.Type.ToString()
                }
            };

            if (_disposeToken.IsCancellationRequested == false)
            {
                _sendQueue.Enqueue(new NotificationValue
                {
                    ValueToSend = value,
                    AllowSkip   = notification.Type == IndexChangeTypes.BatchCompleted //TODO: make sure it makes sense
                });
            }
        }
Example #12
0
 public void RaiseNotifications(IndexChangeNotification obj)
 {
     Database.TransportState.Send(obj);
 }
 public void Send(IndexChangeNotification indexChangeNotification)
 {
     OnIndexChangeNotification?.Invoke(indexChangeNotification);
 }