using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace ZB.MOM.WW.CBDDC.Core.Storage; /// /// Handles operations related to the Operation Log (Oplog), synchronization, and logical clocks. /// public interface IOplogStore : ISnapshotable { /// /// Occurs when changes are applied to the store from external sources (sync). /// event EventHandler ChangesApplied; /// /// Appends a new entry to the operation log asynchronously. /// /// The operation log entry to append. Cannot be null. /// A cancellation token that can be used to cancel the append operation. /// A task that represents the asynchronous append operation. Task AppendOplogEntryAsync(OplogEntry entry, CancellationToken cancellationToken = default); /// /// Appends a new entry to the operation log asynchronously for a specific dataset. /// /// The operation log entry to append. /// The dataset identifier. /// A cancellation token. /// A task that represents the asynchronous append operation. Task AppendOplogEntryAsync( OplogEntry entry, string datasetId, CancellationToken cancellationToken = default) { return AppendOplogEntryAsync(entry, cancellationToken); } /// /// Asynchronously retrieves all oplog entries that occurred after the specified timestamp. /// /// The timestamp after which oplog entries should be returned. /// An optional collection of collection names to filter the results. /// A cancellation token that can be used to cancel the asynchronous operation. /// A task that represents the asynchronous operation containing matching oplog entries. Task> GetOplogAfterAsync(HlcTimestamp timestamp, IEnumerable? collections = null, CancellationToken cancellationToken = default); /// /// Asynchronously retrieves oplog entries after the specified timestamp for a specific dataset. /// /// The lower-bound timestamp. /// The dataset identifier. /// Optional collection filter. /// A cancellation token. /// A task containing matching oplog entries. Task> GetOplogAfterAsync( HlcTimestamp timestamp, string datasetId, IEnumerable? collections = null, CancellationToken cancellationToken = default) { return GetOplogAfterAsync(timestamp, collections, cancellationToken); } /// /// Asynchronously retrieves the latest observed hybrid logical clock (HLC) timestamp. /// /// A cancellation token that can be used to cancel the operation. /// A task that represents the asynchronous operation containing the latest HLC timestamp. Task GetLatestTimestampAsync(CancellationToken cancellationToken = default); /// /// Asynchronously retrieves the latest observed timestamp for a specific dataset. /// /// The dataset identifier. /// A cancellation token. /// A task containing the latest timestamp. Task GetLatestTimestampAsync(string datasetId, CancellationToken cancellationToken = default) { return GetLatestTimestampAsync(cancellationToken); } /// /// Asynchronously retrieves the current vector clock representing the state of distributed events. /// /// A cancellation token that can be used to cancel the asynchronous operation. /// A task that represents the asynchronous operation containing the current vector clock. Task GetVectorClockAsync(CancellationToken cancellationToken = default); /// /// Asynchronously retrieves the vector clock for a specific dataset. /// /// The dataset identifier. /// A cancellation token. /// A task containing the vector clock. Task GetVectorClockAsync(string datasetId, CancellationToken cancellationToken = default) { return GetVectorClockAsync(cancellationToken); } /// /// Retrieves a collection of oplog entries for the specified node that occurred after the given timestamp. /// /// The unique identifier of the node for which to retrieve oplog entries. Cannot be null or empty. /// The timestamp after which oplog entries should be returned. /// An optional collection of collection names to filter the oplog entries. /// A cancellation token that can be used to cancel the asynchronous operation. /// A task that represents the asynchronous operation containing oplog entries for the specified node. Task> GetOplogForNodeAfterAsync(string nodeId, HlcTimestamp since, IEnumerable? collections = null, CancellationToken cancellationToken = default); /// /// Retrieves oplog entries for the specified node and dataset after the provided timestamp. /// /// The node identifier. /// The lower-bound timestamp. /// The dataset identifier. /// Optional collection filter. /// A cancellation token. /// A task containing matching oplog entries. Task> GetOplogForNodeAfterAsync( string nodeId, HlcTimestamp since, string datasetId, IEnumerable? collections = null, CancellationToken cancellationToken = default) { return GetOplogForNodeAfterAsync(nodeId, since, collections, cancellationToken); } /// /// Asynchronously retrieves the hash of the most recent entry for the specified node. /// /// /// The unique identifier of the node for which to retrieve the last entry hash. Cannot be null or /// empty. /// /// A cancellation token that can be used to cancel the operation. /// A task that represents the asynchronous operation containing the hash string of the last entry or null. Task GetLastEntryHashAsync(string nodeId, CancellationToken cancellationToken = default); /// /// Asynchronously retrieves the last entry hash for a node within a specific dataset. /// /// The node identifier. /// The dataset identifier. /// A cancellation token. /// A task containing the last hash or null. Task GetLastEntryHashAsync(string nodeId, string datasetId, CancellationToken cancellationToken = default) { return GetLastEntryHashAsync(nodeId, cancellationToken); } /// /// Asynchronously retrieves a sequence of oplog entries representing the chain between the specified start and end /// hashes. /// /// The hash of the first entry in the chain range. Cannot be null or empty. /// The hash of the last entry in the chain range. Cannot be null or empty. /// A cancellation token that can be used to cancel the asynchronous operation. /// A task that represents the asynchronous operation containing OplogEntry objects in chain order. Task> GetChainRangeAsync(string startHash, string endHash, CancellationToken cancellationToken = default); /// /// Asynchronously retrieves a chain range for a specific dataset. /// /// The start hash. /// The end hash. /// The dataset identifier. /// A cancellation token. /// A task containing chain entries. Task> GetChainRangeAsync( string startHash, string endHash, string datasetId, CancellationToken cancellationToken = default) { return GetChainRangeAsync(startHash, endHash, cancellationToken); } /// /// Asynchronously retrieves the oplog entry associated with the specified hash value. /// /// The hash string identifying the oplog entry to retrieve. Cannot be null or empty. /// A cancellation token that can be used to cancel the asynchronous operation. /// A task representing the asynchronous operation containing the OplogEntry if found, otherwise null. Task GetEntryByHashAsync(string hash, CancellationToken cancellationToken = default); /// /// Asynchronously retrieves an entry by hash for a specific dataset. /// /// The entry hash. /// The dataset identifier. /// A cancellation token. /// A task containing the entry when found. Task GetEntryByHashAsync(string hash, string datasetId, CancellationToken cancellationToken = default) { return GetEntryByHashAsync(hash, cancellationToken); } /// /// Applies a batch of oplog entries asynchronously to the target data store. /// /// A collection of OplogEntry objects representing the operations to apply. Cannot be null. /// A cancellation token that can be used to cancel the batch operation. /// A task that represents the asynchronous batch apply operation. Task ApplyBatchAsync(IEnumerable oplogEntries, CancellationToken cancellationToken = default); /// /// Applies a batch of oplog entries asynchronously for a specific dataset. /// /// The entries to apply. /// The dataset identifier. /// A cancellation token. /// A task that represents the apply operation. Task ApplyBatchAsync( IEnumerable oplogEntries, string datasetId, CancellationToken cancellationToken = default) { return ApplyBatchAsync(oplogEntries, cancellationToken); } /// /// Asynchronously removes entries from the oplog that are older than the specified cutoff timestamp. /// /// The timestamp that defines the upper bound for entries to be pruned. /// A cancellation token that can be used to cancel the prune operation. /// A task that represents the asynchronous prune operation. Task PruneOplogAsync(HlcTimestamp cutoff, CancellationToken cancellationToken = default); /// /// Asynchronously removes entries from the specified dataset oplog that are older than the cutoff. /// /// The prune cutoff timestamp. /// The dataset identifier. /// A cancellation token. /// A task that represents the prune operation. Task PruneOplogAsync(HlcTimestamp cutoff, string datasetId, CancellationToken cancellationToken = default) { return PruneOplogAsync(cutoff, cancellationToken); } }