/// <inheritdoc /> public Task <FdbRangeChunk> GetRangeAsync(KeySelector beginInclusive, KeySelector endExclusive, int limit = 0, bool reverse = false, int targetBytes = 0, FdbStreamingMode mode = FdbStreamingMode.Exact, FdbReadMode read = FdbReadMode.Both, int iteration = 0) { EnsureCanRead(); FdbKey.EnsureKeyIsValid(beginInclusive.Key); FdbKey.EnsureKeyIsValid(endExclusive.Key, endExclusive: true); FdbRangeOptions.EnsureLegalValues(limit, targetBytes, mode, read, iteration); // The iteration value is only needed when in iterator mode, but then it should start from 1 if (iteration == 0) { iteration = 1; } return(m_parent.PerformGetRangeOperation(beginInclusive, endExclusive, snapshot: true, limit, reverse, targetBytes, mode, read, iteration)); }
/// <summary>Add all missing values from the provided defaults</summary> /// <param name="options">Options provided by the caller (can be null)</param> /// <param name="limit">Default value for Limit if not provided</param> /// <param name="targetBytes">Default TargetBytes for limit if not provided</param> /// <param name="mode">Default value for Streaming mode if not provided</param> /// <param name="read">Default value for Read mode if not provided</param> /// <param name="reverse">Default value for Reverse if not provided</param> /// <returns>Options with all the values filled</returns> public static FdbRangeOptions EnsureDefaults(FdbRangeOptions options, int?limit, int?targetBytes, FdbStreamingMode mode, FdbReadMode read, bool reverse) { Contract.Requires((limit ?? 0) >= 0 && (targetBytes ?? 0) >= 0); if (options == null) { options = new FdbRangeOptions() { Limit = limit, TargetBytes = targetBytes, Mode = mode, Reverse = reverse, Read = read, }; } else if (options.Limit == null || options.TargetBytes == null || options.Mode == null || options.Reverse == null || options.Read == null) { options = new FdbRangeOptions { Limit = options.Limit ?? limit, TargetBytes = options.TargetBytes ?? targetBytes, Mode = options.Mode ?? mode, Read = options.Read ?? read, Reverse = options.Reverse ?? reverse }; } Contract.Ensures(options.Mode != null && options.Reverse != null); Contract.Ensures((options.Limit ?? 0) >= 0, "Limit cannot be negative"); Contract.Ensures((options.TargetBytes ?? 0) >= 0, "TargetBytes cannot be negative"); Contract.Ensures(options.Mode.HasValue && Enum.IsDefined(typeof(FdbStreamingMode), options.Mode.Value), "Streaming mode must be valid"); Contract.Ensures(options.Read.HasValue && Enum.IsDefined(typeof(FdbReadMode), options.Read.Value), "Reading mode must be valid"); return(options); }
/// <summary>Asynchronously fetch a new page of results</summary> /// <returns>True if Chunk contains a new page of results. False if all results have been read.</returns> public Task <FdbRangeChunk> GetRangeAsync(KeySelector begin, KeySelector end, int limit, bool reversed, int targetBytes, FdbStreamingMode mode, FdbReadMode read, int iteration, bool snapshot, CancellationToken ct) { var future = FdbNative.TransactionGetRange(m_handle, begin, end, limit, targetBytes, mode, iteration, snapshot, reversed); return(FdbFuture.CreateTaskFromHandle( future, (h) => { KeyValuePair <Slice, Slice>[] items; bool hasMore; Slice first, last; switch (read) { case FdbReadMode.Both: { items = GetKeyValueArrayResult(h, out hasMore, out first, out last); break; } case FdbReadMode.Keys: { items = GetKeyValueArrayResultKeysOnly(h, out hasMore, out first, out last); break; } case FdbReadMode.Values: { items = GetKeyValueArrayResultValuesOnly(h, out hasMore, out first, out last); break; } default: { throw new InvalidOperationException(); } } return new FdbRangeChunk(items, hasMore, iteration, reversed, read, first, last); }, ct )); }
public FdbRangeChunk([NotNull] KeyValuePair <Slice, Slice>[] items, bool hasMore, int iteration, bool reversed, FdbReadMode readMode, Slice first, Slice last) { Contract.NotNull(items, nameof(items)); this.Items = items; this.HasMore = hasMore; this.Iteration = iteration; this.Reversed = reversed; this.ReadMode = readMode; this.First = first; this.Last = last; }
internal static void EnsureLegalValues(int limit, int targetBytes, FdbStreamingMode mode, FdbReadMode read, int iteration) { if (limit < 0) { throw InvalidOptionValue("Range Limit cannot be negative."); } if (targetBytes < 0) { throw InvalidOptionValue("Range TargetBytes cannot be negative."); } if (mode < FdbStreamingMode.WantAll || mode > FdbStreamingMode.Serial) { throw InvalidOptionValue("Range StreamingMode must be valid."); } if (read < FdbReadMode.Both || read > FdbReadMode.Values) { throw InvalidOptionValue("Range ReadMode must be valid."); } if (iteration < 0) { throw InvalidOptionValue("Iteration counter cannot be negative."); } }