feat(fed): add ural
This commit is contained in:
@@ -12,7 +12,9 @@
|
||||
"TileServer": {
|
||||
"DataDirectory": "../../data",
|
||||
"JavaPath": "java",
|
||||
"JvmMaxHeap": "8g",
|
||||
"JvmMaxHeap": "4g",
|
||||
"PlanetilerThreads": 8,
|
||||
"PlanetilerMmapTemp": false,
|
||||
"PlanetilerJarUrl": "https://github.com/openmaptiles/planetiler-openmaptiles/releases/download/v3.16/planetiler-openmaptiles.jar",
|
||||
"PlanetilerHttpTimeout": "15m",
|
||||
"DownloadStallTimeoutSeconds": 45,
|
||||
@@ -65,6 +67,15 @@
|
||||
"MinZoom": 0,
|
||||
"MaxZoom": 15,
|
||||
"Enabled": true
|
||||
},
|
||||
{
|
||||
"Id": "ural-fed-district",
|
||||
"Name": "Уральский федеральный округ",
|
||||
"Url": "https://download.geofabrik.de/russia/ural-fed-district-latest.osm.pbf",
|
||||
"Center": [60.0, 55.0],
|
||||
"MinZoom": 0,
|
||||
"MaxZoom": 15,
|
||||
"Enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -8,7 +8,20 @@ public sealed class TileServerOptions
|
||||
|
||||
public string JavaPath { get; set; } = "java";
|
||||
|
||||
public string JvmMaxHeap { get; set; } = "8g";
|
||||
/// <summary>
|
||||
/// JVM heap only. Planetiler memory-maps temp features outside this budget.
|
||||
/// Keep around one third of the container mem_limit (4g in a 12g box).
|
||||
/// Exit 137 is the OOM killer, not a Java heap dump.
|
||||
/// </summary>
|
||||
public string JvmMaxHeap { get; set; } = "4g";
|
||||
|
||||
/// <summary>0 = Planetiler default (all CPUs). Cap on small containers to limit RSS.</summary>
|
||||
public int PlanetilerThreads { get; set; } = 8;
|
||||
|
||||
/// <summary>
|
||||
/// mmap of feature.db inflates RSS on large z15 extracts. Off by default for 12g hosts.
|
||||
/// </summary>
|
||||
public bool PlanetilerMmapTemp { get; set; }
|
||||
|
||||
public string PlanetilerJarUrl { get; set; } =
|
||||
"https://github.com/openmaptiles/planetiler-openmaptiles/releases/download/v3.16/planetiler-openmaptiles.jar";
|
||||
|
||||
@@ -129,6 +129,7 @@ public sealed class MapSyncService(
|
||||
{
|
||||
var state = await stateStore.GetAsync(extract.Id, ct).ConfigureAwait(false);
|
||||
var pbfPath = dataPaths.OsmPbf(extract.Id);
|
||||
var previousStatus = state.Status;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -150,6 +151,7 @@ public sealed class MapSyncService(
|
||||
var metadata = tileStore.GetMetadata(extract.Id);
|
||||
var zoomRaised = metadata is not null && extract.MaxZoom > metadata.MaxZoom;
|
||||
var shouldBuild = download.Changed
|
||||
|| previousStatus == ExtractSyncState.Failed
|
||||
|| (tilesMissing && options.Value.Sync.RebuildIfTilesMissing)
|
||||
|| zoomRaised;
|
||||
if (!shouldBuild)
|
||||
@@ -168,6 +170,10 @@ public sealed class MapSyncService(
|
||||
extract.MaxZoom,
|
||||
metadata!.MaxZoom);
|
||||
}
|
||||
else if (previousStatus == ExtractSyncState.Failed)
|
||||
{
|
||||
logger.LogInformation("Rebuilding {ExtractId}: previous run failed.", extract.Id);
|
||||
}
|
||||
|
||||
if (!planetiler.IsJavaAvailable())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace TileServer.Infrastructure.Tiles;
|
||||
|
||||
public static class PlanetilerExit
|
||||
{
|
||||
/// <summary>128 + SIGKILL. Docker/cgroup OOM killer, not a Java heap dump.</summary>
|
||||
public const int LinuxOomKill = 137;
|
||||
|
||||
public static bool IsLikelyOom(int exitCode) => exitCode is LinuxOomKill or 9;
|
||||
|
||||
public static string Describe(int exitCode, string extractId)
|
||||
{
|
||||
if (IsLikelyOom(exitCode))
|
||||
{
|
||||
return
|
||||
$"Planetiler was killed (exit {exitCode}, typically the Linux OOM killer) while building '{extractId}'. " +
|
||||
"JVM -Xmx is only the heap; Planetiler also maps temp features. " +
|
||||
"Keep TileServer:JvmMaxHeap around 1/3 of the container mem_limit (4g in 12g) and PlanetilerMmapTemp=false.";
|
||||
}
|
||||
|
||||
return $"Planetiler exited with code {exitCode} for extract '{extractId}'.";
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public sealed class PlanetilerTileBuilder(
|
||||
IOptions<TileServerOptions> options,
|
||||
ILogger<PlanetilerTileBuilder> logger) : ITileBuilder
|
||||
{
|
||||
private const int OomRetryAttempts = 2;
|
||||
|
||||
public async Task BuildAsync(Extract extract, string osmPbfPath, string outputMbtilesPath, CancellationToken ct)
|
||||
{
|
||||
if (!File.Exists(osmPbfPath))
|
||||
@@ -24,16 +26,64 @@ public sealed class PlanetilerTileBuilder(
|
||||
|
||||
var jar = await bootstrapper.EnsureJarAsync(ct).ConfigureAwait(false);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outputMbtilesPath)!);
|
||||
if (File.Exists(outputMbtilesPath))
|
||||
{
|
||||
File.Delete(outputMbtilesPath);
|
||||
}
|
||||
Directory.CreateDirectory(dataPaths.Tmp);
|
||||
|
||||
var cfg = options.Value;
|
||||
var java = cfg.JavaPath;
|
||||
Exception? lastFailure = null;
|
||||
for (var attempt = 1; attempt <= OomRetryAttempts; attempt++)
|
||||
{
|
||||
if (File.Exists(outputMbtilesPath))
|
||||
{
|
||||
File.Delete(outputMbtilesPath);
|
||||
}
|
||||
|
||||
var psi = CreateStartInfo(cfg, jar, extract, osmPbfPath, outputMbtilesPath);
|
||||
logger.LogInformation(
|
||||
"Starting Planetiler for {ExtractId} (attempt {Attempt}/{Max}): {File} {Args}",
|
||||
extract.Id,
|
||||
attempt,
|
||||
OomRetryAttempts,
|
||||
cfg.JavaPath,
|
||||
string.Join(' ', psi.ArgumentList));
|
||||
|
||||
var exitCode = await RunAsync(psi, extract.Id, ct).ConfigureAwait(false);
|
||||
ClearTmp();
|
||||
|
||||
if (exitCode == 0)
|
||||
{
|
||||
if (!File.Exists(outputMbtilesPath))
|
||||
{
|
||||
throw new InvalidOperationException($"Planetiler finished but '{outputMbtilesPath}' was not created.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
lastFailure = new InvalidOperationException(PlanetilerExit.Describe(exitCode, extract.Id));
|
||||
if (!PlanetilerExit.IsLikelyOom(exitCode) || attempt == OomRetryAttempts)
|
||||
{
|
||||
throw lastFailure;
|
||||
}
|
||||
|
||||
logger.LogWarning(
|
||||
lastFailure,
|
||||
"Planetiler OOM for {ExtractId}; retrying after clearing tmp.",
|
||||
extract.Id);
|
||||
}
|
||||
|
||||
throw lastFailure ?? new InvalidOperationException($"Planetiler failed for extract '{extract.Id}'.");
|
||||
}
|
||||
|
||||
private ProcessStartInfo CreateStartInfo(
|
||||
TileServerOptions cfg,
|
||||
string jar,
|
||||
Extract extract,
|
||||
string osmPbfPath,
|
||||
string outputMbtilesPath)
|
||||
{
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = java,
|
||||
FileName = cfg.JavaPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
@@ -59,28 +109,36 @@ public sealed class PlanetilerTileBuilder(
|
||||
psi.ArgumentList.Add($"--natural_earth_url={cfg.NaturalEarthUrl}");
|
||||
psi.ArgumentList.Add($"--lake_centerlines_url={cfg.LakeCenterlinesUrl}");
|
||||
psi.ArgumentList.Add($"--water_polygons_url={cfg.WaterPolygonsUrl}");
|
||||
psi.ArgumentList.Add($"--mmap_temp={cfg.PlanetilerMmapTemp.ToString().ToLowerInvariant()}");
|
||||
if (cfg.PlanetilerThreads > 0)
|
||||
{
|
||||
psi.ArgumentList.Add($"--threads={cfg.PlanetilerThreads}");
|
||||
}
|
||||
|
||||
logger.LogInformation("Starting Planetiler for {ExtractId}: {File} {Args}", extract.Id, java, string.Join(' ', psi.ArgumentList));
|
||||
return psi;
|
||||
}
|
||||
|
||||
private async Task<int> RunAsync(ProcessStartInfo psi, string extractId, CancellationToken ct)
|
||||
{
|
||||
using var process = new Process { StartInfo = psi, EnableRaisingEvents = true };
|
||||
process.OutputDataReceived += (_, e) =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(e.Data))
|
||||
{
|
||||
logger.LogInformation("[planetiler {ExtractId}] {Line}", extract.Id, e.Data);
|
||||
logger.LogInformation("[planetiler {ExtractId}] {Line}", extractId, e.Data);
|
||||
}
|
||||
};
|
||||
process.ErrorDataReceived += (_, e) =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(e.Data))
|
||||
{
|
||||
logger.LogInformation("[planetiler {ExtractId}] {Line}", extract.Id, e.Data);
|
||||
logger.LogInformation("[planetiler {ExtractId}] {Line}", extractId, e.Data);
|
||||
}
|
||||
};
|
||||
|
||||
if (!process.Start())
|
||||
{
|
||||
throw new InvalidOperationException($"Failed to start '{java}'.");
|
||||
throw new InvalidOperationException($"Failed to start '{psi.FileName}'.");
|
||||
}
|
||||
|
||||
process.BeginOutputReadLine();
|
||||
@@ -96,14 +154,31 @@ public sealed class PlanetilerTileBuilder(
|
||||
throw;
|
||||
}
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"Planetiler exited with code {process.ExitCode} for extract '{extract.Id}'.");
|
||||
}
|
||||
return process.ExitCode;
|
||||
}
|
||||
|
||||
if (!File.Exists(outputMbtilesPath))
|
||||
private void ClearTmp()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new InvalidOperationException($"Planetiler finished but '{outputMbtilesPath}' was not created.");
|
||||
if (!Directory.Exists(dataPaths.Tmp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in Directory.EnumerateFiles(dataPaths.Tmp))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
foreach (var dir in Directory.EnumerateDirectories(dataPaths.Tmp))
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(ex, "Could not clear Planetiler tmp {Tmp}", dataPaths.Tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user