Skip to content

Commit

Permalink
Add -map-threads parameter support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Apr 29, 2023
1 parent 53df27a commit e1f471b
Show file tree
Hide file tree
Showing 28 changed files with 4,506 additions and 30 deletions.
8 changes: 4 additions & 4 deletions build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="ControlPanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>5.12.0</TgsCoreVersion>
<TgsCoreVersion>5.13.0</TgsCoreVersion>
<TgsConfigVersion>4.6.0</TgsConfigVersion>
<TgsApiVersion>9.10.2</TgsApiVersion>
<TgsApiLibraryVersion>10.4.1</TgsApiLibraryVersion>
<TgsClientVersion>11.4.1</TgsClientVersion>
<TgsApiVersion>9.11.0</TgsApiVersion>
<TgsApiLibraryVersion>10.5.0</TgsApiLibraryVersion>
<TgsClientVersion>11.5.0</TgsClientVersion>
<TgsDmapiVersion>6.4.2</TgsDmapiVersion>
<TgsInteropVersion>5.6.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.2.2</TgsHostWatchdogVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public class DreamDaemonLaunchParameters
[ResponseOptions]
public bool? LogOutput { get; set; }

/// <summary>
/// If DreamDaemon supports it, the value added as the -map-threads parameter. 0 uses the default BYOND value.
/// </summary>
[Required]
[ResponseOptions]
public uint? MapThreads { get; set; }

/// <summary>
/// Check if we match a given set of <paramref name="otherParameters"/>. <see cref="StartupTimeout"/> is excluded.
/// </summary>
Expand All @@ -108,7 +115,8 @@ public bool CanApplyWithoutReboot(DreamDaemonLaunchParameters otherParameters)
&& TopicRequestTimeout == otherParameters.TopicRequestTimeout
&& AdditionalParameters == otherParameters.AdditionalParameters
&& StartProfiler == otherParameters.StartProfiler
&& LogOutput == otherParameters.LogOutput; // We intentionally don't check StartupTimeout, heartbeat seconds, or heartbeat dump as they don't matter in terms of the watchdog
&& LogOutput == otherParameters.LogOutput
&& MapThreads == otherParameters.MapThreads; // We intentionally don't check StartupTimeout, heartbeat seconds, or heartbeat dump as they don't matter in terms of the watchdog
}
}
}
25 changes: 15 additions & 10 deletions src/Tgstation.Server.Api/Rights/DreamDaemonRights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Tgstation.Server.Api.Rights
public enum DreamDaemonRights : ulong
{
/// <summary>
/// User has no rights
/// User has no rights.
/// </summary>
None = 0,

/// <summary>
/// User can read <see cref="Models.Response.DreamDaemonResponse.ActiveCompileJob"/> and <see cref="Models.Response.DreamDaemonResponse.StagedCompileJob"/>
/// User can read <see cref="Models.Response.DreamDaemonResponse.ActiveCompileJob"/> and <see cref="Models.Response.DreamDaemonResponse.StagedCompileJob"/>.
/// </summary>
ReadRevision = 1 << 0,

Expand All @@ -24,12 +24,12 @@ public enum DreamDaemonRights : ulong
SetPort = 1 << 1,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonSettings.AutoStart"/>
/// User can change <see cref="Models.Internal.DreamDaemonSettings.AutoStart"/>.
/// </summary>
SetAutoStart = 1 << 2,

/// <summary>
/// User set <see cref="Models.Internal.DreamDaemonLaunchParameters.SecurityLevel"/>
/// User set <see cref="Models.Internal.DreamDaemonLaunchParameters.SecurityLevel"/>.
/// </summary>
SetSecurity = 1 << 3,

Expand All @@ -39,7 +39,7 @@ public enum DreamDaemonRights : ulong
ReadMetadata = 1 << 4,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.AllowWebClient"/>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.AllowWebClient"/>.
/// </summary>
SetWebClient = 1 << 5,

Expand Down Expand Up @@ -69,12 +69,12 @@ public enum DreamDaemonRights : ulong
Start = 1 << 10,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.StartupTimeout"/>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.StartupTimeout"/>.
/// </summary>
SetStartupTimeout = 1 << 11,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.HeartbeatSeconds"/>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.HeartbeatSeconds"/>.
/// </summary>
SetHeartbeatInterval = 1 << 12,

Expand All @@ -94,18 +94,23 @@ public enum DreamDaemonRights : ulong
SetAdditionalParameters = 1 << 15,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.Visibility"/>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.Visibility"/>.
/// </summary>
SetVisibility = 1 << 16,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.StartProfiler"/>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.StartProfiler"/>.
/// </summary>
SetProfiler = 1 << 17,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.LogOutput"/>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.LogOutput"/>.
/// </summary>
SetLogOutput = 1 << 18,

/// <summary>
/// User can change <see cref="Models.Internal.DreamDaemonLaunchParameters.MapThreads"/>.
/// </summary>
SetMapThreads = 1 << 19,
}
}
2 changes: 1 addition & 1 deletion src/Tgstation.Server.Api/Tgstation.Server.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<RepositoryUrl>https://github.com/tgstation/tgstation-server</RepositoryUrl>
<Copyright>2018-2023</Copyright>
<PackageTags>json web api tgstation-server tgstation ss13 byond</PackageTags>
<PackageReleaseNotes>Minor documentation correction.</PackageReleaseNotes>
<PackageReleaseNotes>Added support for -map-threads DreamDaemon parameter.</PackageReleaseNotes>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
Expand Down
2 changes: 1 addition & 1 deletion src/Tgstation.Server.Client/Tgstation.Server.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<RepositoryUrl>https://github.com/tgstation/tgstation-server</RepositoryUrl>
<Copyright>2018-2023</Copyright>
<PackageTags>json web api tgstation-server tgstation ss13 byond client</PackageTags>
<PackageReleaseNotes>Updated to latest API library patch.</PackageReleaseNotes>
<PackageReleaseNotes>Added support for -map-threads DreamDaemon parameter.</PackageReleaseNotes>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ sealed class ByondExecutableLock : ReferenceCounter<ByondInstallation>, IByondEx
/// <inheritdoc />
public bool SupportsCli => Instance.SupportsCli;

