Beispiel #1
0
        public FileReaderV8(HeaderPage header, DiskService disk)
        {
            _collections = header.GetCollections().ToDictionary(x => x.Key, x => x.Value);

            // using writer stream from pool (no need to return)
            _stream = disk.GetPool(FileOrigin.Data).Writer;
        }
Beispiel #2
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;
            }
        }
        public FileReaderV8(HeaderPage header, DiskService disk)
        {
            _collections = header.GetCollections().ToDictionary(x => x.Key, x => x.Value);

            // using writer stream from pool (no need to return)
            _stream = new ConcurrentStream(disk.Writer);
        }
Beispiel #4
0
        public TransactionService(HeaderPage header, DiskService disk, WalIndexService walIndex)
        {
            // retain instances
            _header   = header;
            _disk     = disk;
            _walIndex = walIndex;

            // create new transactionID
            _transactionID = walIndex.NextTransactionID();
            _startTime     = DateTime.UtcNow;
        }
Beispiel #5
0
        public FileReaderV8(HeaderPage header, DiskService disk)
        {
            this.UserVersion = header.UserVersion;

            _collections = header.GetCollections().ToDictionary(x => x.Key, x => x.Value);

            // using writer stream from pool (no need to return)
            _stream = disk.GetPool(FileOrigin.Data).Writer;

            _buffer = BufferPool.Rent(PAGE_SIZE);
        }
Beispiel #6
0
        public FileReaderV8(HeaderPage header, DiskService disk)
        {
            // get a copy of pragmas
            this.Pragmas = new EnginePragmas(header.UpdateBuffer(), header);

            _collections = header.GetCollections().ToDictionary(x => x.Key, x => x.Value);

            // using writer stream from pool (no need to return)
            _stream = disk.GetPool(FileOrigin.Data).Writer;

            _buffer = BufferPool.Rent(PAGE_SIZE);
        }
Beispiel #7
0
        public TransactionMonitor(HeaderPage header, LockService locker, DiskService disk, WalIndexService walIndex)
        {
            _header   = header;
            _locker   = locker;
            _disk     = disk;
            _walIndex = walIndex;

            // initialize free pages with all avaiable pages in memory
            _freePages = MAX_TRANSACTION_SIZE;

            // initial size
            _initialSize = MAX_TRANSACTION_SIZE / MAX_OPEN_TRANSACTIONS;
        }
Beispiel #8
0
        public TransactionMonitor(HeaderPage header, LockService locker, DiskService disk, WalIndexService walIndex, EngineSettings settings)
        {
            _header   = header;
            _locker   = locker;
            _disk     = disk;
            _walIndex = walIndex;
            _settings = settings;

            // initialize free pages with all avaiable pages in memory
            _freePages = settings.MaxTransactionSize;

            // initial size
            _initialSize = settings.MaxTransactionSize / MAX_OPEN_TRANSACTIONS;
        }
        /// <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;
            }
        }
Beispiel #10
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();
        }
Beispiel #11
0
        /// <summary>
        /// Initialize database
        /// </summary>
        public async Task OpenAsync()
        {
            LOG("start initializing", "ENGINE");

            try
            {
                // open async stream
                if (_stream is IAsyncInitialize s)
                {
                    await s.InitializeAsync();
                }

                // initialize disk service (will create database if needed)
                _disk = await DiskService.CreateAsync(_stream, _collation, MEMORY_SEGMENT_SIZES, MAX_EXTENDS);

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

                // test for same collation
                if (_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 wal-index service
                _walIndex = new WalIndexService(_disk);

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

                // register system collections
                // this.InitializeSystemCollections();
                _disposed = false;

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

                // explicit dispose (but do not run shutdown operation)
                await this.DisposeAsync();

                throw;
            }
        }
Beispiel #12
0
        public TransactionService(HeaderPage header, LockService locker, DiskService disk, WalIndexService walIndex, int maxTransactionSize, Action <uint> done)
        {
            // retain instances
            _header             = header;
            _locker             = locker;
            _disk               = disk;
            _walIndex           = walIndex;
            _maxTransactionSize = maxTransactionSize;
            _done               = done;

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

            // enter transaction locker to avoid 2 transactions in same thread
            _locker.EnterTransaction();
        }
Beispiel #13
0
 public WalIndexService(DiskService disk, LockService locker)
 {
     _disk   = disk;
     _locker = locker;
 }
Beispiel #14
0
 public SysDump(HeaderPage header, TransactionMonitor monitor, DiskService disk) : base("$dump")
 {
     _header  = header;
     _monitor = monitor;
     _disk    = disk;
 }
Beispiel #15
0
 public WalIndexService(DiskService disk)
 {
     _disk = disk;
 }