Beispiel #1
0
 /// <summary>
 /// Create FasterKV backend
 /// </summary>
 /// <param name="store"></param>
 /// <param name="functionsGen"></param>
 /// <param name="serializer"></param>
 /// <param name="maxSizeSettings"></param>
 public FasterKVProvider(FasterKV <Key, Value> store, Func <WireFormat, Functions> functionsGen, ParameterSerializer serializer = default, MaxSizeSettings maxSizeSettings = default)
 {
     this.store           = store;
     this.functionsGen    = functionsGen;
     this.serializer      = serializer;
     this.maxSizeSettings = maxSizeSettings ?? new MaxSizeSettings();
 }
 /// <summary>
 /// Create SpanByte FasterKV backend
 /// </summary>
 /// <param name="store"></param>
 /// <param name="kvBroker"></param>
 /// <param name="broker"></param>
 /// <param name="tryRecover"></param>
 /// <param name="maxSizeSettings"></param>
 public SpanByteFasterKVProvider(FasterKV <SpanByte, SpanByte> store, SubscribeKVBroker <SpanByte, SpanByte, SpanByte, IKeyInputSerializer <SpanByte, SpanByte> > kvBroker = null, SubscribeBroker <SpanByte, SpanByte, IKeySerializer <SpanByte> > broker = null, bool tryRecover = true, MaxSizeSettings maxSizeSettings = default)
 {
     this.storeWrapper    = new StoreWrapper <SpanByte, SpanByte>(store, tryRecover);
     this.kvBroker        = kvBroker;
     this.broker          = broker;
     this.serializer      = new SpanByteServerSerializer();
     this.maxSizeSettings = maxSizeSettings ?? new MaxSizeSettings();
 }
Beispiel #3
0
 public FasterKVServerSessionBase(Socket socket, FasterKV <Key, Value> store, Functions functions,
                                  ParameterSerializer serializer, MaxSizeSettings maxSizeSettings)
     : base(socket, maxSizeSettings)
 {
     session = store.For(new ServerKVFunctions <Key, Value, Input, Output, Functions, ParameterSerializer>(functions, this))
               .NewSession <ServerKVFunctions <Key, Value, Input, Output, Functions, ParameterSerializer> >();
     this.serializer = serializer;
 }
 /// <summary>
 /// Create new instance
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="maxSizeSettings"></param>
 public ServerSessionBase(Socket socket, MaxSizeSettings maxSizeSettings)
 {
     this.socket          = socket;
     this.maxSizeSettings = maxSizeSettings;
     serverBufferSize     = BufferSizeUtils.ServerBufferSize(maxSizeSettings);
     messageManager       = new NetworkSender(serverBufferSize);
     bytesRead            = 0;
 }
Beispiel #5
0
        /// <summary>
        /// Compute required server buffer size
        /// </summary>
        /// <param name="maxSizeSettings">Settings</param>
        /// <returns></returns>
        public static int ServerBufferSize(MaxSizeSettings maxSizeSettings)
        {
            int minSizeRead = maxSizeSettings.MaxOutputSize + 2 + BatchHeader.Size;

            // leave enough space for double buffering
            int minSize = 2 * minSizeRead + sizeof(int);

            return(MaxBatchSize < minSize ? minSize : MaxBatchSize);
        }
Beispiel #6
0
 /// <summary>
 /// Create FasterKV backend
 /// </summary>
 /// <param name="store"></param>
 /// <param name="functionsGen"></param>
 /// <param name="subscribeKVBroker"></param>
 /// <param name="subscribeBroker"></param>
 /// <param name="serializer"></param>
 /// <param name="maxSizeSettings"></param>
 public FasterKVProvider(FasterKV <Key, Value> store, Func <WireFormat, Functions> functionsGen, SubscribeKVBroker <Key, Value, Input, IKeyInputSerializer <Key, Input> > subscribeKVBroker = null, SubscribeBroker <Key, Value, IKeySerializer <Key> > subscribeBroker = null, ParameterSerializer serializer = default, MaxSizeSettings maxSizeSettings = default)
 {
     this.store             = store;
     this.functionsGen      = functionsGen;
     this.serializer        = serializer;
     this.maxSizeSettings   = maxSizeSettings ?? new MaxSizeSettings();
     this.subscribeKVBroker = subscribeKVBroker;
     this.subscribeBroker   = subscribeBroker;
 }
 public FasterKVServerSessionBase(Socket socket, FasterKV <Key, Value> store, Functions functions,
                                  SessionVariableLengthStructSettings <Value, Input> sessionVariableLengthStructSettings,
                                  ParameterSerializer serializer, MaxSizeSettings maxSizeSettings)
     : base(socket, maxSizeSettings)
 {
     session = store.For(new ServerKVFunctions <Key, Value, Input, Output, Functions>(functions, this))
               .NewSession <ServerKVFunctions <Key, Value, Input, Output, Functions> >(sessionVariableLengthStructSettings: sessionVariableLengthStructSettings);
     this.serializer = serializer;
 }
