// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; namespace FASTER.core { /// /// Interface to FASTER key-value store /// (customized for sample types Key, Value, Input, Output, Context) /// Since there are pointers in the API, we cannot automatically create a /// generic version covering arbitrary blittable types. Instead, the /// user defines the customized interface and provides it to FASTER /// so it can return a (generated) instance for that interface. /// public interface IFasterKV : IDisposable where Key : new() where Value : new() { /* Thread-related operations */ /// /// Start a session with FASTER. FASTER sessions correspond to threads issuing /// operations to FASTER. /// /// Session identifier Guid StartSession(); /// /// Continue a session after recovery. Provide FASTER with the identifier of the /// session that is being continued. /// /// /// Sequence number for resuming operations long ContinueSession(Guid guid); /// /// Stop a session and de-register the thread from FASTER. /// void StopSession(); /// /// Refresh the session epoch. The caller is required to invoke Refresh periodically /// in order to guarantee system liveness. /// void Refresh(); /* Store Interface */ /// /// Read operation /// /// Key of read /// Input argument used by Reader to select what part of value to read /// Reader stores the read result in output /// User context to identify operation in asynchronous callback /// Increasing sequence number of operation (used for recovery) /// Status of operation Status Read(ref Key key, ref Input input, ref Output output, Context context, long lsn); /// /// (Blind) upsert operation /// /// Key of read /// Value being upserted /// User context to identify operation in asynchronous callback /// Increasing sequence number of operation (used for recovery) /// Status of operation Status Upsert(ref Key key, ref Value value, Context context, long lsn); /// /// Atomic read-modify-write operation /// /// Key of read /// Input argument used by RMW callback to perform operation /// User context to identify operation in asynchronous callback /// Increasing sequence number of operation (used for recovery) /// Status of operation Status RMW(ref Key key, ref Input input, Context context, long lsn); /// /// Delete entry (use tombstone if necessary) /// Hash entry is removed as a best effort (if key is in memory and at /// the head of hash chain. /// Value is set to null (using ConcurrentWrite) if it is in mutable region /// /// /// /// /// Status Delete(ref Key key, Context userContext, long monotonicSerialNum); /// /// Complete all pending operations issued by this session /// /// Whether we spin-wait for pending operations to complete /// Whether all pending operations have completed bool CompletePending(bool wait); /* Recovery */ /// /// Take full checkpoint of FASTER /// /// Token describing checkpoint /// Whether checkpoint was initiated bool TakeFullCheckpoint(out Guid token); /// /// Take checkpoint of FASTER index only (not log) /// /// Token describing checkpoin /// Whether checkpoint was initiated bool TakeIndexCheckpoint(out Guid token); /// /// Take checkpoint of FASTER log only (not index) /// /// Token describing checkpoin /// Whether checkpoint was initiated bool TakeHybridLogCheckpoint(out Guid token); /// /// Recover from last successfuly checkpoints /// void Recover(); /// /// Recover using full checkpoint token /// /// void Recover(Guid fullcheckpointToken); /// /// Recover using a separate index and log checkpoint token /// /// /// void Recover(Guid indexToken, Guid hybridLogToken); /// /// Complete ongoing checkpoint (spin-wait) /// /// /// Whether checkpoint has completed bool CompleteCheckpoint(bool wait); /// /// Grow the hash index /// /// bool GrowIndex(); /// /// Get number of (non-zero) hash entries in FASTER /// long EntryCount { get; } /// /// Get size of index in #cache lines (64 bytes each) /// long IndexSize { get; } /// /// Get comparer used by this instance of FASTER /// IFasterEqualityComparer Comparer { get; } /// /// Dump distribution of #entries in hash table /// string DumpDistribution(); /// /// Experimental feature /// Check if FASTER contains key in memory (between HeadAddress /// and tail), or between the specified fromAddress (after /// HeadAddress) and tail /// /// /// /// Status ContainsKeyInMemory(ref Key key, long fromAddress = -1); /// /// Get accessor for FASTER hybrid log /// LogAccessor Log { get; } /// /// Get accessor for FASTER read cache /// LogAccessor ReadCache { get; } } }