public FdbRangeOptions WithStreamingMode(FdbStreamingMode mode)
 {
     return(this.Mode == mode ? this : new FdbRangeOptions(this)
     {
         Mode = mode
     });
 }
		/// <summary>Create a new set of options</summary>
		public FdbRangeOptions(int? limit, bool? reverse = null, int? targetBytes = null, FdbStreamingMode? mode = null)
		{
			this.Limit = limit;
			this.Reverse = reverse;
			this.TargetBytes = targetBytes;
			this.Mode = mode;
		}
        public FdbRangeQuery <T> WithMode(FdbStreamingMode mode)
        {
            if (!Enum.IsDefined(typeof(FdbStreamingMode), mode))
            {
                throw new ArgumentOutOfRangeException("mode", "Unsupported streaming mode");
            }

            return(new FdbRangeQuery <T>(
                       this,
                       new FdbRangeOptions(this.Options)
            {
                Mode = mode
            }
                       ));
        }
 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.");
     }
 }
Exemple #5
0
            /// <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);
        }
Exemple #7
0
        /// <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
                       ));
        }
Exemple #8
0
 public static extern FutureHandle fdb_transaction_get_range(
     TransactionHandle transaction,
     byte *beginKeyName, int beginKeyNameLength, bool beginOrEqual, int beginOffset,
     byte *endKeyName, int endKeyNameLength, bool endOrEqual, int endOffset,
     int limit, int targetBytes, FdbStreamingMode mode, int iteration, bool snapshot, bool reverse
     );
		/// <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 StreamingMode 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, bool reverse)
		{
			Contract.Requires((limit ?? 0) >= 0 && (targetBytes ?? 0) >= 0 && Enum.IsDefined(typeof(FdbStreamingMode), mode));

			if (options == null)
			{
				options = new FdbRangeOptions()
				{
					Limit = limit,
					TargetBytes = targetBytes,
					Mode = mode,
					Reverse = reverse
				};
			}
			else if (options.Limit == null || options.TargetBytes == null || options.Mode == null || options.Reverse == null)
			{
				options = new FdbRangeOptions()
				{
					Limit = options.Limit ?? limit,
					TargetBytes = options.TargetBytes ?? targetBytes,
					Mode = options.Mode ?? mode,
					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");

			return options;
		}
		public FdbRangeOptions WithStreamingMode(FdbStreamingMode mode)
		{
			return this.Mode == mode ? this : new FdbRangeOptions(this) { Mode = mode };
		}
		public static FutureHandle TransactionGetRange(TransactionHandle transaction, FdbKeySelector begin, FdbKeySelector end, int limit, int targetBytes, FdbStreamingMode mode, int iteration, bool snapshot, bool reverse)
		{
			fixed (byte* ptrBegin = begin.Key.Array)
			fixed (byte* ptrEnd = end.Key.Array)
			{
				var future = NativeMethods.fdb_transaction_get_range(
					transaction,
					ptrBegin + begin.Key.Offset, begin.Key.Count, begin.OrEqual, begin.Offset,
					ptrEnd + end.Key.Offset, end.Key.Count, end.OrEqual, end.Offset,
					limit, targetBytes, mode, iteration, snapshot, reverse);
				Contract.Assert(future != null);
#if DEBUG_NATIVE_CALLS
					Debug.WriteLine("fdb_transaction_get_range(0x" + transaction.Handle.ToString("x") + ", begin: " + begin.PrettyPrint(FdbKey.PrettyPrintMode.Begin) + ", end: " + end.PrettyPrint(FdbKey.PrettyPrintMode.End) + ", " + snapshot + ") => 0x" + future.Handle.ToString("x"));
#endif
				return future;
			}
		}
			public static extern FutureHandle fdb_transaction_get_range(
				TransactionHandle transaction,
				byte* beginKeyName, int beginKeyNameLength, bool beginOrEqual, int beginOffset,
				byte* endKeyName, int endKeyNameLength, bool endOrEqual, int endOffset,
				int limit, int targetBytes, FdbStreamingMode mode, int iteration, bool snapshot, bool reverse
			);