private MiniNode(int externalTcpPort = 41111, int externalHttpPort = 41112) { _oneTimeDbPath = Path.Combine(Path.GetTempPath(), string.Format("mini-node-one-time-db-{0}-{1}", externalTcpPort, externalHttpPort)); 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, dbVerifyHashes: true); }
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(); }
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, db, () => new TFChunkReader(db, db.Config.WriterCheckpoint), TFConsts.ReadIndexReaderCount, db.Config.WriterCheckpoint, 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, _httpEndPoint.ToHttpUrl()); 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(); }