Beispiel #8
0
        /// <summary>
        /// Compute required client buffer size
        /// </summary>
        /// <param name="maxSizeSettings">Settings</param>
        /// <returns></returns>
        public static int ClientBufferSize(MaxSizeSettings maxSizeSettings)
        {
            int minSizeUpsert  = maxSizeSettings.MaxKeySize + maxSizeSettings.MaxValueSize + 2 + BatchHeader.Size;
            int minSizeReadRmw = maxSizeSettings.MaxKeySize + maxSizeSettings.MaxInputSize + 2 + BatchHeader.Size;

            // leave enough space for double buffering
            int minSize = 2 * (minSizeUpsert < minSizeReadRmw ? minSizeReadRmw : minSizeUpsert) + sizeof(int);

            return(MaxBatchSize < minSize ? minSize : MaxBatchSize);
        }
        public ServerSessionBase(Socket socket, FasterKV <Key, Value> store, Functions functions, ParameterSerializer serializer, MaxSizeSettings maxSizeSettings)
        {
            this.socket          = socket;
            session              = store.For(new ServerFunctions <Key, Value, Input, Output, Functions, ParameterSerializer>(functions, this)).NewSession <ServerFunctions <Key, Value, Input, Output, Functions, ParameterSerializer> >();
            this.maxSizeSettings = maxSizeSettings;
            serverBufferSize     = BufferSizeUtils.ServerBufferSize(maxSizeSettings);
            messageManager       = new NetworkSender(serverBufferSize);
            this.serializer      = serializer;

            bytesRead = 0;
        }
Beispiel #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="store">Instance of FasterKV store to use in server</param>
        /// <param name="functionsGen">Functions generator (based on wire format)</param>
        /// <param name="address">IP address</param>
        /// <param name="port">Port</param>
        /// <param name="serializer">Parameter serializer</param>
        /// <param name="maxSizeSettings">Max size settings</param>
        public FasterKVServer(FasterKV <Key, Value> store, Func <WireFormat, Functions> functionsGen, string address, int port, ParameterSerializer serializer = default, MaxSizeSettings maxSizeSettings = default) : base()
        {
            this.maxSizeSettings = maxSizeSettings ?? new MaxSizeSettings();
            var ip       = IPAddress.Parse(address);
            var endPoint = new IPEndPoint(ip, port);

            servSocket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            servSocket.Bind(endPoint);
            servSocket.Listen(512);
            acceptEventArg = new SocketAsyncEventArgs
            {
                UserToken = (store, functionsGen, serializer)
            };
            acceptEventArg.Completed += AcceptEventArg_Completed;
        }
Beispiel #11
0
 /// <summary>
 /// Create SpanByte FasterKV backend
 /// </summary>
 /// <param name="store"></param>
 /// <param name="kvBroker"></param>
 /// <param name="broker"></param>
 /// <param name="recoverStore"></param>
 /// <param name="maxSizeSettings"></param>
 public SpanByteFasterKVProvider(FasterKV <SpanByte, SpanByte> store, SubscribeKVBroker <SpanByte, SpanByte, SpanByte, IKeyInputSerializer <SpanByte, SpanByte> > kvBroker = null, SubscribeBroker <SpanByte, SpanByte, IKeySerializer <SpanByte> > broker = null, bool recoverStore = false, MaxSizeSettings maxSizeSettings = default)
 {
     this.store = store;
     if (recoverStore)
     {
         try
         {
             store.Recover();
         }
         catch
         { }
     }
     this.kvBroker        = kvBroker;
     this.broker          = broker;
     this.serializer      = new SpanByteServerSerializer();
     this.maxSizeSettings = maxSizeSettings ?? new MaxSizeSettings();
 }
 /// <summary>
 /// Create FasterKV backend
 /// </summary>
 /// <param name="store"></param>
 /// <param name="serializer"></param>
 /// <param name="kvBroker"></param>
 /// <param name="broker"></param>
 /// <param name="recoverStore"></param>
 /// <param name="maxSizeSettings"></param>
 public FasterKVProviderBase(FasterKV <Key, Value> store, ParameterSerializer serializer, SubscribeKVBroker <Key, Value, Input, IKeyInputSerializer <Key, Input> > kvBroker = null, SubscribeBroker <Key, Value, IKeySerializer <Key> > broker = null, bool recoverStore = false, MaxSizeSettings maxSizeSettings = default)
 {
     this.store = store;
     if (recoverStore)
     {
         try
         {
             store.Recover();
         }
         catch
         { }
     }
     this.kvBroker        = kvBroker;
     this.broker          = broker;
     this.serializer      = serializer;
     this.maxSizeSettings = maxSizeSettings ?? new MaxSizeSettings();
 }
