Пример #1
0
        /// <summary>
        /// Create server instance; use Start to start the server.
        /// </summary>
        /// <param name="opts"></param>
        public VarLenServer(ServerOptions opts)
        {
            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 <SpanByte, SpanByte>(indexSize, logSettings, checkpointSettings, disableLocking: false);

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

            // Create session provider for VarLen
            provider = new SpanByteFasterKVProvider(store, kvBroker, broker, opts.Recover);

            server = new FasterServerTcp(opts.Address, opts.Port);
            server.Register(WireFormat.DefaultVarLenKV, provider);
            server.Register(WireFormat.WebSocket, provider);
        }
Пример #2
0
 /// <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();
 }
Пример #3
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;
 }
Пример #4
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);
            }
        }
Пример #5
0
 /// <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();
 }
Пример #6
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();
 }
Пример #7
0
        public WebsocketServerSession(
            INetworkSender networkSender,
            FasterKV <Key, Value> store,
            Functions functions,
            ParameterSerializer serializer,
            SubscribeKVBroker <Key, Value, Input, IKeyInputSerializer <Key, Input> > subscribeKVBroker,
            SubscribeBroker <Key, Value, IKeySerializer <Key> > subscribeBroker)
            : base(networkSender, store, functions, null, serializer)
        {
            this.subscribeKVBroker = subscribeKVBroker;
            this.subscribeBroker   = subscribeBroker;

            readHead = 0;

            // Reserve minimum 4 bytes to send pending sequence number as output
            if (this.networkSender.GetMaxSizeSettings.MaxOutputSize < sizeof(int))
            {
                this.networkSender.GetMaxSizeSettings.MaxOutputSize = sizeof(int);
            }
        }
Пример #8
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);
        }
Пример #9
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;
 }
Пример #10
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)