Exemple #1
0
            private void TriggerWatcher(string path, IWatcher newWatcher, WatchedEvent.WatchedEventType type = WatchedEvent.WatchedEventType.WatcherRemoved)
            {
                IWatcher watcher;

                if (this.watchers.TryGetValue(path, out watcher))
                {
                    WatchedEvent evt = new WatchedEvent(type, WatchedEvent.WatchedEventKeeperState.SyncConnected, path);

                    this.ev.PushEvent(this.ToString(evt));

                    if (watcher.Kind.HasFlag(WatcherKind.OneUse))
                    {
                        this.watchers.Remove(path);
                    }

                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        watcher.Process(evt);
                    });
                }

                if (newWatcher != null)
                {
                    this.watchers[path] = newWatcher;
                }
            }
            public void WatcherNotificationReceived(WatchedEvent.WatchedEventType eventType)
            {
                lock (this)
                {
                    this.WatcherNotificationCount++;
                }

                Trace.TraceInformation($"RingMasterClientInstrumentation WatcherNotificationCount={this.WatcherNotificationCount}");
            }
Exemple #3
0
        /// <summary>
        /// Deserialize a <see cref="WatcherCall"/>
        /// </summary>
        /// <returns>A <see cref="WatcherCall"/></returns>
        private WatcherCall DeserializeWatcherCall()
        {
            WatcherCall watcherCall = new WatcherCall();

            watcherCall.WatcherId = this.binaryReader.ReadUInt64();

            if (this.serializationVersionUsed >= SerializationFormatVersions.Version23)
            {
                watcherCall.Kind = (WatcherKind)this.binaryReader.ReadByte();
            }
            else
            {
                watcherCall.Kind = this.binaryReader.ReadBoolean() ? WatcherKind.OneUse : default(WatcherKind);
            }

            bool nullwatcher = this.binaryReader.ReadBoolean();

            if (!nullwatcher)
            {
                WatchedEvent.WatchedEventType        type  = (WatchedEvent.WatchedEventType) this.binaryReader.ReadInt32();
                WatchedEvent.WatchedEventKeeperState state = (WatchedEvent.WatchedEventKeeperState) this.binaryReader.ReadInt32();
                string path = this.binaryReader.ReadString();

                byte[] data = null;
                IStat  stat = null;
                if (this.serializationVersionUsed >= SerializationFormatVersions.Version23)
                {
                    data = this.DeserializeByteArray();
                    stat = this.DeserializeStat();
                }

                watcherCall.WatcherEvt = new WatchedEvent(type, state, path, data, stat);
            }
            else
            {
                watcherCall.WatcherEvt = null;
            }

            return(watcherCall);
        }
Exemple #4
0
        /// <summary>
        /// Installs the bulk watcher.
        /// </summary>
        /// <param name="watchedEventType">the watched event type</param>
        /// <param name="jobState">the job state</param>
        /// <param name="cancellation">The cancellation.</param>
        /// <returns>async task</returns>
        protected async Task InstallBulkWatcher(WatchedEvent.WatchedEventType watchedEventType, JobState jobState, CancellationToken cancellation)
        {
            if (this.WatcherCountPerNode <= 0)
            {
                return;
            }

            this.Log($"installing bulk watchers. Number per node: {this.WatcherCountPerNode}");

            this.watcherTriggerCount = 0;
            var watcher = new CallbackWatcher
            {
                OnProcess = (watchedEvent) =>
                {
                    if (watchedEvent.EventType == watchedEventType)
                    {
                        Interlocked.Increment(ref this.watcherTriggerCount);
                    }
                },
            };

            var startFrom = string.Empty;

            var  clock          = Stopwatch.StartNew();
            long processedCount = 0;

            while (!cancellation.IsCancellationRequested)
            {
                var children = await this.HelperClient.GetChildren($"/{this.RootNodeName}/Instance{this.ServiceContext.ReplicaOrInstanceId}", null, $">:{MaxChildrenCount}:{startFrom}");

                await Helpers.ForEachAsync(
                    children,
                    async (child) =>
                {
                    var subroot = $"/{this.RootNodeName}/Instance{this.ServiceContext.ReplicaOrInstanceId}/{child}";

                    List <Task> addWatcherTasks = new List <Task>();
                    foreach (var watcherClient in this.bulkWatcherClients)
                    {
                        addWatcherTasks.Add(Task.Run(async() =>
                        {
                            await watcherClient.RegisterBulkWatcher(subroot, watcher);
                        }));
                    }

                    await Task.WhenAll(addWatcherTasks);
                    startFrom = child;
                },
                    children.Count);

                processedCount += children.Count;
                Helper.LogAndSetJobStatus(
                    this.Log,
                    jobState,
                    $"Installing bulk watcher. {processedCount} number of nodes processed. Rate: {processedCount * this.clients.Count() / clock.Elapsed.TotalSeconds:G4} /sec");

                if (children.Count < MaxChildrenCount)
                {
                    break;
                }
            }

            this.Log("finished installing bulk watchers");
        }
Exemple #5
0
 public void WatcherNotificationReceived(WatchedEvent.WatchedEventType eventType)
 {
     this.instrumentation?.WatcherNotificationReceived(eventType);
 }