-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C#] SpanByteFasterKVProvider (#520)
* Added SpanByteFasterKVProvider, and changed SpanByteSerializer to SpanByteServerSerializer and SpanByteClientSerializer * Removed unnecessary functions / debugs * fixed nit
- Loading branch information
1 parent
1b319a5
commit 0504248
Showing
6 changed files
with
116 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using FASTER.common; | ||
using FASTER.core; | ||
using System.Buffers; | ||
|
||
namespace FASTER.client | ||
{ | ||
/// <summary> | ||
/// Serializer for SpanByte (can be used on client side) | ||
/// </summary> | ||
public unsafe class SpanByteClientSerializer : IClientSerializer<SpanByte, SpanByte, SpanByte, SpanByteAndMemory> | ||
{ | ||
readonly MemoryPool<byte> memoryPool; | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="memoryPool"></param> | ||
public SpanByteClientSerializer(MemoryPool<byte> memoryPool = default) | ||
{ | ||
this.memoryPool = memoryPool ?? MemoryPool<byte>.Shared; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public SpanByteAndMemory ReadOutput(ref byte* src) | ||
{ | ||
int length = *(int*)src; | ||
var mem = memoryPool.Rent(length); | ||
new ReadOnlySpan<byte>(src + sizeof(int), length).CopyTo(mem.Memory.Span); | ||
src += length + sizeof(int); | ||
return new SpanByteAndMemory(mem, length); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Write(ref SpanByte k, ref byte* dst, int length) | ||
{ | ||
var len = k.TotalSize; | ||
if (length < len) return false; | ||
k.CopyTo(dst); | ||
dst += len; | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
using FASTER.common; | ||
using FASTER.core; | ||
|
||
namespace FASTER.server | ||
{ | ||
|
||
/// <summary> | ||
/// Session provider for FasterKV store based on | ||
/// [K, V, I, O, C] = [SpanByte, SpanByte, SpanByte, SpanByteAndMemory, long] | ||
/// </summary> | ||
public sealed class SpanByteFasterKVProvider : ISessionProvider, IDisposable | ||
{ | ||
readonly FasterKV<SpanByte, SpanByte> store; | ||
readonly SpanByteServerSerializer serializer; | ||
readonly MaxSizeSettings maxSizeSettings; | ||
|
||
/// <summary> | ||
/// Create SpanByte FasterKV backend | ||
/// </summary> | ||
/// <param name="store"></param> | ||
/// <param name="maxSizeSettings"></param> | ||
public SpanByteFasterKVProvider(FasterKV<SpanByte, SpanByte> store, MaxSizeSettings maxSizeSettings = default) | ||
{ | ||
this.store = store; | ||
this.serializer = new SpanByteServerSerializer(); | ||
this.maxSizeSettings = maxSizeSettings ?? new MaxSizeSettings(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IServerSession GetSession(WireFormat wireFormat, Socket socket) | ||
{ | ||
return new BinaryServerSession<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, SpanByteFunctionsForServer<long>, SpanByteServerSerializer> | ||
(socket, store, new SpanByteFunctionsForServer<long>(wireFormat), serializer, maxSizeSettings); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters