Example #1
0
        /// <summary>
        /// Initialize LiteEngine using initial engine settings
        /// </summary>
        public LiteEngine(EngineSettings settings)
        {
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));

            // clear checkpoint if database is readonly
            if (_settings.ReadOnly)
            {
                _settings.Checkpoint = 0;
            }

            LOG($"start initializing{(_settings.ReadOnly ? " (readonly)" : "")}", "ENGINE");

            try
            {
                // initialize locker service (no dependency)
                _locker = new LockService(settings.Timeout, settings.ReadOnly);

                // initialize disk service (will create database if needed)
                _disk = new DiskService(settings);

                // read page with no cache ref (has a own PageBuffer) - do not Release() support
                var buffer = _disk.ReadFull(FileOrigin.Data).First();

                // if first byte are 1 this datafile are encrypted but has do defined password to open
                if (buffer[0] == 1)
                {
                    throw new LiteException(0, "This data file is encrypted and needs a password to open");
                }

                _header = new HeaderPage(buffer);

                // initialize wal-index service
                _walIndex = new WalIndexService(_disk, _locker);

                // if exists log file, restore wal index references (can update full _header instance)
                if (_disk.GetLength(FileOrigin.Log) > 0)
                {
                    _walIndex.RestoreIndex(ref _header);
                }

                // initialize sort temp disk
                _sortDisk = new SortDisk(settings.CreateTempFactory(), CONTAINER_SORT_SIZE, settings.UtcDate);

                // initialize transaction monitor as last service
                _monitor = new TransactionMonitor(_header, _locker, _disk, _walIndex, _settings);

                // register system collections
                this.InitializeSystemCollections();

                LOG("initialization completed", "ENGINE");
            }
            catch (Exception ex)
            {
                LOG(ex.Message, "ERROR");

                // explicit dispose (but do not run shutdown operation)
                this.Dispose(true);
                throw;
            }
        }
Example #2
0
        public QueryExecutor(LiteEngine engine, TransactionMonitor monitor, SortDisk sortDisk, bool utcDate, string collection, Query query, IEnumerable <BsonDocument> source)
        {
            _engine     = engine;
            _monitor    = monitor;
            _sortDisk   = sortDisk;
            _utcDate    = utcDate;
            _collection = collection;
            _query      = query;

            // source will be != null when query will run over external data source, like system collections or files (not user collection)
            _source = source;
        }
Example #3
0
        /// <summary>
        /// Initialize LiteEngine using initial engine settings
        /// </summary>
        public LiteEngine(EngineSettings settings)
        {
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));

            LOG($"start initializing{(_settings.ReadOnly ? " (readonly)" : "")}", "ENGINE");

            try
            {
                // initialize disk service (will create database if needed)
                _disk = new DiskService(settings, MEMORY_SEGMENT_SIZES);

                // get header page from disk service
                _header = _disk.Header;

                // test for same collation
                if (settings.Collation != null && settings.Collation.ToString() != _header.Pragmas.Collation.ToString())
                {
                    throw new LiteException(0, $"Datafile collation '{_header.Pragmas.Collation}' is different from engine settings. Use Rebuild database to change collation.");
                }

                // initialize locker service
                _locker = new LockService(_header.Pragmas);

                // initialize wal-index service
                _walIndex = new WalIndexService(_disk, _locker);

                // restore wal index references, if exists
                _walIndex.RestoreIndex(_header);

                // initialize sort temp disk
                _sortDisk = new SortDisk(settings.CreateTempFactory(), CONTAINER_SORT_SIZE, _header.Pragmas);

                // initialize transaction monitor as last service
                _monitor = new TransactionMonitor(_header, _settings, _locker, _disk, _walIndex);

                // register system collections
                this.InitializeSystemCollections();

                LOG("initialization completed", "ENGINE");
            }
            catch (Exception ex)
            {
                LOG(ex.Message, "ERROR");

                // explicit dispose (but do not run shutdown operation)
                this.Dispose(true);
                throw;
            }
        }
Example #4
0
        public QueryExecutor(LiteEngine engine, TransactionMonitor monitor, SortDisk sortDisk, EnginePragmas pragmas, string collection, Query query, IEnumerable <BsonDocument> source)
        {
            _engine     = engine;
            _monitor    = monitor;
            _sortDisk   = sortDisk;
            _pragmas    = pragmas;
            _collection = collection;
            _query      = query;

            _cursor = new CursorInfo(collection, query);

            LOG(_query.ToSQL(_collection).Replace(Environment.NewLine, " "), "QUERY");

            // source will be != null when query will run over external data source, like system collections or files (not user collection)
            _source = source;
        }
Example #5
0
        public TransactionService(HeaderPage header, LockService locker, DiskService disk, WalIndexService walIndex, int maxTransactionSize, TransactionMonitor monitor, bool queryOnly)
        {
            // retain instances
            _header   = header;
            _locker   = locker;
            _disk     = disk;
            _walIndex = walIndex;
            _monitor  = monitor;

            this.QueryOnly          = queryOnly;
            this.MaxTransactionSize = maxTransactionSize;

            // create new transactionID
            _transactionID = walIndex.NextTransactionID();
            _startTime     = DateTime.UtcNow;
            _reader        = _disk.GetReader();
        }
        public TransactionService(HeaderPage header, LockService locker, DiskService disk, WalIndexService walIndex, int maxTransactionSize, TransactionMonitor monitor, Action <uint> done)
        {
            // retain instances
            _header   = header;
            _locker   = locker;
            _disk     = disk;
            _walIndex = walIndex;
            _monitor  = monitor;
            _done     = done;

            this.MaxTransactionSize = maxTransactionSize;

            // create new transactionID
            _transactionID = walIndex.NextTransactionID();
            _startTime     = DateTime.UtcNow;
            _reader        = _disk.GetReader();

            // enter transaction locker to avoid 2 transactions in same thread
            _locker.EnterTransaction();
        }
Example #7
0
 public SysDump(HeaderPage header, TransactionMonitor monitor, DiskService disk) : base("$dump")
 {
     _header  = header;
     _monitor = monitor;
     _disk    = disk;
 }
Example #8
0
 public SysDump(HeaderPage header, TransactionMonitor monitor) : base("$dump")
 {
     _header  = header;
     _monitor = monitor;
 }
Example #9
0
 public SysPageList(HeaderPage header, TransactionMonitor monitor) : base("$page_list")
 {
     _header  = header;
     _monitor = monitor;
 }