Beispiel #13
0
        /// <summary>
        /// Create server instance; use Start to start the server.
        /// </summary>
        /// <param name="opts"></param>
        /// <param name="functionsGen"></param>
        /// <param name="serializer"></param>
        /// <param name="keyInputSerializer"></param>
        /// <param name="disableLocking"></param>
        /// <param name="maxSizeSettings"></param>
        public GenericServer(ServerOptions opts, Func <Functions> functionsGen, ParameterSerializer serializer, IKeyInputSerializer <Key, Input> keyInputSerializer,
                             bool disableLocking, MaxSizeSettings maxSizeSettings = default)
        {
            this.opts = opts;

            opts.GetSettings(out logSettings, out var checkpointSettings, out var indexSize);
            if (opts.EnableStorageTier && !Directory.Exists(opts.LogDir))
            {
                Directory.CreateDirectory(opts.LogDir);
            }
            if (!Directory.Exists(opts.CheckpointDir))
            {
                Directory.CreateDirectory(opts.CheckpointDir);
            }

            store = new FasterKV <Key, Value>(indexSize, logSettings, checkpointSettings, disableLocking: disableLocking);

            if (opts.Recover)
            {
                try
                {
                    store.Recover();
                }
                catch { }
            }

            if (!opts.DisablePubSub)
            {
                kvBroker = new SubscribeKVBroker <Key, Value, Input, IKeyInputSerializer <Key, Input> >(keyInputSerializer, null, opts.PubSubPageSizeBytes(), true);
                broker   = new SubscribeBroker <Key, Value, IKeySerializer <Key> >(keyInputSerializer, null, opts.PubSubPageSizeBytes(), true);
            }

            // Create session provider for VarLen
            provider = new FasterKVProvider <Key, Value, Input, Output, Functions, ParameterSerializer>(functionsGen, store, serializer, kvBroker, broker, opts.Recover, maxSizeSettings);

            server = new FasterServerTcp(opts.Address, opts.Port);
            server.Register(WireFormat.DefaultFixedLenKV, provider);
        }
        public BinaryServerSession(Socket socket, FasterKV <Key, Value> store, Functions functions, ParameterSerializer serializer, MaxSizeSettings maxSizeSettings)
            : base(socket, store, functions, serializer, maxSizeSettings)
        {
            readHead = 0;

            // Reserve minimum 4 bytes to send pending sequence number as output
            if (this.maxSizeSettings.MaxOutputSize < sizeof(int))
            {
                this.maxSizeSettings.MaxOutputSize = sizeof(int);
            }
        }
Beispiel #15
0
 /// <summary>
 /// Create new session
 /// </summary>
 public static ClientSession <ReadOnlyMemory <T>, ReadOnlyMemory <T>, ReadOnlyMemory <T>, (IMemoryOwner <T>, int), byte, Functions, MemoryParameterSerializer <T> > NewSession <T, Functions>(this FasterKVClient <ReadOnlyMemory <T>, ReadOnlyMemory <T> > store, Functions functions, WireFormat wireFormat = WireFormat.DefaultVarLenKV, MaxSizeSettings maxSizeSettings = default, MemoryPool <T> memoryPool = default)
     where T : unmanaged
     where Functions : MemoryFunctionsBase <T>
 {
     return(new ClientSession <ReadOnlyMemory <T>, ReadOnlyMemory <T>, ReadOnlyMemory <T>, (IMemoryOwner <T>, int), byte, Functions, MemoryParameterSerializer <T> >
                (store.address, store.port, functions, wireFormat, new MemoryParameterSerializer <T>(memoryPool), maxSizeSettings));
 }
