fix: make transcode leases ownership-checked and cleanup-aware
Cleanup never matched a live session because the controller registered empty manifest and segment paths, renewal was a read-modify-write that could revert a takeover, and the takeover script compared an ISO date to a number, so it errored. - populate the session record's manifest and segment paths from the playlist path - renew the lease via a Lua compare-and-set on the owning pod - store the lease expiry as unix milliseconds so the scripts can compare it - retain the session record past its lease so an orphan can still be taken over - test the Redis store against a real Redis, including the renew-vs-takeover race - drop the live stream record nothing ever read back
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MediaBrowser.Controller.MediaEncoding;
|
||||
|
||||
@@ -46,4 +47,40 @@ public sealed class TranscodeSession
|
||||
/// Gets or sets the last durable playback offset in ticks, used to resume playback after failover.
|
||||
/// </summary>
|
||||
public long LastDurablePlaybackOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a session record for an HLS output, deriving <see cref="ManifestPath"/> and
|
||||
/// <see cref="SegmentPathPrefix"/> from the playlist path so that cleanup can recognise
|
||||
/// every file the session owns.
|
||||
/// </summary>
|
||||
/// <param name="playSessionId">The play session identifier.</param>
|
||||
/// <param name="mediaSourceId">The media source identifier.</param>
|
||||
/// <param name="ownerPod">The name of the pod that owns the session.</param>
|
||||
/// <param name="playlistPath">The absolute path of the HLS playlist (.m3u8) file.</param>
|
||||
/// <param name="leaseDuration">The initial lease duration.</param>
|
||||
/// <returns>The new <see cref="TranscodeSession"/>.</returns>
|
||||
public static TranscodeSession CreateForPlaylist(
|
||||
string playSessionId,
|
||||
string mediaSourceId,
|
||||
string ownerPod,
|
||||
string playlistPath,
|
||||
TimeSpan leaseDuration)
|
||||
=> new TranscodeSession
|
||||
{
|
||||
PlaySessionId = playSessionId,
|
||||
OwnerPod = ownerPod,
|
||||
LeaseExpiresUtc = DateTime.UtcNow.Add(leaseDuration),
|
||||
ManifestPath = playlistPath,
|
||||
SegmentPathPrefix = GetSegmentPathPrefix(playlistPath),
|
||||
MediaSourceId = mediaSourceId,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the prefix every segment file of the HLS output at <paramref name="playlistPath"/> starts with.
|
||||
/// Segments are written as <c><playlist path without extension><index><segment extension></c>.
|
||||
/// </summary>
|
||||
/// <param name="playlistPath">The absolute path of the HLS playlist (.m3u8) file.</param>
|
||||
/// <returns>The segment path prefix.</returns>
|
||||
public static string GetSegmentPathPrefix(string playlistPath)
|
||||
=> Path.ChangeExtension(playlistPath, null) ?? playlistPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user