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 BasePipe(TransactionService transaction, IDocumentLookup lookup, SortDisk tempDisk, bool utcDate)
 {
     _transaction = transaction;
     _lookup      = lookup;
     _tempDisk    = tempDisk;
     _utcDate     = utcDate;
 }
Example #3
0
 public BasePipe(TransactionService transaction, IDocumentLookup lookup, SortDisk tempDisk, EnginePragmas pragmas)
 {
     _transaction = transaction;
     _lookup      = lookup;
     _tempDisk    = tempDisk;
     _pragmas     = pragmas;
 }
Example #4
0
 /// <summary>
 /// Select corrent pipe
 /// </summary>
 public BasePipe GetPipe(TransactionService transaction, Snapshot snapshot, SortDisk tempDisk, bool utcDate)
 {
     if (this.GroupBy == null)
     {
         return(new QueryPipe(transaction, this.GetLookup(snapshot, utcDate), tempDisk, utcDate));
     }
     else
     {
         return(new GroupByPipe(transaction, this.GetLookup(snapshot, utcDate), tempDisk, utcDate));
     }
 }
Example #5
0
 /// <summary>
 /// Select corrent pipe
 /// </summary>
 public BasePipe GetPipe(TransactionService transaction, Snapshot snapshot, SortDisk tempDisk, EnginePragmas pragmas)
 {
     if (this.GroupBy == null)
     {
         return(new QueryPipe(transaction, this.GetLookup(snapshot, pragmas), tempDisk, pragmas));
     }
     else
     {
         return(new GroupByPipe(transaction, this.GetLookup(snapshot, pragmas), tempDisk, pragmas));
     }
 }
Example #6
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 #7
0
        public SortService(SortDisk disk, int order, EnginePragmas pragmas)
        {
            _disk          = disk;
            _order         = order;
            _pragmas       = pragmas;
            _containerSize = disk.ContainerSize;

            _reader = new Lazy <Stream>(() => _disk.GetReader());

            var bytes = BufferPool.Rent(disk.ContainerSize);

            _buffer = new BufferSlice(bytes, 0, _containerSize);
        }
Example #8
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 #9
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 #10
0
 public GroupByPipe(TransactionService transaction, IDocumentLookup loader, SortDisk tempDisk, bool utcDate)
     : base(transaction, loader, tempDisk, utcDate)
 {
 }
Example #11
0
 public QueryPipe(TransactionService transaction, IDocumentLookup loader, SortDisk tempDisk, EnginePragmas pragmas)
     : base(transaction, loader, tempDisk, pragmas)
 {
 }