Beispiel #16
0
 /// <summary>
 /// Create new session
 /// </summary>
 public static ClientSession <Key, Value, Value, Value, byte, Functions, FixedLenSerializer <Key, Value, Value, Value> > NewSession <Key, Value, Functions>(this FasterKVClient <Key, Value> store, Functions functions, WireFormat wireFormat = WireFormat.DefaultFixedLenKV, MaxSizeSettings maxSizeSettings = default)
     where Key : unmanaged
     where Value : unmanaged
     where Functions : CallbackFunctionsBase <Key, Value, Value, Value, byte>
 {
     return(new ClientSession <Key, Value, Value, Value, byte, Functions, FixedLenSerializer <Key, Value, Value, Value> >
                (store.address, store.port, functions, wireFormat, new FixedLenSerializer <Key, Value, Value, Value>(), maxSizeSettings));
 }
Beispiel #17
0
        public BinaryServerSession(Socket socket, FasterKV <Key, Value> store, Functions functions, ParameterSerializer serializer, MaxSizeSettings maxSizeSettings, SubscribeKVBroker <Key, Value, Input, IKeyInputSerializer <Key, Input> > subscribeKVBroker, SubscribeBroker <Key, Value, IKeySerializer <Key> > subscribeBroker)
            : base(socket, store, functions, null, serializer, maxSizeSettings)
        {
            this.subscribeKVBroker = subscribeKVBroker;
            this.subscribeBroker   = subscribeBroker;

            readHead = 0;

            // Reserve minimum 4 bytes to send pending sequence number as output
            if (this.maxSizeSettings.MaxOutputSize < sizeof(int))
            {
                this.maxSizeSettings.MaxOutputSize = sizeof(int);
            }
        }
Beispiel #18
0
 /// <summary>
 /// Create session with remote FasterKV server (establishes network connection)
 /// </summary>
 /// <typeparam name="Key">Key</typeparam>
 /// <typeparam name="Value">Value</typeparam>
 /// <returns></returns>
 public static ClientSession <Key, Value, Value, Value, byte, CallbackFunctionsBase <Key, Value, Value, Value, byte>, FixedLenSerializer <Key, Value, Value, Value> > NewSession <Key, Value>(this FasterKVClient <Key, Value> store, MaxSizeSettings maxSizeSettings = default)
     where Key : unmanaged
     where Value : unmanaged
 {
     return(new ClientSession <Key, Value, Value, Value, byte, CallbackFunctionsBase <Key, Value, Value, Value, byte>, FixedLenSerializer <Key, Value, Value, Value> >
                (store.address, store.port, new CallbackFunctionsBase <Key, Value, Value, Value, byte>(), new FixedLenSerializer <Key, Value, Value, Value>(), maxSizeSettings));
 }
Beispiel #19
0
 /// <summary>
 /// Create new session
 /// </summary>
 /// <typeparam name="T">Type of memory (unmanaged)</typeparam>
 /// <param name="store">Client instance of store wrapper</param>
 /// <param name="maxSizeSettings">Settings for max sizes</param>
 /// <param name="memoryPool">Memory pool</param>
 /// <returns>Instance of client session</returns>
 public static ClientSession <ReadOnlyMemory <T>, ReadOnlyMemory <T>, ReadOnlyMemory <T>, (IMemoryOwner <T>, int), byte, MemoryFunctionsBase <T>, MemoryParameterSerializer <T> > NewSession <T>(this FasterKVClient <ReadOnlyMemory <T>, ReadOnlyMemory <T> > store, MaxSizeSettings maxSizeSettings = default, MemoryPool <T> memoryPool = default)
     where T : unmanaged
 {
     return(new ClientSession <ReadOnlyMemory <T>, ReadOnlyMemory <T>, ReadOnlyMemory <T>, (IMemoryOwner <T>, int), byte, MemoryFunctionsBase <T>, MemoryParameterSerializer <T> >
                (store.address, store.port, new MemoryFunctionsBase <T>(), new MemoryParameterSerializer <T>(memoryPool), maxSizeSettings));
 }
Beispiel #20
0
 /// <summary>
 /// Create session with remote FasterKV server (establishes network connection)
 /// </summary>
 /// <typeparam name="Input"></typeparam>
 /// <typeparam name="Output"></typeparam>
 /// <typeparam name="Context"></typeparam>
 /// <typeparam name="Functions"></typeparam>
 /// <typeparam name="ParameterSerializer"></typeparam>
 /// <param name="functions">Local callback functions</param>
 /// <param name="serializer">Parameter serializer</param>
 /// <param name="maxSizeSettings"></param>
 /// <returns></returns>
 public ClientSession <Key, Value, Input, Output, Context, Functions, ParameterSerializer> NewSession <Input, Output, Context, Functions, ParameterSerializer>(Functions functions, ParameterSerializer serializer = default, MaxSizeSettings maxSizeSettings = default)
     where Functions : ICallbackFunctions <Key, Value, Input, Output, Context>
     where ParameterSerializer : IClientSerializer <Key, Value, Input, Output>
 {
     return(new ClientSession <Key, Value, Input, Output, Context, Functions, ParameterSerializer>(address, port, functions, serializer, maxSizeSettings ?? new MaxSizeSettings()));
 }
