Esempio n. 1
0
 public void DisableDirectWrites()
 {
     if (_scheduler != null)
     {
         _scheduler = null;
         Log.Verbose("API will forward writes to leader");
     }
 }
Esempio n. 2
0
        async Task LeaderMethod(CancellationToken token, CloudPageBlob blob)
        {
            var processors  = Environment.ProcessorCount;
            int parallelism = processors / 2;

            if (parallelism < 1)
            {
                parallelism = 1;
            }
            _log.Information("Node is a leader with {processors} processors. Setting parallelism to {parallelism}",
                             processors,
                             parallelism);
            using (var source = new CancellationTokenSource())
                using (var linked = CancellationTokenSource.CreateLinkedTokenSource(token, source.Token))
                    using (var scheduler = MessageWriteScheduler.Create(_account, parallelism, source)) {
                        try {
                            _log.Information("Message write scheduler created");
                            _api.EnableDirectWrites(scheduler);

                            // tell the world who is the leader
                            await _info.WriteToBlob(_account);

                            // sleep till cancelled
                            await Task.Delay(-1, linked.Token);
                        }
                        catch (OperationCanceledException) {
                            // expect this exception to be thrown in normal circumstances or check the cancellation token, because
                            // if the lease can't be renewed, the token will signal a cancellation request.
                            _log.Information("Shutting down the scheduler");
                            // shutdown the scheduler
                            _api.DisableDirectWrites();


                            var shutdown = scheduler.Shutdown();
                            if (shutdown.Wait(5000))
                            {
                                _log.Information("Scheduler is down");
                            }
                            else
                            {
                                _log.Error("Scheduler failed to shutdown in time");
                            }
                        }
                        finally {
                            _api.DisableDirectWrites();
                            _log.Information("This node is no longer a leader");
                        }
                    }
        }
		public void DisableDirectWrites() {
			if (_scheduler != null) {
				_scheduler = null;
				Log.Verbose("API will forward writes to leader");	
			}
		}
		public void EnableDirectWrites(MessageWriteScheduler scheduler) {
			_scheduler = scheduler;
			Log.Verbose("API will handle writes on this node");
		}
Esempio n. 5
0
 public void EnableDirectWrites(MessageWriteScheduler scheduler)
 {
     _scheduler = scheduler;
     Log.Verbose("API will handle writes on this node");
 }