private void Compact <T>(T functions, long untilAddress, VariableLengthStructSettings <Key, Value> variableLengthStructSettings) where T : IFunctions <Key, Value, Input, Output, Context> { var fhtSession = fht.NewSession(); var originalUntilAddress = untilAddress; var tempKv = new FasterKV <Key, Value, Input, Output, Context, T> (fht.IndexSize, functions, new LogSettings(), comparer: fht.Comparer, variableLengthStructSettings: variableLengthStructSettings); var tempKvSession = tempKv.NewSession(); using (var iter1 = fht.Log.Scan(fht.Log.BeginAddress, untilAddress)) { while (iter1.GetNext(out RecordInfo recordInfo)) { ref var key = ref iter1.GetKey(); ref var value = ref iter1.GetValue(); if (recordInfo.Tombstone) { tempKvSession.Delete(ref key, default, 0);
/// <summary> /// Compact the log until specified address, moving active records to the tail of the log. /// </summary> /// <param name="functions">Functions used to manage key-values during compaction</param> /// <param name="cf">User provided compaction functions (see <see cref="ICompactionFunctions{Key, Value}"/>).</param> /// <param name="untilAddress">Compact log until this address</param> /// <param name="shiftBeginAddress">Whether to shift begin address to untilAddress after compaction. To avoid /// data loss on failure, set this to false, and shift begin address only after taking a checkpoint. This /// ensures that records written to the tail during compaction are first made stable.</param> /// <returns>Address until which compaction was done</returns> public long Compact <Input, Output, Context, Functions, CompactionFunctions>(Functions functions, CompactionFunctions cf, long untilAddress, bool shiftBeginAddress) where Functions : IFunctions <Key, Value, Input, Output, Context> where CompactionFunctions : ICompactionFunctions <Key, Value> { if (untilAddress > fht.Log.SafeReadOnlyAddress) { throw new FasterException("Can compact only until Log.SafeReadOnlyAddress"); } var originalUntilAddress = untilAddress; var lf = new LogCompactionFunctions <Key, Value, Input, Output, Context, Functions>(functions); using var fhtSession = fht.For(lf).NewSession <LogCompactionFunctions <Key, Value, Input, Output, Context, Functions> >(); VariableLengthStructSettings <Key, Value> variableLengthStructSettings = null; if (allocator is VariableLengthBlittableAllocator <Key, Value> varLen) { variableLengthStructSettings = new VariableLengthStructSettings <Key, Value> { keyLength = varLen.KeyLength, valueLength = varLen.ValueLength, }; } using (var tempKv = new FasterKV <Key, Value>(fht.IndexSize, new LogSettings { LogDevice = new NullDevice(), ObjectLogDevice = new NullDevice() }, comparer: fht.Comparer, variableLengthStructSettings: variableLengthStructSettings)) using (var tempKvSession = tempKv.NewSession <Input, Output, Context, Functions>(functions)) { using (var iter1 = fht.Log.Scan(fht.Log.BeginAddress, untilAddress)) { while (iter1.GetNext(out var recordInfo)) { ref var key = ref iter1.GetKey(); ref var value = ref iter1.GetValue(); if (recordInfo.Tombstone || cf.IsDeleted(key, value)) { tempKvSession.Delete(ref key, default, 0);
public FasterKVIterator(FasterKV <Key, Value> fht, Functions functions, long untilAddress) { this.fht = fht; enumerationPhase = 0; VariableLengthStructSettings <Key, Value> variableLengthStructSettings = null; if (fht.hlog is VariableLengthBlittableAllocator <Key, Value> varLen) { variableLengthStructSettings = new VariableLengthStructSettings <Key, Value> { keyLength = varLen.KeyLength, valueLength = varLen.ValueLength, }; } tempKv = new FasterKV <Key, Value>(fht.IndexSize, new LogSettings { LogDevice = new NullDevice(), ObjectLogDevice = new NullDevice(), MutableFraction = 1 }, comparer: fht.Comparer, variableLengthStructSettings: variableLengthStructSettings); tempKvSession = tempKv.NewSession <Input, Output, Context, Functions>(functions); iter1 = fht.Log.Scan(fht.Log.BeginAddress, untilAddress); }
/// <summary> /// Start a new client session with FASTER. /// </summary> /// <param name="functions">Callback functions</param> /// <param name="sessionName">Name of session (optional)</param> /// <param name="sessionVariableLengthStructSettings">Session-specific variable-length struct settings</param> /// <param name="readFlags">ReadFlags for this session; override those specified at FasterKV level, and may be overridden on individual Read operations</param> /// <returns>Session instance</returns> public ClientSession <Key, Value, Input, Output, Context, Functions> NewSession <Functions>(Functions functions, string sessionName = null, SessionVariableLengthStructSettings <Value, Input> sessionVariableLengthStructSettings = null, ReadFlags readFlags = ReadFlags.Default) where Functions : IFunctions <Key, Value, Input, Output, Context> { return(_fasterKV.NewSession <Input, Output, Context, Functions>(functions, sessionName, sessionVariableLengthStructSettings, readFlags)); }
/// <summary> /// Start a new client session with FASTER. /// </summary> /// <param name="functions">Callback functions</param> /// <param name="sessionId">ID/name of session (auto-generated if not provided)</param> /// <param name="threadAffinitized">For advanced users. Specifies whether session holds the thread epoch across calls. Do not use with async code. /// Ensure thread calls session Refresh periodically to move the system epoch forward.</param> /// <param name="sessionVariableLengthStructSettings">Session-specific variable-length struct settings</param> /// <returns>Session instance</returns> public ClientSession <Key, Value, Input, Output, Context, Functions> NewSession <Functions>(Functions functions, string sessionId = null, bool threadAffinitized = false, SessionVariableLengthStructSettings <Value, Input> sessionVariableLengthStructSettings = null) where Functions : IFunctions <Key, Value, Input, Output, Context> { return(_fasterKV.NewSession <Input, Output, Context, Functions>(functions, sessionId, threadAffinitized, sessionVariableLengthStructSettings)); }
/// <summary> /// Start a new client session with FASTER. /// </summary> /// <param name="functions">Callback functions</param> /// <param name="sessionId">ID/name of session (auto-generated if not provided)</param> /// <param name="threadAffinitized">For advanced users. Specifies whether session holds the thread epoch across calls. Do not use with async code. Ensure thread calls session Refresh periodically to move the system epoch forward.</param> /// <returns>Session instance</returns> public ClientSession <Key, Value, Input, Output, Context, Functions> NewSession <Functions>(Functions functions, string sessionId = null, bool threadAffinitized = false) where Functions : IFunctions <Key, Value, Input, Output, Context> { return(_fasterKV.NewSession <Input, Output, Context, Functions>(functions, sessionId, threadAffinitized)); }