protected override void OnArgsParsed(SingleNodeOptions options) { var now = DateTime.UtcNow; TfDb = GetTfDb(options, now); _appSets = GetAppSettings(options); _vNodeSets = GetVNodeSettings(options); }
private static SingleVNodeSettings GetVNodeSettings(SingleNodeOptions options) { var http = new IPEndPoint(options.Ip, options.HttpPort); var tcp = new IPEndPoint(options.Ip, options.TcpPort); var vnodeSettings = new SingleVNodeSettings(tcp, http); return(vnodeSettings); }
protected override void OnArgsParsed(SingleNodeOptions options) { var now = DateTime.UtcNow; TfDb = GetTfDb(options, now); _appSets = GetAppSettings(options); _vNodeSets = GetVNodeSettings(options); _noProjections = options.NoProjections; _projectionThreads = options.ProjectionThreads; }
private static SingleVNodeSettings GetVNodeSettings(SingleNodeOptions options) { var tcp = new IPEndPoint(options.Ip, options.TcpPort); var http = new IPEndPoint(options.Ip, options.HttpPort); var prefixes = options.PrefixesString.IsNotEmptyString() ? options.PrefixesString.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) : new[] { http.ToHttpUrl() }; var vnodeSettings = new SingleVNodeSettings(tcp, http, prefixes.Select(p => p.Trim()).ToArray()); return(vnodeSettings); }
private MiniNode(int externalTcpPort = 4222, int externalHttpPort = 5222) { _oneTimeDbPath = Path.Combine(Path.GetTempPath(), "mini-node-one-time-db"); TryDeleteDirectory(_oneTimeDbPath); Directory.CreateDirectory(_oneTimeDbPath); _tfChunkDb = new TFChunkDb(CreateOneTimeDbConfig(256 * 1024 * 1024, _oneTimeDbPath, 2)); var ip = GetLocalIp(); TcpEndPoint = new IPEndPoint(ip, externalTcpPort); HttpEndPoint = new IPEndPoint(ip, externalHttpPort); var singleVNodeSettings = new SingleVNodeSettings(TcpEndPoint, HttpEndPoint, new[] { HttpEndPoint.ToHttpUrl() }); var appSettings = new SingleVNodeAppSettings(TimeSpan.FromHours(1)); _node = new SingleVNode(_tfChunkDb, singleVNodeSettings, appSettings); }
protected virtual void SetUp() { var dbPath = Path.Combine(Path.GetTempPath(), "EventStoreTests", Guid.NewGuid().ToString()); Directory.CreateDirectory(dbPath); var chunkSize = 256 * 1024 * 1024; var chunksToCache = 2; if (Runtime.IsMono) { _writerChk = new FileCheckpoint(Path.Combine(dbPath, Checkpoint.Writer + ".chk"), Checkpoint.Writer, cached: true); _chaserChk = new FileCheckpoint(Path.Combine(dbPath, Checkpoint.Chaser + ".chk"), Checkpoint.Chaser, cached: true); } else { _writerChk = new MemoryMappedFileCheckpoint(Path.Combine(dbPath, Checkpoint.Writer + ".chk"), Checkpoint.Writer, cached: true); _chaserChk = new MemoryMappedFileCheckpoint(Path.Combine(dbPath, Checkpoint.Chaser + ".chk"), Checkpoint.Chaser, cached: true); } var nodeConfig = new TFChunkDbConfig(dbPath, new VersionedPatternFileNamingStrategy(dbPath, "chunk-"), chunkSize, chunksToCache, _writerChk, new[] { _chaserChk }); var settings = new SingleVNodeSettings(new IPEndPoint(IPAddress.Loopback, 1111), new IPEndPoint(IPAddress.Loopback, 2111), new[] { new IPEndPoint(IPAddress.Loopback, 2111).ToHttpUrl() }); var appsets = new SingleVNodeAppSettings(TimeSpan.FromDays(1)); _db = new TFChunkDb(nodeConfig); _vNode = new SingleVNode(_db, settings, appsets); var startCallback = new EnvelopeCallback <SystemMessage.SystemStart>(); _vNode.Bus.Subscribe <SystemMessage.SystemStart>(startCallback); _vNode.Start(); startCallback.Wait(); }
static SingleVNodeSettings CreateSingleVNodeSettings() { var settings = new SingleVNodeSettings( TcpEndPoint, null, new IPEndPoint(IPAddress.None, 0), new[] { string.Format("http://{0}:{1}/", HttpEndPoint.Address, HttpEndPoint.Port) }, false, null, Opts.WorkerThreadsDefault, Opts.MinFlushDelayMsDefault, TimeSpan.FromMilliseconds(Opts.PrepareTimeoutMsDefault), TimeSpan.FromMilliseconds(Opts.CommitTimeoutMsDefault), TimeSpan.FromMilliseconds(Opts.StatsPeriodDefault), StatsStorage.None); return(settings); }
private static SingleVNodeSettings GetVNodeSettings(SingleNodeOptions options) { X509Certificate2 certificate = null; if (options.SecureTcpPort > 0) { if (options.CertificateStore.IsNotEmptyString()) { certificate = LoadCertificateFromStore(options.CertificateStore, options.CertificateName); } else if (options.CertificateFile.IsNotEmptyString()) { certificate = LoadCertificateFromFile(options.CertificateFile, options.CertificatePassword); } else { throw new Exception("No server certificate specified."); } } var tcpEndPoint = new IPEndPoint(options.Ip, options.TcpPort); var secureTcpEndPoint = options.SecureTcpPort > 0 ? new IPEndPoint(options.Ip, options.SecureTcpPort) : null; var httpEndPoint = new IPEndPoint(options.Ip, options.HttpPort); var prefixes = options.HttpPrefixes.IsNotEmpty() ? options.HttpPrefixes : new[] { httpEndPoint.ToHttpUrl() }; var vnodeSettings = new SingleVNodeSettings(tcpEndPoint, secureTcpEndPoint, httpEndPoint, prefixes.Select(p => p.Trim()).ToArray(), options.EnableTrustedAuth, certificate, options.WorkerThreads, TimeSpan.FromMilliseconds(options.MinFlushDelayMs), TimeSpan.FromMilliseconds(options.PrepareTimeoutMs), TimeSpan.FromMilliseconds(options.CommitTimeoutMs), TimeSpan.FromSeconds(options.StatsPeriodSec), StatsStorage.StreamAndCsv, false, options.DisableScavengeMerging); return(vnodeSettings); }
public SingleVNode(TFChunkDb db, SingleVNodeSettings vNodeSettings, SingleVNodeAppSettings appSettings) { Ensure.NotNull(db, "db"); Ensure.NotNull(vNodeSettings, "vNodeSettings"); db.OpenVerifyAndClean(); _tcpEndPoint = vNodeSettings.ExternalTcpEndPoint; _httpEndPoint = vNodeSettings.HttpEndPoint; _outputBus = new InMemoryBus("OutputBus"); _controller = new SingleVNodeController(Bus, _httpEndPoint); _mainQueue = new QueuedHandler(_controller, "MainQueue"); _controller.SetMainQueue(MainQueue); //MONITORING var monitoringInnerBus = new InMemoryBus("MonitoringInnerBus", watchSlowMsg: false); var monitoringRequestBus = new InMemoryBus("MonitoringRequestBus", watchSlowMsg: false); var monitoringQueue = new QueuedHandler(monitoringInnerBus, "MonitoringQueue", watchSlowMsg: true, slowMsgThresholdMs: 100); var monitoring = new MonitoringService(monitoringQueue, monitoringRequestBus, db.Config.WriterCheckpoint, appSettings.StatsPeriod); Bus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.SystemInit, Message>()); Bus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.BecomeShuttingDown, Message>()); monitoringInnerBus.Subscribe <SystemMessage.SystemInit>(monitoring); monitoringInnerBus.Subscribe <SystemMessage.BecomeShuttingDown>(monitoring); monitoringInnerBus.Subscribe <MonitoringMessage.GetFreshStats>(monitoring); //STORAGE SUBSYSTEM var indexPath = Path.Combine(db.Config.Path, "index"); var tableIndex = new TableIndex(indexPath, () => new HashListMemTable(), new InMemoryCheckpoint(), maxSizeForMemory: 1000000, maxTablesPerLevel: 2); var readIndex = new ReadIndex(_mainQueue, pos => new TFChunkChaser(db, db.Config.WriterCheckpoint, new InMemoryCheckpoint(pos)), () => new TFChunkReader(db, db.Config.WriterCheckpoint), TFConsts.ReadIndexReaderCount, tableIndex, new XXHashUnsafe()); var writer = new TFChunkWriter(db); var storageWriter = new StorageWriter(_mainQueue, _outputBus, writer, readIndex); var storageReader = new StorageReader(_mainQueue, _outputBus, readIndex, TFConsts.StorageReaderHandlerCount); monitoringRequestBus.Subscribe <MonitoringMessage.InternalStatsRequest>(storageReader); var chaser = new TFChunkChaser(db, db.Config.WriterCheckpoint, db.Config.GetNamedCheckpoint(Checkpoint.Chaser)); var storageChaser = new StorageChaser(_mainQueue, chaser); _outputBus.Subscribe <SystemMessage.SystemInit>(storageChaser); _outputBus.Subscribe <SystemMessage.SystemStart>(storageChaser); _outputBus.Subscribe <SystemMessage.BecomeShuttingDown>(storageChaser); var storageScavenger = new StorageScavenger(db, readIndex); _outputBus.Subscribe <SystemMessage.ScavengeDatabase>(storageScavenger); //TCP var tcpService = new TcpService(MainQueue, _tcpEndPoint); Bus.Subscribe <SystemMessage.SystemInit>(tcpService); Bus.Subscribe <SystemMessage.SystemStart>(tcpService); Bus.Subscribe <SystemMessage.BecomeShuttingDown>(tcpService); //HTTP HttpService = new HttpService(MainQueue, vNodeSettings.HttpPrefixes); Bus.Subscribe <SystemMessage.SystemInit>(HttpService); Bus.Subscribe <SystemMessage.BecomeShuttingDown>(HttpService); Bus.Subscribe <HttpMessage.SendOverHttp>(HttpService); Bus.Subscribe <HttpMessage.UpdatePendingRequests>(HttpService); HttpService.SetupController(new AdminController(MainQueue)); HttpService.SetupController(new PingController()); HttpService.SetupController(new StatController(monitoringQueue)); HttpService.SetupController(new ReadEventDataController(MainQueue)); HttpService.SetupController(new AtomController(MainQueue)); HttpService.SetupController(new WebSiteController(MainQueue)); //REQUEST MANAGEMENT var requestManagement = new RequestManagementService(MainQueue, 1, 1); Bus.Subscribe <ReplicationMessage.EventCommited>(requestManagement); Bus.Subscribe <ReplicationMessage.CreateStreamRequestCreated>(requestManagement); Bus.Subscribe <ReplicationMessage.WriteRequestCreated>(requestManagement); Bus.Subscribe <ReplicationMessage.TransactionStartRequestCreated>(requestManagement); Bus.Subscribe <ReplicationMessage.TransactionWriteRequestCreated>(requestManagement); Bus.Subscribe <ReplicationMessage.TransactionCommitRequestCreated>(requestManagement); Bus.Subscribe <ReplicationMessage.DeleteStreamRequestCreated>(requestManagement); Bus.Subscribe <ReplicationMessage.RequestCompleted>(requestManagement); Bus.Subscribe <ReplicationMessage.CommitAck>(requestManagement); Bus.Subscribe <ReplicationMessage.PrepareAck>(requestManagement); Bus.Subscribe <ReplicationMessage.WrongExpectedVersion>(requestManagement); Bus.Subscribe <ReplicationMessage.InvalidTransaction>(requestManagement); Bus.Subscribe <ReplicationMessage.StreamDeleted>(requestManagement); Bus.Subscribe <ReplicationMessage.PreparePhaseTimeout>(requestManagement); Bus.Subscribe <ReplicationMessage.CommitPhaseTimeout>(requestManagement); var clientService = new ClientService(); Bus.Subscribe <TcpMessage.ConnectionClosed>(clientService); Bus.Subscribe <ClientMessage.SubscribeToStream>(clientService); Bus.Subscribe <ClientMessage.UnsubscribeFromStream>(clientService); Bus.Subscribe <ClientMessage.SubscribeToAllStreams>(clientService); Bus.Subscribe <ClientMessage.UnsubscribeFromAllStreams>(clientService); Bus.Subscribe <ReplicationMessage.EventCommited>(clientService); //TIMER //var timer = new TimerService(new TimerBasedScheduler(new RealTimer(), new RealTimeProvider())); TimerService = new TimerService(new ThreadBasedScheduler(new RealTimeProvider())); Bus.Subscribe <TimerMessage.Schedule>(TimerService); MainQueue.Start(); monitoringQueue.Start(); }
public SingleVNode(TFChunkDb db, SingleVNodeSettings vNodeSettings, bool dbVerifyHashes, int memTableEntryCount, params ISubsystem[] subsystems) { Ensure.NotNull(db, "db"); Ensure.NotNull(vNodeSettings, "vNodeSettings"); _settings = vNodeSettings; _mainBus = new InMemoryBus("MainBus"); _controller = new SingleVNodeController(_mainBus, _settings.ExternalHttpEndPoint, db, this); _mainQueue = new QueuedHandler(_controller, "MainQueue"); _controller.SetMainQueue(_mainQueue); _subsystems = subsystems; // MONITORING var monitoringInnerBus = new InMemoryBus("MonitoringInnerBus", watchSlowMsg: false); var monitoringRequestBus = new InMemoryBus("MonitoringRequestBus", watchSlowMsg: false); var monitoringQueue = new QueuedHandler(monitoringInnerBus, "MonitoringQueue", true, TimeSpan.FromMilliseconds(100)); var monitoring = new MonitoringService(monitoringQueue, monitoringRequestBus, _mainQueue, db.Config.WriterCheckpoint, db.Config.Path, vNodeSettings.StatsPeriod, _settings.ExternalHttpEndPoint, vNodeSettings.StatsStorage); _mainBus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.SystemInit, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.StateChangeMessage, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom <SystemMessage.BecomeShuttingDown, Message>()); _mainBus.Subscribe(monitoringQueue.WidenFrom <ClientMessage.WriteEventsCompleted, Message>()); monitoringInnerBus.Subscribe <SystemMessage.SystemInit>(monitoring); monitoringInnerBus.Subscribe <SystemMessage.StateChangeMessage>(monitoring); monitoringInnerBus.Subscribe <SystemMessage.BecomeShuttingDown>(monitoring); monitoringInnerBus.Subscribe <ClientMessage.WriteEventsCompleted>(monitoring); monitoringInnerBus.Subscribe <MonitoringMessage.GetFreshStats>(monitoring); var truncPos = db.Config.TruncateCheckpoint.Read(); if (truncPos != -1) { Log.Info("Truncate checkpoint is present. Truncate: {0} (0x{0:X}), Writer: {1} (0x{1:X}), Chaser: {2} (0x{2:X}), Epoch: {3} (0x{3:X})", truncPos, db.Config.WriterCheckpoint.Read(), db.Config.ChaserCheckpoint.Read(), db.Config.EpochCheckpoint.Read()); var truncator = new TFChunkDbTruncator(db.Config); truncator.TruncateDb(truncPos); } db.Open(dbVerifyHashes); // STORAGE SUBSYSTEM var indexPath = Path.Combine(db.Config.Path, "index"); var tableIndex = new TableIndex(indexPath, () => new HashListMemTable(maxSize: memTableEntryCount * 2), maxSizeForMemory: memTableEntryCount, maxTablesPerLevel: 2); var readIndex = new ReadIndex(_mainQueue, ESConsts.PTableInitialReaderCount, ESConsts.PTableMaxReaderCount, () => new TFChunkReader(db, db.Config.WriterCheckpoint), tableIndex, new XXHashUnsafe(), new LRUCache <string, StreamCacheInfo>(ESConsts.StreamMetadataCacheCapacity), Application.IsDefined(Application.AdditionalCommitChecks), Application.IsDefined(Application.InfiniteMetastreams) ? int.MaxValue : 1); var writer = new TFChunkWriter(db); var epochManager = new EpochManager(ESConsts.CachedEpochCount, db.Config.EpochCheckpoint, writer, initialReaderCount: 1, maxReaderCount: 5, readerFactory: () => new TFChunkReader(db, db.Config.WriterCheckpoint)); epochManager.Init(); var storageWriter = new StorageWriterService(_mainQueue, _mainBus, _settings.MinFlushDelayMs, db, writer, readIndex, epochManager); // subscribes internally monitoringRequestBus.Subscribe <MonitoringMessage.InternalStatsRequest>(storageWriter); var storageReader = new StorageReaderService(_mainQueue, _mainBus, readIndex, ESConsts.StorageReaderThreadCount, db.Config.WriterCheckpoint); _mainBus.Subscribe <SystemMessage.SystemInit>(storageReader); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(storageReader); _mainBus.Subscribe <SystemMessage.BecomeShutdown>(storageReader); monitoringRequestBus.Subscribe <MonitoringMessage.InternalStatsRequest>(storageReader); var chaser = new TFChunkChaser(db, db.Config.WriterCheckpoint, db.Config.ChaserCheckpoint); var storageChaser = new StorageChaser(_mainQueue, db.Config.WriterCheckpoint, chaser, readIndex, epochManager); _mainBus.Subscribe <SystemMessage.SystemInit>(storageChaser); _mainBus.Subscribe <SystemMessage.SystemStart>(storageChaser); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(storageChaser); var storageScavenger = new StorageScavenger(db, readIndex, Application.IsDefined(Application.AlwaysKeepScavenged), mergeChunks: false /*!Application.IsDefined(Application.DisableMergeChunks)*/); // ReSharper disable RedundantTypeArgumentsOfMethod _mainBus.Subscribe <SystemMessage.ScavengeDatabase>(storageScavenger); // ReSharper restore RedundantTypeArgumentsOfMethod // MISC WORKERS _workerBuses = Enumerable.Range(0, vNodeSettings.WorkerThreads).Select(queueNum => new InMemoryBus(string.Format("Worker #{0} Bus", queueNum + 1), watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(200))).ToArray(); _workersHandler = new MultiQueuedHandler( vNodeSettings.WorkerThreads, queueNum => new QueuedHandlerThreadPool(_workerBuses[queueNum], string.Format("Worker #{0}", queueNum + 1), groupName: "Workers", watchSlowMsg: true, slowMsgThreshold: TimeSpan.FromMilliseconds(200))); // AUTHENTICATION INFRASTRUCTURE var passwordHashAlgorithm = new Rfc2898PasswordHashAlgorithm(); var dispatcher = new IODispatcher(_mainBus, new PublishEnvelope(_workersHandler, crossThread: true)); var internalAuthenticationProvider = new InternalAuthenticationProvider(dispatcher, passwordHashAlgorithm, ESConsts.CachedPrincipalCount); var passwordChangeNotificationReader = new PasswordChangeNotificationReader(_mainQueue, dispatcher); _mainBus.Subscribe <SystemMessage.SystemStart>(passwordChangeNotificationReader); _mainBus.Subscribe <SystemMessage.BecomeShutdown>(passwordChangeNotificationReader); _mainBus.Subscribe(internalAuthenticationProvider); SubscribeWorkers(bus => { bus.Subscribe(dispatcher.ForwardReader); bus.Subscribe(dispatcher.BackwardReader); bus.Subscribe(dispatcher.Writer); bus.Subscribe(dispatcher.StreamDeleter); bus.Subscribe(dispatcher); }); // TCP { var tcpService = new TcpService(_mainQueue, _settings.ExternalTcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Normal, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, null); _mainBus.Subscribe <SystemMessage.SystemInit>(tcpService); _mainBus.Subscribe <SystemMessage.SystemStart>(tcpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(tcpService); } // SECURE TCP if (vNodeSettings.ExternalSecureTcpEndPoint != null) { var secureTcpService = new TcpService(_mainQueue, _settings.ExternalSecureTcpEndPoint, _workersHandler, TcpServiceType.External, TcpSecurityType.Secure, new ClientTcpDispatcher(), ESConsts.ExternalHeartbeatInterval, ESConsts.ExternalHeartbeatTimeout, internalAuthenticationProvider, _settings.Certificate); _mainBus.Subscribe <SystemMessage.SystemInit>(secureTcpService); _mainBus.Subscribe <SystemMessage.SystemStart>(secureTcpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(secureTcpService); } SubscribeWorkers(bus => { var tcpSendService = new TcpSendService(); // ReSharper disable RedundantTypeArgumentsOfMethod bus.Subscribe <TcpMessage.TcpSend>(tcpSendService); // ReSharper restore RedundantTypeArgumentsOfMethod }); // HTTP var authenticationProviders = new List <AuthenticationProvider> { new BasicHttpAuthenticationProvider(internalAuthenticationProvider), }; if (_settings.EnableTrustedAuth) { authenticationProviders.Add(new TrustedAuthenticationProvider()); } authenticationProviders.Add(new AnonymousAuthenticationProvider()); var httpPipe = new HttpMessagePipe(); var httpSendService = new HttpSendService(httpPipe, forwardRequests: false); _mainBus.Subscribe <SystemMessage.StateChangeMessage>(httpSendService); _mainBus.Subscribe(new WideningHandler <HttpMessage.SendOverHttp, Message>(_workersHandler)); SubscribeWorkers(bus => { bus.Subscribe <HttpMessage.HttpSend>(httpSendService); bus.Subscribe <HttpMessage.HttpSendPart>(httpSendService); bus.Subscribe <HttpMessage.HttpBeginSend>(httpSendService); bus.Subscribe <HttpMessage.HttpEndSend>(httpSendService); bus.Subscribe <HttpMessage.SendOverHttp>(httpSendService); }); _httpService = new HttpService(ServiceAccessibility.Public, _mainQueue, new TrieUriRouter(), _workersHandler, vNodeSettings.HttpPrefixes); _httpService.SetupController(new AdminController(_mainQueue)); _httpService.SetupController(new PingController()); _httpService.SetupController(new StatController(monitoringQueue, _workersHandler)); _httpService.SetupController(new AtomController(httpSendService, _mainQueue, _workersHandler)); _httpService.SetupController(new GuidController(_mainQueue)); _httpService.SetupController(new UsersController(httpSendService, _mainQueue, _workersHandler)); _mainBus.Subscribe <SystemMessage.SystemInit>(_httpService); _mainBus.Subscribe <SystemMessage.BecomeShuttingDown>(_httpService); _mainBus.Subscribe <HttpMessage.PurgeTimedOutRequests>(_httpService); SubscribeWorkers(bus => { HttpService.CreateAndSubscribePipeline(bus, authenticationProviders.ToArray()); }); // REQUEST MANAGEMENT var requestManagement = new RequestManagementService(_mainQueue, 1, 1, vNodeSettings.PrepareTimeout, vNodeSettings.CommitTimeout); _mainBus.Subscribe <SystemMessage.SystemInit>(requestManagement); _mainBus.Subscribe <ClientMessage.WriteEvents>(requestManagement); _mainBus.Subscribe <ClientMessage.TransactionStart>(requestManagement); _mainBus.Subscribe <ClientMessage.TransactionWrite>(requestManagement); _mainBus.Subscribe <ClientMessage.TransactionCommit>(requestManagement); _mainBus.Subscribe <ClientMessage.DeleteStream>(requestManagement); _mainBus.Subscribe <StorageMessage.RequestCompleted>(requestManagement); _mainBus.Subscribe <StorageMessage.CheckStreamAccessCompleted>(requestManagement); _mainBus.Subscribe <StorageMessage.AlreadyCommitted>(requestManagement); _mainBus.Subscribe <StorageMessage.CommitAck>(requestManagement); _mainBus.Subscribe <StorageMessage.PrepareAck>(requestManagement); _mainBus.Subscribe <StorageMessage.WrongExpectedVersion>(requestManagement); _mainBus.Subscribe <StorageMessage.InvalidTransaction>(requestManagement); _mainBus.Subscribe <StorageMessage.StreamDeleted>(requestManagement); _mainBus.Subscribe <StorageMessage.RequestManagerTimerTick>(requestManagement); // SUBSCRIPTIONS var subscrBus = new InMemoryBus("SubscriptionsBus", true, TimeSpan.FromMilliseconds(50)); var subscription = new SubscriptionsService(readIndex); subscrBus.Subscribe <TcpMessage.ConnectionClosed>(subscription); subscrBus.Subscribe <ClientMessage.SubscribeToStream>(subscription); subscrBus.Subscribe <ClientMessage.UnsubscribeFromStream>(subscription); subscrBus.Subscribe <StorageMessage.EventCommited>(subscription); var subscrQueue = new QueuedHandlerThreadPool(subscrBus, "Subscriptions", false); _mainBus.Subscribe(subscrQueue.WidenFrom <TcpMessage.ConnectionClosed, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom <ClientMessage.SubscribeToStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom <ClientMessage.UnsubscribeFromStream, Message>()); _mainBus.Subscribe(subscrQueue.WidenFrom <StorageMessage.EventCommited, Message>()); // USER MANAGEMENT var ioDispatcher = new IODispatcher(_mainBus, new PublishEnvelope(_mainQueue)); _mainBus.Subscribe(ioDispatcher.BackwardReader); _mainBus.Subscribe(ioDispatcher.ForwardReader); _mainBus.Subscribe(ioDispatcher.Writer); _mainBus.Subscribe(ioDispatcher.StreamDeleter); _mainBus.Subscribe(ioDispatcher); var userManagement = new UserManagementService( _mainQueue, ioDispatcher, passwordHashAlgorithm, vNodeSettings.SkipInitializeStandardUsersCheck); _mainBus.Subscribe <UserManagementMessage.Create>(userManagement); _mainBus.Subscribe <UserManagementMessage.Update>(userManagement); _mainBus.Subscribe <UserManagementMessage.Enable>(userManagement); _mainBus.Subscribe <UserManagementMessage.Disable>(userManagement); _mainBus.Subscribe <UserManagementMessage.Delete>(userManagement); _mainBus.Subscribe <UserManagementMessage.ResetPassword>(userManagement); _mainBus.Subscribe <UserManagementMessage.ChangePassword>(userManagement); _mainBus.Subscribe <UserManagementMessage.Get>(userManagement); _mainBus.Subscribe <UserManagementMessage.GetAll>(userManagement); _mainBus.Subscribe <SystemMessage.BecomeMaster>(userManagement); // TIMER _timeProvider = new RealTimeProvider(); _timerService = new TimerService(new ThreadBasedScheduler(_timeProvider)); // ReSharper disable RedundantTypeArgumentsOfMethod _mainBus.Subscribe <TimerMessage.Schedule>(_timerService); // ReSharper restore RedundantTypeArgumentsOfMethod _workersHandler.Start(); _mainQueue.Start(); monitoringQueue.Start(); subscrQueue.Start(); if (subsystems != null) { foreach (var subsystem in subsystems) { subsystem.Register(db, _mainQueue, _mainBus, _timerService, _timeProvider, httpSendService, new[] { _httpService }, _workersHandler); } } }
public MiniNode(string pathname, int?tcpPort = null, int?tcpSecPort = null, int?httpPort = null, ISubsystem[] subsystems = null, int?chunkSize = null, int?cachedChunkSize = null, bool enableTrustedAuth = false, bool skipInitializeStandardUsersCheck = true, int memTableSize = 1000, bool inMemDb = true, bool disableFlushToDisk = false) { if (_running) { throw new Exception("Previous MiniNode is still running!!!"); } _running = true; RunningTime.Start(); RunCount += 1; IPAddress ip = IPAddress.Loopback; //GetLocalIp(); int extTcpPort = tcpPort ?? PortsHelper.GetAvailablePort(ip); int extSecTcpPort = tcpSecPort ?? PortsHelper.GetAvailablePort(ip); int extHttpPort = httpPort ?? PortsHelper.GetAvailablePort(ip); _dbPath = Path.Combine(pathname, string.Format("mini-node-db-{0}-{1}-{2}", extTcpPort, extSecTcpPort, extHttpPort)); Directory.CreateDirectory(_dbPath); FileStreamExtensions.ConfigureFlush(disableFlushToDisk); Db = new TFChunkDb(CreateDbConfig(chunkSize ?? ChunkSize, _dbPath, cachedChunkSize ?? CachedChunkSize, inMemDb)); TcpEndPoint = new IPEndPoint(ip, extTcpPort); TcpSecEndPoint = new IPEndPoint(ip, extSecTcpPort); HttpEndPoint = new IPEndPoint(ip, extHttpPort); var singleVNodeSettings = new SingleVNodeSettings(TcpEndPoint, TcpSecEndPoint, HttpEndPoint, new[] { HttpEndPoint.ToHttpUrl() }, enableTrustedAuth, ssl_connections.GetCertificate(), 1, TFConsts.MinFlushDelayMs, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2), TimeSpan.FromHours(1), StatsStorage.None, skipInitializeStandardUsersCheck: skipInitializeStandardUsersCheck); Log.Info("\n{0,-25} {1} ({2}/{3}, {4})\n" + "{5,-25} {6} ({7})\n" + "{8,-25} {9} ({10}-bit)\n" + "{11,-25} {12}\n" + "{13,-25} {14}\n" + "{15,-25} {16}\n" + "{17,-25} {18}\n" + "{19,-25} {20}\n\n", "ES VERSION:", VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp, "OS:", OS.OsFlavor, Environment.OSVersion, "RUNTIME:", OS.GetRuntimeVersion(), Marshal.SizeOf(typeof(IntPtr)) * 8, "GC:", GC.MaxGeneration == 0 ? "NON-GENERATION (PROBABLY BOEHM)" : string.Format("{0} GENERATIONS", GC.MaxGeneration + 1), "DBPATH:", _dbPath, "TCP ENDPOINT:", TcpEndPoint, "TCP SECURE ENDPOINT:", TcpSecEndPoint, "HTTP ENDPOINT:", HttpEndPoint); Node = new SingleVNode(Db, singleVNodeSettings, dbVerifyHashes: true, memTableEntryCount: memTableSize, subsystems: subsystems); Node.HttpService.SetupController(new TestController(Node.MainQueue, Node.NetworkSendService)); }