コード例 #1
0
        /// <inheritdoc/>
        public override bool InPlaceUpdater(ref Key key, ref SpanByte input, ref SpanByte value, ref Output output, ref RMWInfo rmwInfo)
        {
            // The default implementation of IPU simply writes input to destination, if there is space
            UpsertInfo upsertInfo = new(ref rmwInfo);

            return(ConcurrentWriter(ref key, ref input, ref input, ref value, ref output, ref upsertInfo));
        }
コード例 #2
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
        /// <inheritdoc />
        public override bool ConcurrentWriter(ref Key key, ref SpanByte src, ref SpanByte dst)
        {
            if (locking)
            {
                dst.SpinLock();
            }

            // We can write the source (src) data to the existing destination (dst) in-place,
            // only if there is sufficient space
            if (dst.Length < src.Length || dst.IsMarkedReadOnly())
            {
                dst.MarkReadOnly();
                if (locking)
                {
                    dst.Unlock();
                }
                return(false);
            }

            // Option 1: write the source data, leaving the destination size unchanged. You will need
            // to mange the actual space used by the value if you stop here.
            src.CopyTo(ref dst);

            // We can adjust the length header on the serialized log, if we wish.
            // This method will also zero out the extra space to retain log scan correctness.
            dst.ShrinkSerializedLength(src.Length);

            if (locking)
            {
                dst.Unlock();
            }
            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Upsert with Span input
 /// </summary>
 /// <param name="clientSession"></param>
 /// <param name="key"></param>
 /// <param name="desiredValue"></param>
 /// <param name="userContext"></param>
 /// <param name="serialNo"></param>
 /// <returns></returns>
 public static Status Upsert <Input, Output, Context, Functions>(this ClientSession <SpanByte, SpanByte, Input, Output, Context, Functions> clientSession, ReadOnlySpan <byte> key, ReadOnlySpan <byte> desiredValue, Context userContext = default, long serialNo = 0)
     where Functions : IFunctions <SpanByte, SpanByte, Input, Output, Context>
 {
     fixed(byte *k = key)
     fixed(byte *v = desiredValue)
     return(clientSession.Upsert(SpanByte.FromFixedSpan(key), SpanByte.FromFixedSpan(desiredValue), userContext, serialNo));
 }
コード例 #4
0
 /// <summary>
 /// Constructor using given SpanByte
 /// </summary>
 /// <param name="spanByte"></param>
 public SpanByteAndMemory(SpanByte spanByte)
 {
     if (spanByte.Serialized)
     {
         throw new Exception("Cannot create new SpanByteAndMemory using serialized SpanByte");
     }
     SpanByte = spanByte;
     Memory   = default;
 }
コード例 #5
0
ファイル: SpanByte.cs プロジェクト: rustedwizard/FASTER
 /// <summary>
 /// Try to copy to given pre-allocated SpanByte, checking if space permits at destination SpanByte
 /// </summary>
 /// <param name="dst"></param>
 public bool TryCopyTo(ref SpanByte dst)
 {
     if (dst.Length < Length)
     {
         return(false);
     }
     CopyTo(ref dst);
     return(true);
 }
コード例 #6
0
        /// <summary>
        /// Delete with Span input
        /// </summary>
        /// <typeparam name="Input"></typeparam>
        /// <typeparam name="Output"></typeparam>
        /// <typeparam name="Context"></typeparam>
        /// <typeparam name="Functions"></typeparam>
        /// <param name="clientSession"></param>
        /// <param name="key"></param>
        /// <param name="userContext"></param>
        /// <param name="serialNo"></param>
        /// <returns></returns>
        public static Status Delete <Input, Output, Context, Functions>(this ClientSession <SpanByte, SpanByte, Input, Output, Context, Functions> clientSession, ReadOnlySpan <byte> key, Context userContext = default, long serialNo = 0)
            where Functions : IFunctions <SpanByte, SpanByte, Input, Output, Context>
        {
            fixed(byte *k = key)
            {
                var _key = SpanByte.FromFixedSpan(key);

                return(clientSession.Delete(ref _key, userContext, serialNo));
            }
        }
コード例 #7
0
        /// <inheritdoc />
        public override bool ConcurrentWriter(ref Key key, ref SpanByte input, ref SpanByte src, ref SpanByte dst, ref Output output, ref UpsertInfo upsertInfo)
        {
            if (dst.Length < src.Length)
            {
                return(false);
            }

            // We can adjust the length header on the serialized log, if we wish.
            // This method will also zero out the extra space to retain log scan correctness.
            dst.UnmarkExtraMetadata();
            dst.ShrinkSerializedLength(src.Length);

            // Write the source data, leaving the destination size unchanged. You will need
            // to mange the actual space used by the value if you stop here.
            src.CopyTo(ref dst);

            return(true);
        }
コード例 #8
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc />
 public override void SingleWriter(ref Key key, ref SpanByte src, ref SpanByte dst)
 {
     src.CopyTo(ref dst);
 }
コード例 #9
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc />
 public override bool Unlock(ref RecordInfo recordInfo, ref SpanByte key, ref SpanByte value, LockType lockType, long lockContext)
 {
     value.Unlock();
     return(true);
 }
コード例 #10
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc />
 public override void Lock(ref RecordInfo recordInfo, ref SpanByte key, ref SpanByte value, LockType lockType, ref long lockContext)
 {
     value.SpinLock();
 }
コード例 #11
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc />
 public override void ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst)
 {
     dst = value.ToByteArray();
 }
