// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using EpicGames.Horde.Storage; namespace Jupiter.Implementation { public interface IContentIdStore { /// /// Resolve a content id from its hash into the actual blob (that can in turn be chunked into a set of blobs) /// /// The namespace to operate in /// The identifier for the content id /// /// Cancellation token for the operation /// Task ResolveAsync(NamespaceId ns, ContentId contentId, bool mustBeContentId = false, CancellationToken cancellationToken = default); /// /// Add a mapping from contentId to a chunked set of blobIdentifiers /// /// The namespace to operate in /// The contentId /// The blob the content id maps to /// Weight of this identifier compared to previous mappings, used to determine which is more important, lower weight is considered a better fit /// Cancellation token for the operation /// Task PutAsync(NamespaceId ns, ContentId contentId, BlobId[] blobIdentifiers, int contentWeight, CancellationToken cancellationToken = default); /// /// Retrieve the underlying content id mapping structure /// /// The namespace to operate in /// The content id you wish to fetch the mapping for /// Cancellation token /// All existing mappings for that content id IAsyncEnumerable GetContentIdMappingsAsync(NamespaceId ns, ContentId identifier, CancellationToken cancellationToken = default); } public class ContentIdMapping { public ContentIdMapping(int weight, BlobId[] referencedBlobs) { Weight = weight; ReferencedBlobs = referencedBlobs; } public int Weight { get; set; } public BlobId[] ReferencedBlobs { get; set; } } public class InvalidContentIdException : Exception { public InvalidContentIdException(ContentId contentId) : base($"Unknown content id {contentId}") { } } public class ContentIdResolveException : Exception { public ContentId ContentId { get; } public ContentIdResolveException(ContentId contentId) : base($"Unable to find any mapping of contentId {contentId} that has all blobs present") { ContentId = contentId; } } }