예제 #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 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);
        }