コード例 #12
0
 /// <inheritdoc/>
 public override bool InitialUpdater(ref Key key, ref SpanByte input, ref SpanByte value, ref Output output, ref RMWInfo rmwInfo)
 {
     input.CopyTo(ref value);
     return(true);
 }
コード例 #13
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc/>
 public override bool InPlaceUpdater(ref Key key, ref SpanByte input, ref SpanByte value, ref Output output)
 {
     // The default implementation of IPU simply writes input to destination, if there is space
     return(ConcurrentWriter(ref key, ref input, ref value));
 }
コード例 #14
0
 /// <summary>
 /// Constructor using SpanByte at given (fixed) pointer, of given length
 /// </summary>
 public SpanByteAndMemory(void *pointer, int length)
 {
     SpanByte = new SpanByte(length, (IntPtr)pointer);
     Memory   = default;
 }
コード例 #15
0
 /// <inheritdoc />
 public override void ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst)
 {
     value.SpinLock();
     dst = value.ToByteArray();
     value.Unlock();
 }
コード例 #16
0
 /// <summary>
 /// Constructor using given SpanByte
 /// </summary>
 /// <param name="spanByte"></param>
 public SpanByteAndMemory(SpanByte spanByte)
 {
     SpanByte = spanByte;
     Memory   = default;
 }
コード例 #17
0
 /// <inheritdoc />
 public override void ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst, ref RecordInfo recordInfo, long address)
 {
     dst = value.ToByteArray();
 }
コード例 #18
0
 /// <inheritdoc />
 public override void SingleReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst, long address)
 {
     dst = value.ToByteArray();
 }
コード例 #19
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc/>
 public override void InitialUpdater(ref Key key, ref SpanByte input, ref SpanByte value, ref Output output)
 {
     input.CopyTo(ref value);
 }
コード例 #20
0
ファイル: SpanByteFunctions.cs プロジェクト: tli2/FASTER
 /// <inheritdoc/>
 public override void CopyUpdater(ref Key key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue, ref Output output)
 {
     oldValue.CopyTo(ref newValue);
 }
コード例 #21
0
 /// <inheritdoc />
 public override bool SingleWriter(ref Key key, ref SpanByte input, ref SpanByte src, ref SpanByte dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason)
 {
     src.CopyTo(ref dst);
     return(true);
 }
コード例 #22
0
 /// <summary>
 /// Blindly copy to given pre-allocated SpanByte, assuming sufficient space.
 /// Does not change length of destination.
 /// </summary>
 /// <param name="dst"></param>
 public void CopyTo(ref SpanByte dst)
 {
     dst.ExtraMetadata = ExtraMetadata;
     AsReadOnlySpan().CopyTo(dst.AsSpan());
 }
コード例 #23
0
 /// <inheritdoc/>
 public override bool CopyUpdater(ref Key key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue, ref Output output, ref RMWInfo rmwInfo)
 {
     oldValue.CopyTo(ref newValue);
     return(true);
 }
コード例 #24
0
ファイル: SpanByte.cs プロジェクト: rustedwizard/FASTER
 /// <summary>
 /// Blindly copy to given pre-allocated SpanByte, assuming sufficient space.
 /// Does not change length of destination.
 /// </summary>
 /// <param name="dst"></param>
 public void CopyTo(ref SpanByte dst)
 {
     AsReadOnlySpan().CopyTo(dst.AsSpan());
 }
コード例 #25
0
 /// <inheritdoc />
 public override bool ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst, ref ReadInfo readInfo)
 {
     dst = value.ToByteArray();
     return(true);
 }