Ejemplo n.º 1
0
        public void Start()
        {
            if (EmbeddedEventStoreConfiguration.RunWithLogging)
            {
                if (!Directory.Exists(EmbeddedEventStoreConfiguration.LogPath))
                {
                    Directory.CreateDirectory(EmbeddedEventStoreConfiguration.LogPath);
                }
                LogManager.Init(string.Format("as-embed-es-{0}", DateTime.Now.Ticks), EmbeddedEventStoreConfiguration.LogPath);
            }

            var db       = CreateTFChunkDb(EmbeddedEventStoreConfiguration.StoragePath);
            var settings = CreateSingleVNodeSettings();

            _node = new SingleVNode(db, settings, false, 0xf4240, new ISubsystem[0]);
            var waitHandle = new ManualResetEvent(false);

            _node.MainBus.Subscribe(new AdHocHandler <SystemMessage.BecomeMaster>(m => waitHandle.Set()));
            _node.Start();
            waitHandle.WaitOne();
            _credentials = new UserCredentials("admin", "changeit");
            _connection  = EventStoreConnection.Create(
                ConnectionSettings.Create().
                EnableVerboseLogging().
                SetDefaultUserCredentials(_credentials).
                UseConsoleLogger(),
                TcpEndPoint);
            _connection.Connect();
        }
Ejemplo n.º 2
0
        protected override void Create(SingleNodeOptions options)
        {
            var dbPath = Path.GetFullPath(ResolveDbPath(options.DbPath, options.HttpPort));

            _dbLock = new ExclusiveDbLock(dbPath);
            if (!_dbLock.Acquire())
            {
                throw new Exception(string.Format("Couldn't acquire exclusive lock on DB at '{0}'.", dbPath));
            }

            var db             = new TFChunkDb(CreateDbConfig(dbPath, options.CachedChunks, options.ChunksCacheSize));
            var vnodeSettings  = GetVNodeSettings(options);
            var dbVerifyHashes = !options.SkipDbVerify;
            var runProjections = options.RunProjections;

            Log.Info("\n{0,-25} {1}\n{2,-25} {3} (0x{3:X})\n{4,-25} {5} (0x{5:X})\n{6,-25} {7} (0x{7:X})\n{8,-25} {9} (0x{9:X})\n",
                     "DATABASE:", db.Config.Path,
                     "WRITER CHECKPOINT:", db.Config.WriterCheckpoint.Read(),
                     "CHASER CHECKPOINT:", db.Config.ChaserCheckpoint.Read(),
                     "EPOCH CHECKPOINT:", db.Config.EpochCheckpoint.Read(),
                     "TRUNCATE CHECKPOINT:", db.Config.TruncateCheckpoint.Read());

            var enabledNodeSubsystems = runProjections >= RunProjections.System
                ? new[] { NodeSubsystems.Projections }
                : new NodeSubsystems[0];

            _projections = new Projections.Core.ProjectionsSubsystem(options.ProjectionThreads, runProjections);
            _node        = new SingleVNode(db, vnodeSettings, dbVerifyHashes, ESConsts.MemTableEntryCount, _projections);
            RegisterWebControllers(enabledNodeSubsystems);
            RegisterUIProjections();
        }
Ejemplo n.º 3
0
        public MiniNode(string pathname)
        {
            var ip = GetLocalIp();

            int extTcpPort = GetAvailablePort(ip);
            int extHttpPort = GetAvailablePort(ip);

            _dbPath = Path.Combine(pathname, string.Format("mini-node-db-{0}-{1}", extTcpPort, extHttpPort));
            Directory.CreateDirectory(_dbPath);
            _tfChunkDb = new TFChunkDb(CreateOneTimeDbConfig(1024*1024, _dbPath, 1));

            TcpEndPoint = new IPEndPoint(ip, extTcpPort);
            HttpEndPoint = new IPEndPoint(ip, extHttpPort);

            var singleVNodeSettings = new SingleVNodeSettings(TcpEndPoint,
                                                              HttpEndPoint,
                                                              new[] {HttpEndPoint.ToHttpUrl()},
                                                              1,
                                                              1,
                                                              1,
                                                              TimeSpan.FromHours(1),
                                                              StatsStorage.None);

            _node = new SingleVNode(_tfChunkDb, singleVNodeSettings, dbVerifyHashes: true, memTableEntryCount: 1000);
        }
Ejemplo n.º 4
0
        protected override void Create()
        {
            Node = new SingleVNode(TfDb, _vNodeSets, _appSets);

            if (!_noProjections)
            {
                _projections = new Projections(TfDb, Node.MainQueue, Node.Bus, Node.TimerService, Node.HttpService, _projectionThreads);
            }
        }
Ejemplo n.º 5
0
        public SingleVNodeController(IPublisher outputBus, IPEndPoint httpEndPoint, TFChunkDb db, SingleVNode node)
        {
            Ensure.NotNull(outputBus, "outputBus");
            Ensure.NotNull(httpEndPoint, "httpEndPoint");
            Ensure.NotNull(db, "db");
            Ensure.NotNull(node, "node");

            _outputBus    = outputBus;
            _httpEndPoint = httpEndPoint;
            _db           = db;
            _node         = node;

            _fsm = CreateFSM();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        protected override void Create(SingleNodeOptions options)
        {
            var dbPath         = ResolveDbPath(options.DbPath, options.HttpPort);
            var db             = new TFChunkDb(CreateDbConfig(dbPath, options.ChunksToCache));
            var vnodeSettings  = GetVNodeSettings(options);
            var appSettings    = new SingleVNodeAppSettings(TimeSpan.FromSeconds(options.StatsPeriodSec));
            var dbVerifyHashes = !options.DoNotVerifyDbHashesOnStartup;

            _node = new SingleVNode(db, vnodeSettings, appSettings, dbVerifyHashes);

            if (!options.NoProjections)
            {
                _projections = new Projections.Core.Projections(db,
                                                                _node.MainQueue,
                                                                _node.Bus,
                                                                _node.TimerService,
                                                                _node.HttpService,
                                                                options.ProjectionThreads);
            }
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        protected virtual void TearDown()
        {
            try
            {
                var shutdownCallback = new EnvelopeCallback <SystemMessage.BecomeShutdown>();
                _vNode.Bus.Subscribe <SystemMessage.BecomeShutdown>(shutdownCallback);

                _vNode.Stop();

                shutdownCallback.Wait();

                _db.Dispose();
                _writerChk.Dispose();
                _chaserChk.Dispose();
                Directory.Delete(_db.Config.Path, true);

                _vNode = null;
                _db    = null;
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 12
0
        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)
        {
            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);
            Db = new TFChunkDb(CreateDbConfig(chunkSize ?? ChunkSize, _dbPath, cachedChunkSize ?? CachedChunkSize));

            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: 1000, subsystems: subsystems);
            Node.HttpService.SetupController(new TestController(Node.MainQueue, Node.NetworkSendService));
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
 protected override void Create()
 {
     Node = new SingleVNode(TfDb, _vNodeSets, _appSets);
 }
Ejemplo n.º 15
0
        protected virtual void TearDown()
        {
            try
            {
                var shutdownCallback = new EnvelopeCallback<SystemMessage.BecomeShutdown>();
                _vNode.Bus.Subscribe<SystemMessage.BecomeShutdown>(shutdownCallback);

                _vNode.Stop();

                shutdownCallback.Wait();

                _db.Dispose();
                _writerChk.Dispose();
                _chaserChk.Dispose();
                Directory.Delete(_db.Config.Path, true);

                _vNode = null;
                _db = null;
            }
            catch (Exception)
            {

            }
        }