public static IPEndPoint GetLoopback() { var ip = IPAddress.Loopback; int port = PortsHelper.GetAvailablePort(ip); return(new IPEndPoint(ip, port)); }
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, IPAddress advertisedExtIPAddress = null, int advertisedExtHttpPort = 0, int hashCollisionReadLimit = EventStore.Core.Util.Opts.HashCollisionReadLimitDefault, byte indexBitnessVersion = EventStore.Core.Util.Opts.IndexBitnessVersionDefault, string dbPath = "", bool isReadOnlyReplica = false) { RunningTime.Start(); RunCount += 1; var ip = IPAddress.Loopback; //GetLocalIp(); int extTcpPort = tcpPort ?? PortsHelper.GetAvailablePort(ip); int extSecTcpPort = tcpSecPort ?? PortsHelper.GetAvailablePort(ip); int extHttpPort = httpPort ?? PortsHelper.GetAvailablePort(ip); int intTcpPort = PortsHelper.GetAvailablePort(ip); int intSecTcpPort = PortsHelper.GetAvailablePort(ip); int intHttpPort = PortsHelper.GetAvailablePort(ip); if (string.IsNullOrEmpty(dbPath)) { DbPath = Path.Combine(pathname, $"mini-node-db-{extTcpPort}-{extSecTcpPort}-{extHttpPort}"); } else { DbPath = dbPath; } TcpEndPoint = new IPEndPoint(ip, extTcpPort); TcpSecEndPoint = new IPEndPoint(ip, extSecTcpPort); IntTcpEndPoint = new IPEndPoint(ip, intTcpPort); IntSecTcpEndPoint = new IPEndPoint(ip, intSecTcpPort); IntHttpEndPoint = new IPEndPoint(ip, intHttpPort); ExtHttpEndPoint = new IPEndPoint(ip, extHttpPort); var builder = TestVNodeBuilder.AsSingleNode(); if (inMemDb) { builder.RunInMemory(); } else { builder.RunOnDisk(DbPath); } builder.WithInternalTcpOn(IntTcpEndPoint) .WithInternalSecureTcpOn(IntSecTcpEndPoint) .WithExternalTcpOn(TcpEndPoint) .WithExternalSecureTcpOn(TcpSecEndPoint) .WithInternalHttpOn(IntHttpEndPoint) .WithExternalHttpOn(ExtHttpEndPoint) .WithTfChunkSize(chunkSize ?? ChunkSize) .WithTfChunksCacheSize(cachedChunkSize ?? CachedChunkSize) .WithServerCertificate(ssl_connections.GetCertificate()) .WithWorkerThreads(1) .DisableDnsDiscovery() .WithPrepareTimeout(TimeSpan.FromSeconds(10)) .WithCommitTimeout(TimeSpan.FromSeconds(10)) .WithStatsPeriod(TimeSpan.FromHours(1)) .DisableScavengeMerging() .NoGossipOnPublicInterface() .WithInternalHeartbeatInterval(TimeSpan.FromSeconds(10)) .WithInternalHeartbeatTimeout(TimeSpan.FromSeconds(10)) .WithExternalHeartbeatInterval(TimeSpan.FromSeconds(10)) .WithExternalHeartbeatTimeout(TimeSpan.FromSeconds(10)) .MaximumMemoryTableSizeOf(memTableSize) .DoNotVerifyDbHashes() .WithStatsStorage(StatsStorage.None) .AdvertiseExternalIPAs(advertisedExtIPAddress) .AdvertiseExternalHttpPortAs(advertisedExtHttpPort) .WithHashCollisionReadLimitOf(hashCollisionReadLimit) .WithIndexBitnessVersion(indexBitnessVersion) .WithHttpMessageHandlerFactory(() => HttpMessageHandler); if (enableTrustedAuth) { builder.EnableTrustedAuth(); } if (disableFlushToDisk) { builder.WithUnsafeDisableFlushToDisk(); } if (isReadOnlyReplica) { builder.EnableReadOnlyReplica(); } if (subsystems != null) { foreach (var subsystem in subsystems) { builder.AddCustomSubsystem(subsystem); } } 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:", ExtHttpEndPoint); Node = builder.Build(); Db = ((TestVNodeBuilder)builder).GetDb(); _kestrelTestServer = new TestServer(new WebHostBuilder() .UseKestrel() .UseStartup(new ClusterVNodeStartup(Node))); HttpMessageHandler = _kestrelTestServer.CreateHandler(); HttpClient = new HttpClient(HttpMessageHandler); Node.ExternalHttpService.SetupController(new TestController(Node.MainQueue)); }
public MiniNode(string pathname, int?tcpPort = null, int?httpPort = null, ISubsystem[] subsystems = null, int?chunkSize = null, int?cachedChunkSize = null, bool enableTrustedAuth = false, int memTableSize = 1000, bool inMemDb = true, bool disableFlushToDisk = false, string advertisedExtHostAddress = null, int advertisedHttpPort = 0, int hashCollisionReadLimit = Util.Opts.HashCollisionReadLimitDefault, byte indexBitnessVersion = Util.Opts.IndexBitnessVersionDefault, string dbPath = "", bool isReadOnlyReplica = false) { RunningTime.Start(); RunCount += 1; var ip = IPAddress.Loopback; int extTcpPort = tcpPort ?? PortsHelper.GetAvailablePort(ip); int httpEndPointPort = httpPort ?? PortsHelper.GetAvailablePort(ip); int intTcpPort = PortsHelper.GetAvailablePort(ip); if (string.IsNullOrEmpty(dbPath)) { DbPath = Path.Combine(pathname, $"mini-node-db-{extTcpPort}-{httpEndPointPort}"); } else { DbPath = dbPath; } TcpEndPoint = new IPEndPoint(ip, extTcpPort); IntTcpEndPoint = new IPEndPoint(ip, intTcpPort); HttpEndPoint = new IPEndPoint(ip, httpEndPointPort); var options = new ClusterVNodeOptions { IndexBitnessVersion = indexBitnessVersion, Application = new() { StatsPeriodSec = 60 * 60, WorkerThreads = 1 }, Interface = new() { ExtTcpHeartbeatInterval = 10_000, ExtTcpHeartbeatTimeout = 10_000, IntTcpHeartbeatInterval = 10_000, IntTcpHeartbeatTimeout = 10_000, EnableTrustedAuth = enableTrustedAuth, EnableAtomPubOverHttp = true }, Cluster = new() { DiscoverViaDns = false, ReadOnlyReplica = isReadOnlyReplica }, Database = new() { ChunkSize = chunkSize ?? ChunkSize, ChunksCacheSize = cachedChunkSize ?? CachedChunkSize, SkipDbVerify = true, StatsStorage = StatsStorage.None, MaxMemTableSize = memTableSize, DisableScavengeMerging = true, HashCollisionReadLimit = hashCollisionReadLimit, CommitTimeoutMs = 10_000, PrepareTimeoutMs = 10_000, UnsafeDisableFlushToDisk = disableFlushToDisk }, Subsystems = new List <ISubsystem>(subsystems ?? Array.Empty <ISubsystem>()) }.Secure(new X509Certificate2Collection(ssl_connections.GetRootCertificate()),
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); int intTcpPort = PortsHelper.GetAvailablePort(ip); int intSecTcpPort = PortsHelper.GetAvailablePort(ip); int intHttpPort = 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); IntTcpEndPoint = new IPEndPoint(ip, intTcpPort); IntSecTcpEndPoint = new IPEndPoint(ip, intSecTcpPort); IntHttpEndPoint = new IPEndPoint(ip, intHttpPort); var vNodeSettings = new ClusterVNodeSettings(Guid.NewGuid(), 0, IntTcpEndPoint, IntSecTcpEndPoint, TcpEndPoint, TcpSecEndPoint, IntHttpEndPoint, HttpEndPoint, new [] { HttpEndPoint.ToHttpUrl() }, enableTrustedAuth, ssl_connections.GetCertificate(), 1, false, "whatever", new IPEndPoint[] {}, TFConsts.MinFlushDelayMs, 1, 1, 1, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2), false, "", false, TimeSpan.FromHours(1), StatsStorage.None, 1, new InternalAuthenticationProviderFactory(), true, true, true, false, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), false, memTableSize); 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 ClusterVNode(Db, vNodeSettings, new KnownEndpointGossipSeedSource(new [] { HttpEndPoint }), new InfoController(null), subsystems); Node.ExternalHttpService.SetupController(new TestController(Node.MainQueue)); }