Exemple #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));
        }
Exemple #2
0
        /// <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);
        }
Exemple #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));
 }
Exemple #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;
 }
Exemple #5
0
 /// <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);
 }
Exemple #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));
            }
        }
Exemple #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);
        }
Exemple #8
0
 /// <inheritdoc />
 public override void SingleWriter(ref Key key, ref SpanByte src, ref SpanByte dst)
 {
     src.CopyTo(ref dst);
 }
Exemple #9
0
 /// <inheritdoc />
 public override bool Unlock(ref RecordInfo recordInfo, ref SpanByte key, ref SpanByte value, LockType lockType, long lockContext)
 {
     value.Unlock();
     return(true);
 }
Exemple #10
0
 /// <inheritdoc />
 public override void Lock(ref RecordInfo recordInfo, ref SpanByte key, ref SpanByte value, LockType lockType, ref long lockContext)
 {
     value.SpinLock();
 }
Exemple #11
0
 /// <inheritdoc />
 public override void ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst)
 {
     dst = value.ToByteArray();
 }
Exemple #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);
 }
Exemple #13
0
 /// <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));
 }
 /// <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;
 }
 /// <inheritdoc />
 public override void ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst)
 {
     value.SpinLock();
     dst = value.ToByteArray();
     value.Unlock();
 }
Exemple #16
0
 /// <summary>
 /// Constructor using given SpanByte
 /// </summary>
 /// <param name="spanByte"></param>
 public SpanByteAndMemory(SpanByte spanByte)
 {
     SpanByte = spanByte;
     Memory   = default;
 }
 /// <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();
 }
 /// <inheritdoc />
 public override void SingleReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref byte[] dst, long address)
 {
     dst = value.ToByteArray();
 }
Exemple #19
0
 /// <inheritdoc/>
 public override void InitialUpdater(ref Key key, ref SpanByte input, ref SpanByte value, ref Output output)
 {
     input.CopyTo(ref value);
 }
Exemple #20
0
 /// <inheritdoc/>
 public override void CopyUpdater(ref Key key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue, ref Output output)
 {
     oldValue.CopyTo(ref newValue);
 }
Exemple #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);
 }
Exemple #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());
 }
Exemple #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);
 }
Exemple #24
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)
 {
     AsReadOnlySpan().CopyTo(dst.AsSpan());
 }
Exemple #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);
 }