public StorageMaintenance(IStorageFragment fragment, IStorageManagerService service) { _mode = MaintenanceMode.Normal; _service = service; _fragment = fragment; _lock = new ExclusiveLock(); }
internal void IsEnabled_Should_Not_Lock_If_Lock_None_Is_Provided(MaintenanceLockMode mode) { using (MaintenanceMode.Enable(MaintenanceLockMode.None)) { Assert.False(MaintenanceMode.IsEnabled(mode)); } }
internal void IsEnabledForHttpMethod_Should_Return_True_For_Update_Methods_Full_Lock(string method) { using (MaintenanceMode.Enable(MaintenanceLockMode.Full)) { Assert.True(MaintenanceMode.IsEnabledForHttpMethod(method)); } }
internal void IsEnabledForHttpMethod_Should_Return_False_For_Read_Methods_Write_Only_Lock(string method) { using (MaintenanceMode.Enable(MaintenanceLockMode.Write)) { Assert.False(MaintenanceMode.IsEnabledForHttpMethod(method)); } }
protected void Application_Start() { #if AZURESDK Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.Changed += (s, a) => { Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.RequestRecycle(); }; #endif MaintenanceMode.RefreshIsInMaintainanceMode(); DatabaseSetup.Initialize(); this.container = CreateContainer(); DependencyResolver.SetResolver(new UnityServiceLocator(this.container)); RegisterGlobalFilters(GlobalFilters.Filters); RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); AreaRegistration.RegisterAllAreas(); AppRoutes.RegisterRoutes(RouteTable.Routes); #if AZURESDK if (Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable) { System.Diagnostics.Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener()); System.Diagnostics.Trace.AutoFlush = true; } #endif this.OnStart(); }
internal void Should_Not_Allow_To_Lock_Twice(MaintenanceLockMode mode) { using (MaintenanceMode.Enable(mode)) { var e = Assert.Throws <MaintenanceModeEnabledException>(() => MaintenanceMode.Enable(mode)); Assert.Equal(HttpStatusCode.ServiceUnavailable, e.StatusCode); } }
internal void IsEnabled_Should_Not_Lock_Read_If_Write_Only_Mock_Mode_Is_Provided() { using (MaintenanceMode.Enable(MaintenanceLockMode.Write)) { Assert.True(MaintenanceMode.IsEnabled(MaintenanceLockMode.None)); Assert.True(MaintenanceMode.IsEnabled(MaintenanceLockMode.Write)); Assert.False(MaintenanceMode.IsEnabled(MaintenanceLockMode.Full)); } }
internal void IsEnabled_Full_Lock_Mode_Should_Lock_Read_And_Write() { using (MaintenanceMode.Enable(MaintenanceLockMode.Full)) { Assert.True(MaintenanceMode.IsEnabled(MaintenanceLockMode.None)); Assert.True(MaintenanceMode.IsEnabled(MaintenanceLockMode.Write)); Assert.True(MaintenanceMode.IsEnabled(MaintenanceLockMode.Full)); } }
public void Truncate() { Mode = MaintenanceMode.Lockdown; foreach (var fragment in _fragments) fragment.Maintenance.Truncate(); Mode = MaintenanceMode.Normal; }
public async Task RebuildIndexAsync(IIndexBuildProgressReporter reporter = null) { using (MaintenanceMode.Enable(MaintenanceLockMode.Write)) // allow to read data while reindexing { var progress = new IndexRebuildProgress(reporter); await progress.StartedAsync().ConfigureAwait(false); // TODO: lock collections for writing somehow? var indexSettings = _sparkSettings.IndexSettings ?? new IndexSettings(); if (indexSettings.ClearIndexOnRebuild) { await progress.CleanStartedAsync().ConfigureAwait(false); await _indexStore.Clean().ConfigureAwait(false); await progress.CleanCompletedAsync().ConfigureAwait(false); } var paging = _entryReader .ReadAsync(new FhirStorePageReaderOptions { PageSize = indexSettings.ReindexBatchSize }) .ConfigureAwait(false); var count = 0; //async entries => //{ // Selecting records page-by-page (page size is defined in app config, default is 100). // This will help to keep memory usage under control. await foreach (var entry in paging) { count++; // TODO: use BulkWrite operation for this try { await _indexService.Process(entry).ConfigureAwait(false); } catch (Exception) { // TODO: log exception! await progress.ErrorAsync($"Failed to reindex entry {entry.Key}") .ConfigureAwait(false); } } await progress.RecordsProcessedAsync(count, count) .ConfigureAwait(false); // }) //.ConfigureAwait(false); // TODO: - unlock collections for writing await progress.DoneAsync().ConfigureAwait(false); } }
protected void Application_Start() { MaintenanceMode.RefreshIsInMaintainanceMode(); DatabaseSetup.Initialize(); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DependencyResolver.SetResolver(new UnityMvcResolver(Container.InitUnityContainer())); ModelBinders.Binders.DefaultBinder = new DefaultModelBinder(); }
protected void Application_Start() { MaintenanceMode.RefreshIsInMaintainanceMode(); DatabaseSetup.Initialize(); this._container = CreateContainer(); DependencyResolver.SetResolver(new UnityDependencyResolver(this._container)); GlobalFilters.Filters.Add(new MaintenanceModeAttribute()); GlobalFilters.Filters.Add(new HandleErrorAttribute()); AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); }
public void Truncate() { if (!IsFragmented) return; _mode = MaintenanceMode.Lockdown; _lock.EnterExclusive(); try { using (var memoryStore = new MemoryBinaryStore()) { var entries = _fragment.TableOfContent.Entries; var memoryEntries = new List<Entry>(); foreach (var entry in entries) { var content = _service.GetContent(entry); long storeOffset; if (!memoryStore.TryWrite(content, out storeOffset)) throw new MaintenanceException("Failed to write data block to memory store, " + entry.Key.ToString()); memoryEntries.Add(new Entry { Key = entry.Key, ValueLength = content.Length, ValueOffset = storeOffset + 16 }); } byte[] tableOfContent; using (var stream = new MemoryStream()) { var converter = new EntryBinaryConverter(); foreach (var entry in memoryEntries) converter.ConvertTo(entry, stream); tableOfContent = stream.ToArray(); } var data = memoryStore.ToArray(); _service.ApplyTruncatedData(tableOfContent, data); } } finally { _mode = MaintenanceMode.Normal; _lock.ExitExclusive(); } }
protected void Application_Start() { MaintenanceMode.RefreshIsInMaintainanceMode(); DatabaseSetup.Initialize(); AreaRegistration.RegisterAllAreas(); GlobalFilters.Filters.Add(new MaintenanceModeAttribute()); GlobalFilters.Filters.Add(new HandleErrorAttribute()); RouteConfig.RegisterRoutes(RouteTable.Routes); var serializer = new JsonTextSerializer(); EventBus = new EventBus(new MessageSender(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.events"), serializer); }
protected void Application_Start() { #if AZURESDK Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.Changed += (s, a) => { Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.RequestRecycle(); }; #endif MaintenanceMode.RefreshIsInMaintainanceMode(); DatabaseSetup.Initialize(); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); var serializer = new JsonTextSerializer(); #if LOCAL EventBus = new EventBus(new MessageSender(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Events"), serializer); #else var settings = InfrastructureSettings.Read(HttpContext.Current.Server.MapPath(@"~\bin\Settings.xml")).ServiceBus; if (!MaintenanceMode.IsInMaintainanceMode) { new ServiceBusConfig(settings).Initialize(); } EventBus = new EventBus(new TopicSender(settings, "conference/events"), new StandardMetadataProvider(), serializer); #endif #if AZURESDK if (Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable) { //System.Diagnostics.Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener()); System.Diagnostics.Trace.AutoFlush = true; } #endif }
public override bool OnStart() { RoleEnvironment.Changing += (sender, e) => { if (e.Changes .OfType <RoleEnvironmentConfigurationSettingChange>() .Any(x => x.ConfigurationSettingName != MaintenanceMode.MaintenanceModeSettingName)) { Trace.TraceInformation("Recycling worker role because of configuration change"); e.Cancel = true; } }; RoleEnvironment.Changed += (sender, e) => { if (e.Changes .OfType <RoleEnvironmentConfigurationSettingChange>() .Any(x => x.ConfigurationSettingName == MaintenanceMode.MaintenanceModeSettingName)) { Trace.TraceInformation("Refreshing maintenance mode because of configuration change"); MaintenanceMode.RefreshIsInMaintainanceMode(); } }; MaintenanceMode.RefreshIsInMaintainanceMode(); var config = DiagnosticMonitor.GetDefaultInitialConfiguration(); TimeSpan transferPeriod; if (!TimeSpan.TryParse(RoleEnvironment.GetConfigurationSettingValue("Diagnostics.ScheduledTransferPeriod"), out transferPeriod)) { transferPeriod = TimeSpan.FromMinutes(1); } TimeSpan sampleRate; if (!TimeSpan.TryParse(RoleEnvironment.GetConfigurationSettingValue("Diagnostics.PerformanceCounterSampleRate"), out sampleRate)) { sampleRate = TimeSpan.FromSeconds(30); } LogLevel logLevel; if (!Enum.TryParse <LogLevel>(RoleEnvironment.GetConfigurationSettingValue("Diagnostics.LogLevelFilter"), out logLevel)) { logLevel = LogLevel.Verbose; } //// Setup performance counters //config.PerformanceCounters.DataSources.Add( // new PerformanceCounterConfiguration // { // CounterSpecifier = @"\Processor(_Total)\% Processor Time", // SampleRate = sampleRate // }); #if !LOCAL foreach (var counterName in new[] { Infrastructure.Azure.Instrumentation.SessionSubscriptionReceiverInstrumentation.TotalSessionsCounterName, Infrastructure.Azure.Instrumentation.SessionSubscriptionReceiverInstrumentation.CurrentSessionsCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.TotalMessagesCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.TotalMessagesSuccessfullyProcessedCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.TotalMessagesUnsuccessfullyProcessedCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.TotalMessagesCompletedCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.TotalMessagesNotCompletedCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.MessagesReceivedPerSecondCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.AverageMessageProcessingTimeCounterName, Infrastructure.Azure.Instrumentation.SubscriptionReceiverInstrumentation.CurrentMessagesInProcessCounterName, }) { //config.PerformanceCounters.DataSources.Add( // new PerformanceCounterConfiguration // { // CounterSpecifier = @"\" + Infrastructure.Azure.Instrumentation.Constants.ReceiversPerformanceCountersCategory + @"(*)\" + counterName, // SampleRate = sampleRate // }); } foreach (var counterName in new[] { Infrastructure.Azure.Instrumentation.EventStoreBusPublisherInstrumentation.CurrentEventPublishersCounterName, Infrastructure.Azure.Instrumentation.EventStoreBusPublisherInstrumentation.EventPublishingRequestsPerSecondCounterName, Infrastructure.Azure.Instrumentation.EventStoreBusPublisherInstrumentation.EventsPublishedPerSecondCounterName, Infrastructure.Azure.Instrumentation.EventStoreBusPublisherInstrumentation.TotalEventsPublishedCounterName, Infrastructure.Azure.Instrumentation.EventStoreBusPublisherInstrumentation.TotalEventsPublishingRequestsCounterName, }) { //config.PerformanceCounters.DataSources.Add( // new PerformanceCounterConfiguration // { // CounterSpecifier = @"\" + Infrastructure.Azure.Instrumentation.Constants.EventPublishersPerformanceCountersCategory + @"(*)\" + counterName, // SampleRate = sampleRate // }); } #endif //config.PerformanceCounters.ScheduledTransferPeriod = transferPeriod; //// Setup logs //config.Logs.ScheduledTransferPeriod = transferPeriod; //config.Logs.ScheduledTransferLogLevelFilter = logLevel; //DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config); //// Trace.Listeners.Add(new DiagnosticMonitorTraceListener()); //Trace.AutoFlush = true; //Database.DefaultConnectionFactory = new ServiceConfigurationSettingConnectionFactory(Database.DefaultConnectionFactory); return(base.OnStart()); }
public override async Task Execute() { await _appSettings.Reload(); Mode = _getMode(_appSettings.CurrentValue); }
internal void IsEnabledForHttpMethod_Should_Return_False_If_Maintenance_Mode_Is_Not_Enabled(string method) { Assert.False(MaintenanceMode.IsEnabledForHttpMethod(method)); }
internal void IsEnabled_Should_Return_False_If_Maintenance_Mode_Is_Not_Enabled(MaintenanceLockMode mode) { Assert.False(MaintenanceMode.IsEnabled(mode)); }