/// <inheritdoc />
public bool SupportsMapThreads => Instance.SupportsMapThreads;

/// <inheritdoc />
public void DoNotDeleteThisSession() => DangerousDropReference();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ sealed class ByondInstallation : IByondInstallation
/// <inheritdoc />
public bool SupportsCli { get; }

/// <inheritdoc />
public bool SupportsMapThreads => Version.Major >= 515 && Version.Minor >= 1605;

/// <summary>
/// The <see cref="Task"/> that completes when the BYOND version finished installing.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ public interface IByondInstallation
/// If <see cref="DreamDaemonPath"/> supports being run as a command-line application.
/// </summary>
bool SupportsCli { get; }

/// <summary>
/// If <see cref="DreamDaemonPath"/> supports the -map-threads parameter.
/// </summary>
bool SupportsMapThreads { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ static string FormatExceptionForUsers(Exception exception)
StartupTimeout = x.StartupTimeout,
LogOutput = x.LogOutput,
})
.FirstOrDefaultAsync(cancellationToken)
;
.FirstOrDefaultAsync(cancellationToken);
if (ddSettings == default)
throw new JobException(ErrorCode.InstanceMissingDreamDaemonSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ await using (process)
// important to run on all ports to allow port changing
var arguments = String.Format(
CultureInfo.InvariantCulture,
"{0} -port {1} -ports 1-65535 {2}-close -verbose -{3} -{4}{5}{6} -params \"{7}\"",
"{0} -port {1} -ports 1-65535 {2}-close -verbose -{3} -{4}{5}{6}{7} -params \"{8}\"",
dmbProvider.DmbName,
launchParameters.Port.Value,
launchParameters.AllowWebClient.Value ? "-webclient " : String.Empty,
Expand All @@ -502,6 +502,9 @@ await using (process)
launchParameters.StartProfiler.Value
? " -profile"
: String.Empty,
byondLock.SupportsMapThreads && launchParameters.MapThreads.Value != 0
? $" -map-threads {launchParameters.MapThreads.Value}"
: String.Empty,
parameters);

var process = await processExecutor.LaunchProcess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public Task<IActionResult> Delete(CancellationToken cancellationToken)
| DreamDaemonRights.SetAdditionalParameters
| DreamDaemonRights.SetVisibility
| DreamDaemonRights.SetProfiler
| DreamDaemonRights.SetLogOutput)]
| DreamDaemonRights.SetLogOutput
| DreamDaemonRights.SetMapThreads)]
[ProducesResponseType(typeof(DreamDaemonResponse), 200)]
[ProducesResponseType(typeof(ErrorMessageResponse), 410)]
#pragma warning disable CA1502 // TODO: Decomplexify
Expand Down Expand Up @@ -226,7 +227,8 @@ bool CheckModified<T>(Expression<Func<Api.Models.Internal.DreamDaemonSettings, T
|| CheckModified(x => x.TopicRequestTimeout, DreamDaemonRights.SetTopicTimeout)
|| CheckModified(x => x.AdditionalParameters, DreamDaemonRights.SetAdditionalParameters)
|| CheckModified(x => x.StartProfiler, DreamDaemonRights.SetProfiler)
|| CheckModified(x => x.LogOutput, DreamDaemonRights.SetLogOutput))
|| CheckModified(x => x.LogOutput, DreamDaemonRights.SetLogOutput)
|| CheckModified(x => x.MapThreads, DreamDaemonRights.SetMapThreads))
return Forbid();
await DatabaseContext.Save(cancellationToken);
Expand Down Expand Up @@ -368,6 +370,7 @@ Task<IActionResult> ReadImpl(DreamDaemonSettings settings, CancellationToken can
result.AdditionalParameters = settings.AdditionalParameters;
result.StartProfiler = settings.StartProfiler;
result.LogOutput = settings.LogOutput;
result.MapThreads = settings.MapThreads;
}
if (revision)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ async Task<Models.Instance> CreateDefaultInstance(InstanceCreateRequest initialS
AdditionalParameters = String.Empty,
StartProfiler = false,
LogOutput = false,
MapThreads = 0,
},
DreamMakerSettings = new DreamMakerSettings
{
Expand Down
17 changes: 13 additions & 4 deletions src/Tgstation.Server.Host/Database/DatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,22 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
/// <summary>
/// Used by unit tests to remind us to setup the correct MSSQL migration downgrades.
/// </summary>
internal static readonly Type MSLatestMigration = typeof(MSAddReattachInfoInitialCompileJob);
internal static readonly Type MSLatestMigration = typeof(MSAddMapThreads);

/// <summary>
/// Used by unit tests to remind us to setup the correct MYSQL migration downgrades.
/// </summary>
internal static readonly Type MYLatestMigration = typeof(MYAddReattachInfoInitialCompileJob);
internal static readonly Type MYLatestMigration = typeof(MYAddMapThreads);

/// <summary>
/// Used by unit tests to remind us to setup the correct PostgresSQL migration downgrades.
/// </summary>
internal static readonly Type PGLatestMigration = typeof(PGAddReattachInfoInitialCompileJob);
internal static readonly Type PGLatestMigration = typeof(PGAddMapThreads);

/// <summary>
/// Used by unit tests to remind us to setup the correct SQLite migration downgrades.
/// </summary>
internal static readonly Type SLLatestMigration = typeof(SLAddReattachInfoInitialCompileJob);
internal static readonly Type SLLatestMigration = typeof(SLAddMapThreads);

/// <inheritdoc />
#pragma warning disable CA1502 // Cyclomatic complexity
Expand Down Expand Up @@ -425,6 +425,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

string BadDatabaseType() => throw new ArgumentException($"Invalid DatabaseType: {currentDatabaseType}", nameof(currentDatabaseType));

if (targetVersion < new Version(5, 13, 0))
targetMigration = currentDatabaseType switch
{
DatabaseType.MySql => nameof(MYAddReattachInfoInitialCompileJob),
DatabaseType.PostgresSql => nameof(PGAddReattachInfoInitialCompileJob),
DatabaseType.SqlServer => nameof(MSAddReattachInfoInitialCompileJob),
DatabaseType.Sqlite => nameof(SLAddReattachInfoInitialCompileJob),
_ => BadDatabaseType(),
};
if (targetVersion < new Version(5, 7, 3))
targetMigration = currentDatabaseType switch
{
Expand Down
Loading

0 comments on commit e1f471b

Please sign in to comment.