Beispiel #21
0
 /// <summary>
 /// Create session with remote FasterKV server (establishes network connection)
 /// </summary>
 /// <typeparam name="Key"></typeparam>
 /// <typeparam name="Value"></typeparam>
 /// <typeparam name="Input"></typeparam>
 /// <typeparam name="Output"></typeparam>
 /// <typeparam name="Functions"></typeparam>
 /// <returns></returns>
 public static ClientSession <Key, Value, Input, Output, byte, Functions, FixedLenSerializer <Key, Value, Input, Output> > NewSession <Key, Value, Input, Output, Functions>(this FasterKVClient <Key, Value> store, Functions functions, MaxSizeSettings maxSizeSettings = default)
     where Key : unmanaged
     where Value : unmanaged
     where Input : unmanaged
     where Output : unmanaged
     where Functions : CallbackFunctionsBase <Key, Value, Input, Output, byte>
 {
     return(new ClientSession <Key, Value, Input, Output, byte, Functions, FixedLenSerializer <Key, Value, Input, Output> >
                (store.address, store.port, functions, new FixedLenSerializer <Key, Value, Input, Output>(), maxSizeSettings));
 }
Beispiel #22
0
 /// <summary>
 /// Create server instance; use Start to start the server.
 /// </summary>
 /// <param name="opts"></param>
 /// <param name="functionsGen"></param>
 /// <param name="maxSizeSettings"></param>
 public FixedLenServer(ServerOptions opts, Func <WireFormat, Functions> functionsGen, MaxSizeSettings maxSizeSettings = default)
     : base(opts, functionsGen, new FixedLenSerializer <Key, Value, Input, Output>(), new FixedLenKeySerializer <Key, Input>(), maxSizeSettings)
 {
 }
Beispiel #23
0
 /// <summary>
 /// Create server instance; use Start to start the server.
 /// </summary>
 /// <param name="opts"></param>
 /// <param name="functionsGen"></param>
 /// <param name="disableLocking"></param>
 /// <param name="maxSizeSettings"></param>
 public FixedLenServer(ServerOptions opts, Func <Functions> functionsGen, bool disableLocking, MaxSizeSettings maxSizeSettings = default)
     : base(opts, functionsGen, new FixedLenSerializer <Key, Value, Input, Output>(), new FixedLenKeySerializer <Key, Input>(), disableLocking, maxSizeSettings)
 {
 }
Beispiel #24
0
 /// <summary>
 /// Create FasterKV backend
 /// </summary>
 /// <param name="functionsGen"></param>
 /// <param name="store"></param>
 /// <param name="serializer"></param>
 /// <param name="kvBroker"></param>
 /// <param name="broker"></param>
 /// <param name="recoverStore"></param>
 /// <param name="maxSizeSettings"></param>
 public FasterKVProvider(Func<Functions> functionsGen, FasterKV<Key, Value> store, ParameterSerializer serializer = default, SubscribeKVBroker<Key, Value, Input, IKeyInputSerializer<Key, Input>> kvBroker = null, SubscribeBroker<Key, Value, IKeySerializer<Key>> broker = null, bool recoverStore = false, MaxSizeSettings maxSizeSettings = default)
     : base(store, serializer, kvBroker, broker, recoverStore, maxSizeSettings)
 {
     this.functionsGen = functionsGen;
 }
 /// <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();
 }
Beispiel #26
0
 /// <summary>
 /// Create default SpanByte FasterKV backend with SpanByteFunctionsForServer&lt;long&gt; as functions, and SpanByteServerSerializer as parameter serializer
 /// </summary>
 /// <param name="store"></param>
 /// <param name="kvBroker"></param>
 /// <param name="broker"></param>
 /// <param name="recoverStore"></param>
 /// <param name="maxSizeSettings"></param>
 public SpanByteFasterKVProvider(FasterKV <SpanByte, SpanByte> store, SubscribeKVBroker <SpanByte, SpanByte, SpanByte, IKeyInputSerializer <SpanByte, SpanByte> > kvBroker = null, SubscribeBroker <SpanByte, SpanByte, IKeySerializer <SpanByte> > broker = null, bool recoverStore = false, MaxSizeSettings maxSizeSettings = default)
     : base(store, new(), kvBroker, broker, recoverStore, maxSizeSettings)