// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; using System.Threading; namespace FASTER.core { /// /// Interface for devices /// public interface IDevice { /// /// Size of sector /// uint SectorSize { get; } /// /// Name of device /// string FileName { get; } /// /// Returns the maximum capacity of the storage device, in number of bytes. /// If returned CAPACITY_UNSPECIFIED, the storage device has no specfied capacity limit. /// long Capacity { get; } /// /// A device breaks up each logical log into multiple self-contained segments that are of the same size. /// It is an atomic unit of data that cannot be partially present on a device (i.e. either the entire segment /// is present or no data from the segment is present). Examples of this include files or named blobs. This /// property returns the size of each segment. /// long SegmentSize { get; } /// /// The index of the first segment present on this device /// int StartSegment { get; } /// /// The index of the last segment present on this device /// int EndSegment { get; } /// /// Initialize device. This function is used to pass optional information that may only be known after /// FASTER initialization (whose constructor takes in IDevice upfront). Implementation are free to ignore /// information if it does not need the supplied information. /// /// This is a bit of a hack. /// /// /// /// The instance of the epoch protection framework to use, if needed /// void Initialize(long segmentSize, LightEpoch epoch = null); /* Segmented addressing API */ /// /// Write /// /// /// /// /// /// /// void WriteAsync(IntPtr sourceAddress, int segmentId, ulong destinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult); /// /// Read /// /// /// /// /// /// /// void ReadAsync(int segmentId, ulong sourceAddress, IntPtr destinationAddress, uint readLength, IOCompletionCallback callback, IAsyncResult asyncResult); /* Direct addressing API */ /// /// Write /// /// /// /// /// /// void WriteAsync(IntPtr alignedSourceAddress, ulong alignedDestinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult); /// /// Read /// /// /// /// /// /// void ReadAsync(ulong alignedSourceAddress, IntPtr alignedDestinationAddress, uint aligned_read_length, IOCompletionCallback callback, IAsyncResult asyncResult); /// /// Truncates the log until the given address. The truncated portion should no longer be accessed as the device is no longer responsible for /// its maintenance, but physical deletion may not happen immediately. /// /// upper bound of truncated address /// callback to invoke when truncation is complete /// result to be passed to the callback void TruncateUntilAddressAsync(long toAddress, AsyncCallback callback, IAsyncResult result); /// /// Truncates the log until the given address. The truncated portion should no longer be accessed as the device is no longer responsible for /// its maintenance, but physical deletion may not happen immediately. This version of the function can block. /// /// upper bound of truncated address void TruncateUntilAddress(long toAddress); /// /// Truncates the log until the given segment. Physical deletion of the given segments are guaranteed to have happened when the callback is invoked. /// /// the largest (in index) segment to truncate /// callback to invoke when truncation is complete /// result to be passed to the callback void TruncateUntilSegmentAsync(int toSegment, AsyncCallback callback, IAsyncResult result); /// /// Truncates the log until the given segment. Physical deletion of the given segments are guaranteed to have happened when the function returns. /// This version of the function can block. /// /// the largest (in index) segment to truncate void TruncateUntilSegment(int toSegment); /// /// Removes a single segment from the device. This function should not normally be called. /// Instead, use /// /// index of the segment to remov /// callback to invoke when removal is complete /// result to be passed to the callback void RemoveSegmentAsync(int segment, AsyncCallback callback, IAsyncResult result); /// /// Removes a single segment from the device. This function should not normally be called. /// Instead, use /// /// index of the segment to remov void RemoveSegment(int segment); /* Close */ /// /// Close /// void Close(); } }