Rename server roles, master = SchedulingPublisher and replica = Subscriber (#10480)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace Umbraco.Cms.Core.Models
|
||||
bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the server is master.
|
||||
/// Gets or sets a value indicating whether the server is has the SchedulingPublisher role.
|
||||
/// </summary>
|
||||
bool IsMaster { get; set; }
|
||||
bool IsSchedulingPublisher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the registration was created.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Extensions;
|
||||
@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
private string _serverAddress;
|
||||
private string _serverIdentity;
|
||||
private bool _isActive;
|
||||
private bool _isMaster;
|
||||
private bool _isSchedulingPublisher;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ServerRegistration"/> class.
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
/// <param name="accessed">The date and time the registration was last accessed.</param>
|
||||
/// <param name="isActive">A value indicating whether the registration is active.</param>
|
||||
/// <param name="isMaster">A value indicating whether the registration is master.</param>
|
||||
public ServerRegistration(int id, string serverAddress, string serverIdentity, DateTime registered, DateTime accessed, bool isActive, bool isMaster)
|
||||
public ServerRegistration(int id, string serverAddress, string serverIdentity, DateTime registered, DateTime accessed, bool isActive, bool isSchedulingPublisher)
|
||||
{
|
||||
UpdateDate = accessed;
|
||||
CreateDate = registered;
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
ServerAddress = serverAddress;
|
||||
ServerIdentity = serverIdentity;
|
||||
IsActive = isActive;
|
||||
IsMaster = isMaster;
|
||||
IsSchedulingPublisher = isSchedulingPublisher;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,12 +86,12 @@ namespace Umbraco.Cms.Core.Models
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the server is master.
|
||||
/// Gets or sets a value indicating whether the server has the SchedulingPublisher role
|
||||
/// </summary>
|
||||
public bool IsMaster
|
||||
public bool IsSchedulingPublisher
|
||||
{
|
||||
get => _isMaster;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _isMaster, nameof(IsMaster));
|
||||
get => _isSchedulingPublisher;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _isSchedulingPublisher, nameof(IsSchedulingPublisher));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,7 +118,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{{\"{0}\", \"{1}\", {2}active, {3}master}}", ServerAddress, ServerIdentity, IsActive ? "" : "!", IsMaster ? "" : "!");
|
||||
return string.Format("{{\"{0}\", \"{1}\", {2}active, {3}master}}", ServerAddress, ServerIdentity, IsActive ? "" : "!", IsSchedulingPublisher ? "" : "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.Sync
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is the default service which determines a server's role by using a master election process.
|
||||
/// The master election process doesn't occur until just after startup so this election process doesn't really affect the primary startup phase.
|
||||
/// The scheduling publisher election process doesn't occur until just after startup so this election process doesn't really affect the primary startup phase.
|
||||
/// </remarks>
|
||||
public sealed class ElectedServerRoleAccessor : IServerRoleAccessor
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Umbraco.Cms.Core.Sync
|
||||
namespace Umbraco.Cms.Core.Sync
|
||||
{
|
||||
/// <summary>
|
||||
/// The role of a server in an application environment.
|
||||
@@ -16,13 +16,13 @@
|
||||
Single = 1,
|
||||
|
||||
/// <summary>
|
||||
/// In a multi-servers environment, the server is a replica server.
|
||||
/// In a multi-servers environment, the server is a Subscriber server.
|
||||
/// </summary>
|
||||
Replica = 2,
|
||||
Subscriber = 2,
|
||||
|
||||
/// <summary>
|
||||
/// In a multi-servers environment, the server is the master server.
|
||||
/// In a multi-servers environment, the server is the Scheduling Publisher.
|
||||
/// </summary>
|
||||
Master = 3
|
||||
SchedulingPublisher = 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Umbraco.Cms.Core.Sync
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The micro optimization is specifically to avoid a DB query just after the app starts up to determine the <see cref="ServerRole"/>
|
||||
/// which by default is done with master election by a database query. The master election process doesn't occur until just after startup
|
||||
/// which by default is done with scheduling publisher election by a database query. The master election process doesn't occur until just after startup
|
||||
/// so this micro optimization doesn't really affect the primary startup phase.
|
||||
/// </remarks>
|
||||
public class SingleServerRoleAccessor : IServerRoleAccessor
|
||||
|
||||
@@ -89,8 +89,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
|
||||
switch (_serverRegistrar.CurrentServerRole)
|
||||
{
|
||||
case ServerRole.Replica:
|
||||
_logger.LogDebug("Does not run on replica servers.");
|
||||
case ServerRole.Subscriber:
|
||||
_logger.LogDebug("Does not run on subscriber servers.");
|
||||
return;
|
||||
case ServerRole.Unknown:
|
||||
_logger.LogDebug("Does not run on servers with unknown role.");
|
||||
|
||||
@@ -69,8 +69,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
// Don't run on replicas nor unknown role servers
|
||||
switch (_serverRegistrar.CurrentServerRole)
|
||||
{
|
||||
case ServerRole.Replica:
|
||||
_logger.LogDebug("Does not run on replica servers.");
|
||||
case ServerRole.Subscriber:
|
||||
_logger.LogDebug("Does not run on subscriber servers.");
|
||||
return;
|
||||
case ServerRole.Unknown:
|
||||
_logger.LogDebug("Does not run on servers with unknown role.");
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
{
|
||||
switch (_serverRegistrar.CurrentServerRole)
|
||||
{
|
||||
case ServerRole.Replica:
|
||||
_logger.LogDebug("Does not run on replica servers.");
|
||||
case ServerRole.Subscriber:
|
||||
_logger.LogDebug("Does not run on subscriber servers.");
|
||||
return Task.CompletedTask;
|
||||
case ServerRole.Unknown:
|
||||
_logger.LogDebug("Does not run on servers with unknown role.");
|
||||
|
||||
@@ -69,8 +69,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
|
||||
switch (_serverRegistrar.CurrentServerRole)
|
||||
{
|
||||
case ServerRole.Replica:
|
||||
_logger.LogDebug("Does not run on replica servers.");
|
||||
case ServerRole.Subscriber:
|
||||
_logger.LogDebug("Does not run on subscriber servers.");
|
||||
return Task.CompletedTask;
|
||||
case ServerRole.Unknown:
|
||||
_logger.LogDebug("Does not run on servers with unknown role.");
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
/// Used to cleanup temporary file locations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Will run on all servers - even though file upload should only be handled on the master, this will
|
||||
/// ensure that in the case it happes on replicas that they are cleaned up too.
|
||||
/// Will run on all servers - even though file upload should only be handled on the scheduling publisher, this will
|
||||
/// ensure that in the case it happens on subscribers that they are cleaned up too.
|
||||
/// </remarks>
|
||||
public class TempFileCleanup : RecurringHostedServiceBase
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using NPoco;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;
|
||||
@@ -35,6 +35,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
[Column("isMaster")]
|
||||
public bool IsMaster { get; set; }
|
||||
public bool IsSchedulingPublisher { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Persistence.Factories
|
||||
@@ -7,7 +7,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories
|
||||
{
|
||||
public static ServerRegistration BuildEntity(ServerRegistrationDto dto)
|
||||
{
|
||||
var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsMaster);
|
||||
var model = new ServerRegistration(dto.Id, dto.ServerAddress, dto.ServerIdentity, dto.DateRegistered, dto.DateAccessed, dto.IsActive, dto.IsSchedulingPublisher);
|
||||
// reset dirty initial properties (U4-1946)
|
||||
model.ResetDirtyProperties(false);
|
||||
return model;
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories
|
||||
ServerAddress = entity.ServerAddress,
|
||||
DateRegistered = entity.CreateDate,
|
||||
IsActive = entity.IsActive,
|
||||
IsMaster = ((ServerRegistration) entity).IsMaster,
|
||||
IsSchedulingPublisher = ((ServerRegistration) entity).IsSchedulingPublisher,
|
||||
DateAccessed = entity.UpdateDate,
|
||||
ServerIdentity = entity.ServerIdentity
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Mappers
|
||||
{
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.Id), nameof(ServerRegistrationDto.Id));
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.IsActive), nameof(ServerRegistrationDto.IsActive));
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.IsMaster), nameof(ServerRegistrationDto.IsMaster));
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.IsSchedulingPublisher), nameof(ServerRegistrationDto.IsSchedulingPublisher));
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.ServerAddress), nameof(ServerRegistrationDto.ServerAddress));
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.CreateDate), nameof(ServerRegistrationDto.DateRegistered));
|
||||
DefineMap<ServerRegistration, ServerRegistrationDto>(nameof(ServerRegistration.UpdateDate), nameof(ServerRegistrationDto.DateAccessed));
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
switch (serverRole)
|
||||
{
|
||||
case ServerRole.Single:
|
||||
case ServerRole.Master:
|
||||
case ServerRole.SchedulingPublisher:
|
||||
PruneOldInstructions();
|
||||
instructionsWerePruned = true;
|
||||
break;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
((ServerRegistrationRepository) _serverRegistrationRepository).ClearCache(); // ensure we have up-to-date cache
|
||||
|
||||
var regs = _serverRegistrationRepository.GetMany().ToArray();
|
||||
var hasMaster = regs.Any(x => ((ServerRegistration) x).IsMaster);
|
||||
var hasSchedulingPublisher = regs.Any(x => ((ServerRegistration) x).IsSchedulingPublisher);
|
||||
var server = regs.FirstOrDefault(x => x.ServerIdentity.InvariantEquals(serverIdentity));
|
||||
|
||||
if (server == null)
|
||||
@@ -67,22 +67,20 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
|
||||
server.IsActive = true;
|
||||
if (hasMaster == false)
|
||||
server.IsMaster = true;
|
||||
if (hasSchedulingPublisher == false)
|
||||
server.IsSchedulingPublisher = true;
|
||||
|
||||
_serverRegistrationRepository.Save(server);
|
||||
_serverRegistrationRepository.DeactiveStaleServers(staleTimeout); // triggers a cache reload
|
||||
|
||||
// reload - cheap, cached
|
||||
|
||||
// default role is single server, but if registrations contain more
|
||||
// than one active server, then role is master or replica
|
||||
regs = _serverRegistrationRepository.GetMany().ToArray();
|
||||
|
||||
// default role is single server, but if registrations contain more
|
||||
// than one active server, then role is master or replica
|
||||
// than one active server, then role is scheduling publisher or subscriber
|
||||
_currentServerRole = regs.Count(x => x.IsActive) > 1
|
||||
? (server.IsMaster ? ServerRole.Master : ServerRole.Replica)
|
||||
? (server.IsSchedulingPublisher ? ServerRole.SchedulingPublisher : ServerRole.Subscriber)
|
||||
: ServerRole.Single;
|
||||
|
||||
scope.Complete();
|
||||
@@ -105,7 +103,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
|
||||
var server = _serverRegistrationRepository.GetMany().FirstOrDefault(x => x.ServerIdentity.InvariantEquals(serverIdentity));
|
||||
if (server == null) return;
|
||||
server.IsActive = server.IsMaster = false;
|
||||
server.IsActive = server.IsSchedulingPublisher = false;
|
||||
_serverRegistrationRepository.Save(server); // will trigger a cache reload // will trigger a cache reload
|
||||
|
||||
scope.Complete();
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPoco
|
||||
DateRegistered = DateTime.Now,
|
||||
IsActive = true,
|
||||
DateAccessed = DateTime.Now,
|
||||
IsMaster = true
|
||||
IsSchedulingPublisher = true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Replica()
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Subscriber()
|
||||
{
|
||||
HealthCheckNotifier sut = CreateHealthCheckNotifier(serverRole: ServerRole.Replica);
|
||||
HealthCheckNotifier sut = CreateHealthCheckNotifier(serverRole: ServerRole.Subscriber);
|
||||
await sut.PerformExecuteAsync(null);
|
||||
VerifyNotificationsNotSent();
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Replica()
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Subscriber()
|
||||
{
|
||||
KeepAlive sut = CreateKeepAlive(serverRole: ServerRole.Replica);
|
||||
KeepAlive sut = CreateKeepAlive(serverRole: ServerRole.Subscriber);
|
||||
await sut.PerformExecuteAsync(null);
|
||||
VerifyKeepAliveRequestNotSent();
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
||||
private const int MaxLogAgeInMinutes = 60;
|
||||
|
||||
[Test]
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Replica()
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Subscriber()
|
||||
{
|
||||
LogScrubber sut = CreateLogScrubber(serverRole: ServerRole.Replica);
|
||||
LogScrubber sut = CreateLogScrubber(serverRole: ServerRole.Subscriber);
|
||||
await sut.PerformExecuteAsync(null);
|
||||
VerifyLogsNotScrubbed();
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Replica()
|
||||
public async Task Does_Not_Execute_When_Server_Role_Is_Subscriber()
|
||||
{
|
||||
ScheduledPublishing sut = CreateScheduledPublishing(serverRole: ServerRole.Replica);
|
||||
ScheduledPublishing sut = CreateScheduledPublishing(serverRole: ServerRole.Subscriber);
|
||||
await sut.PerformExecuteAsync(null);
|
||||
VerifyScheduledPublishingNotPerformed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user