示例#1
0
        static IEnumerable <TOut> InternalScan <TOut>(Tx tx, byte[] key,
                                                      Func <Slice, byte[], TOut> convert, string traceName, int skip = 0)
        {
            tx.TraceStart(traceName);

            ushort x     = 0;
            var    slice = Slice.Create(key);
            var    range = FdbKeyRange.StartsWith(slice);

            using (var c = tx.CreateCursor()) {
                if (!c.MoveToFirstAfter(key))
                {
                    tx.TraceStop(traceName, x);
                    yield break;
                }

                var pair = c.Current;

                for (var i = 0; i < int.MaxValue; i++)
                {
                    var current = Slice.Create(pair.Key);
                    if (!range.Contains(current))
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }
                    if (i >= skip)
                    {
                        x += 1;
                        yield return(convert(current, pair.Value));
                    }

                    if (!c.MoveNext())
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }
                    pair = c.Current;
                }
            }
        }
示例#2
0
        public static void DeleteRange(Tx tx, byte[] key, string traceName)
        {
            tx.TraceStart(traceName);
            ushort x     = 0;
            var    slice = Slice.Create(key);
            var    range = FdbKeyRange.StartsWith(slice);

            using (var c = tx.CreateCursor()) {
                if (!c.MoveToFirstAfter(key))
                {
                    tx.TraceStop(traceName, x);
                    return;
                }

                var pair = c.Current;

                for (var i = 0; i < int.MaxValue; i++)
                {
                    var current = Slice.Create(pair.Key);
                    if (!range.Contains(current))
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }

                    x += 1;
                    tx.Delete(pair.Key);

                    if (!c.MoveNext())
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }
                    pair = c.Current;
                }
            }


            tx.TraceStop(traceName);
        }
示例#3
0
 public static void Delete(Tx tx, byte[] key)
 {
     tx.TraceStart("Delete");
     tx.Delete(key);
     tx.TraceStop("Delete");
 }